diff options
| author | Herwin Grobben <h.grobben@aemics.nl> | 2021-01-26 14:49:56 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-02-01 16:21:01 +1100 |
| commit | 8f68e26f79ee325669fb7dc7bbd092fccd5b038f (patch) | |
| tree | 9b958a5127f0872a099dab9c044c2a88f2d278aa /ports/stm32/flash.c | |
| parent | 60e05ae84ec08c06e3f9d9051339811641479a94 (diff) | |
stm32: Add support for G4 MCUs, and add NUCLEO_G474RE board defn.
This commit adds support for the STM32G4 series of MCUs, and a board
definition for NUCLEO_G474RE. This board has the REPL on LPUART1 which is
connected to the on-board ST-link USB-UART.
Diffstat (limited to 'ports/stm32/flash.c')
| -rw-r--r-- | ports/stm32/flash.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/ports/stm32/flash.c b/ports/stm32/flash.c index b926679f9..eeeab5204 100644 --- a/ports/stm32/flash.c +++ b/ports/stm32/flash.c @@ -97,7 +97,7 @@ static const flash_layout_t flash_layout[] = { }; #endif -#elif defined(STM32L0) || defined(STM32L4) || defined(STM32WB) +#elif defined(STM32G4) || defined(STM32L0) || defined(STM32L4) || defined(STM32WB) static const flash_layout_t flash_layout[] = { { (uint32_t)FLASH_BASE, (uint32_t)FLASH_PAGE_SIZE, 512 }, @@ -126,12 +126,20 @@ static uint32_t get_bank(uint32_t addr) { if (addr < (FLASH_BASE + FLASH_BANK_SIZE)) { return FLASH_BANK_1; } else { + #if defined(FLASH_OPTR_DBANK) return FLASH_BANK_2; + #else + return 0; + #endif } } else { // bank swap if (addr < (FLASH_BASE + FLASH_BANK_SIZE)) { + #if defined(FLASH_OPTR_DBANK) return FLASH_BANK_2; + #else + return 0; + #endif } else { return FLASH_BANK_1; } @@ -157,6 +165,25 @@ static uint32_t get_page(uint32_t addr) { return (addr - FLASH_BASE) / FLASH_PAGE_SIZE; } +#elif defined(STM32G4) + +static uint32_t get_page(uint32_t addr) { + return (addr - FLASH_BASE) / FLASH_PAGE_SIZE; +} + +static uint32_t get_bank(uint32_t addr) { + // no bank swap + if (addr < (FLASH_BASE + FLASH_BANK_SIZE)) { + return FLASH_BANK_1; + } else { + #if defined(FLASH_OPTR_DBANK) + return FLASH_BANK_2; + #else + return 0; + #endif + } +} + #endif bool flash_is_valid_addr(uint32_t addr) { @@ -225,6 +252,12 @@ int flash_erase(uint32_t flash_dest, uint32_t num_word32) { EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; EraseInitStruct.PageAddress = flash_dest; EraseInitStruct.NbPages = (4 * num_word32 + FLASH_PAGE_SIZE - 4) / FLASH_PAGE_SIZE; + #elif defined(STM32G4) + __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); + EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; + EraseInitStruct.Page = get_page(flash_dest); + EraseInitStruct.Banks = get_bank(flash_dest); + EraseInitStruct.NbPages = (4 * num_word32 + FLASH_PAGE_SIZE - 4) / FLASH_PAGE_SIZE; #elif defined(STM32L0) __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR); EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; @@ -258,7 +291,7 @@ int flash_erase(uint32_t flash_dest, uint32_t num_word32) { #else EraseInitStruct.VoltageRange = 0; // unused parameter on STM32H7A3/B3 #endif - #if defined(STM32H7) + #if defined(STM32G4) || defined(STM32H7) EraseInitStruct.Banks = get_bank(flash_dest); #endif EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL); @@ -337,7 +370,7 @@ int flash_write(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32) { HAL_StatusTypeDef status = HAL_OK; - #if defined(STM32L4) || defined(STM32WB) + #if defined(STM32G4) || defined(STM32L4) || defined(STM32WB) // program the flash uint64 by uint64 for (int i = 0; i < num_word32 / 2; i++) { |
