diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b8a599546..406975122a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed a bug where guards would raise exceptions instead of just being false +- Fixed STM32 not aborting when `AVM_ABORT()` is used +- Fixed a bug that would leave the STM32 trapped in a loop on hard faults, rather than aborting ## [0.6.0-alpha.1] - 2023-10-09 diff --git a/src/platforms/stm32/src/main.c b/src/platforms/stm32/src/main.c index a5a482b534..672980aef6 100644 --- a/src/platforms/stm32/src/main.c +++ b/src/platforms/stm32/src/main.c @@ -19,6 +19,7 @@ */ #include +#include #include #include @@ -61,6 +62,8 @@ "\n" int _write(int file, char *ptr, int len); +pid_t _getpid(void); +int _kill(pid_t pid, int sig); static void clock_setup() { @@ -124,6 +127,30 @@ int _write(int file, char *ptr, int len) return -1; } +// newlib stubs to support AVM_ABORT +pid_t _getpid() +{ + return 1; +} + +int _kill(pid_t pid, int sig) +{ + UNUSED(pid); + if (sig == SIGABRT) { + fprintf(stderr, "Aborted\n"); + } else { + fprintf(stderr, "Unknown signal %d\n", sig); + } + errno = EINVAL; + return -1; +} + +// Redefine weak linked while(1) loop from libopencm3/cm3/nvic.h. +void hard_fault_handler() { + fprintf(stderr, "\nHard Fault detected!\n"); + AVM_ABORT(); +} + int main() { clock_setup();