STM32使用fsmc控制NOR flash 例程(3)
- UID
- 1029342
- 性别
- 男
|
STM32使用fsmc控制NOR flash 例程(3)
void FSMC_NOR_Init(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
/*-- GPIO Configuration ------------------------------------------------------*/
/* NOR Data lines configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_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_Init(GPIOE, &GPIO_InitStructure);
/* NOR Address lines configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 |
GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* NOE and NWE configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* NE2 configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOG, &GPIO_InitStructure);
/*-- FSMC Configuration ----------------------------------------------------*/
p.FSMC_AddressSetupTime = 0x05; /*ADDSET 地址建立时间*/
p.FSMC_AddressHoldTime = 0x00; /*ADDHOLD 地址保持时间*/
p.FSMC_DataSetupTime = 0x07; /*DATAST 数据建立时间*/
p.FSMC_BusTurnAroundDuration = 0x00; /*BUSTURN 总线返转时间*/
p.FSMC_CLKDivision = 0x00; /*CLKDIV 时钟分频*/
p.FSMC_DataLatency = 0x00; /*DATLAT 数据保持时间*/
p.FSMC_AccessMode = FSMC_AccessMode_B; /*访问模式*/
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; // NOR/SRAM的存储块,共4个选项
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; // 是都选择地址和数据复用数据线
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR; // 连接到相应存储块的外部存储器类型
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; //存储器数据总线宽度
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; // 使能或关闭同步NOR闪存存储器的突发访问模式
//设置是否使用迸发访问模式(应该就是连续读写模式吧)
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; // 设置WAIT信号的有效电平
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; // 设置是否使用环回模式
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; // 设置WAIT信号有效时机
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; // 设定是否使能写操作
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; // 设定是否使用WAIT信号
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; // 使能或关闭扩展模式,扩展模式用于访问具有不同读写操作时序的存储器
// 设定是否使用单独的写时序
FSMC_NORSRAMInitStructure.FSMC_AsyncWait = FSMC_AsyncWait_Disable; // 设定是否使用异步等待信号
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; // 设定是否使用迸发写模式
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; // 设定读写时序
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; //
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //
/* Enable FSMC Bank1_NOR Bank */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); //
}
/******************************************************************************
* Function Name : FSMC_NOR_ReadID
* Description : Reads NOR memory's Manufacturer and Device Code.
* Input : - NOR_ID: pointer to a NOR_IDTypeDef structure which will hold
* the Manufacturer and Device Code.
* Output : None
* Return : None
*******************************************************************************/
void FSMC_NOR_ReadID(NOR_IDTypeDef* NOR_ID)
{
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x0090);
NOR_ID->Manufacturer_Code = *(vu16 *) ADDR_SHIFT(0x0000);
NOR_ID->Device_Code1 = *(vu16 *) ADDR_SHIFT(0x0001);
NOR_ID->Device_Code2 = *(vu16 *) ADDR_SHIFT(0x000E);
NOR_ID->Device_Code3 = *(vu16 *) ADDR_SHIFT(0x000F);
}
/*******************************************************************************
* Function Name : FSMC_NOR_EraseBlock
* Description : Erases the specified Nor memory block.
* Input : - BlockAddr: address of the block to erase.
* Output : None
* Return : NOR_Status:The returned value can be: NOR_SUCCESS, NOR_ERROR
* or NOR_TIMEOUT
*******************************************************************************/
NOR_Status FSMC_NOR_EraseBlock(u32 BlockAddr)
{
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x0080);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
NOR_WRITE((Bank1_NOR2_ADDR + BlockAddr), 0x30);
return (FSMC_NOR_GetStatus(BlockErase_Timeout));
} |
|
|
|
|
|