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.
modussl
Damien George 2015-06-07 23:48:07 +01:00
parent 491c321720
commit 0aa5e75000
1 changed files with 13 additions and 0 deletions

View File

@ -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
}