w25qxx.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef __W25Qxx_H
  2. #define __W25Qxx_H
  3. #include "gpio.h"
  4. #include "main.h"
  5. #include "stm32l4xx_hal_gpio.h"
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define W25X_WriteEnable 0x06 //FLASH 写使能
  10. #define W25X_WriteDisable 0x04
  11. #define W25X_ReadStatusReg 0x05 //FLASH 读取状态
  12. #define W25X_WriteStatusReg 0x01 //FLASH 写状态
  13. #define W25X_ReadData 0x03 //可低速下读FLASH数据
  14. #define W25X_FastReadData 0x0B //快速读取
  15. #define W25X_FastReadDual 0x3B
  16. #define W25X_PageProgram 0x02 //按页写FLASH
  17. #define W25X_BlockErase 0xD8
  18. #define W25X_SectorErase 0x20 //擦除FLASH扇区
  19. #define W25X_ChipErase 0xC7 //擦除FLASH块
  20. #define W25X_PowerDown 0xB9 //深度掉电模式功耗1uA
  21. #define W25X_ReleasePowerDown 0xAB //退出深度掉电模式
  22. #define W25X_DeviceID 0xAB
  23. #define W25X_ManufactDeviceID 0x90
  24. #define W25X_JedecDeviceID 0x9F //FLASH 读ID
  25. #define FLASH_CS_PIN GPIO_PIN_15
  26. #define FLASH_CS_PORT GPIOB
  27. #define SPI_FLASH_CS_LOW() HAL_GPIO_WritePin(FLASH_CS_PORT, FLASH_CS_PIN, GPIO_PIN_RESET);
  28. #define SPI_FLASH_CS_HIGH() HAL_GPIO_WritePin(FLASH_CS_PORT, FLASH_CS_PIN, GPIO_PIN_SET);
  29. static uint8_t spi1_flash_read_byte(void);
  30. static uint8_t spi1_flash_send_byte(uint8_t byte);
  31. static void spi1_flash_write_enable(void);
  32. void spi1_flash_wait_for_write_end(void) ;
  33. uint32_t spi_flash_read_ID(void);
  34. void spi1_flash_read(uint32_t addr,uint8_t *pdata, uint16_t size);
  35. void spi1_flash_page_write(uint32_t addr, uint8_t *pdata, uint16_t size);
  36. void spi1_flash_write(uint32_t addr, uint8_t *pdata, uint32_t size);
  37. void spi1_flash_sector_erase(uint32_t sector_addr);
  38. void spi1_flash_block_erase(void);
  39. void spi1_flash_enter_deep_power_down(void);
  40. void spi1_flash_release_from_deep_power_down(void);
  41. #endif