Skip to content

Commit 61104fc

Browse files
jeromecoutantbakatrouble
authored andcommitted
STM32F7 : FLASH driver issue
1 parent c5a72d7 commit 61104fc

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

targets/TARGET_STM/TARGET_STM32F7/TARGET_STM32F722xE/flash_data.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,21 @@
3030
#ifndef MBED_FLASH_DATA_H
3131
#define MBED_FLASH_DATA_H
3232

33-
#include "device.h"
34-
#include <stdint.h>
33+
// #include "device.h"
34+
// #include <stdint.h>
3535

3636
#if DEVICE_FLASH
3737

38-
/* Exported types ------------------------------------------------------------*/
39-
/* Exported constants --------------------------------------------------------*/
40-
/* Exported macro ------------------------------------------------------------*/
41-
/* Flash size */
42-
#define FLASH_SIZE (uint32_t) 0x80000
38+
#define FLASH_SIZE 0x80000
4339

44-
/* Base address of the Flash sectors Bank 1 */
45-
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 32 Kbytes */
46-
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08008000) /* Base @ of Sector 1, 32 Kbytes */
47-
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08010000) /* Base @ of Sector 2, 32 Kbytes */
48-
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x08018000) /* Base @ of Sector 3, 32 Kbytes */
49-
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08020000) /* Base @ of Sector 4, 128 Kbytes */
50-
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08040000) /* Base @ of Sector 5, 256 Kbytes */
40+
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
41+
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
42+
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
43+
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
44+
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
45+
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
46+
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
47+
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
5148

5249
#endif
5350
#endif

targets/TARGET_STM/TARGET_STM32F7/flash_api.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,37 @@ static uint32_t GetSector(uint32_t address)
206206
sector += 16 + (tmp >> 17);
207207
}
208208
#else // SINGLE BANK
209-
if (address < ADDR_FLASH_SECTOR_4) { // Sectors 0 to 3
210-
sector += tmp >> 15;
211-
} else if (address < ADDR_FLASH_SECTOR_5) { // Sector 4
212-
sector += FLASH_SECTOR_4;
213-
} else { // Sectors 5 to 11
214-
sector += 4 + (tmp >> 18);
209+
if (address < ADDR_FLASH_SECTOR_1) {
210+
sector = 0;
211+
} else if (address < ADDR_FLASH_SECTOR_2) {
212+
sector = 1;
213+
} else if (address < ADDR_FLASH_SECTOR_3) {
214+
sector = 2;
215+
} else if (address < ADDR_FLASH_SECTOR_4) {
216+
sector = 3;
217+
} else if (address < ADDR_FLASH_SECTOR_5) {
218+
sector = 4;
219+
} else if (address < ADDR_FLASH_SECTOR_6) {
220+
sector = 5;
221+
} else if (address < ADDR_FLASH_SECTOR_7) {
222+
sector = 6;
223+
#if defined (ADDR_FLASH_SECTOR_8)
224+
} else if (address < ADDR_FLASH_SECTOR_8) {
225+
sector = 7;
226+
} else if (address < ADDR_FLASH_SECTOR_9) {
227+
sector = 8;
228+
} else if (address < ADDR_FLASH_SECTOR_10) {
229+
sector = 9;
230+
} else if (address < ADDR_FLASH_SECTOR_11) {
231+
sector = 10;
232+
} else {
233+
sector = 11;
234+
}
235+
#else
236+
} else {
237+
sector = 7;
215238
}
239+
#endif
216240
#endif
217241
return sector;
218242
}
@@ -239,11 +263,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
239263
#else // SINGLE BANK
240264
if ((Sector == FLASH_SECTOR_0) || (Sector == FLASH_SECTOR_1) || \
241265
(Sector == FLASH_SECTOR_2) || (Sector == FLASH_SECTOR_3)) {
242-
sectorsize = 32 * 1024;
266+
sectorsize = ADDR_FLASH_SECTOR_1 - ADDR_FLASH_SECTOR_0;
243267
} else if (Sector == FLASH_SECTOR_4) {
244-
sectorsize = 128 * 1024;
268+
sectorsize = ADDR_FLASH_SECTOR_5 - ADDR_FLASH_SECTOR_4;
245269
} else {
246-
sectorsize = 256 * 1024;
270+
sectorsize = ADDR_FLASH_SECTOR_7 - ADDR_FLASH_SECTOR_6;
247271
}
248272
#endif
249273
return sectorsize;

0 commit comments

Comments
 (0)