Skip to content

Commit 5db6e4f

Browse files
adustmkegilbert
authored andcommitted
Replase CMSIS flash driver by SDK flash driver
1 parent 86d0f29 commit 5db6e4f

File tree

4 files changed

+101
-139
lines changed

4 files changed

+101
-139
lines changed

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2017 ARM Limited
2+
*******************************************************************************
3+
* Copyright (c) 2017, STMicroelectronics
4+
* All rights reserved.
35
*
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
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
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.
917
*
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.
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+
*******************************************************************************
1529
*/
1630

1731
#include "flash_api.h"
@@ -152,8 +166,7 @@ static uint32_t GetSector(uint32_t address)
152166
} else {
153167
sector += 4 + (tmp >>17);
154168
}
155-
printf("address:0X%04x%04x, secteur: %d\n", (address>>16)&0XFFFF, (address&0XFFFF), sector);
156-
return sector;
169+
return sector;
157170
}
158171

159172
/**
@@ -168,7 +181,7 @@ static uint32_t GetSectorSize(uint32_t Sector)
168181
(Sector == FLASH_SECTOR_3) || (Sector == FLASH_SECTOR_12) || (Sector == FLASH_SECTOR_13) ||\
169182
(Sector == FLASH_SECTOR_14) || (Sector == FLASH_SECTOR_15)) {
170183
sectorsize = 16 * 1024;
171-
} else if((Sector == FLASH_SECTOR_4) || (Sector == FLASH_SECTOR_16)){
184+
} else if((Sector == FLASH_SECTOR_4) || (Sector == FLASH_SECTOR_16)) {
172185
sectorsize = 64 * 1024;
173186
} else {
174187
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: 1 addition & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ uint32_t flash_get_size(const flash_t *obj)
152152
*/
153153
static uint32_t GetSector(uint32_t address)
154154
{
155-
<<<<<<< HEAD
156155
uint32_t sector = 0;
157156
uint32_t tmp = address - ADDR_FLASH_SECTOR_0;
158157
if (address & 0x100000) { // handle 2nd bank
@@ -167,109 +166,7 @@ static uint32_t GetSector(uint32_t address)
167166
} else {
168167
sector += 4 + (tmp >>17);
169168
}
170-
printf("address:0X%04x%04x, secteur: %d\n", (address>>16)&0XFFFF, (address&0XFFFF), sector);
171-
=======
172-
uint32_t sector = 0;
173-
174-
if((address < ADDR_FLASH_SECTOR_1) && (address >= ADDR_FLASH_SECTOR_0))
175-
{
176-
sector = FLASH_SECTOR_0;
177-
}
178-
else if((address < ADDR_FLASH_SECTOR_2) && (address >= ADDR_FLASH_SECTOR_1))
179-
{
180-
sector = FLASH_SECTOR_1;
181-
}
182-
else if((address < ADDR_FLASH_SECTOR_3) && (address >= ADDR_FLASH_SECTOR_2))
183-
{
184-
sector = FLASH_SECTOR_2;
185-
}
186-
else if((address < ADDR_FLASH_SECTOR_4) && (address >= ADDR_FLASH_SECTOR_3))
187-
{
188-
sector = FLASH_SECTOR_3;
189-
}
190-
else if((address < ADDR_FLASH_SECTOR_5) && (address >= ADDR_FLASH_SECTOR_4))
191-
{
192-
sector = FLASH_SECTOR_4;
193-
}
194-
else if((address < ADDR_FLASH_SECTOR_6) && (address >= ADDR_FLASH_SECTOR_5))
195-
{
196-
sector = FLASH_SECTOR_5;
197-
}
198-
else if((address < ADDR_FLASH_SECTOR_7) && (address >= ADDR_FLASH_SECTOR_6))
199-
{
200-
sector = FLASH_SECTOR_6;
201-
}
202-
else if((address < ADDR_FLASH_SECTOR_8) && (address >= ADDR_FLASH_SECTOR_7))
203-
{
204-
sector = FLASH_SECTOR_7;
205-
}
206-
else if((address < ADDR_FLASH_SECTOR_9) && (address >= ADDR_FLASH_SECTOR_8))
207-
{
208-
sector = FLASH_SECTOR_8;
209-
}
210-
else if((address < ADDR_FLASH_SECTOR_10) && (address >= ADDR_FLASH_SECTOR_9))
211-
{
212-
sector = FLASH_SECTOR_9;
213-
}
214-
else if((address < ADDR_FLASH_SECTOR_11) && (address >= ADDR_FLASH_SECTOR_10))
215-
{
216-
sector = FLASH_SECTOR_10;
217-
}
218-
else if((address < ADDR_FLASH_SECTOR_12) && (address >= ADDR_FLASH_SECTOR_11))
219-
{
220-
sector = FLASH_SECTOR_11;
221-
}
222-
else if((address < ADDR_FLASH_SECTOR_13) && (address >= ADDR_FLASH_SECTOR_12))
223-
{
224-
sector = FLASH_SECTOR_12;
225-
}
226-
else if((address < ADDR_FLASH_SECTOR_14) && (address >= ADDR_FLASH_SECTOR_13))
227-
{
228-
sector = FLASH_SECTOR_13;
229-
}
230-
else if((address < ADDR_FLASH_SECTOR_15) && (address >= ADDR_FLASH_SECTOR_14))
231-
{
232-
sector = FLASH_SECTOR_14;
233-
}
234-
else if((address < ADDR_FLASH_SECTOR_16) && (address >= ADDR_FLASH_SECTOR_15))
235-
{
236-
sector = FLASH_SECTOR_15;
237-
}
238-
else if((address < ADDR_FLASH_SECTOR_17) && (address >= ADDR_FLASH_SECTOR_16))
239-
{
240-
sector = FLASH_SECTOR_16;
241-
}
242-
else if((address < ADDR_FLASH_SECTOR_18) && (address >= ADDR_FLASH_SECTOR_17))
243-
{
244-
sector = FLASH_SECTOR_17;
245-
}
246-
else if((address < ADDR_FLASH_SECTOR_19) && (address >= ADDR_FLASH_SECTOR_18))
247-
{
248-
sector = FLASH_SECTOR_18;
249-
}
250-
else if((address < ADDR_FLASH_SECTOR_20) && (address >= ADDR_FLASH_SECTOR_19))
251-
{
252-
sector = FLASH_SECTOR_19;
253-
}
254-
else if((address < ADDR_FLASH_SECTOR_21) && (address >= ADDR_FLASH_SECTOR_20))
255-
{
256-
sector = FLASH_SECTOR_20;
257-
}
258-
else if((address < ADDR_FLASH_SECTOR_22) && (address >= ADDR_FLASH_SECTOR_21))
259-
{
260-
sector = FLASH_SECTOR_21;
261-
}
262-
else if((address < ADDR_FLASH_SECTOR_23) && (address >= ADDR_FLASH_SECTOR_22))
263-
{
264-
sector = FLASH_SECTOR_22;
265-
}
266-
else/*(address < FLASH_END_ADDR) && (address >= ADDR_FLASH_SECTOR_23))*/
267-
{
268-
sector = FLASH_SECTOR_23;
269-
}
270-
271-
>>>>>>> 634df4142... fix STM32F439 flash HAL
272-
return sector;
169+
return sector;
273170
}
274171

275172
/**
@@ -279,7 +176,6 @@ static uint32_t GetSector(uint32_t address)
279176
*/
280177
static uint32_t GetSectorSize(uint32_t Sector)
281178
{
282-
<<<<<<< HEAD
283179
uint32_t sectorsize = 0x00;
284180
if((Sector == FLASH_SECTOR_0) || (Sector == FLASH_SECTOR_1) || (Sector == FLASH_SECTOR_2) ||\
285181
(Sector == FLASH_SECTOR_3) || (Sector == FLASH_SECTOR_12) || (Sector == FLASH_SECTOR_13) ||\
@@ -291,24 +187,6 @@ static uint32_t GetSectorSize(uint32_t Sector)
291187
sectorsize = 128 * 1024;
292188
}
293189
return sectorsize;
294-
=======
295-
uint32_t sectorsize = 0x00;
296-
if((Sector == FLASH_SECTOR_0) || (Sector == FLASH_SECTOR_1) || (Sector == FLASH_SECTOR_2) ||\
297-
(Sector == FLASH_SECTOR_3) || (Sector == FLASH_SECTOR_12) || (Sector == FLASH_SECTOR_13) ||\
298-
(Sector == FLASH_SECTOR_14) || (Sector == FLASH_SECTOR_15))
299-
{
300-
sectorsize = 16 * 1024;
301-
}
302-
else if((Sector == FLASH_SECTOR_4) || (Sector == FLASH_SECTOR_16))
303-
{
304-
sectorsize = 64 * 1024;
305-
}
306-
else
307-
{
308-
sectorsize = 128 * 1024;
309-
}
310-
return sectorsize;
311-
>>>>>>> 634df4142... fix STM32F439 flash HAL
312190
}
313191

314192
#endif

targets/targets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@
917917
"macro_name": "STM32_D11_SPI_ETHERNET_PIN"
918918
}
919919
},
920-
"extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx", "STM32F429xI", "FLASH_CMSIS_ALGO"],
920+
"extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xx", "STM32F429xI"],
921921
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
922922
"progen": {"target": "nucleo-f429zi"},
923923
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "USB_STM_HAL", "USBHOST_OTHER"],
@@ -940,7 +940,7 @@
940940
"macro_name": "STM32_D11_SPI_ETHERNET_PIN"
941941
}
942942
},
943-
"extra_labels": ["STM", "STM32F4", "STM32F439", "STM32F439ZI", "STM32F439xx", "STM32F439xI", "FLASH_CMSIS_ALGO"],
943+
"extra_labels": ["STM", "STM32F4", "STM32F439", "STM32F439ZI", "STM32F439xx", "STM32F439xI"],
944944
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
945945
"progen": {"target": "nucleo-f439zi"},
946946
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "MBEDTLS_CONFIG_HW_SUPPORT", "USB_STM_HAL", "USBHOST_OTHER"],
@@ -1234,7 +1234,7 @@
12341234
"inherits": ["Target"],
12351235
"core": "Cortex-M4F",
12361236
"default_toolchain": "ARM",
1237-
"extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xI", "STM32F429xx", "FLASH_CMSIS_ALGO"],
1237+
"extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI", "STM32F429xI", "STM32F429xx"],
12381238
"macros": ["RTC_LSI=1","TRANSACTION_QUEUE_SIZE_SPI=2", "USBHOST_OTHER"],
12391239
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
12401240
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG", "FLASH"],

0 commit comments

Comments
 (0)