Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
hal/flash_api.h@2:4364577b5ad8, 2020-11-09 (annotated)
- Committer:
- elijahsj
- Date:
- Mon Nov 09 00:33:19 2020 -0500
- Revision:
- 2:4364577b5ad8
- Parent:
- 1:8a094db1347f
copied mbed library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| elijahsj | 1:8a094db1347f | 1 | /** \addtogroup hal */ |
| elijahsj | 1:8a094db1347f | 2 | /** @{*/ |
| elijahsj | 1:8a094db1347f | 3 | |
| elijahsj | 1:8a094db1347f | 4 | /* mbed Microcontroller Library |
| elijahsj | 1:8a094db1347f | 5 | * Copyright (c) 2017 ARM Limited |
| elijahsj | 1:8a094db1347f | 6 | * |
| elijahsj | 1:8a094db1347f | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| elijahsj | 1:8a094db1347f | 8 | * you may not use this file except in compliance with the License. |
| elijahsj | 1:8a094db1347f | 9 | * You may obtain a copy of the License at |
| elijahsj | 1:8a094db1347f | 10 | * |
| elijahsj | 1:8a094db1347f | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| elijahsj | 1:8a094db1347f | 12 | * |
| elijahsj | 1:8a094db1347f | 13 | * Unless required by applicable law or agreed to in writing, software |
| elijahsj | 1:8a094db1347f | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| elijahsj | 1:8a094db1347f | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| elijahsj | 1:8a094db1347f | 16 | * See the License for the specific language governing permissions and |
| elijahsj | 1:8a094db1347f | 17 | * limitations under the License. |
| elijahsj | 1:8a094db1347f | 18 | */ |
| elijahsj | 1:8a094db1347f | 19 | #ifndef MBED_FLASH_API_H |
| elijahsj | 1:8a094db1347f | 20 | #define MBED_FLASH_API_H |
| elijahsj | 1:8a094db1347f | 21 | |
| elijahsj | 1:8a094db1347f | 22 | #include "device.h" |
| elijahsj | 1:8a094db1347f | 23 | #include <stdint.h> |
| elijahsj | 1:8a094db1347f | 24 | |
| elijahsj | 1:8a094db1347f | 25 | #if DEVICE_FLASH |
| elijahsj | 1:8a094db1347f | 26 | |
| elijahsj | 1:8a094db1347f | 27 | #define MBED_FLASH_INVALID_SIZE 0xFFFFFFFF |
| elijahsj | 1:8a094db1347f | 28 | |
| elijahsj | 1:8a094db1347f | 29 | typedef struct flash_s flash_t; |
| elijahsj | 1:8a094db1347f | 30 | |
| elijahsj | 1:8a094db1347f | 31 | #if TARGET_FLASH_CMSIS_ALGO |
| elijahsj | 1:8a094db1347f | 32 | #include "flash_data.h" |
| elijahsj | 1:8a094db1347f | 33 | #endif |
| elijahsj | 1:8a094db1347f | 34 | |
| elijahsj | 1:8a094db1347f | 35 | #ifdef __cplusplus |
| elijahsj | 1:8a094db1347f | 36 | extern "C" { |
| elijahsj | 1:8a094db1347f | 37 | #endif |
| elijahsj | 1:8a094db1347f | 38 | |
| elijahsj | 1:8a094db1347f | 39 | /** |
| elijahsj | 1:8a094db1347f | 40 | * \defgroup flash_hal Flash HAL API |
| elijahsj | 1:8a094db1347f | 41 | * @{ |
| elijahsj | 1:8a094db1347f | 42 | */ |
| elijahsj | 1:8a094db1347f | 43 | |
| elijahsj | 1:8a094db1347f | 44 | /** Initialize the flash peripheral and the flash_t object |
| elijahsj | 1:8a094db1347f | 45 | * |
| elijahsj | 1:8a094db1347f | 46 | * @param obj The flash object |
| elijahsj | 1:8a094db1347f | 47 | * @return 0 for success, -1 for error |
| elijahsj | 1:8a094db1347f | 48 | */ |
| elijahsj | 1:8a094db1347f | 49 | int32_t flash_init(flash_t *obj); |
| elijahsj | 1:8a094db1347f | 50 | |
| elijahsj | 1:8a094db1347f | 51 | /** Uninitialize the flash peripheral and the flash_t object |
| elijahsj | 1:8a094db1347f | 52 | * |
| elijahsj | 1:8a094db1347f | 53 | * @param obj The flash object |
| elijahsj | 1:8a094db1347f | 54 | * @return 0 for success, -1 for error |
| elijahsj | 1:8a094db1347f | 55 | */ |
| elijahsj | 1:8a094db1347f | 56 | int32_t flash_free(flash_t *obj); |
| elijahsj | 1:8a094db1347f | 57 | |
| elijahsj | 1:8a094db1347f | 58 | /** Erase one sector starting at defined address |
| elijahsj | 1:8a094db1347f | 59 | * |
| elijahsj | 1:8a094db1347f | 60 | * The address should be at sector boundary. This function does not do any check for address alignments |
| elijahsj | 1:8a094db1347f | 61 | * @param obj The flash object |
| elijahsj | 1:8a094db1347f | 62 | * @param address The sector starting address |
| elijahsj | 1:8a094db1347f | 63 | * @return 0 for success, -1 for error |
| elijahsj | 1:8a094db1347f | 64 | */ |
| elijahsj | 1:8a094db1347f | 65 | int32_t flash_erase_sector(flash_t *obj, uint32_t address); |
| elijahsj | 1:8a094db1347f | 66 | |
| elijahsj | 1:8a094db1347f | 67 | /** Read data starting at defined address |
| elijahsj | 1:8a094db1347f | 68 | * |
| elijahsj | 1:8a094db1347f | 69 | * This function has a WEAK implementation using memcpy for backwards compatibility. |
| elijahsj | 1:8a094db1347f | 70 | * @param obj The flash object |
| elijahsj | 1:8a094db1347f | 71 | * @param address Address to begin reading from |
| elijahsj | 1:8a094db1347f | 72 | * @param data The buffer to read data into |
| elijahsj | 1:8a094db1347f | 73 | * @param size The number of bytes to read |
| elijahsj | 1:8a094db1347f | 74 | * @return 0 for success, -1 for error |
| elijahsj | 1:8a094db1347f | 75 | */ |
| elijahsj | 1:8a094db1347f | 76 | int32_t flash_read(flash_t *obj, uint32_t address, uint8_t *data, uint32_t size); |
| elijahsj | 1:8a094db1347f | 77 | |
| elijahsj | 1:8a094db1347f | 78 | /** Program pages starting at defined address |
| elijahsj | 1:8a094db1347f | 79 | * |
| elijahsj | 1:8a094db1347f | 80 | * The pages should not cross multiple sectors. |
| elijahsj | 1:8a094db1347f | 81 | * This function does not do any check for address alignments or if size is aligned to a page size. |
| elijahsj | 1:8a094db1347f | 82 | * @param obj The flash object |
| elijahsj | 1:8a094db1347f | 83 | * @param address The sector starting address |
| elijahsj | 1:8a094db1347f | 84 | * @param data The data buffer to be programmed |
| elijahsj | 1:8a094db1347f | 85 | * @param size The number of bytes to program |
| elijahsj | 1:8a094db1347f | 86 | * @return 0 for success, -1 for error |
| elijahsj | 1:8a094db1347f | 87 | */ |
| elijahsj | 1:8a094db1347f | 88 | int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size); |
| elijahsj | 1:8a094db1347f | 89 | |
| elijahsj | 1:8a094db1347f | 90 | /** Get sector size |
| elijahsj | 1:8a094db1347f | 91 | * |
| elijahsj | 1:8a094db1347f | 92 | * @param obj The flash object |
| elijahsj | 1:8a094db1347f | 93 | * @param address The sector starting address |
| elijahsj | 1:8a094db1347f | 94 | * @return The size of a sector |
| elijahsj | 1:8a094db1347f | 95 | */ |
| elijahsj | 1:8a094db1347f | 96 | uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address); |
| elijahsj | 1:8a094db1347f | 97 | |
| elijahsj | 1:8a094db1347f | 98 | /** Get page size |
| elijahsj | 1:8a094db1347f | 99 | * |
| elijahsj | 1:8a094db1347f | 100 | * The page size defines the writable page size |
| elijahsj | 1:8a094db1347f | 101 | * @param obj The flash object |
| elijahsj | 1:8a094db1347f | 102 | * @return The size of a page |
| elijahsj | 1:8a094db1347f | 103 | */ |
| elijahsj | 1:8a094db1347f | 104 | uint32_t flash_get_page_size(const flash_t *obj); |
| elijahsj | 1:8a094db1347f | 105 | |
| elijahsj | 1:8a094db1347f | 106 | /** Get start address for the flash region |
| elijahsj | 1:8a094db1347f | 107 | * |
| elijahsj | 1:8a094db1347f | 108 | * @param obj The flash object |
| elijahsj | 1:8a094db1347f | 109 | * @return The start address for the flash region |
| elijahsj | 1:8a094db1347f | 110 | */ |
| elijahsj | 1:8a094db1347f | 111 | uint32_t flash_get_start_address(const flash_t *obj); |
| elijahsj | 1:8a094db1347f | 112 | |
| elijahsj | 1:8a094db1347f | 113 | /** Get the flash region size |
| elijahsj | 1:8a094db1347f | 114 | * |
| elijahsj | 1:8a094db1347f | 115 | * @param obj The flash object |
| elijahsj | 1:8a094db1347f | 116 | * @return The flash region size |
| elijahsj | 1:8a094db1347f | 117 | */ |
| elijahsj | 1:8a094db1347f | 118 | uint32_t flash_get_size(const flash_t *obj); |
| elijahsj | 1:8a094db1347f | 119 | |
| elijahsj | 1:8a094db1347f | 120 | /**@}*/ |
| elijahsj | 1:8a094db1347f | 121 | |
| elijahsj | 1:8a094db1347f | 122 | #ifdef __cplusplus |
| elijahsj | 1:8a094db1347f | 123 | } |
| elijahsj | 1:8a094db1347f | 124 | #endif |
| elijahsj | 1:8a094db1347f | 125 | |
| elijahsj | 1:8a094db1347f | 126 | #endif |
| elijahsj | 1:8a094db1347f | 127 | |
| elijahsj | 1:8a094db1347f | 128 | #endif |
| elijahsj | 1:8a094db1347f | 129 | |
| elijahsj | 1:8a094db1347f | 130 | /** @}*/ |