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


Problems with Nucleo-F303RE

Hello, I am using STM32 Workbench Version: 1.13.2.201703061529 with Nucleo_F303RE board (featuring the microcontroller STM32F303RET6).
I work under Windows 7.

I am trying to use the microcontroller Timers and TIM3 in particular. The code I developed initialize TIM3 to generate an interrupt every 1sec and write a string to USART2. The Timer is initially disabled and is enabled when a character on the USART is received. The code for the TIM3 initialization and interrup handler is the following. USART works correctly since I tried without timer. As soon as TIM3 (and the attached interrupt) is enabled the microprocessor hangs and is no more able to receive input from USART. A strange thing is that in the NVIC.IRQChannel field I must insert 29 and not TIM3_IRQn (is not recognized and gives an error) even if the file stm32f30x.h is included at the beginning of main.c

void Initialize_Timer(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

TIM_TimeBaseInitTypeDef timerInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

timerInitStructure.TIM_Prescaler = 35999;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = 1999;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3, &timerInitStructure);

TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE);

TIM_Cmd(TIM3, DISABLE);

NVIC_InitStructure.NVIC_IRQChannel = 29;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
USART_write_string(“TIM UPDATE”, 1);
}
}

I tried to switch to HAL libraries but also in this case I can not make timer works.
It seems that htim3 can not be resolved. But other types like hdac1 and huart2 are recognized.

Can anyone help? I have absolutely no idea how to proceed.
Following is the TIM3 initialization function

static void MX_TIM3_Init(void)
{

TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_OC_InitTypeDef sConfigOC;

__HAL_RCC_TIM3_CLK_ENABLE();

htim3.Instance = TIM3;
htim3.Init.Prescaler = 0;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 0;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
{
Error_Handler();
}

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}

if (HAL_TIM_OC_Init(&htim3) != HAL_OK)
{
Error_Handler();
}

sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}

sConfigOC.OCMode = TIM_OCMODE_TIMING;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_OC_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}

}

Hi marco73it,

your timer period is set to 0:

htim3.Init.Period = 0;

Setting the timer period to 0 the timer will not work.

BR
Michael


About not finding TIM3_IRQn, have you double checked the symbols? When using the F303RE you should have STM32F303xE defined. I tried to build a TIM example from the StdPeriph and it worked well. As for the mcu hanging problem, I cannot test since I don’t have the board.

I do not understand what you mean with “should have STM32F303xE defined”.
Do you mean that I should put a

  1. define STM32F303xE xxxxxxxx


in the code and, in this case, what is the value to assign to STM32F303xE?
Where the assignement should be made? In main.c?

Check your project settings, when I created the project in OpenSTM32 it set all the defines for me. I added a picture of how it looks for me. If you check stm32f30x.h you will see that the STM32F303xE define is used.

Properties


 

Newest Forum Posts

  1. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  2. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  3. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  4. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  5. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  6. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  8. Build a project in "release" mode by tang, 2025-02-20 10:36
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35
  10. Fail to debug in Win 11 C/C++ by mortenlund, 2024-12-26 20:27

Last-Modified Blogs