2025-08-13 5:35 PM
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:
Result: It doesn't work correctly. It seems that something inside the while loop isn't functioning properly.
2. When code is written inside the while loop wrote by myself.
Code:
Result: It works correctly
Solved! Go to Solution.
2025-08-13 5:54 PM
Probably due to the unconditional while loop that it gets stuck in. It never makes it to the other code.
2025-08-13 5:54 PM
Probably due to the unconditional while loop that it gets stuck in. It never makes it to the other code.
2025-08-13 7:47 PM
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:
Result: It doesn't work correctly.
2025-08-13 7:54 PM
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
2025-08-13 7:58 PM
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.
2025-08-13 8:06 PM
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