libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
eefc.h
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * Copyright (C) 2013 Gareth McMullin <gareth@blacksphere.co.nz>
5 *
6 * This library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef SAM3X_EEFC_H
21#define SAM3X_EEFC_H
22
25
26/* --- Convenience macros ------------------------------------------------ */
27#define EEFC EEFC_BASE
28#define EEFC0 EEFC0_BASE
29#define EEFC1 EEFC1_BASE
30
31/* --- Enhanced Embedded Flash Controller (EEFC) registers --------------- */
32#define EEFC_FMR(port) MMIO32((port) + 0x00)
33#define EEFC_FCR(port) MMIO32((port) + 0x04)
34#define EEFC_FSR(port) MMIO32((port) + 0x08)
35#define EEFC_FRR(port) MMIO32((port) + 0x0C)
36/* 0x0010 - Reserved */
37
38
39/* EEFC Flash Mode Register (EEFC_FMR) */
40/* Bit [31:25] - Reserved */
41#define EEFC_FMR_FAM (0x01 << 24)
42/* Bit [23:12] - Reserved */
43#define EEFC_FMR_FWS_MASK (0x0F << 8)
44/* Bit [7:1] - Reserved */
45#define EEFC_FMR_FRDY (0x01 << 0)
46
47/* EEFC Flash Command Register (EEFC_FCR) */
48#define EEFC_FCR_FKEY (0x5A << 24)
49#define EEFC_FCR_FARG_MASK (0xFFFF << 8)
50#define EEFC_FCR_FCMD_MASK (0xFF << 0)
51#define EEFC_FCR_FCMD_GETD (0x00 << 0)
52#define EEFC_FCR_FCMD_WP (0x01 << 0)
53#define EEFC_FCR_FCMD_WPL (0x02 << 0)
54#define EEFC_FCR_FCMD_EWP (0x03 << 0)
55#define EEFC_FCR_FCMD_EWPL (0x04 << 0)
56#define EEFC_FCR_FCMD_EA (0x05 << 0)
57#define EEFC_FCR_FCMD_SLB (0x08 << 0)
58#define EEFC_FCR_FCMD_CLB (0x09 << 0)
59#define EEFC_FCR_FCMD_GLB (0x0A << 0)
60#define EEFC_FCR_FCMD_SGPB (0x0B << 0)
61#define EEFC_FCR_FCMD_CGPB (0x0C << 0)
62#define EEFC_FCR_FCMD_GGPB (0x0D << 0)
63#define EEFC_FCR_FCMD_STUI (0x0E << 0)
64#define EEFC_FCR_FCMD_SPUI (0x0F << 0)
65
66/* EEFC Flash Status Register (EEFC_FSR) */
67/* Bit [31:3] - Reserved */
68#define EEFC_FSR_FLOCKE (0x01 << 2)
69#define EEFC_FSR_FCMDE (0x01 << 1)
70#define EEFC_FSR_FRDY (0x01 << 0)
71
72static inline void eefc_set_latency(uint8_t wait)
73{
74#if defined(SAM3A) || defined(SAM3U) || defined(SAM3X)
75 EEFC_FMR(EEFC0) = (EEFC_FMR(EEFC0) & ~EEFC_FMR_FWS_MASK) | (wait << 8);
76 EEFC_FMR(EEFC1) = (EEFC_FMR(EEFC1) & ~EEFC_FMR_FWS_MASK) | (wait << 8);
77#elif defined(SAM3N) || defined(SAM3S)
78 EEFC_FMR(EEFC) = (EEFC_FMR(EEFC) & ~EEFC_FMR_FWS_MASK) | (wait << 8);
79#endif
80}
81
82#endif
83
#define EEFC0
Definition: eefc.h:28
#define EEFC_FMR(port)
Definition: eefc.h:32
#define EEFC
Definition: eefc.h:27
static void eefc_set_latency(uint8_t wait)
Definition: eefc.h:72
#define EEFC1
Definition: eefc.h:29