spiflash.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @file spiflash.c
  3. * @author chipsea
  4. * @brief
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. #ifndef __SPIFLASH_H__
  11. #define __SPIFLASH_H__
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include "types.h"
  16. #include "spi.h"
  17. /*gd25q16 cmd define*/
  18. #define FLASH_WREN 0x06
  19. #define FLASH_WRDIS 0x04
  20. #define FLASH_CE 0x60
  21. //#define FLASH_CE 0xC7
  22. #define FLASH_DP 0xB9
  23. #define FLASH_RDI 0xAB
  24. #define FLASH_SE 0x20
  25. #define FLASH_BE_32KB 0x52
  26. #define FLASH_BE_64KB 0xD8
  27. #define FLASH_WRSR 0x01
  28. #define FLASH_RDID 0x9F
  29. #define FLASH_RDSR_LOW 0x05
  30. #define FLASH_RDSR_HIGH 0x35
  31. #define FLASH_PP 0x02
  32. #define FLASH_READ 0x03
  33. #define FLASH_PES 0x75
  34. #define FLASH_PER 0x7A
  35. extern uint32_t spiflash_space;
  36. typedef enum{
  37. FLASH_ERROR = 0,
  38. FLASH_IDLE = 1,
  39. FLASH_ERASING = 2,
  40. FALSH_DATA_WRITING = 3,
  41. FLASH_STATUS_WRITEING = 4,
  42. FLASH_READING = 5
  43. }FLASH_STATUS_e;
  44. extern hal_spi_t spiflash_spi;
  45. /*gd25q16 api for hardware debug*/
  46. uint32_t spiflash_read_identification(void);
  47. uint16_t spiflash_read_status_register(uint8_t bitsSel);
  48. bool spiflash_bus_busy(void);
  49. void spiflash_program_erase_suspend(void);
  50. void spiflash_program_erase_resume(void);
  51. void spiflash_deep_powerdown(void);
  52. void spiflash_release_from_powerdown(void);
  53. void spiflash_write_enable(void);
  54. void spiflash_write_disable(void);
  55. void spiflash_chip_erase(void);
  56. void spiflash_sector_erase(uint32_t addr);
  57. void spiflash_block_erase_32KB(uint32_t addr);
  58. void spiflash_block_erase_64KB(uint32_t addr);
  59. void spiflash_write_status_register(uint8_t data);
  60. void spiflash_write(uint32_t addr,uint8_t* tx_buf,uint16_t tx_len);
  61. void spiflash_read(uint32_t addr,uint8_t* rx_buf,uint16_t rx_len);
  62. int spiflash_init(void);
  63. /*gd25q16 api for user develop*/
  64. int vendorflash_init(void);
  65. int vendorflash_read(uint32_t addr,uint8_t *data,uint16_t len);
  66. int vendorflash_erase(uint32_t addr,uint32_t len);
  67. int vendorflash_write(uint32_t addr,const uint8_t *data,uint16_t len);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif