diff options
-rw-r--r-- | libmaple/usb/usb.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c index 0474cad..0549f3c 100644 --- a/libmaple/usb/usb.c +++ b/libmaple/usb/usb.c @@ -380,28 +380,19 @@ void usbWaitReset(void) { */ int16 usbSendBytes(uint8* sendBuf, uint16 len) { - if (reset_state == NDTR_NRTS) { + if (reset_state != START || bDeviceState != CONFIGURED) { return -1; /* indicates to caller to stop trying, were not connected */ } - /* Block for any pending writes */ - while (countTx) - ; -/* while (countTx != 0) { */ -/* if (reset_state == NDTR_NRTS) { */ -/* return 0; */ -/* } */ -/* }/\* wait for pipe to be clear *\/ */ - - - /* ideally we should wait here, but it gets stuck - for some reason. countTx wont decrement when - theres no host side port reading the data, this is - known, but even if we add the check for NDTR_NRTS it - still gets stuck...*/ - if (countTx != 0) { - return 0; /* indicated to caller to keep trying, were just busy */ + /* This may be the correct behavior but it's undocumented + if (countTx >= VCOM_TX_EPSIZE) { + return 0; // indicates to caller that the buffer is full } + */ + + /* Block for any pending writes */ + while (countTx) + ; uint16 sent = len; |