Skip to content

Commit 473f8d3

Browse files
Yossi LevyYossi Levy
authored andcommitted
Fixing the order of component if more than one is included for a target.
Revert deprecation of FlashIAPBlockDevice 2 argument constructor has this was a breaking change. This follows a similar change in the external flashiap-driver repo.
1 parent 06dffda commit 473f8d3

File tree

5 files changed

+77
-5
lines changed

5 files changed

+77
-5
lines changed

components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ FlashIAPBlockDevice::FlashIAPBlockDevice()
4242
DEBUG_PRINTF("FlashIAPBlockDevice: %" PRIX32 " %" PRIX32 "\r\n", address, size);
4343
}
4444

45-
FlashIAPBlockDevice::FlashIAPBlockDevice(uint32_t address, uint32_t)
46-
: _flash(), _base(0), _size(0), _is_initialized(false), _init_ref_count(0)
45+
FlashIAPBlockDevice::FlashIAPBlockDevice(uint32_t address, uint32_t size)
46+
: _flash(), _base(address), _size(size), _is_initialized(false), _init_ref_count(0)
4747
{
4848

4949
}
@@ -70,11 +70,27 @@ int FlashIAPBlockDevice::init()
7070
int ret = _flash.init();
7171

7272
if (ret) {
73+
core_util_atomic_decr_u32(&_init_ref_count, 1);
7374
return ret;
7475
}
7576

76-
_base = _flash.get_flash_start();
77-
_size = _flash.get_flash_size();
77+
if (_size + _base > _flash.get_flash_size() + _flash.get_flash_start()) {
78+
core_util_atomic_decr_u32(&_init_ref_count, 1);
79+
return BD_ERROR_DEVICE_ERROR;
80+
}
81+
82+
if (_base < _flash.get_flash_start()) {
83+
core_util_atomic_decr_u32(&_init_ref_count, 1);
84+
return BD_ERROR_DEVICE_ERROR;
85+
}
86+
87+
if (!_base) {
88+
_base = _flash.get_flash_start();
89+
}
90+
91+
if (!_size) {
92+
_size = _flash.get_flash_size() - (_base - _flash.get_flash_start());
93+
}
7894

7995
_is_initialized = true;
8096
return ret;

components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class FlashIAPBlockDevice : public BlockDevice {
3131
/** Creates a FlashIAPBlockDevice **/
3232
FlashIAPBlockDevice();
3333

34-
MBED_DEPRECATED("Please use default constructor instead")
34+
/** Creates a FlashIAPBlockDevice
35+
*
36+
* @param address Physical address where the block device start
37+
* @param size The block device size
38+
*/
3539
FlashIAPBlockDevice(uint32_t address, uint32_t size = 0);
3640

3741
virtual ~FlashIAPBlockDevice();

features/storage/TESTS/filesystem/general_filesystem/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#elif COMPONENT_SD
2525
#include "SDBlockDevice.h"
2626
#include "FATFileSystem.h"
27+
#elif COMPONENT_FLASHIAP
28+
#include "FlashIAPBlockDevice.h"
29+
#include "LittleFileSystem.h"
2730
#else
2831
#error [NOT_SUPPORTED] storage test not supported on this platform
2932
#endif

features/storage/system_storage/SystemStorage.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,23 @@
3030
#include "SDBlockDevice.h"
3131
#endif
3232

33+
#if COMPONENT_FLASHIAP
34+
#include "nvstore.h"
35+
#include "FlashIAPBlockDevice.h"
36+
#endif
37+
3338
using namespace mbed;
3439

40+
// Align a value to a specified size.
41+
// Parameters :
42+
// val - [IN] Value.
43+
// size - [IN] Size.
44+
// Return : Aligned value.
45+
static inline uint32_t align_up(uint32_t val, uint32_t size)
46+
{
47+
return (((val - 1) / size) + 1) * size;
48+
}
49+
3550
MBED_WEAK BlockDevice *BlockDevice::get_default_instance()
3651
{
3752
#if COMPONENT_SPIF
@@ -68,6 +83,32 @@ MBED_WEAK BlockDevice *BlockDevice::get_default_instance()
6883

6984
return &default_bd;
7085

86+
#elif COMPONENT_FLASHIAP
87+
88+
uint32_t top_address;
89+
uint32_t bottom_address;
90+
size_t area_size;
91+
FlashIAP flash;
92+
NVStore &nvstore = NVStore::get_instance();
93+
nvstore.get_area_params(0, top_address, area_size); //Find where nvstore begins
94+
95+
int ret = flash.init();
96+
if (ret != 0) {
97+
return 0;
98+
}
99+
100+
//Find the start of first sector after text area
101+
bottom_address = align_up(FLASHIAP_ROM_END, flash.get_sector_size(FLASHIAP_ROM_END));
102+
103+
if (top_address <= bottom_address) {
104+
return 0;
105+
}
106+
107+
ret = flash.deinit();
108+
109+
static FlashIAPBlockDevice default_bd(bottom_address, top_address - bottom_address);
110+
111+
return &default_bd;
71112
#else
72113

73114
return NULL;
@@ -92,6 +133,13 @@ MBED_WEAK FileSystem *FileSystem::get_default_instance()
92133

93134
return &sdcard;
94135

136+
#elif COMPONENT_FLASHIAP
137+
138+
static LittleFileSystem flash("flash", BlockDevice::get_default_instance());
139+
flash.set_as_default();
140+
141+
return &flash;
142+
95143
#else
96144

97145
return NULL;

targets/targets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,7 @@
17391739
"device_name": "STM32L486RG"
17401740
},
17411741
"MTB_ADV_WISE_1570": {
1742+
"components": ["FLASHIAP"],
17421743
"inherits": ["FAMILY_STM32"],
17431744
"core": "Cortex-M4F",
17441745
"extra_labels_add": ["STM32L4", "STM32L486RG", "STM32L486xG", "WISE_1570"],

0 commit comments

Comments
 (0)