Skip to content

Commit 4e8531f

Browse files
authored
Merge pull request #1358 from tannewt/fix_840_qspi
Fix QSPI on Feather nRF52840
2 parents 027ed82 + d446d32 commit 4e8531f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ endif
2020

2121
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840
2222

23-
SPI_FLASH_FILESYSTEM = 1
23+
QSPI_FLASH_FILESYSTEM = 1
2424
EXTERNAL_FLASH_DEVICE_COUNT = 1
2525
EXTERNAL_FLASH_DEVICES = "GD25Q16C"

ports/nrf/supervisor/qspi_flash.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void spi_flash_init(void) {
115115
.dpmconfig = false
116116
},
117117
.phy_if = {
118-
.sck_freq = NRF_QSPI_FREQ_32MDIV16,
118+
.sck_freq = NRF_QSPI_FREQ_32MDIV16, // Start at a slow 2mhz and speed up once we know what we're talking to.
119119
.sck_delay = 10, // min time CS must stay high before going low again. in unit of 62.5 ns
120120
.spi_mode = NRF_QSPI_MODE_0,
121121
.dpmen = false
@@ -132,7 +132,7 @@ void spi_flash_init(void) {
132132
qspi_cfg.pins.io2_pin = MICROPY_QSPI_DATA2;
133133
qspi_cfg.pins.io3_pin = MICROPY_QSPI_DATA3;
134134
qspi_cfg.prot_if.readoc = NRF_QSPI_READOC_READ4IO;
135-
qspi_cfg.prot_if.writeoc = NRF_QSPI_WRITEOC_PP4IO;
135+
qspi_cfg.prot_if.writeoc = NRF_QSPI_WRITEOC_PP4O;
136136
#endif
137137

138138
// No callback for blocking API
@@ -142,5 +142,17 @@ void spi_flash_init(void) {
142142
void spi_flash_init_device(const external_flash_device* device) {
143143
check_quad_enable(device);
144144

145-
// TODO(tannewt): Adjust the speed for the found device.
145+
// Switch to single output line if the device doesn't support quad programs.
146+
if (!device->supports_qspi_writes) {
147+
NRF_QSPI->IFCONFIG0 &= ~QSPI_IFCONFIG0_WRITEOC_Msk;
148+
NRF_QSPI->IFCONFIG0 |= QSPI_IFCONFIG0_WRITEOC_PP;
149+
}
150+
151+
// Speed up as much as we can.
152+
uint8_t sckfreq = 0;
153+
while (32000000 / (sckfreq + 1) > device->max_clock_speed_mhz * 1000000 && sckfreq < 16) {
154+
sckfreq += 1;
155+
}
156+
NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_SCKFREQ_Msk;
157+
NRF_QSPI->IFCONFIG1 |= sckfreq << QSPI_IFCONFIG1_SCKDELAY_Pos;
146158
}

supervisor/shared/external_flash/devices.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ typedef struct {
8686
}
8787

8888
// Settings for the Gigadevice GD25Q16C 2MiB SPI flash.
89-
// Datasheet: http://www.gigadevice.com/wp-content/uploads/2017/12/DS-00086-GD25Q16C-Rev2.6.pdf
89+
// Datasheet: http://www.gigadevice.com/datasheet/gd25q16c/
9090
#define GD25Q16C {\
9191
.total_size = (1 << 21), /* 2 MiB */ \
9292
.start_up_time_us = 5000, \

0 commit comments

Comments
 (0)