rustrannik wrote on Friday, August 11, 2017:
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 Clock_Counter;
extern void Init_TIM4(void);
#define configUSE_TRACE_FACILITY 1
#define configGENERATE_RUN_TIME_STATS 1
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()(Init_TIM4())
#define portGET_RUN_TIME_COUNTER_VALUE() (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 (TIM_GetITStatus(TIM4, TIM_IT_Update)) {
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
++Clock_Counter;
};//if (TIM_IT_Update)
};//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 Default_Handler, 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 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) )
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_USART2_Comm (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…