#include "flash.h" // #include "gpio.h" #include "main.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}; /*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); // // 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); // GPIO_InitTypeDef GPIO_InitStruct = {0}; // __HAL_RCC_GPIOA_CLK_ENABLE(); // /*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); // /*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); // /*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); // Flash_GPIO_Init(); 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); // Flash_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); // Flash_Write_MorePage(pBuffer, WriteAddr, NumByteToWrite); // W25Q128_Write(pBuffer, WriteAddr, NumByteToWrite); } /** * @brief 清除flash中secpos扇区的数据 * */ void erase_Sector_Flash(uint32_t secpos) { W25QXX_Erase_Sector(secpos); }