I used STM32F407 mcu with external SRAM memory connected on FSMC.
I initialized FSMC in board.c file before the C enviroment setup:
Code: Select all
void __early_init(void)
{
stm32_clock_init();
#ifdef FSMC_USED
// CLOCK the peripheral
#if defined(STM32F10X_HD)
RCC->AHBENR |= RCC_AHBENR_FSMCEN;
#elif defined(STM32F4XX)
RCC->AHB3ENR |= RCC_AHB3ENR_FSMCEN;
#else
#error "Not supported device!"
#endif
// SETUP FSMC to work correctly
FSMC_Bank1->BTCR[0] = FSMC_BCR1_WREN | FSMC_BCR1_MWID_0 | FSMC_BCR1_MBKEN; // FSMC_BCR1 register
FSMC_Bank1->BTCR[1] = FSMC_BTR1_DATAST_1 | FSMC_BTR1_DATAST_0; // FSMC_BTR1 register
#endif
}
But in hal_lld.c the FSMC resets:
Code: Select all
file 'os\hal\platforms\STM32F4xx\hal_lld.c'
...
89 /**
90 * @brief Low level HAL driver initialization.
91 *
92 * @notapi
93 */
94 void hal_lld_init(void) {
95
96 /* Reset of all peripherals. AHB3 is not reseted because it could have
97 been initialized in the board initialization file (board.c).*/
98 rccResetAHB1(~0);
98 rccResetAHB2(~0);
99 rccResetAHB3(~0);
100 rccResetAPB1(~RCC_APB1RSTR_PWRRST);
101 rccResetAPB2(~0);
The comments says that AHB3 not resets (FSMC on it) but code do that. Need to remove 'rccResetAHB3(~0);' or mask FSMC to not reset.
p.s. On STM32F103 there is no such problem.