From 8ef6249e01f44e9a789e04b1d5baf1e77bfff6ae Mon Sep 17 00:00:00 2001 From: Epagris Date: Fri, 19 Apr 2024 14:01:17 +0200 Subject: [PATCH] - driver: only poll FIFO free space if transmission size > 0 - CDC: buffer size increased --- class/cdc.c | 4 +++- usb_driver.c | 15 +++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/class/cdc.c b/class/cdc.c index a7fd1e3..e256520 100644 --- a/class/cdc.c +++ b/class/cdc.c @@ -12,11 +12,13 @@ static USB_CdcState cdcs = { 0 }; static uint8_t tx_buffer[USB_CDC_PCKT_BUFSIZE]; -#define USB_CDC_FIFO_MEM_SIZE (2048) +#define USB_CDC_FIFO_MEM_SIZE (3072) // FIXME: ez vagy a blocking FIFO bugos static uint8_t fifo_mem[USB_CDC_FIFO_MEM_SIZE]; static BFifo fifo; +void usb_cdc_read_callback(const uint8_t * data, uint32_t size); + void usb_cdc_init(const USB_CdcAssignments *as) { // clear the structure memset(&cdcs, 0, sizeof(USB_CdcState)); diff --git a/usb_driver.c b/usb_driver.c index ff3f808..4317650 100644 --- a/usb_driver.c +++ b/usb_driver.c @@ -267,7 +267,7 @@ void usbdrv_build_fifo() { if (cfg->is_configured) { cfg->fifo_size = CEIL4(MAX(USB_MIN_GROSS_TX_FIFO_SIZE, cfg->max_packet_size)); // correct FIFO size if necessary cfg->fifo_address = next_fifo_addr; // store FIFO address - cfg->zlp_next = false; // clear ZLP next + cfg->zlp_next = false; // clear ZLP next next_fifo_addr += cfg->fifo_size; // advance next address } } @@ -476,8 +476,11 @@ uint32_t usbdrv_arm_IN_endpoint(uint8_t ep, const uint8_t *data, uint16_t len) { } // determine final write size - uint32_t freeSize = USBINEP[ep].DTXFSTS * sizeof(uint32_t); // get free transmit buffer size - uint16_t writeSize = MIN(freeSize, len); // limit transmit size to free size + uint32_t freeSize = 0; + if (len > 0) { // only poll DTXFSTS if (len > 0) (see datasheet) + freeSize = USBINEP[ep].DTXFSTS * sizeof(uint32_t); // get free transmit buffer size + } + uint16_t writeSize = MIN(freeSize, len); // limit transmit size to free size // calculate packet count based on max packet size uint16_t mps = gs.ep_IN[ep].max_packet_size; @@ -486,10 +489,10 @@ uint32_t usbdrv_arm_IN_endpoint(uint8_t ep, const uint8_t *data, uint16_t len) { packet_count = writeSize / mps + (((writeSize % mps) > 0) ? 1 : 0); } - // set zlp_next if transmission size is integer multiple of max packet size + // set zlp_next if transmission size is integer multiple of max packet size6 gs.ep_IN[ep].zlp_next = (writeSize > 0) && ((writeSize % mps) == 0); - // program DIEPTSIZ with transfer length (TODO: currently only a single transfer!) + // program DIEPTSIZ with transfer length USBINEP[ep].DIEPTSIZ = (packet_count << USB_OTG_DIEPTSIZ_PKTCNT_Pos) | writeSize; // enable endpoint and cancel responding NAK @@ -690,7 +693,7 @@ void usbdrv_process_event(uint8_t evt_code, USBDRV_EventData *evt_data) { // see if a ZLP transmission was queued if (gs.ep_IN[ep].zlp_next) { usbdrv_arm_IN_endpoint(ep, NULL, 0); // send ZLP - } else { // no ZLP + } else { // no ZLP USBMSG("IN [%d]\n", ep); cbcpd.code = USB_CBC_IN_DONE;