Skip to content

Commit f437518

Browse files
authored
Merge pull request #5948 from EmergReanimator/spi_flash_fix
Spi flash fix
2 parents a04cd64 + cfa7e8a commit f437518

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

supervisor/shared/external_flash/spi_flash.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ bool spi_flash_sector_command(uint8_t command, uint32_t address) {
105105

106106
bool spi_flash_write_data(uint32_t address, uint8_t *data, uint32_t data_length) {
107107
uint8_t request[4] = {CMD_PAGE_PROGRAM, 0x00, 0x00, 0x00};
108+
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
108109
// Write the SPI flash write address into the bytes following the command byte.
109110
address_to_bytes(address, request + 1);
110111
if (!flash_enable()) {
111112
return false;
112113
}
113-
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
114114
bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, request, 4);
115115
if (status) {
116116
status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, data, data_length);
@@ -126,12 +126,12 @@ bool spi_flash_read_data(uint32_t address, uint8_t *data, uint32_t data_length)
126126
request[0] = CMD_FAST_READ_DATA;
127127
command_length = 5;
128128
}
129+
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
129130
// Write the SPI flash read address into the bytes following the command byte.
130131
address_to_bytes(address, request + 1);
131132
if (!flash_enable()) {
132133
return false;
133134
}
134-
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
135135
bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, request, command_length);
136136
if (status) {
137137
status = common_hal_busio_spi_read(&supervisor_flash_spi_bus, data, data_length, 0xff);
@@ -144,14 +144,15 @@ void spi_flash_init(void) {
144144
cs_pin.base.type = &digitalio_digitalinout_type;
145145
common_hal_digitalio_digitalinout_construct(&cs_pin, SPI_FLASH_CS_PIN);
146146

147-
148147
// Set CS high (disabled).
149148
common_hal_digitalio_digitalinout_switch_to_output(&cs_pin, true, DRIVE_MODE_PUSH_PULL);
150149
common_hal_digitalio_digitalinout_never_reset(&cs_pin);
151150

152151
supervisor_flash_spi_bus.base.type = &busio_spi_type;
153152
common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN);
154153
common_hal_busio_spi_never_reset(&supervisor_flash_spi_bus);
154+
155+
return;
155156
}
156157

157158
void spi_flash_init_device(const external_flash_device *device) {
@@ -160,4 +161,6 @@ void spi_flash_init_device(const external_flash_device *device) {
160161
if (spi_flash_baudrate > SPI_FLASH_MAX_BAUDRATE) {
161162
spi_flash_baudrate = SPI_FLASH_MAX_BAUDRATE;
162163
}
164+
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
165+
return;
163166
}

0 commit comments

Comments
 (0)