vPortStartFirstTask crashes in cortex m0plus controller

Hi, Currently i am working with cortex m0plus controller using freertos. When i am resetting the controller using NVIC_systemReset the system gets hangs at vPortStartFirstTask at nop instruction after svc instruction. thanks in advance

vPortStartFirstTask crashes in cortex m0plus controller

There is a problem on Cortex-M0 that interrupts have to be enabled to call SVC to in turn start the scheduler so there is an instruction during which interrupt are enabled and the scheduler is not started. What can be done about this? On the M3 system interrupts are not enabled until the first task context is restored. That is possible because it uses the basepri, but there is no basepri on the m0.

vPortStartFirstTask crashes in cortex m0plus controller

Thanks Dave,
is there any solution for this. this not hanging everytime. but sometimes this happens.

vPortStartFirstTask crashes in cortex m0plus controller

Hi dave, Can you explain you point in detail.. that would be better for me to understand.. thanks in advance

vPortStartFirstTask crashes in cortex m0plus controller

For the code you post it looks like you are using an out of date FreeRTOS version, although I don’t think that is related to your problem. Try replacing the code in prvStartFirstTask() (vPortStartFirstTask() in your case) with the following. It starts the scheduler without using the SVCHandler, so interrupts can remain disabled until the task context is ready:
/* The MSP stack is not reset as, unlike on M3/4 parts, there is no vector
table offset register that can be used to locate the initial stack value.
Not all M0 parts have the application vector table at address 0. */
    
ldr r3, =pxCurrentTCB /* Obtain location of pxCurrentTCB. */
ldr r1, [r3]            
ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */
adds r0, #32 /* Discard everything up to r0. */
msr psp, r0  /* This is now the new top of stack to use in the task. */
movs r0, #2  /* Switch to the psp stack. */
msr CONTROL, r0
pop {r0-r5}  /* Pop the registers that are saved automatically. */
mov lr, r5   /* lr is now in r5. */
cpsie i      /* The first task has its context and interrupts can be enabled.*/
pop {pc}     /* Finally, pop the PC to jump to the user defined task code. */
Please let me know if this solves the problem. Regards.

vPortStartFirstTask crashes in cortex m0plus controller

thanks for your kind reply.. Fine this works. After adding this part of code i am getting the error as insufficient heap. we are not using any dynamic memory allocation. by adding this code suddenly hangs at insufficient heap.. thanks in advance

vPortStartFirstTask crashes in cortex m0plus controller

Does this happen the first time the system boots up (powers on), or only when you reset it using NVIC_systemReset? What does resetting using NVIC_systemReset mean? Is it a hard reset? Regards.

vPortStartFirstTask crashes in cortex m0plus controller

thanks again. yes this happens some times when i am resetting the controller using system reset. this not happening at every startup NVIC_SystemReset() is an arm core API used to reset the controller. In this we are writing in AIRCR (Application Interrupt and Reset Control Register) which in turn request for an system soft reset.. thanks

vPortStartFirstTask crashes in cortex m0plus controller

yes this happens some times when i am resetting the controller using system reset.
If that means on a power on reset, then I don’t know what could be causing the problem. Does it happen even when no interrupts are enabled before the scheduler is started? Regards.

vPortStartFirstTask crashes in cortex m0plus controller

Thanks again No this is not all happening before scheduler starts.