MaJerle / stm32-usart-uart-dma-rx-tx

STM32 examples for USART using DMA for efficient RX and TX transmission
MIT License
1.27k stars 319 forks source link

Using CubeMX and HAL for UART DMA on H7 #21

Closed egoltzman closed 1 year ago

egoltzman commented 2 years ago

I'm trying to do the same functionality on H750 but with using CubeMX (From within CubeIDE) and using HAL function (Mainly HAL_UARTEx_ReceiveToIdle_DMA) but it is not working for me. Is there any reason for you to use the LL over the HAL?

MaJerle commented 2 years ago

I am using LL drivers to show to full concept to the community - this is main reason actually.

If you want to use it with HAL and CubeMX, ensure that in GUI you have:

You can use this project from G4 as an idea how to implement it. https://github.com/STMicroelectronics/STM32CubeG4/blob/master/Projects/NUCLEO-G474RE/Examples/UART/UART_ReceptionToIdle_CircularDMA/Src/main.c

egoltzman commented 2 years ago

Thank you Tilan for your quick response. The suggestion to use the G4 example was great and indeed I was able to port it to my target MCU and run it on the H750 DK successfully. But, When I tried to use it together with my TouchGFX application (As I need on my final project target board) the same test that worked before I added TGFX is not working fine. I thought it might be FreeRTOS that caused the problem but after adding it to the first working test it is still working so it looks like it is not FreeRTOS but TGFX and all its related stuff like DMA2D, LTDC etc. that make the change. What I see is that the HAL_UARTEx_RxEventCallback is being called with the right value in "Size" but the content of the received circular buffer (aRXBufferUser) holds only the last character that was sent in the first entry of the buffer., that is, if I send "1234567", I get Size of 7 and the buffer looks like this: [image: image.png] It looks to me like the increment action on the memory somehow is not working. What do you think? Thanks, Eyal

Eyal Goltzman איל גולצמן Managing Partner

EmbeddedPartners.co.il http://embeddedpartners.co.il/ @.*** +972-54-4875-625

On Wed, 18 May 2022 at 18:13, Tilen Majerle @.***> wrote:

I am using LL drivers to show to full concept to the community - this is main reason actually.

If you want to use it with HAL and CubeMX, ensure that in GUI you have:

  • UART is enabled
  • UART interrupts are enabled
  • UART has configured DMA for RX & DMA has configuration in circular mode

You can use this project from G4 as an idea how to implement it.

https://github.com/STMicroelectronics/STM32CubeG4/blob/master/Projects/NUCLEO-G474RE/Examples/UART/UART_ReceptionToIdle_CircularDMA/Src/main.c

— Reply to this email directly, view it on GitHub https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx/issues/21#issuecomment-1130146098, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA57KHMUDIAA73PA43CUJXDVKUCKHANCNFSM5WIZ2EZA . You are receiving this because you authored the thread.Message ID: @.***>

MaJerle commented 2 years ago

Eyal - I don't see the image but it could be that there is a problem with priorities at DMA level or if TouchGFX is using DMA for some other operations.

Did you make sure that interrupts for UART & its DMA stream are above (lower prio) that FreeRTOS minimum is?

egoltzman commented 2 years ago

Hi Tilen, This is how the image looks like: aRXBufferUser[0] is 0x37 aRXBufferUser[1..19] is 0x0

As for the priorities, When I added FreeRTOS the CubeMX updated the UART and DMA priorities to 5 but, as I mention, on the sample test I run without TouchGFX and with FreeRTOS (And the updated priorities of 5) and the UART is still working there as expected. The problem start when TGFX is added to the project with many other elements (DMA2D. LTDC etc.)

egoltzman commented 2 years ago

Tilen, I think I know now the reason for the problem, the CubeMX call the initializations of the elments in the wrong order and I need to change it manually in CubeMX to fit this order: MX_GPIO_Init(); MX_CRC_Init(); MX_LTDC_Init(); MX_DMA2D_Init(); MX_FMC_Init(); MX_MDMA_Init(); MX_JPEG_Init(); MX_TouchGFX_Init(); / USER CODE BEGIN 2 / MX_DMA_Init(); MX_USART3_UART_Init();

Somehow, someone is braking the DMA settings. Thanks! Eyal