From caabdd99c0f8402f5a141123f02cdf4be0a10ecf Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 3 Jul 2019 01:00:40 +1000 Subject: [PATCH] stm32/qspi: Handle bus acquisition. When going out of memory-mapped mode to do a control transfer to the QSPI flash, the MPU settings must be changed to forbid access to the memory mapped region. And any ongoing transfer (eg memory mapped continuous read) must be aborted. --- ports/stm32/qspi.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ports/stm32/qspi.c b/ports/stm32/qspi.c index 282759967e..ec744bfb27 100644 --- a/ports/stm32/qspi.c +++ b/ports/stm32/qspi.c @@ -139,6 +139,16 @@ STATIC int qspi_ioctl(void *self_in, uint32_t cmd) { case MP_QSPI_IOCTL_INIT: qspi_init(); break; + case MP_QSPI_IOCTL_BUS_ACQUIRE: + // Disable memory-mapped region during bus access + qspi_mpu_disable_all(); + // Abort any ongoing transfer if peripheral is busy + if (QUADSPI->SR & QUADSPI_SR_BUSY) { + QUADSPI->CR |= QUADSPI_CR_ABORT; + while (QUADSPI->CR & QUADSPI_CR_ABORT) { + } + } + break; case MP_QSPI_IOCTL_BUS_RELEASE: // Switch to memory-map mode when bus is idle qspi_memory_map();