libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
fmc_common_f47.c
Go to the documentation of this file.
1/** @addtogroup fmc_file FMC peripheral API
2@ingroup peripheral_apis
3
4@author @htmlonly © @endhtmlonly 2012 Ken Sarkies ksarkies@internode.on.net
5
6This library supports the Flexible Memory Controller in the STM32F4xx and
7STM32F7xx series of ARM Cortex Microcontrollers by ST Microelectronics.
8*/
9/*
10 *
11 * This file is part of the libopencm3 project.
12 *
13 * This library is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with this library. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27/* Utility functions for the SDRAM component of the FMC */
28
29#include <stdint.h>
31
32/**@{*/
33
34/*
35 * Install various timing values into the correct place in the
36 * SDRAM Timing Control Register format.
37 *
38 * Note that the register is 'zero' based to save bits so 1 cycle
39 * is stored as '0'. This command takes actual cycles and adjusts
40 * by subtracting 1.
41 */
42uint32_t
44 uint32_t result;
45
46 result = 0;
47 result |= ((t->trcd - 1) & 0xf) << FMC_SDTR_TRCD_SHIFT;
48 result |= ((t->trp - 1) & 0xf) << FMC_SDTR_TRP_SHIFT;
49 result |= ((t->twr - 1) & 0xf) << FMC_SDTR_TWR_SHIFT;
50 result |= ((t->trc - 1) & 0xf) << FMC_SDTR_TRC_SHIFT;
51 result |= ((t->tras - 1) & 0xf) << FMC_SDTR_TRAS_SHIFT;
52 result |= ((t->txsr - 1) & 0xf) << FMC_SDTR_TXSR_SHIFT;
53 result |= ((t->tmrd - 1) & 0xf) << FMC_SDTR_TMRD_SHIFT;
54 return result;
55}
56
57/*
58 * Send a command to the SDRAM controller, wait until it is not
59 * busy before sending. This allows you to chain sending commands
60 * and the code will pause as needed between them.
61 */
62void
64 enum fmc_sdram_command cmd, int autorefresh, int modereg) {
65 uint32_t tmp_reg = 0;
66
67 switch (bank) {
68 case SDRAM_BANK1:
69 tmp_reg = FMC_SDCMR_CTB1;
70 break;
71 case SDRAM_BANK2:
72 tmp_reg = FMC_SDCMR_CTB2;
73 break;
76 break;
77 }
78 tmp_reg |= autorefresh << FMC_SDCMR_NRFS_SHIFT;
79 tmp_reg |= modereg << FMC_SDCMR_MRD_SHIFT;
80 switch (cmd) {
81 case SDRAM_CLK_CONF:
83 break;
86 break;
87 case SDRAM_LOAD_MODE:
89 break;
90 case SDRAM_PALL:
91 tmp_reg |= FMC_SDCMR_MODE_PALL;
92 break;
95 break;
98 break;
99 case SDRAM_NORMAL:
100 default:
101 break;
102 }
103
104 /* Wait for the next chance to talk to the controller */
105 while (FMC_SDSR & FMC_SDSR_BUSY);
106
107 /* Send the next command */
108 FMC_SDCMR = tmp_reg;
109}
110
111/**@}*/
#define FMC_SDTR_TRAS_SHIFT
#define FMC_SDTR_TRC_SHIFT
#define FMC_SDTR_TMRD_SHIFT
#define FMC_SDTR_TRP_SHIFT
#define FMC_SDSR_BUSY
#define FMC_SDCMR_CTB1
#define FMC_SDCMR_MODE_POWER_DOWN
#define FMC_SDCMR_MRD_SHIFT
#define FMC_SDCMR_MODE_AUTO_REFRESH
fmc_sdram_bank
#define FMC_SDTR_TXSR_SHIFT
#define FMC_SDCMR_CTB2
fmc_sdram_command
#define FMC_SDSR
#define FMC_SDCMR_MODE_CLOCK_CONFIG_ENA
#define FMC_SDCMR
#define FMC_SDCMR_MODE_PALL
#define FMC_SDCMR_MODE_SELF_REFRESH
#define FMC_SDCMR_NRFS_SHIFT
#define FMC_SDTR_TWR_SHIFT
#define FMC_SDCMR_MODE_LOAD_MODE_REGISTER
#define FMC_SDTR_TRCD_SHIFT
@ SDRAM_BANK1
@ SDRAM_BANK2
@ SDRAM_BOTH_BANKS
@ SDRAM_PALL
@ SDRAM_NORMAL
@ SDRAM_CLK_CONF
@ SDRAM_AUTO_REFRESH
@ SDRAM_POWER_DOWN
@ SDRAM_SELF_REFRESH
@ SDRAM_LOAD_MODE
uint32_t sdram_timing(struct sdram_timing *t)
void sdram_command(enum fmc_sdram_bank bank, enum fmc_sdram_command cmd, int autorefresh, int modereg)