libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
f1/flash.h
Go to the documentation of this file.
1/** @defgroup flash_defines FLASH Defines
2 *
3 * @ingroup STM32F1xx_defines
4 *
5 * @brief Defined Constants and Types for the STM32F1xx FLASH Memory
6 *
7 * @version 1.0.0
8 *
9 * @date 14 January 2014
10 *
11 * LGPL License Terms @ref lgpl_license
12 */
13
14/*
15 * This file is part of the libopencm3 project.
16 *
17 * Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
18 * Copyright (C) 2010 Mark Butler <mbutler@physics.otago.ac.nz>
19 *
20 * This library is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU Lesser General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public License
31 * along with this library. If not, see <http://www.gnu.org/licenses/>.
32 */
33
34/*
35 * For details see:
36 * PM0075 programming manual: STM32F10xxx Flash programming
37 * August 2010, Doc ID 17863 Rev 1
38 * https://github.com/libopencm3/libopencm3-archive/blob/master/st_micro/CD00283419.pdf
39 */
40
41#ifndef LIBOPENCM3_FLASH_H
42#define LIBOPENCM3_FLASH_H
43
44/**@{*/
45
49
50/* --- FLASH_OPTION bytes ------------------------------------------------- */
51
52/** @defgroup flash_options Option Byte Addresses
53@ingroup flash_defines
54@{*/
55#define FLASH_OPTION_BYTE_0 FLASH_OPTION_BYTE(0)
56#define FLASH_OPTION_BYTE_1 FLASH_OPTION_BYTE(1)
57#define FLASH_OPTION_BYTE_2 FLASH_OPTION_BYTE(2)
58#define FLASH_OPTION_BYTE_3 FLASH_OPTION_BYTE(3)
59#define FLASH_OPTION_BYTE_4 FLASH_OPTION_BYTE(4)
60#define FLASH_OPTION_BYTE_5 FLASH_OPTION_BYTE(5)
61#define FLASH_OPTION_BYTE_6 FLASH_OPTION_BYTE(6)
62#define FLASH_OPTION_BYTE_7 FLASH_OPTION_BYTE(7)
63/**@}*/
64
65/*****************************************************************************/
66/* Register values */
67/*****************************************************************************/
68
69/* --- FLASH_ACR values ---------------------------------------------------- */
70
71/** @defgroup flash_latency FLASH Wait States
72@ingroup flash_defines
73@{*/
74#define FLASH_ACR_LATENCY_0WS 0x00
75#define FLASH_ACR_LATENCY_1WS 0x01
76#define FLASH_ACR_LATENCY_2WS 0x02
77/**@}*/
78#define FLASH_ACR_HLFCYA (1 << 3)
79
80/* --- FLASH_SR values ----------------------------------------------------- */
81
82#define FLASH_SR_EOP (1 << 5)
83#define FLASH_SR_WRPRTERR (1 << 4)
84#define FLASH_SR_PGERR (1 << 2)
85#define FLASH_SR_BSY (1 << 0)
86
87/* --- FLASH_CR values ----------------------------------------------------- */
88
89/* --- FLASH_OBR values ---------------------------------------------------- */
90
91/* FLASH_OBR[25:18]: Data1 */
92/* FLASH_OBR[17:10]: Data0 */
93#define FLASH_OBR_NRST_STDBY (1 << 4)
94#define FLASH_OBR_NRST_STOP (1 << 3)
95#define FLASH_OBR_WDG_SW (1 << 2)
96#define FLASH_OBR_RDPRT_EN (1 << FLASH_OBR_RDPRT_SHIFT)
97
98/*****************************************************************************/
99/* API definitions */
100/*****************************************************************************/
101
102/* Read protection option byte protection enable key */
103#define FLASH_RDP_KEY ((uint16_t)0x00a5)
104
105/* --- Function prototypes ------------------------------------------------- */
106
108
109void flash_halfcycle_enable(void);
110void flash_halfcycle_disable(void);
111void flash_unlock_upper(void);
112void flash_lock_upper(void);
116
118
119/**@}*/
120
121#endif
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void flash_clear_wrprterr_flag_upper(void)
Clear the Write Protect Error Status Flag, upper Bank.
Definition: flash.c:151
void flash_lock_upper(void)
Lock the Flash Program and Erase Controller, upper Bank.
Definition: flash.c:117
void flash_clear_pgerr_flag_upper(void)
Clear the Programming Error Status Flag, upper Bank.
Definition: flash.c:127
void flash_halfcycle_disable(void)
Disable the FLASH Half Cycle Mode.
Definition: flash.c:86
void flash_unlock_upper(void)
Unlock the Flash Program and Erase Controller, upper Bank.
Definition: flash.c:98
void flash_halfcycle_enable(void)
Enable the FLASH Half Cycle Mode.
Definition: flash.c:76
void flash_clear_eop_flag_upper(void)
Clear the End of Operation Status Flag, upper Bank.
Definition: flash.c:139