cancel
Showing results for 
Search instead for 
Did you mean: 

Timer Interrupt frequency influenced by WFE

profclonk
Associate II
Posted on October 29, 2012 at 02:03

Dear readers,

the attached program for the STM32F407VGT6 (on the STM32F4 Discovery) should generate an interrupt every 500ms. The ISR toggles GPIO pin D14, which lets the LED (red) connected to it blink with 1Hz. The infinite loop in the main() function should also toggle D12 very fast, but the LED (green) connected to it stays dark.

When removing line 60 (the __WFE instruction), the frequency on D14 drops to 1/4 Hz, and the LED on D12 is dimly lit, as expected with this simple form of 50% PWM.

Why does D12 stay low when using WFE, and why does the frequency on D14 change when not using WFE?

I am using the

https://launchpad.net/gcc-arm-embedded

toolchain, the linker script and startup code from the ST examples for the Atollic Studio IDE, CMSIS and the STM32F4xx Standard Peripherals Library V1.0.2.

Thank you very much in advance!
2 REPLIES 2
Posted on October 29, 2012 at 02:21

Why wouldn't you use WFI, that would be more appropriate?

The Cortex-M3 supposedly has some WFE issue related to interrupt latency.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Event Register workaround for M3&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=26

I'll take a look at the code on the F4 under Keil in the next day or too.

I would definitely not clear the interrupt as the last thing before exiting, as this has known re-entrant issues. Clear it first, then toggle the GPIO, or frankly use the timers in PWM or Toggle mode.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
profclonk
Associate II
Posted on October 29, 2012 at 14:32

Oops, i thought WFE would return whenever WFI returns or a fault occurs... got it wrong, apparantly. Replacing it by WFI results in both LED's blinking synchroneously, as expected.

When omitting WFI/WFE completely and modifying the ISR to

        TIM_ClearITPendingBit (TIMEOUT_TIM, TIM_IT_Update);

        GPIOD->ODR ^= (1 << 14);

the frequency of D14 is 1Hz, and the LED on D12 is dimly lit (this is just to verify the main loop runs), just as expected. Is there some documentation about when the UIF flag has to be cleared to ensure correct operation? Is this required for all timers, and only for timers?

The LED blinking is just for verifying the timer's operation, i will later replace the GPIO toggling by some other operations i want the controller to perform in a regular interval, this is why i don't use hardware PWM.

Ah, testing it in Keil for me would be nice.