Skip to content

Add FlashIAP block device as default block device for WISE 1570 #8317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,8 @@
#define DEBUG_PRINTF(...)
#endif

FlashIAPBlockDevice::FlashIAPBlockDevice()
: _flash(), _base(0), _size(0), _is_initialized(false), _init_ref_count(0)
{
DEBUG_PRINTF("FlashIAPBlockDevice: %" PRIX32 " %" PRIX32 "\r\n", address, size);
}

FlashIAPBlockDevice::FlashIAPBlockDevice(uint32_t address, uint32_t)
: _flash(), _base(0), _size(0), _is_initialized(false), _init_ref_count(0)
FlashIAPBlockDevice::FlashIAPBlockDevice(uint32_t address, uint32_t size)
: _flash(), _base(address), _size(size), _is_initialized(false), _init_ref_count(0)
{

}
Expand All @@ -70,11 +64,27 @@ int FlashIAPBlockDevice::init()
int ret = _flash.init();

if (ret) {
core_util_atomic_decr_u32(&_init_ref_count, 1);
return ret;
}

_base = _flash.get_flash_start();
_size = _flash.get_flash_size();
if (_size + _base > _flash.get_flash_size() + _flash.get_flash_start()) {
core_util_atomic_decr_u32(&_init_ref_count, 1);
return BD_ERROR_DEVICE_ERROR;
}

if (_base < _flash.get_flash_start()) {
core_util_atomic_decr_u32(&_init_ref_count, 1);
return BD_ERROR_DEVICE_ERROR;
}

if (!_base) {
_base = _flash.get_flash_start();
}

if (!_size) {
_size = _flash.get_flash_size() - (_base - _flash.get_flash_start());
}

_is_initialized = true;
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
*/
class FlashIAPBlockDevice : public BlockDevice {
public:
/** Creates a FlashIAPBlockDevice **/
FlashIAPBlockDevice();

MBED_DEPRECATED("Please use default constructor instead")
FlashIAPBlockDevice(uint32_t address, uint32_t size = 0);

/** Creates a FlashIAPBlockDevice
*
* @param address Physical address where the block device start
* @param size The block device size
*/
FlashIAPBlockDevice(uint32_t address = MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS,
uint32_t size = MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE);

virtual ~FlashIAPBlockDevice();

/** Initialize a block device
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ control_t fslittle_fopen_test_05(const size_t call_count)
}


static const char fslittle_fopen_ascii_illegal_buf_g[] = "\"'*+,./:;<=>?[\\]|";
static const char fslittle_fopen_ascii_illegal_buf_g[] = "\"?'*+,./:;<=>?[\\]|";

/** @brief test to call fopen() with filename that in includes
* illegal characters
Expand Down
19 changes: 19 additions & 0 deletions components/storage/blockdevice/COMPONENT_FLASHIAP/mbed_lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "flashiap-block-device",
"config": {
"base-address": {
"help": "Base address for the block device on the external flash.",
"value": "0xFFFFFFFF"
},
"size": {
"help": "Memory allocated for block device.",
"value": "0"
}
},
"target_overrides": {
"REALTEK_RTL8195AM": {
"base-address": "0x1C0000",
"size": "0x40000"
}
}
}
3 changes: 3 additions & 0 deletions features/storage/TESTS/filesystem/general_filesystem/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#elif COMPONENT_SD
#include "SDBlockDevice.h"
#include "FATFileSystem.h"
#elif COMPONENT_FLASHIAP
#include "FlashIAPBlockDevice.h"
#include "LittleFileSystem.h"
#else
#error [NOT_SUPPORTED] storage test not supported on this platform
#endif
Expand Down
52 changes: 52 additions & 0 deletions features/storage/system_storage/SystemStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,22 @@
#include "SDBlockDevice.h"
#endif

#if COMPONENT_FLASHIAP
#include "FlashIAPBlockDevice.h"
#endif

using namespace mbed;

// Align a value to a specified size.
// Parameters :
// val - [IN] Value.
// size - [IN] Size.
// Return : Aligned value.
static inline uint32_t align_up(uint32_t val, uint32_t size)
{
return (((val - 1) / size) + 1) * size;
}

MBED_WEAK BlockDevice *BlockDevice::get_default_instance()
{
#if COMPONENT_SPIF
Expand Down Expand Up @@ -68,6 +82,37 @@ MBED_WEAK BlockDevice *BlockDevice::get_default_instance()

return &default_bd;

#elif COMPONENT_FLASHIAP

#if (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE == 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS == 0xFFFFFFFF)

size_t flash_size;
uint32_t start_address;
uint32_t bottom_address;
FlashIAP flash;

int ret = flash.init();
if (ret != 0) {
return 0;
}

//Find the start of first sector after text area
bottom_address = align_up(FLASHIAP_ROM_END, flash.get_sector_size(FLASHIAP_ROM_END));
start_address = flash.get_flash_start();
flash_size = flash.get_flash_size();

ret = flash.deinit();

static FlashIAPBlockDevice default_bd(bottom_address, start_address + flash_size - bottom_address);

#else

static FlashIAPBlockDevice default_bd;

#endif

return &default_bd;

#else

return NULL;
Expand All @@ -92,6 +137,13 @@ MBED_WEAK FileSystem *FileSystem::get_default_instance()

return &sdcard;

#elif COMPONENT_FLASHIAP

static LittleFileSystem flash("flash", BlockDevice::get_default_instance());
flash.set_as_default();

return &flash;

#else

return NULL;
Expand Down
1 change: 1 addition & 0 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,7 @@
"device_name": "STM32L486RG"
},
"MTB_ADV_WISE_1570": {
"components": ["FLASHIAP"],
"inherits": ["FAMILY_STM32"],
"core": "Cortex-M4F",
"extra_labels_add": ["STM32L4", "STM32L486RG", "STM32L486xG", "WISE_1570"],
Expand Down