From f20c932bb9cc8f04968afef68b05f3f32f1b5dc3 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 9 Sep 2020 16:34:29 +0200 Subject: [PATCH] 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. --- src/machine/usb_nrf52840.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/machine/usb_nrf52840.go b/src/machine/usb_nrf52840.go index c8375619..e5132335 100644 --- a/src/machine/usb_nrf52840.go +++ b/src/machine/usb_nrf52840.go @@ -87,9 +87,12 @@ func exitCriticalSection() { // Configure the USB CDC interface. The config is here for compatibility with the UART interface. func (usbcdc *USBCDC) Configure(config UARTConfig) { - // enable IRQ + // Enable IRQ. Make sure this is higher than the SWI2 interrupt handler so + // that it is possible to print to the console from a BLE interrupt. You + // shouldn't generally do that but it is useful for debugging and panic + // logging. usbcdc.interrupt = interrupt.New(nrf.IRQ_USBD, USB.handleInterrupt) - usbcdc.interrupt.SetPriority(0xD0) + usbcdc.interrupt.SetPriority(0x40) // interrupt priority 2 (lower number means more important) usbcdc.interrupt.Enable() // enable USB