spi_flash.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef SPI_FLASH_H
  2. #define SPI_FLASH_H
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #ifdef PRINTF_STDLIB
  8. #include <stdio.h>
  9. #endif
  10. #ifdef PRINTF_CUSTOM
  11. #include "tinystdio.h"
  12. #endif
  13. #define SPI_FLASH_SECTOR_SIZE 4096
  14. #define SPI_FLASH_SECTORS_IN_BLOCK_NUMBER 16
  15. #define SPI_FLASH_BLOCK_SIZE 16//4
  16. #define SPI_FLASH_BLOCK_NUMBER 32
  17. #if defined ( __ICCARM__ )
  18. typedef int ssize_t;
  19. #endif
  20. typedef struct {
  21. bool present;
  22. // uint16_t sector_size;
  23. uint32_t sector_size;
  24. uint8_t sector_erase_op;
  25. uint16_t sector_count;
  26. } spi_flash_desc_t;
  27. extern spi_flash_desc_t spi_flash_desc;
  28. extern bool spi_flash_init(void);
  29. extern ssize_t spi_flash_read(int addr, void *buf, size_t len, uint32_t timeout);
  30. extern ssize_t spi_flash_write(int addr, const void *buf, size_t len, uint32_t timeout);
  31. extern int spi_flash_erase_sector(int addr, uint32_t timeout);
  32. extern int spi_flash_chip_erase(uint32_t timeout);
  33. extern void spi_flash_test(void);
  34. #endif /* SPI_FLASH_H */