Mistake on this page?
Report an issue in GitHub or email us
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 
30 typedef struct flash_s flash_t;
31 
32 #if TARGET_FLASH_CMSIS_ALGO
33 #include "flash_data.h"
34 #endif
35 
36 #ifdef __cplusplus
37 extern "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  */
50 int32_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  */
57 int32_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  */
66 int32_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  */
77 int32_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  * This function does not do any check for address alignments or if size is aligned to a page size.
83  * @param obj The flash object
84  * @param address The sector starting address
85  * @param data The data buffer to be programmed
86  * @param size The number of bytes to program
87  * @return 0 for success, -1 for error
88  */
89 int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size);
90 
91 /** Get sector size
92  *
93  * @param obj The flash object
94  * @param address The sector starting address
95  * @return The size of a sector
96  */
97 uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address);
98 
99 /** Get page size
100  *
101  * The page size defines the writable page size
102  * @param obj The flash object
103  * @return The size of a page
104  */
105 uint32_t flash_get_page_size(const flash_t *obj);
106 
107 /** Get start address for the flash region
108  *
109  * @param obj The flash object
110  * @return The start address for the flash region
111  */
112 uint32_t flash_get_start_address(const flash_t *obj);
113 
114 /** Get the flash region size
115  *
116  * @param obj The flash object
117  * @return The flash region size
118  */
119 uint32_t flash_get_size(const flash_t *obj);
120 
121 /** Get the flash erase value
122  *
123  * @param obj The flash object
124  * @return The flash erase value
125  */
126 uint8_t flash_get_erase_value(const flash_t *obj);
127 
128 /**@}*/
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif
135 
136 #endif
137 
138 /** @}*/
uint32_t flash_get_start_address(const flash_t *obj)
Get start address for the flash region.
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
Erase one sector starting at defined address.
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.
uint8_t flash_get_erase_value(const flash_t *obj)
Get the flash erase value.
uint32_t flash_get_size(const flash_t *obj)
Get the flash region size.
int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size)
Program pages starting at defined address.
Target flash configuration For targets not supporting TrustZone, its flash_set_target_config must def...
Definition: flash_data.h:58
uint32_t flash_get_page_size(const flash_t *obj)
Get page size.
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
Get sector size.
int32_t flash_init(flash_t *obj)
Initialize the flash peripheral and the flash_t object.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.