Skip to content

Commit 3d68a53

Browse files
Ben Cookelinlingao
authored andcommitted
Correct the default pins for the spi flash for the mts dragonfly - on behalf of Ben C.
1 parent b895bf6 commit 3d68a53

File tree

3 files changed

+88
-20
lines changed

3 files changed

+88
-20
lines changed

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ enum spif_default_instructions {
9595
// e.g. (1)Set Write Enable, (2)Program, (3)Wait Memory Ready
9696
SingletonPtr<PlatformMutex> SPIFBlockDevice::_mutex;
9797

98+
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
9899
// Local Function
99100
static unsigned int local_math_power(int base, int exp);
101+
#endif
100102

101103
//***********************
102104
// SPIF Block Device APIs
@@ -128,11 +130,14 @@ int SPIFBlockDevice::init()
128130
uint8_t vendor_device_ids[4];
129131
size_t data_length = 3;
130132
int status = SPIF_BD_ERROR_OK;
133+
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
131134
uint32_t basic_table_addr = 0;
132135
size_t basic_table_size = 0;
133136
uint32_t sector_map_table_addr = 0;
134137
size_t sector_map_table_size = 0;
138+
#endif
135139
spif_bd_error spi_status = SPIF_BD_ERROR_OK;
140+
uint32_t density_bits = 0;
136141

137142
_mutex->lock();
138143

@@ -155,7 +160,6 @@ int SPIFBlockDevice::init()
155160
tr_info("INFO: Initialize flash memory OK\n");
156161
}
157162

158-
159163
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
160164
spi_status = _spi_send_general_command(SPIF_RDID, SPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)vendor_device_ids,
161165
data_length);
@@ -180,7 +184,7 @@ int SPIFBlockDevice::init()
180184
status = SPIF_BD_ERROR_READY_FAILED;
181185
goto exit_point;
182186
}
183-
187+
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
184188
/**************************** Parse SFDP Header ***********************************/
185189
if (0 != _sfdp_parse_sfdp_headers(basic_table_addr, basic_table_size, sector_map_table_addr, sector_map_table_size)) {
186190
tr_error("ERROR: init - Parse SFDP Headers Failed");
@@ -210,11 +214,22 @@ int SPIFBlockDevice::init()
210214
goto exit_point;
211215
}
212216
}
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;
214227
// Configure BUS Mode to 1_1_1 for all commands other than Read
215228
// 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;
217231
_is_initialized = true;
232+
#endif
218233

219234
exit_point:
220235
_mutex->unlock();
@@ -333,17 +348,19 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
333348
return BD_ERROR_DEVICE_ERROR;
334349
}
335350

336-
int type = 0;
337-
uint32_t offset = 0;
338-
uint32_t chunk = 4096;
339351
int cur_erase_inst = _erase_instruction;
340352
int size = (int)in_size;
341353
bool erase_failed = false;
342354
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;
343359
// Find region of erased address
344360
int region = _utils_find_addr_region(addr);
345361
// Erase Types of selected region
346362
uint8_t bitfield = _region_erase_types_bitfield[region];
363+
#endif
347364

348365
tr_info("DEBUG: erase - addr: %llu, in_size: %llu", addr, in_size);
349366

@@ -359,7 +376,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
359376

360377
// For each iteration erase the largest section supported by current region
361378
while (size > 0) {
362-
379+
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
363380
// iterate to find next Largest erase type ( a. supported by region, b. smaller than size)
364381
// find the matching instruction and erase size chunk for that type.
365382
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)
371388
addr, size, cur_erase_inst, chunk);
372389
tr_debug("DEBUG: erase - Region: %d, Type:%d",
373390
region, type);
374-
391+
#endif
375392
_mutex->lock();
376393

377394
if (_set_write_enable() != 0) {
@@ -382,7 +399,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
382399
}
383400

384401
_spi_send_erase_command(cur_erase_inst, addr, size);
385-
402+
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
386403
addr += chunk;
387404
size -= chunk;
388405

@@ -391,7 +408,10 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
391408
region++;
392409
bitfield = _region_erase_types_bitfield[region];
393410
}
394-
411+
#else
412+
addr += _min_common_erase_size;
413+
size -= _min_common_erase_size;
414+
#endif
395415
if (false == _is_mem_ready()) {
396416
tr_error("ERROR: SPI After Erase Device not ready - failed\n");
397417
erase_failed = true;
@@ -431,6 +451,7 @@ bd_size_t SPIFBlockDevice::get_erase_size() const
431451
// Find minimal erase size supported by the region to which the address belongs to
432452
bd_size_t SPIFBlockDevice::get_erase_size(bd_addr_t addr)
433453
{
454+
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
434455
// Find region of current address
435456
int region = _utils_find_addr_region(addr);
436457

@@ -457,6 +478,9 @@ bd_size_t SPIFBlockDevice::get_erase_size(bd_addr_t addr)
457478
}
458479

459480
return (bd_size_t)min_region_erase_size;
481+
#else
482+
return _min_common_erase_size;
483+
#endif
460484
}
461485

462486
bd_size_t SPIFBlockDevice::size() const
@@ -596,6 +620,7 @@ spif_bd_error SPIFBlockDevice::_spi_send_general_command(int instruction, bd_add
596620
return SPIF_BD_ERROR_OK;
597621
}
598622

623+
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
599624
/*********************************************************/
600625
/********** SFDP Parsing and Detection Functions *********/
601626
/*********************************************************/
@@ -887,6 +912,7 @@ int SPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_
887912

888913
return 0;
889914
}
915+
#endif
890916

891917
int SPIFBlockDevice::_reset_flash_mem()
892918
{
@@ -1040,6 +1066,7 @@ int SPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t &bitfield, i
10401066
/*********************************************/
10411067
/************** Local Functions **************/
10421068
/*********************************************/
1069+
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
10431070
static unsigned int local_math_power(int base, int exp)
10441071
{
10451072
// 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)
10501077
}
10511078
return result;
10521079
}
1053-
1054-
1080+
#endif

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class SPIFBlockDevice : public mbed::BlockDevice {
198198
private:
199199

200200
// Internal functions
201-
201+
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
202202
/****************************************/
203203
/* SFDP Detection and Parsing Functions */
204204
/****************************************/
@@ -222,7 +222,7 @@ class SPIFBlockDevice : public mbed::BlockDevice {
222222
int _sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
223223
int &erase4k_inst,
224224
int *erase_type_inst_arr, unsigned int *erase_type_size_arr);
225-
225+
#endif
226226
/***********************/
227227
/* Utilities Functions */
228228
/***********************/
@@ -299,8 +299,8 @@ class SPIFBlockDevice : public mbed::BlockDevice {
299299
unsigned int _read_dummy_and_mode_cycles; // Number of Dummy and Mode Bits required by Read Bus Mode
300300
unsigned int _write_dummy_and_mode_cycles; // Number of Dummy and Mode Bits required by Write Bus Mode
301301
unsigned int _dummy_and_mode_cycles; // Number of Dummy and Mode Bits required by Current Bus Mode
302-
uint32_t _init_ref_count;
303302
bool _is_initialized;
303+
uint32_t _init_ref_count;
304304
};
305305

306306
#endif /* MBED_SPIF_BLOCK_DEVICE_H */

components/storage/blockdevice/COMPONENT_SPIF/mbed_lib.json

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,35 @@
55
"SPI_MISO": "SPI_MISO",
66
"SPI_CLK": "SPI_SCK",
77
"SPI_CS": "SPI_CS",
8-
"SPI_FREQ": "40000000"
8+
"SPI_FREQ": "40000000",
9+
"SFDP_ENABLE": {
10+
"help": "Enables Serial Flash Discovery Protocal for automatically determining flash parameters from the SFDP register",
11+
"value": true
12+
},
13+
"density_bits": {
14+
"help": "Flash density in bits. 16Mb = 16000000",
15+
"value": null
16+
},
17+
"page_size_bytes": {
18+
"help": "Flash page size in bytes",
19+
"value": null
20+
},
21+
"read_dummy_cycles": {
22+
"help": "Number of dummy cycles required between read cmd/addr and data output",
23+
"value": null
24+
},
25+
"mode_write_dummy_cycles": {
26+
"help": "Number of dummy cycles required between write or mode commands and data",
27+
"value": null
28+
},
29+
"sector_erase_inst": {
30+
"help": "Sector erase instruction.",
31+
"value": null
32+
},
33+
"sector_size_pages": {
34+
"help": "Sector size in pages for sector erase",
35+
"value": null
36+
}
937
},
1038
"target_overrides": {
1139
"LPC54114": {
@@ -36,19 +64,19 @@
3664
"SPI_MOSI": "PC_3",
3765
"SPI_MISO": "PC_2",
3866
"SPI_CLK": "PB_13",
39-
"SPI_CS": "PC_12"
67+
"SPI_CS": "PC_12"
4068
},
4169
"MTB_MXCHIP_EMW3166": {
4270
"SPI_MOSI": "PB_15",
4371
"SPI_MISO": "PB_14",
4472
"SPI_CLK": "PB_13",
45-
"SPI_CS": "PA_10"
73+
"SPI_CS": "PA_10"
4674
},
4775
"MTB_USI_WM_BN_BM_22": {
4876
"SPI_MOSI": "PC_3",
4977
"SPI_MISO": "PC_2",
5078
"SPI_CLK": "PB_13",
51-
"SPI_CS": "PA_6"
79+
"SPI_CS": "PA_6"
5280
},
5381
"MTB_ADV_WISE_1570": {
5482
"SPI_MOSI": "PA_7",
@@ -62,6 +90,20 @@
6290
"SPI_MISO": "PE_13",
6391
"SPI_CLK": "PE_12",
6492
"SPI_CS": "PE_11"
93+
},
94+
"MTS_DRAGONFLY_F411RE": {
95+
"SPI_MOSI": "SPI3_MOSI",
96+
"SPI_MISO": "SPI3_MISO",
97+
"SPI_CLK": "SPI3_SCK",
98+
"SPI_CS": "SPI_CS1",
99+
"SPI_FREQ": "40000000",
100+
"SFDP_ENABLE": null,
101+
"density_bits": 16000000,
102+
"page_size_bytes": 256,
103+
"read_dummy_cycles": 0,
104+
"mode_write_dummy_cycles": 0,
105+
"sector_erase_inst": "0xD8",
106+
"sector_size_pages": 256
65107
}
66108
}
67109
}

0 commit comments

Comments
 (0)