43 lines
1.1 KiB
C
43 lines
1.1 KiB
C
|
#include "flash.h"
|
||
|
|
||
|
/**
|
||
|
* @brief flash初始化
|
||
|
* @param
|
||
|
*/
|
||
|
void Flash_Init(void)
|
||
|
{
|
||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||
|
|
||
|
HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
|
||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||
|
|
||
|
GPIO_InitStruct.Pin = FLASH_CS_Pin;
|
||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||
|
|
||
|
W25QXX_Init();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief 读取flash中的数据
|
||
|
* @param pBuffer 保存读取的数据
|
||
|
* @param ReadAddr 读取数据的位置
|
||
|
* @param NumByteToRead 读取数据的长度
|
||
|
*/
|
||
|
void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
|
||
|
{
|
||
|
W25QXX_Read(pBuffer, ReadAddr, NumByteToRead);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief 将数据写入到flash中
|
||
|
* @param pBuffer 要写入的数据
|
||
|
* @param ReadAddr 要写入数据的位置
|
||
|
* @param NumByteToRead 要写入数据的长度
|
||
|
*/
|
||
|
void write_Flash(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
|
||
|
{
|
||
|
W25QXX_Write(pBuffer, WriteAddr, NumByteToWrite);
|
||
|
}
|