Skip to content

Commit 9c81ba8

Browse files
Merge pull request #4835 from u-blox/c030_bootloader
Add bootloader support for the UBLOX_C030 platforms.
2 parents a81783e + 1c7a7bc commit 9c81ba8

File tree

8 files changed

+310
-9
lines changed

8 files changed

+310
-9
lines changed

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/system_clock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "ublox_low_level_api.h"
3636
#include "stm32f4xx.h"
37+
#include "nvic_addr.h"
3738

3839
/*!< Uncomment the following line if you need to relocate your vector Table in
3940
Internal SRAM. */
@@ -89,7 +90,7 @@ void SystemInit(void)
8990
#ifdef VECT_TAB_SRAM
9091
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
9192
#else
92-
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
93+
SCB->VTOR = NVIC_FLASH_VECTOR_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
9394
#endif
9495

9596
ublox_board_init();

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/device/TOOLCHAIN_ARM_STD/stm32f437xx.sct

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,18 @@
2929
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3030

3131
; 1 MB FLASH (0x100000) + 192 KB SRAM (0x30000) + 64 KB CCBRAM (0x10000)+ 4 KB BKPSRAM
32-
LR_IROM1 0x08000000 0x100000 { ; load region size_region
3332

34-
ER_IROM1 0x08000000 0x100000 { ; load address = execution address
33+
#if !defined(MBED_APP_START)
34+
#define MBED_APP_START 0x08000000
35+
#endif
36+
37+
#if !defined(MBED_APP_SIZE)
38+
#define MBED_APP_SIZE 0x100000
39+
#endif
40+
41+
LR_IROM1 MBED_APP_START MBED_APP_SIZE { ; load region size_region
42+
43+
ER_IROM1 MBED_APP_START MBED_APP_SIZE { ; load address = execution address
3544
*.o (RESET, +First)
3645
*(InRoot$$Sections)
3746
.ANY (+RO)

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/device/TOOLCHAIN_GCC_ARM/STM32F437xx.ld

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
#if !defined(MBED_APP_START)
2+
#define MBED_APP_START 0x08000000
3+
#endif
4+
5+
#if !defined(MBED_APP_SIZE)
6+
#define MBED_APP_SIZE 1024k
7+
#endif
8+
19
/* Linker script to configure memory regions. */
210
MEMORY
311
{
412
RAM (xrw) : ORIGIN = 0x200001AC, LENGTH = 192K - 0x1AC /* 0x1AC is to leave room for vectors */
513
CCM_RAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
614
BACKUP_SRAM (rw) : ORIGIN = 0x40024000, LENGTH = 4096
7-
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
15+
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
816
}
917

1018
/* Linker script to place sections and symbol values. Should be used together

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/device/TOOLCHAIN_IAR/stm32f437xx.icf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*###ICF### Section handled by ICF editor, don't touch! ****/
22
/*-Editor annotation file-*/
33
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
4+
if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x08000000; }
5+
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0x100000; }
46
/*-Specials-*/
5-
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
7+
define symbol __ICFEDIT_intvec_start__ = MBED_APP_START;
68
/*-Memory Regions-*/
7-
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
8-
define symbol __ICFEDIT_region_ROM_end__ = 0x080FFFFF;
9+
define symbol __ICFEDIT_region_ROM_start__ = MBED_APP_START;
10+
define symbol __ICFEDIT_region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
911
define symbol __ICFEDIT_region_NVIC_start__ = 0x20000000;
1012
define symbol __ICFEDIT_region_NVIC_end__ = 0x200001AF;
1113
define symbol __ICFEDIT_region_RAM_start__ = 0x200001B0;
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/* mbed Microcontroller Library
2+
*******************************************************************************
3+
* Copyright (c) 2017, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software
16+
* without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*******************************************************************************
29+
*/
30+
31+
#include "flash_api.h"
32+
#include "flash_data.h"
33+
#include "mbed_critical.h"
34+
35+
#if DEVICE_FLASH
36+
37+
#if defined (STM32F427xx) || defined (STM32F437xx)
38+
#define FLASH_SIZE (uint32_t) 0x100000
39+
#endif
40+
41+
static uint32_t GetSector(uint32_t Address);
42+
static uint32_t GetSectorSize(uint32_t Sector);
43+
44+
int32_t flash_init(flash_t *obj)
45+
{
46+
/* Allow Access to Flash control registers and user Falsh */
47+
if (HAL_FLASH_Unlock()) {
48+
return -1;
49+
} else {
50+
return 0;
51+
}
52+
}
53+
int32_t flash_free(flash_t *obj)
54+
{
55+
/* Disable the Flash option control register access (recommended to protect
56+
the option Bytes against possible unwanted operations) */
57+
if (HAL_FLASH_Lock()) {
58+
return -1;
59+
} else {
60+
return 0;
61+
}
62+
}
63+
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
64+
{
65+
/*Variable used for Erase procedure*/
66+
static FLASH_EraseInitTypeDef EraseInitStruct;
67+
uint32_t FirstSector;
68+
uint32_t SectorError = 0;
69+
70+
if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {
71+
72+
return -1;
73+
}
74+
75+
/* Get the 1st sector to erase */
76+
FirstSector = GetSector(address);
77+
78+
/* Fill EraseInit structure*/
79+
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
80+
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
81+
EraseInitStruct.Sector = FirstSector;
82+
EraseInitStruct.NbSectors = 1;
83+
if(HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK){
84+
return -1;
85+
} else {
86+
return 0;
87+
}
88+
}
89+
90+
int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size)
91+
{
92+
93+
if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {
94+
return -1;
95+
}
96+
97+
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
98+
you have to make sure that these data are rewritten before they are accessed during code
99+
execution. If this cannot be done safely, it is recommended to flush the caches by setting the
100+
DCRST and ICRST bits in the FLASH_CR register. */
101+
__HAL_FLASH_DATA_CACHE_DISABLE();
102+
__HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
103+
104+
__HAL_FLASH_DATA_CACHE_RESET();
105+
__HAL_FLASH_INSTRUCTION_CACHE_RESET();
106+
107+
__HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
108+
__HAL_FLASH_DATA_CACHE_ENABLE();
109+
110+
while (size > 0) {
111+
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, address, (uint64_t)*data) != HAL_OK) {
112+
return -1;
113+
} else {
114+
size--;
115+
address++;
116+
data++;
117+
}
118+
}
119+
return 0;
120+
}
121+
122+
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
123+
{
124+
125+
if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {
126+
return MBED_FLASH_INVALID_SIZE;
127+
}
128+
129+
return (GetSectorSize(GetSector(address)));
130+
}
131+
132+
uint32_t flash_get_page_size(const flash_t *obj)
133+
{
134+
// not applicable for STM32F4
135+
return (0x4000); // minimum sector size
136+
}
137+
uint32_t flash_get_start_address(const flash_t *obj)
138+
{
139+
return FLASH_BASE;
140+
}
141+
uint32_t flash_get_size(const flash_t *obj)
142+
{
143+
return FLASH_SIZE;
144+
}
145+
146+
/**
147+
* @brief Gets the sector of a given address
148+
* @param None
149+
* @retval The sector of a given address
150+
*/
151+
static uint32_t GetSector(uint32_t address)
152+
{
153+
uint32_t sector = 0;
154+
uint32_t tmp = address - ADDR_FLASH_SECTOR_0;
155+
if (address < ADDR_FLASH_SECTOR_4) { // 16k sectorsize
156+
sector += tmp >>14;
157+
} else if (address < ADDR_FLASH_SECTOR_5) { //64k sector size
158+
sector += FLASH_SECTOR_4;
159+
} else {
160+
sector += 4 + (tmp >>17);
161+
}
162+
return sector;
163+
}
164+
165+
/**
166+
* @brief Gets sector Size
167+
* @param None
168+
* @retval The size of a given sector
169+
*/
170+
static uint32_t GetSectorSize(uint32_t Sector)
171+
{
172+
uint32_t sectorsize = 0x00;
173+
if((Sector == FLASH_SECTOR_0) || (Sector == FLASH_SECTOR_1) || (Sector == FLASH_SECTOR_2) ||\
174+
(Sector == FLASH_SECTOR_3)) {
175+
sectorsize = 16 * 1024;
176+
} else if((Sector == FLASH_SECTOR_4)){
177+
sectorsize = 64 * 1024;
178+
} else {
179+
sectorsize = 128 * 1024;
180+
}
181+
return sectorsize;
182+
}
183+
184+
#endif
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* mbed Microcontroller Library
2+
*******************************************************************************
3+
* Copyright (c) 2016, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software
16+
* without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*******************************************************************************
29+
*/
30+
#ifndef MBED_FLASH_DATA_H
31+
#define MBED_FLASH_DATA_H
32+
33+
#include "device.h"
34+
#include <stdint.h>
35+
36+
#if DEVICE_FLASH
37+
38+
/* Exported types ------------------------------------------------------------*/
39+
/* Exported constants --------------------------------------------------------*/
40+
/* Exported macro ------------------------------------------------------------*/
41+
/* Base address of the Flash sectors */
42+
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
43+
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
44+
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
45+
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
46+
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
47+
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
48+
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
49+
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
50+
#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */
51+
#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */
52+
#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */
53+
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */
54+
55+
#endif
56+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017-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+
#ifndef NVIC_ADDR_H
17+
#define NVIC_ADDR_H
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
#if defined(__ICCARM__)
24+
#pragma section=".intvec"
25+
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t)__section_begin(".intvec"))
26+
#elif defined(__CC_ARM)
27+
extern uint32_t Load$$LR$$LR_IROM1$$Base[];
28+
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t)Load$$LR$$LR_IROM1$$Base)
29+
#elif defined(__GNUC__)
30+
extern uint32_t g_pfnVectors[];
31+
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t)g_pfnVectors)
32+
#else
33+
#error "Flash vector address not set for this toolchain"
34+
#endif
35+
36+
#ifdef __cplusplus
37+
}
38+
#endif
39+
40+
#endif

targets/targets.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,10 +1707,11 @@
17071707
}
17081708
},
17091709
"macros_add": ["RTC_LSI=1", "HSE_VALUE=12000000", "GNSSBAUD=9600"],
1710-
"device_has_add": ["ANALOGOUT", "TRNG"],
1710+
"device_has_add": ["ANALOGOUT", "SERIAL_FC", "TRNG", "FLASH"],
17111711
"features": ["LWIP"],
17121712
"public": false,
1713-
"device_name": "STM32F437VG"
1713+
"device_name": "STM32F437VG",
1714+
"bootloader_supported": true
17141715
},
17151716
"UBLOX_C030_U201": {
17161717
"inherits": ["UBLOX_C030"],

0 commit comments

Comments
 (0)