MCU is an STM32L422

FreeRTOS (CMSIS-V2), 3 simple tasks, they run just fine on their own. USART1 is configured to receive data via IDLE detection and DMA circular buffer. Again it works fine on it's own.

To couple them I call

HAL_UART_Receive_DMA(rf->port, RxBuffer1, RX_BFR_SIZE);

from one of the tasks. It was getting stuck before I started clearing the IDLE flag as seen above. It is now fine, DMA interrupt is activated and RTOS keeps running happily.

Problem is when I actually receive some data. Something smaller than the size of the buffer so no overflows etc. Upon receiving data it gets stuck within stm32l4xx_hal_uart.c and the actual Callback function never gets called.

Started debugging, no error flags, isrflags only include IDLE, TC, and TXE. I suppose all are as expected. It keeps looping in and out of void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) in the same file above. It is hard to tell why my Callback function never gets called, and because it is not get called IDLE flag stays up permanently, explaining the loop behaviour.

However I noticed that when I let it go through few times within debug, it eventually brakes out freertos routines and everything goes back to normal, until the next piece of data is received. It never works when a normal run though.

Feels very much like a timing / priority issue, I increased USART and DMA interrupt priorities (initially they were 5) to 6 or 10 from CubeIDE but nothing changed.

Not sharing code to not to clutter, I am not doing anything significant other than the ones described above.

  • \$\begingroup\$ I'm not that firm in STM32 HAL, but so far I didn't have to use __HAL_* stuff in my own code. Maybe you break some logic with setting unexpected bits. \$\endgroup\$
    – Arsenal
    Aug 31 at 14:08
  • \$\begingroup\$ Searching through the implementation of the UART I only see the Idle-flag handled correctly when you have HAL_UART_RECEPTION_TOIDLE selected - which you don't. \$\endgroup\$
    – Arsenal
    Aug 31 at 14:12
  • \$\begingroup\$ @Arsenal, thank you. It is set here; github.com/STMicroelectronics/STM32CubeF7/blob/master/Drivers/… .. It is again part of the HAL driver. IDLE interrupt works just fine if I don't start the FreeRTOS kernel. Do you use LL instead ? \$\endgroup\$
    – Charles
    Aug 31 at 15:43
  • \$\begingroup\$ So do you use FreeRTOS functions in the callback? If yes, are the IRQ priorities set so that it allows you to use FreeRTOS functions from IRQs? Is there enough stack for the RTOS tasks and kernel? \$\endgroup\$
    – Justme
    Aug 31 at 17:01
  • \$\begingroup\$ @Justme, thanks, I don't. Once again, once RTOS kernel is started, execution never reaches to the callback, and for test purposes all I have in the callback is one liner clearing the IDLE flag, but I never get to it unless I am debugging. \$\endgroup\$
    – Charles
    Aug 31 at 17:05


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.