Skip to content

Commit d7d0d0b

Browse files
committed
STM32H7 FLASH and DEVICE_KEY
- Enable FLASHIAP for all H7 boards - Use "TDB_INTERNAL" for all H7 boards - Define specific internal_base_address only for DISCO_H747I_CM7 (default address is the end of FLASH which is correct for other H7 boards) - Correct GetSectorBase function with Dual Bank information
1 parent cbf9f06 commit d7d0d0b

File tree

6 files changed

+49
-83
lines changed

6 files changed

+49
-83
lines changed

features/storage/kvstore/conf/global/mbed_lib.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@
2020
"NUCLEO_F429ZI": {
2121
"storage_type": "TDB_INTERNAL"
2222
},
23+
"NUCLEO_H743ZI": {
24+
"storage_type": "TDB_INTERNAL"
25+
},
26+
"NUCLEO_H743ZI2": {
27+
"storage_type": "TDB_INTERNAL"
28+
},
2329
"DISCO_H747I": {
2430
"storage_type": "TDB_INTERNAL"
2531
},
32+
"DISCO_H747I_CM4": {
33+
"storage_type": "TDB_INTERNAL"
34+
},
2635
"UBLOX_EVK_ODIN_W2": {
2736
"storage_type": "TDB_INTERNAL"
2837
},

features/storage/kvstore/conf/tdb_internal/mbed_lib.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"internal_base_address": "0x00028000"
1717
},
1818
"DISCO_H747I": {
19-
"internal_size": "256*1024",
19+
"internal_size": "2*FLASH_SECTOR_SIZE",
2020
"internal_base_address": "0x080C0000"
2121
},
22-
"ARM_MUSCA_A1_S": {
22+
"ARM_MUSCA_A1_S": {
2323
"internal_size": "0x8000",
2424
"internal_base_address": "0x00420000"
2525
},
Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,21 @@
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-
*/
1+
/*
2+
******************************************************************************
3+
* @attention
4+
*
5+
* <h2><center>&copy; Copyright (c) 2016-2019 STMicroelectronics.
6+
* All rights reserved.</center></h2>
7+
*
8+
* This software component is licensed by ST under BSD 3-Clause license,
9+
* the "License"; You may not use this file except in compliance with the
10+
* License. You may obtain a copy of the License at:
11+
* opensource.org/licenses/BSD-3-Clause
12+
*
13+
******************************************************************************
14+
*/
15+
3016
#ifndef MBED_FLASH_DATA_H
3117
#define MBED_FLASH_DATA_H
3218

33-
#include "device.h"
34-
#include <stdint.h>
35-
36-
#if DEVICE_FLASH
37-
38-
/* Exported types ------------------------------------------------------------*/
39-
/* Exported constants --------------------------------------------------------*/
40-
/* Exported macro ------------------------------------------------------------*/
41-
42-
/* Flash size */
43-
#ifndef FLASH_SIZE
44-
#define FLASH_SIZE (uint32_t) 0x200000 // 2Mb
45-
#endif
46-
4719
#define ADDR_FLASH_SECTOR_0_BANK1 ((uint32_t)0x08000000) /* Base @ of Sector 0, Bank1, 128 Kbyte */
4820
#define ADDR_FLASH_SECTOR_1_BANK1 ((uint32_t)0x08020000) /* Base @ of Sector 1, Bank1, 128 Kbyte */
4921
#define ADDR_FLASH_SECTOR_2_BANK1 ((uint32_t)0x08040000) /* Base @ of Sector 2, Bank1, 128 Kbyte */
@@ -62,6 +34,4 @@
6234
#define ADDR_FLASH_SECTOR_6_BANK2 ((uint32_t)0x081C0000) /* Base @ of Sector 6, Bank2, 128 Kbyte */
6335
#define ADDR_FLASH_SECTOR_7_BANK2 ((uint32_t)0x081E0000) /* Base @ of Sector 7, Bank2, 128 Kbyte */
6436

65-
#endif // DEVICE_FLASH
66-
6737
#endif

targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/flash_data.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
******************************************************************************
33
* @attention
44
*
5-
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
5+
* <h2><center>&copy; Copyright (c) 2018-2019 STMicroelectronics.
66
* All rights reserved.</center></h2>
77
*
88
* This software component is licensed by ST under BSD 3-Clause license,
@@ -16,20 +16,6 @@
1616
#ifndef MBED_FLASH_DATA_H
1717
#define MBED_FLASH_DATA_H
1818

19-
#include "device.h"
20-
#include <stdint.h>
21-
22-
#if DEVICE_FLASH
23-
24-
/* Exported types ------------------------------------------------------------*/
25-
/* Exported constants --------------------------------------------------------*/
26-
/* Exported macro ------------------------------------------------------------*/
27-
28-
/* Flash size */
29-
#ifndef FLASH_SIZE
30-
#define FLASH_SIZE (uint32_t) 0x200000 // 2Mb
31-
#endif
32-
3319
#define ADDR_FLASH_SECTOR_0_BANK1 ((uint32_t)0x08000000) /* Base @ of Sector 0, Bank1, 128 Kbyte */
3420
#define ADDR_FLASH_SECTOR_1_BANK1 ((uint32_t)0x08020000) /* Base @ of Sector 1, Bank1, 128 Kbyte */
3521
#define ADDR_FLASH_SECTOR_2_BANK1 ((uint32_t)0x08040000) /* Base @ of Sector 2, Bank1, 128 Kbyte */
@@ -48,6 +34,4 @@
4834
#define ADDR_FLASH_SECTOR_6_BANK2 ((uint32_t)0x081C0000) /* Base @ of Sector 6, Bank2, 128 Kbyte */
4935
#define ADDR_FLASH_SECTOR_7_BANK2 ((uint32_t)0x081E0000) /* Base @ of Sector 7, Bank2, 128 Kbyte */
5036

51-
#endif // DEVICE_FLASH
52-
5337
#endif

targets/TARGET_STM/TARGET_STM32H7/flash_api.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2017 ARM Limited
3-
* Copyright (c) 2017 STMicroelectronics
2+
* Copyright (c) 2017-2019 ARM Limited
3+
* Copyright (c) 2017-2019 STMicroelectronics
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,7 @@
2323

2424
static uint32_t GetSector(uint32_t Address);
2525
static uint32_t GetSectorSize(uint32_t Sector);
26-
static uint32_t GetSectorBase(uint32_t SectorId);
26+
static uint32_t GetSectorBase(uint32_t SectorId, uint32_t BanksId);
2727

2828
int32_t flash_init(flash_t *obj)
2929
{
@@ -50,7 +50,6 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
5050
{
5151
/* Variable used for Erase procedure */
5252
FLASH_EraseInitTypeDef EraseInitStruct;
53-
uint32_t SectorId;
5453
uint32_t SectorError = 0;
5554
int32_t status = 0;
5655

@@ -70,29 +69,23 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
7069
return -1;
7170
}
7271

73-
/* Get the 1st sector to erase */
74-
SectorId = GetSector(address);
75-
7672
/* Fill EraseInit structure */
7773
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
7874
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
79-
EraseInitStruct.Sector = SectorId;
75+
EraseInitStruct.Sector = GetSector(address);
8076
EraseInitStruct.NbSectors = 1;
8177

8278
if (address < ADDR_FLASH_SECTOR_0_BANK2) {
8379
EraseInitStruct.Banks = FLASH_BANK_1;
84-
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
85-
status = -1;
86-
}
8780
} else {
88-
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
8981
EraseInitStruct.Banks = FLASH_BANK_2;
90-
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
91-
status = -1;
92-
}
9382
}
9483

95-
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)GetSectorBase(SectorId), GetSectorSize(SectorId));
84+
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
85+
status = -1;
86+
}
87+
88+
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)GetSectorBase(EraseInitStruct.Sector, EraseInitStruct.Banks), GetSectorSize(EraseInitStruct.Sector));
9689
SCB_InvalidateICache();
9790

9891
HAL_FLASH_Lock();
@@ -218,18 +211,25 @@ static uint32_t GetSector(uint32_t Address)
218211
*/
219212
static uint32_t GetSectorSize(uint32_t Sector)
220213
{
221-
return (uint32_t)(128 * 1024); // 128 KB
214+
return FLASH_SECTOR_SIZE;
222215
}
223216

224217
/**
225218
* @brief Gets sector base address
226219
* @param SectorId
220+
* @param BanksId
227221
* @retval base address of a given sector
228222
*/
229-
static uint32_t GetSectorBase(uint32_t SectorId)
223+
static uint32_t GetSectorBase(uint32_t SectorId, uint32_t BanksId)
230224
{
231225
uint32_t i = 0;
232-
uint32_t address_sector = FLASH_BASE;
226+
uint32_t address_sector;
227+
228+
if (BanksId == FLASH_BANK_1) {
229+
address_sector = FLASH_BANK1_BASE;
230+
} else {
231+
address_sector = FLASH_BANK2_BASE;
232+
}
233233

234234
for (i = 0; i < SectorId; i++) {
235235
address_sector += GetSectorSize(i);

targets/targets.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,6 +3236,7 @@
32363236
"macro_name": "HSE_VALUE"
32373237
}
32383238
},
3239+
"components_add": ["FLASHIAP"],
32393240
"macros_add": [
32403241
"STM32H743xx",
32413242
"EXTRA_IDLE_STACK_REQUIRED",
@@ -3288,6 +3289,7 @@
32883289
"macro_name": "HSE_VALUE"
32893290
}
32903291
},
3292+
"components_add": ["FLASHIAP"],
32913293
"macros_add": [
32923294
"STM32H743xx",
32933295
"EXTRA_IDLE_STACK_REQUIRED",
@@ -3359,6 +3361,7 @@
33593361
"STM32H747xI",
33603362
"DISCO_H747I"
33613363
],
3364+
"components_add": ["FLASHIAP"],
33623365
"config": {
33633366
"lpticker_lptim": {
33643367
"help": "This target supports LPTIM. Set value 1 to use LPTIM for LPTICKER, or 0 to use RTC wakeup timer",

0 commit comments

Comments
 (0)