libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
flash.c
Go to the documentation of this file.
1/** @defgroup flash_file FLASH peripheral API
2 *
3 * @ingroup peripheral_apis
4 *
5 * @brief <b>libopencm3 STM32F3xx FLASH</b>
6 *
7 * @version 1.0.0
8 *
9 * @author @htmlonly &copy; @endhtmlonly 2010
10 * Thomas Otto <tommi@viadmin.org>
11 * @author @htmlonly &copy; @endhtmlonly 2010
12 * Mark Butler <mbutler@physics.otago.ac.nz>
13 *
14 * @date 14 January 2014
15 *
16 * This library supports the FLASH memory controller in the STM32F3
17 * series of ARM Cortex Microcontrollers by ST Microelectronics.
18 *
19 * For the STM32F3xx, accessing FLASH memory is described in
20 * section 3 of the STM32F3xx Reference Manual.
21 *
22 * LGPL License Terms @ref lgpl_license
23 */
24
25/*
26 * This file is part of the libopencm3 project.
27 *
28 * Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
29 * Copyright (C) 2010 Mark Butler <mbutler@physics.otago.ac.nz>
30 *
31 * This library is free software: you can redistribute it and/or modify
32 * it under the terms of the GNU Lesser General Public License as published by
33 * the Free Software Foundation, either version 3 of the License, or
34 * (at your option) any later version.
35 *
36 * This library is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU Lesser General Public License for more details.
40 *
41 * You should have received a copy of the GNU Lesser General Public License
42 * along with this library. If not, see <http://www.gnu.org/licenses/>.
43 */
44
45/**@{*/
46
48
50{
51 while ((FLASH_SR & FLASH_SR_BSY) == FLASH_SR_BSY);
52}
53
55{
57}
58
60{
62}
63
64/*---------------------------------------------------------------------------*/
65
66/** @brief Clear All Status Flags
67
68Clears program error, end of operation, busy flags.
69 */
70
72{
76}
77
78void flash_program_half_word(uint32_t address, uint16_t data)
79{
81
83
84 MMIO16(address) = data;
85
87
88 FLASH_CR &= ~FLASH_CR_PG;
89}
90
91void flash_erase_page(uint32_t page_address)
92{
94
96 FLASH_AR = page_address;
98
100
101 FLASH_CR &= ~FLASH_CR_PER;
102}
103
105{
107
110
112 FLASH_CR &= ~FLASH_CR_MER;
113}
114
115
116/**@}*/
117
#define MMIO16(addr)
Definition: common.h:68
#define FLASH_SR_WRPRTERR
Definition: f3/flash.h:77
#define FLASH_CR_PG
Definition: f3/flash.h:92
#define FLASH_CR_MER
Definition: f3/flash.h:90
#define FLASH_SR_BSY
Definition: f3/flash.h:74
#define FLASH_SR_PGERR
Definition: f3/flash.h:76
#define FLASH_CR_PER
Definition: f3/flash.h:91
#define FLASH_CR_STRT
Definition: f3/flash.h:87
void flash_erase_page(uint32_t page_address)
Definition: flash.c:91
void flash_wait_for_last_operation(void)
Wait until Last Operation has Ended.
Definition: flash.c:49
void flash_clear_eop_flag(void)
Clear the End of OPeration flag.
void flash_clear_pgerr_flag(void)
Definition: flash.c:54
void flash_clear_status_flags(void)
Clear All Status Flags.
Definition: flash.c:71
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
#define FLASH_AR
Flash Address register.
Definition: f3/flash.h:52
#define FLASH_SR
Flash Status register.
Definition: f3/flash.h:48
#define FLASH_CR
Flash Control register.
Definition: f3/flash.h:50