@@ -107,7 +107,8 @@ static unsigned int local_math_power(int base, int exp);
107107// ***********************
108108SPIFBlockDevice::SPIFBlockDevice (
109109 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 )
111112{
112113 _address_size = SPIF_ADDR_SIZE_3_BYTES;
113114 // Initial SFDP read tables are read with 8 dummy cycles
@@ -205,7 +206,7 @@ int SPIFBlockDevice::init()
205206 _region_high_boundary[0 ] = _device_size_bytes - 1 ;
206207
207208 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,
209210 sector_map_table_size);
210211 if (0 != _sfdp_parse_sector_map_table (sector_map_table_addr, sector_map_table_size)) {
211212 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)
296297 uint32_t offset = 0 ;
297298 uint32_t chunk = 0 ;
298299
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);
300301
301302 while (size > 0 ) {
302303
@@ -352,6 +353,10 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
352353 int status = SPIF_BD_ERROR_OK;
353354 // Find region of erased address
354355 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+ }
355360 // Erase Types of selected region
356361 uint8_t bitfield = _region_erase_types_bitfield[region];
357362
@@ -377,7 +382,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
377382 offset = addr % _erase_type_size_arr[type];
378383 chunk = ((offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
379384
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 " , " ,
381386 addr, size, cur_erase_inst, chunk);
382387 debug_if (MBED_CONF_SPIF_DRIVER_DEBUG, " DEBUG: erase - Region: %d, Type:%d" ,
383388 region, type);
@@ -439,7 +444,7 @@ bd_size_t SPIFBlockDevice::get_erase_size() const
439444}
440445
441446// 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
443448{
444449 // Find region of current address
445450 int region = _utils_find_addr_region (addr);
@@ -693,7 +698,7 @@ int SPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, si
693698 (param_table[5 ] << 8 ) |
694699 param_table[4 ]);
695700 _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);
697702
698703 // Set Default read/program/erase Instructions
699704 _read_instruction = SPIF_READ;
@@ -998,7 +1003,7 @@ int SPIFBlockDevice::_set_write_enable()
9981003/* ********************************************/
9991004/* ************ Utility Functions *************/
10001005/* ********************************************/
1001- int SPIFBlockDevice::_utils_find_addr_region (bd_size_t offset)
1006+ int SPIFBlockDevice::_utils_find_addr_region (bd_size_t offset) const
10021007{
10031008 // Find the region to which the given offset belong to
10041009 if ((offset > _device_size_bytes) || (_regions_count == 0 )) {
0 commit comments