红牛板Flash驱动AT45D161D--擦除操作

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值