Commit 0aa5e750 authored by Damien George's avatar Damien George
Browse files

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.
parent 491c3217
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "pendsv.h" #include "pendsv.h"
#include "py/obj.h" #include "py/obj.h"
#include "irq.h"
#include "timer.h" #include "timer.h"
#include "usb.h" #include "usb.h"
...@@ -417,6 +418,10 @@ int USBD_CDC_Tx(const uint8_t *buf, uint32_t len, uint32_t timeout) { ...@@ -417,6 +418,10 @@ int USBD_CDC_Tx(const uint8_t *buf, uint32_t len, uint32_t timeout) {
// timeout // timeout
return i; 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 __WFI(); // enter sleep mode, waiting for interrupt
} }
...@@ -444,6 +449,10 @@ void USBD_CDC_TxAlways(const uint8_t *buf, uint32_t len) { ...@@ -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). // (wraparound of tick is taken care of by 2's complement arithmetic).
uint32_t start = HAL_GetTick(); uint32_t start = HAL_GetTick();
while (((UserTxBufPtrIn + 1) & (APP_TX_DATA_SIZE - 1)) == UserTxBufPtrOut && HAL_GetTick() - start <= 500) { 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 __WFI(); // enter sleep mode, waiting for interrupt
} }
...@@ -489,6 +498,10 @@ int USBD_CDC_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) { ...@@ -489,6 +498,10 @@ int USBD_CDC_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) {
// timeout // timeout
return i; 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 __WFI(); // enter sleep mode, waiting for interrupt
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment