Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions hal/stm32u5.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ void RAMFUNCTION hal_flash_clear_errors(uint8_t bank)

}

#if (TZ_SECURE())
/* Map a secure alias address (0x0C...) to the 0x08... address the bank
* checks below expect. Both aliases name the same flash page. */
static uint32_t RAMFUNCTION flash_addr_unalias(uint32_t address)
{
if ((address & FLASH_SECURE_MMAP_BASE) == FLASH_SECURE_MMAP_BASE)
address = (address & ~FLASH_SECURE_MMAP_BASE) | FLASHMEM_ADDRESS_SPACE;
return address;
}
#endif

int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
{
int i = 0;
Expand All @@ -71,6 +82,9 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
volatile uint32_t *sr, *cr;

hal_flash_clear_errors(0);
#if (TZ_SECURE())
address = flash_addr_unalias(address);
#endif
dst = (uint32_t*)address;

#if (TZ_SECURE())
Expand Down Expand Up @@ -199,6 +213,9 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
hal_flash_clear_errors(0);
if (len == 0)
return -1;
#if (TZ_SECURE())
address = flash_addr_unalias(address);
#endif

if (address < ARCH_FLASH_OFFSET)
return -1;
Expand Down
Loading