libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
fmc_common_f47.h
Go to the documentation of this file.
1
/** @addtogroup fmc_defines
2
*
3
* @version 1.0.0
4
*
5
* @author @htmlonly © @endhtmlonly 2013
6
* Chuck McManis <cmcmanis@mcmanis.com>
7
*
8
* @date 2013
9
*
10
* This library supports the Flexible Memory Controller (FMC) in the STM32F4xx
11
* and STM32F7xx series of ARM Cortex Microcontrollers by ST Microelectronics.
12
*
13
* LGPL License Terms @ref lgpl_license
14
*/
15
/*
16
* This file is part of the libopencm3 project.
17
*
18
* Copyright (C) 2013 Chuck McManis <cmcmanis@mcmanis.com>
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
#ifndef LIBOPENCM3_FMC_COMMON_F47_H
36
#define LIBOPENCM3_FMC_COMMON_F47_H
37
38
#ifndef LIBOPENCM3_FSMC_H
39
#error "This file should not be included directly, it is included with fsmc.h"
40
#endif
41
42
/* --- Convenience macros -------------------------------------------------- */
43
#define FMC_BANK5_BASE 0xa0000000U
44
#define FMC_BANK6_BASE 0xb0000000U
45
#define FMC_BANK7_BASE 0xc0000000U
46
#define FMC_BANK8_BASE 0xd0000000U
47
48
/* --- FMC registers ------------------------------------------------------ */
49
50
/* SDRAM Control Registers 1 .. 2 */
51
#define FMC_SDCR(x) MMIO32(FSMC_BASE + 0x140 + 4 * (x))
52
#define FMC_SDCR1 FMC_SDCR(0)
53
#define FMC_SDCR2 FMC_SDCR(1)
54
55
56
/* SDRAM Timing Registers 1 .. 2 */
57
#define FMC_SDTR(x) MMIO32(FSMC_BASE + 0x148 + 4 * (x))
58
#define FMC_SDTR1 FMC_SDTR(0)
59
#define FMC_SDTR2 FMC_SDTR(1)
60
61
/* SDRAM Command Mode Register */
62
#define FMC_SDCMR MMIO32(FSMC_BASE + (uint32_t) 0x150)
63
64
/* SDRAM Refresh Timer Register */
65
#define FMC_SDRTR MMIO32(FSMC_BASE + 0x154)
66
67
/* SDRAM Status Register */
68
#define FMC_SDSR MMIO32(FSMC_BASE + (uint32_t) 0x158)
69
70
/* --- FMC_SDCRx values ---------------------------------------------------- */
71
72
/* Bits [31:15]: Reserved. */
73
74
/* RPIPE: Read Pipe */
75
#define FMC_SDCR_RPIPE_SHIFT 13
76
#define FMC_SDCR_RPIPE_MASK (3 << FMC_SDCR_RPIPE_SHIFT)
77
#define FMC_SDCR_RPIPE_NONE (0 << FMC_SDCR_RPIPE_SHIFT)
78
#define FMC_SDCR_RPIPE_1CLK (1 << FMC_SDCR_RPIPE_SHIFT)
79
#define FMC_SDCR_RPIPE_2CLK (2 << FMC_SDCR_RPIPE_SHIFT)
80
81
/* RBURST: Burst Read */
82
#define FMC_SDCR_RBURST (1 << 12)
83
84
/* SDCLK: SDRAM Clock Configuration */
85
#define FMC_SDCR_SDCLK_SHIFT 10
86
#define FMC_SDCR_SDCLK_MASK (3 << FMC_SDCR_SDCLK_SHIFT)
87
#define FMC_SDCR_SDCLK_DISABLE (0 << FMC_SDCR_SDCLK_SHIFT)
88
#define FMC_SDCR_SDCLK_2HCLK (2 << FMC_SDCR_SDCLK_SHIFT)
89
#define FMC_SDCR_SDCLK_3HCLK (3 << FMC_SDCR_SDCLK_SHIFT)
90
91
/* WP: Write Protect */
92
#define FMC_SDCR_WP_ENABLE (1 << 9)
93
94
/* CAS: CAS Latency */
95
#define FMC_SDCR_CAS_SHIFT 7
96
#define FMC_SDCR_CAS_1CYC (1 << FMC_SDCR_CAS_SHIFT)
97
#define FMC_SDCR_CAS_2CYC (2 << FMC_SDCR_CAS_SHIFT)
98
#define FMC_SDCR_CAS_3CYC (3 << FMC_SDCR_CAS_SHIFT)
99
100
/* NB: Number of Internal banks */
101
#define FMC_SDCR_NB2 0
102
#define FMC_SDCR_NB4 (1 << 6)
103
104
/* MWID: Memory width */
105
#define FMC_SDCR_MWID_SHIFT 4
106
#define FMC_SDCR_MWID_8b (0 << FMC_SDCR_MWID_SHIFT)
107
#define FMC_SDCR_MWID_16b (1 << FMC_SDCR_MWID_SHIFT)
108
#define FMC_SDCR_MWID_32b (2 << FMC_SDCR_MWID_SHIFT)
109
110
/* NR: Number of rows */
111
#define FMC_SDCR_NR_SHIFT 2
112
#define FMC_SDCR_NR_11 (0 << FMC_SDCR_NR_SHIFT)
113
#define FMC_SDCR_NR_12 (1 << FMC_SDCR_NR_SHIFT)
114
#define FMC_SDCR_NR_13 (2 << FMC_SDCR_NR_SHIFT)
115
116
/* NC: Number of Columns */
117
#define FMC_SDCR_NC_SHIFT 0
118
#define FMC_SDCR_NC_8 (0 << FMC_SDCR_NC_SHIFT)
119
#define FMC_SDCR_NC_9 (1 << FMC_SDCR_NC_SHIFT)
120
#define FMC_SDCR_NC_10 (2 << FMC_SDCR_NC_SHIFT)
121
#define FMC_SDCR_NC_11 (3 << FMC_SDCR_NC_SHIFT)
122
123
/* --- FMC_SDTRx values --------------------------------------------------- */
124
125
/* Bits [31:28]: Reserved. */
126
127
/* TRCD: Row to Column Delay */
128
#define FMC_SDTR_TRCD_SHIFT 24
129
#define FMC_SDTR_TRCD_MASK (15 << FMC_SDTR_TRCD_SHIFT)
130
131
/* TRP: Row Precharge Delay */
132
#define FMC_SDTR_TRP_SHIFT 20
133
#define FMC_SDTR_TRP_MASK (15 << FMC_SDTR_TRP_SHIFT)
134
135
/* TWR: Recovery Delay */
136
#define FMC_SDTR_TWR_SHIFT 16
137
#define FMC_SDTR_TWR_MASK (15 << FMC_SDTR_TWR_SHIFT)
138
139
/* TRC: Row Cycle Delay */
140
#define FMC_SDTR_TRC_SHIFT 12
141
#define FMC_SDTR_TRC_MASK (15 << FMC_SDTR_TRC_SHIFT)
142
143
/* TRAS: Self Refresh Time */
144
#define FMC_SDTR_TRAS_SHIFT 8
145
#define FMC_SDTR_TRAS_MASK (15 << FMC_SDTR_TRAS_SHIFT)
146
147
/* TXSR: Exit Self-refresh Delay */
148
#define FMC_SDTR_TXSR_SHIFT 4
149
#define FMC_SDTR_TXSR_MASK (15 << FMC_SDTR_TXSR_SHIFT)
150
151
/* TRMD: Load Mode Register to Active */
152
#define FMC_SDTR_TMRD_SHIFT 0
153
#define FMC_SDTR_TMRD_MASK (15 << FMC_SDTR_TMRD_SHIFT)
154
155
/*
156
* Some config bits only count in CR1 or TR1, even if you
157
* are just configuring bank 2, so these masks let you copy
158
* out those bits after you have computed values for CR2 and
159
* TR2 and put them into CR1 and TR1
160
*/
161
#define FMC_SDTR_DNC_MASK (FMC_SDTR_TRP_MASK | FMC_SDTR_TRC_MASK)
162
#define FMC_SDCR_DNC_MASK (FMC_SDCR_SDCLK_MASK | \
163
FMC_SDCR_RPIPE_MASK | \
164
FMC_SDCR_RBURST)
165
166
/* --- FMC_SDCMR values --------------------------------------------------- */
167
168
/* Bits [31:22]: Reserved. */
169
170
/* MRD: Mode Register Definition */
171
#define FMC_SDCMR_MRD_SHIFT 9
172
#define FMC_SDCMR_MRD_MASK (0x1fff << FMC_SDCMR_MRD_SHIFT)
173
174
/* NRFS: Number of Auto-refresh */
175
#define FMC_SDCMR_NRFS_SHIFT 5
176
#define FMC_SDCMR_NRFS_MASK (15 << FMC_SDCMR_NRFS_SHIFT)
177
178
/* CTB1: Command Target Bank 1 */
179
#define FMC_SDCMR_CTB1 (1 << 4)
180
181
/* CTB2: Command Target Bank 2 */
182
#define FMC_SDCMR_CTB2 (1 << 3)
183
184
/* MODE: Command Mode */
185
#define FMC_SDCMR_MODE_SHIFT 0
186
#define FMC_SDCMR_MODE_MASK 7
187
#define FMC_SDCMR_MODE_NORMAL 0
188
#define FMC_SDCMR_MODE_CLOCK_CONFIG_ENA 1
189
#define FMC_SDCMR_MODE_PALL 2
190
#define FMC_SDCMR_MODE_AUTO_REFRESH 3
191
#define FMC_SDCMR_MODE_LOAD_MODE_REGISTER 4
192
#define FMC_SDCMR_MODE_SELF_REFRESH 5
193
#define FMC_SDCMR_MODE_POWER_DOWN 6
194
195
/* --- FMC_SDRTR values ---------------------------------------------------- */
196
197
/* Bits [31:15]: Reserved. */
198
199
/* REIE: Refresh Error Interrupt Enable */
200
#define FMC_SDRTR_REIE (1 << 14)
201
202
/* COUNT: Refresh Timer Count */
203
#define FMC_SDRTR_COUNT_SHIFT 1
204
#define FMC_SDRTR_COUNT_MASK (0x1fff << FMC_SDRTR_COUNT_SHIFT)
205
206
/* CRE: Clear Refresh Error Flag */
207
#define FMC_SDRTR_CRE (1 << 0)
208
209
/* --- FMC_SDSR values ---------------------------------------------------- */
210
211
/* Bits [31:6]: Reserved. */
212
213
/* BUSY: Set if the SDRAM is working on the command */
214
#define FMC_SDSR_BUSY (1 << 5)
215
216
/* MODES: Status modes */
217
#define FMC_SDSR_MODE_NORMAL 0
218
#define FMC_SDSR_MODE_SELF_REFRESH 1
219
#define FMC_SDSR_MODE_POWER_DOWN 2
220
221
/* Mode shift */
222
#define FMC_SDSR_MODE2_SHIFT 3
223
#define FMC_SDSR_MODE1_SHIFT 1
224
225
/* RE: Refresh Error */
226
#define FMC_SDSR_RE (1 << 0)
227
228
/* Helper function for setting the timing parameters */
229
struct
sdram_timing
{
230
int
trcd
;
/* RCD Delay */
231
int
trp
;
/* RP Delay */
232
int
twr
;
/* Write Recovery Time */
233
int
trc
;
/* Row Cycle Delay */
234
int
tras
;
/* Self Refresh TIme */
235
int
txsr
;
/* Exit Self Refresh Time */
236
int
tmrd
;
/* Load to Active delay */
237
};
238
239
/* Mode register parameters */
240
#define SDRAM_MODE_BURST_LENGTH_1 ((uint16_t)0x0000)
241
#define SDRAM_MODE_BURST_LENGTH_2 ((uint16_t)0x0001)
242
#define SDRAM_MODE_BURST_LENGTH_4 ((uint16_t)0x0002)
243
#define SDRAM_MODE_BURST_LENGTH_8 ((uint16_t)0x0004)
244
#define SDRAM_MODE_BURST_TYPE_SEQUENTIAL ((uint16_t)0x0000)
245
#define SDRAM_MODE_BURST_TYPE_INTERLEAVED ((uint16_t)0x0008)
246
#define SDRAM_MODE_CAS_LATENCY_2 ((uint16_t)0x0020)
247
#define SDRAM_MODE_CAS_LATENCY_3 ((uint16_t)0x0030)
248
#define SDRAM_MODE_OPERATING_MODE_STANDARD ((uint16_t)0x0000)
249
#define SDRAM_MODE_WRITEBURST_MODE_PROGRAMMED ((uint16_t)0x0000)
250
#define SDRAM_MODE_WRITEBURST_MODE_SINGLE ((uint16_t)0x0200)
251
252
enum
fmc_sdram_bank
{
SDRAM_BANK1
,
SDRAM_BANK2
,
SDRAM_BOTH_BANKS
};
253
enum
fmc_sdram_command
{
SDRAM_CLK_CONF
,
SDRAM_NORMAL
,
SDRAM_PALL
,
254
SDRAM_AUTO_REFRESH
,
SDRAM_LOAD_MODE
,
255
SDRAM_SELF_REFRESH
,
SDRAM_POWER_DOWN
};
256
257
/* Send an array of timing parameters (indices above) to create SDTR register
258
* value
259
*/
260
BEGIN_DECLS
261
262
uint32_t
sdram_timing
(
struct
sdram_timing
*t);
263
void
sdram_command
(
enum
fmc_sdram_bank
bank,
enum
fmc_sdram_command
cmd,
264
int
autorefresh,
int
modereg);
265
266
END_DECLS
267
268
#endif
269
/**@}*/
END_DECLS
#define END_DECLS
Definition:
common.h:34
BEGIN_DECLS
#define BEGIN_DECLS
Definition:
common.h:33
sdram_timing
uint32_t sdram_timing(struct sdram_timing *t)
Definition:
fmc_common_f47.c:43
fmc_sdram_bank
fmc_sdram_bank
Definition:
fmc_common_f47.h:252
fmc_sdram_command
fmc_sdram_command
Definition:
fmc_common_f47.h:253
sdram_command
void sdram_command(enum fmc_sdram_bank bank, enum fmc_sdram_command cmd, int autorefresh, int modereg)
Definition:
fmc_common_f47.c:63
SDRAM_BANK1
@ SDRAM_BANK1
Definition:
fmc_common_f47.h:252
SDRAM_BANK2
@ SDRAM_BANK2
Definition:
fmc_common_f47.h:252
SDRAM_BOTH_BANKS
@ SDRAM_BOTH_BANKS
Definition:
fmc_common_f47.h:252
SDRAM_PALL
@ SDRAM_PALL
Definition:
fmc_common_f47.h:253
SDRAM_NORMAL
@ SDRAM_NORMAL
Definition:
fmc_common_f47.h:253
SDRAM_CLK_CONF
@ SDRAM_CLK_CONF
Definition:
fmc_common_f47.h:253
SDRAM_AUTO_REFRESH
@ SDRAM_AUTO_REFRESH
Definition:
fmc_common_f47.h:254
SDRAM_POWER_DOWN
@ SDRAM_POWER_DOWN
Definition:
fmc_common_f47.h:255
SDRAM_SELF_REFRESH
@ SDRAM_SELF_REFRESH
Definition:
fmc_common_f47.h:255
SDRAM_LOAD_MODE
@ SDRAM_LOAD_MODE
Definition:
fmc_common_f47.h:254
sdram_timing
Definition:
fmc_common_f47.h:229
sdram_timing::trcd
int trcd
Definition:
fmc_common_f47.h:230
sdram_timing::tras
int tras
Definition:
fmc_common_f47.h:234
sdram_timing::tmrd
int tmrd
Definition:
fmc_common_f47.h:236
sdram_timing::trp
int trp
Definition:
fmc_common_f47.h:231
sdram_timing::twr
int twr
Definition:
fmc_common_f47.h:232
sdram_timing::txsr
int txsr
Definition:
fmc_common_f47.h:235
sdram_timing::trc
int trc
Definition:
fmc_common_f47.h:233
include
libopencm3
stm32
common
fmc_common_f47.h
Generated on Tue Mar 7 2023 16:11:49 for libopencm3 by
1.9.4