spi_flash.h 976 B

123456789101112131415161718192021222324252627282930313233343536
  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. typedef struct {
  18. bool present;
  19. // uint16_t sector_size;
  20. uint32_t sector_size;
  21. uint8_t sector_erase_op;
  22. uint16_t sector_count;
  23. } spi_flash_desc_t;
  24. extern spi_flash_desc_t spi_flash_desc;
  25. extern bool spi_flash_init(void);
  26. extern ssize_t spi_flash_read(int addr, void *buf, size_t len, uint32_t timeout);
  27. extern ssize_t spi_flash_write(int addr, const void *buf, size_t len, uint32_t timeout);
  28. extern int spi_flash_erase_sector(int addr, uint32_t timeout);
  29. extern int spi_flash_chip_erase(uint32_t timeout);
  30. extern void spi_flash_test(void);
  31. #endif /* SPI_FLASH_H */