Skip to content

Commit f20c932

Browse files
aykevldeadprogram
authored andcommitted
nrf52840: use higher priority for USB-CDC code
This ensures that stdout (println etc) keeps working in interrupts. Generally you shouldn't print anything in an interrupt. However, printing things for debugging is very useful and printing panic messages can be critical when the code doesn't work for some reason.
1 parent e7227df commit f20c932

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/machine/usb_nrf52840.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ func exitCriticalSection() {
8787

8888
// Configure the USB CDC interface. The config is here for compatibility with the UART interface.
8989
func (usbcdc *USBCDC) Configure(config UARTConfig) {
90-
// enable IRQ
90+
// Enable IRQ. Make sure this is higher than the SWI2 interrupt handler so
91+
// that it is possible to print to the console from a BLE interrupt. You
92+
// shouldn't generally do that but it is useful for debugging and panic
93+
// logging.
9194
usbcdc.interrupt = interrupt.New(nrf.IRQ_USBD, USB.handleInterrupt)
92-
usbcdc.interrupt.SetPriority(0xD0)
95+
usbcdc.interrupt.SetPriority(0x40) // interrupt priority 2 (lower number means more important)
9396
usbcdc.interrupt.Enable()
9497

9598
// enable USB

0 commit comments

Comments
 (0)