cancel
Showing results for 
Search instead for 
Did you mean: 

Why does the behavior of the while loop I wrote differ from the one generated by STM32CubeMX?

Shion
Associate II

Hello everyone.

Why does the behavior of the while loop I wrote differ from the one generated by STM32CubeMX? Since the code generated by STM32CubeMX is highly abstracted, is it possible that even the same while loop behaves differently due to internal processing? Where can I learn about such rules? I'm a beginner, so I would really appreciate any guidance. If anyone knows, I would be grateful for your help.

 

Here are the details of the issue.

 

1. When code is written inside the while loop generated by STM32CubeIDE

Code:

Shion_0-1755130651074.png

Result: It doesn't work correctly. It seems that something inside the while loop isn't functioning properly.

Shion_1-1755130821918.png

2. When code is written inside the while loop wrote by myself.

Code:

Shion_2-1755130908489.png

 

Result: It works correctly

Shion_3-1755130945747.png

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

Probably due to the unconditional while loop that it gets stuck in. It never makes it to the other code.

TDK_0-1755132855670.png

 

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

View solution in original post

5 REPLIES 5
TDK
Super User

Probably due to the unconditional while loop that it gets stuck in. It never makes it to the other code.

TDK_0-1755132855670.png

 

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

Sorry, your comment is correct. I had mistakenly written the wrong code and result. For some reason, when I place the code inside the while loop generated by STM32CubeMX, TeraTerm becomes unresponsive. However, when I use my own custom while loop, this issue does not occur.

 

When code is written inside the while loop generated by STM32CubeMX

Code:

Shion_2-1755139527281.png

 

Result: It doesn't work correctly. 

 

Shion_0-1755139019236.png

 

Karl Yamashita
Principal

Looks like AT commands so the device you're talking to is responding before you call HAL_UART_Receive

You need to enable UART interrupts and use HAL_UART_Receive_IT or enable DMA and use HAL_UART_Receive_DMA 

Who turned off the lights?

Open Source CAN bus analyzer
Shion
Associate II

I apologize. I've found the cause of the issue. It turns out that inserting a break statement into the while loop generated by STM32CubeMX was not appropriate. I'm sorry for troubling you with scuh a basic mistake. Thank you very much for your support.

Karl Yamashita
Principal

Well breaking out of the while loop indicates you timed out on receive due to the other device already replied before you called HAL_UART_Receive. You still need to use HAL_UART_Receive_IT

Who turned off the lights?

Open Source CAN bus analyzer