From 8793aaa387a1b10500d046db5fa183acdeb9368a Mon Sep 17 00:00:00 2001 From: Eric Price Date: Tue, 16 Oct 2018 15:51:46 +0200 Subject: [PATCH] LP-602 Re-enable rx_status checking in usb_csc to optionally reenable rx after reset This partially reverts 1203fa9e665b1ed0236c7456e1b5f064e3366460 LP-495 F4 USB CDC: remove internal rx_active state tracking and use actual endpoint status instead (like F1) However rx_status is only used in the reinit case, without reintroducing issue LP-495 --- flight/pios/stm32f4xx/pios_usb_cdc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/flight/pios/stm32f4xx/pios_usb_cdc.c b/flight/pios/stm32f4xx/pios_usb_cdc.c index 2da23bc87..52513f8bd 100644 --- a/flight/pios/stm32f4xx/pios_usb_cdc.c +++ b/flight/pios/stm32f4xx/pios_usb_cdc.c @@ -91,8 +91,9 @@ struct pios_usb_cdc_dev { * that are strictly < maxPacketSize for this interface which means we never have * to bother with zero length packets (ZLP). */ - uint8_t tx_packet_buffer[PIOS_USB_BOARD_CDC_DATA_LENGTH - 1] __attribute__((aligned(4))); + uint8_t tx_packet_buffer[PIOS_USB_BOARD_CDC_DATA_LENGTH - 1] __attribute__((aligned(4))); volatile bool tx_active; + volatile bool rx_active; uint8_t ctrl_tx_packet_buffer[PIOS_USB_BOARD_CDC_MGMT_LENGTH] __attribute__((aligned(4))); @@ -191,8 +192,9 @@ int32_t PIOS_USB_CDC_Init(uint32_t *usbcdc_id, const struct pios_usb_cdc_cfg *cf pios_usb_cdc_id = (uint32_t)usb_cdc_dev; - /* Tx is not active yet */ + /* Tx and Rx are not active yet */ usb_cdc_dev->tx_active = false; + usb_cdc_dev->rx_active = false; /* Clear stats */ usb_cdc_dev->rx_dropped = 0; @@ -279,6 +281,7 @@ static void PIOS_USB_CDC_RxStart(uint32_t usbcdc_id, uint16_t rx_bytes_avail) PIOS_USBHOOK_EndpointRx(usb_cdc_dev->cfg->data_rx_ep, usb_cdc_dev->rx_packet_buffer, sizeof(usb_cdc_dev->rx_packet_buffer)); + usb_cdc_dev->rx_active = true; } } @@ -608,6 +611,12 @@ static void PIOS_USB_CDC_DATA_IF_Init(uint32_t usb_cdc_id) (uint32_t)usb_cdc_dev); usb_cdc_dev->usb_data_if_enabled = true; usb_cdc_dev->tx_active = false; + /* Check if rx was previously active, if so we need to reactivate */ + if (usb_cdc_dev->rx_active) { + PIOS_USBHOOK_EndpointRx(usb_cdc_dev->cfg->data_rx_ep, + usb_cdc_dev->rx_packet_buffer, + sizeof(usb_cdc_dev->rx_packet_buffer)); + } } static void PIOS_USB_CDC_DATA_IF_DeInit(uint32_t usb_cdc_id) @@ -711,9 +720,11 @@ static bool PIOS_USB_CDC_DATA_EP_OUT_Callback( usb_cdc_dev->rx_packet_buffer, sizeof(usb_cdc_dev->rx_packet_buffer)); rc = true; + usb_cdc_dev->rx_active = true; } else { /* Not enough room left for a message, apply backpressure */ rc = false; + usb_cdc_dev->rx_active = false; } #if defined(PIOS_INCLUDE_FREERTOS) -- 2.11.4.GIT