stm32f407 timer setup stm32duino
I think I solved that, but I had to mix some functions because for some reason I wasn't able to trigger the interrupt by setting TIM registers only

uint16_t returnPeriod(uint16_t prescaler, unsigned long time, uint8_t mhz) {
    return (time) / ((1000000 / mhz) * 0.00001) / prescaler;
}

const byte LedPin = PG7;

stimer_t timerx;

void setup() {

    pinMode(LedPin, OUTPUT);
    //digitalWrite(LedPin, HIGH);
    //NVIC_EnableIRQ(TIM5_IRQn); this is not working for some reason i have to use TimerHandleInit &amp;  attachIntHandle
    timerx.timer = TIM5;
    TimerHandleInit(&amp;timerx, 0, 0);
    TIM5-&gt;PSC = 10000;
    attachIntHandle(&amp;timerx, tim5TestInterrupt);

}


volatile bool enableFlag = false;
unsigned long time_now = 0, time_before = 0;

void loop() {
    time_before = time_now;
    time_now = micros();

    if (enableFlag == false) { //make sure we enable after timeout
        TIM5-&gt;ARR = returnPeriod(TIM5-&gt;PSC, 5000000, 84); //wait 0.5seconds
        TIM5-&gt;CNT = 0;
        TIM5-&gt;CR1 |= TIM_CR1_CEN;
    }

    while ((TIM5-&gt;CR1 &amp; TIM_CR1_CEN)) { // wait till timeout aka timer disabled

    }
    if(Serial){
        Serial.println(time_now-time_before); //it should print delay time + timeout time
    }
}

void tim5TestInterrupt(stimer_t* st32timer) {

    if (enableFlag == false) {
        enableFlag = true;
        digitalWrite(LedPin,HIGH);

        TIM5-&gt;ARR = returnPeriod(TIM5-&gt;PSC, 30000000, 84); //timeout after 3 seconds
        TIM5-&gt;CNT = 0;
    }
    else {
        enableFlag = false;
        digitalWrite(LedPin, LOW);

        TIM5-&gt;CR1 &amp;= ~TIM_CR1_CEN; //disable timer

    }
}