Trying to run FreeRTOS on ESP32 ARM Cortex M4F, but it fails inside xPortStartScheduler.
static void prvPortStartFirstTask( void )
{
/* Start the first task. This also clears the bit that indicates the FPU is
* in use in case the FPU was used before the scheduler was started - which
* would otherwise result in the unnecessary leaving of space in the SVC stack
* for lazy saving of FPU registers. */
__asm volatile (
" ldr r0, =0xE000ED08 \n"/* Use the NVIC offset register to locate the stack. */
" ldr r0, [r0] \n"
" ldr r0, [r0] \n"
" msr msp, r0 \n"/* Set the msp back to the start of the stack. */
" mov r0, #0 \n"
" msr control, r0 \n"
" cpsie i \n"/* Globally enable interrupts. */
" cpsie f \n"
" dsb \n"
" isb \n"
" svc 0 \n"/* System call to start first task. */
" nop \n"
" .ltorg \n"
);
}
The call to “svc 0” will fail because the BASEPRI is not zero.
When calling xTaskCreate() BASEPRI is set to configMAX_SYSCALL_INTERRUPT_PRIORITY and this is done before starting the scheduler. Should be ok.
I tried manually setting BASEPRI to 0 and this seems to fix the issue, but I have been using FreeRTOS in the past, and never had to do this “fix”. Also found solutions that proposed changing
static UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
to zero. But again this seems wrong, somehow.
So to sum up:
Init_stuff..
xTaskCreate(..); // Sets BASEPRI = 0xA0 (configMAX_SYSCALL_INTERRUPT_PRIORITY)
vTaskStartScheduler();
-> xPortStartScheduler(...)
-> prvPortStartFirstTask() // svc 0 fails because BASEPRI=0xA0
I’m guessing there is something important that I’m missing, where is BASEPRI suppose to be cleared ?