2024-12-06 13:23:28 +00:00
|
|
|
#include "flash.h"
|
2025-01-11 02:19:58 +00:00
|
|
|
// #include "gpio.h"
|
|
|
|
#include "main.h"
|
2024-12-06 13:23:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief flash初始化
|
|
|
|
* @param
|
|
|
|
*/
|
|
|
|
void Flash_Init(void)
|
|
|
|
{
|
2025-01-17 12:32:22 +00:00
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
2025-01-11 02:19:58 +00:00
|
|
|
|
2025-01-17 12:32:22 +00:00
|
|
|
HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
2025-01-11 02:19:58 +00:00
|
|
|
|
2025-01-17 12:32:22 +00:00
|
|
|
/*Configure GPIO pin : FLASH_CS_Pin */
|
|
|
|
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(FLASH_CS_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
// GPIO_InitStruct.Pin = FLASH_CS_Pin | FLASH_CLK_Pin | FLASH_MISO_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);
|
2025-01-11 02:19:58 +00:00
|
|
|
|
|
|
|
// // GPIO_InitStruct.Pin = FLASH_MOSI_Pin;
|
|
|
|
// // GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
// // GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
|
|
// // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
|
|
// // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
// GPIO_InitStruct.Pin = FLASH_CS_Pin | FLASH_CLK_Pin | FLASH_MISO_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);
|
|
|
|
|
|
|
|
// GPIO_InitStruct.Pin = FLASH_MOSI_Pin;
|
|
|
|
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
// GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
|
|
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
|
|
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
2024-12-06 13:23:28 +00:00
|
|
|
|
2025-01-17 12:32:22 +00:00
|
|
|
// GPIO_InitTypeDef GPIO_InitStruct = {0};
|
2024-12-06 13:23:28 +00:00
|
|
|
|
2025-01-17 12:32:22 +00:00
|
|
|
// __HAL_RCC_GPIOA_CLK_ENABLE();
|
2025-01-11 02:19:58 +00:00
|
|
|
|
2025-01-17 12:32:22 +00:00
|
|
|
// /*Configure GPIO pin Output Level */
|
|
|
|
// // HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin, GPIO_PIN_RESET);
|
|
|
|
// HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MOSI_Pin, GPIO_PIN_RESET);
|
2025-01-11 02:19:58 +00:00
|
|
|
|
2025-01-17 12:32:22 +00:00
|
|
|
// /*Configure GPIO pins : FLASH_CS_Pin FLASH_CLK_Pin FLASH_MISO_Pin */
|
|
|
|
// // GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin;
|
|
|
|
// GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MOSI_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);
|
2024-12-06 13:23:28 +00:00
|
|
|
|
2025-01-17 12:32:22 +00:00
|
|
|
// /*Configure GPIO pin : FLASH_MOSI_Pin */
|
|
|
|
// GPIO_InitStruct.Pin = FLASH_MISO_Pin;
|
|
|
|
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
// GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
|
|
// HAL_GPIO_Init(FLASH_MOSI_GPIO_Port, &GPIO_InitStruct);
|
2025-01-11 02:19:58 +00:00
|
|
|
|
2025-01-17 12:32:22 +00:00
|
|
|
// Flash_GPIO_Init();
|
|
|
|
W25QXX_Init();
|
2024-12-06 13:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 读取flash中的数据
|
|
|
|
* @param pBuffer 保存读取的数据
|
|
|
|
* @param ReadAddr 读取数据的位置
|
|
|
|
* @param NumByteToRead 读取数据的长度
|
|
|
|
*/
|
|
|
|
void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
|
|
|
|
{
|
2025-01-17 12:32:22 +00:00
|
|
|
W25QXX_Read(pBuffer, ReadAddr, NumByteToRead);
|
|
|
|
// Flash_Read(pBuffer, ReadAddr, NumByteToRead);
|
2025-01-11 02:19:58 +00:00
|
|
|
|
2024-12-06 13:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 将数据写入到flash中
|
|
|
|
* @param pBuffer 要写入的数据
|
|
|
|
* @param ReadAddr 要写入数据的位置
|
|
|
|
* @param NumByteToRead 要写入数据的长度
|
|
|
|
*/
|
|
|
|
void write_Flash(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
|
|
|
|
{
|
2025-01-17 12:32:22 +00:00
|
|
|
W25QXX_Write(pBuffer, WriteAddr, NumByteToWrite);
|
2025-01-11 02:19:58 +00:00
|
|
|
// Flash_Write_MorePage(pBuffer, WriteAddr, NumByteToWrite);
|
2025-01-17 12:32:22 +00:00
|
|
|
// W25Q128_Write(pBuffer, WriteAddr, NumByteToWrite);
|
2024-12-06 13:23:28 +00:00
|
|
|
}
|