cancel
Showing results for 
Search instead for 
Did you mean: 

UART getting stuck in TX mode on resuming from sleep mode.

racemax
Associate II

Hello @Tilen MAJERLE  and everyone else,

So, I have written firmware to work on the STM32L476RG microcontroller. A part of it is not working properly.

I activated DMA on the SPI(SPI1) and UART(UART5) communication channels. I use the SPI to communicate with a camera, while I use the UART to communicate with a Bluetooth module (HM-11). Previously I was using the polling method to communicate, and it worked. But I wanted to optimize it, so I switched to DMA. It did shave off some seconds off the image download time.

When I switched to DMA, I noticed that when the system went to sleep, I could still wake it up via Bluetooth, but it will not respond to commands after waking it up from SLEEP MODE. I used the debugging tool and found that it was getting stuck here: 

racemax_0-1729267444550.png

 

What could be making it get stuck in that position? The system is supposed to transmit a coded message via Bluetooth when it wakes up that's why it gets to the highlighted code in the above picture.

You can also take a look at the priorities assigned to the interrupts below:

racemax_1-1729267530845.png

DMA2 belongs to UART5 and DMA1 belongs to SPI1.

Let me know what other information you will need.

Thanks in advance.

3 REPLIES 3
Tilen MAJERLE
ST Employee

I do not fully understand why do you use DMA to send single character and then wait for the state to go back from TX_BUSY. I'd suggest to use the UART callbacks (TX Complete callback, in particular).

How do you go to sleep? Is it just __WFI instruction or you go to STOP mode (with more than just __WFI instruction)?

Hello @Tilen MAJERLE ,

 

My system goes to sleep using the following instructions:

HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);

 

For the DMA I'll use it to send the entire string and see how it goes.

 

Hello @Tilen MAJERLE,

I used the callbacks as you suggested. It solved the problem. However, it gave rise to a new one.

When it wakes up, the system does process commands. However, it returns incomplete data via the Bluetooth module. Refer to the screenshot showing the interrupts and their priorities.

Let me know what other information you will need to assist. Thanks.