FreeRTOS 5.4 vs 7.1 compatibility

alan_rouse wrote on Friday, March 30, 2012:

I have been running with FreeRTOS V5.4 for a long time now on projects using Eclipse and an STM32 ARM processor, and have no problems with it.  However, I want to evaluate Precipio’s Trace add-on, which needs FreeRTOS V7.1.  I tried updating to this latest version, but my project won’t run:

My startup code is quite straightforward, creating a single task then starting the scheduler.  That first task in turn creates further tasks.  However, the problem occurs when the code reaches the vTaskStartScheduler() command, at which point the debugger jumps to the default handler.  On stepping through vTaskStartScheduler() I have found that the error occurs when it calls

void vPortStartFirstTask( void )
{
	__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. */
					" cpsie i				\n" /* Globally enable interrupts. */
					" svc 0					\n" /* System call to start first task. */
					" nop					\n"
				);
}

When the debugger reaches the svc 0 instruction it jumps the the Default Handler.

FreeRTOS v5.4 has slightly different code, and this works.

void vPortStartFirstTask( void )
{
	__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. */
					" svc 0					\n" /* System call to start first task. */
				);
}

Can anyone suggest how I should modify my code to be compatible with FreeRTOS v7.1?

rtel wrote on Friday, March 30, 2012:

The extra line of code (cpsie) should not effect you.  It was added to prevent a hard fault being generated under certain conditions with certain libraries.  If you are jumping to the default handler, rather than hard faulting, I would suggest that your interrupt vector table is not populated with the FreeRTOS interrupt handlers.

If you are using CMSIS compliant vector table then you can add the following three lines to FreeRTOSConfig.h to allow the code to vector to FreeRTOS correctly:

#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler

Otherwise you will have to populate the vector table manually, and can check your previous working project to see where these three functions fit into the table.

Regards.

alan_rouse wrote on Saturday, March 31, 2012:

Richard

Thanks for your prompt response.

Regards
Alan