Skip to content

Commit

Permalink
Updating FSMC driver (SRAM part)
Browse files Browse the repository at this point in the history
  • Loading branch information
fpoussin committed Oct 29, 2019
1 parent 97b7064 commit 90f32c3
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 193 deletions.
32 changes: 16 additions & 16 deletions os/hal/include/fsmc/sram.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,32 @@
* @brief SRAM driver enable switch.
* @details If set to @p TRUE the support for SRAM1 is included.
*/
#if !defined(STM32_SRAM_USE_FSMC_SRAM1) || defined(__DOXYGEN__)
#define STM32_SRAM_USE_FSMC_SRAM1 FALSE
#if !defined(STM32_FSMC_USE_SRAM1) || defined(__DOXYGEN__)
#define STM32_FSMC_USE_SRAM1 FALSE
#endif

/**
* @brief SRAM driver enable switch.
* @details If set to @p TRUE the support for SRAM2 is included.
*/
#if !defined(STM32_SRAM_USE_FSMC_SRAM2) || defined(__DOXYGEN__)
#define STM32_SRAM_USE_FSMC_SRAM2 FALSE
#if !defined(STM32_FSMC_USE_SRAM2) || defined(__DOXYGEN__)
#define STM32_FSMC_USE_SRAM2 FALSE
#endif

/**
* @brief SRAM driver enable switch.
* @details If set to @p TRUE the support for SRAM3 is included.
*/
#if !defined(STM32_SRAM_USE_FSMC_SRAM3) || defined(__DOXYGEN__)
#define STM32_SRAM_USE_FSMC_SRAM3 FALSE
#if !defined(STM32_FSMC_USE_SRAM3) || defined(__DOXYGEN__)
#define STM32_FSMC_USE_SRAM3 FALSE
#endif

/**
* @brief SRAM driver enable switch.
* @details If set to @p TRUE the support for SRAM4 is included.
*/
#if !defined(STM32_SRAM_USE_FSMC_SRAM4) || defined(__DOXYGEN__)
#define STM32_SRAM_USE_FSMC_SRAM4 FALSE
#if !defined(STM32_FSMC_USE_SRAM4) || defined(__DOXYGEN__)
#define STM32_FSMC_USE_SRAM4 FALSE
#endif

/** @} */
Expand All @@ -77,13 +77,13 @@
/* Derived constants and error checks. */
/*===========================================================================*/

#if !STM32_SRAM_USE_FSMC_SRAM1 && !STM32_SRAM_USE_FSMC_SRAM2 && \
!STM32_SRAM_USE_FSMC_SRAM3 && !STM32_SRAM_USE_FSMC_SRAM4
#if !STM32_FSMC_USE_SRAM1 && !STM32_FSMC_USE_SRAM2 && \
!STM32_FSMC_USE_SRAM3 && !STM32_FSMC_USE_SRAM4
#error "SRAM driver activated but no SRAM peripheral assigned"
#endif

#if (STM32_SRAM_USE_FSMC_SRAM1 || STM32_SRAM_USE_FSMC_SRAM2 || \
STM32_SRAM_USE_FSMC_SRAM3 || STM32_SRAM_USE_FSMC_SRAM4) && !STM32_HAS_FSMC
#if (STM32_FSMC_USE_SRAM1 || STM32_FSMC_USE_SRAM2 || \
STM32_FSMC_USE_SRAM3 || STM32_FSMC_USE_SRAM4) && !STM32_HAS_FSMC
#error "FSMC not present in the selected device"
#endif

Expand Down Expand Up @@ -137,19 +137,19 @@ struct SRAMDriver {
/* External declarations. */
/*===========================================================================*/

#if STM32_SRAM_USE_FSMC_SRAM1 && !defined(__DOXYGEN__)
#if STM32_FSMC_USE_SRAM1 && !defined(__DOXYGEN__)
extern SRAMDriver SRAMD1;
#endif

#if STM32_SRAM_USE_FSMC_SRAM2 && !defined(__DOXYGEN__)
#if STM32_FSMC_USE_SRAM2 && !defined(__DOXYGEN__)
extern SRAMDriver SRAMD2;
#endif

#if STM32_SRAM_USE_FSMC_SRAM3 && !defined(__DOXYGEN__)
#if STM32_FSMC_USE_SRAM3 && !defined(__DOXYGEN__)
extern SRAMDriver SRAMD3;
#endif

#if STM32_SRAM_USE_FSMC_SRAM4 && !defined(__DOXYGEN__)
#if STM32_FSMC_USE_SRAM4 && !defined(__DOXYGEN__)
extern SRAMDriver SRAMD4;
#endif

Expand Down
12 changes: 6 additions & 6 deletions os/hal/include/hal_fsmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,25 +327,25 @@ struct FSMCDriver {
/* End of the mandatory fields.*/

#if HAL_USE_FSMC_SRAM
#if STM32_SRAM_USE_FSMC_SRAM1
#if STM32_FSMC_USE_SRAM1
FSMC_SRAM_NOR_TypeDef *sram1;
#endif
#if STM32_SRAM_USE_FSMC_SRAM2
#if STM32_FSMC_USE_SRAM2
FSMC_SRAM_NOR_TypeDef *sram2;
#endif
#if STM32_SRAM_USE_FSMC_SRAM3
#if STM32_FSMC_USE_SRAM3
FSMC_SRAM_NOR_TypeDef *sram3;
#endif
#if STM32_SRAM_USE_FSMC_SRAM4
#if STM32_FSMC_USE_SRAM4
FSMC_SRAM_NOR_TypeDef *sram4;
#endif
#endif

#if HAL_USE_FSMC_NAND
#if STM32_NAND_USE_FSMC_NAND1
#if STM32_FSMC_USE_NAND1
FSMC_NAND_TypeDef *nand1;
#endif
#if STM32_NAND_USE_FSMC_NAND2
#if STM32_FSMC_USE_NAND1
FSMC_NAND_TypeDef *nand2;
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion os/hal/ports/STM32/LLD/FSMCv1/hal_fsmc_sdram_lld.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
defined(STM32F769xx) || defined(STM32F777xx) || \
defined(STM32F779xx))

#if (STM32_FSMC_USE_SDRAM1 == TRUE) || (STM32_FSMC_USE_SDRAM2 == TRUE) || defined(__DOXYGEN__)
#if (HAL_USE_FSMC_SDRAM == TRUE) || defined(__DOXYGEN__)

#include "hal_fsmc_sdram_lld.h"

Expand Down
2 changes: 1 addition & 1 deletion os/hal/ports/STM32/LLD/FSMCv1/hal_fsmc_sdram_lld.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include "hal_fsmc.h"

#if (STM32_FSMC_USE_SDRAM1 == TRUE) || (STM32_FSMC_USE_SDRAM2 == TRUE) || defined(__DOXYGEN__)
#if (HAL_USE_FSMC_SDRAM == TRUE) || defined(__DOXYGEN__)

/*===========================================================================*/
/* Driver constants. */
Expand Down
61 changes: 10 additions & 51 deletions os/hal/ports/STM32/LLD/FSMCv1/hal_fsmc_sram_lld.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
* @{
*/
#include "hal.h"
#include "hal_fsmc_sram.h"

#if (STM32_USE_FSMC_SRAM == TRUE) || defined(__DOXYGEN__)
#if (HAL_USE_FSMC_SRAM == TRUE) || defined(__DOXYGEN__)

#include "hal_fsmc_sram_lld.h"

/*===========================================================================*/
/* Driver local definitions. */
Expand All @@ -36,28 +37,28 @@
/**
* @brief SRAM1 driver identifier.
*/
#if STM32_SRAM_USE_FSMC_SRAM1 || defined(__DOXYGEN__)
#if STM32_FSMC_USE_SRAM1 || defined(__DOXYGEN__)
SRAMDriver SRAMD1;
#endif

/**
* @brief SRAM2 driver identifier.
*/
#if STM32_SRAM_USE_FSMC_SRAM2 || defined(__DOXYGEN__)
#if STM32_FSMC_USE_SRAM2 || defined(__DOXYGEN__)
SRAMDriver SRAMD2;
#endif

/**
* @brief SRAM3 driver identifier.
*/
#if STM32_SRAM_USE_FSMC_SRAM3 || defined(__DOXYGEN__)
#if STM32_FSMC_USE_SRAM3 || defined(__DOXYGEN__)
SRAMDriver SRAMD3;
#endif

/**
* @brief SRAM4 driver identifier.
*/
#if STM32_SRAM_USE_FSMC_SRAM4 || defined(__DOXYGEN__)
#if STM32_FSMC_USE_SRAM4 || defined(__DOXYGEN__)
SRAMDriver SRAMD4;
#endif

Expand All @@ -81,36 +82,6 @@ SRAMDriver SRAMD4;
/* Driver exported functions. */
/*===========================================================================*/

/**
* @brief Low level SRAM driver initialization.
*
* @notapi
*/
void fsmcSramInit(void) {

fsmc_init();

#if STM32_SRAM_USE_FSMC_SRAM1
SRAMD1.sram = FSMCD1.sram1;
SRAMD1.state = SRAM_STOP;
#endif /* STM32_SRAM_USE_FSMC_SRAM1 */

#if STM32_SRAM_USE_FSMC_SRAM2
SRAMD2.sram = FSMCD1.sram2;
SRAMD2.state = SRAM_STOP;
#endif /* STM32_SRAM_USE_FSMC_SRAM2 */

#if STM32_SRAM_USE_FSMC_SRAM3
SRAMD3.sram = FSMCD1.sram3;
SRAMD3.state = SRAM_STOP;
#endif /* STM32_SRAM_USE_FSMC_SRAM3 */

#if STM32_SRAM_USE_FSMC_SRAM4
SRAMD4.sram = FSMCD1.sram4;
SRAMD4.state = SRAM_STOP;
#endif /* STM32_SRAM_USE_FSMC_SRAM4 */
}

/**
* @brief Configures and activates the SRAM peripheral.
*
Expand All @@ -119,20 +90,11 @@ void fsmcSramInit(void) {
*
* @notapi
*/
void fsmcSramStart(SRAMDriver *sramp, const SRAMConfig *cfgp) {

if (FSMCD1.state == FSMC_STOP)
fsmc_start(&FSMCD1);

osalDbgAssert((sramp->state == SRAM_STOP) || (sramp->state == SRAM_READY),
"invalid state");
void lld_sram_start(SRAMDriver *sramp, const SRAMConfig *cfgp) {

if (sramp->state == SRAM_STOP) {
sramp->sram->BTR = cfgp->btr;
sramp->sram->BWTR = cfgp->bwtr;
sramp->sram->BCR = cfgp->bcr | FSMC_BCR_MBKEN;
sramp->state = SRAM_READY;
}
}

/**
Expand All @@ -142,9 +104,8 @@ void fsmcSramStart(SRAMDriver *sramp, const SRAMConfig *cfgp) {
*
* @notapi
*/
void fsmcSramStop(SRAMDriver *sramp) {
void lld_sram_stop(SRAMDriver *sramp) {

if (sramp->state == SRAM_READY) {
uint32_t mask = FSMC_BCR_MBKEN;
#if (defined(STM32F427xx) || defined(STM32F437xx) || \
defined(STM32F429xx) || defined(STM32F439xx) || \
Expand All @@ -155,11 +116,9 @@ void fsmcSramStop(SRAMDriver *sramp) {
mask |= FSMC_BCR_CCLKEN;
#endif
sramp->sram->BCR &= ~mask;
sramp->state = SRAM_STOP;
}
}

#endif /* STM32_USE_FSMC_SRAM */
#endif /* STM32_FSMC_USE_SRAM */

/** @} */

Loading

0 comments on commit 90f32c3

Please sign in to comment.