41#ifndef LIBOPENCM3_FLASH_H
42#define LIBOPENCM3_FLASH_H
50#define FLASH_ACR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00)
51#define FLASH_PDKEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x04)
52#define FLASH_KEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x08)
53#define FLASH_OPTKEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x0C)
54#define FLASH_SR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x10)
55#define FLASH_CR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x14)
56#define FLASH_ECCR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x18)
57#define FLASH_OPTR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x20)
58#define FLASH_PCROP1SR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x24)
59#define FLASH_PCROP1ER MMIO32(FLASH_MEM_INTERFACE_BASE + 0x28)
60#define FLASH_WRP1AR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x2C)
61#define FLASH_WRP1BR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x30)
62#define FLASH_PCROP2SR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x44)
63#define FLASH_PCROP2ER MMIO32(FLASH_MEM_INTERFACE_BASE + 0x48)
64#define FLASH_WRP2AR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x4C)
65#define FLASH_WRP2BR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x50)
69#define FLASH_ACR_SLEEP_PD (1 << 14)
70#define FLASH_ACR_RUN_PD (1 << 13)
71#define FLASH_ACR_PRFTEN (1 << 8)
73#define FLASH_ACR_LATENCY_SHIFT 0
74#define FLASH_ACR_LATENCY_MASK 0x07
76#define FLASH_ACR_LATENCY_0WS 0x00
77#define FLASH_ACR_LATENCY_1WS 0x01
78#define FLASH_ACR_LATENCY_2WS 0x02
79#define FLASH_ACR_LATENCY_3WS 0x03
80#define FLASH_ACR_LATENCY_4WS 0x04
84#define FLASH_SR_BSY (1 << 16)
85#define FLASH_SR_OPTVERR (1 << 15)
86#define FLASH_SR_RDERR (1 << 14)
87#define FLASH_SR_FASTERR (1 << 9)
88#define FLASH_SR_MISERR (1 << 8)
89#define FLASH_SR_PGSERR (1 << 7)
90#define FLASH_SR_SIZERR (1 << 6)
91#define FLASH_SR_PGAERR (1 << 5)
92#define FLASH_SR_WRPERR (1 << 4)
93#define FLASH_SR_PROGERR (1 << 3)
94#define FLASH_SR_OPERR (1 << 1)
95#define FLASH_SR_EOP (1 << 0)
99#define FLASH_CR_LOCK (1 << 31)
100#define FLASH_CR_OPTLOCK (1 << 30)
101#define FLASH_CR_OBL_LAUNCH (1 << 27)
102#define FLASH_CR_RDERRIE (1 << 26)
103#define FLASH_CR_ERRIE (1 << 25)
104#define FLASH_CR_EOPIE (1 << 24)
105#define FLASH_CR_FSTPG (1 << 18)
106#define FLASH_CR_OPTSTRT (1 << 17)
107#define FLASH_CR_START (1 << 16)
108#define FLASH_CR_MER2 (1 << 15)
109#define FLASH_CR_BKER (1 << 11)
110#define FLASH_CR_MER1 (1 << 2)
111#define FLASH_CR_PER (1 << 1)
112#define FLASH_CR_PG (1 << 0)
114#define FLASH_CR_PNB_SHIFT 3
115#define FLASH_CR_PNB_MASK 0xff
119#define FLASH_ECCR_ECCD (1 << 31)
120#define FLASH_ECCR_ECCC (1 << 30)
121#define FLASH_ECCR_ECCIE (1 << 24)
122#define FLASH_ECCR_SYSF_ECC (1 << 20)
123#define FLASH_ECCR_BK_ECC (1 << 19)
125#define FLASH_ECCR_ADDR_ECC_SHIFT 0
126#define FLASH_ECCR_ADDR_ECC_MASK 0x7ffff
130#define FLASH_OPTR_SRAM2_RST (1 << 25)
131#define FLASH_OPTR_SRAM2_PE (1 << 24)
132#define FLASH_OPTR_nBOOT1 (1 << 23)
133#define FLASH_OPTR_DUALBANK (1 << 21)
134#define FLASH_OPTR_BFB2 (1 << 20)
135#define FLASH_OPTR_WWDG_SW (1 << 19)
136#define FLASH_OPTR_IWDG_STDBY (1 << 18)
137#define FLASH_OPTR_IWDG_STOP (1 << 17)
138#define FLASH_OPTR_IDWG_SW (1 << 16)
139#define FLASH_OPTR_nRST_SHDW (1 << 14)
140#define FLASH_OPTR_nRST_STDBY (1 << 13)
141#define FLASH_OPTR_nRST_STOP (1 << 12)
143#define FLASH_OPTR_BOR_SHIFT 8
144#define FLASH_OPTR_BOR_MASK 0x700
145#define FLASH_OPTR_BOR_LEVEL_0 0
146#define FLASH_OPTR_BOR_LEVEL_1 1
147#define FLASH_OPTR_BOR_LEVEL_2 2
148#define FLASH_OPTR_BOR_LEVEL_3 3
149#define FLASH_OPTR_BOR_LEVEL_4 4
151#define FLASH_OPTR_RDP_SHIFT 0
152#define FLASH_OPTR_RDP_MASK 0xff
153#define FLASH_OPTR_RDP_LEVEL_0 0xAA
154#define FLASH_OPTR_RDP_LEVEL_1 0xBB
155#define FLASH_OPTR_RDP_LEVEL_2 0xCC
159#define FLASH_PCROP1SR_PCROP1_STRT_SHIFT 0
160#define FLASH_PCROP1SR_PCROP1_STRT_MASK 0xffff
164#define FLASH_PCROP1ER_PCROP_RDP (1 << 31)
165#define FLASH_PCROP1ER_PCROP1_END_SHIFT 0
166#define FLASH_PCROP1ER_PCROP1_END_MASK 0xffff
170#define FLASH_WRP1AR_WRP1A_END_SHIFT 16
171#define FLASH_WRP1AR_WRP1A_END_MASK 0xff
173#define FLASH_WRP1AR_WRP1A_STRT_SHIFT 0
174#define FLASH_WRP1AR_WRP1A_STRT_MASK 0xff
178#define FLASH_WRP1BR_WRP1B_END_SHIFT 16
179#define FLASH_WRP1BR_WRP1B_END_MASK 0xff
181#define FLASH_WRP1BR_WRP1B_STRT_SHIFT 0
182#define FLASH_WRP1BR_WRP1B_STRT_MASK 0xff
186#define FLASH_PCROP2SR_PCROP2_STRT_SHIFT 0
187#define FLASH_PCROP2SR_PCROP2_STRT_MASK 0xffff
191#define FLASH_PCROP2ER_PCROP2_END_SHIFT 0
192#define FLASH_PCROP2ER_PCROP2_END_MASK 0xffff
196#define FLASH_WRP2AR_WRP2A_END_SHIFT 16
197#define FLASH_WRP2AR_WRP2A_END_MASK 0xff
199#define FLASH_WRP2AR_WRP2A_STRT_SHIFT 0
200#define FLASH_WRP2AR_WRP2A_STRT_MASK 0xff
204#define FLASH_WRP2BR_WRP2B_END_SHIFT 16
205#define FLASH_WRP2BR_WRP2B_END_MASK 0xff
207#define FLASH_WRP2BR_WRP2B_STRT_SHIFT 0
208#define FLASH_WRP2BR_WRP2B_STRT_MASK 0xff
212#define FLASH_PDKEYR_PDKEY1 ((uint32_t)0x04152637)
213#define FLASH_PDKEYR_PDKEY2 ((uint32_t)0xfafbfcfd)
215#define FLASH_KEYR_KEY1 ((uint32_t)0x45670123)
216#define FLASH_KEYR_KEY2 ((uint32_t)0xcdef89ab)
218#define FLASH_OPTKEYR_KEY1 ((uint32_t)0x08192a3b)
219#define FLASH_OPTKEYR_KEY2 ((uint32_t)0x4c5d6e7f)
232void 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.