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