Skip to content

Commit

Permalink
Fix for issue #466 and #467 (they're duplicates). We were not clearin…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
EmbeddedMan committed May 30, 2014
1 parent 4d066c1 commit ae53ffd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
31 changes: 15 additions & 16 deletions hardware/pic32/cores/pic32/HardwareSerial_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -328,30 +330,25 @@ 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
}

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...
Expand Down Expand Up @@ -762,21 +759,23 @@ 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;

// 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

Expand Down
4 changes: 2 additions & 2 deletions hardware/pic32/cores/pic32/System_Defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae53ffd

Please sign in to comment.