[Solved] Problem with Hardware Timer Examples

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
oakx
Posts: 2
Joined: Tue Mar 10, 2020 11:53 am

[Solved] Problem with Hardware Timer Examples

Post by oakx »

Hello everyone,

Now, I'm studying on how to use HardwareTimer Library as described in https://github.com/stm32duino/wiki/wiki ... er-library
I've tested the Timebase_callback.ino example, it's worked as expected.

However, when I tried to run the All-in-one_setPWM.ino or PWM_Fullconfiguration.ino, there was no output at both LED_BUILTIN pin (D13) and D3 pin (tested with oscilloscope)

The board I'm currently using is "Nucleo-F303K8"
I don't think that there should be any change in the code, or am I missing something?

Any help would be grateful
Thanks,
Last edited by oakx on Tue Mar 10, 2020 7:25 pm, edited 1 time in total.
ABOSTM
Posts: 60
Joined: Wed Jan 08, 2020 8:40 am
Answers: 7

Re: Problem with Hardware Timer Examples

Post by ABOSTM »

Hi @oakx ,
I just checked on my Nucleo-F303K8 and you are right it doesn't work out of the box:
Timebase_callback.ino doesn't associate a pin to HardwareTimer, so any instance is working.
But other examples like All-in-one_setPWM.ino need to associate a pin to and HardwareTimer.
For Nucleo-F303K8, the HardwareTimer capability for LED_BUILTIN (= D13 = PB3) has been commented out. So it can't work.

If you are familiar with stm32duino varaints, you can uncomment following line in ...\variants\NUCLEO_F303K8\PeripheralPins.c

Code: Select all

{PB_3,  TIM2,   STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2
Otherwise I suggest to change pin and test on D2:
replace

Code: Select all

#if defined(LED_BUILTIN)
#define pin  LED_BUILTIN
#else
#define pin  D2
#endif
by

Code: Select all

#define pin D2
oakx
Posts: 2
Joined: Tue Mar 10, 2020 11:53 am

Re: Problem with Hardware Timer Examples

Post by oakx »

@ABOSTM I managed to uncomment out that line in the file from
~/.arduino15/packages/STM32/hardware/stm32/1.8.0/variants/NUCLEO_F303K8/PeripheralPins.c

and it works like a charm

Thank you so much
Post Reply

Return to “General discussion”