Hello,
I am working on a project based on STM32F429 for quite a while now. Recently I’ve started noticing rare system hangs.
I decided to check utilization of system resources and enabled the following:
~~~
extern volatile uint32
t ClockCounter;
extern void Init_TIM4(void);
define configUSETRACEFACILITY 1
define configGENERATERUNTIME_STATS 1
define portCONFIGURETIMERFORRUNTIMESTATS()(InitTIM4())
define portGETRUNTIMECOUNTERVALUE() (Clock_Counter)
~~~
For the run time stats I use general purpose Timer4, which generates interruption at 10kHz (according to recommendation) and does the following:
~~~
void TIM4
IRQHandler(void) {
if (TIMGetITStatus(TIM4, TIM
ITUpdate)) {
TIM
ClearITPendingBit(TIM4,TIMIT
Update);
++ClockCounter;
};//if (TIM
ITUpdate)
};//TIM4
IRQHandler()
~~~
IRQ priority was originally set to 1, which is very high, however, since no RTOS API used, so it shouldn’t matter.
And that was the beginning of disaster: system started constantly hanging at random time (from 18ms to 18minutes) in random spots, causing random consequences (BusFault, HardFault, dropping to DefaultHandler, all sorts of assert_failed() in different spots).
I tried to set other priorities from 0 to F, but it had almost no effect, only hanging frequency changes a little bit.
RTOS priorities are set as follows:
~~~
define configPRIO_BITS 4
define configLIBRARYLOWESTINTERRUPT_PRIORITY 0xF
define configLIBRARYMAXSYSCALLINTERRUPTPRIORITY 5
define configKERNELINTERRUPTPRIORITY ( configLIBRARYLOWESTINTERRUPTPRIORITY << (8 – configPRIOBITS) )
define configMAXSYSCALLINTERRUPTPRIORITY ( configLIBRARYMAXSYSCALLINTERRUPTPRIORITY << (8 – configPRIOBITS) )
~~~
I updated FreeRTOS to v9.0.0 -> No effect
I removed all other functionality and tasks, only 1 task with 1 semaphore left and 1 timer IRQ, and it still hangs all the time. Disabling one of them (Task Scheduler or IRQ) leaves system 100% stable, but useless.
Task code:
~~~
void Task
USART2Comm (void *par) {
xSemaphoreGive(SemId_USART2_Tx);
for(;;) {
if (xSemaphoreTake(SemId_USART2_Rx,500) == pdPASS) {
//all removed
} else {//if (msg received successfully)
//all removed
};//else if (msg received successfully)
LedTog(LED_BLUE1);
};//inf loop
};//UART2_Comm_Task()
~~~
main() code:
~~~
int main(void) {
Init_Clock();
Init_LEDs();
Init_Buttons();
SCB->SHCSR |= SCB_SHCSR_BUSFAULTENA_Msk; // Enabling BusFault hook
SystemInit();
SystemCoreClockUpdate();
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
if ((SemId_USART2_Rx = xSemaphoreCreateCounting(16,0)) == NULL) { goto InitFailed; };//;//
if ((SemId_USART2_Tx = xSemaphoreCreateBinary()) == NULL) { goto InitFailed; };
xTaskCreate(Task_USART2_Comm, "U2C", 8*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, &TaskHandler);
if (TaskHandler == NULL) { goto InitFailed; };
vTaskStartScheduler();
// normally should never get here
InitFailed:
for(int i=0;;) {
if (++i >= 1000000) { i=0; LedTog(LED_RED2); };
};//inf loop trap
};//main()
~~~
Debugging showed that system crashes right after leaving timer irq.
Any thoughts?
Thanks in advance…