Skip to content

Commit 61881e8

Browse files
authored
Merge pull request #10756 from martinichka/feature-correct-trace-level-storage-spif
Cleaned up trace log SPIF Block Device
2 parents fe6f458 + 8a328dd commit 61881e8

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ SPIFBlockDevice::SPIFBlockDevice(
120120
_region_erase_types_bitfield[0] = ERASE_BITMASK_NONE;
121121

122122
if (SPIF_BD_ERROR_OK != _spi_set_frequency(freq)) {
123-
tr_error("ERROR: SPI Set Frequency Failed");
123+
tr_error("SPI Set Frequency Failed");
124124
}
125125

126126
_cs = 1;
@@ -151,7 +151,7 @@ int SPIFBlockDevice::init()
151151

152152
// Soft Reset
153153
if (-1 == _reset_flash_mem()) {
154-
tr_error("ERROR: init - Unable to initialize flash memory, tests failed\n");
154+
tr_error("init - Unable to initialize flash memory, tests failed");
155155
status = SPIF_BD_ERROR_DEVICE_ERROR;
156156
goto exit_point;
157157
}
@@ -160,7 +160,7 @@ int SPIFBlockDevice::init()
160160
spi_status = _spi_send_general_command(SPIF_RDID, SPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)vendor_device_ids,
161161
data_length);
162162
if (spi_status != SPIF_BD_ERROR_OK) {
163-
tr_error("ERROR: init - Read Vendor ID Failed");
163+
tr_error("init - Read Vendor ID Failed");
164164
status = SPIF_BD_ERROR_DEVICE_ERROR;
165165
goto exit_point;
166166
}
@@ -176,22 +176,22 @@ int SPIFBlockDevice::init()
176176

177177
//Synchronize Device
178178
if (false == _is_mem_ready()) {
179-
tr_error("ERROR: init - _is_mem_ready Failed");
179+
tr_error("init - _is_mem_ready Failed");
180180
status = SPIF_BD_ERROR_READY_FAILED;
181181
goto exit_point;
182182
}
183183

184184
/**************************** Parse SFDP Header ***********************************/
185185
if (0 != _sfdp_parse_sfdp_headers(basic_table_addr, basic_table_size, sector_map_table_addr, sector_map_table_size)) {
186-
tr_error("ERROR: init - Parse SFDP Headers Failed");
186+
tr_error("init - Parse SFDP Headers Failed");
187187
status = SPIF_BD_ERROR_PARSING_FAILED;
188188
goto exit_point;
189189
}
190190

191191

192192
/**************************** Parse Basic Parameters Table ***********************************/
193193
if (0 != _sfdp_parse_basic_param_table(basic_table_addr, basic_table_size)) {
194-
tr_error("ERROR: init - Parse Basic Param Table Failed");
194+
tr_error("init - Parse Basic Param Table Failed");
195195
status = SPIF_BD_ERROR_PARSING_FAILED;
196196
goto exit_point;
197197
}
@@ -203,7 +203,7 @@ int SPIFBlockDevice::init()
203203

204204
if ((sector_map_table_addr != 0) && (0 != sector_map_table_size)) {
205205
if (0 != _sfdp_parse_sector_map_table(sector_map_table_addr, sector_map_table_size)) {
206-
tr_error("ERROR: init - Parse Sector Map Table Failed");
206+
tr_error("init - Parse Sector Map Table Failed");
207207
status = SPIF_BD_ERROR_PARSING_FAILED;
208208
goto exit_point;
209209
}
@@ -213,6 +213,7 @@ int SPIFBlockDevice::init()
213213
// Dummy And Mode Cycles Back default 0
214214
_dummy_and_mode_cycles = _write_dummy_and_mode_cycles;
215215
_is_initialized = true;
216+
tr_debug("Device size: %llu Kbytes", _device_size_bytes / 1024);
216217

217218
if (_device_size_bytes > (1 << 24)) {
218219
tr_debug("Size is bigger than 16MB and thus address does not fit in 3 byte, switch to 4 byte address mode");
@@ -247,7 +248,7 @@ int SPIFBlockDevice::deinit()
247248
// Disable Device for Writing
248249
status = _spi_send_general_command(SPIF_WRDI, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0);
249250
if (status != SPIF_BD_ERROR_OK) {
250-
tr_error("ERROR: Write Disable failed");
251+
tr_error("Write Disable failed");
251252
}
252253
_is_initialized = false;
253254

@@ -299,7 +300,7 @@ int SPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
299300

300301
//Send WREN
301302
if (_set_write_enable() != 0) {
302-
tr_error("ERROR: Write Enabe failed\n");
303+
tr_error("Write Enabe failed");
303304
program_failed = true;
304305
status = SPIF_BD_ERROR_WREN_FAILED;
305306
goto exit_point;
@@ -312,7 +313,7 @@ int SPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
312313
size -= chunk;
313314

314315
if (false == _is_mem_ready()) {
315-
tr_error("ERROR: Device not ready after write, failed\n");
316+
tr_error("Device not ready after write, failed");
316317
program_failed = true;
317318
status = SPIF_BD_ERROR_READY_FAILED;
318319
goto exit_point;
@@ -347,12 +348,12 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
347348
uint8_t bitfield = _region_erase_types_bitfield[region];
348349

349350
if ((addr + in_size) > _device_size_bytes) {
350-
tr_error("ERROR: erase exceeds flash device size");
351+
tr_error("erase exceeds flash device size");
351352
return SPIF_BD_ERROR_INVALID_ERASE_PARAMS;
352353
}
353354

354355
if (((addr % get_erase_size(addr)) != 0) || (((addr + in_size) % get_erase_size(addr + in_size - 1)) != 0)) {
355-
tr_error("ERROR: invalid erase - unaligned address and size");
356+
tr_error("invalid erase - unaligned address and size");
356357
return SPIF_BD_ERROR_INVALID_ERASE_PARAMS;
357358
}
358359

@@ -369,7 +370,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
369370
_mutex->lock();
370371

371372
if (_set_write_enable() != 0) {
372-
tr_error("ERROR: SPI Erase Device not ready - failed");
373+
tr_error("SPI Erase Device not ready - failed");
373374
erase_failed = true;
374375
status = SPIF_BD_ERROR_READY_FAILED;
375376
goto exit_point;
@@ -387,7 +388,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
387388
}
388389

389390
if (false == _is_mem_ready()) {
390-
tr_error("ERROR: SPI After Erase Device not ready - failed\n");
391+
tr_error("SPI After Erase Device not ready - failed");
391392
erase_failed = true;
392393
status = SPIF_BD_ERROR_READY_FAILED;
393394
goto exit_point;
@@ -446,7 +447,7 @@ bd_size_t SPIFBlockDevice::get_erase_size(bd_addr_t addr)
446447
}
447448

448449
if (i_ind == 4) {
449-
tr_error("ERROR: no erase type was found for region addr");
450+
tr_error("no erase type was found for region addr");
450451
}
451452
}
452453

@@ -605,19 +606,19 @@ int SPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_addr
605606
spif_bd_error status = _spi_send_read_command(SPIF_SFDP, sector_map_table, sector_map_table_addr /*address*/,
606607
sector_map_table_size);
607608
if (status != SPIF_BD_ERROR_OK) {
608-
tr_error("ERROR: init - Read SFDP First Table Failed");
609+
tr_error("init - Read SFDP First Table Failed");
609610
return -1;
610611
}
611612

612613
// Currently we support only Single Map Descriptor
613614
if (!((sector_map_table[0] & 0x3) == 0x03) && (sector_map_table[1] == 0x0)) {
614-
tr_error("ERROR: Sector Map - Supporting Only Single! Map Descriptor (not map commands)");
615+
tr_error("Sector Map - Supporting Only Single! Map Descriptor (not map commands)");
615616
return -1;
616617
}
617618

618619
_regions_count = sector_map_table[2] + 1;
619620
if (_regions_count > SPIF_MAX_REGIONS) {
620-
tr_error("ERROR: Supporting up to %d regions, current setup to %d regions - fail",
621+
tr_error("Supporting up to %d regions, current setup to %d regions - fail",
621622
SPIF_MAX_REGIONS, _regions_count);
622623
return -1;
623624
}
@@ -659,13 +660,13 @@ int SPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, si
659660
spif_bd_error status = _spi_send_read_command(SPIF_SFDP, param_table, basic_table_addr /*address*/,
660661
basic_table_size);
661662
if (status != SPIF_BD_ERROR_OK) {
662-
tr_error("ERROR: init - Read SFDP First Table Failed");
663+
tr_error("init - Read SFDP First Table Failed");
663664
return -1;
664665
}
665666

666667
// Check address size, currently only supports 3byte addresses
667668
if ((param_table[2] & 0x4) != 0 || (param_table[7] & 0x80) != 0) {
668-
tr_error("ERROR: init - verify 3byte addressing Failed");
669+
tr_error("init - verify 3byte addressing Failed");
669670
return -1;
670671
}
671672

@@ -676,6 +677,7 @@ int SPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, si
676677
(param_table[5] << 8) |
677678
param_table[4]);
678679
_device_size_bytes = (density_bits + 1) / 8;
680+
tr_debug("Density bits: %ld , device size: %llu bytes", density_bits, _device_size_bytes);
679681

680682
// Set Default read/program/erase Instructions
681683
_read_instruction = SPIF_READ;
@@ -711,14 +713,14 @@ int SPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_t
711713

712714
spif_bd_error status = _spi_send_read_command(SPIF_SFDP, sfdp_header, addr /*address*/, data_length);
713715
if (status != SPIF_BD_ERROR_OK) {
714-
tr_error("ERROR: init - Read SFDP Failed");
716+
tr_error("init - Read SFDP Failed");
715717
return -1;
716718
}
717719

718720
// Verify SFDP signature for sanity
719721
// Also check that major/minor version is acceptable
720722
if (!(memcmp(&sfdp_header[0], "SFDP", 4) == 0 && sfdp_header[5] == 1)) {
721-
tr_error("ERROR: init - _verify SFDP signature and version Failed");
723+
tr_error("init - _verify SFDP signature and version Failed");
722724
return -1;
723725
}
724726

@@ -733,14 +735,14 @@ int SPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_t
733735

734736
status = _spi_send_read_command(SPIF_SFDP, param_header, addr, data_length);
735737
if (status != SPIF_BD_ERROR_OK) {
736-
tr_error("ERROR: init - Read Param Table %d Failed", i_ind + 1);
738+
tr_error("init - Read Param Table %d Failed", i_ind + 1);
737739
return -1;
738740
}
739741

740742
// The SFDP spec indicates the standard table is always at offset 0
741743
// in the parameter headers, we check just to be safe
742744
if (param_header[2] != 1) {
743-
tr_error("ERROR: Param Table %d - Major Version should be 1!", i_ind + 1);
745+
tr_error("Param Table %d - Major Version should be 1!", i_ind + 1);
744746
return -1;
745747
}
746748

@@ -806,7 +808,7 @@ int SPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param
806808
if (erase4k_inst != erase_type_inst_arr[i_ind]) {
807809
//Verify 4KErase Type is identical to Legacy 4K erase type specified in Byte 1 of Param Table
808810
erase4k_inst = erase_type_inst_arr[i_ind];
809-
tr_warning("WARNING: _detectEraseTypesInstAndSize - Default 4K erase Inst is different than erase type Inst for 4K");
811+
tr_warning("_detectEraseTypesInstAndSize - Default 4K erase Inst is different than erase type Inst for 4K");
810812

811813
}
812814
}
@@ -818,7 +820,7 @@ int SPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param
818820
}
819821

820822
if (false == found_4Kerase_type) {
821-
tr_warning("WARNING: Couldn't find Erase Type for 4KB size");
823+
tr_warning("Couldn't find Erase Type for 4KB size");
822824
}
823825
return 0;
824826
}
@@ -881,7 +883,7 @@ int SPIFBlockDevice::_reset_flash_mem()
881883
if (SPIF_BD_ERROR_OK == _spi_send_general_command(SPIF_RSTEN, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0)) {
882884
// store received values in status_value
883885
} else {
884-
tr_error("ERROR: Sending RSTEN failed\n");
886+
tr_error("Sending RSTEN failed");
885887
status = -1;
886888
}
887889

@@ -890,7 +892,7 @@ int SPIFBlockDevice::_reset_flash_mem()
890892
if (SPIF_BD_ERROR_OK == _spi_send_general_command(SPIF_RST, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0)) {
891893
// store received values in status_value
892894
} else {
893-
tr_error("ERROR: Sending RST failed\n");
895+
tr_error("Sending RST failed");
894896
status = -1;
895897
}
896898
_is_mem_ready();
@@ -913,12 +915,12 @@ bool SPIFBlockDevice::_is_mem_ready()
913915
//Read the Status Register from device
914916
if (SPIF_BD_ERROR_OK != _spi_send_general_command(SPIF_RDSR, SPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,
915917
1)) { // store received values in status_value
916-
tr_error("ERROR: Reading Status Register failed\n");
918+
tr_error("Reading Status Register failed");
917919
}
918920
} while ((status_value[0] & SPIF_STATUS_BIT_WIP) != 0 && retries < IS_MEM_READY_MAX_RETRIES);
919921

920922
if ((status_value[0] & SPIF_STATUS_BIT_WIP) != 0) {
921-
tr_error("ERROR: _is_mem_ready FALSE\n");
923+
tr_error("_is_mem_ready FALSE");
922924
mem_ready = false;
923925
}
924926
return mem_ready;
@@ -932,24 +934,24 @@ int SPIFBlockDevice::_set_write_enable()
932934

933935
do {
934936
if (SPIF_BD_ERROR_OK != _spi_send_general_command(SPIF_WREN, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0)) {
935-
tr_error("ERROR:Sending WREN command FAILED\n");
937+
tr_error("Sending WREN command FAILED");
936938
break;
937939
}
938940

939941
if (false == _is_mem_ready()) {
940-
tr_error("ERROR: Device not ready, write failed");
942+
tr_error("Device not ready, write failed");
941943
break;
942944
}
943945

944946
memset(status_value, 0, 2);
945947
if (SPIF_BD_ERROR_OK != _spi_send_general_command(SPIF_RDSR, SPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,
946948
1)) { // store received values in status_value
947-
tr_error("ERROR: Reading Status Register failed\n");
949+
tr_error("Reading Status Register failed");
948950
break;
949951
}
950952

951953
if ((status_value[0] & SPIF_STATUS_BIT_WEL) == 0) {
952-
tr_error("ERROR: _set_write_enable failed\n");
954+
tr_error("_set_write_enable failed");
953955
break;
954956
}
955957
status = 0;
@@ -1002,7 +1004,7 @@ int SPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t &bitfield, i
10021004
}
10031005

10041006
if (i_ind == 4) {
1005-
tr_error("ERROR: no erase type was found for current region addr");
1007+
tr_error("no erase type was found for current region addr");
10061008
}
10071009
return largest_erase_type;
10081010

0 commit comments

Comments
 (0)