22
22
#include < inttypes.h>
23
23
24
24
#include " mbed_trace.h"
25
- #include " mbed_debug.h"
26
25
#define TRACE_GROUP " SPIF"
27
26
using namespace mbed ;
28
27
@@ -158,7 +157,7 @@ int SPIFBlockDevice::init()
158
157
status = SPIF_BD_ERROR_DEVICE_ERROR;
159
158
goto exit_point;
160
159
} else {
161
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: Initialize flash memory OK\n " );
160
+ tr_debug ( " Initialize flash memory OK\n " );
162
161
}
163
162
164
163
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
@@ -207,7 +206,7 @@ int SPIFBlockDevice::init()
207
206
_region_high_boundary[0 ] = _device_size_bytes - 1 ;
208
207
209
208
if ((sector_map_table_addr != 0 ) && (0 != sector_map_table_size)) {
210
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: init - Parsing Sector Map Table - addr: 0x%" PRIx32 " h, Size: %d" , sector_map_table_addr,
209
+ tr_debug ( " init - Parsing Sector Map Table - addr: 0x%" PRIx32 " h, Size: %d" , sector_map_table_addr,
211
210
sector_map_table_size);
212
211
if (0 != _sfdp_parse_sector_map_table (sector_map_table_addr, sector_map_table_size)) {
213
212
tr_error (" init - Parse Sector Map Table Failed" );
@@ -272,7 +271,7 @@ int SPIFBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
272
271
}
273
272
274
273
int status = SPIF_BD_ERROR_OK;
275
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG Read - Inst: 0x%xh" , _read_instruction);
274
+ tr_debug ( " Read - Inst: 0x%xh" , _read_instruction);
276
275
_mutex->lock ();
277
276
278
277
// Set Dummy Cycles for Specific Read Command Mode
@@ -298,7 +297,7 @@ int SPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
298
297
uint32_t offset = 0 ;
299
298
uint32_t chunk = 0 ;
300
299
301
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: program - Buff: 0x%" PRIx32 " h, addr: %llu, size: %llu" , (uint32_t )buffer, addr, size);
300
+ tr_debug ( " program - Buff: 0x%" PRIx32 " h, addr: %llu, size: %llu" , (uint32_t )buffer, addr, size);
302
301
303
302
while (size > 0 ) {
304
303
@@ -361,7 +360,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
361
360
// Erase Types of selected region
362
361
uint8_t bitfield = _region_erase_types_bitfield[region];
363
362
364
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: erase - addr: %llu, in_size: %llu" , addr, in_size);
363
+ tr_debug ( " erase - addr: %llu, in_size: %llu" , addr, in_size);
365
364
366
365
if ((addr + in_size) > _device_size_bytes) {
367
366
tr_error (" erase exceeds flash device size" );
@@ -383,9 +382,9 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
383
382
offset = addr % _erase_type_size_arr[type];
384
383
chunk = ((offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
385
384
386
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %" PRIu32 " , " ,
385
+ tr_debug ( " erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %" PRIu32 " , " ,
387
386
addr, size, cur_erase_inst, chunk);
388
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: erase - Region: %d, Type:%d" ,
387
+ tr_debug ( " erase - Region: %d, Type:%d" ,
389
388
region, type);
390
389
391
390
_mutex->lock ();
@@ -571,7 +570,7 @@ spif_bd_error SPIFBlockDevice::_spi_send_program_command(int prog_inst, const vo
571
570
572
571
spif_bd_error SPIFBlockDevice::_spi_send_erase_command (int erase_inst, bd_addr_t addr, bd_size_t size)
573
572
{
574
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: Erase Inst: 0x%xh, addr: %llu, size: %llu" , erase_inst, addr, size);
573
+ tr_debug ( " Erase Inst: 0x%xh, addr: %llu, size: %llu" , erase_inst, addr, size);
575
574
addr = (((int )addr) & 0xFFFFF000 );
576
575
_spi_send_general_command (erase_inst, addr, NULL , 0 , NULL , 0 );
577
576
return SPIF_BD_ERROR_OK;
@@ -745,12 +744,12 @@ int SPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_t
745
744
tr_error (" init - _verify SFDP signature and version Failed" );
746
745
return -1 ;
747
746
} else {
748
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: init - verified SFDP Signature and version Successfully" );
747
+ tr_debug ( " init - verified SFDP Signature and version Successfully" );
749
748
}
750
749
751
750
// Discover Number of Parameter Headers
752
751
int number_of_param_headers = (int )(sfdp_header[6 ]) + 1 ;
753
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: number of Param Headers: %d" , number_of_param_headers);
752
+ tr_debug ( " number of Param Headers: %d" , number_of_param_headers);
754
753
755
754
addr += SPIF_SFDP_HEADER_SIZE;
756
755
data_length = SPIF_PARAM_HEADER_SIZE;
@@ -773,14 +772,14 @@ int SPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_t
773
772
774
773
if ((param_header[0 ] == 0 ) && (param_header[7 ] == 0xFF )) {
775
774
// Found Basic Params Table: LSB=0x00, MSB=0xFF
776
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: Found Basic Param Table at Table: %d" , i_ind + 1 );
775
+ tr_debug ( " Found Basic Param Table at Table: %d" , i_ind + 1 );
777
776
basic_table_addr = ((param_header[6 ] << 16 ) | (param_header[5 ] << 8 ) | (param_header[4 ]));
778
777
// Supporting up to 64 Bytes Table (16 DWORDS)
779
778
basic_table_size = ((param_header[3 ] * 4 ) < SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES) ? (param_header[3 ] * 4 ) : 64 ;
780
779
781
780
} else if ((param_header[0 ] == 81 ) && (param_header[7 ] == 0xFF )) {
782
781
// Found Sector Map Table: LSB=0x81, MSB=0xFF
783
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: Found Sector Map Table at Table: %d" , i_ind + 1 );
782
+ tr_debug ( " Found Sector Map Table at Table: %d" , i_ind + 1 );
784
783
sector_map_table_addr = ((param_header[6 ] << 16 ) | (param_header[5 ] << 8 ) | (param_header[4 ]));
785
784
sector_map_table_size = param_header[3 ] * 4 ;
786
785
@@ -799,9 +798,9 @@ unsigned int SPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_
799
798
// Page Size is specified by 4 Bits (N), calculated by 2^N
800
799
int page_to_power_size = ((int )basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE]) >> 4 ;
801
800
page_size = local_math_power (2 , page_to_power_size);
802
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: Detected Page Size: %d" , page_size);
801
+ tr_debug ( " Detected Page Size: %d" , page_size);
803
802
} else {
804
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: Using Default Page Size: %d" , page_size);
803
+ tr_debug ( " Using Default Page Size: %d" , page_size);
805
804
}
806
805
return page_size;
807
806
}
@@ -823,7 +822,7 @@ int SPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param
823
822
erase_type_inst_arr[i_ind] = 0xff ; // 0xFF default for unsupported type
824
823
erase_type_size_arr[i_ind] = local_math_power (2 ,
825
824
basic_param_table_ptr[SPIF_BASIC_PARAM_ERASE_TYPE_1_SIZE_BYTE + 2 * i_ind]); // Size given as 2^N
826
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: Erase Type(A) %d - Inst: 0x%xh, Size: %d" , (i_ind + 1 ), erase_type_inst_arr[i_ind],
825
+ tr_debug ( " Erase Type(A) %d - Inst: 0x%xh, Size: %d" , (i_ind + 1 ), erase_type_inst_arr[i_ind],
827
826
erase_type_size_arr[i_ind]);
828
827
if (erase_type_size_arr[i_ind] > 1 ) {
829
828
// if size==1 type is not supported
@@ -846,7 +845,7 @@ int SPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param
846
845
}
847
846
_region_erase_types_bitfield[0 ] |= bitfield; // If there's no region map, set region "0" types bitfield as defualt;
848
847
}
849
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " INFO: Erase Type %d - Inst: 0x%xh, Size: %d" , (i_ind + 1 ),
848
+ tr_info ( " Erase Type %d - Inst: 0x%xh, Size: %d" , (i_ind + 1 ),
850
849
erase_type_inst_arr[i_ind], erase_type_size_arr[i_ind]);
851
850
bitfield = bitfield << 1 ;
852
851
}
@@ -874,7 +873,7 @@ int SPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_
874
873
read_inst = basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE];
875
874
_read_dummy_and_mode_cycles = (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE - 1] >> 5)
876
875
+ (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE - 1] & 0x1F);
877
- debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "\nDEBUG: Read Bus Mode set to 2-2-2, Instruction: 0x%xh", read_inst);
876
+ tr_debug("\nRead Bus Mode set to 2-2-2, Instruction: 0x%xh", read_inst);
878
877
break;
879
878
}
880
879
}
@@ -884,20 +883,20 @@ int SPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_
884
883
read_inst = basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE];
885
884
_read_dummy_and_mode_cycles = (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE - 1] >> 5)
886
885
+ (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE - 1] & 0x1F);
887
- debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "\nDEBUG: Read Bus Mode set to 1-2-2, Instruction: 0x%xh", read_inst);
886
+ tr_debug("\nRead Bus Mode set to 1-2-2, Instruction: 0x%xh", read_inst);
888
887
break;
889
888
}
890
889
if (examined_byte & 0x01) {
891
890
// Fast Read 1-1-2 Supported
892
891
read_inst = basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE];
893
892
_read_dummy_and_mode_cycles = (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE - 1] >> 5)
894
893
+ (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE - 1] & 0x1F);
895
- debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "\nDEBUG: Read Bus Mode set to 1-1-2, Instruction: 0x%xh", _read_instruction);
894
+ tr_debug("\nRead Bus Mode set to 1-1-2, Instruction: 0x%xh", _read_instruction);
896
895
break;
897
896
}
898
897
*/
899
898
_read_dummy_and_mode_cycles = 0 ;
900
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " \n DEBUG: Read Bus Mode set to 1-1-1, Instruction: 0x%xh" , read_inst);
899
+ tr_debug ( " Read Bus Mode set to 1-1-1, Instruction: 0x%xh" , read_inst);
901
900
} while (false );
902
901
903
902
return 0 ;
@@ -908,21 +907,21 @@ int SPIFBlockDevice::_reset_flash_mem()
908
907
// Perform Soft Reset of the Device prior to initialization
909
908
int status = 0 ;
910
909
char status_value[2 ] = {0 };
911
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " INFO: _reset_flash_mem:\n " );
910
+ tr_info ( " _reset_flash_mem:\n " );
912
911
// Read the Status Register from device
913
912
if (SPIF_BD_ERROR_OK == _spi_send_general_command (SPIF_RDSR, SPI_NO_ADDRESS_COMMAND, NULL , 0 , status_value, 1 )) {
914
913
// store received values in status_value
915
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: Reading Status Register Success: value = 0x%x\n " , (int )status_value[0 ]);
914
+ tr_debug ( " Reading Status Register Success: value = 0x%x\n " , (int )status_value[0 ]);
916
915
} else {
917
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " ERROR: Reading Status Register failed\n " );
916
+ tr_error ( " Reading Status Register failed\n " );
918
917
status = -1 ;
919
918
}
920
919
921
920
if (0 == status) {
922
921
// Send Reset Enable
923
922
if (SPIF_BD_ERROR_OK == _spi_send_general_command (SPIF_RSTEN, SPI_NO_ADDRESS_COMMAND, NULL , 0 , NULL , 0 )) {
924
923
// store received values in status_value
925
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: Sending RSTEN Success\n " );
924
+ tr_debug ( " Sending RSTEN Success\n " );
926
925
} else {
927
926
tr_error (" Sending RSTEN failed" );
928
927
status = -1 ;
@@ -932,7 +931,7 @@ int SPIFBlockDevice::_reset_flash_mem()
932
931
// Send Reset
933
932
if (SPIF_BD_ERROR_OK == _spi_send_general_command (SPIF_RST, SPI_NO_ADDRESS_COMMAND, NULL , 0 , NULL , 0 )) {
934
933
// store received values in status_value
935
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: Sending RST Success\n " );
934
+ tr_debug ( " Sending RST Success\n " );
936
935
} else {
937
936
tr_error (" Sending RST failed" );
938
937
status = -1 ;
0 commit comments