Skip to content

Commit df47241

Browse files
kywwilson11Alan C. Assis
authored andcommitted
STM32G4 Flash Driver
Added a flash driver for the STM32G4 series. The primary change here is the addition of stm32g4xxx_flash.c. This file uses the STM32L4 flash driver as a template. The primary difference is the accounting for dual banks with different page sizes. Fixed error while building b-g474e-dpow1/buckboost. It was possible (technically) to have page be used uninitialzied. Changing the if statement to default to using a flash_page_size == 2048 fixes this issue.
1 parent 5592145 commit df47241

File tree

5 files changed

+697
-20
lines changed

5 files changed

+697
-20
lines changed

arch/arm/src/stm32/hardware/stm32_flash.h

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,37 @@
178178
/* Define the Valid Configuration the G4 */
179179

180180
# elif defined(CONFIG_STM32_STM32G4XXX)
181-
# if defined(CONFIG_STM32_FLASH_CONFIG_B)
182-
# define STM32_FLASH_NPAGES 32
183-
# define STM32_FLASH_PAGESIZE 4096
184-
185-
# elif defined(CONFIG_STM32_FLASH_CONFIG_C)
186-
# define STM32_FLASH_NPAGES 64
187-
# define STM32_FLASH_PAGESIZE 4096
188-
189-
# elif defined(CONFIG_STM32_FLASH_CONFIG_E)
190-
# define STM32_FLASH_NPAGES 128
191-
# define STM32_FLASH_PAGESIZE 4096
181+
# if defined(CONFIG_STM32_STM32G43XX)
182+
# if defined(CONFIG_STM32_FLASH_CONFIG_6)
183+
# define STM32_FLASH_NPAGES 16
184+
# define STM32_FLASH_PAGESIZE 2048
185+
186+
# elif defined(CONFIG_STM32_FLASH_CONFIG_8)
187+
# define STM32_FLASH_NPAGES 32
188+
# define STM32_FLASH_PAGESIZE 2048
189+
190+
# elif defined(CONFIG_STM32_FLASH_CONFIG_B)
191+
# define STM32_FLASH_NPAGES 64
192+
# define STM32_FLASH_PAGESIZE 2048
193+
# endif
194+
# elif defined(CONFIG_STM32_STM32G47XX) || defined(CONFIG_STM32_STM32G48XX)
195+
# if defined(CONFIG_STM32_FLASH_CONFIG_B)
196+
# define STM32_FLASH_SIZE 32 * 4096
197+
198+
# elif defined(CONFIG_STM32_FLASH_CONFIG_C)
199+
# define STM32_FLASH_SIZE 64 * 4096
200+
201+
# elif defined(CONFIG_STM32_FLASH_CONFIG_E)
202+
# define STM32_FLASH_SIZE 128 * 4096
203+
# endif
204+
# elif defined(CONFIG_STM32_STM32G49XX)
205+
# elif defined(CONFIG_STM32_FLASH_CONFIG_C)
206+
# define STM32_FLASH_NPAGES 128
207+
# define STM32_FLASH_PAGESIZE 2048
208+
209+
# elif defined(CONFIG_STM32_FLASH_CONFIG_E)
210+
# define STM32_FLASH_NPAGES 256
211+
# define STM32_FLASH_PAGESIZE 2048
192212
# endif
193213

194214
/* Define the Valid Configuration the F1 and F3 */
@@ -261,7 +281,7 @@
261281
#elif defined(CONFIG_STM32_STM32G4XXX)
262282
# define STM32_FLASH_PDKEYR_OFFSET 0x0004
263283
# define STM32_FLASH_KEYR_OFFSET 0x0008
264-
# define STM32_FLASH_OPT_KEYR_OFFSET 0x000c
284+
# define STM32_FLASH_OPTKEYR_OFFSET 0x000c
265285
# define STM32_FLASH_SR_OFFSET 0x0010
266286
# define STM32_FLASH_CR_OFFSET 0x0014
267287
# define STM32_FLASH_ECCR_OFFSET 0x0018
@@ -324,7 +344,7 @@
324344
#elif defined(CONFIG_STM32_STM32G4XXX)
325345
# define STM32_FLASH_PDKEYR (STM32_FLASHIF_BASE+STM32_FLASH_PDKEYR_OFFSET)
326346
# define STM32_FLASH_KEYR (STM32_FLASHIF_BASE+STM32_FLASH_KEYR_OFFSET)
327-
# define STM32_FLASH_OPT_KEYR (STM32_FLASHIF_BASE+STM32_FLASH_OPT_KEYR_OFFSET)
347+
# define STM32_FLASH_OPTKEYR (STM32_FLASHIF_BASE+STM32_FLASH_OPTKEYR_OFFSET)
328348
# define STM32_FLASH_SR (STM32_FLASHIF_BASE+STM32_FLASH_SR_OFFSET)
329349
# define STM32_FLASH_CR (STM32_FLASHIF_BASE+STM32_FLASH_CR_OFFSET)
330350
# define STM32_FLASH_ECCR (STM32_FLASHIF_BASE+STM32_FLASH_ECCR_OFFSET)
@@ -538,10 +558,18 @@
538558
# define FLASH_CR_PER (1 << 1)
539559
# define FLASH_CR_MER1 (1 << 2)
540560
# define FLASH_CR_PNB_SHIFT (3)
541-
# define FLASH_CR_PNB_MASK (0x7f << FLASH_CR_PNB_SHIFT)
561+
# if defined(CONFIG_STM32_STM32G43XX)
562+
# define FLASH_CR_PNB_MASK (0x3f << FLASH_CR_PNB_SHIFT)
563+
# elif defined(CONFIG_STM32_STM32G47XX) || defined (CONFIG_STM32_STM32G48XX)
564+
# define FLASH_CR_PNB_MASK (0x7f << FLASH_CR_PNB_SHIFT)
565+
# elif defined(CONFIG_STM32_STM32G49XX)
566+
# define FLASH_CR_PNB_MASK (0xff << FLASH_CR_PNB_SHIFT)
567+
# endif
542568
# define FLASH_CR_PNB(n) (((n) << FLASH_CR_PNB_SHIFT) & FLASH_CR_PNB_MASK)
543-
# define FLASH_CR_BKER (1 << 11)
544-
# define FLASH_CR_MER2 (1 << 15)
569+
# if defined(CONFIG_STM32_STM32G47XX) || defined (CONFIG_STM32_STM32G48XX)
570+
# define FLASH_CR_BKER (1 << 11)
571+
# define FLASH_CR_MER2 (1 << 15)
572+
# endif
545573
# define FLASH_CR_START (1 << 16)
546574
# define FLASH_CR_OPTSTRT (1 << 17)
547575
# define FLASH_CR_FSTPG (1 << 18)
@@ -550,7 +578,9 @@
550578
# define FLASH_CR_RDERRIE (1 << 26)
551579
# define FLASH_CR_OBL_LAUNCH (1 << 27)
552580
# define FLASH_CR_SEC_PROT1 (1 << 28)
553-
# define FLASH_CR_SEC_PROT2 (1 << 29)
581+
# if defined(CONFIG_STM32_STM32G47XX) || defined (CONFIG_STM32_STM32G48XX)
582+
# define FLASH_CR_SEC_PROT2 (1 << 29)
583+
# endif
554584
# define FLASH_CR_OPTLOCK (1 << 30)
555585
# define FLASH_CR_LOCK (1 << 31)
556586
#endif
@@ -568,8 +598,10 @@
568598
# define FLASH_ECCR_BK_ECC (1 << 21)
569599
# define FLASH_ECCR_SYSF_ECC (1 << 22)
570600
# define FLASH_ECCR_ECCIE (1 << 24)
571-
# define FLASH_ECCR_ECCC2 (1 << 28)
572-
# define FLASH_ECCR_ECCD2 (1 << 29)
601+
# if defined(CONFIG_STM32_STM32G47XX) || defined (CONFIG_STM32_STM32G48XX)
602+
# define FLASH_ECCR_ECCC2 (1 << 28)
603+
# define FLASH_ECCR_ECCD2 (1 << 29)
604+
# endif
573605
# define FLASH_ECCR_ECCC (1 << 30)
574606
# define FLASH_ECCR_ECCD (1 << 31)
575607
#endif
@@ -633,7 +665,11 @@
633665
# define FLASH_OPTR_IWDG_STDBY (1 << 18)
634666
# define FLASH_OPTR_WWDG_SW (1 << 19)
635667
# define FLASH_OPTR_BFB2 (1 << 20)
636-
# define FLASH_OPTR_DBANK (1 << 22)
668+
# if defined(CONFIG_STM32_STM32G47XX) || defined (CONFIG_STM32_STM32G48XX)
669+
# define FLASH_OPTR_DBANK (1 << 22)
670+
# elif defined (CONFIG_STM32_STM32G49XX)
671+
# define FLASH_OPTR_PB4_PUPEN (1 << 22)
672+
# endif
637673
# define FLASH_OPTR_NBOOT1 (1 << 23)
638674
# define FLASH_OPTR_SRAM_PE (1 << 24)
639675
# define FLASH_OPTR_CCMSRAM_RST (1 << 25)

arch/arm/src/stm32/stm32_flash.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
# include "stm32f10xxf30xx_flash.c"
3737
#elif defined(CONFIG_STM32_STM32F20XX) || defined (CONFIG_STM32_STM32F4XXX)
3838
# include "stm32f20xxf40xx_flash.c"
39+
#elif defined(CONFIG_STM32_STM32G4XXX)
40+
# include "stm32g4xxx_flash.c"
3941
#else
4042
# warning "No FLASH support for the selected part"
4143
#endif

arch/arm/src/stm32/stm32_flash.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@
3535
* Public Function Prototypes
3636
****************************************************************************/
3737

38+
int stm32_flash_lock(void);
39+
int stm32_flash_unlock(void);
40+
41+
/****************************************************************************
42+
* Name: stm32_flash_user_optbytes
43+
*
44+
* Description:
45+
* Modify the contents of the user option bytes (USR OPT) on the flash.
46+
* This does not set OBL_LAUNCH so new options take effect only after
47+
* next power reset.
48+
*
49+
* Input Parameters:
50+
* clrbits - Bits in the option bytes to be cleared
51+
* setbits - Bits in the option bytes to be set
52+
*
53+
* Returned Value:
54+
* Option bytes after operation is completed
55+
*
56+
****************************************************************************/
57+
58+
uint32_t stm32_flash_users_optbytes(uint32_t clrbits, uint32_t setbits);
59+
3860
/****************************************************************************
3961
* Name: stm32_eeprom_size
4062
*

0 commit comments

Comments
 (0)