mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #4720 from marcuschangarm/flashiap_read
FlashIAP: Add explicit read function to flash_api.hpull/4657/merge
commit
efc5c47e55
|
@ -75,10 +75,11 @@ int FlashIAP::deinit()
|
||||||
|
|
||||||
int FlashIAP::read(void *buffer, uint32_t addr, uint32_t size)
|
int FlashIAP::read(void *buffer, uint32_t addr, uint32_t size)
|
||||||
{
|
{
|
||||||
|
int32_t ret = -1;
|
||||||
_mutex->lock();
|
_mutex->lock();
|
||||||
memcpy(buffer, (const void *)addr, size);
|
ret = flash_read(&_flash, addr, (uint8_t *) buffer, size);
|
||||||
_mutex->unlock();
|
_mutex->unlock();
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
|
int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
|
||||||
|
|
|
@ -64,6 +64,17 @@ int32_t flash_free(flash_t *obj);
|
||||||
*/
|
*/
|
||||||
int32_t flash_erase_sector(flash_t *obj, uint32_t address);
|
int32_t flash_erase_sector(flash_t *obj, uint32_t address);
|
||||||
|
|
||||||
|
/** Read data starting at defined address
|
||||||
|
*
|
||||||
|
* This function has a WEAK implementation using memcpy for backwards compatibility.
|
||||||
|
* @param obj The flash object
|
||||||
|
* @param address Address to begin reading from
|
||||||
|
* @param data The buffer to read data into
|
||||||
|
* @param size The number of bytes to read
|
||||||
|
* @return 0 for success, -1 for error
|
||||||
|
*/
|
||||||
|
int32_t flash_read(flash_t *obj, uint32_t address, uint8_t *data, uint32_t size);
|
||||||
|
|
||||||
/** Program one page starting at defined address
|
/** Program one page starting at defined address
|
||||||
*
|
*
|
||||||
* The page should be at page boundary, should not cross multiple sectors.
|
* The page should be at page boundary, should not cross multiple sectors.
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
* Copyright (c) 2017 ARM Limited
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "hal/flash_api.h"
|
||||||
|
|
||||||
|
#if DEVICE_FLASH
|
||||||
|
|
||||||
|
#include "platform/mbed_toolchain.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
MBED_WEAK int32_t flash_read(flash_t *obj, uint32_t address, uint8_t *data, uint32_t size)
|
||||||
|
{
|
||||||
|
memcpy(data, (const void *)address, size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue