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.
Dependencies: FXAS21002 FXOS8700Q
arm_uc_pal_flashiap_mbed.cpp
00001 // ---------------------------------------------------------------------------- 00002 // Copyright 2016-2017 ARM Ltd. 00003 // 00004 // SPDX-License-Identifier: Apache-2.0 00005 // 00006 // Licensed under the Apache License, Version 2.0 (the "License"); 00007 // you may not use this file except in compliance with the License. 00008 // You may obtain a copy of the License at 00009 // 00010 // http://www.apache.org/licenses/LICENSE-2.0 00011 // 00012 // Unless required by applicable law or agreed to in writing, software 00013 // distributed under the License is distributed on an "AS IS" BASIS, 00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 // See the License for the specific language governing permissions and 00016 // limitations under the License. 00017 // ---------------------------------------------------------------------------- 00018 00019 #include "arm_uc_config.h" 00020 #if defined(ARM_UC_FEATURE_PAL_FLASHIAP) && (ARM_UC_FEATURE_PAL_FLASHIAP == 1) 00021 #if defined(TARGET_LIKE_MBED) 00022 00023 #include "update-client-pal-flashiap/arm_uc_pal_flashiap_platform.h" 00024 #include "mbed.h" 00025 00026 SingletonPtr<FlashIAP> flash; 00027 00028 int32_t arm_uc_flashiap_init(void) 00029 { 00030 /* Workaround for https://github.com/ARMmbed/mbed-os/issues/4967 00031 * pal_init calls flash.init() before here. Second call to flash.init() will 00032 * return -1 error state. Hence we ignore the result of flash.init here. 00033 */ 00034 flash->init(); 00035 return 0; 00036 } 00037 00038 int32_t arm_uc_flashiap_erase(uint32_t address, uint32_t size) 00039 { 00040 return flash->erase(address, size); 00041 } 00042 00043 int32_t arm_uc_flashiap_program(const uint8_t *buffer, uint32_t address, uint32_t size) 00044 { 00045 uint32_t page_size = flash->get_page_size(); 00046 int status = ARM_UC_FLASHIAP_FAIL; 00047 00048 for (uint32_t i = 0; i < size; i += page_size) { 00049 status = flash->program(buffer + i, address + i, page_size); 00050 if (status != ARM_UC_FLASHIAP_SUCCESS) { 00051 break; 00052 } 00053 } 00054 00055 return status; 00056 } 00057 00058 int32_t arm_uc_flashiap_read(uint8_t *buffer, uint32_t address, uint32_t size) 00059 { 00060 return flash->read(buffer, address, size); 00061 } 00062 00063 uint32_t arm_uc_flashiap_get_page_size(void) 00064 { 00065 return flash->get_page_size(); 00066 } 00067 00068 uint32_t arm_uc_flashiap_get_sector_size(uint32_t address) 00069 { 00070 uint32_t sector_size = flash->get_sector_size(address); 00071 if (sector_size == ARM_UC_FLASH_INVALID_SIZE || sector_size == 0) { 00072 return ARM_UC_FLASH_INVALID_SIZE; 00073 } else { 00074 return sector_size; 00075 } 00076 } 00077 00078 uint32_t arm_uc_flashiap_get_flash_size(void) 00079 { 00080 return flash->get_flash_size(); 00081 } 00082 00083 uint32_t arm_uc_flashiap_get_flash_start(void) 00084 { 00085 return flash->get_flash_start(); 00086 } 00087 00088 #endif /* TARGET_LIKE_MBED */ 00089 #endif /* ARM_UC_FEATURE_PAL_FLASHIAP */
Generated on Tue Jul 12 2022 20:20:57 by
