summaryrefslogtreecommitdiff
path: root/ports/nrf/supervisor
diff options
context:
space:
mode:
authorYihui Xiong <yihui.xiong@hotmail.com>2020-08-07 16:23:42 +0800
committerYihui Xiong <yihui.xiong@hotmail.com>2020-08-07 16:23:42 +0800
commitaf1291ec28a8d2881e820fc1ce9b938ab5a6f097 (patch)
tree8d84c9da2651b569cb9c32b9ec9f8f71dc0fa597 /ports/nrf/supervisor
parentd8257380d7e1658d710bf841424a64c2c6451d5f (diff)
dynamically enable or disable QSPI by default
Diffstat (limited to 'ports/nrf/supervisor')
-rw-r--r--ports/nrf/supervisor/port.c4
-rw-r--r--ports/nrf/supervisor/qspi_flash.c40
2 files changed, 17 insertions, 27 deletions
diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c
index 36c9f836e..87a4d7396 100644
--- a/ports/nrf/supervisor/port.c
+++ b/ports/nrf/supervisor/port.c
@@ -65,7 +65,7 @@
#include "common-hal/audiopwmio/PWMAudioOut.h"
#endif
-#if defined(MICROPY_QSPI_CS) && defined(MICROPY_QSPI_OFF_WHEN_SLEEP)
+#if defined(MICROPY_QSPI_CS)
extern void qspi_disable(void);
#endif
@@ -299,7 +299,7 @@ void port_interrupt_after_ticks(uint32_t ticks) {
}
void port_sleep_until_interrupt(void) {
-#if defined(MICROPY_QSPI_CS) && defined(MICROPY_QSPI_OFF_WHEN_SLEEP)
+#if defined(MICROPY_QSPI_CS)
qspi_disable();
#endif
diff --git a/ports/nrf/supervisor/qspi_flash.c b/ports/nrf/supervisor/qspi_flash.c
index 852f0c44a..5ab56c6bc 100644
--- a/ports/nrf/supervisor/qspi_flash.c
+++ b/ports/nrf/supervisor/qspi_flash.c
@@ -39,7 +39,21 @@
#include "supervisor/shared/external_flash/qspi_flash.h"
// When USB is disconnected, disable QSPI in sleep mode to save energy
-#if defined(MICROPY_QSPI_OFF_WHEN_SLEEP)
+void qspi_disable(void)
+{
+ // If VBUS is detected, no need to disable QSPI
+ if (NRF_QSPI->ENABLE && !(NRF_POWER->USBREGSTATUS & POWER_USBREGSTATUS_VBUSDETECT_Msk)) {
+ // Keep CS high when QSPI is diabled
+ nrf_gpio_cfg_output(MICROPY_QSPI_CS);
+ nrf_gpio_pin_write(MICROPY_QSPI_CS, 1);
+
+ // Workaround to disable QSPI according to nRF52840 Revision 1 Errata V1.4 - 3.8
+ NRF_QSPI->TASKS_DEACTIVATE = 1;
+ *(volatile uint32_t *)0x40029054 = 1;
+ NRF_QSPI->ENABLE = 0;
+ }
+}
+
void qspi_enable(void)
{
if (NRF_QSPI->ENABLE) {
@@ -60,30 +74,6 @@ void qspi_enable(void)
} while (--remaining_attempts);
}
-void qspi_disable(void)
-{
- // Turn off QSPI when USB is disconnected
- if (NRF_QSPI->ENABLE && !(NRF_POWER->USBREGSTATUS & POWER_USBREGSTATUS_VBUSDETECT_Msk)) {
- // Keep CS high when QSPI is diabled
- nrf_gpio_cfg_output(MICROPY_QSPI_CS);
- nrf_gpio_pin_write(MICROPY_QSPI_CS, 1);
-
- // Workaround to disable QSPI according to nRF52840 Revision 1 Errata V1.4 - 3.8
- NRF_QSPI->TASKS_DEACTIVATE = 1;
- *(volatile uint32_t *)0x40029054 = 1;
- NRF_QSPI->ENABLE = 0;
- }
-}
-#else
-void qspi_enable(void)
-{
-}
-
-void qspi_disable(void)
-{
-}
-#endif
-
bool spi_flash_command(uint8_t command) {
qspi_enable();
nrf_qspi_cinstr_conf_t cinstr_cfg = {