I’m developing using Red Suite 5 and FreeRTOS 7.5.2 on the STM32F4. A certain task seems to be getting dropped from the task list after running for an hour or so, after which the program will either behave erratically or hardfault right away.
When crashing, the program appears to be trying to swap in an invalid task address (pxCurrentTCB == 0x0) during the PendSV interrupt handler. Additionally, the internal bookkeeping data is inconsistent: uxCurrentNumberOfTasks == 9, but only 8 tasks exist in the list returned by uxTaskGetSystemState(). Also pxReadyTasksLists.uxNumberOfItems == 2 (the lost task and another task ran at the same priority), but there only seems to be one valid item, the other is a pointer to pxReadyTasksLists.xListEnd.
I’m 99% sure it’s not a stack problem, I’m using “#define configCHECK_FOR_STACK_OVERFLOW 2” and when calling uxTaskGetSystemState() or manually checking stacks in the debugger I’ve never come within 150 bytes for any task, and never within 500 bytes for the task in question.
I’m guessing I have an interrupt priority problem, since that seems to be the most common issue on the Cortex-M chips, but as far as I can tell I’m doing everything correctly.
// Definitions in FreeRTOSConfig.h #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xF #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 #define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) // Called when the program starts before any other NVIC functions NVIC_SetPriorityGrouping(3); // Calls to install each individual interrupt, where: // irq is the interrupt number // prio is the assigned priority, I only use (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 0) to (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 2) NVIC_SetPriority(irq, prio); NVIC_EnableIRQ(irq);
Here’s information from the hard fault:
R0 = 2001C064
R1 = 0
R2 = 0
R3 = 20000F74
R12 = 200004BC
LR [R14] = 557CF342 subroutine call return address
PC [R15] = 557CF342 program counter
PSR = 6000000E
BFAR = E000ED38
CFSR = 00000001
HFSR = 40000000
DFSR = 00000001
AFSR = 00000000
SCB_SHCSR = 00000400
Any insight into what might be going wrong would be greatly appreciated, I’ve been banging my head against this for a few days without much progress. If anything is unclear I would be happy to elaborate.