代码如下,在初始化FSMC的时候,进入函数HAL_SRAM_Init中的FSMC_NORSRAM_Extended_
timing_Init函数中,调用MODIFY_REG对BWTR进行写的时候就跳到了HardFault_Handler,不知道有哪个地方配置错了,头一次整FSMC,请大神指点。
void LCD_IO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__GPIOB_CLK_ENABLE();
__GPIOD_CLK_ENABLE();
__GPIOE_CLK_ENABLE();
__GPIOG_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_0; //background lit
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 |
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_14 | GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 |
GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
}
void LCD_FSMC_Init()
{
SRAM_HandleTypeDef SramHandle;
FSMC_NORSRAM_TimingTypeDef SRAM_Timing;
FSMC_NORSRAM_TimingTypeDef SRAM_ExtTiming;
SramHandle.Instance =FSMC_NORSRAM_DEVICE;
__FSMC_CLK_ENABLE();
SramHandle.Init.AsynchronousWait=FSMC_ASYNCHRONOUS_WAIT_DISABLE;
SramHandle.Init.BurstAccessMode=FSMC_BURST_ACCESS_MODE_DISABLE;
SramHandle.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
SramHandle.Init.ExtendedMode=FSMC_EXTENDED_MODE_ENABLE;
SramHandle.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
SramHandle.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
SramHandle.Init.NSBank = FSMC_NORSRAM_BANK4;
SramHandle.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
SramHandle.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
SramHandle.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
SramHandle.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
SramHandle.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
SramHandle.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
SRAM_Timing.AccessMode= FSMC_ACCESS_MODE_A;
SRAM_Timing.AddressHoldTime = 0x00;
SRAM_Timing.AddressSetupTime = 0x01;
SRAM_Timing.BusTurnAroundDuration = 0x00;
SRAM_Timing.CLKDivision = 0x00;
SRAM_Timing.DataLatency = 0x00;
SRAM_Timing.DataSetupTime = 0x0f;
SRAM_ExtTiming.AccessMode = FSMC_ACCESS_MODE_A;
SRAM_ExtTiming.AddressHoldTime = 0x00;
SRAM_ExtTiming.AddressSetupTime = 0x00;
SRAM_ExtTiming.BusTurnAroundDuration = 0x00;
SRAM_ExtTiming.CLKDivision = 0x00;
SRAM_ExtTiming.DataLatency = 0x00;
SRAM_ExtTiming.DataSetupTime = 0x03;
HAL_SRAM_Init(&SramHandle, &SRAM_Timing, &SRAM_ExtTiming);
}
void LCD_Init(void)
{
LCD_IO_Init();
LCD_FSMC_Init();
}
一周热门 更多>