How to enable IRQs before exiting a program. #16757
Answered
by
GitHubsSilverBullet
davefes
asked this question in
STM32 / Pyboard
-
Trying to disable IRQs on a WeAct 8MB flash board. Appears that if IRQs are not enabled before exiting the program then bad things happen. I have read comments about USB comms getting messed-up if IRQs are not enabled. I tried catching a CTRL-C and re-enabling IRQs befor exiting, but could not get that to work. from machine import Pin
from stm import GPIOA, GPIO_BSRRL, GPIO_BSRRH
import machine
import time
@micropython.viper
def ir_pulse(gpio: ptr16, pin: int, on: int, off: int): # on=12 => 2.00 us on WeAct F411 (? MHz)
ptr_on = ptr16(uint(gpio) + uint(GPIO_BSRRL)) # on=0 => 0.167 us (PYB)
ptr_off = ptr16(uint(gpio) + uint(GPIO_BSRRH)) # --> 96.5 ns per on-loop (PYB)
bit = 1 << pin # (=16 clock cycles)
ptr_on[0] = bit
while(on > 0):
on -= 1
ptr_off[0] = bit
while(off > 0):
off -= 1
pa1 = Pin('A1', mode=Pin.OUT)
isr = machine.disable_irq()
while True:
try:
ir_pulse(GPIOA, 1, 12, 55, 10)
except KeyboardInterrupt as err:
machine.enable_irq(isr)
print('exiting properly')
time.sleep(1) I am guessing that as interrupts are disabled, then Ctrl-C is not going to work. How do I ensure interrupts get enabled before closing the program? |
Beta Was this translation helpful? Give feedback.
Answered by
GitHubsSilverBullet
Feb 15, 2025
Replies: 1 comment 2 replies
-
Why not disable and enable interrupts only within you time-sensitive function? |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
davefes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not disable and enable interrupts only within you time-sensitive function?