flash_api.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /** \addtogroup hal */
  2. /** @{*/
  3. /* mbed Microcontroller Library
  4. * Copyright (c) 2017 ARM Limited
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef MBED_FLASH_API_H
  19. #define MBED_FLASH_API_H
  20. #include "device.h"
  21. #include <stdint.h>
  22. #if DEVICE_FLASH
  23. #define MBED_FLASH_INVALID_SIZE 0xFFFFFFFF
  24. typedef struct flash_s flash_t;
  25. #if TARGET_FLASH_CMSIS_ALGO
  26. #include "flash_data.h"
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /**
  32. * \defgroup flash_hal Flash HAL API
  33. * @{
  34. */
  35. /** Initialize the flash peripheral and the flash_t object
  36. *
  37. * @param obj The flash object
  38. * @return 0 for success, -1 for error
  39. */
  40. int32_t flash_init(flash_t *obj);
  41. /** Uninitialize the flash peripheral and the flash_t object
  42. *
  43. * @param obj The flash object
  44. * @return 0 for success, -1 for error
  45. */
  46. int32_t flash_free(flash_t *obj);
  47. /** Erase one sector starting at defined address
  48. *
  49. * The address should be at sector boundary. This function does not do any check for address alignments
  50. * @param obj The flash object
  51. * @param address The sector starting address
  52. * @return 0 for success, -1 for error
  53. */
  54. int32_t flash_erase_sector(flash_t *obj, uint32_t address);
  55. /** Read data starting at defined address
  56. *
  57. * This function has a WEAK implementation using memcpy for backwards compatibility.
  58. * @param obj The flash object
  59. * @param address Address to begin reading from
  60. * @param data The buffer to read data into
  61. * @param size The number of bytes to read
  62. * @return 0 for success, -1 for error
  63. */
  64. int32_t flash_read(flash_t *obj, uint32_t address, uint8_t *data, uint32_t size);
  65. /** Program pages starting at defined address
  66. *
  67. * The pages should not cross multiple sectors.
  68. * This function does not do any check for address alignments or if size is aligned to a page size.
  69. * @param obj The flash object
  70. * @param address The sector starting address
  71. * @param data The data buffer to be programmed
  72. * @param size The number of bytes to program
  73. * @return 0 for success, -1 for error
  74. */
  75. int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size);
  76. /** Get sector size
  77. *
  78. * @param obj The flash object
  79. * @param address The sector starting address
  80. * @return The size of a sector
  81. */
  82. uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address);
  83. /** Get page size
  84. *
  85. * The page size defines the writable page size
  86. * @param obj The flash object
  87. * @return The size of a page
  88. */
  89. uint32_t flash_get_page_size(const flash_t *obj);
  90. /** Get start address for the flash region
  91. *
  92. * @param obj The flash object
  93. * @return The start address for the flash region
  94. */
  95. uint32_t flash_get_start_address(const flash_t *obj);
  96. /** Get the flash region size
  97. *
  98. * @param obj The flash object
  99. * @return The flash region size
  100. */
  101. uint32_t flash_get_size(const flash_t *obj);
  102. /**@}*/
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif
  107. #endif
  108. /** @}*/