Skip to content

Commit 4f9fcf8

Browse files
author
Veijo Pesonen
committed
Bugfix: Concurrent SFDP header address init fixed
After switching from local variables to shared info structure JEDEC Basic Flash Parameter Table and Sector Map Parameter Table addresses and sizes must be protected by a mutex. Theoretically multiple calls to Q/SPIFBlockDevice might occur.
1 parent c84deff commit 4f9fcf8

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinNam
179179

180180
int QSPIFBlockDevice::init()
181181
{
182+
int status = QSPIF_BD_ERROR_OK;
183+
182184
if (_unique_device_status == 0) {
183185
tr_debug("QSPIFBlockDevice csel: %d", (int)_csel);
184186
} else if (_unique_device_status == -1) {
@@ -189,12 +191,6 @@ int QSPIFBlockDevice::init()
189191
return QSPIF_BD_ERROR_DEVICE_MAX_EXCEED;
190192
}
191193

192-
int status = QSPIF_BD_ERROR_OK;
193-
_sfdp_info.bptbl.addr = 0x0;
194-
_sfdp_info.bptbl.size = 0;
195-
_sfdp_info.smptbl.addr = 0x0;
196-
_sfdp_info.smptbl.size = 0;
197-
198194
_mutex.lock();
199195

200196
// All commands other than Read and RSFDP use default 1-1-1 bus mode (Program/Erase are constrained by flash memory performance more than bus performance)
@@ -236,6 +232,11 @@ int QSPIFBlockDevice::init()
236232
goto exit_point;
237233
}
238234

235+
_sfdp_info.bptbl.addr = 0x0;
236+
_sfdp_info.bptbl.size = 0;
237+
_sfdp_info.smptbl.addr = 0x0;
238+
_sfdp_info.smptbl.size = 0;
239+
239240
/**************************** Parse SFDP Header ***********************************/
240241
if (sfdp_parse_headers(callback(this, &QSPIFBlockDevice::_qspi_send_read_sfdp_command), _sfdp_info) < 0) {
241242
tr_error("Init - Parse SFDP Headers Failed");

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ int SPIFBlockDevice::init()
120120
int status = SPIF_BD_ERROR_OK;
121121
spif_bd_error spi_status = SPIF_BD_ERROR_OK;
122122

123-
_sfdp_info.bptbl.addr = 0x0;
124-
_sfdp_info.bptbl.size = 0;
125-
_sfdp_info.smptbl.addr = 0x0;
126-
_sfdp_info.smptbl.size = 0;
127-
128123
_mutex->lock();
129124

130125
if (!_is_initialized) {
@@ -171,6 +166,11 @@ int SPIFBlockDevice::init()
171166
goto exit_point;
172167
}
173168

169+
_sfdp_info.bptbl.addr = 0x0;
170+
_sfdp_info.bptbl.size = 0;
171+
_sfdp_info.smptbl.addr = 0x0;
172+
_sfdp_info.smptbl.size = 0;
173+
174174
/**************************** Parse SFDP Header ***********************************/
175175
if (sfdp_parse_headers(callback(this, &SPIFBlockDevice::_spi_send_read_sfdp_command), _sfdp_info) < 0) {
176176
tr_error("init - Parse SFDP Headers Failed");

0 commit comments

Comments
 (0)