STM32: How to avoid disabling USB IRQs in sdcard.c ?
https://github.com/micropython/micropython/blob/00d6a79b3d5dc80d840dc1d51166e7d95856b3d6/ports/stm32/sdcard.c#L599
Any suggestions for a better way to handle this other than disabling USB IRQs ? This is starting to be an issue especially when reading/writing many blocks in one call or reading/writing frequently in a loop, all USB IRQs are disabled and this stops other things that don't access MSC at all from working.
I tried setting a flag in sdcard.c when reading/writing instead of disabling IRQs, to indicate the card is busy and checking this flag in usbcd_msc_interface.c returning -1 from usbd_msc_IsReady() if the flag is set, it almost works except on the host I see I/O errors and things eventually fail... Is there anything else I can try ?
diff --git a/ports/stm32/usbd_msc_interface.c b/ports/stm32/usbd_msc_interface.c
index 62fe32bf5..71eb58259 100644
--- a/ports/stm32/usbd_msc_interface.c
+++ b/ports/stm32/usbd_msc_interface.c
@@ -242,9 +242,10 @@ STATIC int8_t usbd_msc_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *b
return lu_ioctl(lun, MP_BLOCKDEV_IOCTL_BLOCK_COUNT, block_num);
}
+extern volatile uint32_t sdcard_busy;
// Check if a logical unit is ready
STATIC int8_t usbd_msc_IsReady(uint8_t lun) {
- if (lun >= usbd_msc_lu_num) {
+ if (lun >= usbd_msc_lu_num || sdcard_busy) {
return -1;
}
return lu_flag_is_set(lun, FLAGS_STARTED) ? 0 : -1;
Also tried returning different status codes from here: https://publib.boulder.ibm.com/tividd/td/TSMM/GC32-0767-00/en_US/HTML/anrcms45.htm but all of them cause I/O errors on the host.
SCSI status codes, sense keys: https://www.t10.org/lists/1spc-lst.htm
Disable IRQs around sdcard reads.
Once the code switches to using DMA, this can be removed.
This should fix #743
I tracked the problem down to an SDIO_FLAG_RXOVERR error. Since the FIFO is only 32 bit x 32 entries (or 128 bytes), I guessed that the timer tick interrupt was probably happening during a read and causing the FIFO to overflow.
Once the code is switched to using DMA, then the disable/enable IRQ can be removed.