STM32 HAL库 打开FSMC的函数时
时间: 2024-06-08 21:12:06 浏览: 149
在使用STM32 HAL库时打开FSMC的函数是`HAL_SRAM_Init()`,该函数用于初始化SRAM、PSRAM和NOR Flash存储器。在函数中,需要配置FSMC的时序、数据宽度、读写模式等参数,并且需要指定所要初始化的存储器类型。例如,如果要初始化NOR Flash存储器,则需要将FSMC_BANK1_NORSRAM1作为参数传递给函数。以下是一个示例代码片段:
```c
/* 使能FSMC时钟 */
__HAL_RCC_FSMC_CLK_ENABLE();
/* 初始化FSMC */
FSMC_NORSRAM_TimingTypeDef Timing;
FSMC_NORSRAM_InitTypeDef Init;
Init.NSBank = FSMC_NORSRAM_BANK1;
Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
Init.MemoryType = FSMC_MEMORY_TYPE_NOR;
Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
Init.WaitSignal = FSMC_WAIT_SIGNAL_ENABLE;
Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
Init.ContinuousClock = FSMC_CONTINUOUS_CLOCK_SYNC_ONLY;
Timing.AddressSetupTime = 0xF;
Timing.AddressHoldTime = 0xF;
Timing.DataSetupTime = 0xFF;
Timing.BusTurnAroundDuration = 0xF;
Timing.CLKDivision = 0xF;
Timing.DataLatency = 0xF;
Timing.AccessMode = FSMC_ACCESS_MODE_A;
HAL_SRAM_Init(&hsram1, &Init, &Timing);
```
在上面的示例代码中,`__HAL_RCC_FSMC_CLK_ENABLE()`函数用于使能FSMC时钟,然后通过配置`FSMC_NORSRAM_TimingTypeDef`和`FSMC_NORSRAM_InitTypeDef`结构体中的参数来初始化FSMC。最后,调用`HAL_SRAM_Init()`函数来初始化SRAM、PSRAM或NOR Flash存储器。
阅读全文