From 7430b92d27c912cf2e43337b4c4a45dac73100b0 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 7 Mar 2021 20:20:29 +0900 Subject: [PATCH] address hw pin-reset while sleep. --- ports/nrf/supervisor/qspi_flash.c | 49 ++++++++++++++++++------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/ports/nrf/supervisor/qspi_flash.c b/ports/nrf/supervisor/qspi_flash.c index 00a88d52b9..d2bf9678da 100644 --- a/ports/nrf/supervisor/qspi_flash.c +++ b/ports/nrf/supervisor/qspi_flash.c @@ -41,6 +41,27 @@ #include "supervisor/serial.h" // dbg_printf() #endif +#ifdef QSPI_FLASH_POWERDOWN +// Parameters for external QSPI Flash power-down +// for W25Q128FV, +// tDP (nCS high to Power-down mode) = 3us +// tRES (nCS high to Standby mode) = 3us +// sck_delay = max(tDP, tRES) / 62.5ns = 48 -> 50 (w/ margin) +#define DUR_DPM_ENTER 1 // tDP in (256*62.5ns) units +#define DUR_DPM_EXIT 1 // tRES in (256*62.5ns) units +#define SCK_DELAY 50 // max(tDP, tRES) in (62.5ns) units +// wait necessary just after DPM enter/exit (cut and try) +#define WAIT_AFTER_DPM_ENTER 10 // usec +#define WAIT_AFTER_DPM_EXIT 50 // usec +#endif + +static int sck_delay_saved = 0; +#ifdef NRF_DEBUG_PRINT +extern void dbg_dumpQSPIreg(void); +#else +#define dbg_dumpQSPIreg(...) +#endif + // When USB is disconnected, disable QSPI in sleep mode to save energy void qspi_disable(void) { @@ -222,6 +243,13 @@ void spi_flash_init(void) { // No callback for blocking API nrfx_qspi_init(&qspi_cfg, NULL, NULL); + +#ifdef QSPI_FLASH_POWERDOWN + // If pin-reset while flash is in power-down mode, + // the flash cannot accept any commands. Send CMD_WAKE to release it. + spi_flash_write_command(CMD_WAKE, NULL, 0); + NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT); +#endif } void spi_flash_init_device(const external_flash_device* device) { @@ -246,27 +274,6 @@ void spi_flash_init_device(const external_flash_device* device) { NRF_QSPI->IFCONFIG1 |= sckfreq << QSPI_IFCONFIG1_SCKFREQ_Pos; } -#ifdef QSPI_FLASH_POWERDOWN -// Parameters for external QSPI Flash power-down -// for W25Q128FV, -// tDP (nCS high to Power-down mode) = 3us -// tRES (nCS high to Standby mode) = 3us -// sck_delay = max(tDP, tRES) / 62.5ns = 48 -> 50 (w/ margin) -#define DUR_DPM_ENTER 1 // tDP in (256*62.5ns) units -#define DUR_DPM_EXIT 1 // tRES in (256*62.5ns) units -#define SCK_DELAY 50 // max(tDP, tRES) in (62.5ns) units -// wait necessary just after DPM enter/exit (cut and try) -#define WAIT_AFTER_DPM_ENTER 10 // usec -#define WAIT_AFTER_DPM_EXIT 50 // usec -#endif - -static int sck_delay_saved = 0; -#ifdef NRF_DEBUG_PRINT -extern void dbg_dumpQSPIreg(void); -#else -#define dbg_dumpQSPIreg(...) -#endif - void qspi_flash_enter_sleep(void) { #ifdef QSPI_FLASH_POWERDOWN uint32_t r;