The library of Timer1..Timer3 seems not to work in this board.
I have searched but I do not see any clear example.
Greetings and thank you
On the right side you have the modules (including Timers).
In that web the reference of those libraries I do not have them.
my board is an STMF303 – F303K8 And do not use these libraries
I’ve open a discussion around timer management here:
https://github.com/stm32duino/Arduino_C … issues/146
Does not support this micro.
The other two do not compile either.
Timer1 … 2 …
I have tried this example and it does not work either.
#define ANY_DELAY_RQUIRED 0x0FFF
TIM6->SR = 0
TIM6->ARR = ANY_DELAY_RQUIRED
TIM6->CR1 |= TIM_CR1_CEN
while (!(TIM6->SR & TIM_SR_UIF)); /* Loop until the update event flag is set */
/* The required time delay has been elapsed */
/* User code can be executed */
Compile without errors but it does not work
__HAL_RCC_TIM6_CLK_ENABLE
https://github.com/stm32duino/Arduino_C … rcc.h#L797
To use it I include in the project #include <Timer.h>.
I will try your option to see if it works.



TIM6-> SR = 0;
TIM6-> ARR = 250;
TIM6-> CR1 | = TIM_CR1_CEN;
while (! (TIM6-> SR & TIM_SR_UIF));
point A
Never go to point A
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; <———–new line
TIM6->SR = 0;
TIM6->ARR = 250;
TIM6->CR1 |= TIM_CR1_CEN;
while (!(TIM6->SR & TIM_SR_UIF));
point A
And with the new line, that tells you that the oscillator is internal,
goes to point A immediately without doing any kind of timing
take a look at the datasheet and it is not that difficult to work out a set of routines of your own, with direct register access.
if i get some time, i may write one myself.
The strange thing is that not even the code of st works.
tim3_init(100); //set prescaler to 100
tim3_setpr1(50000ul); //oc1 period to be 50000 ticks
tim3_act1(led12_flp); //install user handler
ei(); //enable global interrupts
it can be expanded to other chips as well. for more, see here: https://dannyelectronics.wordpress.com/ … ollection/
the basic code should run on other STM32 chips, with minimum re-configuration: mostly to change clock sourcing.
I have managed to prove it but interruptions do not trigger
in the SysTick_Handler, a fudge since there are a lot of timers
without using.
In the timer interrupts do not work.
I have tried with the timer 6, 7, 1,3 and it does not work.
For example the basic timer 6 counts correctly but
even if you set the active interrupt, it never triggers it.
Also if in any timer active this:
TIM6->DIER |= TIM_DIER_UIE;
1. Read the datasheet and see what you have to do there.
2. Flip a pin in the isr to help you understand what’s going on.
and the modes of configuration:
AN4013 Application note STM32 cross-series timer overview
AN4776 Application note General-purpose timer cookbook
I do not see the fault.
void tim6_init()
{
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; // Enable TIM6 clock
TIM6->PSC = 41999; // Set prescaler to 41999
TIM6->ARR = 5999; // Set auto-reload to 5999
TIM6->CR1 |= TIM_CR1_OPM; // One pulse mode
TIM6->EGR |= TIM_EGR_UG; // Force update
TIM6->SR &= ~TIM_SR_UIF; // Clear the update flag
TIM6->DIER |= TIM_DIER_UIE; // Enable interrupt on update event
NVIC_EnableIRQ(TIM6_DAC_IRQn); // Enable TIM6 IRQ
TIM6->CR1 |= TIM_CR1_CEN; // Enable TIM6 counter
}
void TIM6_DAC_IRQHandler()
{
if (TIM6->SR & TIM_SR_UIF != 0) // If update flag is set
{
TIM6->SR &= ~TIM_SR_UIF; // Interrupt has been handled
Serial.println(“INTERRUPT”);
}
}
the following:
IO_OUT(LED_PORT, LED12); //led as output
tim6_init(100); tim6_setpr(10000); tim6_act(led12_flp);
tim7_init(100); tim7_setpr(10000*1.01); tim7_act(led12_flp);
ei(); //enable global interrupts
Note that, if the IRQHandler is defined in a cpp file or the ino file, you have to declare the TIM6_DAC_IRQHandler as extern “C”
extern "C" void TIM6_DAC_IRQHandler()
Both in your example and in the previous one published by me.
The problem is that when you reach the end of the account, the micro is blocked and never enters the
interruption, it’s as if I was going to look for that interruption and I will not find it, and of course it hangs up.
This happens with the two examples with yours and mine
Any suggestions?
Core: nucleo STMF303 – F303K8
and that line where I put it, because I tested the start of the program:
extern “C” void TIM6_DAC_IRQHandler();
and I get an error.
core.a(timer.c.o)*: In function TIM6_DAC1_IRQHandler
timer.c*: (.text.TIM6_DAC1_IRQHandler+0x0): multiple definition of TIM6_DAC1_IRQHandler
interruption,
you haven’t (and couldn’t) establish that. if you try to establish that, you will find the problem with your code.
Any suggestions?
the same as I gave you earlier.
As already said, I have to review timer management, issue opened to track this review:
https://github.com/stm32duino/Arduino_C … issues/146
You issue is linked to this PR:
https://github.com/stm32duino/Arduino_C … 2/pull/150
Core already defined TIMx_IRQHandler while it should not.
Specifically this line:
https://github.com/stm32duino/Arduino_C … 54128R1119
WEAK void TIM6_IRQHandler(void)





Many many thanks, everyone.
Summarized for the one that happens to me and does not go crazy …
Change the timer.c file
All these void TIM…. for these WEAK void TIM…… and save.
When the interruption is defined in this way:
extern “C” {
void TIM6_DAC_IRQHandler ()
{
interruption code
}
}
And now
I almost died in this one.
thanks, thanks, thanks, everyone.