Skip to content

Commit 8793aaa

Browse files
committed
LP-602 Re-enable rx_status checking in usb_csc to optionally reenable rx after reset
This partially reverts 1203fa9 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
1 parent 868d787 commit 8793aaa

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

flight/pios/stm32f4xx/pios_usb_cdc.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ struct pios_usb_cdc_dev {
9191
* that are strictly < maxPacketSize for this interface which means we never have
9292
* to bother with zero length packets (ZLP).
9393
*/
94-
uint8_t tx_packet_buffer[PIOS_USB_BOARD_CDC_DATA_LENGTH - 1] __attribute__((aligned(4)));
94+
uint8_t tx_packet_buffer[PIOS_USB_BOARD_CDC_DATA_LENGTH - 1] __attribute__((aligned(4)));
9595
volatile bool tx_active;
96+
volatile bool rx_active;
9697

9798
uint8_t ctrl_tx_packet_buffer[PIOS_USB_BOARD_CDC_MGMT_LENGTH] __attribute__((aligned(4)));
9899

@@ -191,8 +192,9 @@ int32_t PIOS_USB_CDC_Init(uint32_t *usbcdc_id, const struct pios_usb_cdc_cfg *cf
191192

192193
pios_usb_cdc_id = (uint32_t)usb_cdc_dev;
193194

194-
/* Tx is not active yet */
195+
/* Tx and Rx are not active yet */
195196
usb_cdc_dev->tx_active = false;
197+
usb_cdc_dev->rx_active = false;
196198

197199
/* Clear stats */
198200
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)
279281
PIOS_USBHOOK_EndpointRx(usb_cdc_dev->cfg->data_rx_ep,
280282
usb_cdc_dev->rx_packet_buffer,
281283
sizeof(usb_cdc_dev->rx_packet_buffer));
284+
usb_cdc_dev->rx_active = true;
282285
}
283286
}
284287

@@ -608,6 +611,12 @@ static void PIOS_USB_CDC_DATA_IF_Init(uint32_t usb_cdc_id)
608611
(uint32_t)usb_cdc_dev);
609612
usb_cdc_dev->usb_data_if_enabled = true;
610613
usb_cdc_dev->tx_active = false;
614+
/* Check if rx was previously active, if so we need to reactivate */
615+
if (usb_cdc_dev->rx_active) {
616+
PIOS_USBHOOK_EndpointRx(usb_cdc_dev->cfg->data_rx_ep,
617+
usb_cdc_dev->rx_packet_buffer,
618+
sizeof(usb_cdc_dev->rx_packet_buffer));
619+
}
611620
}
612621

613622
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(
711720
usb_cdc_dev->rx_packet_buffer,
712721
sizeof(usb_cdc_dev->rx_packet_buffer));
713722
rc = true;
723+
usb_cdc_dev->rx_active = true;
714724
} else {
715725
/* Not enough room left for a message, apply backpressure */
716726
rc = false;
727+
usb_cdc_dev->rx_active = false;
717728
}
718729

719730
#if defined(PIOS_INCLUDE_FREERTOS)

0 commit comments

Comments
 (0)