/*
 * falsh.c
 *
 *  Created on: Mar 11, 2021
 *      Author: 13370
 */

#include "flash.h"

//读取SPI FLASH
//在指定地址开始读取指定长度的数据
//pBuffer:数据存储区
//ReadAddr:开始读取的地址(24bit)
//NumByteToRead:要读取的字节数(最大65535)


void W25QXX_Read(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
{
	unsigned char buff[4];
	HAL_GPIO_WritePin(FLASH_E_GPIO_Port,FLASH_E_Pin,0);
	buff[0]=W25X_ReadData;
	buff[1]=(uint8_t)((ReadAddr)>>16);
	buff[2]=(uint8_t)((ReadAddr)>>8);
    buff[3]=(uint8_t)ReadAddr;
	HAL_SPI_Transmit(&hspi2,buff,4,100);         	//发送读取命令

	HAL_SPI_Receive(&hspi2,pBuffer,NumByteToRead,100);
	HAL_GPIO_WritePin(FLASH_E_GPIO_Port,FLASH_E_Pin,1);

}
