123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #ifndef __SPI_FLASH_H
- #define __SPI_FLASH_H
- #include "stm32f7xx.h"
- #include <stdio.h>
- /* Private typedef -----------------------------------------------------------*/
- //#define sFLASH_ID 0xEF3015 //W25X16
- //#define sFLASH_ID 0xEF4015 //W25Q16
- //#define sFLASH_ID 0XEF4017 //W25Q64
- #define sFLASH_ID 0XEF4018 //W25Q128
- //#define SPI_FLASH_PageSize 4096
- #define SPI_FLASH_PageSize 256
- #define SPI_FLASH_PerWritePageSize 256
- /* Private define ------------------------------------------------------------*/
- /*命令定义-开头*******************************/
- #define W25X_WriteEnable 0x06
- #define W25X_WriteDisable 0x04
- #define W25X_ReadStatusReg 0x05
- #define W25X_WriteStatusReg 0x01
- #define W25X_ReadData 0x03
- #define W25X_FastReadData 0x0B
- #define W25X_FastReadDual 0x3B
- #define W25X_PageProgram 0x02
- #define W25X_BlockErase 0xD8
- #define W25X_SectorErase 0x20
- #define W25X_ChipErase 0xC7
- #define W25X_PowerDown 0xB9
- #define W25X_ReleasePowerDown 0xAB
- #define W25X_DeviceID 0xAB
- #define W25X_ManufactDeviceID 0x90
- #define W25X_JedecDeviceID 0x9F
- #define WIP_Flag 0x01 /* Write In Progress (WIP) flag */
- #define Dummy_Byte 0xFF
- /*命令定义-结尾*******************************/
- #define SPIx SPI2
- #define SPIx_CLK_ENABLE() __HAL_RCC_SPI2_CLK_ENABLE()
- #define SPIx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
- #define SPIx_MISO_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
- #define SPIx_MOSI_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
- #define SPIx_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
- #define SPIx_FORCE_RESET() __HAL_RCC_SPI2_FORCE_RESET()
- #define SPIx_RELEASE_RESET() __HAL_RCC_SPI2_RELEASE_RESET()
- /* Definition for SPIx Pins */
- #define SPIx_SCK_PIN GPIO_PIN_13
- #define SPIx_SCK_GPIO_PORT GPIOB
- #define SPIx_MISO_PIN GPIO_PIN_14
- #define SPIx_MISO_GPIO_PORT GPIOB
- #define SPIx_MOSI_PIN GPIO_PIN_15
- #define SPIx_MOSI_GPIO_PORT GPIOB
- //#define FLASH_CS_PIN GPIO_PIN_12
- //#define FLASH_CS_GPIO_PORT GPIOB
- #define FLASH_CS_PIN GPIO_PIN_8
- #define FLASH_CS_GPIO_PORT GPIOD
- #define SPI_FLASH_CS_LOW() HAL_GPIO_WritePin(FLASH_CS_GPIO_PORT, FLASH_CS_PIN, GPIO_PIN_RESET)
- #define SPI_FLASH_CS_HIGH() HAL_GPIO_WritePin(FLASH_CS_GPIO_PORT, FLASH_CS_PIN, GPIO_PIN_SET)
- /*SPI接口定义-结尾****************************/
- /*等待超时时间*/
- #define SPIT_FLAG_TIMEOUT ((uint32_t)0x10000)
- #define SPIT_LONG_TIMEOUT ((uint32_t)(10 * SPIT_FLAG_TIMEOUT))
- /*信息输出*/
- #define FLASH_DEBUG_ON 1
- #define FLASH_INFO(fmt,arg...) printf("<<-FLASH-INFO->> "fmt"\n",##arg)
- #define FLASH_ERROR(fmt,arg...) printf("<<-FLASH-ERROR->> "fmt"\n",##arg)
- #define FLASH_DEBUG(fmt,arg...) do{\
- if(FLASH_DEBUG_ON)\
- printf("<<-FLASH-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\
- }while(0)
- void SPI_FLASH_W25Q_Init(void);
- void SPI_FLASH_Init(void);
- void SPI_FLASH_SectorErase(uint32_t SectorAddr);
- void SPI_FLASH_BulkErase(void);
- void SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
- void SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
- void SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
- uint32_t SPI_FLASH_ReadID(void);
- uint32_t SPI_FLASH_ReadDeviceID(void);
- void SPI_FLASH_StartReadSequence(uint32_t ReadAddr);
- void SPI_Flash_PowerDown(void);
- void SPI_Flash_WAKEUP(void);
- uint8_t SPI_FLASH_ReadByte(void);
- uint8_t SPI_FLASH_SendByte(uint8_t byte);
- uint16_t SPI_FLASH_SendHalfWord(uint16_t HalfWord);
- void SPI_FLASH_WriteEnable(void);
- void SPI_FLASH_WaitForWriteEnd(void);
- #endif /* __SPI_FLASH_H */
|