Skip to content

Loading…

Fix for issue #466 and #467 (they're duplicates). We were not clearing t... #468

Merged
merged 1 commit into from

1 participant

@EmbeddedMan
chipKIT32 member

...he USB interrupt flag before enabling the interrupt.

Also added LENGTHOF macro, and tried compiling with asserts turned on (SODEBUG) and something dies. Still need to debug that. But this code change now allows USB serial to work again.

@EmbeddedMan EmbeddedMan Fix for issue #466 and #467 (they're duplicates). We were not clearin…
…g the USB interrupt flag before enabling the interrupt.

Also added LENGTHOF macro, and tried compiling with asserts turned on (SODEBUG) and something dies. Still need to debug that. But this code change now allows USB serial to work again.
ae53ffd
@EmbeddedMan EmbeddedMan merged commit 128e4fc into chipKIT32:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 30, 2014
  1. @EmbeddedMan

    Fix for issue #466 and #467 (they're duplicates). We were not clearin…

    EmbeddedMan committed
    …g the USB interrupt flag before enabling the interrupt.
    
    Also added LENGTHOF macro, and tried compiling with asserts turned on (SODEBUG) and something dies. Still need to debug that. But this code change now allows USB serial to work again.
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 18 deletions.
  1. +15 −16 hardware/pic32/cores/pic32/HardwareSerial_usb.c
  2. +2 −2 hardware/pic32/cores/pic32/System_Defs.h
View
31 hardware/pic32/cores/pic32/HardwareSerial_usb.c
@@ -33,8 +33,9 @@
#include "HardwareSerial_usb.h"
#include "HardwareSerial_cdcacm.h"
+#include "System_Defs.h"
-void __attribute__((interrupt(),nomips16)) IntUSB1Handler(void);
+void __attribute__((vector(_USB_1_VECTOR), interrupt(_USB_IPL_ISR), nomips16)) IntUSB1Handler(void);
// XXX -- move to relocated compat.h
#define MCF_USB_OTG_CTL U1CON
@@ -87,6 +88,7 @@ void __attribute__((interrupt(),nomips16)) IntUSB1Handler(void);
#define PA_TO_KVA0(pa) ((pa) | 0x80000000) // cachable
#define PA_TO_KVA1(pa) ((pa) | 0xa0000000)
*/
+#define LENGTHOF(x) ( sizeof(x)/sizeof(x[0]) )
#define HWRETRIES 1
#define SWRETRIES 3
@@ -328,13 +330,17 @@ static byte next_address; // set after successful status
// called by usb on device attach
//************************************************************************
#ifdef _USE_USB_IRQ_
- void __attribute__((interrupt(),nomips16)) IntUSB1Handler(void)
+ void __attribute__((vector(_USB_1_VECTOR), interrupt(_USB_IPL_ISR),nomips16)) IntUSB1Handler(void)
#else
void usb_isr(void)
#endif
{
int rv __attribute__((aligned));
+#ifdef _USE_USB_IRQ_
+ IFS1bits.USBIF = 0;
+#endif
+
if (! bdts)
{
return; // XXX
@@ -342,16 +348,7 @@ static byte next_address; // set after successful status
assert(! usb_in_isr);
assert((usb_in_isr = true) ? true : true);
- assert((usb_in_ticks = ticks) ? true : true);
-#ifdef _USE_USB_IRQ_
-#if defined(__PIC32MX2XX__)
- /// TODO: Plib replacement function should go here
- IFS1CLR = 0x00000008; // USBIF
-#else
- IFS1CLR = 0x02000000; // USBIF
-#endif
-#endif
// *** device ***
// if we just transferred a token...
@@ -762,6 +759,7 @@ void usb_initialize(void)
bdts = (struct bdt *)bdt_ram;
assert(BDT_RAM_SIZE >= LENGTHOF(endpoints)*4*sizeof(struct bdt));
+ assert(NULL == bdts);
// power on
U1PWRCbits.USBPWR = 1;
@@ -769,14 +767,15 @@ void usb_initialize(void)
// enable int
#ifdef _USE_USB_IRQ_
#if defined(__PIC32MX2XX__)
- /// TODO: Plib replacement function should go here
- IEC1bits.USBIE = 1;
- IPC7bits.USBIP = 6;
IPC7bits.USBIS = 0;
-#else
+ IPC7bits.USBIP = _USB_IPL_IPC;
+ IFS1bits.USBIF = 0;
IEC1bits.USBIE = 1;
- IPC11bits.USBIP = 6;
+#else
IPC11bits.USBIS = 0;
+ IPC11bits.USBIP = _USB_IPL_IPC;
+ IFS1bits.USBIF = 0;
+ IEC1bits.USBIE = 1;
#endif
#endif
View
4 hardware/pic32/cores/pic32/System_Defs.h
@@ -528,8 +528,8 @@
/* USB Interrupt
*/
-#define _USB_IPL_ISR ipl2
-#define _USB_IPL_IPC 2
+#define _USB_IPL_ISR ipl6
+#define _USB_IPL_IPC 6
#define _USB_SPL_IPC 0
/* CAN Interrupts
Something went wrong with that request. Please try again.