1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #ifndef __W25Qxx_H
- #define __W25Qxx_H
- #include "gpio.h"
- #include "main.h"
- #include "stm32l4xx_hal_gpio.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define W25X_WriteEnable 0x06 //FLASH 写使能
- #define W25X_WriteDisable 0x04
- #define W25X_ReadStatusReg 0x05 //FLASH 读取状态
- #define W25X_WriteStatusReg 0x01 //FLASH 写状态
- #define W25X_ReadData 0x03 //可低速下读FLASH数据
- #define W25X_FastReadData 0x0B //快速读取
- #define W25X_FastReadDual 0x3B
- #define W25X_PageProgram 0x02 //按页写FLASH
- #define W25X_BlockErase 0xD8
- #define W25X_SectorErase 0x20 //擦除FLASH扇区
- #define W25X_ChipErase 0xC7 //擦除FLASH块
- #define W25X_PowerDown 0xB9 //深度掉电模式功耗1uA
- #define W25X_ReleasePowerDown 0xAB //退出深度掉电模式
- #define W25X_DeviceID 0xAB
- #define W25X_ManufactDeviceID 0x90
- #define W25X_JedecDeviceID 0x9F //FLASH 读ID
- #define FLASH_CS_PIN GPIO_PIN_15
- #define FLASH_CS_PORT GPIOB
-
- #define SPI_FLASH_CS_LOW() HAL_GPIO_WritePin(FLASH_CS_PORT, FLASH_CS_PIN, GPIO_PIN_RESET);
- #define SPI_FLASH_CS_HIGH() HAL_GPIO_WritePin(FLASH_CS_PORT, FLASH_CS_PIN, GPIO_PIN_SET);
- static uint8_t spi1_flash_read_byte(void);
- static uint8_t spi1_flash_send_byte(uint8_t byte);
- static void spi1_flash_write_enable(void);
- void spi1_flash_wait_for_write_end(void) ;
- uint32_t spi_flash_read_ID(void);
- void spi1_flash_read(uint32_t addr,uint8_t *pdata, uint16_t size);
- void spi1_flash_page_write(uint32_t addr, uint8_t *pdata, uint16_t size);
- void spi1_flash_write(uint32_t addr, uint8_t *pdata, uint32_t size);
- void spi1_flash_sector_erase(uint32_t sector_addr);
- void spi1_flash_block_erase(void);
- void spi1_flash_enter_deep_power_down(void);
- void spi1_flash_release_from_deep_power_down(void);
- #endif
|