mbed-dev-f303

Committer:
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4
Date:
Tue Jun 14 09:21:18 2022 +0000
Revision:
0:bdf663c61a82
lib

Who changed what in which revision?

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