1+ #ifndef __STM32L4_H
2+ #define __STM32L4_H
3+
4+ #define STM32L4_PAGE_SIZE 0x800
5+ /* Flash Program ad Erase Controller Register Map */
6+ #define STM32L4_FPEC_BASE 0x40022000
7+ #define STM32L4_FLASH_ACR (STM32L4_FPEC_BASE+0x00)
8+ #define STM32L4_FLASH_KEYR (STM32L4_FPEC_BASE+0x08)
9+ #define STM32L4_FLASH_OPTKEYR (STM32L4_FPEC_BASE+0x0c)
10+ #define STM32L4_FLASH_SR (STM32L4_FPEC_BASE+0x10)
11+ #define STM32L4_FLASH_CR (STM32L4_FPEC_BASE+0x14)
12+ #define STM32L4_FLASH_OPTR (STM32L4_FPEC_BASE+0x20)
13+
14+ #define STM32L4_FLASH_CR_PG (1 << 0)
15+ #define STM32L4_FLASH_CR_PER (1 << 1)
16+ #define STM32L4_FLASH_CR_MER1 (1 << 2)
17+ #define STM32L4_FLASH_CR_PAGE_SHIFT 3
18+ #define STM32L4_FLASH_CR_BKER (1 << 11)
19+ #define STM32L4_FLASH_CR_MER2 (1 << 15)
20+ #define STM32L4_FLASH_CR_STRT (1 << 16)
21+ #define STM32L4_FLASH_CR_OPTSTRT (1 << 17)
22+ #define STM32L4_FLASH_CR_FSTPG (1 << 18)
23+ #define STM32L4_FLASH_CR_EOPIE (1 << 24)
24+ #define STM32L4_FLASH_CR_ERRIE (1 << 25)
25+ #define STM32L4_FLASH_CR_OBL_LAUNCH (1 << 27)
26+ #define STM32L4_FLASH_CR_OPTLOCK (1 << 30)
27+ #define STM32L4_FLASH_CR_LOCK (1 << 31)
28+
29+ #define STM32L4_FLASH_SR_EOP (1 << 0)
30+ #define STM32L4_FLASH_SR_OPERR (1 << 1)
31+ #define STM32L4_FLASH_SR_PROGERR (1 << 3)
32+ #define STM32L4_FLASH_SR_WRPERR (1 << 4)
33+ #define STM32L4_FLASH_SR_PGAERR (1 << 5)
34+ #define STM32L4_FLASH_SR_SIZERR (1 << 6)
35+ #define STM32L4_FLASH_SR_PGSERR (1 << 7)
36+ #define STM32L4_FLASH_SR_MSERR (1 << 8)
37+ #define STM32L4_FLASH_SR_FASTERR (1 << 9)
38+ #define STM32L4_FLASH_SR_RDERR (1 << 14)
39+ #define STM32L4_FLASH_SR_OPTVERR (1 << 15)
40+ #define STM32L4_FLASH_SR_ERROR_MASK 0xC3FA
41+ #define STM32L4_FLASH_SR_BSY (1 << 16)
42+
43+ #define STM32L4_KEY1 0x45670123
44+ #define STM32L4_KEY2 0xCDEF89AB
45+
46+ #define STM32L4_OPTKEY1 0x08192A3B
47+ #define STM32L4_OPTKEY2 0x4C5D6E7F
48+
49+ #define STM32L4_SR_ERROR_MASK 0xF2
50+ #define STM32L4_SR_EOP 0x01
51+
52+ #define STM32L4_OR_DUALBANK (1 << 21)
53+
54+ #define STM32L4_DBGMCU_IDCODE 0xE0042000
55+ #define STM32L4_FLASH_SIZE_REG 0x1FFF75E0
56+
57+ #define STM32L4_SIZE_OF_ONE_WRITE 0x1000
58+ #define STM32L4_ERASE_TIME_IN_WRITES 10
59+
60+ /*
61+ * flash errors returned to flash_target_task
62+ * 0x0 - 0x1000 - reserved for target (we can use this pool here)
63+ * bit 9 (0x200) - error while flash erasing. [8..0] represent FLASH_SR[8..0]
64+ * bit 10 (0x400) - error while flash writing. [8..0] represent FLASH_SR[8..0]
65+ */
66+ #define STM32L4_ERASE_ERROR_BIT 0x200
67+ #define STM32L4_FLASH_ERROR_BIT 0x400
68+ #define STM32L4_ERASE_NEVER_END 0x800
69+ #define STM32L4_ERROR_ON_FLASH_WRITE_SETUP 0x801
70+
71+ typedef struct CORTEXM_s CORTEXM_t ;
72+
73+ typedef struct STM32L4_PRIV_s {
74+ CORTEXM_t * cortex ;
75+ } STM32L4_PRIV_t ;
76+
77+ int stm32l4_probe (CORTEXM_t * cortexm );
78+
79+ #endif //__STM32L4_H
0 commit comments