Updates for STM32F429 chip
After a few rounds of review, changes are added to support additional peripherals of the STM32F427/429
This commit is contained in:
committed by
Frantisek Burian
parent
3fc84d6519
commit
07d0076934
@@ -50,7 +50,7 @@ OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
|
||||
OBJS += usb.o usb_standard.o usb_control.o usb_fx07_common.o \
|
||||
usb_f107.o usb_f207.o
|
||||
|
||||
OBJS += mac.o phy.o mac_stm32fxx7.o phy_ksz8051mll.o
|
||||
OBJS += mac.o phy.o mac_stm32fxx7.o phy_ksz8051mll.o fmc.o
|
||||
|
||||
VPATH += ../../usb:../:../../cm3:../common
|
||||
VPATH += ../../ethernet
|
||||
|
||||
99
lib/stm32/f4/fmc.c
Normal file
99
lib/stm32/f4/fmc.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/* vim: set noexpandtab ts=8:
|
||||
*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Utility functions for the SDRAM component of the FMC */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <libopencm3/stm32/fsmc.h>
|
||||
|
||||
/*
|
||||
* Install various timing values into the correct place in the
|
||||
* SDRAM Timing Control Register format.
|
||||
*
|
||||
* Note that the register is 'zero' based to save bits so 1 cycle
|
||||
* is stored as '0'. This command takes actual cycles and adjusts
|
||||
* by subtracting 1.
|
||||
*/
|
||||
uint32_t
|
||||
sdram_timing(struct sdram_timing *t) {
|
||||
uint32_t result;
|
||||
|
||||
result = 0;
|
||||
result |= ((t->trcd - 1) & 0xf) * FMC_SDTR_TRCD_SHIFT;
|
||||
result |= ((t->trp - 1) & 0xf) * FMC_SDTR_TRP_SHIFT;
|
||||
result |= ((t->twr - 1) & 0xf) * FMC_SDTR_TWR_SHIFT;
|
||||
result |= ((t->trc - 1) & 0xf) * FMC_SDTR_TRC_SHIFT;
|
||||
result |= ((t->tras - 1) & 0xf) * FMC_SDTR_TRAS_SHIFT;
|
||||
result |= ((t->txsr - 1) & 0xf) * FMC_SDTR_TXSR_SHIFT;
|
||||
result |= ((t->tmrd - 1) & 0xf) * FMC_SDTR_TMRD_SHIFT;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a command to the SDRAM controller, wait until it is not
|
||||
* busy before sending. This allows you to chain sending commands
|
||||
* and the code will pause as needed between them.
|
||||
*/
|
||||
void
|
||||
sdram_command(enum fmc_sdram_bank bank,
|
||||
enum fmc_sdram_command cmd, int autorefresh, int modereg) {
|
||||
uint32_t tmp_reg = 0;
|
||||
|
||||
switch (bank) {
|
||||
case SDRAM_BANK1:
|
||||
tmp_reg = FMC_SDCMR_CTB1;
|
||||
break;
|
||||
case SDRAM_BANK2:
|
||||
tmp_reg = FMC_SDCMR_CTB2;
|
||||
break;
|
||||
case SDRAM_BOTH_BANKS:
|
||||
tmp_reg = FMC_SDCMR_CTB1 | FMC_SDCMR_CTB2;
|
||||
break;
|
||||
}
|
||||
tmp_reg |= autorefresh * FMC_SDCMR_NRFS_SHIFT;
|
||||
tmp_reg |= modereg * FMC_SDCMR_MRD_SHIFT;
|
||||
switch (cmd) {
|
||||
case SDRAM_CLK_CONF:
|
||||
tmp_reg |= FMC_SDCMR_MODE_CLOCK_CONFIG_ENA;
|
||||
break;
|
||||
case SDRAM_AUTO_REFRESH:
|
||||
tmp_reg |= FMC_SDCMR_MODE_AUTO_REFRESH;
|
||||
break;
|
||||
case SDRAM_LOAD_MODE:
|
||||
tmp_reg |= FMC_SDCMR_MODE_LOAD_MODE_REGISTER;
|
||||
break;
|
||||
case SDRAM_PALL:
|
||||
tmp_reg |= FMC_SDCMR_MODE_PALL;
|
||||
break;
|
||||
case SDRAM_SELF_REFRESH:
|
||||
tmp_reg |= FMC_SDCMR_MODE_SELF_REFRESH;
|
||||
break;
|
||||
case SDRAM_POWER_DOWN:
|
||||
tmp_reg |= FMC_SDCMR_MODE_POWER_DOWN;
|
||||
break;
|
||||
case SDRAM_NORMAL:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Wait for the next chance to talk to the controller */
|
||||
while (FMC_SDSR & FMC_SDSR_BUSY) ;
|
||||
|
||||
/* Send the next command */
|
||||
FMC_SDCMR = tmp_reg;
|
||||
}
|
||||
Reference in New Issue
Block a user