From 9ceb7ca646a8a0b8ae7885a93ee2ad7f89cd88c6 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Tue, 28 Mar 2017 16:13:02 +0100 Subject: usb: Extra debug / error handling. --- usb/usb.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'usb') diff --git a/usb/usb.c b/usb/usb.c index c37fc5f..977e7a5 100644 --- a/usb/usb.c +++ b/usb/usb.c @@ -41,7 +41,8 @@ void usb_setup(void) /* Initial Configuration */ SET_MASKED(USB0_USBCTRL, BV(USBCTRL_SUSP) | BV(USBCTRL_PDE), 0); SET_BIT(USB0_CONTROL, CONTROL_DPPULLUPNONOTG); - SET_BIT(USB0_INTEN, INTEN_USBRSTEN); + USB0_INTEN = BV(INTEN_STALLEN) | BV(INTEN_RESUMEEN) | + BV(INTEN_SLEEPEN) | BV(INTEN_ERROREN) | BV(INTEN_USBRSTEN); /* NVIC Enable interrupt */ ISR_CLRPEND(73); @@ -81,13 +82,34 @@ void usb_isr(void) { uint8_t stat = USB0_ISTAT; - if (IS_BIT_SET(stat, ISTAT_TOKDNE)) { - uart_puts("tokdne"); + if (GET_BIT(stat, ISTAT_STALL)) { + uart_puts("INT: stall"); + USB0_ISTAT = BV(ISTAT_STALL); + } + if (GET_BIT(stat, ISTAT_RESUME)) { + uart_puts("INT: resume"); + USB0_ISTAT = BV(ISTAT_RESUME); + } + if (GET_BIT(stat, ISTAT_SLEEP)) { + uart_puts("INT: sleep"); + USB0_ISTAT = BV(ISTAT_SLEEP); + } + if (GET_BIT(stat, ISTAT_TOKDNE)) { + uart_puts("INT: tokdne"); i_tokdne(); USB0_ISTAT = BV(ISTAT_TOKDNE); } - if (IS_BIT_SET(stat, ISTAT_USBRST)) { - uart_puts("usbrst"); + if (GET_BIT(stat, ISTAT_SOFTOK)) { + /*uart_puts("INT: softok");*/ + USB0_ISTAT = BV(ISTAT_SOFTOK); + } + if (GET_BIT(stat, ISTAT_ERROR)) { + uart_printf("INT: error (0x%x)\n", (unsigned)USB0_ERRSTAT); + USB0_ERRSTAT = USB0_ERRSTAT; + USB0_ISTAT = BV(ISTAT_ERROR); + } + if (GET_BIT(stat, ISTAT_USBRST)) { + uart_puts("INT: usbrst"); i_usbrst(); USB0_ISTAT = BV(ISTAT_USBRST); } -- cgit v1.2.3-54-g00ecf