Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


Disassembly looks funny and doesn't correspond with C code

Edit: Sorry, forgot details.
STM32F042G6
Debugging using ST-LINK V2
Versions (now upgraded):
Ac6 C/C++ Debugging Tools for MCU v.1.11.2 (was v1.80.)
Ac6 C/C++ Embedded Development Tools for MCU v.1.12.0 (was v.1.8.0)
Ac6 Linker Script Editor v.1.11.0 (was v.1.7.0)
GNU Tools ARM Embedded (for windows 32bits) v.1.7.0
Open OCD (for windows 32 bits) v.1.8.0


I’m having issues when debuging, because alltough my project compiles fine and I can load it on the mcu, when I start debugging I notice in the disassembly it looks funny and does not correspond with the C code.

For example it has more than one occurance of code for line 103 and 104:

103 adc_val = HAL_ADC_GetValue(&hadc);
08002e98: movs r0, r7
08002e9a: bl 0x80006f8
08002e9e: ldr r4, pc, #76  ; (0x8002eec )
104 HAL_GPIO_TogglePin(GPIOB, LED_Pin);
08002ea0: movs r1, #1
103 adc_val = HAL_ADC_GetValue(&hadc);
08002ea2: str r0, r4, #0
104 HAL_GPIO_TogglePin(GPIOB, LED_Pin);
08002ea4: ldr r0, pc, #52  ; (0x8002edc )
08002ea6: bl 0x8000d10

C code
while (1)
  {
  /* USER CODE END WHILE */
	  uint16_t rawValue;
	  float temp;
	  adc_val = HAL_ADC_GetValue(&hadc);
	  HAL_GPIO_TogglePin(GPIOB, LED_Pin);
	  HAL_Delay(500);
  /* USER CODE BEGIN 3 */


	  HAL_ADC_PollForConversion(&hadc_temp, HAL_MAX_DELAY);
	  HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY);
	  rawValue = HAL_ADC_GetValue(&hadc_temp);
	  adc_val = HAL_ADC_GetValue(&hadc);
	  temp = ((float)rawValue) / 4095 * 3300;
	  temp = ((temp - 760.0) / 2.5) + 25;
  }
  /* USER CODE END 3 */

}


When I try to step past what is line 16 here
adc_val = HAL_ADC_GetValue(&hadc);
it jumps back to start of while loop again. It is also true that there is no reference to the code
temp = ((float)rawValue) / 4095 * 3300;
temp = ((temp - 760.0) / 2.5) + 25;
in the disassembly.

I suspect the dissasembly may be from an earlier version of the code where the adc part was not added yet. But it seems to compile fine and generates new output files if I clean the code and rebuild the whole project.

Any insight? Appreciate it, Thanks.

Edit: If I change the delay value the LED blinks faster so the code compiles and is loaded, nothing old about it.

Sorry for the late reply - I tried to respond yesterday but ran into multiple, severe networking issues.

Check your project’s optimization level:

Properties -> C/C++ Build -> Settings -> Tool Settings -> MCU GCC Compiler -> Optimzation -> Optimization Level.

You want “None (-O0)” or “Optimize for Debug (-Og)”.

Your “missing code” has been optimized out by the compiler. It did not see any subsequent reference to the calculated values, so it omitted the calculations themselves.

Add the “volatile” keyword to your variable declaration to force the compiler to not make assumptions about your variable usage.

More information about optimization levels in GCC:

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.htmlQuestion

I hope this helps.

I originally wrote a slightly longer and more methodical response to your question, but the web site decided I was no longer logged in and “optimized” it away :-D


Dale


Thank you so much Dale, this seems to have solved my issue!
If you ever feel like adding the extension that was part of what you initially wrote, feel free to do so ;) I alway press CTRL+A CTRL+C before pressing “Post”.Been burned like you before.

I also had a few extra issues but I figured it out after a while and I forgot to answer you. Thanks again.


 

Newest Forum Posts

  1. Монтаж камина с грилем в Москве - установка и барбекю by KpddomErorb, 2025-05-10 18:28
  2. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  9. Build a project in "release" mode by tang, 2025-02-20 10:36
  10. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35

Last-Modified Blogs