Skip to content

Commit 2a1f586

Browse files
Avoid excessive SPI re-configuration in run-time of SPI flash.
1 parent f610b6b commit 2a1f586

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

supervisor/shared/external_flash/spi_flash.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ 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);
109108
// Write the SPI flash write address into the bytes following the command byte.
110109
address_to_bytes(address, request + 1);
111110
if (!flash_enable()) {
@@ -126,7 +125,6 @@ bool spi_flash_read_data(uint32_t address, uint8_t *data, uint32_t data_length)
126125
request[0] = CMD_FAST_READ_DATA;
127126
command_length = 5;
128127
}
129-
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
130128
// Write the SPI flash read address into the bytes following the command byte.
131129
address_to_bytes(address, request + 1);
132130
if (!flash_enable()) {
@@ -144,14 +142,15 @@ void spi_flash_init(void) {
144142
cs_pin.base.type = &digitalio_digitalinout_type;
145143
common_hal_digitalio_digitalinout_construct(&cs_pin, SPI_FLASH_CS_PIN);
146144

147-
148145
// Set CS high (disabled).
149146
common_hal_digitalio_digitalinout_switch_to_output(&cs_pin, true, DRIVE_MODE_PUSH_PULL);
150147
common_hal_digitalio_digitalinout_never_reset(&cs_pin);
151148

152149
supervisor_flash_spi_bus.base.type = &busio_spi_type;
153150
common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN);
154151
common_hal_busio_spi_never_reset(&supervisor_flash_spi_bus);
152+
153+
return;
155154
}
156155

157156
void spi_flash_init_device(const external_flash_device *device) {
@@ -160,4 +159,6 @@ void spi_flash_init_device(const external_flash_device *device) {
160159
if (spi_flash_baudrate > SPI_FLASH_MAX_BAUDRATE) {
161160
spi_flash_baudrate = SPI_FLASH_MAX_BAUDRATE;
162161
}
162+
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
163+
return;
163164
}

0 commit comments

Comments
 (0)