Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32G0 FLASH : support MCU with dual bank #15204

Merged
merged 1 commit into from
Jan 14, 2022
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
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