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


SW4STM32 doesn't move to main loop

Hello!

I am very new to STM32 programming but finally got to manage my first LED toggling project according to the UM1718 user manual for CubeMX tutorial 1 .
What I do’t understand is the fact, that when I break the programflow, the programm doesn’t move to the main while loop but stays in the HAL_TIM_Base_Start_IT(&htim3); function. Why is that?

here is the code snippet:

int main(void)
{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration----------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_TIM3_Init();

/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim3);

don’t know why, but the post cuted some text away. Heres the complete main:

int main(void)
{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration----------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_TIM3_Init();

/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim3);

/* USER CODE END 2 */
uint32_t i = 0;
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
i++;

/* USER CODE BEGIN 3 */

}
/* USER CODE END 3 */

}


OK found the problem!
It was due to a compiler optimization, that the empty or even used (with a never used again variable) while loop was ommited. Without optimizatin everything works fine!


Another way you can force the inclusion of the infinite while() loop (with optimization on) would be to declare the i variable volatile, like this:

volatile uint32_t i;
while (1)
{
i++;
}

Doing this is also useful when you want to create a software delay and don’t care about accuracy, like this:

volatile uint32_t i;
for (i = 100000; i > 0; i--) ;

As for use of compiler optimization, I normally set the optimization level to “optimize for debug (-Og)” for the debug build of my projects, and use higher level optimization, normally “optimize for size (-Os)” for the release build.


 

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