I am relatively new to FreeRTOS and embedded devices in general but I have been attempting to get ethernet communication with a SAMA5D27 dev board. I have been using MPLab libraries to set up FreeRTOS and it seems to be building correctly. Everything is initiating and I can create tasks but when vTaskStartScheduler() is called it causes it to jump to the undefined instructions interrupt handler and nothing ever actually runs. I traced through it with the debugger and it seems to always get stuck on this line in FreeRTOS_tasks.c:
apparently pxNewTCB points to an invalid memory location, for example 0 which may point to a previous allocation failure. As Hartmut points out, most of those cases can be found with configASSERT resolving to something meaningful.
Step through the memset() assembly code in the debugger to see if it is using floating point registers. Some memory set and move functions use the wide floating point registers as an optimisation. If it does use them, are you building FreeRTOS to include floating point support? If not, the floating point registers won’t be saved and restored with the task’s context, and can get corrupted.
I stepped through memset and found that all values looked reasonable so I went back again and found that the debugger was getting hung up on that spot but the code actually does execute past it.
configAssert() is actually being called with vPortRestoreTaskContext(); in xPortStartScheduler();
vPortRestoreTaskContext:
// Switch to system mode
CPS #SYS_MODE
portRESTORE_CONTEXT
.macro portRESTORE_CONTEXT
// Set the SP to point to the stack of the task being restored.
LDR R0, =pxCurrentTCB
LDR R1, [R0]
LDR SP, [R1]
// Is there a floating point context to restore? If the restored
// ulPortTaskHasFPUContext is zero then no.
LDR R0, =ulPortTaskHasFPUContext
POP {R1}
STR R1, [R0]
CMP R1, #0
// Restore the floating point context, if any
POPNE {R0}
#if configFPU_D32 == 1
VPOPNE {D16-D31}
#endif
VPOPNE {D0-D15}
VMSRNE FPSCR, R0
// Restore the critical section nesting depth
LDR R0, =ulCriticalNesting
POP {R1}
STR R1, [R0]
// Restore all system mode registers other than the SP (which is already
// being used)
POP {R0-R12, R14}
// Return to the task code, loading CPSR on the way. CPSR has the interrupt
// enable bit set appropriately for the task about to execute.
RFEIA sp!
.endm
It always throws the fault immediately when I try to step through it but for some reason if I ‘run to cursor’ line by line it lets me pass the ‘switch to system mode’ instruction and then errors on the second line: