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