Hi, I’m trying the GCC Cortex-M3 port on the SAM3X8E chip for the Arduino platform with this simple program:
#include <FreeRTOS.h>
#include <task.h>
void hello_world_task( void* pvParameters )
{
(void) pvParameters;
pinMode( 13, OUTPUT );
bool led_state = false;
while( 1 )
{
vTaskDelay( pdMS_TO_TICKS( 250 ) );
digitalWrite( 13, (led_state = !led_state) );
}
}
void setup()
{
xTaskCreate(
hello_world_task,
"HWT",
configMINIMAL_STACK_SIZE*4,
(void*) 0,
tskIDLE_PRIORITY,
NULL );
/* (1) */ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
__enable_irq();
vTaskStartScheduler();
}
void loop() {}
(1) SysTick()
triggers an interrupt before the first task is created, so the kernel crashes. That’s way I needed to disable the SysTick interrupt and then to enable it here (as well as the whole interrupt system).
The scheduler already starts, but when it’s time to start the first and only task it seems that the SVCHandler()
corrupts its address, so I get a fault handler (or at least that’s not the address of the task).
In the attached image you can see that the value of the LR register (register 14) before executing the instruction BX is wrong, so a fault handler is triggered.
The LR register holds the value FFFF FFF9
when landing in vPortSVCHandler
after the call to the function prvPortStartFirstTask()
, as shown:
Is that normal? What must I look for? Any hint? Thanks!