FSMC. SDRAM. Style cleanup

This commit is contained in:
barthess 2014-10-22 10:33:02 +03:00
parent e52b67e87f
commit 5f231b6aaf
9 changed files with 156 additions and 112 deletions

View File

@ -28,7 +28,8 @@
#include "hal.h"
#include "fsmc.h"
#if HAL_USE_NAND || STM32_USE_FSMC_SRAM || defined(__DOXYGEN__)
#if HAL_USE_NAND || STM32_USE_FSMC_SRAM || STM32_USE_FSMC_SDRAM || \
defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver local definitions. */
@ -102,6 +103,17 @@ void fsmc_init(void) {
#if STM32_USE_FSMC_PCCARD
FSMCD1.pccard = (FSMC_PCCARD_TypeDef *)FSMC_Bank4_R_BASE;
#endif
#if (defined(STM32F427xx) || defined(STM32F437xx) || \
defined(STM32F429xx) || defined(STM32F439xx))
#if STM32_SDRAM_USE_FSMC_SDRAM1
FSMCD1.sdram1 = (FSMC_SDRAM_TypeDef *)FSMC_Bank5_R_BASE;
#endif
#if STM32_SDRAM_USE_FSMC_SDRAM2
FSMCD1.sdram2 = (FSMC_SDRAM_TypeDef *)FSMC_Bank6_R_BASE;
#endif
#endif
}
}
@ -183,6 +195,6 @@ CH_IRQ_HANDLER(STM32_FSMC_HANDLER) {
}
#endif /* !STM32_NAND_USE_EXT_INT */
#endif /* HAL_USE_FSMC || STM32_USE_FSMC_SRAM */
#endif /* HAL_USE_FSMC || STM32_USE_FSMC_SRAM || STM32_USE_FSMC_SDRAM */
/** @} */

View File

@ -29,7 +29,7 @@
#ifndef _FSMC_H_
#define _FSMC_H_
#if HAL_USE_NAND || STM32_USE_FSMC_SRAM || defined(__DOXYGEN__)
#if HAL_USE_NAND || STM32_USE_FSMC_SRAM || STM32_USE_FSMC_SDRAM || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver constants. */
@ -86,6 +86,11 @@
#define FSMC_Bank2_MAP_BASE ((uint32_t) 0x70000000)
#define FSMC_Bank3_MAP_BASE ((uint32_t) 0x80000000)
#define FSMC_Bank4_MAP_BASE ((uint32_t) 0x90000000)
#if (defined(STM32F427xx) || defined(STM32F437xx) || \
defined(STM32F429xx) || defined(STM32F439xx))
#define FSMC_Bank5_MAP_BASE ((uint32_t) 0xC0000000)
#define FSMC_Bank6_MAP_BASE ((uint32_t) 0xD0000000)
#endif
/*
* Subbunks of bank1
@ -158,6 +163,15 @@ typedef struct {
__IO uint32_t BWTR; /**< SRAM/NOR write timing registers */
} FSMC_SRAM_NOR_TypeDef;
#if (defined(STM32F427xx) || defined(STM32F437xx) || \
defined(STM32F429xx) || defined(STM32F439xx))
typedef struct {
__IO uint32_t SDCR; /**< SDRAM control register */
uint32_t RESERVED0; /**< Reserved */
__IO uint32_t SDTR; /**< SDRAM timing register */
} FSMC_SDRAM_TypeDef;
#endif
/**
* @brief PCR register
*/
@ -280,6 +294,15 @@ struct FSMCDriver {
#if STM32_USE_FSMC_PCCARD
FSMC_PCCard_TypeDef *pccard;
#endif
#if (defined(STM32F427xx) || defined(STM32F437xx) || \
defined(STM32F429xx) || defined(STM32F439xx))
#if STM32_SDRAM_USE_FSMC_SDRAM1
FSMC_SDRAM_TypeDef *sdram1;
#endif
#if STM32_SDRAM_USE_FSMC_SDRAM2
FSMC_SDRAM_TypeDef *sdram2;
#endif
#endif
};
/*===========================================================================*/
@ -304,7 +327,7 @@ extern "C" {
}
#endif
#endif /* HAL_USE_NAND || STM32_USE_FSMC_SRAM */
#endif /* HAL_USE_NAND || STM32_USE_FSMC_SRAM || STM32_USE_FSMC_SDRAM */
#endif /* _FSMC_H_ */

View File

@ -39,6 +39,17 @@
/* Driver local definitions. */
/*===========================================================================*/
#define SDCR2_DONTCARE_BITS (FMC_SDClock_Period_Mask | \
FMC_Read_Burst_Mask | \
FMC_ReadPipe_Delay_Mask)
#define SDTR2_DONTCARE_BITS (FMC_RowCycleDelay_Mask | FMC_RPDelay_Mask)
/*
* FMC SDCRx write protection mask
*/
#define SDCR_WriteProtection_RESET ((uint32_t)0x00007DFF)
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
@ -75,14 +86,14 @@ SDRAMDriver SDRAMD2;
*
* @notapi
*/
static void fsmcSdramInitSequence(uint32_t CommandTarget) {
static void fsmc_sdram_init_sequence(uint32_t command_target) {
uint32_t tmpreg;
/* Step 3 -----------------------------------------------------------------*/
/* Wait until the SDRAM controller is ready */
while (FMC_Bank5_6->SDSR & FMC_SDSR_BUSY);
/* Configure a clock configuration enable command */
FMC_Bank5_6->SDCMR = (uint32_t) FMC_Command_Mode_CLK_Enabled |
CommandTarget |
command_target |
((1 -1) << 5) | // FMC_AutoRefreshNumber = 1
(0 << 9); // FMC_ModeRegisterDefinition = 0
/* Step 4 -----------------------------------------------------------------*/
@ -93,7 +104,7 @@ static void fsmcSdramInitSequence(uint32_t CommandTarget) {
while (FMC_Bank5_6->SDSR & FMC_SDSR_BUSY);
/* Configure a PALL (precharge all) command */
FMC_Bank5_6->SDCMR = (uint32_t) FMC_Command_Mode_PALL |
CommandTarget |
command_target |
((1 -1) << 5) | // FMC_AutoRefreshNumber = 1
(0 << 9); // FMC_ModeRegisterDefinition = 0
/* Step 6 -----------------------------------------------------------------*/
@ -101,14 +112,14 @@ static void fsmcSdramInitSequence(uint32_t CommandTarget) {
while (FMC_Bank5_6->SDSR & FMC_SDSR_BUSY);
/* Configure a Auto-Refresh command: Send the first command */
FMC_Bank5_6->SDCMR = (uint32_t) FMC_Command_Mode_AutoRefresh |
CommandTarget |
command_target |
((4 -1) << 5) | // FMC_AutoRefreshNumber = 4
(0 << 9); // FMC_ModeRegisterDefinition = 0
/* Wait until the SDRAM controller is ready */
while (FMC_Bank5_6->SDSR & FMC_SDSR_BUSY);
/* Configure a Auto-Refresh command: Send the second command*/
FMC_Bank5_6->SDCMR = (uint32_t) FMC_Command_Mode_AutoRefresh |
CommandTarget |
command_target |
((4 -1) << 5) | // FMC_AutoRefreshNumber = 4
(0 << 9); // FMC_ModeRegisterDefinition = 0
/* Step 7 -----------------------------------------------------------------*/
@ -122,7 +133,7 @@ static void fsmcSdramInitSequence(uint32_t CommandTarget) {
FMC_SDCMR_MRD_WRITEBURST_MODE_SINGLE;
/* Send the command */
FMC_Bank5_6->SDCMR = (uint32_t) FMC_Command_Mode_LoadMode |
CommandTarget |
command_target |
((1 -1) << 5) | // FMC_AutoRefreshNumber = 1
(tmpreg << 9);
/* Step 8 -----------------------------------------------------------------*/
@ -152,8 +163,6 @@ static void fsmcSdramInitSequence(uint32_t CommandTarget) {
/**
* @brief Low level SDRAM driver initialization.
*
* @notapi
*/
void fsmcSdramInit(void) {
@ -168,7 +177,6 @@ void fsmcSdramInit(void) {
SDRAMD2.sdram = FSMCD1.sdram2;
SDRAMD2.state = SDRAM_STOP;
#endif /* STM32_SDRAM_USE_FSMC_SDRAM2 */
}
/**
@ -176,13 +184,7 @@ void fsmcSdramInit(void) {
*
* @param[in] sdramp pointer to the @p SDRAMDriver object
* @param[in] cfgp pointer to the @p SDRAMConfig object
*
* @notapi
*/
#define SDCR2_DONTCARE_BITS (FMC_SDClock_Period_Mask | \
FMC_Read_Burst_Mask | \
FMC_ReadPipe_Delay_Mask)
#define SDTR2_DONTCARE_BITS (FMC_RowCycleDelay_Mask | FMC_RPDelay_Mask)
void fsmcSdramStart(SDRAMDriver *sdramp, const SDRAMConfig *cfgp) {
if (FSMCD1.state == FSMC_STOP)
@ -196,19 +198,19 @@ void fsmcSdramStart(SDRAMDriver *sdramp, const SDRAMConfig *cfgp) {
if (sdramp->sdram == (FSMC_SDRAM_TypeDef *)FSMC_Bank5_R_BASE) {
sdramp->sdram->SDCR = cfgp->sdcr;
sdramp->sdram->SDTR = cfgp->sdtr;
fsmcSdramInitSequence(FMC_Command_Target_bank1);
} else { /* SDCR2 "don't care" bits configuration */
fsmc_sdram_init_sequence(FMC_Command_Target_bank1);
}
else { /* SDCR2 "don't care" bits configuration */
((FSMC_SDRAM_TypeDef *)FSMC_Bank5_R_BASE)->SDCR =
cfgp->sdcr & SDCR2_DONTCARE_BITS;
sdramp->sdram->SDCR = cfgp->sdcr;
((FSMC_SDRAM_TypeDef *)FSMC_Bank5_R_BASE)->SDTR =
cfgp->sdtr & SDTR2_DONTCARE_BITS;
sdramp->sdram->SDTR = cfgp->sdtr;
fsmcSdramInitSequence(FMC_Command_Target_bank2);
fsmc_sdram_init_sequence(FMC_Command_Target_bank2);
}
sdramp->state = SDRAM_READY;
}
}
/**
@ -225,7 +227,6 @@ void fsmcSdramStop(SDRAMDriver *sdramp) {
}
}
/**
* @brief Wait until the SDRAM controller is ready.
*
@ -244,18 +245,14 @@ void fsmcSdram_WaitReady(void) {
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
/* FMC SDCRx write protection Mask*/
#define SDCR_WriteProtection_RESET ((uint32_t)0x00007DFF)
void fsmcSdram_WriteProtectionConfig(SDRAMDriver *sdramp, int State) {
void fsmcSdram_WriteProtectionConfig(SDRAMDriver *sdramp, int state) {
if (State)
if (state)
sdramp->sdram->SDCR |= FMC_Write_Protection_Enable;
else
sdramp->sdram->SDCR &= SDCR_WriteProtection_RESET;
}
#endif /* STM32_USE_FSMC_SDRAM */
#endif /* STM32F427xx / STM32F429xx / STM32F437xx / STM32F439xx */

View File

@ -40,7 +40,8 @@
/* Driver constants. */
/*===========================================================================*/
/** @defgroup FMC_ColumnBits_Number
/**
* @defgroup FMC_ColumnBits_Number
* @{
*/
#define FMC_ColumnBits_Number_8b ((uint32_t)0x00000000)
@ -58,7 +59,8 @@
* @}
*/
/** @defgroup FMC_RowBits_Number
/**
* @defgroup FMC_RowBits_Number
* @{
*/
#define FMC_RowBits_Number_11b ((uint32_t)0x00000000)
@ -74,7 +76,8 @@
* @}
*/
/** @defgroup FMC_SDMemory_Data_Width
/**
* @defgroup FMC_SDMemory_Data_Width
* @{
*/
#define FMC_SDMemory_Width_8b ((uint32_t)0x00000000)
@ -90,7 +93,8 @@
* @}
*/
/** @defgroup FMC_InternalBank_Number
/**
* @defgroup FMC_InternalBank_Number
* @{
*/
#define FMC_InternalBank_Number_2 ((uint32_t)0x00000000)
@ -105,7 +109,8 @@
*/
/** @defgroup FMC_CAS_Latency
/**
* @defgroup FMC_CAS_Latency
* @{
*/
#define FMC_CAS_Latency_1 ((uint32_t)0x00000080)
@ -121,7 +126,8 @@
* @}
*/
/** @defgroup FMC_Write_Protection
/**
* @defgroup FMC_Write_Protection
* @{
*/
#define FMC_Write_Protection_Disable ((uint32_t)0x00000000)
@ -136,7 +142,8 @@
*/
/** @defgroup FMC_SDClock_Period
/**
* @defgroup FMC_SDClock_Period
* @{
*/
#define FMC_SDClock_Disable ((uint32_t)0x00000000)
@ -153,7 +160,8 @@
* @}
*/
/** @defgroup FMC_Read_Burst
/**
* @defgroup FMC_Read_Burst
* @{
*/
#define FMC_Read_Burst_Disable ((uint32_t)0x00000000)
@ -168,7 +176,8 @@
* @}
*/
/** @defgroup FMC_ReadPipe_Delay
/**
* @defgroup FMC_ReadPipe_Delay
* @{
*/
#define FMC_ReadPipe_Delay_0 ((uint32_t)0x00000000)
@ -185,7 +194,8 @@
* @}
*/
/** @defgroup FMC_Command_Mode
/**
* @defgroup FMC_Command_Mode
* @{
*/
#define FMC_Command_Mode_normal ((uint32_t)0x00000000)
@ -209,7 +219,8 @@
* @}
*/
/** @defgroup FMC_Command_Target
/**
* @defgroup FMC_Command_Target
* @{
*/
#define FMC_Command_Target_bank2 ((uint32_t)0x00000008)
@ -225,7 +236,8 @@
* @}
*/
/** @defgroup FMC_AutoRefresh_Number
/**
* @defgroup FMC_AutoRefresh_Number
* @{
*/
#define IS_FMC_AUTOREFRESH_NUMBER(NUMBER) (((NUMBER) > 0) && ((NUMBER) <= 16))
@ -234,7 +246,8 @@
* @}
*/
/** @defgroup FMC_ModeRegister_Definition
/**
* @defgroup FMC_ModeRegister_Definition
* @{
*/
#define IS_FMC_MODE_REGISTER(CONTENT) ((CONTENT) <= 8191)
@ -368,7 +381,7 @@ extern "C" {
void fsmcSdramStart(SDRAMDriver *sdramp, const SDRAMConfig *cfgp);
void fsmcSdramStop(SDRAMDriver *sdramp);
void fsmcSdram_WaitReady(void);
void fsmcSdram_WriteProtectionConfig(SDRAMDriver *sdramp, int State);
void fsmcSdram_WriteProtectionConfig(SDRAMDriver *sdramp, int state);
#ifdef __cplusplus
}
#endif

View File

@ -2,6 +2,7 @@ include ${CHIBIOS}/os/hal/ports/STM32/STM32F4xx/platform.mk
PLATFORMSRC += ${CHIBIOS}/community/os/hal/ports/STM32/LLD/FSMCv1/fsmc.c \
${CHIBIOS}/community/os/hal/ports/STM32/LLD/FSMCv1/nand_lld.c \
${CHIBIOS}/community/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram.c
${CHIBIOS}/community/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram.c \
${CHIBIOS}/community/os/hal/src/fsmc_sdram.c
PLATFORMINC += ${CHIBIOS}/community/os/hal/ports/STM32/LLD/FSMCv1

View File

@ -27,7 +27,7 @@
<link>
<name>os</name>
<type>2</type>
<locationURI>CHIBIOS/os</locationURI>
<locationURI>CHIBIOS</locationURI>
</link>
</linkedResources>
</projectDescription>

View File

@ -82,7 +82,7 @@ PROJECT = ch
# Imported source files and paths
CHIBIOS = ../../../../..
include $(CHIBIOS)/community/os/hal/hal.mk
include $(CHIBIOS)/community/os/hal/boards/NONSTANDARD_STM32F4_BARTHESS2/board.mk
include $(CHIBIOS)/os/hal/boards/ST_STM32F429I_DISCOVERY/board.mk
include $(CHIBIOS)/community/os/hal/ports/STM32/STM32F4xx/platform.mk
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
include $(CHIBIOS)/os/rt/rt.mk

View File

@ -49,7 +49,6 @@ write memtest function using ideas from http://www.memtest86.com/technical.htm
******************************************************************************
*/
/*
/*
******************************************************************************
* GLOBAL VARIABLES
@ -81,7 +80,6 @@ static const SDRAMConfig sdram_cfg = {
(2 << 24) // FMC_RCDDelay = 2 (TRCD: 20ns => 2x11.11ns)
};
/* benchmarking results in MiB/S */
double memset_speed_ext;
double memset_speed_int;

View File

@ -41,7 +41,7 @@
#define STM32_CLOCK48_REQUIRED TRUE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSE
#define STM32_PLLM_VALUE 12
#define STM32_PLLM_VALUE 8
#define STM32_PLLN_VALUE 336
#define STM32_PLLP_VALUE 2
#define STM32_PLLQ_VALUE 7