- UID
- 1029342
- 性别
- 男
|
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));
}
/******************************************************************************* * Function Name : FSMC_NOR_EraseChip
* Description : Erases the entire chip.
* Input : None
* Output : None
* Return : NOR_Status:The returned value can be: NOR_SUCCESS, NOR_ERROR
* or NOR_TIMEOUT
*******************************************************************************/ NOR_Status FSMC_NOR_EraseChip(void)
{
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(ADDR_SHIFT(0x05555), 0x0010);
return (FSMC_NOR_GetStatus(ChipErase_Timeout));
}
/****************************************************************************** * Function Name : FSMC_NOR_WriteHalfWord
* Description : Writes a half-word to the NOR memory.
* Input : - WriteAddr : NOR memory internal address to write to. * - Data : Data to write.
* Output : None
* Return : NOR_Status:The returned value can be: NOR_SUCCESS, NOR_ERROR
* or NOR_TIMEOUT
*******************************************************************************/ NOR_Status FSMC_NOR_WriteHalfWord(u32 WriteAddr, u16 Data) {
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00AA);
NOR_WRITE(ADDR_SHIFT(0x02AAA), 0x0055);
NOR_WRITE(ADDR_SHIFT(0x05555), 0x00A0);
NOR_WRITE((Bank1_NOR2_ADDR + WriteAddr), Data);
return (FSMC_NOR_GetStatus(Program_Timeout));
}
/******************************************************************************* * Function Name : FSMC_NOR_WriteBuffer
* Description : Writes a half-word buffer to the FSMC NOR memory.
* Input : - pBuffer : pointer to buffer.
* - WriteAddr : NOR memory internal address from which the data * will be written.
* - NumHalfwordToWrite : number of Half words to write. * Output : None
* Return : NOR_Status:The returned value can be: NOR_SUCCESS, NOR_ERROR
* or NOR_TIMEOUT
*******************************************************************************/ NOR_Status FSMC_NOR_WriteBuffer(u16* pBuffer, u32 WriteAddr, u32 NumHalfwordToWrite)
{
NOR_Status status = NOR_ONGOING;
do
{
/* Transfer data to the memory */
status = FSMC_NOR_WriteHalfWord(WriteAddr, *pBuffer++);
WriteAddr = WriteAddr + 2;
NumHalfwordToWrite--;
}
while((status == NOR_SUCCESS) && (NumHalfwordToWrite != 0));
return (status);
} |
|