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