Skip to main content
Visitor II
March 26, 2025
Question

STM32G4 HAL DMA start failed after software reset and Optimization -O3

  • March 26, 2025
  • 2 replies
  • 648 views

These's a very strange bug in current verion of STM32G4 HAL library(STM32Cube_FW_G4_V1.6.1) and it took me 2 days to find a workaround.

The problem is:

When normal power on, everything is fine.

When compiler optimization set to -o1, everything is fine.

But if I set complier optimization to -o3, and perform a software reset(__NVIC_SystemReset()), after reset, the HAL function "HAL_SPI_TransmitReceive_DMA" will fail on "HAL_DMA_Start_IT" line.

Since my optimization is set to -o3, I can't dig deeper to find out what exactly happens. And my workaround is individually set stm32g4xx_hal_dma.c file to compile under -o1.

After doing so the problem disappears.

My IDE is uVision V5.41, and ARM Compiler version is V6.22.

    This topic has been closed for replies.

    2 replies

    TomZhuAuthor
    Visitor II
    March 27, 2025

    More details:

    My projects is using MCU to collect sensor data, in the main loop I will poll data ready interrupt pin to start spi transmission.

    After software reset, the program will at first using synchronized spi transmit and receive to setup sensor, this part is ok with no problem, but after the system enters working state (means poll data ready pin to start spi dma transmission), the first a few data can be received by spi dma, then the function "HAL_SPI_TransmitReceive_DMA" will always fail.

    Please somebody help. Thanks in advance.

    Technical Moderator
    March 28, 2025

    Hello @TomZhu 

    Is your application work fine with the previous version of HAL library?

    TomZhuAuthor
    Visitor II
    March 29, 2025

    @Saket_Om Thanks for your attention.

    I did not test my project under previous version of HAL library, but I can try to do so. Please advise which version is worth tying, thank you!