obj_hal_w25qxx.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "dev_spi_conf.h"
  2. #ifdef USE_OBJ_HAL_W25QXX
  3. #ifndef OBJ_HAL_W25QXX_H
  4. #define OBJ_HAL_W25QXX_H
  5. #include "stm32f7xx.h"
  6. #include <stdio.h>
  7. //W25X系列/Q系列芯片列表
  8. //W25Q80 ID 0XEF13
  9. //W25Q16 ID 0XEF14
  10. //W25Q32 ID 0XEF15
  11. //W25Q64 ID 0XEF16
  12. //W25Q128 ID 0XEF17
  13. //W25Q256 ID 0XEF18
  14. //W25Q512 ID 0XEF19
  15. #define W25Q10 0XEF10
  16. #define W25Q20 0XEF11
  17. #define W25Q40 0XEF12
  18. #define W25Q80 0XEF13
  19. #define W25Q16 0XEF14
  20. #define W25Q32 0XEF15
  21. #define W25Q64 0XEF16
  22. #define W25Q128 0XEF17
  23. #define W25Q256 0XEF18
  24. #define W25Q512 0XEF19
  25. //////////////////////////////////////////////////////////////////////////////////
  26. //指令表
  27. #define W25X_WriteEnable 0x06
  28. #define W25X_WriteDisable 0x04
  29. #define W25X_ReadStatusReg1 0x05
  30. #define W25X_ReadStatusReg2 0x35
  31. #define W25X_ReadStatusReg3 0x15
  32. #define W25X_WriteStatusReg1 0x01
  33. #define W25X_WriteStatusReg2 0x31
  34. #define W25X_WriteStatusReg3 0x11
  35. #define W25X_ReadData 0x03
  36. #define W25X_FastReadData 0x0B
  37. #define W25X_FastReadDual 0x3B
  38. #define W25X_PageProgram 0x02
  39. #define W25X_BlockErase 0xD8
  40. #define W25X_SectorErase 0x20
  41. #define W25X_ChipErase 0xC7
  42. #define W25X_PowerDown 0xB9
  43. #define W25X_ReleasePowerDown 0xAB
  44. #define W25X_DeviceID 0xAB
  45. #define W25X_ManufactDeviceID 0x90
  46. #define W25X_JedecDeviceID 0x9F
  47. #define W25X_Enable4ByteAddr 0xB7
  48. #define W25X_Exit4ByteAddr 0xE9
  49. typedef struct
  50. {
  51. uint16_t W25Q_TYPE;
  52. uint16_t W25Q_OK;
  53. uint8_t UniqID[8];
  54. uint16_t PageSize;
  55. uint32_t PageCount;
  56. uint32_t SectorSize;
  57. uint32_t SectorCount;
  58. uint32_t BlockSize;
  59. uint32_t BlockCount; // so block trong chip flash
  60. uint32_t CapacityInKiloByte;
  61. uint8_t StatusRegister[3];
  62. }w25qxx_object_t;
  63. extern w25qxx_object_t w25qxx_obj ;
  64. void W25QXX_Init(void);
  65. uint16_t W25QXX_ReadID(void); //读取FLASH ID
  66. uint8_t W25QXX_ReadSR(uint8_t regno); //读取状态寄存器
  67. void W25QXX_4ByteAddr_Enable(void); //使能4字节地址模式
  68. void W25QXX_Write_SR(uint8_t regno,uint8_t sr); //写状态寄存器
  69. void W25QXX_Write_Enable(void); //写使能
  70. void W25QXX_Write_Disable(void); //写保护
  71. void W25QXX_Write_NoCheck(uint8_t * pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
  72. void W25QXX_Read(uint8_t * pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead); //读取flash
  73. void W25QXX_Write(uint8_t * pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);//写入flash
  74. void W25QXX_Erase_Chip(void); //整片擦除
  75. void W25QXX_Erase_Sector(uint32_t Dst_Addr); //扇区擦除
  76. void W25QXX_Wait_Busy(void); //等待空闲
  77. void W25QXX_PowerDown(void); //进入掉电模式
  78. void W25QXX_WAKEUP(void); //唤醒
  79. uint16_t W25QXX_ID_OK(void);
  80. #endif
  81. #endif //-----------------------USE_OBJ_HAL_W25QXX--------------------------------------//