spi_flash.h 1.1 KB

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