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