Skip to content

Commit e2eb9b3

Browse files
theotherjimmyjanjongboom
authored andcommitted
Merge pull request ARMmbed#4640 from chrissnow/xDot-Bootloader
STM32L1 Flash API and xDot bootloader support
1 parent 50b3418 commit e2eb9b3

File tree

8 files changed

+210
-11
lines changed

8 files changed

+210
-11
lines changed

targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_ARM_MICRO/stm32l151rc.sct

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#! armcc -E
12
; Scatter-Loading Description File
23
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34
; Copyright (c) 2015, STMicroelectronics
@@ -27,10 +28,19 @@
2728
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2829
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2930

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 0x40000
37+
#endif
38+
39+
3040
; STM32L151RC: 256KB FLASH + 32KB SRAM
31-
LR_IROM1 0x08000000 0x40000 { ; load region size_region
41+
LR_IROM1 MBED_APP_START MBED_APP_SIZE { ; load region size_region
3242

33-
ER_IROM1 0x08000000 0x40000 { ; load address = execution address
43+
ER_IROM1 MBED_APP_START MBED_APP_SIZE { ; load address = execution address
3444
*.o (RESET, +First)
3545
*(InRoot$$Sections)
3646
.ANY (+RO)

targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_ARM_STD/stm32l151rc.sct

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#! armcc -E
12
; Scatter-Loading Description File
23
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34
; Copyright (c) 2015, STMicroelectronics
@@ -27,10 +28,19 @@
2728
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2829
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2930

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 0x40000
37+
#endif
38+
39+
3040
; STM32L151RC: 256KB FLASH + 32KB SRAM
31-
LR_IROM1 0x08000000 0x40000 { ; load region size_region
41+
LR_IROM1 MBED_APP_START MBED_APP_SIZE { ; load region size_region
3242

33-
ER_IROM1 0x08000000 0x40000 { ; load address = execution address
43+
ER_IROM1 MBED_APP_START MBED_APP_SIZE { ; load address = execution address
3444
*.o (RESET, +First)
3545
*(InRoot$$Sections)
3646
.ANY (+RO)

targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_GCC_ARM/STM32L151XC.ld

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
/* Linker script to configure memory regions. */
2+
#if !defined(MBED_APP_START)
3+
#define MBED_APP_START 0x08000000
4+
#endif
25

6+
#if !defined(MBED_APP_SIZE)
7+
#define MBED_APP_SIZE 256k
8+
#endif
39
MEMORY
410
{
511
/* 256KB FLASH, 32KB RAM, Reserve up till 0x13C. There are 0x73 vectors = 292
612
* bytes (0x124) in RAM. But all GCC scripts seem to require BootRAM @0x138
713
*/
8-
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256k
14+
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
915
RAM (rwx) : ORIGIN = 0x2000013C, LENGTH = 0x8000-0x13C
1016
}
1117

targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/TOOLCHAIN_IAR/stm32l152xc.icf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x08000000; }
2+
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0x40000; }
13
/* [ROM = 256kb = 0x40000] */
2-
define symbol __intvec_start__ = 0x08000000;
3-
define symbol __region_ROM_start__ = 0x08000000;
4-
define symbol __region_ROM_end__ = 0x0803FFFF;
4+
define symbol __intvec_start__ = MBED_APP_START;
5+
define symbol __region_ROM_start__ = MBED_APP_START;
6+
define symbol __region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
57

68
/* [RAM = 32kb = 0x8000] Vector table dynamic copy: 73 vectors = 292 bytes (0x124) to be reserved in RAM */
79
define symbol __NVIC_start__ = 0x20000000;

targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/system_stm32l1xx.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,25 @@ void SystemInit (void)
204204
#ifdef DATA_IN_ExtSRAM
205205
SystemInit_ExtMemCtl();
206206
#endif /* DATA_IN_ExtSRAM */
207-
207+
208+
209+
#if defined(__ICCARM__)
210+
#pragma section=".intvec"
211+
#define FLASH_VTOR_BASE ((uint32_t)__section_begin(".intvec"))
212+
#elif defined(__CC_ARM)
213+
extern uint32_t Load$$LR$$LR_IROM1$$Base[];
214+
#define FLASH_VTOR_BASE ((uint32_t)Load$$LR$$LR_IROM1$$Base)
215+
#elif defined(__GNUC__)
216+
extern uint32_t g_pfnVectors[];
217+
#define FLASH_VTOR_BASE ((uint32_t)g_pfnVectors)
218+
#else
219+
#error "Flash vector address not set for this toolchain"
220+
#endif
221+
208222
#ifdef VECT_TAB_SRAM
209223
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
210224
#else
211-
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
225+
SCB->VTOR = FLASH_VTOR_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
212226
#endif
213227

214228
/* Configure the Cube driver */

targets/TARGET_STM/TARGET_STM32L1/common_objects.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ struct i2c_s {
110110
#endif
111111
};
112112

113+
struct flash_s {
114+
/* nothing to be stored for now */
115+
uint32_t dummy;
116+
};
117+
118+
struct dac_s {
119+
DACName dac;
120+
PinName pin;
121+
uint32_t channel;
122+
DAC_HandleTypeDef handle;
123+
};
124+
113125
#include "gpio_object.h"
114126

115127
#ifdef __cplusplus
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "flash_api.h"
18+
#include "mbed_critical.h"
19+
20+
#if DEVICE_FLASH
21+
#include "mbed_assert.h"
22+
#include "cmsis.h"
23+
24+
/* L1 targets embed 16 pages sectors */
25+
#define NUM_PAGES_IN_SECTOR 16
26+
27+
int32_t flash_init(flash_t *obj)
28+
{
29+
/* Unlock the Flash to enable the flash control register access *************/
30+
HAL_FLASH_Unlock();
31+
return 0;
32+
}
33+
34+
int32_t flash_free(flash_t *obj)
35+
{
36+
/* Lock the Flash to disable the flash control register access (recommended
37+
* to protect the FLASH memory against possible unwanted operation) *********/
38+
HAL_FLASH_Lock();
39+
return 0;
40+
}
41+
42+
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
43+
{
44+
uint32_t FirstPage = 0;
45+
uint32_t PAGEError = 0;
46+
FLASH_EraseInitTypeDef EraseInitStruct;
47+
48+
if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {
49+
50+
return -1;
51+
}
52+
53+
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR | FLASH_FLAG_EOP | FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR);
54+
/* MBED HAL erases 1 sector at a time */
55+
/* Fill EraseInit structure*/
56+
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
57+
EraseInitStruct.PageAddress = address;
58+
EraseInitStruct.NbPages = NUM_PAGES_IN_SECTOR;
59+
60+
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
61+
you have to make sure that these data are rewritten before they are accessed during code
62+
execution. If this cannot be done safely, it is recommended to flush the caches by setting the
63+
DCRST and ICRST bits in the FLASH_CR register. */
64+
65+
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK) {
66+
return -1;
67+
} else {
68+
return 0;
69+
}
70+
}
71+
72+
int32_t flash_program_page(flash_t *obj, uint32_t address,
73+
const uint8_t *data, uint32_t size)
74+
{
75+
uint32_t StartAddress = 0;
76+
77+
if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {
78+
return -1;
79+
}
80+
81+
if ((size % 4) != 0) {
82+
/* L1 flash devices can only be programmed 32bits/4 bytes at a time */
83+
return -1;
84+
}
85+
86+
/* Program the user Flash area word by word */
87+
StartAddress = address;
88+
89+
/* HW needs an aligned address to program flash, which data
90+
* parameters doesn't ensure */
91+
if ((uint32_t) data % 4 != 0) {
92+
volatile uint32_t data32;
93+
while (address < (StartAddress + size)) {
94+
for (uint8_t i =0; i < 4; i++) {
95+
*(((uint8_t *) &data32) + i) = *(data + i);
96+
}
97+
98+
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data32) == HAL_OK) {
99+
address = address + 4;
100+
data = data + 4;
101+
} else {
102+
return -1;
103+
}
104+
}
105+
} else { /* case where data is aligned, so let's avoid any copy */
106+
while (address < (StartAddress + size)) {
107+
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, *((uint32_t*) data)) == HAL_OK) {
108+
address = address + 4;
109+
data = data + 4;
110+
} else {
111+
return -1;
112+
}
113+
}
114+
}
115+
116+
return 0;
117+
}
118+
119+
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
120+
{
121+
if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {
122+
return MBED_FLASH_INVALID_SIZE;
123+
} else {
124+
return (NUM_PAGES_IN_SECTOR * FLASH_PAGE_SIZE);
125+
}
126+
}
127+
128+
uint32_t flash_get_page_size(const flash_t *obj)
129+
{
130+
return FLASH_PAGE_SIZE;
131+
}
132+
133+
uint32_t flash_get_start_address(const flash_t *obj)
134+
{
135+
return FLASH_BASE;
136+
}
137+
138+
uint32_t flash_get_size(const flash_t *obj)
139+
{
140+
return FLASH_SIZE;
141+
}
142+
143+
#endif

targets/targets.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,9 @@
12951295
"progen": {"target": "xdot-l151cc"},
12961296
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
12971297
"default_lib": "std",
1298-
"release_versions": ["5"]
1298+
"release_versions": ["5"],
1299+
"device_name": "STM32L151CC",
1300+
"bootloader_supported": true
12991301
},
13001302
"MOTE_L152RC": {
13011303
"inherits": ["Target"],

0 commit comments

Comments
 (0)