cancel
Showing results for 
Search instead for 
Did you mean: 

Why is the code for UART callbacks being optimized out with optimization set to -O (none)

GreenGuy
Lead

Nucleo STM32H723ZG

CubeMX 6.3.0

Cube IDE 1.7.0

Package 1.9.0

Using CubeMX the UART2 is set up for DMA on transmit and receive. The code is working for transmit and I see data on the scope that matches what is being setup in the buffer. The transmit pin has been connected to the receive pin to loop back the data. The receive buffer after transmitting is not populating with the data. I tried to break point in the receive callback and the code is breaking in the HAL_TIMPeriodElapsedCallback which is just after the UART_DMA callbacks. Inspection of the Listing output reveals that the there is no DMA Callback code for HAL_UART_RXFifoFullCallback and HAL_UART_TxFifoEmptyCallback which explains why the breakpoint is falling through the timer callback fucntion. The optimization is set to -O (none) and I have code in the callbacks. These functions are supposed to overload the _weak function of the same name in the HAL UART code created from CubeMX.

What is the deal?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> They exist in the stm32h7xx_hal_uart_ex.c. In the current 1.9.0 repo they are at lines 287 and 302.

Sort of. They are called HAL_UARTEx_RxFifoFullCallback and HAL_UARTEx_TxFifoEmptyCallback.

https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c#L287

https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c#L302

Those callbacks are new for me, otherwise I would have noticed the "Ex" omission. Glad you got it working.

The callback for TX is HAL_UART_TxCpltCallback. No need to implement it if you don't care about when it finishes.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

8 REPLIES 8
Pavel A.
Evangelist III

"Optimization none" is -O0. -O means same as -O1.

S.Ma
Principal

Be careful that if you monitor the usart in the watch debug window, the debugger will read and steal the data from the sw... try to use ram buffer and avoid viewing hw registers.

It is -O0

GreenGuy
Lead

I always view the memory after a transaction and do not view while running. Neither do I monitor the registers. I do set breakpoints but the breakpoint for the callbacks are breaking in the wrong place because the source code for the Uart callbacks is not being created and the breakpoints end up breaking in an unrelated callback (Periodic Tick Timer).

TDK
Guru

> HAL_UART_RXFifoFullCallback

> HAL_UART_TxFifoEmptyCallback

These functions don't exist in HAL, nor are there references to them. It makes sense the compiler would optimize them out.

https://github.com/STMicroelectronics/STM32CubeH7/search?q=HAL_UART_RXFifoFullCallback

https://github.com/STMicroelectronics/STM32CubeH7/search?q=HAL_UART_TxFifoEmptyCallback

The callback that should be called when reception completes is HAL_UART_RxCpltCallback.

If you feel a post has answered your question, please click "Accept as Solution".
GreenGuy
Lead

They exist in the stm32h7xx_hal_uart_ex.c. In the current 1.9.0 repo they are at lines 287 and 302. However, it is true, in my case they are not applicable. I am not sure why I tried to use them. I think it was referenced in another online source but I cannot remember where now. I ended up using the RxEventcallback and it compiles and works. Not sure what to do the Tx as I am not there yet for the callback. Tx using DMA seems to be working without a callback. I am only sending a test string at the moment.

TDK
Guru

> They exist in the stm32h7xx_hal_uart_ex.c. In the current 1.9.0 repo they are at lines 287 and 302.

Sort of. They are called HAL_UARTEx_RxFifoFullCallback and HAL_UARTEx_TxFifoEmptyCallback.

https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c#L287

https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c#L302

Those callbacks are new for me, otherwise I would have noticed the "Ex" omission. Glad you got it working.

The callback for TX is HAL_UART_TxCpltCallback. No need to implement it if you don't care about when it finishes.

If you feel a post has answered your question, please click "Accept as Solution".
GreenGuy
Lead

Solved