timerinterruptstm32f0cubemx

STM32F0 TIMx prescale settings has no effect on update interrupt


I generated my code from STM32CubeMx and wanted to generate a update event every 1µs. I work with the internal clock at 48MHz, which should be with Prescaler:0 and Autoreload:47 result to 1µs. I use a STM32F030 with TrueStudio V.9.0.0

generated code

/* TIM17 init function */
static void MX_TIM17_Init(void)
{

  LL_TIM_InitTypeDef TIM_InitStruct;

  /* Peripheral clock enable */
  LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM17);

  /* TIM17 interrupt Init */
  NVIC_SetPriority(TIM17_IRQn, 3);
  NVIC_EnableIRQ(TIM17_IRQn);

  TIM_InitStruct.Prescaler = 0;
  TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  TIM_InitStruct.Autoreload = 47;
  TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  TIM_InitStruct.RepetitionCounter = 0;
  LL_TIM_Init(TIM17, &TIM_InitStruct);

  LL_TIM_EnableARRPreload(TIM17);

}

I added in my init:

LL_TIM_EnableIT_UPDATE(TIM17);
LL_TIM_EnableCounter(TIM17);

In the IRQ_Handler i toggle a PIN:

void TIM17_IRQHandler(void)
{
  /* USER CODE BEGIN TIM17_IRQn 0 */
    LL_GPIO_TogglePin(LED_D2_2_GPIO_Port,LED_D2_2_Pin);

  /* USER CODE END TIM17_IRQn 0 */
  /* USER CODE BEGIN TIM17_IRQn 1 */

  /* USER CODE END TIM17_IRQn 1 */
}

After flashing my device with the code it generates a Signal with Frequency 889kHz with Pulsewidth of 564ns measured with Oscilloscope. Changes on Prescaler or Autoreload does not affect this output, it stays right away at T_Pulse=564ns or F=889kHz. Any idea what I am missing here?

Register output from debugging:

CR1:0x81           CR2:0
DIER:0x01          SR:0x03
CCMR1_O/I:0        CCER:0
PSC:0              ARR:0x2f
RCR:0              CCR1:0
BDTR:0             DCR:0    
DMAR:0x81

Solution

  • The solution was the clearance of the FLAG UIE in TIM17->SR in the IRQ_Handler. I was stuck permanently in the IRQ routine.