Skip to content

Commit 47b8125

Browse files
adustm0xc0170
authored andcommitted
Replase CMSIS flash driver by SDK flash driver
1 parent 03aa77a commit 47b8125

File tree

4 files changed

+104
-117
lines changed

4 files changed

+104
-117
lines changed

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/device/flash_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static uint32_t GetSector(uint32_t address)
165165
} else {
166166
sector += 4 + (tmp >>17);
167167
}
168-
return sector;
168+
return sector;
169169
}
170170

171171
/**
@@ -180,7 +180,7 @@ static uint32_t GetSectorSize(uint32_t Sector)
180180
(Sector == FLASH_SECTOR_3) || (Sector == FLASH_SECTOR_12) || (Sector == FLASH_SECTOR_13) ||\
181181
(Sector == FLASH_SECTOR_14) || (Sector == FLASH_SECTOR_15)) {
182182
sectorsize = 16 * 1024;
183-
} else if((Sector == FLASH_SECTOR_4) || (Sector == FLASH_SECTOR_16)){
183+
} else if((Sector == FLASH_SECTOR_4) || (Sector == FLASH_SECTOR_16)) {
184184
sectorsize = 64 * 1024;
185185
} else {
186186
sectorsize = 128 * 1024;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 Bank 1 */
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+
/* Base address of the Flash sectors Bank 2 */
56+
#define ADDR_FLASH_SECTOR_12 ((uint32_t)0x08100000) /* Base @ of Sector 0, 16 Kbytes */
57+
#define ADDR_FLASH_SECTOR_13 ((uint32_t)0x08104000) /* Base @ of Sector 1, 16 Kbytes */
58+
#define ADDR_FLASH_SECTOR_14 ((uint32_t)0x08108000) /* Base @ of Sector 2, 16 Kbytes */
59+
#define ADDR_FLASH_SECTOR_15 ((uint32_t)0x0810C000) /* Base @ of Sector 3, 16 Kbytes */
60+
#define ADDR_FLASH_SECTOR_16 ((uint32_t)0x08110000) /* Base @ of Sector 4, 64 Kbytes */
61+
#define ADDR_FLASH_SECTOR_17 ((uint32_t)0x08120000) /* Base @ of Sector 5, 128 Kbytes */
62+
#define ADDR_FLASH_SECTOR_18 ((uint32_t)0x08140000) /* Base @ of Sector 6, 128 Kbytes */
63+
#define ADDR_FLASH_SECTOR_19 ((uint32_t)0x08160000) /* Base @ of Sector 7, 128 Kbytes */
64+
#define ADDR_FLASH_SECTOR_20 ((uint32_t)0x08180000) /* Base @ of Sector 8, 128 Kbytes */
65+
#define ADDR_FLASH_SECTOR_21 ((uint32_t)0x081A0000) /* Base @ of Sector 9, 128 Kbytes */
66+
#define ADDR_FLASH_SECTOR_22 ((uint32_t)0x081C0000) /* Base @ of Sector 10, 128 Kbytes */
67+
#define ADDR_FLASH_SECTOR_23 ((uint32_t)0x081E0000) /* Base @ of Sector 11, 128 Kbytes */
68+
69+
70+
#endif
71+
#endif

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/device/flash_api.c

Lines changed: 28 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -152,107 +152,21 @@ uint32_t flash_get_size(const flash_t *obj)
152152
*/
153153
static uint32_t GetSector(uint32_t address)
154154
{
155-
uint32_t sector = 0;
156-
157-
if((address < ADDR_FLASH_SECTOR_1) && (address >= ADDR_FLASH_SECTOR_0))
158-
{
159-
sector = FLASH_SECTOR_0;
160-
}
161-
else if((address < ADDR_FLASH_SECTOR_2) && (address >= ADDR_FLASH_SECTOR_1))
162-
{
163-
sector = FLASH_SECTOR_1;
164-
}
165-
else if((address < ADDR_FLASH_SECTOR_3) && (address >= ADDR_FLASH_SECTOR_2))
166-
{
167-
sector = FLASH_SECTOR_2;
168-
}
169-
else if((address < ADDR_FLASH_SECTOR_4) && (address >= ADDR_FLASH_SECTOR_3))
170-
{
171-
sector = FLASH_SECTOR_3;
172-
}
173-
else if((address < ADDR_FLASH_SECTOR_5) && (address >= ADDR_FLASH_SECTOR_4))
174-
{
175-
sector = FLASH_SECTOR_4;
176-
}
177-
else if((address < ADDR_FLASH_SECTOR_6) && (address >= ADDR_FLASH_SECTOR_5))
178-
{
179-
sector = FLASH_SECTOR_5;
180-
}
181-
else if((address < ADDR_FLASH_SECTOR_7) && (address >= ADDR_FLASH_SECTOR_6))
182-
{
183-
sector = FLASH_SECTOR_6;
184-
}
185-
else if((address < ADDR_FLASH_SECTOR_8) && (address >= ADDR_FLASH_SECTOR_7))
186-
{
187-
sector = FLASH_SECTOR_7;
188-
}
189-
else if((address < ADDR_FLASH_SECTOR_9) && (address >= ADDR_FLASH_SECTOR_8))
190-
{
191-
sector = FLASH_SECTOR_8;
192-
}
193-
else if((address < ADDR_FLASH_SECTOR_10) && (address >= ADDR_FLASH_SECTOR_9))
194-
{
195-
sector = FLASH_SECTOR_9;
196-
}
197-
else if((address < ADDR_FLASH_SECTOR_11) && (address >= ADDR_FLASH_SECTOR_10))
198-
{
199-
sector = FLASH_SECTOR_10;
200-
}
201-
else if((address < ADDR_FLASH_SECTOR_12) && (address >= ADDR_FLASH_SECTOR_11))
202-
{
203-
sector = FLASH_SECTOR_11;
204-
}
205-
else if((address < ADDR_FLASH_SECTOR_13) && (address >= ADDR_FLASH_SECTOR_12))
206-
{
207-
sector = FLASH_SECTOR_12;
208-
}
209-
else if((address < ADDR_FLASH_SECTOR_14) && (address >= ADDR_FLASH_SECTOR_13))
210-
{
211-
sector = FLASH_SECTOR_13;
212-
}
213-
else if((address < ADDR_FLASH_SECTOR_15) && (address >= ADDR_FLASH_SECTOR_14))
214-
{
215-
sector = FLASH_SECTOR_14;
216-
}
217-
else if((address < ADDR_FLASH_SECTOR_16) && (address >= ADDR_FLASH_SECTOR_15))
218-
{
219-
sector = FLASH_SECTOR_15;
220-
}
221-
else if((address < ADDR_FLASH_SECTOR_17) && (address >= ADDR_FLASH_SECTOR_16))
222-
{
223-
sector = FLASH_SECTOR_16;
224-
}
225-
else if((address < ADDR_FLASH_SECTOR_18) && (address >= ADDR_FLASH_SECTOR_17))
226-
{
227-
sector = FLASH_SECTOR_17;
228-
}
229-
else if((address < ADDR_FLASH_SECTOR_19) && (address >= ADDR_FLASH_SECTOR_18))
230-
{
231-
sector = FLASH_SECTOR_18;
232-
}
233-
else if((address < ADDR_FLASH_SECTOR_20) && (address >= ADDR_FLASH_SECTOR_19))
234-
{
235-
sector = FLASH_SECTOR_19;
236-
}
237-
else if((address < ADDR_FLASH_SECTOR_21) && (address >= ADDR_FLASH_SECTOR_20))
238-
{
239-
sector = FLASH_SECTOR_20;
240-
}
241-
else if((address < ADDR_FLASH_SECTOR_22) && (address >= ADDR_FLASH_SECTOR_21))
242-
{
243-
sector = FLASH_SECTOR_21;
244-
}
245-
else if((address < ADDR_FLASH_SECTOR_23) && (address >= ADDR_FLASH_SECTOR_22))
246-
{
247-
sector = FLASH_SECTOR_22;
248-
}
249-
else/*(address < FLASH_END_ADDR) && (address >= ADDR_FLASH_SECTOR_23))*/
250-
{
251-
sector = FLASH_SECTOR_23;
252-
}
253-
254-
255-
return sector;
155+
uint32_t sector = 0;
156+
uint32_t tmp = address - ADDR_FLASH_SECTOR_0;
157+
if (address & 0x100000) { // handle 2nd bank
158+
sector = FLASH_SECTOR_12;
159+
tmp = address - ADDR_FLASH_SECTOR_12;
160+
}
161+
if (address < ADDR_FLASH_SECTOR_4) { // 16k sectorsize
162+
//printf("tmp for sectors less than 4: 0X%4x")
163+
sector += tmp >>14;
164+
} else if (address < ADDR_FLASH_SECTOR_5) { //64k sector size
165+
sector += FLASH_SECTOR_4;
166+
} else {
167+
sector += 4 + (tmp >>17);
168+
}
169+
return sector;
256170
}
257171

258172
/**
@@ -262,15 +176,17 @@ static uint32_t GetSector(uint32_t address)
262176
*/
263177
static uint32_t GetSectorSize(uint32_t Sector)
264178
{
265-
uint32_t sectorsize = 0x00;
266-
if((Sector == FLASH_SECTOR_0) || (Sector == FLASH_SECTOR_1) || (Sector == FLASH_SECTOR_2) ||\
267-
(Sector == FLASH_SECTOR_3) || (Sector == FLASH_SECTOR_12) || (Sector == FLASH_SECTOR_13) ||\
268-
(Sector == FLASH_SECTOR_14) || (Sector == FLASH_SECTOR_15)) {
269-
sectorsize = 16 * 1024;
270-
} else if((Sector == FLASH_SECTOR_4) || (Sector == FLASH_SECTOR_16)) {
271-
sectorsize = 64 * 1024;
272-
} else {
273-
sectorsize = 128 * 1024;
274-
}
275-
return sectorsize;
179+
uint32_t sectorsize = 0x00;
180+
if((Sector == FLASH_SECTOR_0) || (Sector == FLASH_SECTOR_1) || (Sector == FLASH_SECTOR_2) ||\
181+
(Sector == FLASH_SECTOR_3) || (Sector == FLASH_SECTOR_12) || (Sector == FLASH_SECTOR_13) ||\
182+
(Sector == FLASH_SECTOR_14) || (Sector == FLASH_SECTOR_15)) {
183+
sectorsize = 16 * 1024;
184+
} else if((Sector == FLASH_SECTOR_4) || (Sector == FLASH_SECTOR_16)){
185+
sectorsize = 64 * 1024;
186+
} else {
187+
sectorsize = 128 * 1024;
188+
}
189+
return sectorsize;
276190
}
191+
192+
#endif

targets/targets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@
958958
"macro_name": "CLOCK_SOURCE_USB"
959959
}
960960
},
961-
"extra_labels_add": ["STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx", "STM32F429xI", "FLASH_CMSIS_ALGO"],
961+
"extra_labels_add": ["STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx", "STM32F429xI"],
962962
"macros_add": ["USB_STM_HAL", "USBHOST_OTHER"],
963963
"device_has_add": ["ANALOGOUT", "CAN", "ERROR_RED", "LOWPOWERTIMER", "SERIAL_FC", "TRNG", "FLASH"],
964964
"detect_code": ["0796"],
@@ -988,7 +988,7 @@
988988
"macro_name": "CLOCK_SOURCE_USB"
989989
}
990990
},
991-
"extra_labels_add": ["STM32F4", "STM32F439", "STM32F439ZI", "STM32F439xx", "STM32F439xI", "FLASH_CMSIS_ALGO"],
991+
"extra_labels_add": ["STM32F4", "STM32F439", "STM32F439ZI", "STM32F439xx", "STM32F439xI"],
992992
"macros_add": ["MBEDTLS_CONFIG_HW_SUPPORT", "USB_STM_HAL", "USBHOST_OTHER"],
993993
"device_has_add": ["ANALOGOUT", "CAN", "ERROR_RED", "LOWPOWERTIMER", "SERIAL_FC", "TRNG", "FLASH"],
994994
"detect_code": ["0797"],
@@ -1255,7 +1255,7 @@
12551255
"DISCO_F429ZI": {
12561256
"inherits": ["FAMILY_STM32"],
12571257
"core": "Cortex-M4F",
1258-
"extra_labels_add": ["STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xI", "STM32F429xx", "FLASH_CMSIS_ALGO"],
1258+
"extra_labels_add": ["STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xI", "STM32F429xx"],
12591259
"config": {
12601260
"clock_source": {
12611261
"help": "Mask value : USE_PLL_HSE_EXTC | USE_PLL_HSE_XTAL (need HW patch) | USE_PLL_HSI",

0 commit comments

Comments
 (0)