@@ -95,10 +95,8 @@ enum spif_default_instructions {
95
95
// e.g. (1)Set Write Enable, (2)Program, (3)Wait Memory Ready
96
96
SingletonPtr<PlatformMutex> SPIFBlockDevice::_mutex;
97
97
98
- #ifdef MBED_CONF_SPIF_SFDP_ENABLE
99
98
// Local Function
100
99
static unsigned int local_math_power (int base, int exp);
101
- #endif
102
100
103
101
// ***********************
104
102
// SPIF Block Device APIs
@@ -130,14 +128,11 @@ int SPIFBlockDevice::init()
130
128
uint8_t vendor_device_ids[4 ];
131
129
size_t data_length = 3 ;
132
130
int status = SPIF_BD_ERROR_OK;
133
- #ifdef MBED_CONF_SPIF_SFDP_ENABLE
134
131
uint32_t basic_table_addr = 0 ;
135
132
size_t basic_table_size = 0 ;
136
133
uint32_t sector_map_table_addr = 0 ;
137
134
size_t sector_map_table_size = 0 ;
138
- #endif
139
135
spif_bd_error spi_status = SPIF_BD_ERROR_OK;
140
- uint32_t density_bits = 0 ;
141
136
142
137
_mutex->lock ();
143
138
@@ -160,6 +155,7 @@ int SPIFBlockDevice::init()
160
155
tr_info (" INFO: Initialize flash memory OK\n " );
161
156
}
162
157
158
+
163
159
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
164
160
spi_status = _spi_send_general_command (SPIF_RDID, SPI_NO_ADDRESS_COMMAND, NULL , 0 , (char *)vendor_device_ids,
165
161
data_length);
@@ -184,7 +180,7 @@ int SPIFBlockDevice::init()
184
180
status = SPIF_BD_ERROR_READY_FAILED;
185
181
goto exit_point;
186
182
}
187
- # ifdef MBED_CONF_SPIF_SFDP_ENABLE
183
+
188
184
/* *************************** Parse SFDP Header ***********************************/
189
185
if (0 != _sfdp_parse_sfdp_headers (basic_table_addr, basic_table_size, sector_map_table_addr, sector_map_table_size)) {
190
186
tr_error (" ERROR: init - Parse SFDP Headers Failed" );
@@ -214,22 +210,11 @@ int SPIFBlockDevice::init()
214
210
goto exit_point;
215
211
}
216
212
}
217
- #else
218
- density_bits = MBED_CONF_SPIF_DRIVER_DENSITY_BITS;
219
- _device_size_bytes = (density_bits + 1 ) / 8 ;
220
- _read_instruction = SPIF_READ;
221
- _prog_instruction = SPIF_PP;
222
- _erase_instruction = MBED_CONF_SPIF_DRIVER_SECTOR_ERASE_INST;
223
- // Set Page Size (SPI write must be done on Page limits)
224
- _page_size_bytes = MBED_CONF_SPIF_DRIVER_PAGE_SIZE_BYTES;
225
- // _sector_size_pages = MBED_CONF_SPIF_DRIVER_SECTOR_SIZE_PAGES;
226
- _min_common_erase_size = MBED_CONF_SPIF_DRIVER_SECTOR_SIZE_PAGES * MBED_CONF_SPIF_DRIVER_PAGE_SIZE_BYTES;
213
+
227
214
// Configure BUS Mode to 1_1_1 for all commands other than Read
228
215
// Dummy And Mode Cycles Back default 0
229
- _read_dummy_and_mode_cycles = MBED_CONF_SPIF_DRIVER_READ_DUMMY_CYCLES;
230
- _write_dummy_and_mode_cycles = MBED_CONF_SPIF_DRIVER_MODE_WRITE_DUMMY_CYCLES;
216
+ _dummy_and_mode_cycles = _write_dummy_and_mode_cycles;
231
217
_is_initialized = true ;
232
- #endif
233
218
234
219
exit_point:
235
220
_mutex->unlock ();
@@ -348,19 +333,17 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
348
333
return BD_ERROR_DEVICE_ERROR;
349
334
}
350
335
336
+ int type = 0 ;
337
+ uint32_t offset = 0 ;
338
+ uint32_t chunk = 4096 ;
351
339
int cur_erase_inst = _erase_instruction;
352
340
int size = (int )in_size;
353
341
bool erase_failed = false ;
354
342
int status = SPIF_BD_ERROR_OK;
355
- #ifdef MBED_CONF_SPIF_SFDP_ENABLE
356
- int type = 0 ;
357
- uint32_t offset = 0 ;
358
- uint32_t chunk = 4096 ;
359
343
// Find region of erased address
360
344
int region = _utils_find_addr_region (addr);
361
345
// Erase Types of selected region
362
346
uint8_t bitfield = _region_erase_types_bitfield[region];
363
- #endif
364
347
365
348
tr_info (" DEBUG: erase - addr: %llu, in_size: %llu" , addr, in_size);
366
349
@@ -376,7 +359,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
376
359
377
360
// For each iteration erase the largest section supported by current region
378
361
while (size > 0 ) {
379
- # ifdef MBED_CONF_SPIF_SFDP_ENABLE
362
+
380
363
// iterate to find next Largest erase type ( a. supported by region, b. smaller than size)
381
364
// find the matching instruction and erase size chunk for that type.
382
365
type = _utils_iterate_next_largest_erase_type (bitfield, size, (unsigned int )addr, _region_high_boundary[region]);
@@ -388,7 +371,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
388
371
addr, size, cur_erase_inst, chunk);
389
372
tr_debug (" DEBUG: erase - Region: %d, Type:%d" ,
390
373
region, type);
391
- # endif
374
+
392
375
_mutex->lock ();
393
376
394
377
if (_set_write_enable () != 0 ) {
@@ -399,7 +382,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
399
382
}
400
383
401
384
_spi_send_erase_command (cur_erase_inst, addr, size);
402
- # ifdef MBED_CONF_SPIF_SFDP_ENABLE
385
+
403
386
addr += chunk;
404
387
size -= chunk;
405
388
@@ -408,10 +391,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
408
391
region++;
409
392
bitfield = _region_erase_types_bitfield[region];
410
393
}
411
- #else
412
- addr += _min_common_erase_size;
413
- size -= _min_common_erase_size;
414
- #endif
394
+
415
395
if (false == _is_mem_ready ()) {
416
396
tr_error (" ERROR: SPI After Erase Device not ready - failed\n " );
417
397
erase_failed = true ;
@@ -451,7 +431,6 @@ bd_size_t SPIFBlockDevice::get_erase_size() const
451
431
// Find minimal erase size supported by the region to which the address belongs to
452
432
bd_size_t SPIFBlockDevice::get_erase_size (bd_addr_t addr)
453
433
{
454
- #ifdef MBED_CONF_SPIF_SFDP_ENABLE
455
434
// Find region of current address
456
435
int region = _utils_find_addr_region (addr);
457
436
@@ -478,9 +457,6 @@ bd_size_t SPIFBlockDevice::get_erase_size(bd_addr_t addr)
478
457
}
479
458
480
459
return (bd_size_t )min_region_erase_size;
481
- #else
482
- return _min_common_erase_size;
483
- #endif
484
460
}
485
461
486
462
bd_size_t SPIFBlockDevice::size () const
@@ -620,7 +596,6 @@ spif_bd_error SPIFBlockDevice::_spi_send_general_command(int instruction, bd_add
620
596
return SPIF_BD_ERROR_OK;
621
597
}
622
598
623
- #ifdef MBED_CONF_SPIF_SFDP_ENABLE
624
599
/* ********************************************************/
625
600
/* ********* SFDP Parsing and Detection Functions *********/
626
601
/* ********************************************************/
@@ -912,7 +887,6 @@ int SPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_
912
887
913
888
return 0 ;
914
889
}
915
- #endif
916
890
917
891
int SPIFBlockDevice::_reset_flash_mem ()
918
892
{
@@ -1066,7 +1040,6 @@ int SPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t &bitfield, i
1066
1040
/* ********************************************/
1067
1041
/* ************* Local Functions **************/
1068
1042
/* ********************************************/
1069
- #ifdef MBED_CONF_SPIF_SFDP_ENABLE
1070
1043
static unsigned int local_math_power (int base, int exp)
1071
1044
{
1072
1045
// Integer X^Y function, used to calculate size fields given in 2^N format
@@ -1077,4 +1050,5 @@ static unsigned int local_math_power(int base, int exp)
1077
1050
}
1078
1051
return result;
1079
1052
}
1080
- #endif
1053
+
1054
+
0 commit comments