This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 6e7b35d02 mcu/stm32h7: Fix flash write/erase
6e7b35d02 is described below
commit 6e7b35d02a6e3f1080cafac9b7bb24c5202a77cb
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Tue Jul 11 11:07:22 2023 +0200
mcu/stm32h7: Fix flash write/erase
Flash min write size was incorrectly set to 1 while for most
H7 MCUs it has to be 32 bytes.
HAL_FLASH_Program uses different arguments then the reset of
MCU with non-linear flash sectors.
Write now respects minimum write size.
STM32H7 hal requires eraseInit.Banks field to be set.
Signed-off-by: Jerzy Kasenberg <[email protected]>
---
hw/mcu/stm/stm32_common/src/hal_flash.c | 17 ++++++++++++++---
hw/mcu/stm/stm32h7xx/syscfg.yml | 2 +-
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/hw/mcu/stm/stm32_common/src/hal_flash.c
b/hw/mcu/stm/stm32_common/src/hal_flash.c
index f5dc80c9f..9301df49f 100644
--- a/hw/mcu/stm/stm32_common/src/hal_flash.c
+++ b/hw/mcu/stm/stm32_common/src/hal_flash.c
@@ -121,7 +121,7 @@ stm32_flash_write_linear(const struct hal_flash *dev,
uint32_t address,
/* FIXME: L1 was previously unlocking flash before erasing/programming,
* and locking again afterwards. Maybe all MCUs should do the same?
*/
-#if MYNEWT_VAL(MCU_STM32U5) || MYNEWT_VAL(MCU_STM32H7)
+#if MYNEWT_VAL(MCU_STM32U5)
rc = HAL_FLASH_Program(FLASH_PROGRAM_TYPE, address, (uint32_t)&val);
#else
rc = HAL_FLASH_Program(FLASH_PROGRAM_TYPE, address, val);
@@ -156,6 +156,7 @@ stm32_flash_write_non_linear(const struct hal_flash *dev,
uint32_t address,
const uint8_t *sptr;
uint32_t i;
int rc;
+ int inc = MYNEWT_VAL(MCU_FLASH_MIN_WRITE_SIZE);
sptr = src;
/*
@@ -163,13 +164,17 @@ stm32_flash_write_non_linear(const struct hal_flash *dev,
uint32_t address,
*/
STM32_HAL_FLASH_CLEAR_ERRORS();
- for (i = 0; i < num_bytes; i++) {
+ for (i = 0; i < num_bytes; i += inc) {
+#if MYNEWT_VAL(MCU_STM32H7)
+ rc = HAL_FLASH_Program(FLASH_PROGRAM_TYPE, address, (uint32_t)(sptr +
i));
+#else
rc = HAL_FLASH_Program(FLASH_PROGRAM_TYPE, address, sptr[i]);
+#endif
if (rc != 0) {
return rc;
}
- address++;
+ address += inc;
}
return 0;
@@ -205,6 +210,12 @@ stm32_flash_erase_sector(const struct hal_flash *dev,
uint32_t sector_address)
eraseinit.TypeErase = FLASH_TYPEERASE_SECTORS;
#ifdef FLASH_OPTCR_nDBANK
eraseinit.Banks = FLASH_BANK_1; /* Only used for mass erase */
+#elif defined STM32H7
+#if defined (DUAL_BANK)
+ eraseinit.Banks = IS_FLASH_PROGRAM_ADDRESS_BANK1(ADDRESS) ?
FLASH_BANK_1 : FLASH_BANK_2;
+#else
+ eraseinit.Banks = FLASH_BANK_1;
+#endif
#endif
eraseinit.Sector = i;
eraseinit.NbSectors = 1;
diff --git a/hw/mcu/stm/stm32h7xx/syscfg.yml b/hw/mcu/stm/stm32h7xx/syscfg.yml
index ced6a3b37..1d2229df8 100644
--- a/hw/mcu/stm/stm32h7xx/syscfg.yml
+++ b/hw/mcu/stm/stm32h7xx/syscfg.yml
@@ -21,7 +21,7 @@ syscfg.defs:
description: >
Specifies the required alignment for internal flash writes.
Used internally by the newt tool.
- value: 1
+ value: 32
MCU_STM32H7:
description: MCUs are of STM32H7xx family