首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

STM32-移植FATFS的NANDFLASH驱动(5)

STM32-移植FATFS的NANDFLASH驱动(5)

  • /**
  •    * @brief  This routine erase complete block from NAND FLASH
  •    * @param  PageAddress: Any address into block to be erased
  •    * @retval :New status of the NAND operation. This parameter can be:
  •    *              - NAND_TIMEOUT_ERROR: when the previous operation generate
  •    *                a Timeout error
  •    *              - NAND_READY: when memory is ready for the next operation
  •    */

  • uint32_t FSMC_NAND_EraseBlock(uint32_t PageAddress)  
  • {  
  •   uint32_t data = 0xff, status = NAND_ERROR;  

  •    *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_ERASE0;  

  •    *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(PageAddress);  
  •    *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_4th_CYCLE(PageAddress);  

  •    *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_ERASE1;  

  •    while( GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_6) == 0 );  

  •    /* Read status operation ------------------------------------ */
  •    FSMC_NAND_GetStatus();  

  •    data = *(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA);  

  •    if(!(data&0x1)) status = NAND_READY;  

  •    return (status);  
  • }  

  • /**
  •    * @brief  This routine reset the NAND FLASH
  •    * @param  None
  •    * @retval :NAND_READY
  •    */

  • uint32_t FSMC_NAND_Reset(void)  
  • {  
  •    *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_RESET;  

  •    return (NAND_READY);  
  • }  

  • /**
  •    * @brief  Get the NAND operation status
  •    * @param  None
  •    * @retval :New status of the NAND operation. This parameter can be:
  •    *              - NAND_TIMEOUT_ERROR: when the previous operation generate
  •    *                a Timeout error
  •    *              - NAND_READY: when memory is ready for the next operation   
  •    */


  • uint32_t FSMC_NAND_GetStatus(void)  
  • {  
  •    uint32_t timeout = 0x1000000, status = NAND_READY;  

  •    status = FSMC_NAND_ReadStatus();  

  •    /* Wait for a NAND operation to complete or a TIMEOUT to occur */
  •    while ((status != NAND_READY) &&( timeout != 0x00))  
  •    {  
  •       status = FSMC_NAND_ReadStatus();  
  •       timeout --;      
  •    }  

  •    if(timeout == 0x00)  
  •    {           
  •      status =  NAND_TIMEOUT_ERROR;      
  •    }  

  •    /* Return the operation status */
  •    return (status);      
  • }  

  • /**
  •    * @brief  Reads the NAND memory status using the Read status command
  •    * @param  None
  •    * @retval :The status of the NAND memory. This parameter can be:
  •    *              - NAND_BUSY: when memory is busy
  •    *              - NAND_READY: when memory is ready for the next operation   
  •    *              - NAND_ERROR: when the previous operation gererates error     
  •    */

  • uint32_t FSMC_NAND_ReadStatus(void)  
  • {  
  •    uint32_t data = 0x00, status = NAND_BUSY;  

  •    /* Read status operation ------------------------------------ */
  •    *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_STATUS;  
  •    data = *(__IO uint8_t *)(Bank_NAND_ADDR);  

  •    if((data & NAND_ERROR) == NAND_ERROR)  
  •    {  
  •      status = NAND_ERROR;  
  •    }  
  •    else
    if((data & NAND_READY) == NAND_READY)  
  •    {  
  •      status = NAND_READY;  
  •    }  
  •    else
  •    {  
  •      status = NAND_BUSY;  
  •    }  

  •    return (status);  
  • }  
继承事业,薪火相传
返回列表