@@ -170,6 +170,25 @@ void qspi_memory_map(void) {
170170 qspi_mpu_enable_mapped ();
171171}
172172
173+ void qspi_memory_map_exit (void ) {
174+ // Prevent access to QSPI memory-mapped region.
175+ qspi_mpu_disable_all ();
176+
177+ // Abort any ongoing transfer if peripheral is busy
178+ if (QUADSPI -> SR & QUADSPI_SR_BUSY ) {
179+ QUADSPI -> CR |= QUADSPI_CR_ABORT ;
180+ while (QUADSPI -> CR & QUADSPI_CR_ABORT ) {
181+ }
182+ }
183+ }
184+
185+ // Needed on F7 due to errata 2.4.3: "Memory-mapped read operations may fail when timeout counter is enabled".
186+ // Call this function to disable then re-enable memory-mapped mode, which resets the CS pin to inactive.
187+ void qspi_memory_map_restart (void ) {
188+ qspi_memory_map_exit ();
189+ qspi_memory_map ();
190+ }
191+
173192static int qspi_ioctl (void * self_in , uint32_t cmd , uintptr_t arg ) {
174193 (void )self_in ;
175194 switch (cmd ) {
@@ -178,13 +197,7 @@ static int qspi_ioctl(void *self_in, uint32_t cmd, uintptr_t arg) {
178197 break ;
179198 case MP_QSPI_IOCTL_BUS_ACQUIRE :
180199 // Disable memory-mapped region during bus access
181- qspi_mpu_disable_all ();
182- // Abort any ongoing transfer if peripheral is busy
183- if (QUADSPI -> SR & QUADSPI_SR_BUSY ) {
184- QUADSPI -> CR |= QUADSPI_CR_ABORT ;
185- while (QUADSPI -> CR & QUADSPI_CR_ABORT ) {
186- }
187- }
200+ qspi_memory_map_exit ();
188201 break ;
189202 case MP_QSPI_IOCTL_BUS_RELEASE :
190203 // Switch to memory-map mode when bus is idle
0 commit comments