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-os/drivers/FlashIAP.h@0:fb8047b156bb, 2020-01-15 (annotated)
- Committer:
- rahul_dahiya
- Date:
- Wed Jan 15 15:57:15 2020 +0530
- Revision:
- 0:fb8047b156bb
STM32F7 LWIP
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rahul_dahiya |
0:fb8047b156bb | 1 | /* mbed Microcontroller Library |
rahul_dahiya |
0:fb8047b156bb | 2 | * Copyright (c) 2017 ARM Limited |
rahul_dahiya |
0:fb8047b156bb | 3 | * |
rahul_dahiya |
0:fb8047b156bb | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
rahul_dahiya |
0:fb8047b156bb | 5 | * of this software and associated documentation files (the "Software"), to deal |
rahul_dahiya |
0:fb8047b156bb | 6 | * in the Software without restriction, including without limitation the rights |
rahul_dahiya |
0:fb8047b156bb | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
rahul_dahiya |
0:fb8047b156bb | 8 | * copies of the Software, and to permit persons to whom the Software is |
rahul_dahiya |
0:fb8047b156bb | 9 | * furnished to do so, subject to the following conditions: |
rahul_dahiya |
0:fb8047b156bb | 10 | * |
rahul_dahiya |
0:fb8047b156bb | 11 | * The above copyright notice and this permission notice shall be included in |
rahul_dahiya |
0:fb8047b156bb | 12 | * all copies or substantial portions of the Software. |
rahul_dahiya |
0:fb8047b156bb | 13 | * |
rahul_dahiya |
0:fb8047b156bb | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
rahul_dahiya |
0:fb8047b156bb | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
rahul_dahiya |
0:fb8047b156bb | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
rahul_dahiya |
0:fb8047b156bb | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
rahul_dahiya |
0:fb8047b156bb | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
rahul_dahiya |
0:fb8047b156bb | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
rahul_dahiya |
0:fb8047b156bb | 20 | * SOFTWARE. |
rahul_dahiya |
0:fb8047b156bb | 21 | */ |
rahul_dahiya |
0:fb8047b156bb | 22 | #ifndef MBED_FLASHIAP_H |
rahul_dahiya |
0:fb8047b156bb | 23 | #define MBED_FLASHIAP_H |
rahul_dahiya |
0:fb8047b156bb | 24 | |
rahul_dahiya |
0:fb8047b156bb | 25 | #if defined (DEVICE_FLASH) || defined(DOXYGEN_ONLY) |
rahul_dahiya |
0:fb8047b156bb | 26 | |
rahul_dahiya |
0:fb8047b156bb | 27 | #include "flash_api.h" |
rahul_dahiya |
0:fb8047b156bb | 28 | #include "platform/SingletonPtr.h" |
rahul_dahiya |
0:fb8047b156bb | 29 | #include "platform/PlatformMutex.h" |
rahul_dahiya |
0:fb8047b156bb | 30 | #include "platform/NonCopyable.h" |
rahul_dahiya |
0:fb8047b156bb | 31 | |
rahul_dahiya |
0:fb8047b156bb | 32 | namespace mbed { |
rahul_dahiya |
0:fb8047b156bb | 33 | |
rahul_dahiya |
0:fb8047b156bb | 34 | /** \addtogroup drivers */ |
rahul_dahiya |
0:fb8047b156bb | 35 | |
rahul_dahiya |
0:fb8047b156bb | 36 | /** Flash IAP driver. It invokes flash HAL functions. |
rahul_dahiya |
0:fb8047b156bb | 37 | * |
rahul_dahiya |
0:fb8047b156bb | 38 | * @note Synchronization level: Thread safe |
rahul_dahiya |
0:fb8047b156bb | 39 | * @ingroup drivers |
rahul_dahiya |
0:fb8047b156bb | 40 | */ |
rahul_dahiya |
0:fb8047b156bb | 41 | class FlashIAP : private NonCopyable<FlashIAP> { |
rahul_dahiya |
0:fb8047b156bb | 42 | public: |
rahul_dahiya |
0:fb8047b156bb | 43 | FlashIAP(); |
rahul_dahiya |
0:fb8047b156bb | 44 | ~FlashIAP(); |
rahul_dahiya |
0:fb8047b156bb | 45 | |
rahul_dahiya |
0:fb8047b156bb | 46 | /** Initialize a flash IAP device |
rahul_dahiya |
0:fb8047b156bb | 47 | * |
rahul_dahiya |
0:fb8047b156bb | 48 | * Should be called once per lifetime of the object. |
rahul_dahiya |
0:fb8047b156bb | 49 | * @return 0 on success or a negative error code on failure |
rahul_dahiya |
0:fb8047b156bb | 50 | */ |
rahul_dahiya |
0:fb8047b156bb | 51 | int init(); |
rahul_dahiya |
0:fb8047b156bb | 52 | |
rahul_dahiya |
0:fb8047b156bb | 53 | /** Deinitialize a flash IAP device |
rahul_dahiya |
0:fb8047b156bb | 54 | * |
rahul_dahiya |
0:fb8047b156bb | 55 | * @return 0 on success or a negative error code on failure |
rahul_dahiya |
0:fb8047b156bb | 56 | */ |
rahul_dahiya |
0:fb8047b156bb | 57 | int deinit(); |
rahul_dahiya |
0:fb8047b156bb | 58 | |
rahul_dahiya |
0:fb8047b156bb | 59 | /** Read data from a flash device. |
rahul_dahiya |
0:fb8047b156bb | 60 | * |
rahul_dahiya |
0:fb8047b156bb | 61 | * This method invokes memcpy - reads number of bytes from the address |
rahul_dahiya |
0:fb8047b156bb | 62 | * |
rahul_dahiya |
0:fb8047b156bb | 63 | * @param buffer Buffer to write to |
rahul_dahiya |
0:fb8047b156bb | 64 | * @param addr Flash address to begin reading from |
rahul_dahiya |
0:fb8047b156bb | 65 | * @param size Size to read in bytes |
rahul_dahiya |
0:fb8047b156bb | 66 | * @return 0 on success, negative error code on failure |
rahul_dahiya |
0:fb8047b156bb | 67 | */ |
rahul_dahiya |
0:fb8047b156bb | 68 | int read(void *buffer, uint32_t addr, uint32_t size); |
rahul_dahiya |
0:fb8047b156bb | 69 | |
rahul_dahiya |
0:fb8047b156bb | 70 | /** Program data to pages |
rahul_dahiya |
0:fb8047b156bb | 71 | * |
rahul_dahiya |
0:fb8047b156bb | 72 | * The sectors must have been erased prior to being programmed |
rahul_dahiya |
0:fb8047b156bb | 73 | * |
rahul_dahiya |
0:fb8047b156bb | 74 | * @param buffer Buffer of data to be written |
rahul_dahiya |
0:fb8047b156bb | 75 | * @param addr Address of a page to begin writing to, must be a multiple of program and sector sizes |
rahul_dahiya |
0:fb8047b156bb | 76 | * @param size Size to write in bytes, must be a multiple of program and sector sizes |
rahul_dahiya |
0:fb8047b156bb | 77 | * @return 0 on success, negative error code on failure |
rahul_dahiya |
0:fb8047b156bb | 78 | */ |
rahul_dahiya |
0:fb8047b156bb | 79 | int program(const void *buffer, uint32_t addr, uint32_t size); |
rahul_dahiya |
0:fb8047b156bb | 80 | |
rahul_dahiya |
0:fb8047b156bb | 81 | /** Erase sectors |
rahul_dahiya |
0:fb8047b156bb | 82 | * |
rahul_dahiya |
0:fb8047b156bb | 83 | * The state of an erased sector is undefined until it has been programmed |
rahul_dahiya |
0:fb8047b156bb | 84 | * |
rahul_dahiya |
0:fb8047b156bb | 85 | * @param addr Address of a sector to begin erasing, must be a multiple of the sector size |
rahul_dahiya |
0:fb8047b156bb | 86 | * @param size Size to erase in bytes, must be a multiple of the sector size |
rahul_dahiya |
0:fb8047b156bb | 87 | * @return 0 on success, negative error code on failure |
rahul_dahiya |
0:fb8047b156bb | 88 | */ |
rahul_dahiya |
0:fb8047b156bb | 89 | int erase(uint32_t addr, uint32_t size); |
rahul_dahiya |
0:fb8047b156bb | 90 | |
rahul_dahiya |
0:fb8047b156bb | 91 | /** Get the sector size at the defined address |
rahul_dahiya |
0:fb8047b156bb | 92 | * |
rahul_dahiya |
0:fb8047b156bb | 93 | * Sector size might differ at address ranges. |
rahul_dahiya |
0:fb8047b156bb | 94 | * An example <0-0x1000, sector size=1024; 0x10000-0x20000, size=2048> |
rahul_dahiya |
0:fb8047b156bb | 95 | * |
rahul_dahiya |
0:fb8047b156bb | 96 | * @param addr Address of or inside the sector to query |
rahul_dahiya |
0:fb8047b156bb | 97 | * @return Size of a sector in bytes or MBED_FLASH_INVALID_SIZE if not mapped |
rahul_dahiya |
0:fb8047b156bb | 98 | */ |
rahul_dahiya |
0:fb8047b156bb | 99 | uint32_t get_sector_size(uint32_t addr) const; |
rahul_dahiya |
0:fb8047b156bb | 100 | |
rahul_dahiya |
0:fb8047b156bb | 101 | /** Get the flash start address |
rahul_dahiya |
0:fb8047b156bb | 102 | * |
rahul_dahiya |
0:fb8047b156bb | 103 | * @return Flash start address |
rahul_dahiya |
0:fb8047b156bb | 104 | */ |
rahul_dahiya |
0:fb8047b156bb | 105 | uint32_t get_flash_start() const; |
rahul_dahiya |
0:fb8047b156bb | 106 | |
rahul_dahiya |
0:fb8047b156bb | 107 | /** Get the flash size |
rahul_dahiya |
0:fb8047b156bb | 108 | * |
rahul_dahiya |
0:fb8047b156bb | 109 | * @return Flash size |
rahul_dahiya |
0:fb8047b156bb | 110 | */ |
rahul_dahiya |
0:fb8047b156bb | 111 | uint32_t get_flash_size() const; |
rahul_dahiya |
0:fb8047b156bb | 112 | |
rahul_dahiya |
0:fb8047b156bb | 113 | /** Get the program page size |
rahul_dahiya |
0:fb8047b156bb | 114 | * |
rahul_dahiya |
0:fb8047b156bb | 115 | * The page size defines the writable page size |
rahul_dahiya |
0:fb8047b156bb | 116 | * @return Size of a program page in bytes |
rahul_dahiya |
0:fb8047b156bb | 117 | */ |
rahul_dahiya |
0:fb8047b156bb | 118 | uint32_t get_page_size() const; |
rahul_dahiya |
0:fb8047b156bb | 119 | |
rahul_dahiya |
0:fb8047b156bb | 120 | private: |
rahul_dahiya |
0:fb8047b156bb | 121 | |
rahul_dahiya |
0:fb8047b156bb | 122 | /* Check if address and size are aligned to a sector |
rahul_dahiya |
0:fb8047b156bb | 123 | * |
rahul_dahiya |
0:fb8047b156bb | 124 | * @param addr Address of block to check for alignment |
rahul_dahiya |
0:fb8047b156bb | 125 | * @param size Size of block to check for alignment |
rahul_dahiya |
0:fb8047b156bb | 126 | * @return true if the block is sector aligned, false otherwise |
rahul_dahiya |
0:fb8047b156bb | 127 | */ |
rahul_dahiya |
0:fb8047b156bb | 128 | bool is_aligned_to_sector(uint32_t addr, uint32_t size); |
rahul_dahiya |
0:fb8047b156bb | 129 | |
rahul_dahiya |
0:fb8047b156bb | 130 | flash_t _flash; |
rahul_dahiya |
0:fb8047b156bb | 131 | static SingletonPtr<PlatformMutex> _mutex; |
rahul_dahiya |
0:fb8047b156bb | 132 | }; |
rahul_dahiya |
0:fb8047b156bb | 133 | |
rahul_dahiya |
0:fb8047b156bb | 134 | } /* namespace mbed */ |
rahul_dahiya |
0:fb8047b156bb | 135 | |
rahul_dahiya |
0:fb8047b156bb | 136 | #endif /* DEVICE_FLASH */ |
rahul_dahiya |
0:fb8047b156bb | 137 | |
rahul_dahiya |
0:fb8047b156bb | 138 | #endif /* MBED_FLASHIAP_H */ |