2 Commits 5d7d863829 ... 68d7e8c720

Auteur SHA1 Message Date
  Dmitry Filimonchuk 68d7e8c720 #135 fix F429 RX buffer overflow il y a 2 ans
  Dmitry Filimonchuk a79c8b5243 #135 add sequental TX data and variable packet length il y a 2 ans
2 fichiers modifiés avec 12 ajouts et 14 suppressions
  1. 5 2
      demo/cdc_loop.c
  2. 7 12
      src/usbd_stm32f429_otgfs.c

+ 5 - 2
demo/cdc_loop.c

@@ -359,8 +359,11 @@ static void cdc_rxonly (usbd_device *dev, uint8_t event, uint8_t ep) {
 
 static void cdc_txonly(usbd_device *dev, uint8_t event, uint8_t ep) {
     uint8_t _t = dev->driver->frame_no();
-    memset(fifo, _t, CDC_DATA_SZ);
-    usbd_ep_write(dev, ep, fifo, CDC_DATA_SZ);
+    if (_t > CDC_DATA_SZ) _t = CDC_DATA_SZ;
+    for (size_t i = 0; i < _t; ++i) {
+        fifo[i] = fpos++;
+    }
+    usbd_ep_write(dev, ep, fifo, _t);
 }
 
 static void cdc_rxtx(usbd_device *dev, uint8_t event, uint8_t ep) {

+ 7 - 12
src/usbd_stm32f429_otgfs.c

@@ -335,26 +335,25 @@ static int32_t ep_read(uint8_t ep, void* buf, uint16_t blen) {
             tmp >>= 8;
         }
     }
+    _BST(EPOUT(ep)->DOEPCTL, USB_OTG_DOEPCTL_CNAK | USB_OTG_DOEPCTL_EPENA);
     return (len < blen) ? len : blen;
 }
 
 static int32_t ep_write(uint8_t ep, const void *buf, uint16_t blen) {
-    uint32_t len, tmp;
+    uint32_t len, tmp = 0;
     ep &= 0x7F;
     volatile uint32_t* fifo = EPFIFO(ep);
     USB_OTG_INEndpointTypeDef* epi = EPIN(ep);
+    /* check if EP enabled*/
+    if (ep != 0 && epi->DIEPCTL & USB_OTG_DIEPCTL_EPENA) return -1;
     /* transfer data size in 32-bit words */
     len = (blen + 3) >> 2;
     /* no enough space in TX fifo */
-    if (len > epi->DTXFSTS) return -1;
-    if (ep != 0 && epi->DIEPCTL & USB_OTG_DIEPCTL_EPENA) {
-        return -1;
-    }
-    epi->DIEPTSIZ = 0;
+    if (len > 0 && len > _FLD2VAL(USB_OTG_DTXFSTS_INEPTFSAV, epi->DTXFSTS)) return -1;
+    //epi->DIEPTSIZ = 0;
     epi->DIEPTSIZ = (1 << 19) + blen;
-    _BMD(epi->DIEPCTL, USB_OTG_DIEPCTL_STALL, USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_CNAK);
+    _BST(epi->DIEPCTL, USB_OTG_DIEPCTL_EPENA | USB_OTG_DIEPCTL_CNAK);
     /* push data to FIFO */
-    tmp = 0;
     for (int idx = 0; idx < blen; idx++) {
         tmp |= (uint32_t)((const uint8_t*)buf)[idx] << ((idx & 0x03) << 3);
         if ((idx & 0x03) == 0x03 || (idx + 1) == blen) {
@@ -410,10 +409,6 @@ static void evt_poll(usbd_device *dev, usbd_evt_callback callback) {
                 }
                 evt = usbd_evt_epsetup;
                 break;
-            case 0x03:  /* OUT completed */
-            case 0x04:  /* SETUP completed */
-                _BST(EPOUT(ep)->DOEPCTL, USB_OTG_DOEPCTL_CNAK | USB_OTG_DOEPCTL_EPENA);
-                // fall through
             default:
                 /* pop GRXSTSP */
                 OTG->GRXSTSP;