Merge pull request #1358 from tannewt/fix_840_qspi

Fix QSPI on Feather nRF52840
This commit is contained in:
Dan Halbert 2018-11-27 08:38:35 -05:00 committed by GitHub
commit 4e8531f4a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

@ -20,6 +20,6 @@ endif
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 NRF_DEFINES += -DNRF52840_XXAA -DNRF52840
SPI_FLASH_FILESYSTEM = 1 QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICE_COUNT = 1 EXTERNAL_FLASH_DEVICE_COUNT = 1
EXTERNAL_FLASH_DEVICES = "GD25Q16C" EXTERNAL_FLASH_DEVICES = "GD25Q16C"

View File

@ -115,7 +115,7 @@ void spi_flash_init(void) {
.dpmconfig = false .dpmconfig = false
}, },
.phy_if = { .phy_if = {
.sck_freq = NRF_QSPI_FREQ_32MDIV16, .sck_freq = NRF_QSPI_FREQ_32MDIV16, // Start at a slow 2mhz and speed up once we know what we're talking to.
.sck_delay = 10, // min time CS must stay high before going low again. in unit of 62.5 ns .sck_delay = 10, // min time CS must stay high before going low again. in unit of 62.5 ns
.spi_mode = NRF_QSPI_MODE_0, .spi_mode = NRF_QSPI_MODE_0,
.dpmen = false .dpmen = false
@ -132,7 +132,7 @@ void spi_flash_init(void) {
qspi_cfg.pins.io2_pin = MICROPY_QSPI_DATA2; qspi_cfg.pins.io2_pin = MICROPY_QSPI_DATA2;
qspi_cfg.pins.io3_pin = MICROPY_QSPI_DATA3; qspi_cfg.pins.io3_pin = MICROPY_QSPI_DATA3;
qspi_cfg.prot_if.readoc = NRF_QSPI_READOC_READ4IO; qspi_cfg.prot_if.readoc = NRF_QSPI_READOC_READ4IO;
qspi_cfg.prot_if.writeoc = NRF_QSPI_WRITEOC_PP4IO; qspi_cfg.prot_if.writeoc = NRF_QSPI_WRITEOC_PP4O;
#endif #endif
// No callback for blocking API // No callback for blocking API
@ -142,5 +142,17 @@ void spi_flash_init(void) {
void spi_flash_init_device(const external_flash_device* device) { void spi_flash_init_device(const external_flash_device* device) {
check_quad_enable(device); check_quad_enable(device);
// TODO(tannewt): Adjust the speed for the found device. // Switch to single output line if the device doesn't support quad programs.
if (!device->supports_qspi_writes) {
NRF_QSPI->IFCONFIG0 &= ~QSPI_IFCONFIG0_WRITEOC_Msk;
NRF_QSPI->IFCONFIG0 |= QSPI_IFCONFIG0_WRITEOC_PP;
}
// Speed up as much as we can.
uint8_t sckfreq = 0;
while (32000000 / (sckfreq + 1) > device->max_clock_speed_mhz * 1000000 && sckfreq < 16) {
sckfreq += 1;
}
NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_SCKFREQ_Msk;
NRF_QSPI->IFCONFIG1 |= sckfreq << QSPI_IFCONFIG1_SCKDELAY_Pos;
} }

View File

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