flash.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef __FLASH_H
  2. #define __FLASH_H
  3. #include <stm32f10x.h>
  4. #define FLASH_PAGE_SIZE 256
  5. #define FLASH_SECTOR_SIZE 4096
  6. #define FLASH_SECTOR_COUNT 512
  7. #define FLASH_BLOCK_SIZE 65536
  8. #define FLASH_PAGES_PER_SECTOR FLASH_SECTOR_SIZE/FLASH_PAGE_SIZE
  9. #define SPI_FLASH_CS PCout(4) //选中FLASH
  10. ////////////////////////////////////////////////////////////////////////////
  11. //W25X16读写
  12. #define FLASH_ID 0XEF14
  13. //指令表
  14. #define W25X_WriteEnable 0x06
  15. #define W25X_WriteDisable 0x04
  16. #define W25X_ReadStatusReg 0x05
  17. #define W25X_WriteStatusReg 0x01
  18. #define W25X_ReadData 0x03
  19. #define W25X_FastReadData 0x0B
  20. #define W25X_FastReadDual 0x3B
  21. #define W25X_PageProgram 0x02
  22. #define W25X_BlockErase 0xD8
  23. #define W25X_SectorErase 0x20
  24. #define W25X_ChipErase 0xC7
  25. #define W25X_PowerDown 0xB9
  26. #define W25X_ReleasePowerDown 0xAB
  27. #define W25X_DeviceID 0xAB
  28. #define W25X_ManufactDeviceID 0x90
  29. #define W25X_JedecDeviceID 0x9F
  30. uint8_t SPI_Flash_Init(void);
  31. u16 SPI_Flash_ReadID(void); //读取FLASH ID
  32. u8 SPI_Flash_ReadSR(void); //读取状态寄存器
  33. void SPI_FLASH_Write_SR(u8 sr); //写状态寄存器
  34. void SPI_FLASH_Write_Enable(void); //写使能
  35. void SPI_FLASH_Write_Disable(void); //写保护
  36. void SPI_Flash_Read(u8* pBuffer,u32 ReadAddr,u16 NumByteToRead); //读取flash
  37. void SPI_Flash_Write(u8* pBuffer,u32 WriteAddr,u16 NumByteToWrite);//写入flash
  38. void SPI_Flash_Erase_Chip(void); //整片擦除
  39. void SPI_Flash_Erase_Sector(u32 Dst_Addr);//扇区擦除
  40. void SPI_Flash_Wait_Busy(void); //等待空闲
  41. void SPI_Flash_PowerDown(void); //进入掉电模式
  42. void SPI_Flash_WAKEUP(void); //唤醒
  43. void W25X_Read_Sector(uint32_t nSector, u8* pBuffer);
  44. void W25X_Write_Sector(uint32_t nSector, u8* pBuffer);
  45. #endif