43#ifndef LIBOPENCM3_FLASH_H
44#define LIBOPENCM3_FLASH_H
52#define FLASH_ACR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00)
53#define FLASH_PDKEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x04)
54#define FLASH_KEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x08)
55#define FLASH_OPTKEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x0C)
56#define FLASH_SR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x10)
57#define FLASH_CR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x14)
58#define FLASH_ECCR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x18)
59#define FLASH_OPTR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x20)
60#define FLASH_PCROP1SR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x24)
61#define FLASH_PCROP1ER MMIO32(FLASH_MEM_INTERFACE_BASE + 0x28)
62#define FLASH_WRP1AR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x2C)
63#define FLASH_WRP1BR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x30)
64#define FLASH_PCROP2SR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x44)
65#define FLASH_PCROP2ER MMIO32(FLASH_MEM_INTERFACE_BASE + 0x48)
66#define FLASH_WRP2AR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x4C)
67#define FLASH_WRP2BR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x50)
68#define FLASH_SEC1R MMIO32(FLASH_MEM_INTERFACE_BASE + 0x70)
69#define FLASH_SEC2R MMIO32(FLASH_MEM_INTERFACE_BASE + 0x74)
73#define FLASH_ACR_DBG_SWEN (1 << 18)
74#define FLASH_ACR_SLEEP_PD (1 << 14)
75#define FLASH_ACR_RUN_PD (1 << 13)
76#define FLASH_ACR_PRFTEN (1 << 8)
78#define FLASH_ACR_LATENCY_SHIFT 0
79#define FLASH_ACR_LATENCY_MASK 0xf
83#define FLASH_SR_BSY (1 << 16)
84#define FLASH_SR_OPTVERR (1 << 15)
85#define FLASH_SR_RDERR (1 << 14)
86#define FLASH_SR_FASTERR (1 << 9)
87#define FLASH_SR_MISERR (1 << 8)
88#define FLASH_SR_PGSERR (1 << 7)
89#define FLASH_SR_SIZERR (1 << 6)
90#define FLASH_SR_PGAERR (1 << 5)
91#define FLASH_SR_WRPERR (1 << 4)
92#define FLASH_SR_PROGERR (1 << 3)
93#define FLASH_SR_OPERR (1 << 1)
94#define FLASH_SR_EOP (1 << 0)
98#define FLASH_CR_LOCK (1 << 31)
99#define FLASH_CR_OPTLOCK (1 << 30)
100#define FLASH_CR_SEC_PROT2 (1 << 29)
101#define FLASH_CR_SEC_PROT1 (1 << 28)
102#define FLASH_CR_OBL_LAUNCH (1 << 27)
103#define FLASH_CR_RDERRIE (1 << 26)
104#define FLASH_CR_ERRIE (1 << 25)
105#define FLASH_CR_EOPIE (1 << 24)
106#define FLASH_CR_FSTPG (1 << 18)
107#define FLASH_CR_OPTSTRT (1 << 17)
108#define FLASH_CR_START (1 << 16)
109#define FLASH_CR_MER2 (1 << 15)
110#define FLASH_CR_BKER (1 << 11)
111#define FLASH_CR_MER1 (1 << 2)
112#define FLASH_CR_PER (1 << 1)
113#define FLASH_CR_PG (1 << 0)
115#define FLASH_CR_PNB_SHIFT 3
116#define FLASH_CR_PNB_MASK 0x7f
120#define FLASH_ECCR_ECCD (1 << 31)
121#define FLASH_ECCR_ECCC (1 << 30)
122#define FLASH_ECCR_ECCD2 (1 << 31)
123#define FLASH_ECCR_ECCC2 (1 << 30)
124#define FLASH_ECCR_ECCIE (1 << 24)
125#define FLASH_ECCR_SYSF_ECC (1 << 22)
126#define FLASH_ECCR_BK_ECC (1 << 21)
128#define FLASH_ECCR_ADDR_ECC_SHIFT 0
129#define FLASH_ECCR_ADDR_ECC_MASK 0x7ffff
133#define FLASH_OPTR_IRHEN (1 << 30)
135#define FLASH_OPTR_NRST_MODE_SHIFT 28
136#define FLASH_OPTR_NRST_MODE_MASK 0x3
137#define FLASH_OPTR_NRST_MODE_RESET 1
138#define FLASH_OPTR_NRST_MODE_GPIO 2
139#define FLASH_OPTR_NRST_MODE_BIDIR 3
141#define FLASH_OPTR_nBOOT0 (1 << 27)
142#define FLASH_OPTR_nSWBOOT0 (1 << 26)
143#define FLASH_OPTR_SRAM_RST (1 << 25)
144#define FLASH_OPTR_SRAM_PE (1 << 24)
145#define FLASH_OPTR_nBOOT1 (1 << 23)
146#define FLASH_OPTR_DUALBANK (1 << 21)
147#define FLASH_OPTR_BFB2 (1 << 20)
148#define FLASH_OPTR_WWDG_SW (1 << 19)
149#define FLASH_OPTR_IWDG_STDBY (1 << 18)
150#define FLASH_OPTR_IWDG_STOP (1 << 17)
151#define FLASH_OPTR_IDWG_SW (1 << 16)
152#define FLASH_OPTR_nRST_SHDW (1 << 14)
153#define FLASH_OPTR_nRST_STDBY (1 << 13)
154#define FLASH_OPTR_nRST_STOP (1 << 12)
156#define FLASH_OPTR_BOR_SHIFT 8
157#define FLASH_OPTR_BOR_MASK 0x7
158#define FLASH_OPTR_BOR_LEVEL_0 0
159#define FLASH_OPTR_BOR_LEVEL_1 1
160#define FLASH_OPTR_BOR_LEVEL_2 2
161#define FLASH_OPTR_BOR_LEVEL_3 3
162#define FLASH_OPTR_BOR_LEVEL_4 4
164#define FLASH_OPTR_RDP_SHIFT 0
165#define FLASH_OPTR_RDP_MASK 0xff
166#define FLASH_OPTR_RDP_LEVEL_0 0xAA
167#define FLASH_OPTR_RDP_LEVEL_1 0xBB
168#define FLASH_OPTR_RDP_LEVEL_2 0xCC
172#define FLASH_PCROP1SR_PCROP1_STRT_SHIFT 0
173#define FLASH_PCROP1SR_PCROP1_STRT_MASK 0x7fff
177#define FLASH_PCROP1ER_PCROP_RDP (1 << 31)
178#define FLASH_PCROP1ER_PCROP1_END_SHIFT 0
179#define FLASH_PCROP1ER_PCROP1_END_MASK 0x7fff
183#define FLASH_WRP1AR_WRP1A_END_SHIFT 16
184#define FLASH_WRP1AR_WRP1A_END_MASK 0x7f
186#define FLASH_WRP1AR_WRP1A_STRT_SHIFT 0
187#define FLASH_WRP1AR_WRP1A_STRT_MASK 0x7f
191#define FLASH_WRP1BR_WRP1B_END_SHIFT 16
192#define FLASH_WRP1BR_WRP1B_END_MASK 0x7f
194#define FLASH_WRP1BR_WRP1B_STRT_SHIFT 0
195#define FLASH_WRP1BR_WRP1B_STRT_MASK 0x7f
199#define FLASH_PCROP2SR_PCROP2_STRT_SHIFT 0
200#define FLASH_PCROP2SR_PCROP2_STRT_MASK 0x7fff
204#define FLASH_PCROP2ER_PCROP2_END_SHIFT 0
205#define FLASH_PCROP2ER_PCROP2_END_MASK 0x7fff
209#define FLASH_WRP2AR_WRP2A_END_SHIFT 16
210#define FLASH_WRP2AR_WRP2A_END_MASK 0x7f
212#define FLASH_WRP2AR_WRP2A_STRT_SHIFT 0
213#define FLASH_WRP2AR_WRP2A_STRT_MASK 0x7f
217#define FLASH_WRP2BR_WRP2B_END_SHIFT 16
218#define FLASH_WRP2BR_WRP2B_END_MASK 0xff
220#define FLASH_WRP2BR_WRP2B_STRT_SHIFT 0
221#define FLASH_WRP2BR_WRP2B_STRT_MASK 0xff
225#define FLASH_SEC1R_BOOT_LOCK (1 << 16)
227#define FLASH_SEC1R_SEC_SIZE1_SHIFT 0
228#define FLASH_SEC1R_SEC_SIZE1_MASK 0xff
232#define FLASH_SEC2R_SEC_SIZE2_SHIFT 0
233#define FLASH_SEC2R_SEC_SIZE2_MASK 0xff
237#define FLASH_PDKEYR_PDKEY1 ((uint32_t)0x04152637)
238#define FLASH_PDKEYR_PDKEY2 ((uint32_t)0xfafbfcfd)
240#define FLASH_KEYR_KEY1 ((uint32_t)0x45670123)
241#define FLASH_KEYR_KEY2 ((uint32_t)0xcdef89ab)
243#define FLASH_OPTKEYR_KEY1 ((uint32_t)0x08192a3b)
244#define FLASH_OPTKEYR_KEY2 ((uint32_t)0x4c5d6e7f)
257void flash_program(uint32_t address, uint8_t *data, uint32_t len);
void flash_program_option_bytes(uint32_t data)
Program the Option Bytes This performs all operations necessary to program the option bytes.
void flash_erase_page(uint32_t page)
Erase a page of FLASH.
void flash_lock_option_bytes(void)
Lock the Option Byte Access This disables write access to the option bytes.
void flash_clear_pgaerr_flag(void)
Clear the Programming Alignment Error Flag.
void flash_clear_pgserr_flag(void)
Clear the Programming Sequence Error Flag This flag is set when incorrect programming configuration h...
void flash_program(uint32_t address, uint8_t *data, uint32_t len)
Program a Data Block to FLASH This programs an arbitrary length data block to FLASH memory.
void flash_clear_size_flag(void)
Clear programming size error flag.
void flash_program_double_word(uint32_t address, uint64_t data)
Program a 64 bit word to FLASH.
void flash_clear_progerr_flag(void)
Clear the Programming Error Status Flag.
void flash_clear_wrperr_flag(void)
Clear the Write Protect Error Flag.
void flash_erase_all_pages(void)
Erase All FLASH This performs all operations necessary to erase all sectors in the FLASH memory.