I have interest to run freeRTOS on an M1 (Microsemi) board but there is no freeRTOS port available for M1. So I picked the M0 port, used NXP M0+ LPC51U68 demo as an example, and made a few update in port.c (portNVIC_PENDSV_PRI and portNVIC_SYSTICK_PRI, which requires 2 bits, instead of 8 bits in M0+, per user manual). also replaced heap_5 by heap_4 due to difficulty to add heap in 2nd segment. And added “weak” and “sections(”.after_vectors") to SVC_Handler and PendSV_Handler (from hal) to make compilation pass.
Back into main(), to keep code minimal at this point, only called vTaskStartScheduler(), which creates the idle and timer task by default (task.c), and then called xPortStartScheduler() and then vPortStartFirstTask() (port.c).
however, got HardFault error.
Debugged into the assembly code in vPortStartFirstTask(). noticed in the NXP demo, the last statement “bx r3” leads to prvTimerTask at 0x5d0b (with “push {r7, lr}”, 1st statement of prvTimerTask). However, with the M1 board, “bx r3” leads to something at 0xfffc0 (with “lsls r2,r3,#13”), which then causes hardFault.
I am not sure if the steps to “start first task” should be different with M1 compared to M0/M0+. I am not proficient at assembly and ARM. so not sure where to find relevant document/guideline or how to trace this issue? any suggestion appreciated.
in addition, have trouble to copy the assembly code from " Debugging Hard Fault & Other Exceptions" (http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html) and paste to the HardFault_Handler(). any additional edit required to use that code in HardFault_Handler()?