STM32F301K8U6-HardwareTimer interrupt does not work

Post here first, or if you can't find a relevant section!
Post Reply
AkPat
Posts: 2
Joined: Sat Feb 18, 2023 10:48 am

STM32F301K8U6-HardwareTimer interrupt does not work

Post by AkPat »

Hello All,

I need your support in solving the following issue:
For my project I use the STM32F301K8U6 chip. In the application I need 0,1s timing, therefore I decided to use the HardwareTimer library.
To check the HW, I uploaded the simplest provided HarwareTimer example, that blinks an LED on pin PA3:

Code: Select all

#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION  < 0x01090000)
#error "Due to API change, this sketch is compatible with STM32_CORE_VERSION  >= 0x01090000"
#endif

#if defined(LED_BUILTIN)
#define pin  LED_BUILTIN
#else
#define pin  PA3
#endif

void Update_IT_callback(void)
{ // Toggle pin. 10hz toogle --> 5Hz PWM
  digitalWrite(pin, !digitalRead(pin));
}


void setup()
{
#if defined(TIM1)
  TIM_TypeDef *Instance = TIM1;
#else
  TIM_TypeDef *Instance = TIM2;
#endif

  // Instantiate HardwareTimer object. Thanks to 'new' instanciation, HardwareTimer is not destructed when setup() function is finished.
  HardwareTimer *MyTim = new HardwareTimer(Instance);

  // configure pin in output mode
  pinMode(pin, OUTPUT);

  MyTim->setOverflow(10, HERTZ_FORMAT); // 10 Hz
  MyTim->attachInterrupt(Update_IT_callback);
  MyTim->resume();
}


void loop()
{
  /* Nothing to do all is done by hardware. Even no interrupt required. */
}
The LED does not blink. I have checked the LED by uploading the "Blink" sketch and it is working as it should.
Anybody has an idea what can be the reason for it?
Any hint on what I should check?
Thanks in advance.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: STM32F301K8U6-HardwareTimer interrupt does not work

Post by GonzoG »

I this example, if your board has LED_BUILTIN defined for a different pin than PA3, it won't work for PA3.
AkPat
Posts: 2
Joined: Sat Feb 18, 2023 10:48 am

Re: STM32F301K8U6-HardwareTimer interrupt does not work

Post by AkPat »

Thanks for Your hint.
I totally overlooked it :shock:
I 've corrected it and it is working now. :)
Post Reply

Return to “General discussion”