mbed library sources. Supersedes mbed-src. Fixed broken STM32F1xx RTC on rtc_api.c
Dependents: Nucleo_F103RB_RTC_battery_bkup_pwr_off_okay
Fork of mbed-dev by
targets/TARGET_NORDIC/TARGET_NRF5/flash_api.c@166:c97ed07ec1a8, 2017-06-08 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Jun 08 15:02:37 2017 +0100
- Revision:
- 166:c97ed07ec1a8
This updates the lib to the mbed lib v 144
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 166:c97ed07ec1a8 | 1 | /* |
AnnaBridge | 166:c97ed07ec1a8 | 2 | * Copyright (c) 2017 Nordic Semiconductor ASA |
AnnaBridge | 166:c97ed07ec1a8 | 3 | * All rights reserved. |
AnnaBridge | 166:c97ed07ec1a8 | 4 | * |
AnnaBridge | 166:c97ed07ec1a8 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 166:c97ed07ec1a8 | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 166:c97ed07ec1a8 | 7 | * |
AnnaBridge | 166:c97ed07ec1a8 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 166:c97ed07ec1a8 | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 166:c97ed07ec1a8 | 10 | * |
AnnaBridge | 166:c97ed07ec1a8 | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
AnnaBridge | 166:c97ed07ec1a8 | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
AnnaBridge | 166:c97ed07ec1a8 | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
AnnaBridge | 166:c97ed07ec1a8 | 14 | * the documentation and/or other materials provided with the distribution. |
AnnaBridge | 166:c97ed07ec1a8 | 15 | * |
AnnaBridge | 166:c97ed07ec1a8 | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
AnnaBridge | 166:c97ed07ec1a8 | 17 | * used to endorse or promote products derived from this software without specific prior |
AnnaBridge | 166:c97ed07ec1a8 | 18 | * written permission. |
AnnaBridge | 166:c97ed07ec1a8 | 19 | * |
AnnaBridge | 166:c97ed07ec1a8 | 20 | * 4. This software, with or without modification, must only be used with a |
AnnaBridge | 166:c97ed07ec1a8 | 21 | * Nordic Semiconductor ASA integrated circuit. |
AnnaBridge | 166:c97ed07ec1a8 | 22 | * |
AnnaBridge | 166:c97ed07ec1a8 | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
AnnaBridge | 166:c97ed07ec1a8 | 24 | * engineered, decompiled, modified and/or disassembled. |
AnnaBridge | 166:c97ed07ec1a8 | 25 | * |
AnnaBridge | 166:c97ed07ec1a8 | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 166:c97ed07ec1a8 | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 166:c97ed07ec1a8 | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 166:c97ed07ec1a8 | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 166:c97ed07ec1a8 | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 166:c97ed07ec1a8 | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 166:c97ed07ec1a8 | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 166:c97ed07ec1a8 | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 166:c97ed07ec1a8 | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 166:c97ed07ec1a8 | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 166:c97ed07ec1a8 | 36 | * |
AnnaBridge | 166:c97ed07ec1a8 | 37 | */ |
AnnaBridge | 166:c97ed07ec1a8 | 38 | |
AnnaBridge | 166:c97ed07ec1a8 | 39 | #include "flash_api.h" |
AnnaBridge | 166:c97ed07ec1a8 | 40 | #include "nrf_nvmc.h" |
AnnaBridge | 166:c97ed07ec1a8 | 41 | #include "nrf_soc.h" |
AnnaBridge | 166:c97ed07ec1a8 | 42 | #include "nrf_sdm.h" |
AnnaBridge | 166:c97ed07ec1a8 | 43 | |
AnnaBridge | 166:c97ed07ec1a8 | 44 | #if DEVICE_FLASH |
AnnaBridge | 166:c97ed07ec1a8 | 45 | |
AnnaBridge | 166:c97ed07ec1a8 | 46 | int32_t flash_init(flash_t *obj) |
AnnaBridge | 166:c97ed07ec1a8 | 47 | { |
AnnaBridge | 166:c97ed07ec1a8 | 48 | (void)(obj); |
AnnaBridge | 166:c97ed07ec1a8 | 49 | uint8_t sd_enabled; |
AnnaBridge | 166:c97ed07ec1a8 | 50 | if ((sd_softdevice_is_enabled(&sd_enabled) == NRF_SUCCESS) && sd_enabled == 1) { |
AnnaBridge | 166:c97ed07ec1a8 | 51 | return -1; |
AnnaBridge | 166:c97ed07ec1a8 | 52 | } |
AnnaBridge | 166:c97ed07ec1a8 | 53 | return 0; |
AnnaBridge | 166:c97ed07ec1a8 | 54 | } |
AnnaBridge | 166:c97ed07ec1a8 | 55 | |
AnnaBridge | 166:c97ed07ec1a8 | 56 | int32_t flash_free(flash_t *obj) |
AnnaBridge | 166:c97ed07ec1a8 | 57 | { |
AnnaBridge | 166:c97ed07ec1a8 | 58 | (void)(obj); |
AnnaBridge | 166:c97ed07ec1a8 | 59 | return 0; |
AnnaBridge | 166:c97ed07ec1a8 | 60 | } |
AnnaBridge | 166:c97ed07ec1a8 | 61 | |
AnnaBridge | 166:c97ed07ec1a8 | 62 | int32_t flash_erase_sector(flash_t *obj, uint32_t address) |
AnnaBridge | 166:c97ed07ec1a8 | 63 | { |
AnnaBridge | 166:c97ed07ec1a8 | 64 | (void)(obj); |
AnnaBridge | 166:c97ed07ec1a8 | 65 | uint8_t sd_enabled; |
AnnaBridge | 166:c97ed07ec1a8 | 66 | if ((sd_softdevice_is_enabled(&sd_enabled) == NRF_SUCCESS) && sd_enabled == 1) { |
AnnaBridge | 166:c97ed07ec1a8 | 67 | return -1; |
AnnaBridge | 166:c97ed07ec1a8 | 68 | } |
AnnaBridge | 166:c97ed07ec1a8 | 69 | nrf_nvmc_page_erase(address); |
AnnaBridge | 166:c97ed07ec1a8 | 70 | return 0; |
AnnaBridge | 166:c97ed07ec1a8 | 71 | } |
AnnaBridge | 166:c97ed07ec1a8 | 72 | |
AnnaBridge | 166:c97ed07ec1a8 | 73 | int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size) |
AnnaBridge | 166:c97ed07ec1a8 | 74 | { |
AnnaBridge | 166:c97ed07ec1a8 | 75 | uint8_t sd_enabled; |
AnnaBridge | 166:c97ed07ec1a8 | 76 | if ((sd_softdevice_is_enabled(&sd_enabled) == NRF_SUCCESS) && sd_enabled == 1) { |
AnnaBridge | 166:c97ed07ec1a8 | 77 | return -1; |
AnnaBridge | 166:c97ed07ec1a8 | 78 | } |
AnnaBridge | 166:c97ed07ec1a8 | 79 | /* We will use *_words function to speed up flashing code. Word means 32bit -> 4B |
AnnaBridge | 166:c97ed07ec1a8 | 80 | * or sizeof(uint32_t). |
AnnaBridge | 166:c97ed07ec1a8 | 81 | */ |
AnnaBridge | 166:c97ed07ec1a8 | 82 | nrf_nvmc_write_words(address, (const uint32_t *) data, (size / sizeof(uint32_t))); |
AnnaBridge | 166:c97ed07ec1a8 | 83 | return 0; |
AnnaBridge | 166:c97ed07ec1a8 | 84 | } |
AnnaBridge | 166:c97ed07ec1a8 | 85 | |
AnnaBridge | 166:c97ed07ec1a8 | 86 | uint32_t flash_get_size(const flash_t *obj) |
AnnaBridge | 166:c97ed07ec1a8 | 87 | { |
AnnaBridge | 166:c97ed07ec1a8 | 88 | (void)(obj); |
AnnaBridge | 166:c97ed07ec1a8 | 89 | /* Just count flash size. */ |
AnnaBridge | 166:c97ed07ec1a8 | 90 | return NRF_FICR->CODESIZE * NRF_FICR->CODEPAGESIZE; |
AnnaBridge | 166:c97ed07ec1a8 | 91 | } |
AnnaBridge | 166:c97ed07ec1a8 | 92 | |
AnnaBridge | 166:c97ed07ec1a8 | 93 | uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) |
AnnaBridge | 166:c97ed07ec1a8 | 94 | { |
AnnaBridge | 166:c97ed07ec1a8 | 95 | (void)(obj); |
AnnaBridge | 166:c97ed07ec1a8 | 96 | /* Test if passed address is in flash space. */ |
AnnaBridge | 166:c97ed07ec1a8 | 97 | if (address < flash_get_size(obj)) { |
AnnaBridge | 166:c97ed07ec1a8 | 98 | return NRF_FICR->CODEPAGESIZE; |
AnnaBridge | 166:c97ed07ec1a8 | 99 | } |
AnnaBridge | 166:c97ed07ec1a8 | 100 | /* Something goes wrong, return invalid size error code. */ |
AnnaBridge | 166:c97ed07ec1a8 | 101 | return MBED_FLASH_INVALID_SIZE; |
AnnaBridge | 166:c97ed07ec1a8 | 102 | } |
AnnaBridge | 166:c97ed07ec1a8 | 103 | |
AnnaBridge | 166:c97ed07ec1a8 | 104 | uint32_t flash_get_page_size(const flash_t *obj) |
AnnaBridge | 166:c97ed07ec1a8 | 105 | { |
AnnaBridge | 166:c97ed07ec1a8 | 106 | (void)(obj); |
AnnaBridge | 166:c97ed07ec1a8 | 107 | return NRF_FICR->CODEPAGESIZE; |
AnnaBridge | 166:c97ed07ec1a8 | 108 | } |
AnnaBridge | 166:c97ed07ec1a8 | 109 | |
AnnaBridge | 166:c97ed07ec1a8 | 110 | uint32_t flash_get_start_address(const flash_t *obj) |
AnnaBridge | 166:c97ed07ec1a8 | 111 | { |
AnnaBridge | 166:c97ed07ec1a8 | 112 | return 0; |
AnnaBridge | 166:c97ed07ec1a8 | 113 | } |
AnnaBridge | 166:c97ed07ec1a8 | 114 | |
AnnaBridge | 166:c97ed07ec1a8 | 115 | #endif |
AnnaBridge | 166:c97ed07ec1a8 | 116 | |
AnnaBridge | 166:c97ed07ec1a8 | 117 | /** @}*/ |