diff --git a/Downstream/Inc/downstream_spi.h b/Downstream/Inc/downstream_spi.h index 8a2b028..1a95b69 100644 --- a/Downstream/Inc/downstream_spi.h +++ b/Downstream/Inc/downstream_spi.h @@ -26,9 +26,8 @@ #define DOWNSTREAM_SPI_FREAKOUT \ do { \ - LED_Fault_SetBlinkRate(LED_FAST_BLINK_RATE); \ - /*Downstream_PacketProcessor_SetErrorState();*/ \ - /*DownstreamInterfaceState = DOWNSTREAM_INTERFACE_ERROR;*/ \ + Downstream_PacketProcessor_FreakOut(); \ + DownstreamInterfaceState = DOWNSTREAM_INTERFACE_ERROR; \ while (1); \ } while (0); diff --git a/Downstream/Inc/downstream_statemachine.h b/Downstream/Inc/downstream_statemachine.h index 785f055..97fc1a5 100644 --- a/Downstream/Inc/downstream_statemachine.h +++ b/Downstream/Inc/downstream_statemachine.h @@ -14,6 +14,7 @@ #include "usbh_def.h" +#include "usb_host.h" #include "downstream_spi.h" @@ -30,6 +31,7 @@ typedef enum #define DOWNSTREAM_STATEMACHINE_FREAKOUT \ do { \ + USB_Host_Disconnect(); \ LED_Fault_SetBlinkRate(LED_FAST_BLINK_RATE); \ DownstreamState = STATE_ERROR; \ while (1); \ diff --git a/Downstream/Inc/usb_host.h b/Downstream/Inc/usb_host.h index a59c43b..d324d0c 100644 --- a/Downstream/Inc/usb_host.h +++ b/Downstream/Inc/usb_host.h @@ -54,6 +54,7 @@ typedef enum { void USB_Host_Init(void); void USB_Host_Process(void); +void USB_Host_Disconnect(void); #ifdef __cplusplus diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h index 25a3dcb..92d159c 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h @@ -67,7 +67,7 @@ #define HOST_USER_CONNECTION 4 #define HOST_USER_DISCONNECTION 5 #define HOST_USER_UNRECOVERED_ERROR 6 - +#define HOST_USER_CLASS_FAILED 7 /** * @} diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c index e4d3553..d049a4f 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c @@ -534,6 +534,7 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost) } else { + phost->pUser(phost, HOST_USER_CLASS_FAILED); phost->gState = HOST_ABORT_STATE; USBH_UsrLog ("Device not supporting %s class.", phost->pActiveClass->Name); } diff --git a/Downstream/Src/downstream_statemachine.c b/Downstream/Src/downstream_statemachine.c index 03f0b79..ee3d281 100644 --- a/Downstream/Src/downstream_statemachine.c +++ b/Downstream/Src/downstream_statemachine.c @@ -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) { 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. //This is distinct from the fast freakout flash caused by internal errors or attacks. default: + USB_Host_Disconnect(); LED_Fault_SetBlinkRate(LED_SLOW_BLINK_RATE); DownstreamState = STATE_ERROR; return; @@ -250,5 +245,16 @@ void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id) DOWNSTREAM_STATEMACHINE_FREAKOUT; 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; + } } diff --git a/Downstream/Src/usb_host.c b/Downstream/Src/usb_host.c index ba4826c..4139c49 100644 --- a/Downstream/Src/usb_host.c +++ b/Downstream/Src/usb_host.c @@ -66,6 +66,12 @@ void USB_Host_Process() } +//Called when Downstream Statemachine or SPI freaks out. +void USB_Host_Disconnect() +{ + USBH_DeInit(&hUsbHostFS); +} + /** * @}