libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
flash_common_f01.h
Go to the documentation of this file.
1/** @addtogroup flash_defines
2 *
3 */
4/*
5 * This file is part of the libopencm3 project.
6 *
7 * Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
8 * Copyright (C) 2010 Mark Butler <mbutler@physics.otago.ac.nz>
9 *
10 * This library is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * For details see:
26 * PM0081 Programming manual: STM32F40xxx and STM32F41xxx Flash programming
27 * September 2011, Doc ID 018520 Rev 1
28 * https://github.com/libopencm3/libopencm3-archive/blob/master/st_micro/DM00023388.pdf
29 */
30
31/** @cond */
32#ifdef LIBOPENCM3_FLASH_H
33/** @endcond */
34#ifndef LIBOPENCM3_FLASH_COMMON_F01_H
35#define LIBOPENCM3_FLASH_COMMON_F01_H
36/**@{*/
37
38/* --- FLASH registers ----------------------------------------------------- */
39
40#define FLASH_ACR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00)
41#define FLASH_KEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x04)
42#define FLASH_OPTKEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x08)
43#define FLASH_SR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x0C)
44#define FLASH_CR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x10)
45#define FLASH_AR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x14)
46#define FLASH_OBR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x1C)
47#define FLASH_WRPR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x20)
48/* Only present in STM32F10x XL series */
49#define FLASH_KEYR2 MMIO32(FLASH_MEM_INTERFACE_BASE + 0x44)
50#define FLASH_SR2 MMIO32(FLASH_MEM_INTERFACE_BASE + 0x4C)
51#define FLASH_CR2 MMIO32(FLASH_MEM_INTERFACE_BASE + 0x50)
52#define FLASH_AR2 MMIO32(FLASH_MEM_INTERFACE_BASE + 0x54)
53
54/* --- FLASH_OPTION bytes ------------------------------------------------- */
55
56#define FLASH_OPTION_BYTE(i) MMIO16(INFO_BASE+0x0800 + (i)*2)
57
58/* --- FLASH_ACR values ---------------------------------------------------- */
59
60#define FLASH_ACR_LATENCY_SHIFT 0
61#define FLASH_ACR_LATENCY_MASK 7
62
63#define FLASH_ACR_PRFTBS (1 << 5)
64#define FLASH_ACR_PRFTBE (1 << 4)
65/** Compatibility define */
66#define FLASH_ACR_PRFTEN FLASH_ACR_PRFTBE
67
68/* --- FLASH_SR values ----------------------------------------------------- */
69
70#define FLASH_SR_EOP (1 << 5)
71#define FLASH_SR_WRPRTERR (1 << 4)
72#define FLASH_SR_PGERR (1 << 2)
73#define FLASH_SR_BSY (1 << 0)
74
75/* --- FLASH_CR values ----------------------------------------------------- */
76
77#define FLASH_CR_EOPIE (1 << 12)
78#define FLASH_CR_ERRIE (1 << 10)
79#define FLASH_CR_OPTWRE (1 << 9)
80#define FLASH_CR_LOCK (1 << 7)
81#define FLASH_CR_STRT (1 << 6)
82#define FLASH_CR_OPTER (1 << 5)
83#define FLASH_CR_OPTPG (1 << 4)
84#define FLASH_CR_MER (1 << 2)
85#define FLASH_CR_PER (1 << 1)
86#define FLASH_CR_PG (1 << 0)
87
88/* --- FLASH_OBR values ---------------------------------------------------- */
89
90#define FLASH_OBR_RDPRT_SHIFT 1
91#define FLASH_OBR_OPTERR (1 << 0)
92
93/* --- FLASH Keys -----------------------------------------------------------*/
94
95#define FLASH_KEYR_KEY1 ((uint32_t)0x45670123)
96#define FLASH_KEYR_KEY2 ((uint32_t)0xcdef89ab)
97
98#define FLASH_OPTKEYR_KEY1 FLASH_KEYR_KEY1
99#define FLASH_OPTKEYR_KEY2 FLASH_KEYR_KEY2
100
101/* --- Function prototypes ------------------------------------------------- */
102
104
105void flash_clear_pgerr_flag(void);
107uint32_t flash_get_status_flags(void);
108void flash_program_word(uint32_t address, uint32_t data);
109void flash_program_half_word(uint32_t address, uint16_t data);
110void flash_erase_page(uint32_t page_address);
111void flash_erase_all_pages(void);
112void flash_erase_option_bytes(void);
113void flash_program_option_bytes(uint32_t address, uint16_t data);
114
116/**@}*/
117
118#endif
119/** @cond */
120#else
121#warning "flash_common_f01.h should not be included directly,"
122#warning "only via flash.h"
123#endif
124/** @endcond */
125
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void flash_erase_page(uint32_t page_address)
Erase a Page of FLASH.
Definition: flash.c:252
uint32_t flash_get_status_flags(void)
Read All Status Flags.
Definition: flash.c:189
void flash_erase_option_bytes(void)
Erase All Option Bytes.
void flash_program_word(uint32_t address, uint32_t data)
Program a 32 bit Word to FLASH.
void flash_clear_pgerr_flag(void)
Unlock the Flash Program and Erase Controller.
void flash_clear_wrprterr_flag(void)
Clear the Write Protect Error Status Flag.
void flash_program_option_bytes(uint32_t address, uint16_t data)
Program the Option Bytes.
void flash_erase_all_pages(void)
Erase All FLASH.
Definition: flash.c:284
void flash_program_half_word(uint32_t address, uint16_t data)
Program a Half Word to FLASH.
Definition: flash.c:218