Skip to content

Commit

Permalink
Merge pull request #15204 from jeromecoutant/PR_G0_DUALBANK
Browse files Browse the repository at this point in the history
STM32G0 FLASH : support MCU with dual bank
  • Loading branch information
0xc0170 authored Jan 14, 2022
2 parents 6bb606f + 5e5d2ab commit c02e10b
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion targets/TARGET_STM/TARGET_STM32G0/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,44 @@
#include "cmsis.h"


uint32_t GetBank(uint32_t Addr)
{
#if defined(FLASH_DBANK_SUPPORT)
if (Addr < (FLASH_BASE + FLASH_BANK_SIZE))
{
return FLASH_BANK_1;
}
else
{
return FLASH_BANK_2;
}
#else
return FLASH_BANK_1;
#endif
}

uint32_t GetPage(uint32_t Addr)
{
uint32_t page = 0;

#if defined(FLASH_DBANK_SUPPORT)
if (Addr < (FLASH_BASE + FLASH_BANK_SIZE))
{
/* Bank 1 */
page = (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;
}
else
{
/* Bank 2 */
page = (Addr - (FLASH_BASE + FLASH_BANK_SIZE)) / FLASH_PAGE_SIZE;
}
#else
page = (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;
#endif

return page;
}

int32_t flash_init(flash_t *obj)
{
return 0;
Expand Down Expand Up @@ -57,7 +95,8 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
/* MBED HAL erases 1 sector at a time */
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Page = (address & 0xFFFFF) / 2048; // page size = 2048
EraseInitStruct.Banks = GetBank(address);
EraseInitStruct.Page = GetPage(address);
EraseInitStruct.NbPages = 1;

/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
Expand Down

0 comments on commit c02e10b

Please sign in to comment.