[华大MCU] 请问华大官方关于HC32F460KCTA使用4线制SPIflash移植fatfs文件系统问题

[复制链接]
1180|1
 楼主| nczywq 发表于 2022-10-19 09:50 | 显示全部楼层 |阅读模式
当前遇到的问题是,直接调用低层函数读写数据是正常的,由于读写无法共存,所有读数据,我采用了复制的方式,没有采用直接指针. 我使用fatfs文件系统后,格式化正常,读正常,就是只要一新建文件,保存,当时是没有报错,但是重启板子后,挂载falsh时,就会提示没有文件系统,就是写文件时,把文件系统给写坏了,找了很久原因,希望能得到华大官方的帮助,谢谢,关键代码如下
  1. #ifndef W25QXX_H
  2. #define W25QXX_H

  3. #include "qspi.h"

  4. /**
  5. *******************************************************************************
  6. ** \defgroup W25QXXGroup W25Q64 SPI NOR Flash driver
  7. **
  8. ******************************************************************************/
  9. //@{

  10. /*******************************************************************************
  11. * Global type definitions ('typedef')
  12. ******************************************************************************/

  13. /*****************************************************************************/
  14. /* Global pre-processor symbols/macros ('define')                            */
  15. /*****************************************************************************/
  16. /* W25QXX Flash ID */
  17. #define W25Q80  0XEF13u
  18. #define W25Q16  0XEF14u
  19. #define W25Q32  0XEF15u
  20. #define W25Q64  0XEF16u
  21. #define W25Q128 0XEF17u

  22. /* W25QXX Command list */
  23. #define W25X_WriteEnable        0x06u
  24. #define W25X_WriteDisable       0x04u
  25. #define W25X_ReadStatusReg      0x05u
  26. #define W25X_WriteStatusReg     0x01u
  27. #define W25X_ReadData           0x03u
  28. #define W25X_FastReadData       0x0Bu
  29. #define W25X_FastReadDual       0x3Bu
  30. #define W25X_PageProgram        0x02u
  31. #define W25X_BlockErase         0xD8u
  32. #define W25X_SectorErase        0x20u
  33. #define W25X_ChipErase          0xC7u
  34. #define W25X_PowerDown          0xB9u
  35. #define W25X_ReleasePowerDown   0xABu
  36. #define W25X_DeviceID           0xABu
  37. #define W25X_ManufactDeviceID   0x90u
  38. #define W25X_JedecDeviceID      0x9Fu

  39. /*******************************************************************************
  40. * Global variable definitions ('extern')
  41. ******************************************************************************/
  42. extern uint16_t W25QXX_TYPE;

  43. /*******************************************************************************
  44. * Global function prototypes (definition in C source)
  45. ******************************************************************************/
  46. int W25QXX_Init(void);
  47. int W25QXX_Read(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
  48. int W25QXX_Write(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);

  49. #endif
  1. #include "w25qxx.h"
  2. #include "string.h"

  3. uint16_t W25QXX_TYPE = W25Q64;
  4. uint8_t W25QXX_BUFFER[4096];

  5. /**
  6. *******************************************************************************
  7. ** \brief W25QXX IO initialize
  8. **
  9. ** \param  None
  10. **
  11. ** \retval int
  12. **
  13. ******************************************************************************/
  14. int W25QXX_Init(void)
  15. {
  16.         int result =  QspiFlash_Init();
  17.         if (result == 0) {
  18.         //        W25QXX_TYPE = W25QXX_ReadID();
  19.         }
  20.         return result;
  21. }


  22. /**
  23. *******************************************************************************
  24. ** \brief W25QXX read flash content
  25. **
  26. ** \param [in] ReadAddr                Address to be read
  27. ** \param [in] NumByteToRead           Number to be read, (MAX. 65535)
  28. ** \param [out] pBuffer                Read data buffer
  29. **
  30. ** \retval Read result
  31. **
  32. ******************************************************************************/
  33. int W25QXX_Read(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead)
  34. {
  35.         while(flashnoreading){};
  36.     stc_qspi_comm_protocol_t stcQspiCommProtocol;
  37.         MEM_ZERO_STRUCT(stcQspiCommProtocol);
  38.         /* Switch to standard read mode */
  39.     stcQspiCommProtocol.enReadMode = QspiReadModeFourWiresIO;
  40.     QSPI_CommProtocolConfig(&stcQspiCommProtocol);
  41.     /* Pointer to flash address map */
  42.         //        pBuffer = (uint8_t *)((uint32_t)QSPI_BUS_ADDRESS + ReadAddr);
  43.                        
  44.                 uint8_t * pFlashReadAddr = (uint8_t *)((uint32_t)QSPI_BUS_ADDRESS + ReadAddr);
  45.                 memcpy(pBuffer, pFlashReadAddr, (uint32_t)NumByteToRead);
  46.                 return 0 ;
  47. }


  48. /**
  49. *******************************************************************************
  50. ** \brief W25QXX flash write
  51. **
  52. ** \param [in] pBuffer                 data buffer to be written
  53. ** \param [in] WriteAddr               Address to be written
  54. ** \param [in] NumByteToWrite          Number to be written, (MAX. 65535)
  55. **
  56. ** \retval None
  57. **
  58. ******************************************************************************/
  59. void W25QXX_Write_NoCheck(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
  60. {
  61.     uint16_t pageremain;
  62.     pageremain = (uint16_t)(256u - WriteAddr % 256u);
  63.     if (NumByteToWrite <= pageremain)
  64.     {
  65.         pageremain = NumByteToWrite;
  66.     }
  67.     while (1)
  68.     {
  69.         QspiFlash_WritePage(WriteAddr,pBuffer , pageremain); //pBuffer
  70.         if (NumByteToWrite == pageremain)
  71.         {
  72.             break;
  73.         }
  74.         else //NumByteToWrite>pageremain
  75.         {
  76.             pBuffer        += pageremain;
  77.             WriteAddr      += pageremain;

  78.             NumByteToWrite -= pageremain;
  79.             if (NumByteToWrite > 256u)
  80.             {
  81.                 pageremain = 256u;
  82.             }
  83.             else
  84.             {
  85.                 pageremain = NumByteToWrite;
  86.             }
  87.         }
  88.     }
  89.                 flashnoreading = 0 ;
  90. }

  91. /**
  92. *******************************************************************************
  93. ** \brief W25QXX flash write API for MSC
  94. **
  95. ** \param [in] pBuffer                 data buffer to be written
  96. ** \param [in] WriteAddr               Address to be written
  97. ** \param [in] NumByteToWrite          Number to be written, (MAX. 65535)
  98. **
  99. ** \retval Write result
  100. **
  101. ******************************************************************************/
  102. int W25QXX_Write(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
  103. {
  104.         if(WriteAddr + NumByteToWrite -1 > (uint32_t)FLASH_MAX_ADDR){
  105.                         return 1 ;
  106.         }
  107.     uint32_t secpos;
  108.     uint16_t secoff;
  109.     uint16_t secremain;
  110.     uint16_t i;
  111.     uint8_t * W25QXX_BUF;
  112.     W25QXX_BUF = W25QXX_BUFFER;
  113.     secpos     = WriteAddr / 4096u;
  114.     secoff     = (uint16_t)(WriteAddr % 4096u);
  115.     secremain  = 4096u - secoff;
  116. //    DDL_Printf("ad:%X,nb:%X\r\n",WriteAddr,NumByteToWrite);           // for test
  117.     if (NumByteToWrite <= secremain)
  118.     {
  119.         secremain = NumByteToWrite;                                // less than 4K
  120.     }
  121.     while (1)
  122.     {
  123.         W25QXX_Read(W25QXX_BUF, secpos * 4096u, 4096u);              // read one sector content
  124.         stc_qspi_comm_protocol_t stcQspiCommProtocol;
  125.             MEM_ZERO_STRUCT(stcQspiCommProtocol);
  126.         stcQspiCommProtocol.enReadMode = QspiReadModeStandard;
  127.         QSPI_CommProtocolConfig(&stcQspiCommProtocol);
  128.         
  129.         for (i = 0u; i < secremain; i++)                            // check if blank sector
  130.         {
  131.             if (W25QXX_BUF[secoff + i] != (uint8_t)0XFF)
  132.             {
  133.                 break;
  134.             }
  135.         }
  136.         if (i < secremain)
  137.         {
  138.             QspiFlash_Erase4KbSector(secpos);                           // not blank, need erase
  139.             for (i = 0u; i < secremain; i++)                        // backup first
  140.             {
  141.                 W25QXX_BUF[i + secoff] = pBuffer[i];
  142.             }
  143.             W25QXX_Write_NoCheck( W25QXX_BUF , secpos * 4096u,4096u); // write back after erase

  144.         }
  145.         else
  146.         {
  147.             W25QXX_Write_NoCheck(pBuffer , WriteAddr, secremain);
  148.         }
  149.         if (NumByteToWrite == secremain)
  150.         {
  151.             break;
  152.         }
  153.         else
  154.         {
  155.             secpos++;                                              // next sector
  156.             secoff          = 0u;

  157.             pBuffer        += secremain;
  158.             WriteAddr      += secremain;
  159.             NumByteToWrite -= secremain;
  160.             if (NumByteToWrite > 4096u)
  161.             {
  162.                 secremain = 4096u;
  163.             }
  164.             else
  165.             {
  166.                 secremain = NumByteToWrite;
  167.             }
  168.         }
  169.     }
  170.     ;
  171.                 return 0 ;
  172. }



  1. /*-----------------------------------------------------------------------*/
  2. /* Low level disk I/O module SKELETON for FatFs     (C)ChaN, 2019        */
  3. /*-----------------------------------------------------------------------*/
  4. /* If a working storage control module is available, it should be        */
  5. /* attached to the FatFs via a glue function rather than modifying it.   */
  6. /* This is an example of glue functions to attach various exsisting      */
  7. /* storage control modules to the FatFs module with a defined API.       */
  8. /*-----------------------------------------------------------------------*/

  9. #include "ff.h"                        /* Obtains integer types */
  10. #include "diskio.h"                /* Declarations of disk functions */
  11. #include "w25qxx.h"

  12. /* Definitions of physical drive number for each drive */
  13. #define W25QXX                0        /* Example: Map Ramdisk to physical drive 0 */
  14. #define FATFS_SECTOR_SIZE         512       
  15. #define FATFS_SECTOR_COUNT         8 * 1024 * 2                        //一共8M空间
  16. #define FATFS_BLOCK_SIZE           8                                                     //每个BLOCK有8个扇区       


  17. /*-----------------------------------------------------------------------*/
  18. /* Get Drive Status                                                      */
  19. /*-----------------------------------------------------------------------*/

  20. DSTATUS disk_status (
  21.         BYTE pdrv                /* Physical drive nmuber to identify the drive */
  22. )
  23. {
  24.         DSTATUS stat = 0;

  25.         switch (pdrv) {
  26.         case W25QXX :
  27.                

  28.                 // translate the reslut code here

  29.                 return stat;
  30.         }
  31.         return STA_NOINIT;
  32. }



  33. /*-----------------------------------------------------------------------*/
  34. /* Inidialize a Drive                                                    */
  35. /*-----------------------------------------------------------------------*/

  36. DSTATUS disk_initialize (
  37.         BYTE pdrv                                /* Physical drive nmuber to identify the drive */
  38. )
  39. {
  40.         DSTATUS stat;
  41.        

  42.         switch (pdrv) {
  43.         case W25QXX :
  44.                 stat = W25QXX_Init();
  45.                 // translate the reslut code here
  46.                 return stat;
  47.         }
  48.         return STA_NOINIT;
  49. }



  50. /*-----------------------------------------------------------------------*/
  51. /* Read Sector(s)                                                        */
  52. /*-----------------------------------------------------------------------*/

  53. DRESULT disk_read (
  54.         BYTE pdrv,                /* Physical drive nmuber to identify the drive */
  55.         BYTE *buff,                /* Data buffer to store read data */
  56.         LBA_t sector,        /* Start sector in LBA */
  57.         UINT count                /* Number of sectors to read */
  58. )
  59. {
  60. //        DRESULT res;
  61.         int result;

  62.         switch (pdrv) {
  63.         case W25QXX :
  64.                 // translate the arguments here
  65.        
  66.                        

  67.         //        result = flashfatfsread(buff, sector * FATFS_SECTOR_SIZE, count * FATFS_SECTOR_SIZE);
  68.         //                result = W25QXX_Read(buff, sector * FATFS_SECTOR_SIZE, count * FATFS_SECTOR_SIZE);
  69.        
  70.                         for(;count>0;count--)
  71.                         {
  72.                                 result = W25QXX_Read(buff,sector*FLASH_SECTOR_SIZE,FLASH_SECTOR_SIZE);
  73.                                 sector++;
  74.                                 buff+=FLASH_SECTOR_SIZE;
  75.                         }

  76.                 // translate the reslut code here

  77.                 return (DRESULT)result;

  78.         }

  79.         return RES_PARERR;
  80. }



  81. /*-----------------------------------------------------------------------*/
  82. /* Write Sector(s)                                                       */
  83. /*-----------------------------------------------------------------------*/

  84. #if FF_FS_READONLY == 0

  85. DRESULT disk_write (
  86.         BYTE pdrv,                        /* Physical drive nmuber to identify the drive */
  87.         const BYTE *buff,        /* Data to be written */
  88.         LBA_t sector,                /* Start sector in LBA */
  89.         UINT count                        /* Number of sectors to write */
  90. )
  91. {
  92.         //DRESULT res;
  93.         int result;

  94.         switch (pdrv) {
  95.         case W25QXX :
  96. //                result = flashfatfswrite((uint8_t *)buff,sector * FATFS_SECTOR_SIZE,count * FATFS_SECTOR_SIZE);
  97. //                result = W25QXX_Write((uint8_t *)&buff, sector * FATFS_SECTOR_SIZE, count * FATFS_SECTOR_SIZE);
  98.        
  99.                         for(;count>0;count--)
  100.                         {                                                                                    
  101.                                 result = W25QXX_Write((uint8_t*)buff,sector*FLASH_SECTOR_SIZE,FLASH_SECTOR_SIZE);
  102.                                 sector++;
  103.                                 buff+=FLASH_SECTOR_SIZE;
  104.                         }
  105.                         return (DRESULT)result;   //RES_PARERR
  106.         }

  107.         return RES_PARERR;
  108. }

  109. #endif


  110. /*-----------------------------------------------------------------------*/
  111. /* Miscellaneous Functions                                               */
  112. /*-----------------------------------------------------------------------*/

  113. DRESULT disk_ioctl (
  114.         BYTE pdrv,                /* Physical drive nmuber (0..) */
  115.         BYTE cmd,                /* Control code */
  116.         void *buff                /* Buffer to send/receive control data */
  117. )
  118. {
  119.         DRESULT res;

  120.         switch (pdrv) {
  121.         case W25QXX :
  122.                 switch(cmd)
  123.           {
  124.                   case CTRL_SYNC:
  125.                                 res = RES_OK;
  126.                                 break;         
  127.                   case GET_SECTOR_SIZE:
  128.                                 *(WORD*)buff = FATFS_SECTOR_SIZE;
  129.                     res = RES_OK;
  130.                     break;         
  131.                   case GET_BLOCK_SIZE:
  132.                     *(WORD*)buff = FATFS_BLOCK_SIZE;
  133.                     res = RES_OK;
  134.                     break;         
  135.                   case GET_SECTOR_COUNT:
  136.                     *(DWORD*)buff = FATFS_SECTOR_COUNT;
  137.                     res = RES_OK;
  138.                     break;
  139.                   default:
  140.                     res = RES_PARERR;
  141.                     break;
  142.             }

  143.                 return res;
  144.         }

  145.         return RES_PARERR;
  146. }
  147. DWORD get_fattime (void)
  148. {                                 
  149.         return 0;
  150. }       
  1. #include "qspi.h"

  2. uint8_t flashnoreading = 1 ;

  3. /**
  4. *******************************************************************************
  5. ** \brief QSPI flash init function
  6. **
  7. ** \param [in] None
  8. **
  9. ** \retval None
  10. **
  11. ******************************************************************************/
  12. int QspiFlash_Init(void)
  13. {
  14.         stc_qspi_init_t stcQspiInit;

  15.     /* configuration structure initialization */
  16.     MEM_ZERO_STRUCT(stcQspiInit);

  17.     /* Configuration peripheral clock */
  18.     PWC_Fcg1PeriphClockCmd(PWC_FCG1_PERIPH_QSPI, Enable);

  19.     /* Configuration QSPI pin */
  20.     PORT_SetFunc(QSPCK_PORT, QSPCK_PIN, Func_Qspi, Disable);
  21.     PORT_SetFunc(QSNSS_PORT, QSNSS_PIN, Func_Qspi, Disable);
  22.     PORT_SetFunc(QSIO0_PORT, QSIO0_PIN, Func_Qspi, Disable);
  23.     PORT_SetFunc(QSIO1_PORT, QSIO1_PIN, Func_Qspi, Disable);
  24.     PORT_SetFunc(QSIO2_PORT, QSIO2_PIN, Func_Qspi, Disable);
  25.     PORT_SetFunc(QSIO3_PORT, QSIO3_PIN, Func_Qspi, Disable);

  26.     /* Configuration QSPI structure */
  27.     stcQspiInit.enClkDiv = QspiHclkDiv3;
  28.     stcQspiInit.enSpiMode = QspiSpiMode3;
  29.     stcQspiInit.enBusCommMode = QspiBusModeRomAccess;
  30.     stcQspiInit.enPrefetchMode = QspiPrefetchStopComplete;
  31.     stcQspiInit.enPrefetchFuncEn = Disable;
  32.     stcQspiInit.enQssnValidExtendTime = QspiQssnValidExtendSck32;
  33.     stcQspiInit.enQssnIntervalTime = QspiQssnIntervalQsck8;
  34.     stcQspiInit.enQsckDutyCorr = QspiQsckDutyCorrHalfHclk;
  35.     stcQspiInit.enVirtualPeriod = QspiVirtualPeriodQsck6;
  36.     stcQspiInit.enWpPinLevel = QspiWpPinOutputHigh;
  37.     stcQspiInit.enQssnSetupDelayTime = QspiQssnSetupDelay1Dot5Qsck;
  38.     stcQspiInit.enQssnHoldDelayTime = QspiQssnHoldDelay1Dot5Qsck;
  39.     stcQspiInit.enFourByteAddrReadEn = Disable;
  40.     stcQspiInit.enAddrWidth = QspiAddressByteThree;
  41.     stcQspiInit.stcCommProtocol.enReadMode = QspiReadModeFourWiresIO;
  42.     stcQspiInit.stcCommProtocol.enTransInstrProtocol = QspiProtocolExtendSpi;
  43.     stcQspiInit.stcCommProtocol.enTransAddrProtocol = QspiProtocolExtendSpi;
  44.     stcQspiInit.stcCommProtocol.enReceProtocol = QspiProtocolExtendSpi;
  45.     stcQspiInit.u8RomAccessInstr = QSPI_3BINSTR_FOUR_WIRES_IO_READ;
  46.     int result = QSPI_Init(&stcQspiInit);
  47.                 flashnoreading = 0;                //允许读取falsh
  48.                 return result;
  49. }
  50. /**
  51. *******************************************************************************
  52. ** \brief QSPI flash write enable function
  53. **
  54. ** \param [in] None
  55. **
  56. ** \retval None
  57. **
  58. ******************************************************************************/
  59. void QspiFlash_WriteEnable(void)
  60. {
  61.     QSPI_EnterDirectCommMode();
  62.     QSPI_WriteDirectCommValue(FLASH_INSTR_WRITE_ENABLE);
  63.     QSPI_ExitDirectCommMode();
  64. }

  65. /**
  66. *******************************************************************************
  67. ** \brief QSPI flash wait for write operation end function
  68. **
  69. ** \param [in] None
  70. **
  71. ** \retval Ok                              Flash internal operation finish
  72. ** \retval ErrorTimeout                    Flash internal operation timeout
  73. **
  74. ******************************************************************************/
  75. en_result_t QspiFlash_WaitForWriteEnd(void)
  76. {
  77.     en_result_t enRet = Ok;
  78.     uint8_t u8Status = 0u;
  79.     uint32_t u32Timeout;
  80.     stc_clk_freq_t stcClkFreq;

  81.     CLK_GetClockFreq(&stcClkFreq);
  82.     u32Timeout = stcClkFreq.sysclkFreq / 1000u;
  83.     QSPI_EnterDirectCommMode();
  84.     QSPI_WriteDirectCommValue(FLASH_INSTR_READ_SR1);
  85.     do
  86.     {
  87.         u8Status = QSPI_ReadDirectCommValue();
  88.         u32Timeout--;
  89.     } while ((u32Timeout != 0u) &&
  90.              ((u8Status & FLASH_BUSY_BIT_MASK) == FLASH_BUSY_BIT_MASK));

  91.     if (FLASH_BUSY_BIT_MASK == u8Status)
  92.     {
  93.         enRet = ErrorTimeout;
  94.     }
  95.     QSPI_ExitDirectCommMode();

  96.     return enRet;
  97. }

  98. /**
  99. *******************************************************************************
  100. ** \brief QSPI flash page write program function
  101. **
  102. ** \param [in] u32Addr                     Valid flash address
  103. **
  104. ** \param [in] pData                       Pointer to send data buffer
  105. **
  106. ** \param [in] len                         Send data length
  107. **
  108. ** \retval Error                           Page write program failed
  109. ** \retval Ok                              Page write program success
  110. **
  111. ******************************************************************************/
  112. en_result_t QspiFlash_WritePage(uint32_t u32Addr, uint8_t * pData, uint16_t len)
  113. {
  114.     en_result_t enRet = Ok;
  115.     uint16_t u16Index = 0u;

  116.     if ((u32Addr > FLASH_MAX_ADDR) || (NULL == pData) || (len > FLASH_PAGE_SIZE))
  117.     {
  118.         enRet = Error;
  119.     }
  120.     else
  121.     {
  122.         QspiFlash_WriteEnable();
  123.         /* Send data to flash */
  124.         QSPI_EnterDirectCommMode();
  125.         QSPI_WriteDirectCommValue(FLASH_INSTR_PAGE_PROGRAM);
  126.         QSPI_WriteDirectCommValue((uint8_t)((u32Addr & 0xFF0000ul) >> 16));
  127.         QSPI_WriteDirectCommValue((uint8_t)((u32Addr & 0xFF00u) >> 8));
  128.         QSPI_WriteDirectCommValue((uint8_t)(u32Addr & 0xFFu));
  129.         while (len--)
  130.         {
  131.            QSPI_WriteDirectCommValue(pData[u16Index]);
  132.            u16Index++;
  133.         }
  134.         QSPI_ExitDirectCommMode();
  135.         /* Wait for flash idle */
  136.         enRet = QspiFlash_WaitForWriteEnd();
  137.     }

  138.     return enRet;
  139. }

  140. /**
  141. *******************************************************************************
  142. ** \brief QSPI flash erase 4Kb sector function
  143. **
  144. ** \param [in] u32Addr                     Valid flash address
  145. **
  146. ** \retval Error                           Sector erase failed
  147. ** \retval Ok                              Sector erase success
  148. **
  149. ******************************************************************************/
  150. en_result_t QspiFlash_Erase4KbSector(uint32_t u32Addr)
  151. {
  152.     en_result_t enRet = Ok;

  153.     if (u32Addr >= FLASH_MAX_ADDR)
  154.     {
  155.         enRet = Error;
  156.     }
  157.     else
  158.     {
  159.         QspiFlash_WriteEnable();
  160.         /* Send instruction to flash */
  161.         QSPI_EnterDirectCommMode();
  162.         QSPI_WriteDirectCommValue(FLASH_INSTR_ERASE_4KB_SECTOR);
  163.         QSPI_WriteDirectCommValue((uint8_t)((u32Addr & 0xFF0000ul) >> 16));
  164.         QSPI_WriteDirectCommValue((uint8_t)((u32Addr & 0xFF00u) >> 8));
  165.         QSPI_WriteDirectCommValue((uint8_t)(u32Addr & 0xFFu));
  166.         QSPI_ExitDirectCommMode();
  167.         /* Wait for flash idle */
  168.         enRet = QspiFlash_WaitForWriteEnd();
  169.     }

  170.     return enRet;
  171. }

  172. /**
  173. *******************************************************************************
  174. ** \brief QSPI flash erase chip function
  175. **
  176. ** \param [in] None
  177. **
  178. ** \retval None
  179. **
  180. ******************************************************************************/
  181. void QspiFlash_EraseChip(void)
  182. {
  183.     QspiFlash_WriteEnable();
  184.     /* Send instruction to flash */
  185.     QSPI_EnterDirectCommMode();
  186.     QSPI_WriteDirectCommValue(FLASH_INSTR_ERASE_CHIP);
  187.     QSPI_ExitDirectCommMode();
  188.     /* Wait for flash idle */
  189.     QspiFlash_WaitForWriteEnd();
  190. }

  191. /**
  192. *******************************************************************************
  193. ** \brief QSPI flash read status register function
  194. **
  195. ** \param [in] u8Reg                       Need to get status register
  196. ** \arg FLASH_INSTR_READ_SR1               Status register 1
  197. ** \arg FLASH_INSTR_READ_SR2               Status register 2
  198. ** \arg FLASH_INSTR_READ_SR3               Status register 3
  199. **
  200. ** \retval uint8_t                         Current register value
  201. **
  202. ******************************************************************************/
  203. uint8_t QspiFlash_ReadStatusRegister(uint8_t u8Reg)
  204. {
  205.     uint8_t regSta = 0u;

  206.     QSPI_EnterDirectCommMode();
  207.     QSPI_WriteDirectCommValue(u8Reg);
  208.     regSta = QSPI_ReadDirectCommValue();
  209.     QSPI_ExitDirectCommMode();

  210.     return regSta;
  211. }
zwsam 发表于 2023-11-29 10:24 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

16

主题

83

帖子

3

粉丝
快速回复 在线客服 返回列表 返回顶部