Skip to content

Commit bce6d12

Browse files
committed
Don't check for corrupt heap too early; Fix QSPI timing
1 parent ca60a03 commit bce6d12

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

ports/nrf/supervisor/qspi_flash.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@
4040

4141
bool spi_flash_command(uint8_t command) {
4242
nrf_qspi_cinstr_conf_t cinstr_cfg = {
43-
.opcode = 0,
44-
.length = 0,
43+
.opcode = command,
44+
.length = 1,
4545
.io2_level = true,
4646
.io3_level = true,
4747
.wipwait = false,
4848
.wren = false
4949
};
50-
cinstr_cfg.opcode = command;
51-
cinstr_cfg.length = 1;
5250
nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
5351
return true;
5452
}
@@ -91,8 +89,7 @@ bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t length) {
9189
}
9290

9391
bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t length) {
94-
nrfx_qspi_read(data, length, address);
95-
return true;
92+
return nrfx_qspi_read(data, length, address) == NRFX_SUCCESS;
9693
}
9794

9895
void spi_flash_init(void) {
@@ -115,7 +112,7 @@ void spi_flash_init(void) {
115112
.dpmconfig = false
116113
},
117114
.phy_if = {
118-
.sck_freq = NRF_QSPI_FREQ_32MDIV16, // Start at a slow 2mhz and speed up once we know what we're talking to.
115+
.sck_freq = NRF_QSPI_FREQ_32MDIV16, // Start at a slow 2MHz and speed up once we know what we're talking to.
119116
.sck_delay = 10, // min time CS must stay high before going low again. in unit of 62.5 ns
120117
.spi_mode = NRF_QSPI_MODE_0,
121118
.dpmen = false
@@ -145,14 +142,19 @@ void spi_flash_init_device(const external_flash_device* device) {
145142
// Switch to single output line if the device doesn't support quad programs.
146143
if (!device->supports_qspi_writes) {
147144
NRF_QSPI->IFCONFIG0 &= ~QSPI_IFCONFIG0_WRITEOC_Msk;
148-
NRF_QSPI->IFCONFIG0 |= QSPI_IFCONFIG0_WRITEOC_PP;
145+
NRF_QSPI->IFCONFIG0 |= QSPI_IFCONFIG0_WRITEOC_PP << QSPI_IFCONFIG0_WRITEOC_Pos;
149146
}
150147

151148
// Speed up as much as we can.
152149
uint8_t sckfreq = 0;
153150
while (32000000 / (sckfreq + 1) > device->max_clock_speed_mhz * 1000000 && sckfreq < 16) {
154151
sckfreq += 1;
155152
}
153+
// No more than 16 MHz. At 32 MHz GD25Q16C doesn't work reliably on Feather 52840, even though
154+
// it should work up to 104 MHz.
155+
// sckfreq = 0 is 32 Mhz
156+
// sckfreq = 1 is 16 MHz, etc.
157+
sckfreq = MAX(1, sckfreq);
156158
NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_SCKFREQ_Msk;
157-
NRF_QSPI->IFCONFIG1 |= sckfreq << QSPI_IFCONFIG1_SCKDELAY_Pos;
159+
NRF_QSPI->IFCONFIG1 |= sckfreq << QSPI_IFCONFIG1_SCKFREQ_Pos;
158160
}

supervisor/shared/stack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void allocate_stack(void) {
5656
}
5757

5858
inline bool stack_ok(void) {
59-
return *stack_alloc->ptr == STACK_CANARY_VALUE;
59+
return stack_alloc == NULL || *stack_alloc->ptr == STACK_CANARY_VALUE;
6060
}
6161

6262
inline void assert_heap_ok(void) {

0 commit comments

Comments
 (0)