mirror of https://github.com/ARMmbed/mbed-os.git
STM32G0 FLASH : support MCU with dual bank
parent
6bb606f62d
commit
5e5d2ab9a5
|
@ -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;
|
||||
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue