/\*\* \* @brief Initializes a Drive \* @param pdrv: Physical drive number (0..) \* @retval DSTATUS: Operation status \*/ DSTATUS USER\_initialize(BYTE pdrv /\* Physical drive nmuber to identify the drive \*/ ) { /\* USER CODE BEGIN INIT \*/ Stat = STA_NOINIT; w25qxx.SPI_CS_Pin = W25QXX_CHIP_SELECT_Pin; w25qxx.SPI_CS_Port = W25QXX_CHIP_SELECT_GPIO_Port; w25qxx.SPI_Handle = &hspi1;
if (w25qxx\_init(&w25qxx)) { // 初始化W25Q Stat = RES_OK; w25qxx\_display\_info(&w25qxx); } else { Stat = RES_ERROR; }
return Stat; /\* USER CODE END INIT \*/ }
/\*\* \* @brief Reads Sector(s) \* @param pdrv: Physical drive number (0..) \* @param \*buff: Data buffer to store read data \* @param sector: Sector address (LBA) \* @param count: Number of sectors to read (1..128) \* @retval DRESULT: Operation result \*/ DRESULT USER\_read(BYTE pdrv, /\* Physical drive nmuber to identify the drive \*/ BYTE \*buff, /\* Data buffer to store read data \*/ DWORD sector, /\* Sector address in LBA \*/ UINT count /\* Number of sectors to read \*/ ) { /\* USER CODE BEGIN READ \*/ DRESULT status = RES_OK; // 读扇区内容 w25qxx\_read\_sector(&w25qxx, sector, buff, count);
return status; /\* USER CODE END READ \*/ }
/\*\* \* @brief Writes Sector(s) \* @param pdrv: Physical drive number (0..) \* @param \*buff: Data to be written \* @param sector: Sector address (LBA) \* @param count: Number of sectors to write (1..128) \* @retval DRESULT: Operation result \*/ #if \_USE\_WRITE == 1 DRESULT USER\_write(BYTE pdrv, /\* Physical drive nmuber to identify the drive \*/ const BYTE \*buff, /\* Data to be written \*/ DWORD sector, /\* Sector address in LBA \*/ UINT count /\* Number of sectors to write \*/ ) { /\* USER CODE BEGIN WRITE \*/ /\* USER CODE HERE \*/ DRESULT status = RES_OK; // 写扇区 w25qxx\_write\_sector(&w25qxx, buff, sector, count); return status; /\* USER CODE END WRITE \*/ } #endif /\* \_USE\_WRITE == 1 \*/
/\*\* \* @brief I/O control operation \* @param pdrv: Physical drive number (0..) \* @param cmd: Control code \* @param \*buff: Buffer to send/receive control data \* @retval DRESULT: Operation result \*/ #if \_USE\_IOCTL == 1 DRESULT USER\_ioctl(BYTE pdrv, /\* Physical drive nmuber (0..) \*/ BYTE cmd, /\* Control code \*/ void \*buff /\* Buffer to send/receive control data \*/ ) { /\* USER CODE BEGIN IOCTL \*/ DRESULT res = RES_ERROR; switch (cmd) { case CTRL_SYNC: res = RES_OK; break; case GET_SECTOR_COUNT: \*(uint32\_t\*) buff = w25qxx.sector_count; res = RES_OK; break; case GET_SECTOR_SIZE: \*(uint16\_t\*) buff = w25qxx.sector_size; res = RES_OK; break; case GET_BLOCK_SIZE: \*(uint32\_t\*) buff = w25qxx.block_size; res = RES_OK; break;
} return res; /\* USER CODE END IOCTL \*/ } #endif /\* \_USE\_IOCTL == 1 \*/
/\* Private includes ----------------------------------------------------------\*/ /\* USER CODE BEGIN Includes \*/ #include <stdio.h> #include "w25qxx/w25qxx.h" /\* USER CODE END Includes \*/