/**
* @brief Erases the all the sectors .
* @param SectorAddr: address of the sector to erase.
* @retval None
*/
void Ext_Flash_ChipErase(void)
{
/* Select the FLASH: Chip Select low */
SPI_FLASH_CS_LOW();
/* Send Chipset Erase instruction : first command */
Ext_Flash_SendByte(CMD_CHIP_ERASE_FIRST_CMD);
/* Send Chipset Erase instruction : second command */
Ext_Flash_SendByte(CMD_CHIP_ERASE_SECOND_CMD);
/* Send Chipset Erase instruction : command */
Ext_Flash_SendByte(CMD_CHIP_ERASE_THIRD_CMD);
/* Send Chipset Erase instruction : first command */
Ext_Flash_SendByte(CMD_CHIP_ERASE_FOUR_CMD);
/* Deselect the FLASH: Chip Select high */
SPI_FLASH_CS_HIGH();
/* Wait the end of Flash writing */
Ext_Flash_WaitForWriteEnd();
}
/**
* @brief Erases the specified FLASH sector.
* @param SectorAddr: address of the sector to erase. SectorAddr : 1~15
* @retval None
*/
void Ext_Flash_SectorErase(U08 u8SectorNo)
{
/* Select the FLASH: Chip Select low */
SPI_FLASH_CS_LOW();
/* Send Sector Erase instruction */
Ext_Flash_SendByte(CMD_SECTOR_ERASE);
/*three address bytes*/
/*2 bits(do't care bits) + 4 bits( address bits) + 18 bits ( do't care bits)*/
Ext_Flash_SendByte(u8SectorNo << 2); /* 2 bits don't care + 4 bits address bits + 2 don't care bits , move left 2 bits */
Ext_Flash_SendByte(DUMMY_WRITE_BYTE); /* 8 bits don't care */
Ext_Flash_SendByte(DUMMY_WRITE_BYTE); /* 8 bits do't care */
/* Deselect the FLASH: Chip Select high */
SPI_FLASH_CS_HIGH();
/* Wait the end of Flash writing */
Ext_Flash_WaitForWriteEnd();
}
/**
* @brief Erases the sector 0a.
* @param SectorAddr: address of the sector to erase.
* @retval None
*/
void Ext_Flash_SectorEraseA(void)
{
/* Select the FLASH: Chip Select low */
SPI_FLASH_CS_LOW();
/* Send Sector Erase instruction */
Ext_Flash_SendByte(CMD_SECTOR_ERASE);
/*three address bytes*/
/*2 bits(do't care bits) + 9 bits( address bits) + 13 bits ( do't care bits)*/
Ext_Flash_SendByte(DUMMY_WRITE_BYTE);
Ext_Flash_SendByte(DUMMY_WRITE_BYTE);
Ext_Flash_SendByte(DUMMY_WRITE_BYTE);
/* Deselect the FLASH: Chip Select high */
SPI_FLASH_CS_HIGH();
/* Wait the end of Flash writing */
Ext_Flash_WaitForWriteEnd();
}
/**
* @brief Erases the sector 0b.
* @param SectorAddr: address of the sector to erase.
* @retval None
*/
void Ext_Flash_SectorEraseB(void)
{
/* Select the FLASH: Chip Select low */
SPI_FLASH_CS_LOW();
/* Send Sector Erase instruction */
Ext_Flash_SendByte(CMD_SECTOR_ERASE);
/*three address bytes*/
/*2 bits(do't care bits) + 9 bits( address bits) + 13 bits ( do't care bits)*/
Ext_Flash_SendByte(DUMMY_WRITE_BYTE);
Ext_Flash_SendByte(0x20);
Ext_Flash_SendByte(DUMMY_WRITE_BYTE);
/* Deselect the FLASH: Chip Select high */
SPI_FLASH_CS_HIGH();
/* Wait the end of Flash writing */
Ext_Flash_WaitForWriteEnd();
}
/**
* @brief Erases the specified FLASH block , a block = 8 pages
* @param BlockAddr: address of the block to erase. BlockAddr : 0~511
* @retval None
*/
void Ext_Flash_BlockErase(U16 u16BlockAddr)
{
/* Select the FLASH: Chip Select low */
SPI_FLASH_CS_LOW();
/* Send block Erase instruction */
Ext_Flash_SendByte(CMD_BLOCK_ERASE);
/* three address bytes , MSB send first */
/*2 bits(do't care bits) + 9 bits( address bits) + 13 bits ( do't care bits)*/
Ext_Flash_SendByte(u16BlockAddr >> 3); /* 2 bits don't care + 6 bits address bits , get rid off low 3 bits of block addr */
Ext_Flash_SendByte(u16BlockAddr << 5); /* low 3 bits of block address + 5 bits do't care , other block addr bits move left 5 bits */
Ext_Flash_SendByte(DUMMY_WRITE_BYTE); /* 8 bits do't care */
/* Deselect the FLASH: Chip Select high */
SPI_FLASH_CS_HIGH();
/* Wait the end of Flash writing */
Ext_Flash_WaitForWriteEnd();
}
/**
* @brief Erases the specified FLASH page.
* @param u16PageNo: page number to erase. PageAddr : 0~4096
* @retval None
*/
void Ext_Flash_PageErase(U16 u16PageNo)
{
/* Select the FLASH: Chip Select low */
SPI_FLASH_CS_LOW();
/* Send Sector Erase instruction */
Ext_Flash_SendByte(CMD_PAGE_ERASE);
/* three address bytes , MSB send first */
/*2 bits(do't care bits) + 12 bits( address bits) + 10 bits ( do't care bits)*/
Ext_Flash_SendByte(u16PageNo >> 6); /* 2 bits don't care + 6 bits address bits , get rid off low 6 bits of page addr */
Ext_Flash_SendByte(u16PageNo << 2); /* Low 6 bits of page address + 2 bits do't care , other page addr bits move left 2 bits*/
Ext_Flash_SendByte(DUMMY_WRITE_BYTE); /* 8 bits do't care */
/* Deselect the FLASH: Chip Select high */
SPI_FLASH_CS_HIGH();
/* Wait the end of Flash writing */
Ext_Flash_WaitForWriteEnd();
}
红牛板Flash驱动AT45D161D--擦除操作
最新推荐文章于 2022-04-09 20:28:00 发布