summaryrefslogtreecommitdiff
path: root/stmhal/usbd_cdc_interface.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-06-07 23:48:07 +0100
committerDamien George <damien.p.george@gmail.com>2015-06-07 23:48:07 +0100
commit0aa5e7500047d869cc78e8914fc08b5d6a3f5994 (patch)
tree856b0341a8cfed034860418e3d89fcaab710df8f /stmhal/usbd_cdc_interface.c
parent491c321720c772ee548f9e6f1612638ae8bce154 (diff)
stmhal: Break immediately from USB CDC busy wait loop if IRQs disabled.
If IRQs are disabled then the USB CDC buffer will never be drained/filled and the sys-tick timer will never increase, so we should not busy wait in this case.
Diffstat (limited to 'stmhal/usbd_cdc_interface.c')
-rw-r--r--stmhal/usbd_cdc_interface.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/stmhal/usbd_cdc_interface.c b/stmhal/usbd_cdc_interface.c
index 8b088660f..2bb8ddb95 100644
--- a/stmhal/usbd_cdc_interface.c
+++ b/stmhal/usbd_cdc_interface.c
@@ -42,6 +42,7 @@
#include "pendsv.h"
#include "py/obj.h"
+#include "irq.h"
#include "timer.h"
#include "usb.h"
@@ -417,6 +418,10 @@ int USBD_CDC_Tx(const uint8_t *buf, uint32_t len, uint32_t timeout) {
// timeout
return i;
}
+ if (query_irq() == IRQ_STATE_DISABLED) {
+ // IRQs disabled so buffer will never be drained; return immediately
+ return i;
+ }
__WFI(); // enter sleep mode, waiting for interrupt
}
@@ -444,6 +449,10 @@ void USBD_CDC_TxAlways(const uint8_t *buf, uint32_t len) {
// (wraparound of tick is taken care of by 2's complement arithmetic).
uint32_t start = HAL_GetTick();
while (((UserTxBufPtrIn + 1) & (APP_TX_DATA_SIZE - 1)) == UserTxBufPtrOut && HAL_GetTick() - start <= 500) {
+ if (query_irq() == IRQ_STATE_DISABLED) {
+ // IRQs disabled so buffer will never be drained; exit loop
+ break;
+ }
__WFI(); // enter sleep mode, waiting for interrupt
}
@@ -489,6 +498,10 @@ int USBD_CDC_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) {
// timeout
return i;
}
+ if (query_irq() == IRQ_STATE_DISABLED) {
+ // IRQs disabled so buffer will never be filled; return immediately
+ return i;
+ }
__WFI(); // enter sleep mode, waiting for interrupt
}