libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
f3/flash.h
Go to the documentation of this file.
1/** @defgroup flash_defines FLASH Defines
2 *
3 * @brief <b>Defined Constants and Types for the STM32F3xx Flash
4 * controller </b>
5 *
6 * @ingroup STM32F3xx_defines
7 *
8 * @version 1.0.0
9 *
10 * @date 11 July 2013
11 *
12 * LGPL License Terms @ref lgpl_license
13 */
14/*
15 * This file is part of the libopencm3 project.
16 *
17 * This library is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU Lesser General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public License
28 * along with this library. If not, see <http://www.gnu.org/licenses/>.
29 */
30
31#ifndef LIBOPENCM3_FLASH_H
32#define LIBOPENCM3_FLASH_H
33/**@{*/
34
37
38/** @defgroup flash_registers Flash Registers
39 * @ingroup flash_defines
40@{*/
41/** Flash Access Control register */
42#define FLASH_ACR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00)
43/** Flash Key register */
44#define FLASH_KEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x04)
45/** Flash Option bytes key register */
46#define FLASH_OPTKEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x08)
47/** Flash Status register*/
48#define FLASH_SR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x0C)
49/** Flash Control register */
50#define FLASH_CR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x10)
51/** Flash Address register */
52#define FLASH_AR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x14)
53/** Flash Option Byte register */
54#define FLASH_OBR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x1C)
55/** Flash Write Protection register */
56#define FLASH_WRPR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x20)
57/*@}*/
58
59/* --- FLASH_ACR values ---------------------------------------------------- */
60
61#define FLASH_ACR_PRFTBS (1 << 5)
62#define FLASH_ACR_PRFTBE (1 << 4)
63/** Compatibility alias */
64#define FLASH_ACR_PRFTEN FLASH_ACR_PRFTBE
65#define FLASH_ACR_HLFCYA (1 << 3)
66#define FLASH_ACR_LATENCY_SHIFT 0
67#define FLASH_ACR_LATENCY_MASK 0x0f
68/** @defgroup flash_latency FLASH Wait States @{*/
69#define FLASH_ACR_LATENCY(w) ((w) & FLASH_ACR_LATENCY_MASK)
70/**@}*/
71
72/* --- FLASH_SR values ----------------------------------------------------- */
73
74#define FLASH_SR_BSY (1 << 0)
75#define FLASH_SR_ERLYBSY (1 << 1)
76#define FLASH_SR_PGERR (1 << 2)
77#define FLASH_SR_WRPRTERR (1 << 4)
78#define FLASH_SR_EOP (1 << 5)
79
80/* --- FLASH_CR values ----------------------------------------------------- */
81
82#define FLASH_CR_OBL_LAUNCH (1 << 13)
83#define FLASH_CR_EOPIE (1 << 12)
84#define FLASH_CR_ERRIE (1 << 10)
85#define FLASH_CR_OPTWRE (1 << 9)
86#define FLASH_CR_LOCK (1 << 7)
87#define FLASH_CR_STRT (1 << 6)
88#define FLASH_CR_OPTER (1 << 5)
89#define FLASH_CR_OPTPG (1 << 4)
90#define FLASH_CR_MER (1 << 2)
91#define FLASH_CR_PER (1 << 1)
92#define FLASH_CR_PG (1 << 0)
93
94/* F3 uses the same keys for option bytes */
95#define FLASH_KEYR_KEY1 ((uint32_t)0x45670123)
96#define FLASH_KEYR_KEY2 ((uint32_t)0xcdef89ab)
97#define FLASH_OPTKEYR_KEY1 FLASH_KEYR_KEY1
98#define FLASH_OPTKEYR_KEY2 FLASH_KEYR_KEY2
99
101
102void flash_clear_pgerr_flag(void);
104void flash_program_half_word(uint32_t address, uint16_t data);
105void flash_erase_page(uint32_t page_address);
106void flash_erase_all_pages(void);
107
109
110/**@}*/
111
112#endif
113
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void flash_erase_page(uint32_t page_address)
Definition: flash.c:91
void flash_clear_pgerr_flag(void)
Definition: flash.c:54
void flash_clear_wrprterr_flag(void)
Definition: flash.c:59
void flash_erase_all_pages(void)
Definition: flash.c:104
void flash_program_half_word(uint32_t address, uint16_t data)
Definition: flash.c:78