Skip to content

Commit 7c692f5

Browse files
author
Veijo Pesonen
committed
SPIFBlockDevice: Refactor vendor specific workarounds
To follow the same convention as with QSPIFBlockDevice there was need to create a separate function for handling vendor specific workarounds.
1 parent 98dbebb commit 7c692f5

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ int QSPIFBlockDevice::init()
226226
goto exit_point;
227227
}
228228

229-
if (0 != _handle_vendor_quirks()) {
229+
if (_handle_vendor_quirks() < 0) {
230230
tr_error("Init - Could not read vendor id");
231231
status = QSPIF_BD_ERROR_DEVICE_ERROR;
232232
goto exit_point;

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
306306
// Enable Fast Mode - for flash chips with low power default
307307
int _enable_fast_mode();
308308

309+
// Query vendor ID and handle special behavior that isn't covered by SFDP data
310+
int _handle_vendor_quirks();
311+
309312
/****************************************/
310313
/* SFDP Detection and Parsing Functions */
311314
/****************************************/
@@ -329,9 +332,6 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
329332
// Detect 4-byte addressing mode and enable it if supported
330333
int _sfdp_detect_and_enable_4byte_addressing(uint8_t *basic_param_table_ptr, int basic_param_table_size);
331334

332-
// Query vendor ID and handle special behavior that isn't covered by SFDP data
333-
int _handle_vendor_quirks();
334-
335335
/***********************/
336336
/* Utilities Functions */
337337
/***********************/

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ SPIFBlockDevice::SPIFBlockDevice(PinName mosi, PinName miso, PinName sclk, PinNa
115115

116116
int SPIFBlockDevice::init()
117117
{
118-
uint8_t vendor_device_ids[4];
119-
size_t data_length = 3;
120118
int status = SPIF_BD_ERROR_OK;
121-
spif_bd_error spi_status = SPIF_BD_ERROR_OK;
122119

123120
_mutex->lock();
124121

@@ -141,24 +138,12 @@ int SPIFBlockDevice::init()
141138
tr_debug("Initialize flash memory OK");
142139
}
143140

144-
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
145-
spi_status = _spi_send_general_command(SPIF_RDID, SPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)vendor_device_ids,
146-
data_length);
147-
if (spi_status != SPIF_BD_ERROR_OK) {
148-
tr_error("init - Read Vendor ID Failed");
141+
if (_handle_vendor_quirks() < 0) {
142+
tr_error("Init - Could not read vendor id");
149143
status = SPIF_BD_ERROR_DEVICE_ERROR;
150144
goto exit_point;
151145
}
152146

153-
switch (vendor_device_ids[0]) {
154-
case 0xbf:
155-
// SST devices come preset with block protection
156-
// enabled for some regions, issue global protection unlock to clear
157-
_set_write_enable();
158-
_spi_send_general_command(SPIF_ULBPR, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0);
159-
break;
160-
}
161-
162147
//Synchronize Device
163148
if (false == _is_mem_ready()) {
164149
tr_error("init - _is_mem_ready Failed");
@@ -764,3 +749,32 @@ int SPIFBlockDevice::_set_write_enable()
764749
} while (false);
765750
return status;
766751
}
752+
753+
int SPIFBlockDevice::_handle_vendor_quirks()
754+
{
755+
uint8_t vendor_device_ids[4];
756+
size_t data_length = 3;
757+
758+
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
759+
spif_bd_error spi_status = _spi_send_general_command(SPIF_RDID, SPI_NO_ADDRESS_COMMAND, NULL, 0,
760+
(char *)vendor_device_ids,
761+
data_length);
762+
763+
if (spi_status != SPIF_BD_ERROR_OK) {
764+
tr_error("Read Vendor ID Failed");
765+
return -1;
766+
}
767+
768+
tr_debug("Vendor device ID = 0x%x 0x%x 0x%x", vendor_device_ids[0], vendor_device_ids[1], vendor_device_ids[2]);
769+
770+
switch (vendor_device_ids[0]) {
771+
case 0xbf:
772+
// SST devices come preset with block protection
773+
// enabled for some regions, issue global protection unlock to clear
774+
_set_write_enable();
775+
_spi_send_general_command(SPIF_ULBPR, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0);
776+
break;
777+
}
778+
779+
return 0;
780+
}

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class SPIFBlockDevice : public mbed::BlockDevice {
260260
// Wait on status register until write not-in-progress
261261
bool _is_mem_ready();
262262

263+
// Query vendor ID and handle special behavior that isn't covered by SFDP data
264+
int _handle_vendor_quirks();
265+
263266
private:
264267
// Master side hardware
265268
mbed::SPI _spi;

0 commit comments

Comments
 (0)