furi_hal_flash.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. /** Init flash, applying necessary workarounds
  6. */
  7. void furi_hal_flash_init();
  8. /** Get flash base address
  9. *
  10. * @return pointer to flash base
  11. */
  12. size_t furi_hal_flash_get_base();
  13. /** Get flash read block size
  14. *
  15. * @return size in bytes
  16. */
  17. size_t furi_hal_flash_get_read_block_size();
  18. /** Get flash write block size
  19. *
  20. * @return size in bytes
  21. */
  22. size_t furi_hal_flash_get_write_block_size();
  23. /** Get flash page size
  24. *
  25. * @return size in bytes
  26. */
  27. size_t furi_hal_flash_get_page_size();
  28. /** Get expected flash cycles count
  29. *
  30. * @return count of erase-write operations
  31. */
  32. size_t furi_hal_flash_get_cycles_count();
  33. /** Get free flash start address
  34. *
  35. * @return pointer to free region start
  36. */
  37. const void* furi_hal_flash_get_free_start_address();
  38. /** Get free flash end address
  39. *
  40. * @return pointer to free region end
  41. */
  42. const void* furi_hal_flash_get_free_end_address();
  43. /** Get first free page start address
  44. *
  45. * @return first free page memory address
  46. */
  47. size_t furi_hal_flash_get_free_page_start_address();
  48. /** Get free page count
  49. *
  50. * @return free page count
  51. */
  52. size_t furi_hal_flash_get_free_page_count();
  53. /** Erase Flash
  54. *
  55. * @warning locking operation with critical section, stales execution
  56. *
  57. * @param page The page to erase
  58. *
  59. * @return true on success
  60. */
  61. bool furi_hal_flash_erase(uint8_t page);
  62. /** Write double word (64 bits)
  63. *
  64. * @warning locking operation with critical section, stales execution
  65. *
  66. * @param address destination address, must be double word aligned.
  67. * @param data data to write
  68. *
  69. * @return true on success
  70. */
  71. bool furi_hal_flash_write_dword(size_t address, uint64_t data);
  72. /** Write aligned page data (up to page size)
  73. *
  74. * @warning locking operation with critical section, stales execution
  75. *
  76. * @param address destination address, must be page aligned.
  77. * @param data data to write
  78. * @param length data length
  79. *
  80. * @return true on success
  81. */
  82. bool furi_hal_flash_program_page(const uint8_t page, const uint8_t* data, uint16_t length);
  83. /** Get flash page number for address
  84. *
  85. * @return page number, -1 for invalid address
  86. */
  87. int16_t furi_hal_flash_get_page_number(size_t address);