im a long way from an expert but printf is a big beast of a function with its own peripheral controls and timings - you cant use it for this kind of thing. if i wanted to test the granularity of various timers, id do a simple pin toggle and measure those with either a scope, or the frequency counter on a multi meter. Answer from Deleted User on reddit.com
🌐
STMicroelectronics Community
community.st.com › t5 › stm32cubeide-mcus › timer-interrupt-not-working › td-p › 717391
Timer interrupt not working - STMicroelectronics Community
September 6, 2024 - Maybe you started the timer without period interrupt enabled. Use the debugger to check it. 3. If it is called, use the debugger to check the values written to CCRx registers. My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
🌐
Reddit
reddit.com › r/stm32 › how to use stm32 timers in interrupt mode?
r/stm32 on Reddit: How to use STM32 timers in interrupt mode?
April 22, 2022 -

I have the following code:

#include "stm32f407xx.h" 
#define TIM2_IRQNO 28  

void TIM2_IRQHandler(void) {     
    printf("tick\n"); 
}  

int main() {
    TIM_PeriClockControl(TIM2, ENABLE);	        //enable system clock on timer

    TIM2->PSC = 168;                            //set prescaler
    TIM2->ARR = 1000;                           //set frequency to 1kHz

    TIM2->CR1 |= (1 << TIM_CR1_URS);            //update enable (after overflow)
    TIM2->EGR |= (1 << 0);                      //update generation
    TIM2->DIER |= (1 << 0);                     //update interrupt enabled

    TIM2->CR1 |= 1 << TIM_CR1_CEN;              //enable timer

    uint32_t *pISER1 = (uint32_t *)0xE000E100;  //NVIC_ISER base addr (or ..104?)
    *pISER1 |= ( 1 << (TIM2_IRQNO % 32) );      //enable NVIC for TIM2

    for(;;);                                    //main loop
}

I have an STM32F407VG microcontroller. It features a 168MHz clock. Whith the prescaler I bring down it's speed to 1MHz on the peripherals and I further decrease the timers speed to 1kHz with the help of the ARR Auto Reload register.

Not sure about EGR and DIER registers, but have seen others use them in their implementations.

After enabling the timer I try to enable the interrupt on the timer using the base address of the ISER register of the NVIC. It should probably end in 104, not 100, but with 104 I managed to print nothing, while using 100 I could print the "tick" text, but uncontrollably fast.

What I would expect form this code is to call the TIM2_IRQHandler after every millisecond (1 tick of the timer with the given PSC and ARR configuration). What am I doing wrong?

🌐
Reddit
reddit.com › r/embedded › stm32l4 timer interrupt trouble.... always fires after ~5us regardless of params
r/embedded on Reddit: STM32L4 timer interrupt trouble.... always fires after ~5us regardless of params
December 8, 2022 -

OK... I have an STM32L452 MCU running at 80MHz

I have a UART4 RX interrupt that is working. That ISR sets a pin high, and kick off a timer3 interrupt after 500 us.

The HAL generated code for setting up TIM3 is

static void MX_TIM3_Init(void)
{
  /* USER CODE BEGIN TIM3_Init 0 */
  /* USER CODE END TIM3_Init 0 */

  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};

  /* USER CODE BEGIN TIM3_Init 1 */
  /* USER CODE END TIM3_Init 1 */
  htim3.Instance = TIM3;
  htim3.Init.Prescaler = 79;
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim3.Init.Period = 499;
  htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  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();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM3_Init 2 */
  /* USER CODE END TIM3_Init 2 */
}

When the UART4 interrupt is triggered, I call

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
	if(huart->Instance==UART4){
		newMasterMessage = 1;
		HAL_GPIO_WritePin(UART4_DE_GPIO_Port, UART4_DE_Pin, GPIO_PIN_SET);	
		HAL_TIM_Base_Start_IT(&htim3);
	}
}

...the ISR for the timer3 interrupt just sets that pin low.

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  // Check which version of the timer triggered this callback and toggle LED
  if (htim == &htim3)
  {
	  HAL_GPIO_WritePin(UART4_DE_GPIO_Port, UART4_DE_Pin, GPIO_PIN_RESET);	
  }
}

My goal is to have the timer fire an interrupt after 500us. With an 80 MHz clock, I use a pre-scalar of 79, and counter of 499, which should do the trick.

However, the interrupt always fires after just ~5us, no matter what parameters I use. I have also tried using tim16, but it does the same thing. I feel like I'm missing something fundamental, but I don't know what.

Can anyone help?

🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › hi-i-m-trying-to-figure-out-why-my-basic-timer-interrupt-on-the › td-p › 215754
Hi, I'm trying to figure out why my basic timer interrupt on the STM32H7B3x dev board isn't working as expected. It seems to be triggering more often than I expect depending on when I clear the flag within the interrupt.
October 14, 2021 - That does not guarantee anything beyond the processor core, i.e. it ignores the resynchronizers on AHB/APB bridges (and in the overcomplicated 'H7 also the inter-matrix resynchronizers), write buffers on the AHB/APB bridges, the peripheral-to-NVIC delay/resynchronization, NVIC's internal delays, and whatnot. It may "work" but only coincidentally, simply as "any" delay. Qualifying the interrupt source works, as writes and reads to the same peripheral are never reordered (pending the peripheral area is tagged as Device in MPU, which it by default is).
🌐
STMicroelectronics Community
community.st.com › t5 › stm32cubeide-mcus › timer-interrupt-is-enabled-but-it-is-not-entering-the-interrupt › td-p › 82356
Timer interrupt is enabled but it is not entering ... - STMicroelectronics Community
April 5, 2022 - I'm working on STM32G030 in STM32CubeIDE without using the HAL( using Low layer). In that i have enable a timer interrupt using .ioc file (hardware file). When i put a break point in the interrupt handler which is in the stm32g0xx_it.h file, it is not entering the handler.I have also tried by giving...
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › stm32-l412-timer-interrupt-not-working › td-p › 106192
Solved: STM32 L412 Timer interrupt not working - STMicroelectronics Community
February 14, 2023 - Is the Timer 6 of STM32L412 has any additional configuration to made in order to work like this. This is what I get when I debug. ... This happens when the specific IRQ handler is not implemented. See the interrupt vector table in the startup code for the proper names.
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › problem-with-timer-interrupt-stm32f427vit6-tim14 › td-p › 166645
Problem with timer interrupt STM32F427Vit6 (TIM14) - STMicroelectronics Community
September 27, 2023 - Update typically occurs at the timer overflow, so the first timer period would not run according to the set prescaler · Cube and other "libraries" compensate for this by forcing the Update event by setting TIMx_EGR.UG · this causes Update event, which not only loads the prescaler value from the intermediate "holding" to "working" prescaler register, but also sets TIMx_SR.UIF as normal overflow-caused Update would · when you enable the Update interrupt, as TIMx_SR.UIF is already set, the interrupt is immediately executed
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 59165099 › stm32-timer-update-interrupt-not-working
STM32 - Timer Update Interrupt not working - Stack Overflow
Perhaps your software is too slow and 10kHz is the fastest it can process the interrupts ? Try with a larger counting period, like 1s or so ... Find the answer to your question by asking.
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › timer-interrupt-not-working-on-stm32f103c8 › td-p › 372511
Timer Interrupt not working on STM32F103C8 - STMicroelectronics Community
April 5, 2018 - Make sure all structures are properly initialized *before* enabling interrupts. If this isn't done there is significant potential for NULL pointers and incorrect values to cause the system to fault. Check the name of the handler matches the one in the startup_stm32f1xx.s, and that you aren't ...
🌐
DigiKey
digikey.com › en › maker › projects › getting-started-with-stm32-timers-and-timer-interrupts › d08e6493cefa486fb1e79c43c0b08cc6
Getting Started with STM32 - Timers and Timer Interrupts
The HAL libraries will manage the main interrupt service routine (ISR) when the timer interrupt occurs (feel free to examine it in stm32l4xx_it.c). At some point in that ISR, the code will call HAL_TIM_PeriodElapsedCallback(), which we need to provide a definition for. In that definition, we check to make sure that the timer handle (htim) is indeed our Timer 16 and then toggle the LED pin. Note that this is a generic timer interrupt callback.
🌐
Stack Overflow
stackoverflow.com › questions › 70602185 › stm32f103c8t6-timer-interrupt-not-working
embedded - stm32f103c8t6 timer interrupt not working - Stack Overflow
I am trying to use timer interrupts to assign outputs directly to one specific foot of the chip using stm32f103c8t6 bluepill. What I want to achieve is to toggle the LED (connected to PC13) on and off by interrupt functions. But the result turns out to be that the PC13 LED is always on which means the interrupt function not working.
🌐
Openstm32
openstm32.org › forumthread6674
OpenSTM32 Community Site | Timer Interrupt Not Working
#include "stm32f1xx_hal.h" TIM_HandleTypeDef htim2; TIM_HandleTypeDef htim4; void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_TIM2_Init(void); static void MX_TIM4_Init(void); int main(void) { HAL_Init(); /* Configure the system clock */ SystemClock_Config(); HAL_MspInit(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM2_Init(); MX_TIM4_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2); HAL_TIM_Base_Start_IT(&htim4); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); // controller doesn't reach here while (1) { /* USER CO
🌐
STMicroelectronics Community
community.st.com › t5 › stm32cubeide-mcus › timer-interrupts-are-not-working-in-stmcubeide › td-p › 286996
Solved: Timer interrupts are not working in STMCubeIDE - STMicroelectronics Community
March 17, 2020 - Hello all, I'm using STMCubeIDE to program an STM32F042K6-T6 development board. I'm attempting to set up an elapsed time interrupt, but it doesn't seem to be working. I am running my chip at 8MHz, and I want to try blinking an LED once a second using the HAL_TIM_PeriodElapsedCallback function.
🌐
Arduino Forum
forum.arduino.cc › other hardware › 3rd party boards
STM32 timer 2 interrupt handler does not work - 3rd Party Boards - Arduino Forum
March 14, 2024 - Hello, I try to initialize an interrupt vector for timer 2 that TIM2_IRQHandler is executed. I use a STM32F401CE controller. With the code below the handler TIM2_IRQHandler is never triggered. Does anybody have an idea which functions I have to execute further to actived a trigger for timer 2? #include #include "IWatchdog.h" /* Set TIMx instance */ TIM_HandleTypeDef Tim2Handle; /** * Blaue LED initialisieren */ void InitBlueLed() { __HAL_RCC_GPIOC_CLK_ENABLE();...
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › problem-with-timer-interrupt-works-in-first-place-but-not-later › td-p › 310030
problem with timer interrupt, works in first place but not later on in program
May 29, 2020 - I use STM32F4 on a self-created board (well, develeped by a collegue), atollic truestudio, the HAL libraries and systick option. (firmware was created by that colleague as well who has left our company). ... send a command via usb (working) to init my sensor system (working), then start the actual program/routine which includes: starting timer with approx 256hz, with every hit of the timer interrupt (ISR) sample data until I have 256 samples (all working), calculating fft (working), sending results out over usb (working), set a counter which decrements in systick function (working), when counter reaches "0" restart the timer (probably not working) and get next samples (NOT working).