2024-08-21 04:38 PM - last edited on 2024-08-22 07:25 AM by SofLit
Hi
Testing CubeMX 6.12.0 and found a bug. This may exist in other editions.
The code generator improperly places the user code comments in the final while(1) loop. This causes MX (and its integration into IDE) to delete all user code. While testing in IDE, the correct comments will prevent the code from getting deleted. Please see a snip from CubeMX code generator below:
========THIS IS WHAT CUBEMX 6.12.0 GENERATES =========
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
===========THIS IS WHAT IT *should* GENERATE ========
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
}
/* USER CODE END WHILE */
==================
Can you please address this ASAP? Thank you!
Solved! Go to Solution.
2024-08-21 04:59 PM
I don't think there's a bug here. Code within USER CODE blocks is not touched. It makes no sense to allow USER CODE blocks to be nested.
What code did you write that it deleted that you think it should not have? Lots of places to write code inside and outside of the main loop:
/* USER CODE BEGIN WHILE */
// code here is not deleted
while (1)
{
// code here is not deleted
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// code here is not deleted
}
/* USER CODE END 3 */
L
2024-08-21 04:59 PM
I don't think there's a bug here. Code within USER CODE blocks is not touched. It makes no sense to allow USER CODE blocks to be nested.
What code did you write that it deleted that you think it should not have? Lots of places to write code inside and outside of the main loop:
/* USER CODE BEGIN WHILE */
// code here is not deleted
while (1)
{
// code here is not deleted
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// code here is not deleted
}
/* USER CODE END 3 */
L
2024-08-21 08:29 PM
@TDK is absolutely right here: The USER CODE ... WHILE block gives you a chance to add some initialization before the loop, the USER CODE ...3 block gives a chance to increment loop counters... etc at the end.
Indeed, I have seen generated code for periodic housekeeping inbetween both user code blocks, like when X-CUBE-BLE1 middleware is added:
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
MX_BlueNRG_MS_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
hth
KnarfB
2024-08-22 07:11 AM
Ahhh, I see your point. I was focused on "inside the braces" which worked only when I did my change but you are right there would be no point to nest...I see the "END WHILE" occurring *after* the closing brace so that's what threw me off.