How can I increase the callback priority/importance on my Timer? (STM32F401)

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
nmz787
Posts: 29
Joined: Sun Jul 10, 2016 7:57 am

Re: How can I increase the callback priority/importance on my Timer? (STM32F401)

Post by nmz787 » Wed Mar 22, 2017 8:35 am

dhylands wrote:I modified nvic.py to add the nvic_set_prio function.

The dump_nvic routine doesn't print 0 entries, so any entry that doesn't show up can be assumed to be zero. You can see that the SysTick_IRQn (-1) now has a priority of 1, and TIM1_UP_TIM10_IRQn (25) doesn't show up any more which means it has a priority of zero.
Thanks! I wouldn't have thought to proceed trying to edit the System IRQs if you hadn't done that :)

After setting IRQ -1 to 1, I indeed see it with dump_nvic()

nmz787
Posts: 29
Joined: Sun Jul 10, 2016 7:57 am

Re: How can I increase the callback priority/importance on my Timer? (STM32F401)

Post by nmz787 » Wed Mar 22, 2017 8:49 am

dhylands wrote:
nmz787 wrote:another odd issue with that code, is that the board locks up if I try to set the default period to something small, like 100

This is odd especially because if I start the board with higher period and width settings, then adjust things later, with the adjust_tim1 function, it works to decrease things, but then you see the variation between UEV and the interrupt-function.
Have you tried hooking up a logic analyzer and seeing how long your interrupt routine takes?
Well, I've been using a 4-channel 250MHz scope, so I think I should have reasonable resolution. Pics attached
If the time between back-to-back firings of the timer IRQ is less than the time that the IRQ takes to run, then your code will be running the timer IRQ for 100% of the time and will never run the foreground app.
The interrupt should only fire once within a few seconds of time (however fast I can hit UP then ENTER on the REPL)... so I don't think how long it takes should matter, also it is only doing two stm.mem instructions, and I have the @micropython.native decorator.

Here is the function:
https://github.com/nmz787/culture_shock ... own.py#L35
Attachments
100_microsec_per_is_ok.png
this shows the period set to ~100, and performance of IRQ is acceptable
100_microsec_per_is_ok.png (43.85 KiB) Viewed 1290 times
12_usec_per__about_33_microsec_delay.png
when period is ~12 usec, IRQ shows obvious delay of about 33 microseconds until it takes effect
12_usec_per__about_33_microsec_delay.png (48.38 KiB) Viewed 1290 times
12_microsec_period.png
12 microsecond period zoomed out, for overall view of a single TIM1 'n-pulse mode' pulse-train. TIM1 is on the bottom, with TIM2 in the middle, and TIM5 up top
12_microsec_period.png (51.42 KiB) Viewed 1290 times

User avatar
dhylands
Posts: 3415
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: How can I increase the callback priority/importance on my Timer? (STM32F401)

Post by dhylands » Wed Mar 22, 2017 4:37 pm

I did some analysis of how long it takes for timer IRQs to be processed a while back:
http://forum.micropython.org/viewtopic. ... t=10#p4781

What you really need is to toggle a GPIO at the beginning of the ISR and at the end so that you can see how long the ISR is actually taking.

It doesn't take much python to get 12 usec worth of code.

The interrupt priority will only be of any significance when 2 interrupts are running at the same time.

If you're trying to modify the period on the fly, then you probably need to read the datasheet about the exact behaviour. There is a shadow register for TIMx_ARR and the timer uses the shadow register. TIMx_ARR is only transferred to the shadow register at very particular times.

Post Reply