Skip to content

Commit

Permalink
arch: stm32h7: Add support for dual bank flash
Browse files Browse the repository at this point in the history
memory

Signed-off-by: Andrés Sánchez Pascual <tito97_sp@hotmail.com>
  • Loading branch information
tito97sp authored and xiaoxiang781216 committed Oct 9, 2022
1 parent 7005370 commit c28b05e
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions arch/arm/src/stm32h7/stm32_flash.c
Expand Up @@ -137,6 +137,7 @@

# define STM32_FLASH_NBLOCKS 16
# define STM32_FLASH_SIZE _K(16 * 128)
# define STM32_DUAL_BANK 1

#endif

Expand Down Expand Up @@ -182,7 +183,7 @@ static struct stm32h7_flash_priv_s stm32h7_flash_bank1_priv =
.stblock = 0,
.stpage = 0,
};
#if STM32_FLASH_NBLOCKS > 1
#if STM32_DUAL_BANK
static struct stm32h7_flash_priv_s stm32h7_flash_bank2_priv =
{
.sem = SEM_INITIALIZER(1),
Expand Down Expand Up @@ -330,15 +331,24 @@ static inline uint32_t stm32h7_flash_size(
static inline
struct stm32h7_flash_priv_s * stm32h7_flash_bank(size_t address)
{
struct stm32h7_flash_priv_s *priv = &stm32h7_flash_bank1_priv;
if (address < priv->base || address >=
priv->base + stm32h7_flash_size(priv))
struct stm32h7_flash_priv_s *priv = NULL;

uint32_t bank_size;
#ifdef STM32_DUAL_BANK
bank_size = stm32h7_flash_size(priv) / 2;
#else
bank_size = stm32h7_flash_size(priv);
#endif

if (address >= stm32h7_flash_bank1_priv.base &&
address < stm32h7_flash_bank1_priv.base + bank_size)
{
return NULL;
priv = &stm32h7_flash_bank1_priv;
}

#if STM32_FLASH_NBLOCKS > 1
if (address >= stm32h7_flash_bank2_priv.base)
#ifdef STM32_DUAL_BANK
else if (address >= stm32h7_flash_bank2_priv.base &&
address < stm32h7_flash_bank2_priv.base + bank_size)
{
priv = &stm32h7_flash_bank2_priv;
}
Expand All @@ -363,7 +373,7 @@ static int stm32h7_israngeerased(size_t startaddress, size_t size)
size_t bwritten = 0;

if (!stm32h7_flash_bank(startaddress) ||
!stm32h7_flash_bank(startaddress + size))
!stm32h7_flash_bank(startaddress + size - 1))
{
return -EIO;
}
Expand All @@ -380,14 +390,15 @@ static int stm32h7_israngeerased(size_t startaddress, size_t size)
count += 4;
}

baddr = (uint8_t *)addr;
baddr = (uint8_t *)startaddress;
while (count < size)
{
if (getreg8(baddr) != FLASH_ERASEDVALUE)
{
bwritten++;
}

baddr++;
count++;
}

Expand Down

0 comments on commit c28b05e

Please sign in to comment.