BriscoeTech / Arduino-FreeRTOS-SAMD21

A port of FreeRTOS that runs on Arduino Samd21 boards
63 stars 19 forks source link

Address of rtosSysTick_Handler() inside sysTickHook invalid resulting in HardFault #30

Closed janulooo closed 2 years ago

janulooo commented 2 years ago

Hi, great work porting FreeRTOS to SAMD21!

However, I'm having issue during application start, on first sysTickHook() call I can see that address of rtosSysTick_Handler is some random value, therefore the function rtosSysTick_Handler() is called incorrectly resulting in HardFault. Looks like some incorrect memory initialisation or something. If I understood the concept correctly, value of rtosSysTick_Handler shall be 0 until set within xPortStartScheduler().

When I try Basic_RTOS_Example compiled and uploaded by Arduino IDE, it works nice. When I import such project to platformio, problem with HardFault caused by invalid rtosSysTick_Handler() starts happening.

Hopefully this is just something you dealt with and I just overlooked something trivial, being new on SAM / Arduino platform. I have experience with STM32 and VisualGDB plugin.

Board: Arduino MKR Wifi 1010 IDE: PlatformIO Debugger: Atmel-ICE

janulooo commented 2 years ago

As discussed on PlatformIO forum, this seems to be an issue outside the FreeRTOS-SAMD21 library. The problem is, that MCU doesn't seem to be initialized properly, especially the interrupts and systick are already enabled when entering the reset handler, causing interruption of memory initialization. First systick without finalized memory initialization causes rtosSysTick_Handler being set to random value, resulting in hard fault. Therefore I'm closing this issue.