@@ -107,7 +107,8 @@ static unsigned int local_math_power(int base, int exp);
107
107
// ***********************
108
108
SPIFBlockDevice::SPIFBlockDevice (
109
109
PinName mosi, PinName miso, PinName sclk, PinName csel, int freq)
110
- : _spi(mosi, miso, sclk), _cs(csel), _device_size_bytes(0 ), _is_initialized(false ), _init_ref_count(0 )
110
+ : _spi(mosi, miso, sclk), _cs(csel), _read_instruction(0 ), _prog_instruction(0 ), _erase_instruction(0 ),
111
+ _erase4k_inst(0 ), _page_size_bytes(0 ), _device_size_bytes(0 ), _init_ref_count(0 ), _is_initialized(false )
111
112
{
112
113
_address_size = SPIF_ADDR_SIZE_3_BYTES;
113
114
// Initial SFDP read tables are read with 8 dummy cycles
@@ -205,7 +206,7 @@ int SPIFBlockDevice::init()
205
206
_region_high_boundary[0 ] = _device_size_bytes - 1 ;
206
207
207
208
if ((sector_map_table_addr != 0 ) && (0 != sector_map_table_size)) {
208
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: init - Parsing Sector Map Table - addr: 0x%lxh , Size: %d" , sector_map_table_addr,
209
+ debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: init - Parsing Sector Map Table - addr: 0x%" PRIx32 " h , Size: %d" , sector_map_table_addr,
209
210
sector_map_table_size);
210
211
if (0 != _sfdp_parse_sector_map_table (sector_map_table_addr, sector_map_table_size)) {
211
212
tr_error (" init - Parse Sector Map Table Failed" );
@@ -296,7 +297,7 @@ int SPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
296
297
uint32_t offset = 0 ;
297
298
uint32_t chunk = 0 ;
298
299
299
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: program - Buff: 0x%lxh , addr: %llu, size: %llu" , (uint32_t )buffer, addr, size);
300
+ debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: program - Buff: 0x%" PRIx32 " h , addr: %llu, size: %llu" , (uint32_t )buffer, addr, size);
300
301
301
302
while (size > 0 ) {
302
303
@@ -352,6 +353,10 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
352
353
int status = SPIF_BD_ERROR_OK;
353
354
// Find region of erased address
354
355
int region = _utils_find_addr_region (addr);
356
+ if (region < 0 ) {
357
+ tr_error (" no region found for address %llu" , addr);
358
+ return SPIF_BD_ERROR_INVALID_ERASE_PARAMS;
359
+ }
355
360
// Erase Types of selected region
356
361
uint8_t bitfield = _region_erase_types_bitfield[region];
357
362
@@ -377,7 +382,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
377
382
offset = addr % _erase_type_size_arr[type];
378
383
chunk = ((offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
379
384
380
- debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %lu , " ,
385
+ debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %" PRIu32 " , " ,
381
386
addr, size, cur_erase_inst, chunk);
382
387
debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: erase - Region: %d, Type:%d" ,
383
388
region, type);
@@ -439,7 +444,7 @@ bd_size_t SPIFBlockDevice::get_erase_size() const
439
444
}
440
445
441
446
// Find minimal erase size supported by the region to which the address belongs to
442
- bd_size_t SPIFBlockDevice::get_erase_size (bd_addr_t addr)
447
+ bd_size_t SPIFBlockDevice::get_erase_size (bd_addr_t addr) const
443
448
{
444
449
// Find region of current address
445
450
int region = _utils_find_addr_region (addr);
@@ -693,7 +698,7 @@ int SPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, si
693
698
(param_table[5 ] << 8 ) |
694
699
param_table[4 ]);
695
700
_device_size_bytes = (density_bits + 1 ) / 8 ;
696
- tr_debug (" Density bits: %ld , device size: %llu bytes" , density_bits, _device_size_bytes);
701
+ tr_debug (" Density bits: %" PRIu32 " , device size: %llu bytes" , density_bits, _device_size_bytes);
697
702
698
703
// Set Default read/program/erase Instructions
699
704
_read_instruction = SPIF_READ;
@@ -998,7 +1003,7 @@ int SPIFBlockDevice::_set_write_enable()
998
1003
/* ********************************************/
999
1004
/* ************ Utility Functions *************/
1000
1005
/* ********************************************/
1001
- int SPIFBlockDevice::_utils_find_addr_region (bd_size_t offset)
1006
+ int SPIFBlockDevice::_utils_find_addr_region (bd_size_t offset) const
1002
1007
{
1003
1008
// Find the region to which the given offset belong to
1004
1009
if ((offset > _device_size_bytes) || (_regions_count == 0 )) {
0 commit comments