Skip to content

Commit 438a52f

Browse files
committed
Fix handoff issue from the bootloader to the application on MTS_DRAGONFLY_F411RE
1 parent 3d68a53 commit 438a52f

File tree

10 files changed

+123
-108
lines changed

10 files changed

+123
-108
lines changed

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ 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
9998
// Local Function
10099
static unsigned int local_math_power(int base, int exp);
101-
#endif
102100

103101
//***********************
104102
// SPIF Block Device APIs
@@ -130,14 +128,11 @@ int SPIFBlockDevice::init()
130128
uint8_t vendor_device_ids[4];
131129
size_t data_length = 3;
132130
int status = SPIF_BD_ERROR_OK;
133-
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
134131
uint32_t basic_table_addr = 0;
135132
size_t basic_table_size = 0;
136133
uint32_t sector_map_table_addr = 0;
137134
size_t sector_map_table_size = 0;
138-
#endif
139135
spif_bd_error spi_status = SPIF_BD_ERROR_OK;
140-
uint32_t density_bits = 0;
141136

142137
_mutex->lock();
143138

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

158+
163159
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
164160
spi_status = _spi_send_general_command(SPIF_RDID, SPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)vendor_device_ids,
165161
data_length);
@@ -184,7 +180,7 @@ int SPIFBlockDevice::init()
184180
status = SPIF_BD_ERROR_READY_FAILED;
185181
goto exit_point;
186182
}
187-
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
183+
188184
/**************************** Parse SFDP Header ***********************************/
189185
if (0 != _sfdp_parse_sfdp_headers(basic_table_addr, basic_table_size, sector_map_table_addr, sector_map_table_size)) {
190186
tr_error("ERROR: init - Parse SFDP Headers Failed");
@@ -214,22 +210,11 @@ int SPIFBlockDevice::init()
214210
goto exit_point;
215211
}
216212
}
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+
227214
// Configure BUS Mode to 1_1_1 for all commands other than Read
228215
// 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;
231217
_is_initialized = true;
232-
#endif
233218

234219
exit_point:
235220
_mutex->unlock();
@@ -348,19 +333,17 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
348333
return BD_ERROR_DEVICE_ERROR;
349334
}
350335

336+
int type = 0;
337+
uint32_t offset = 0;
338+
uint32_t chunk = 4096;
351339
int cur_erase_inst = _erase_instruction;
352340
int size = (int)in_size;
353341
bool erase_failed = false;
354342
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;
359343
// Find region of erased address
360344
int region = _utils_find_addr_region(addr);
361345
// Erase Types of selected region
362346
uint8_t bitfield = _region_erase_types_bitfield[region];
363-
#endif
364347

365348
tr_info("DEBUG: erase - addr: %llu, in_size: %llu", addr, in_size);
366349

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

377360
// For each iteration erase the largest section supported by current region
378361
while (size > 0) {
379-
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
362+
380363
// iterate to find next Largest erase type ( a. supported by region, b. smaller than size)
381364
// find the matching instruction and erase size chunk for that type.
382365
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)
388371
addr, size, cur_erase_inst, chunk);
389372
tr_debug("DEBUG: erase - Region: %d, Type:%d",
390373
region, type);
391-
#endif
374+
392375
_mutex->lock();
393376

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

401384
_spi_send_erase_command(cur_erase_inst, addr, size);
402-
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
385+
403386
addr += chunk;
404387
size -= chunk;
405388

@@ -408,10 +391,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
408391
region++;
409392
bitfield = _region_erase_types_bitfield[region];
410393
}
411-
#else
412-
addr += _min_common_erase_size;
413-
size -= _min_common_erase_size;
414-
#endif
394+
415395
if (false == _is_mem_ready()) {
416396
tr_error("ERROR: SPI After Erase Device not ready - failed\n");
417397
erase_failed = true;
@@ -451,7 +431,6 @@ bd_size_t SPIFBlockDevice::get_erase_size() const
451431
// Find minimal erase size supported by the region to which the address belongs to
452432
bd_size_t SPIFBlockDevice::get_erase_size(bd_addr_t addr)
453433
{
454-
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
455434
// Find region of current address
456435
int region = _utils_find_addr_region(addr);
457436

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

480459
return (bd_size_t)min_region_erase_size;
481-
#else
482-
return _min_common_erase_size;
483-
#endif
484460
}
485461

486462
bd_size_t SPIFBlockDevice::size() const
@@ -620,7 +596,6 @@ spif_bd_error SPIFBlockDevice::_spi_send_general_command(int instruction, bd_add
620596
return SPIF_BD_ERROR_OK;
621597
}
622598

623-
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
624599
/*********************************************************/
625600
/********** SFDP Parsing and Detection Functions *********/
626601
/*********************************************************/
@@ -912,7 +887,6 @@ int SPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_
912887

913888
return 0;
914889
}
915-
#endif
916890

917891
int SPIFBlockDevice::_reset_flash_mem()
918892
{
@@ -1066,7 +1040,6 @@ int SPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t &bitfield, i
10661040
/*********************************************/
10671041
/************** Local Functions **************/
10681042
/*********************************************/
1069-
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
10701043
static unsigned int local_math_power(int base, int exp)
10711044
{
10721045
// 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)
10771050
}
10781051
return result;
10791052
}
1080-
#endif
1053+
1054+

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-
#ifdef MBED_CONF_SPIF_SFDP_ENABLE
201+
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-
#endif
225+
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-
bool _is_initialized;
303302
uint32_t _init_ref_count;
303+
bool _is_initialized;
304304
};
305305

306306
#endif /* MBED_SPIF_BLOCK_DEVICE_H */

components/storage/blockdevice/COMPONENT_SPIF/mbed_lib.json

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,7 @@
55
"SPI_MISO": "SPI_MISO",
66
"SPI_CLK": "SPI_SCK",
77
"SPI_CS": "SPI_CS",
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-
}
8+
"SPI_FREQ": "40000000"
379
},
3810
"target_overrides": {
3911
"LPC54114": {
@@ -60,25 +32,25 @@
6032
"SPI_CLK": "PE_12",
6133
"SPI_CS": "PE_11"
6234
},
63-
"MTB_ADV_WISE_1530": {
35+
"MTB_ADV_WISE_1530": {
6436
"SPI_MOSI": "PC_3",
6537
"SPI_MISO": "PC_2",
6638
"SPI_CLK": "PB_13",
6739
"SPI_CS": "PC_12"
6840
},
69-
"MTB_MXCHIP_EMW3166": {
41+
"MTB_MXCHIP_EMW3166": {
7042
"SPI_MOSI": "PB_15",
7143
"SPI_MISO": "PB_14",
7244
"SPI_CLK": "PB_13",
7345
"SPI_CS": "PA_10"
7446
},
75-
"MTB_USI_WM_BN_BM_22": {
47+
"MTB_USI_WM_BN_BM_22": {
7648
"SPI_MOSI": "PC_3",
7749
"SPI_MISO": "PC_2",
7850
"SPI_CLK": "PB_13",
7951
"SPI_CS": "PA_6"
8052
},
81-
"MTB_ADV_WISE_1570": {
53+
"MTB_ADV_WISE_1570": {
8254
"SPI_MOSI": "PA_7",
8355
"SPI_MISO": "PA_6",
8456
"SPI_CLK": "PA_5",
@@ -95,15 +67,7 @@
9567
"SPI_MOSI": "SPI3_MOSI",
9668
"SPI_MISO": "SPI3_MISO",
9769
"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
70+
"SPI_CS": "SPI_CS1"
10771
}
10872
}
10973
}

targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/TOOLCHAIN_ARM_STD/stm32f411re.sct

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,42 @@
2828
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3030

31+
#if !defined(MBED_APP_START)
32+
#define MBED_APP_START 0x08000000
33+
#endif
34+
35+
#if !defined(MBED_APP_SIZE)
36+
#define MBED_APP_SIZE 0x80000
37+
#endif
38+
3139
#if !defined(MBED_BOOT_STACK_SIZE)
3240
#define MBED_BOOT_STACK_SIZE 0x400
3341
#endif
3442

3543
#define Stack_Size MBED_BOOT_STACK_SIZE
3644

45+
#define MBED_RAM_START 0x20000000
46+
#define MBED_RAM_SIZE 0x20000
47+
#define MBED_VECTTABLE_RAM_START (MBED_RAM_START)
48+
#define MBED_VECTTABLE_RAM_SIZE 0x198
49+
#define MBED_RAM0_START (MBED_RAM_START + MBED_VECTTABLE_RAM_SIZE)
50+
#define MBED_RAM0_SIZE (MBED_RAM_SIZE- MBED_VECTTABLE_RAM_SIZE)
51+
3752
; STM32F411RE: 512 KB FLASH (0x80000) + 128 KB SRAM (0x20000)
38-
; FIRST 64 KB FLASH FOR BOOTLOADER
39-
; REST 448 KB FLASH FOR APPLICATION
40-
LR_IROM1 0x08010000 0x70000 { ; load region size_region
53+
LR_IROM1 MBED_APP_START MBED_APP_SIZE { ; load region size_region
4154

42-
ER_IROM1 0x08010000 0x70000 { ; load address = execution address
55+
ER_IROM1 MBED_APP_START MBED_APP_SIZE { ; load address = execution address
4356
*.o (RESET, +First)
4457
*(InRoot$$Sections)
4558
.ANY (+RO)
4659
}
4760

4861
; Total: 102 vectors = 408 bytes (0x198) to be reserved in RAM
49-
RW_IRAM1 (0x20000000+0x198) (0x20000-0x198-Stack_Size) { ; RW data
62+
RW_IRAM1 (MBED_RAM0_START) (MBED_RAM0_SIZE-Stack_Size) { ; RW data
5063
.ANY (+RW +ZI)
5164
}
5265

53-
ARM_LIB_STACK (0x20000000+0x20000) EMPTY -Stack_Size { ; stack
66+
ARM_LIB_STACK (MBED_RAM0_START+MBED_RAM0_SIZE) EMPTY -Stack_Size { ; stack
5467
}
5568
}
5669

targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/TOOLCHAIN_GCC_ARM/NUCLEO_F411RE.ld

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
/* Linker script for STM32F411 */
22

3+
#if !defined(MBED_APP_START)
4+
#define MBED_APP_START 0x08000000
5+
#endif
6+
7+
#if !defined(MBED_APP_SIZE)
8+
#define MBED_APP_SIZE 512K
9+
#endif
10+
311
#if !defined(MBED_BOOT_STACK_SIZE)
412
#define MBED_BOOT_STACK_SIZE 0x400
513
#endif
614

715
STACK_SIZE = MBED_BOOT_STACK_SIZE;
816

17+
918
/* Linker script to configure memory regions. */
1019
MEMORY
11-
{
12-
/* First 64kB of flash reserved for bootloader */
13-
/* Other 448kB for application */
14-
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 448K
20+
{
21+
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
1522
/* CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K */
1623
RAM (rwx) : ORIGIN = 0x20000198, LENGTH = 128k - 0x198
1724
}

targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/TOOLCHAIN_GCC_ARM/startup_STM32F41x.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ __HeapLimit:
6666

6767
.section .isr_vector
6868
.align 2
69-
.globl __isr_vector
70-
__isr_vector:
69+
.globl g_pfnVectors
70+
g_pfnVectors:
7171
.long __StackTop /* Top of Stack */
7272
.long Reset_Handler /* Reset Handler */
7373
.long NMI_Handler /* NMI Handler */
@@ -171,7 +171,7 @@ __isr_vector:
171171
.long SPI4_IRQHandler /* SPI4 */
172172
.long SPI5_IRQHandler /* SPI5 */
173173

174-
.size __isr_vector, . - __isr_vector
174+
.size g_pfnVectors, . - g_pfnVectors
175175

176176
.text
177177
.thumb

0 commit comments

Comments
 (0)