Improve Downstream error handling:

- Slow flash fault LED when unsupported device connected
- Disconnect downstream USB host on error
pull/7/head
Robert Fisk 9 years ago
parent 3eb95c683c
commit 226e163adf

@ -26,9 +26,8 @@
#define DOWNSTREAM_SPI_FREAKOUT \ #define DOWNSTREAM_SPI_FREAKOUT \
do { \ do { \
LED_Fault_SetBlinkRate(LED_FAST_BLINK_RATE); \ Downstream_PacketProcessor_FreakOut(); \
/*Downstream_PacketProcessor_SetErrorState();*/ \ DownstreamInterfaceState = DOWNSTREAM_INTERFACE_ERROR; \
/*DownstreamInterfaceState = DOWNSTREAM_INTERFACE_ERROR;*/ \
while (1); \ while (1); \
} while (0); } while (0);

@ -14,6 +14,7 @@
#include "usbh_def.h" #include "usbh_def.h"
#include "usb_host.h"
#include "downstream_spi.h" #include "downstream_spi.h"
@ -30,6 +31,7 @@ typedef enum
#define DOWNSTREAM_STATEMACHINE_FREAKOUT \ #define DOWNSTREAM_STATEMACHINE_FREAKOUT \
do { \ do { \
USB_Host_Disconnect(); \
LED_Fault_SetBlinkRate(LED_FAST_BLINK_RATE); \ LED_Fault_SetBlinkRate(LED_FAST_BLINK_RATE); \
DownstreamState = STATE_ERROR; \ DownstreamState = STATE_ERROR; \
while (1); \ while (1); \

@ -54,6 +54,7 @@ typedef enum {
void USB_Host_Init(void); void USB_Host_Init(void);
void USB_Host_Process(void); void USB_Host_Process(void);
void USB_Host_Disconnect(void);
#ifdef __cplusplus #ifdef __cplusplus

@ -67,7 +67,7 @@
#define HOST_USER_CONNECTION 4 #define HOST_USER_CONNECTION 4
#define HOST_USER_DISCONNECTION 5 #define HOST_USER_DISCONNECTION 5
#define HOST_USER_UNRECOVERED_ERROR 6 #define HOST_USER_UNRECOVERED_ERROR 6
#define HOST_USER_CLASS_FAILED 7
/** /**
* @} * @}

@ -534,6 +534,7 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost)
} }
else else
{ {
phost->pUser(phost, HOST_USER_CLASS_FAILED);
phost->gState = HOST_ABORT_STATE; phost->gState = HOST_ABORT_STATE;
USBH_UsrLog ("Device not supporting %s class.", phost->pActiveClass->Name); USBH_UsrLog ("Device not supporting %s class.", phost->pActiveClass->Name);
} }

@ -89,14 +89,8 @@ void Downstream_PacketProcessor(DownstreamPacketTypeDef* receivedPacket)
} }
//Used by downstream_spi freakout macro, indicates we should stop everything.
void Downstream_PacketProcessor_SetErrorState(void)
{
DownstreamState = STATE_ERROR;
}
//Used by downstream class interfaces //Used by downstream class interfaces, and SPI interface
void Downstream_PacketProcessor_FreakOut(void) void Downstream_PacketProcessor_FreakOut(void)
{ {
DOWNSTREAM_STATEMACHINE_FREAKOUT; DOWNSTREAM_STATEMACHINE_FREAKOUT;
@ -212,6 +206,7 @@ void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id)
//Unsupported device classes will cause a slow fault flash. //Unsupported device classes will cause a slow fault flash.
//This is distinct from the fast freakout flash caused by internal errors or attacks. //This is distinct from the fast freakout flash caused by internal errors or attacks.
default: default:
USB_Host_Disconnect();
LED_Fault_SetBlinkRate(LED_SLOW_BLINK_RATE); LED_Fault_SetBlinkRate(LED_SLOW_BLINK_RATE);
DownstreamState = STATE_ERROR; DownstreamState = STATE_ERROR;
return; return;
@ -250,5 +245,16 @@ void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id)
DOWNSTREAM_STATEMACHINE_FREAKOUT; DOWNSTREAM_STATEMACHINE_FREAKOUT;
return; return;
} }
//Called from main():
if (id == HOST_USER_CLASS_FAILED)
{
//Unsupported device classes will cause a slow fault flash.
//This is distinct from the fast freakout flash caused by internal errors or attacks.
USB_Host_Disconnect();
LED_Fault_SetBlinkRate(LED_SLOW_BLINK_RATE);
DownstreamState = STATE_ERROR;
return;
}
} }

@ -66,6 +66,12 @@ void USB_Host_Process()
} }
//Called when Downstream Statemachine or SPI freaks out.
void USB_Host_Disconnect()
{
USBH_DeInit(&hUsbHostFS);
}
/** /**
* @} * @}

Loading…
Cancel
Save