spi_flash.h 1.0 KB

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