← index #7148PR #7344
Off-topic · high · value 0.078
QUERY · ISSUE

STM32: How to avoid disabling USB IRQs in sdcard.c ?

openby iabdalkaderopened 2021-04-22updated 2022-01-28
port-stm32

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

CANDIDATE · PULL REQUEST

stm32/usb: Add USB_VCP.irq method, to set a callback on USB data RX.

mergedby dpgeorgeopened 2021-06-02updated 2021-06-10
port-stm32

This adds IRQ capability to USB VCP similar to UART RX IRQs.

Example use:

>>> usb = pyb.USB_VCP()
>>> usb.irq(lambda u:print(u, u.read()))
>>> while 1:
...     pass
... 
USB_VCP(0) b'a'
USB_VCP(0) b'b'
USB_VCP(0) b'c'
USB_VCP(0) b'd'
USB_VCP(0) b'e'
USB_VCP(0) b'f'

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied