diff --git a/arch/arm/src/stm32/Kconfig b/arch/arm/src/stm32/Kconfig index be780bc43fd..0c95f920d71 100644 --- a/arch/arm/src/stm32/Kconfig +++ b/arch/arm/src/stm32/Kconfig @@ -811,6 +811,73 @@ config ARCH_CHIP_STM32F446Z endchoice +choice + prompt "Override Flash Size Designator" + default STM32_FLASH_CONFIG_DEFAULT + depends on ARCH_CHIP_STM32 + ---help--- + STM32F series parts numbering (sans the package type) ends with a number or letter + that designates the FLASH size. + + Designator Size in KiB + 4 16 + 6 32 + 8 64 + B 128 + C 256 + D 384 + E 512 + F 768 + G 1024 + I 2048 + + This configuration option defaults to using the configuration based on that designator + or the default smaller size if there is no last character designator is present in the + STM32 Chip Selection. + + Examples: + If the STM32F407VE is chosen, the Flash configuration would be 'E', if a variant of + the part with a 2048 KiB Flash is released in the future one could simply select + the 'I' designator here. + + If an STM32F42xxx or Series parts is chosen the default Flash configuration will be 'G' + and can be set herein to 'I' to choose the larger FLASH part. + +config STM32_FLASH_CONFIG_DEFAULT + bool "Default" + +config STM32_FLASH_CONFIG_4 + bool "4 16KiB" + +config STM32_FLASH_CONFIG_6 + bool "6 32KiB" + +config STM32_FLASH_CONFIG_8 + bool "8 64KiB" + +config STM32_FLASH_CONFIG_B + bool "B 128KiB" + +config STM32_FLASH_CONFIG_C + bool "C 256KiB" + +config STM32_FLASH_CONFIG_D + bool "D 384KiB" + +config STM32_FLASH_CONFIG_E + bool "E 512KiB" + +config STM32_FLASH_CONFIG_F + bool "F 768KiB" + +config STM32_FLASH_CONFIG_G + bool "G 1024KiB" + +config STM32_FLASH_CONFIG_I + bool "I 2048KiB" + +endchoice + # This is really 15XX/16XX, but we treat the two the same. config STM32_STM32L15XX bool diff --git a/arch/arm/src/stm32/chip/stm32_flash.h b/arch/arm/src/stm32/chip/stm32_flash.h index 716d496aff4..96f4c3c147a 100644 --- a/arch/arm/src/stm32/chip/stm32_flash.h +++ b/arch/arm/src/stm32/chip/stm32_flash.h @@ -3,6 +3,7 @@ * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt + * David Sidrane * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,57 +35,172 @@ ************************************************************************************/ #ifndef __ARCH_ARM_SRC_STM32_CHIP_STM32_FLASH_H -#define __ARCH_ARM_SRC_STM32_CHIP_STM32_FLASH_H +# define __ARCH_ARM_SRC_STM32_CHIP_STM32_FLASH_H /************************************************************************************ * Pre-processor Definitions ************************************************************************************/ -#if defined(CONFIG_STM32_STM32L15XX) +#define _K(x) ((x)*1024) + +# if !defined(CONFIG_STM32_FLASH_CONFIG_DEFAULT) && \ + !defined(CONFIG_STM32_FLASH_CONFIG_4) && \ + !defined(CONFIG_STM32_FLASH_CONFIG_6) && \ + !defined(CONFIG_STM32_FLASH_CONFIG_8) && \ + !defined(CONFIG_STM32_FLASH_CONFIG_B) && \ + !defined(CONFIG_STM32_FLASH_CONFIG_C) && \ + !defined(CONFIG_STM32_FLASH_CONFIG_D) && \ + !defined(CONFIG_STM32_FLASH_CONFIG_E) && \ + !defined(CONFIG_STM32_FLASH_CONFIG_F) && \ + !defined(CONFIG_STM32_FLASH_CONFIG_G) && \ + !defined(CONFIG_STM32_FLASH_CONFIG_I) +# define CONFIG_STM32_FLASH_CONFIG_DEFAULT +# endif + +# if defined(CONFIG_STM32_FLASH_CONFIG_DEFAULT) +# if defined(CONFIG_STM32_STM32L15XX) + /* The STM32 L15xx/L16xx can support up to 384KB of FLASH. (In reality, supported * L15xx parts have no more than 128KB). The program memory block is divided into * 96 sectors of 4 Kbytes each, and each sector is further split up into 16 pages of * 256 bytes each. The sector is the write protection granularity. In total, the * program memory block contains 1536 pages. */ -# define STM32_FLASH_NPAGES 1536 -# define STM32_FLASH_PAGESIZE 256 +# define STM32_FLASH_NPAGES 1536 +# define STM32_FLASH_PAGESIZE 256 -#elif defined(CONFIG_STM32_LOWDENSITY) -# define STM32_FLASH_NPAGES 32 -# define STM32_FLASH_PAGESIZE 1024 +# elif defined(CONFIG_STM32_LOWDENSITY) +# define STM32_FLASH_NPAGES 32 +# define STM32_FLASH_PAGESIZE 1024 -#elif defined(CONFIG_STM32_MEDIUMDENSITY) -# define STM32_FLASH_NPAGES 128 -# define STM32_FLASH_PAGESIZE 1024 +# elif defined(CONFIG_STM32_MEDIUMDENSITY) +# define STM32_FLASH_NPAGES 128 +# define STM32_FLASH_PAGESIZE 1024 -#elif defined(CONFIG_STM32_CONNECTIVITYLINE) -# define STM32_FLASH_NPAGES 128 -# define STM32_FLASH_PAGESIZE 2048 +# elif defined(CONFIG_STM32_CONNECTIVITYLINE) +# define STM32_FLASH_NPAGES 128 +# define STM32_FLASH_PAGESIZE 2048 -#elif defined(CONFIG_STM32_HIGHDENSITY) -# define STM32_FLASH_NPAGES 256 -# define STM32_FLASH_PAGESIZE 2048 +# elif defined(CONFIG_STM32_HIGHDENSITY) +# define STM32_FLASH_NPAGES 256 +# define STM32_FLASH_PAGESIZE 2048 -#elif defined(CONFIG_STM32_STM32F30XX) -# define STM32_FLASH_NPAGES 128 -# define STM32_FLASH_PAGESIZE (2*1024) +# elif defined(CONFIG_STM32_STM32F30XX) +# define STM32_FLASH_NPAGES 128 +# define STM32_FLASH_PAGESIZE 2048 -#elif defined(CONFIG_STM32_STM32F37XX) -# define STM32_FLASH_NPAGES 128 -# define STM32_FLASH_PAGESIZE (2*1024) +# elif defined(CONFIG_STM32_STM32F37XX) +# define STM32_FLASH_NPAGES 128 +# define STM32_FLASH_PAGESIZE 2048 -#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) -# define STM32_FLASH_NPAGES 8 -/* STM32F4 has mixed page size */ -# undef STM32_FLASH_PAGESIZE -/* TODO: add proper sizes for each chip in the family - maybe in chip.h? */ -# define STM32_FLASH_SIZE (8 * 128 * 1024) -#endif +# elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) +# define STM32_FLASH_NPAGES 8 +# define STM32_FLASH_SIZE _K((4 * 16) + (1 * 64) + (3 * 128)) +# define STM32_FLASH_SIZES {_K(16), _K(16), _K(16), _K(16), \ + _K(64),_K(128), _K(128), _K(128)} -#ifdef STM32_FLASH_PAGESIZE -# define STM32_FLASH_SIZE (STM32_FLASH_NPAGES * STM32_FLASH_PAGESIZE) -#endif /* def STM32_FLASH_PAGESIZE */ + /* STM32F4 has mixed page size */ + +# undef STM32_FLASH_PAGESIZE +# endif +# endif /* CONFIG_STM32_FLASH_CONFIG_DEFAULT */ + +/* Override of the Flash Has been Chosen */ + +# if !defined(CONFIG_STM32_FLASH_CONFIG_DEFAULT) + +/* Define the Valid Configuration the F2 and F4 */ + +# if defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) + +# if defined(CONFIG_STM32_FLASH_CONFIG_B) +# define STM32_FLASH_NPAGES 5 +# define STM32_FLASH_SIZE _K((4 * 16) + (1 * 64)) +# define STM32_FLASH_SIZES {_K(16), _K(16), _K(16), _K(16), \ + _K(64)} + +# elif defined(CONFIG_STM32_FLASH_CONFIG_C) +# define STM32_FLASH_NPAGES 6 +# define STM32_FLASH_SIZE _K((4 * 16) + (1 * 64) + (1 * 128)) +# define STM32_FLASH_SIZES {_K(16), _K(16), _K(16), _K(16), \ + _K(64), _K(128)} + +# elif defined(CONFIG_STM32_FLASH_CONFIG_D) && defined(CONFIG_STM32_STM32F40XX) +# define STM32_FLASH_NPAGES 7 +# define STM32_FLASH_SIZE _K((4 * 16) + (1 * 64) + (2 * 128)) +# define STM32_FLASH_SIZES {_K(16), _K(16), _K(16), _K(16), \ + _K(64), _K(128), _K(128)} + +# elif defined(CONFIG_STM32_FLASH_CONFIG_E) +# define STM32_FLASH_NPAGES 8 +# define STM32_FLASH_SIZE _K((4 * 16) + (1 * 64) + (3 * 128)) +# define STM32_FLASH_SIZES {_K(16), _K(16), _K(16), _K(16), \ + _K(64), _K(128), _K(128), _K(128)} + +# elif defined(CONFIG_STM32_FLASH_CONFIG_F) && defined(CONFIG_STM32_STM32F20XX) +# define STM32_FLASH_NPAGES 9 +# define STM32_FLASH_SIZE _K((4 * 16) + (1 * 64) + (4 * 128)) +# define STM32_FLASH_SIZES {_K(16), _K(16), _K(16), _K(16), \ + _K(64), _K(128), _K(128), _K(128), \ + _K(128)} + +# elif defined(CONFIG_STM32_FLASH_CONFIG_G) +# define STM32_FLASH_NPAGES 12 +# define STM32_FLASH_SIZE _K((4 * 16) + (1 * 64) + (7 * 128)) +# define STM32_FLASH_SIZES {_K(16), _K(16), _K(16), _K(16), \ + _K(64), _K(128), _K(128), _K(128), \ + _K(128), _K(128), _K(128), _K(128)} + +# elif defined(CONFIG_STM32_FLASH_CONFIG_I) && defined(CONFIG_STM32_STM32F40XX) +# define STM32_FLASH_NPAGES 24 +# define STM32_FLASH_SIZE _K((4 * 16) + (1 * 64) + (7 * 128)) + \ + _K((4 * 16) + (1 * 64) + (7 * 128)) +# define STM32_FLASH_SIZES {_K(16), _K(16), _K(16), _K(16), \ + _K(64), _K(128), _K(128), _K(128), \ + _K(128), _K(128), _K(128), _K(128), \ + _K(16), _K(16), _K(16), _K(16), \ + _K(64), _K(128), _K(128), _K(128), \ + _K(128), _K(128), _K(128), _K(128)} +# endif + +/* Define the Valid Configuration the F1 and F3 */ + +# else +# if defined(CONFIG_STM32_FLASH_CONFIG_4) +# define STM32_FLASH_NPAGES 16 +# define STM32_FLASH_PAGESIZE 1024 +# elif defined(CONFIG_STM32_FLASH_CONFIG_6) +# define STM32_FLASH_NPAGES 32 +# define STM32_FLASH_PAGESIZE 1024 +# elif defined(CONFIG_STM32_FLASH_CONFIG_8) +# define STM32_FLASH_NPAGES 64 +# define STM32_FLASH_PAGESIZE 1024 +# elif defined(CONFIG_STM32_FLASH_CONFIG_B) +# define STM32_FLASH_NPAGES 128 +# define STM32_FLASH_PAGESIZE 1024 +# elif defined(CONFIG_STM32_FLASH_CONFIG_C) +# define STM32_FLASH_NPAGES 128 +# define STM32_FLASH_PAGESIZE 2048 +# elif defined(CONFIG_STM32_FLASH_CONFIG_D) +# define STM32_FLASH_NPAGES 192 +# define STM32_FLASH_PAGESIZE 2048 +# elif defined(CONFIG_STM32_FLASH_CONFIG_E) +# define STM32_FLASH_NPAGES 256 +# define STM32_FLASH_PAGESIZE 2048 +# elif defined(CONFIG_STM32_FLASH_CONFIG_F) +# define STM32_FLASH_NPAGES 384 +# define STM32_FLASH_PAGESIZE 2048 +# elif defined(CONFIG_STM32_FLASH_CONFIG_G) +# define STM32_FLASH_NPAGES 512 +# define STM32_FLASH_PAGESIZE 2048 +# elif defined(CONFIG_STM32_FLASH_CONFIG_I) +# endif +# endif +# endif + +# ifdef STM32_FLASH_PAGESIZE +# define STM32_FLASH_SIZE (STM32_FLASH_NPAGES * STM32_FLASH_PAGESIZE) +# endif /* def STM32_FLASH_PAGESIZE */ /* Register Offsets *****************************************************************/ @@ -264,5 +380,12 @@ # define FLASH_OPTCR1_NWRP_MASK (0xff << FLASH_OPTCR_NWRP_SHIFT) #endif +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +void stm32_flash_lock(void); +void stm32_flash_unlock(void); + #endif /* __ARCH_ARM_SRC_STM32_CHIP_STM32_FLASH_H */ diff --git a/arch/arm/src/stm32/stm32_flash.c b/arch/arm/src/stm32/stm32_flash.c index 1cce50ae4e3..668b8667f42 100644 --- a/arch/arm/src/stm32/stm32_flash.c +++ b/arch/arm/src/stm32/stm32_flash.c @@ -60,6 +60,11 @@ #if defined(CONFIG_STM32_STM32F10XX) || defined(CONFIG_STM32_STM32F30XX) || \ defined (CONFIG_STM32_STM32F40XX) +#if defined(CONFIG_STM32_FLASH_CONFIG_DEFAULT) && \ + (defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX)) +# warning "Default Flash Configuration Used - See Override Flash Size Designator" +#endif + /************************************************************************************ * Pre-processor Definitions ************************************************************************************/ @@ -79,6 +84,9 @@ * Private Functions ************************************************************************************/ +/************************************************************************************ + * Public Functions + ************************************************************************************/ void stm32_flash_unlock(void) { while (getreg32(STM32_FLASH_SR) & FLASH_SR_BSY) @@ -100,9 +108,6 @@ void stm32_flash_lock(void) modifyreg32(STM32_FLASH_CR, 0, FLASH_CR_LOCK); } -/************************************************************************************ - * Public Functions - ************************************************************************************/ #if defined(CONFIG_STM32_STM32F10XX) || defined(CONFIG_STM32_STM32F30XX) @@ -142,17 +147,7 @@ size_t up_progmem_getaddress(size_t page) size_t up_progmem_pagesize(size_t page) { - static const size_t page_sizes[STM32_FLASH_NPAGES] = - { - 16 * 1024, - 16 * 1024, - 16 * 1024, - 16 * 1024, - 64 * 1024, - 128 * 1024, - 128 * 1024, - 128 * 1024, - }; + static const size_t page_sizes[STM32_FLASH_NPAGES] = STM32_FLASH_SIZES; if (page >= sizeof(page_sizes) / sizeof(*page_sizes)) {