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
|
@ -55,7 +55,7 @@ int FlashIAP::init()
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
_mutex->lock();
|
_mutex->lock();
|
||||||
if (flash_init(&_flash)) {
|
if (flash_init(&_flash)) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
_mutex->unlock();
|
_mutex->unlock();
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -66,7 +66,7 @@ int FlashIAP::deinit()
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
_mutex->lock();
|
_mutex->lock();
|
||||||
if (flash_free(&_flash)) {
|
if (flash_free(&_flash)) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
_mutex->unlock();
|
_mutex->unlock();
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -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)
|
||||||
|
|
|
@ -42,14 +42,14 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Initialize the flash peripheral and the flash_t object
|
/** Initialize the flash peripheral and the flash_t object
|
||||||
*
|
*
|
||||||
* @param obj The flash object
|
* @param obj The flash object
|
||||||
* @return 0 for success, -1 for error
|
* @return 0 for success, -1 for error
|
||||||
*/
|
*/
|
||||||
int32_t flash_init(flash_t *obj);
|
int32_t flash_init(flash_t *obj);
|
||||||
|
|
||||||
/** Uninitialize the flash peripheral and the flash_t object
|
/** Uninitialize the flash peripheral and the flash_t object
|
||||||
*
|
*
|
||||||
* @param obj The flash object
|
* @param obj The flash object
|
||||||
* @return 0 for success, -1 for error
|
* @return 0 for success, -1 for error
|
||||||
*/
|
*/
|
||||||
|
@ -64,9 +64,20 @@ 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.
|
||||||
* This function does not do any check for address alignments or if size is aligned to a page size.
|
* This function does not do any check for address alignments or if size is aligned to a page size.
|
||||||
* @param obj The flash object
|
* @param obj The flash object
|
||||||
* @param address The sector starting address
|
* @param address The sector starting address
|
||||||
|
@ -77,7 +88,7 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address);
|
||||||
int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size);
|
int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size);
|
||||||
|
|
||||||
/** Get sector size
|
/** Get sector size
|
||||||
*
|
*
|
||||||
* @param obj The flash object
|
* @param obj The flash object
|
||||||
* @param address The sector starting address
|
* @param address The sector starting address
|
||||||
* @return The size of a sector
|
* @return The size of a sector
|
||||||
|
@ -85,7 +96,7 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
|
||||||
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address);
|
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address);
|
||||||
|
|
||||||
/** Get page size
|
/** Get page size
|
||||||
*
|
*
|
||||||
* @param obj The flash object
|
* @param obj The flash object
|
||||||
* @param address The page starting address
|
* @param address The page starting address
|
||||||
* @return The size of a page
|
* @return The size of a page
|
||||||
|
@ -93,14 +104,14 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address);
|
||||||
uint32_t flash_get_page_size(const flash_t *obj);
|
uint32_t flash_get_page_size(const flash_t *obj);
|
||||||
|
|
||||||
/** Get start address for the flash region
|
/** Get start address for the flash region
|
||||||
*
|
*
|
||||||
* @param obj The flash object
|
* @param obj The flash object
|
||||||
* @return The start address for the flash region
|
* @return The start address for the flash region
|
||||||
*/
|
*/
|
||||||
uint32_t flash_get_start_address(const flash_t *obj);
|
uint32_t flash_get_start_address(const flash_t *obj);
|
||||||
|
|
||||||
/** Get the flash region size
|
/** Get the flash region size
|
||||||
*
|
*
|
||||||
* @param obj The flash object
|
* @param obj The flash object
|
||||||
* @return The flash region size
|
* @return The flash region size
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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