32F417: How to block USB_FS ISR from a shared resource (serial FLASH, on SPI)
I have a serial FLASH, a part of which implements a Windows file system (removable block device). Another part of the FLASH is for data logging etc usage.
All this is working, but the ISR which implements the USB block device must be blocked out of the SPI function during data logging, obviously, otherwise it could jump in during one of the data logging accesses; the SPI and the FLASH are obviously not re-entrant!
I have tried disabling USB interrupts, via one of these methods
- zeroing bit 0 of GAHBCFG
- zeroing all of GINTMSK
and restoring these registers after SPI is finished. I am assuming they are fully readable...
Both methods work equally: 100% for protecting the data logging side but there is a tiny chance of USB accesses (file writes, 2MB files) getting corrupted; probability is around the PPM level but not zero, and only if there is heavy data logging FLASH usage. USB file reads are 100% reliable.
USB ints are potentially disabled for 1 FLASH page write which is 18ms. The Windows host is fine with that - so long as I delay about 10ms after each FLASH page write (during logging) to give USB a chance to get in. I also need a bit of a delay to avoid data corruption on the USB VCP which is used for debugs; not surprising.
Another method is for the data logging side to set a flag when using SPI, and when the USB ISR sees this, it returns USBD_BUSY (instead of USBD_OK) and stays out of the SPI. Same principle used in say a USB to serial converter, when the UART TX buffer is full.
This also works 100% for protecting the data logging side, but USB written files are heavily corrupted. I can't see why.
Can anyone see a reason for this? Are the two registers above not quite what they seem in the RM? The text says GAHBCFG should be set up just once and not touched, but the Cube IDE generated sample code does exactly the opposite!
Some more info posted here
but suggestions are not useful or practical at this point in time, and nobody seems to know about the USB implementation on this chip.
Thank you in advance.
