cancel
Showing results for 
Search instead for 
Did you mean: 

ISR memory update & Timer trigger

vbesson
Senior

Hello All, 

I am facing a strange situation

I have an ISR function1 that is triggered on Falling / Rising Edge of a GPIO pin 

This function1 according to the state of variable will either start TIMER2 and stop TIMER3 and the way around.

TIMER2 & 3 have also ISR. 

But before starting/stopping TIMER, it needs to update memory variable that will be used by TIMER ISR.

The issue is that the variable is effectively updated in memory after the start of TIMER and a few (100 CPU) cycles are needed to get the proper value.

This is time critical and I need the value of wrBitPos to be 0 and wrBitCounter to be set a the right value before the first timer iteration. 

How can I fix this ?

I use the volatile declaration for variable.

void function1(){
        TIM3->DIER &= ~TIM_DIER_CC4IE;   // disable CC4 interrupt
        TIM3->CCER &= ~TIM_CCER_CC4E;   // disable CC4 output
        TIM3->CR1 &= ~TIM_CR1_CEN;      // stop the timer

        wrBitPos=0;         
        bytePtr++;  // Reset the BitPos
        wrBitCounter=bytePtr*8;
                
        TIM2->DIER |= TIM_DIER_CC2IE;     // enable CC3 interrupt
        TIM2->CCER |= TIM_CCER_CC3E;     // enable CC3 output
        TIM2->CR1 |= TIM_CR1_CEN;        // start the 
    

 

Thanks

Vincent 

1 REPLY 1
TDK
Super User

You can use a data-sync barrier instruction to ensure data written is completed before the CPU moves on. Variables should be marked as volatile as well.

__DSB();

If you feel a post has answered your question, please click "Accept as Solution".