{
tickstart++;
/* Check for the Timeout */
if(tickstart > W25Qx_TIMEOUT_VALUE)
{
return W25Qx_TIMEOUT;
}
}
return W25Qx_OK;
}
/**
* @brief Read Manufacture/Device ID.
* @param return value address
* @retval None
*/
void BSP_W25Qx_Read_ID(uint8_t *ID)
{
uint8_t cmd[4] = {READ_ID_CMD,0x00,0x00,0x00};
W25Qx_Enable();
/* Send the read ID command */
// HAL_SPI_Transmit(&hspi1, cmd, 4, W25Qx_TIMEOUT_VALUE);
/* Reception of the data */
// HAL_SPI_Receive(&hspi1,ID, 2, W25Qx_TIMEOUT_VALUE);
for(int i=0;i< 4;i++)
spi_SendRcvByte(SPI0,cmd[i]);
for(int i=0;i< 2;i++)
{
ID[i]=spi_SendRcvByte(SPI0,0x00);
}
W25Qx_Disable();
}
/**
* @brief Reads an amount of data from the QSPI memory.
* @param pData: Pointer to data to be read
* @param ReadAddr: Read start address
* @param Size: Size of data to read
* @retval QSPI memory status
*/
uint8_t BSP_W25Qx_Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size)
{
uint8_t cmd[4];
uint8_t status;
/* Configure the command */
cmd[0] = READ_CMD;
cmd[1] = (uint8_t)(ReadAddr > > 16);
cmd[2] = (uint8_t)(ReadAddr > > 8);
cmd[3] = (uint8_t)(ReadAddr);
W25Qx_Enable();
/* Send the read ID command */
// HAL_SPI_Transmit(&hspi1, cmd, 4, W25Qx_TIMEOUT_VALUE);
for(int i= 0;i< 4;i++)
spi_SendRcvByte(SPI0,cmd[i]);
/* Reception of the data */
// if (HAL_SPI_Receive(&hspi1, pData,Size,W25Qx_TIMEOUT_VALUE) != HAL_OK)
// {
// return W25Qx_ERROR;
// }
for(int i= 0;i< Size;i++)
pData[i]=spi_SendRcvByte(SPI0,0x00);
if (status != 0x00)
{
return W25Qx_ERROR;
}
W25Qx_Disable();
return W25Qx_OK;
}
/**
* @brief Writes an amount of data to the QSPI memory.
* @param pData: Pointer to data to be written
* @param WriteAddr: Write start address
* @param Size: Size of data to write,No more than 256byte.
* @retval QSPI memory status
*/
uint8_t BSP_W25Qx_Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size)
{
uint8_t cmd[4];
uint32_t end_addr, current_size, current_addr;
uint32_t tickstart =0;
/* Calculation of the size between the write address and the end of the page */
current_addr = 0;
while (current_addr <= WriteAddr)//判斷地址屬于哪一扇區(qū)開始
{
current_addr += W25Q128FV_PAGE_SIZE;//0x100- > 256 bytes
}
current_size = current_addr - WriteAddr;
/* Check if the size of the data is less than the remaining place in the page */
if (current_size > Size)
{
current_size = Size;
}
/* Initialize the adress variables *///寫入地址大小范圍
current_addr = WriteAddr;
end_addr = WriteAddr + Size;
/* Perform the write page by page */
do
{
/* Configure the command */
cmd[0] = PAGE_PROG_CMD;
cmd[1] = (uint8_t)(current_addr > > 16);
cmd[2] = (uint8_t)(current_addr > > 8);
cmd[3] = (uint8_t)(current_addr);
/* Enable write operations */
BSP_W25Qx_WriteEnable();
W25Qx_Enable();
/* Send the command */
// if (HAL_SPI_Transmit(&hspi1,cmd, 4, W25Qx_TIMEOUT_VALUE) != HAL_OK)
// {
// return W25Qx_ERROR;
// }
for(int i=0;i< 4;i++)
spi_SendRcvByte(SPI0,cmd[i]);
/* Transmission of the data */
// if (HAL_SPI_Transmit(&hspi1, pData,current_size, W25Qx_TIMEOUT_VALUE) != HAL_OK)
// {
// return W25Qx_ERROR;
// }
for(int i=0;i< current_size;i++)
spi_SendRcvByte(SPI0,pData[i]);
W25Qx_Disable();
/* Wait the end of Flash writing */
while(BSP_W25Qx_GetStatus() == W25Qx_BUSY)
{
tickstart++;
/* Check for the Timeout */
if(tickstart > W25Qx_TIMEOUT_VALUE)
{
return W25Qx_TIMEOUT;
}
}
/* Update the address and size variables for next page programming */
current_addr += current_size;
pData += current_size;
current_size = ((current_addr + W25Q128FV_PAGE_SIZE) > end_addr) ? (end_addr - current_addr) : W25Q128FV_PAGE_SIZE;
} while (current_addr < end_addr);
return W25Qx_OK;
}
/**
* @brief Erases the specified block of the QSPI memory.
* @param BlockAddress: Block address to erase
* @retval QSPI memory status
*/
uint8_t BSP_W25Qx_Erase_Block(uint32_t Address)
{
uint8_t cmd[4];
uint32_t tickstart=0 ;
cmd[0] = SECTOR_ERASE_CMD;
cmd[1] = (uint8_t)(Address > > 16);
cmd[2] = (uint8_t)(Address > > 8);
cmd[3] = (uint8_t)(Address);
/* Enable write operations */
BSP_W25Qx_WriteEnable();
/*Select the FLASH: Chip Select low */
W25Qx_Enable();
/* Send the read ID command */
// HAL_SPI_Transmit(&hspi1, cmd, 4, W25Qx_TIMEOUT_VALUE);
for(int i =0;i< 4;i++)
spi_SendRcvByte(SPI0,cmd[i]);
/*Deselect the FLASH: Chip Select high */
W25Qx_Disable();
delay_1ms(1);
/* Wait the end of Flash writing */
while(BSP_W25Qx_GetStatus() == W25Qx_BUSY)
{
tickstart++;
/* Check for the Timeout */
if(tickstart > W25Q128FV_SECTOR_ERASE_MAX_TIME)
{
return W25Qx_TIMEOUT;
}
}
return W25Qx_OK;
}
/**
* @brief Erases the entire QSPI memory.This function will take a very long time.
* @retval QSPI memory status
*/
uint8_t BSP_W25Qx_Erase_Chip(void)
{
uint8_t cmd[4];
uint32_t tickstart ;
cmd[0] = SECTOR_ERASE_CMD;
/* Enable write operations */
BSP_W25Qx_WriteEnable();
/*Select the FLASH: Chip Select low */
W25Qx_Enable();
/* Send the read ID command */
// HAL_SPI_Transmit(&hspi1, cmd, 1, W25Qx_TIMEOUT_VALUE);
spi_SendRcvByte(SPI0,cmd[0]);
/*Deselect the FLASH: Chip Select high */
W25Qx_Disable();
/* Wait the end of Flash writing */
while(BSP_W25Qx_GetStatus() != W25Qx_BUSY)
{
tickstart++;
/* Check for the Timeout */
if(tickstart > W25Q128FV_BULK_ERASE_MAX_TIME)
{
return W25Qx_TIMEOUT;
}
}
return W25Qx_OK;
}
W25Qx.h
/*********************************************************************************************************
*
* File : W25Qx.h
* Hardware Environment:
* Build Environment : RealView MDK-ARM Version: 5.15
* Version : V1.0
* By :
*
* (c) Copyright 2005-2015, WaveShare
* http://www.waveshare.net
* All Rights Reserved
*
*********************************************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __W25Qx_H
#define __W25Qx_H
#ifdef __cplusplus
extern 'C' {
#endif
/* Includes ------------------------------------------------------------------*/
#include 'gd32f30x.h'
#include 'gd32f30x_spi.h'
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup W25Q128FV
* @{
*/
/** @defgroup W25Q128FV_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup W25Q128FV_Exported_Constants
* @{
*/
/**
* @brief W25Q128FV Configuration
*/
上一篇:基于GD32E503主控芯片實現(xiàn)直流數(shù)控電源的設計
下一篇:STM32CUBEMX開發(fā)GD32F303(2)----讀保護與寫保護
- 熱門資源推薦
- 熱門放大器推薦
設計資源 培訓 開發(fā)板 精華推薦
- LTM8053IY 5Vout 從 7Vin 到 40Vin 降壓轉(zhuǎn)換器的典型應用電路
- 使用 Analog Devices 的 LTC6262HTS8 的參考設計
- 使用 Analog Devices 的 LTC3803ES6-5 的參考設計
- UMFT220XA-02,用于 FT220XQ 全速 USB 2.0 接口的 USB 轉(zhuǎn) 4 位 SPI/FT1248 開發(fā)模塊
- ADA4062-2ARZ-RL運算放大器用作陷波濾波器電路的典型應用電路
- AD8311-EVALZ,AD8311 評估板,50dB GSM PA 控制器
- LTC2633-HZ8 雙路 8 位數(shù)模轉(zhuǎn)換器的典型應用
- AT9919DB1,AT9919 單高電流 LED 驅(qū)動器演示板
- 使用 RECOM Power GmbH 的 RSO-123.3D 的參考設計
- 使用外部基準電流的 LT3088IST 線性穩(wěn)壓器的典型應用
- 半導體關稅可能會使您的下一輛汽車更加昂貴
- 潮起!人形機器人成本的20%-30%——靈巧手,國產(chǎn)3大廠商正快速產(chǎn)業(yè)化!
- AB Dynamics發(fā)布用于無人駕駛測試的物體檢測系統(tǒng)
- AI重構出行:高階輔助駕駛的破局之路
- 廣汽即將發(fā)布全新星源增程技術
- Yole表示,到2030年,數(shù)據(jù)中心芯片市場規(guī)模將達到5000億美元
- 綠色節(jié)能趨勢下的延時繼電器發(fā)展:低功耗設計與環(huán)保材料應用
- 國內(nèi)車企在固態(tài)電池領域的挑戰(zhàn)和技術方案
- 資本熱捧 + 政策護航,2025 人形機器人能否叩開 “量產(chǎn)元年” 大門?
- 耐世特推出用于智能運動控制的 MotionIQ?軟件套件