Skip to content

Commit

Permalink
Adding USB Error counter
Browse files Browse the repository at this point in the history
- Tracks number of USB errors on the bus
- Kinetis error tracking is more comprehensive
  * But currently all types of errors just increment the error counter
  * If there multiple errors in the same interrupt, it only counts as a
  single error
- SAM4S only tracks SOF (Start of Frame) EOP (End of Packet) CRC errors
  • Loading branch information
haata committed Jan 26, 2019
1 parent e94a656 commit b3768cc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
5 changes: 2 additions & 3 deletions Lib/ASF/config/conf_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@
* @{
*/
//#define UDC_VBUS_EVENT(b_vbus_high)
//#define UDC_SOF_EVENT() main_sof_action()
extern void usb_sof_event();
#define UDC_SOF_EVENT() usb_sof_event()
//! Mandatory when USB_DEVICE_ATTR authorizes remote wakeup feature
#define UDC_REMOTEWAKEUP_ENABLE()
#define UDC_REMOTEWAKEUP_DISABLE()
//! When a extra string descriptor must be supported
//! other than manufacturer, product and serial string
//@}

//@}
Expand Down
25 changes: 23 additions & 2 deletions Output/USB/arm/usb_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1762,8 +1762,14 @@ void usb_isr()
// set the address to zero during enumeration
USB0_ADDR = 0;

// enable other interrupts (except USB Resume)
USB0_ERREN = 0xFF;
// Enable other interrupts (except USB Resume)
USB0_ERREN = USB_ERREN_BTSERREN |
USB_ERREN_DMAERREN |
USB_ERREN_BTOERREN |
USB_ERREN_DFN8EN |
USB_ERREN_CRC16EN |
USB_ERREN_CRC5EOFEN |
USB_ERREN_PIDERREN;
USB0_INTEN = USB_INTEN_TOKDNEEN |
USB_INTEN_SOFTOKEN |
USB_INTEN_STALLEN |
Expand Down Expand Up @@ -1792,6 +1798,9 @@ void usb_isr()
//serial_phex(err);
//serial_print("\n");
USB0_ISTAT = USB_ISTAT_ERROR;

// A USB error of some type occurred, increment error counter
USBStatus_FrameErrors++;
}

// USB Host signalling device to enter 'sleep' state
Expand Down Expand Up @@ -1848,6 +1857,18 @@ void usb_set_sleep_state(bool sleep) {
}
}

#if defined(_sam_)
// Called on an SOF interrupt, used to record errors
void usb_sof_event()
{
// Check for error
if ( Is_udd_frame_number_crc_error() )
{
USBStatus_FrameErrors++;
}
}
#endif

uint8_t usb_init()
{
#ifdef UART_DEBUG
Expand Down
17 changes: 17 additions & 0 deletions Output/USB/output_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void cliFunc_readLEDs ( char* args );
void cliFunc_usbAddr ( char* args );
void cliFunc_usbConf ( char* args );
void cliFunc_usbInitTime( char* args );
void cliFunc_usbErrors ( char* args );



Expand All @@ -96,6 +97,7 @@ CLIDict_Entry( readLEDs, "Read LED byte:" NL "\t\t1 NumLck, 2 CapsLck, 4 Scrl
CLIDict_Entry( usbAddr, "Shows the negotiated USB unique Id, given to device by host." );
CLIDict_Entry( usbConf, "Shows whether USB is configured or not." );
CLIDict_Entry( usbInitTime, "Displays the time in ms from usb_init() till the last setup call." );
CLIDict_Entry( usbErrors, "Displays number of usb errors since startup." );

CLIDict_Def( usbCLIDict, "USB Module Commands" ) = {
CLIDict_Item( idle ),
Expand All @@ -104,6 +106,7 @@ CLIDict_Def( usbCLIDict, "USB Module Commands" ) = {
CLIDict_Item( usbAddr ),
CLIDict_Item( usbConf ),
CLIDict_Item( usbInitTime ),
CLIDict_Item( usbErrors ),
{ 0, 0, 0 } // Null entry for dictionary end
};

Expand Down Expand Up @@ -157,6 +160,9 @@ volatile uint16_t USBInit_Ticks;
// USB Address - Set by host, unique to the bus
volatile uint8_t USBDev_Address;

// USB Errors
volatile uint32_t USBStatus_FrameErrors;

// Scheduled USB resets, used to clear USB packets before bringing down the USB stack
// This is useful for OSs like Windows where then OS doesn't clear the current state
// after the keyboard is disconnected (i.e. Ctrl keeps being held until Ctrl is pressed again).
Expand Down Expand Up @@ -739,6 +745,9 @@ void USB_flushBuffers()
// USB Module Setup
inline void USB_setup()
{
// Reset frame error counter
USBStatus_FrameErrors = 0;

// Initialize the USB
// If a USB connection does not exist, just ignore it
// All usb related functions will non-fatally fail if called
Expand Down Expand Up @@ -1249,3 +1258,11 @@ void cliFunc_usbInitTime( char* args )
print(" ticks");
}


void cliFunc_usbErrors( char* args )
{
print(NL);
info_msg("USB Frame Errors: ");
printInt32( USBStatus_FrameErrors );
}

2 changes: 2 additions & 0 deletions Output/USB/output_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ extern volatile uint16_t USBInit_Ticks; // Number of times the end time has

extern volatile uint8_t USBDev_Address; // USB Address - Set by host, unique to the bus

extern volatile uint32_t USBStatus_FrameErrors; // Counter of SOF (start of frame) errors



// ----- Functions -----
Expand Down

0 comments on commit b3768cc

Please sign in to comment.