/******************************************************************************
* 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));
} |