From c449cb710853a23bb2839bf9b1179d48cfcef9b7 Mon Sep 17 00:00:00 2001 From: Edward Emelianov Date: Wed, 2 Apr 2025 16:09:27 +0300 Subject: [PATCH] fixed some problems with USB --- F1:F103/USB_New_concept/USB_NEW_concept_7inone/usb_dev.c | 7 +++++-- F1:F103/USB_New_concept/USB_NEW_concept_CDC/usb_dev.c | 7 +++++-- F1:F103/USB_New_concept/USB_NEW_concept_HID/usb_dev.c | 1 + F1:F103/USB_New_concept/USB_NEW_concept_PL2303/usb_dev.c | 9 ++++++--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/F1:F103/USB_New_concept/USB_NEW_concept_7inone/usb_dev.c b/F1:F103/USB_New_concept/USB_NEW_concept_7inone/usb_dev.c index 7dc25ba..7122e2d 100644 --- a/F1:F103/USB_New_concept/USB_NEW_concept_7inone/usb_dev.c +++ b/F1:F103/USB_New_concept/USB_NEW_concept_7inone/usb_dev.c @@ -211,6 +211,7 @@ void usb_class_request(config_pack_t *req, uint8_t *data, uint16_t datalen){ int USB_sendall(uint8_t ifno){ while(lastdsz[ifno] > 0){ if(!CDCready[ifno]) return FALSE; + IWDG->KR = IWDG_REFRESH; } return TRUE; } @@ -220,12 +221,13 @@ int USB_send(uint8_t ifno, const uint8_t *buf, int len){ if(!buf || !CDCready[ifno] || !len) return FALSE; DBG("USB_send"); while(len){ + IWDG->KR = IWDG_REFRESH; int a = RB_write((ringbuffer*)&rbout[ifno], buf, len); + if(lastdsz[ifno] == 0) send_next(ifno); // need to run manually - all data sent, so no IRQ on IN if(a > 0){ len -= a; buf += a; } else if (a < 0) continue; // do nothing if buffer is in reading state - if(lastdsz[ifno] == 0) send_next(ifno); // need to run manually - all data sent, so no IRQ on IN } return TRUE; } @@ -234,9 +236,10 @@ int USB_putbyte(uint8_t ifno, uint8_t byte){ if(!CDCready[ifno]) return FALSE; int l = 0; while((l = RB_write((ringbuffer*)&rbout[ifno], &byte, 1)) != 1){ + IWDG->KR = IWDG_REFRESH; + if(lastdsz[ifno] == 0) send_next(ifno); // need to run manually - all data sent, so no IRQ on IN if(l < 0) continue; } - if(lastdsz[ifno] == 0) send_next(ifno); // need to run manually - all data sent, so no IRQ on IN return TRUE; } diff --git a/F1:F103/USB_New_concept/USB_NEW_concept_CDC/usb_dev.c b/F1:F103/USB_New_concept/USB_NEW_concept_CDC/usb_dev.c index 13b5ddb..942694c 100644 --- a/F1:F103/USB_New_concept/USB_NEW_concept_CDC/usb_dev.c +++ b/F1:F103/USB_New_concept/USB_NEW_concept_CDC/usb_dev.c @@ -183,6 +183,7 @@ void usb_class_request(config_pack_t *req, uint8_t *data, uint16_t datalen){ int USB_sendall(){ while(lastdsz > 0){ if(!CDCready) return FALSE; + IWDG->KR = IWDG_REFRESH; } return TRUE; } @@ -192,12 +193,13 @@ int USB_send(const uint8_t *buf, int len){ if(!buf || !CDCready || !len) return FALSE; DBG("USB_send"); while(len){ + IWDG->KR = IWDG_REFRESH; int a = RB_write((ringbuffer*)&rbout, buf, len); + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN if(a > 0){ len -= a; buf += a; } else if (a < 0) continue; // do nothing if buffer is in reading state - if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN } return TRUE; } @@ -206,9 +208,10 @@ int USB_putbyte(uint8_t byte){ if(!CDCready) return FALSE; int l = 0; while((l = RB_write((ringbuffer*)&rbout, &byte, 1)) != 1){ + IWDG->KR = IWDG_REFRESH; + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN if(l < 0) continue; } - if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN return TRUE; } diff --git a/F1:F103/USB_New_concept/USB_NEW_concept_HID/usb_dev.c b/F1:F103/USB_New_concept/USB_NEW_concept_HID/usb_dev.c index ac768e6..31ed6f3 100644 --- a/F1:F103/USB_New_concept/USB_NEW_concept_HID/usb_dev.c +++ b/F1:F103/USB_New_concept/USB_NEW_concept_HID/usb_dev.c @@ -40,6 +40,7 @@ int USB_send(uint8_t *buf, uint16_t size){ if(!usbON || !size) return 0; uint16_t ctr = 0; while(size){ + IWDG->KR = IWDG_REFRESH; uint16_t s = (size > USB_EP1BUFSZ) ? USB_EP1BUFSZ : size; tx_succesfull = 0; EP_Write(1, (uint8_t*)&buf[ctr], s); diff --git a/F1:F103/USB_New_concept/USB_NEW_concept_PL2303/usb_dev.c b/F1:F103/USB_New_concept/USB_NEW_concept_PL2303/usb_dev.c index a240e70..5b3fd40 100644 --- a/F1:F103/USB_New_concept/USB_NEW_concept_PL2303/usb_dev.c +++ b/F1:F103/USB_New_concept/USB_NEW_concept_PL2303/usb_dev.c @@ -223,6 +223,7 @@ void usb_vendor_request(config_pack_t *req, uint8_t _U_ *data, uint16_t _U_ data int USB_sendall(){ while(lastdsz > 0){ if(!CDCready) return FALSE; + IWDG->KR = IWDG_REFRESH; } return TRUE; } @@ -232,13 +233,14 @@ int USB_send(const uint8_t *buf, int len){ if(!buf || !CDCready || !len) return FALSE; DBG("send"); while(len){ + IWDG->KR = IWDG_REFRESH; int a = RB_write((ringbuffer*)&rbout, buf, len); + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN if(a > 0){ len -= a; buf += a; } else if (a < 0) continue; // do nothing if buffer is in reading state - if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN - } + } return TRUE; } @@ -246,9 +248,10 @@ int USB_putbyte(uint8_t byte){ if(!CDCready) return FALSE; int l = 0; while((l = RB_write((ringbuffer*)&rbout, &byte, 1)) != 1){ + IWDG->KR = IWDG_REFRESH; + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN if(l < 0) continue; } - if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN return TRUE; }