The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
drivers/FlashIAP.h@138:093f2bd7b9eb, 2017-03-14 (annotated)
- Committer:
- <>
- Date:
- Tue Mar 14 16:20:51 2017 +0000
- Revision:
- 138:093f2bd7b9eb
- Child:
- 145:64910690c574
Release 138 of the mbed library
Ports for Upcoming Targets
Fixes and Changes
3716: fix for issue #3715: correction in startup files for ARM and IAR, alignment of system_stm32f429xx.c files https://github.com/ARMmbed/mbed-os/pull/3716
3741: STM32 remove warning in hal_tick_32b.c file https://github.com/ARMmbed/mbed-os/pull/3741
3780: STM32L4 : Fix GPIO G port compatibility https://github.com/ARMmbed/mbed-os/pull/3780
3831: NCS36510: SPISLAVE enabled (Conflict resolved) https://github.com/ARMmbed/mbed-os/pull/3831
3836: Allow to redefine nRF's PSTORAGE_NUM_OF_PAGES outside of the mbed-os https://github.com/ARMmbed/mbed-os/pull/3836
3840: STM32: gpio SPEED - always set High Speed by default https://github.com/ARMmbed/mbed-os/pull/3840
3844: STM32 GPIO: Typo correction. Update comment (GPIO_IP_WITHOUT_BRR) https://github.com/ARMmbed/mbed-os/pull/3844
3850: STM32: change spi error to debug warning https://github.com/ARMmbed/mbed-os/pull/3850
3860: Define GPIO_IP_WITHOUT_BRR for xDot platform https://github.com/ARMmbed/mbed-os/pull/3860
3880: DISCO_F469NI: allow the use of CAN2 instance when CAN1 is not activated https://github.com/ARMmbed/mbed-os/pull/3880
3795: Fix pwm period calc https://github.com/ARMmbed/mbed-os/pull/3795
3828: STM32 CAN API: correct format and type https://github.com/ARMmbed/mbed-os/pull/3828
3842: TARGET_NRF: corrected spi_init() to properly handle re-initialization https://github.com/ARMmbed/mbed-os/pull/3842
3843: STM32L476xG: set APB2 clock to 80MHz (instead of 40MHz) https://github.com/ARMmbed/mbed-os/pull/3843
3879: NUCLEO_F446ZE: Add missing AnalogIn pins on PF_3, PF_5 and PF_10. https://github.com/ARMmbed/mbed-os/pull/3879
3902: Fix heap and stack size for NUCLEO_F746ZG https://github.com/ARMmbed/mbed-os/pull/3902
3829: can_write(): return error code when no tx mailboxes are available https://github.com/ARMmbed/mbed-os/pull/3829
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 138:093f2bd7b9eb | 1 | /* mbed Microcontroller Library |
<> | 138:093f2bd7b9eb | 2 | * Copyright (c) 2017 ARM Limited |
<> | 138:093f2bd7b9eb | 3 | * |
<> | 138:093f2bd7b9eb | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
<> | 138:093f2bd7b9eb | 5 | * of this software and associated documentation files (the "Software"), to deal |
<> | 138:093f2bd7b9eb | 6 | * in the Software without restriction, including without limitation the rights |
<> | 138:093f2bd7b9eb | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
<> | 138:093f2bd7b9eb | 8 | * copies of the Software, and to permit persons to whom the Software is |
<> | 138:093f2bd7b9eb | 9 | * furnished to do so, subject to the following conditions: |
<> | 138:093f2bd7b9eb | 10 | * |
<> | 138:093f2bd7b9eb | 11 | * The above copyright notice and this permission notice shall be included in |
<> | 138:093f2bd7b9eb | 12 | * all copies or substantial portions of the Software. |
<> | 138:093f2bd7b9eb | 13 | * |
<> | 138:093f2bd7b9eb | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
<> | 138:093f2bd7b9eb | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
<> | 138:093f2bd7b9eb | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
<> | 138:093f2bd7b9eb | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
<> | 138:093f2bd7b9eb | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
<> | 138:093f2bd7b9eb | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
<> | 138:093f2bd7b9eb | 20 | * SOFTWARE. |
<> | 138:093f2bd7b9eb | 21 | */ |
<> | 138:093f2bd7b9eb | 22 | #ifndef MBED_FLASHIAP_H |
<> | 138:093f2bd7b9eb | 23 | #define MBED_FLASHIAP_H |
<> | 138:093f2bd7b9eb | 24 | |
<> | 138:093f2bd7b9eb | 25 | #ifdef DEVICE_FLASH |
<> | 138:093f2bd7b9eb | 26 | |
<> | 138:093f2bd7b9eb | 27 | #include "flash_api.h" |
<> | 138:093f2bd7b9eb | 28 | #include "platform/SingletonPtr.h" |
<> | 138:093f2bd7b9eb | 29 | #include "platform/PlatformMutex.h" |
<> | 138:093f2bd7b9eb | 30 | |
<> | 138:093f2bd7b9eb | 31 | namespace mbed { |
<> | 138:093f2bd7b9eb | 32 | |
<> | 138:093f2bd7b9eb | 33 | /** \addtogroup drivers */ |
<> | 138:093f2bd7b9eb | 34 | /** @{*/ |
<> | 138:093f2bd7b9eb | 35 | |
<> | 138:093f2bd7b9eb | 36 | /** Flash IAP driver. It invokes flash HAL functions. |
<> | 138:093f2bd7b9eb | 37 | * |
<> | 138:093f2bd7b9eb | 38 | * Note Synchronization level: Thread safe |
<> | 138:093f2bd7b9eb | 39 | */ |
<> | 138:093f2bd7b9eb | 40 | class FlashIAP { |
<> | 138:093f2bd7b9eb | 41 | public: |
<> | 138:093f2bd7b9eb | 42 | FlashIAP(); |
<> | 138:093f2bd7b9eb | 43 | ~FlashIAP(); |
<> | 138:093f2bd7b9eb | 44 | |
<> | 138:093f2bd7b9eb | 45 | /** Initialize a flash IAP device |
<> | 138:093f2bd7b9eb | 46 | * |
<> | 138:093f2bd7b9eb | 47 | * Should be called once per lifetime of the object. |
<> | 138:093f2bd7b9eb | 48 | * @return 0 on success or a negative error code on failure |
<> | 138:093f2bd7b9eb | 49 | */ |
<> | 138:093f2bd7b9eb | 50 | int init(); |
<> | 138:093f2bd7b9eb | 51 | |
<> | 138:093f2bd7b9eb | 52 | /** Deinitialize a flash IAP device |
<> | 138:093f2bd7b9eb | 53 | * |
<> | 138:093f2bd7b9eb | 54 | * @return 0 on success or a negative error code on failure |
<> | 138:093f2bd7b9eb | 55 | */ |
<> | 138:093f2bd7b9eb | 56 | int deinit(); |
<> | 138:093f2bd7b9eb | 57 | |
<> | 138:093f2bd7b9eb | 58 | /** Read data from a flash device. |
<> | 138:093f2bd7b9eb | 59 | * |
<> | 138:093f2bd7b9eb | 60 | * This method invokes memcpy - reads number of bytes from the address |
<> | 138:093f2bd7b9eb | 61 | * |
<> | 138:093f2bd7b9eb | 62 | * @param buffer Buffer to write to |
<> | 138:093f2bd7b9eb | 63 | * @param addr Flash address to begin reading from |
<> | 138:093f2bd7b9eb | 64 | * @param size Size to read in bytes |
<> | 138:093f2bd7b9eb | 65 | * @return 0 on success, negative error code on failure |
<> | 138:093f2bd7b9eb | 66 | */ |
<> | 138:093f2bd7b9eb | 67 | int read(void *buffer, uint32_t addr, uint32_t size); |
<> | 138:093f2bd7b9eb | 68 | |
<> | 138:093f2bd7b9eb | 69 | /** Program data to pages |
<> | 138:093f2bd7b9eb | 70 | * |
<> | 138:093f2bd7b9eb | 71 | * The sectors must have been erased prior to being programmed |
<> | 138:093f2bd7b9eb | 72 | * |
<> | 138:093f2bd7b9eb | 73 | * @param buffer Buffer of data to be written |
<> | 138:093f2bd7b9eb | 74 | * @param addr Address of a page to begin writing to, must be a multiple of program and sector sizes |
<> | 138:093f2bd7b9eb | 75 | * @param size Size to write in bytes, must be a multiple of program and sector sizes |
<> | 138:093f2bd7b9eb | 76 | * @return 0 on success, negative error code on failure |
<> | 138:093f2bd7b9eb | 77 | */ |
<> | 138:093f2bd7b9eb | 78 | int program(const void *buffer, uint32_t addr, uint32_t size); |
<> | 138:093f2bd7b9eb | 79 | |
<> | 138:093f2bd7b9eb | 80 | /** Erase sectors |
<> | 138:093f2bd7b9eb | 81 | * |
<> | 138:093f2bd7b9eb | 82 | * The state of an erased sector is undefined until it has been programmed |
<> | 138:093f2bd7b9eb | 83 | * |
<> | 138:093f2bd7b9eb | 84 | * @param addr Address of a sector to begin erasing, must be a multiple of the sector size |
<> | 138:093f2bd7b9eb | 85 | * @param size Size to erase in bytes, must be a multiple of the sector size |
<> | 138:093f2bd7b9eb | 86 | * @return 0 on success, negative error code on failure |
<> | 138:093f2bd7b9eb | 87 | */ |
<> | 138:093f2bd7b9eb | 88 | int erase(uint32_t addr, uint32_t size); |
<> | 138:093f2bd7b9eb | 89 | |
<> | 138:093f2bd7b9eb | 90 | /** Get the sector size at the defined address |
<> | 138:093f2bd7b9eb | 91 | * |
<> | 138:093f2bd7b9eb | 92 | * Sector size might differ at address ranges. |
<> | 138:093f2bd7b9eb | 93 | * An example <0-0x1000, sector size=1024; 0x10000-0x20000, size=2048> |
<> | 138:093f2bd7b9eb | 94 | * |
<> | 138:093f2bd7b9eb | 95 | * @param addr Address of or inside the sector to query |
<> | 138:093f2bd7b9eb | 96 | * @return Size of a sector in bytes or MBED_FLASH_INVALID_SIZE if not mapped |
<> | 138:093f2bd7b9eb | 97 | */ |
<> | 138:093f2bd7b9eb | 98 | uint32_t get_sector_size(uint32_t addr) const; |
<> | 138:093f2bd7b9eb | 99 | |
<> | 138:093f2bd7b9eb | 100 | /** Get the flash start address |
<> | 138:093f2bd7b9eb | 101 | * |
<> | 138:093f2bd7b9eb | 102 | * @return Flash start address |
<> | 138:093f2bd7b9eb | 103 | */ |
<> | 138:093f2bd7b9eb | 104 | uint32_t get_flash_start() const; |
<> | 138:093f2bd7b9eb | 105 | |
<> | 138:093f2bd7b9eb | 106 | /** Get the flash size |
<> | 138:093f2bd7b9eb | 107 | * |
<> | 138:093f2bd7b9eb | 108 | * @return Flash size |
<> | 138:093f2bd7b9eb | 109 | */ |
<> | 138:093f2bd7b9eb | 110 | uint32_t get_flash_size() const; |
<> | 138:093f2bd7b9eb | 111 | |
<> | 138:093f2bd7b9eb | 112 | /** Get the program page size |
<> | 138:093f2bd7b9eb | 113 | * |
<> | 138:093f2bd7b9eb | 114 | * @return Size of a program page in bytes |
<> | 138:093f2bd7b9eb | 115 | */ |
<> | 138:093f2bd7b9eb | 116 | uint32_t get_page_size() const; |
<> | 138:093f2bd7b9eb | 117 | |
<> | 138:093f2bd7b9eb | 118 | private: |
<> | 138:093f2bd7b9eb | 119 | |
<> | 138:093f2bd7b9eb | 120 | /** Check if address and size are aligned to a sector |
<> | 138:093f2bd7b9eb | 121 | * |
<> | 138:093f2bd7b9eb | 122 | * @param addr Address of block to check for alignment |
<> | 138:093f2bd7b9eb | 123 | * @param size Size of block to check for alignment |
<> | 138:093f2bd7b9eb | 124 | * @return true if the block is sector aligned, false otherwise |
<> | 138:093f2bd7b9eb | 125 | */ |
<> | 138:093f2bd7b9eb | 126 | bool is_aligned_to_sector(uint32_t addr, uint32_t size); |
<> | 138:093f2bd7b9eb | 127 | |
<> | 138:093f2bd7b9eb | 128 | flash_t _flash; |
<> | 138:093f2bd7b9eb | 129 | static SingletonPtr<PlatformMutex> _mutex; |
<> | 138:093f2bd7b9eb | 130 | }; |
<> | 138:093f2bd7b9eb | 131 | |
<> | 138:093f2bd7b9eb | 132 | } /* namespace mbed */ |
<> | 138:093f2bd7b9eb | 133 | |
<> | 138:093f2bd7b9eb | 134 | #endif /* DEVICE_FLASH */ |
<> | 138:093f2bd7b9eb | 135 | |
<> | 138:093f2bd7b9eb | 136 | #endif /* MBED_FLASHIAP_H */ |
<> | 138:093f2bd7b9eb | 137 | |
<> | 138:093f2bd7b9eb | 138 | /** @}*/ |