static Event usb_event_done[EP_MAX_SLOTS];
+/* Check if we're running in atomic (non-sleepable) context or not */
+static volatile bool in_atomic = false;
+
/* Allocate a free block of the packet memory */
static stm32_UsbMemSlot *usb_malloc(void)
{
ssize_t max_size = sizeof(ep_buffer[ep_num]);
/* Non-blocking read for EP0 */
- if (ep_num == CTRL_ENP_OUT)
+ if (in_atomic && (ep_num == CTRL_ENP_OUT))
{
size = usb_size(size, usb_le16_to_cpu(setup_packet.wLength));
if (UNLIKELY(size > max_size))
ssize_t max_size = sizeof(ep_buffer[ep_num]);
/* Non-blocking write for EP0 */
- if (ep_num == CTRL_ENP_IN)
+ if (in_atomic && (ep_num == CTRL_ENP_IN))
{
size = usb_size(size, usb_le16_to_cpu(setup_packet.wLength));
if (UNLIKELY(size > max_size))
interrupt.status = usb->ISTR;
interrupt.status &= usb->CNTR | 0x1f;
+ /* Set the context as atomic */
+ in_atomic = true;
+
if (interrupt.PMAOVR)
{
LOG_WARN("%s: DMA overrun / underrun\n", __func__);
{
usb_isr_correct_transfer(interrupt);
}
+ in_atomic = false;
}
/* USB: hardware initialization */