Skip to content

Commit a6651b8

Browse files
author
Cruz Monrreal
authored
Merge pull request #8317 from yossi2le/add-flashiap-bd-as-default
Add FlashIAP block device as default block device for WISE 1570
2 parents 00f8ecf + 196fbe5 commit a6651b8

File tree

7 files changed

+104
-16
lines changed

7 files changed

+104
-16
lines changed

components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@
3636
#define DEBUG_PRINTF(...)
3737
#endif
3838

39-
FlashIAPBlockDevice::FlashIAPBlockDevice()
40-
: _flash(), _base(0), _size(0), _is_initialized(false), _init_ref_count(0)
41-
{
42-
DEBUG_PRINTF("FlashIAPBlockDevice: %" PRIX32 " %" PRIX32 "\r\n", address, size);
43-
}
44-
45-
FlashIAPBlockDevice::FlashIAPBlockDevice(uint32_t address, uint32_t)
46-
: _flash(), _base(0), _size(0), _is_initialized(false), _init_ref_count(0)
39+
FlashIAPBlockDevice::FlashIAPBlockDevice(uint32_t address, uint32_t size)
40+
: _flash(), _base(address), _size(size), _is_initialized(false), _init_ref_count(0)
4741
{
4842

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

7266
if (ret) {
67+
core_util_atomic_decr_u32(&_init_ref_count, 1);
7368
return ret;
7469
}
7570

76-
_base = _flash.get_flash_start();
77-
_size = _flash.get_flash_size();
71+
if (_size + _base > _flash.get_flash_size() + _flash.get_flash_start()) {
72+
core_util_atomic_decr_u32(&_init_ref_count, 1);
73+
return BD_ERROR_DEVICE_ERROR;
74+
}
75+
76+
if (_base < _flash.get_flash_start()) {
77+
core_util_atomic_decr_u32(&_init_ref_count, 1);
78+
return BD_ERROR_DEVICE_ERROR;
79+
}
80+
81+
if (!_base) {
82+
_base = _flash.get_flash_start();
83+
}
84+
85+
if (!_size) {
86+
_size = _flash.get_flash_size() - (_base - _flash.get_flash_start());
87+
}
7888

7989
_is_initialized = true;
8090
return ret;

components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@
2828
*/
2929
class FlashIAPBlockDevice : public BlockDevice {
3030
public:
31-
/** Creates a FlashIAPBlockDevice **/
32-
FlashIAPBlockDevice();
33-
34-
MBED_DEPRECATED("Please use default constructor instead")
35-
FlashIAPBlockDevice(uint32_t address, uint32_t size = 0);
3631

32+
/** Creates a FlashIAPBlockDevice
33+
*
34+
* @param address Physical address where the block device start
35+
* @param size The block device size
36+
*/
37+
FlashIAPBlockDevice(uint32_t address = MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS,
38+
uint32_t size = MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE);
39+
3740
virtual ~FlashIAPBlockDevice();
3841

3942
/** Initialize a block device

components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/filesystem/fopen/fopen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ control_t fslittle_fopen_test_05(const size_t call_count)
680680
}
681681

682682

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

685685
/** @brief test to call fopen() with filename that in includes
686686
* illegal characters
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "flashiap-block-device",
3+
"config": {
4+
"base-address": {
5+
"help": "Base address for the block device on the external flash.",
6+
"value": "0xFFFFFFFF"
7+
},
8+
"size": {
9+
"help": "Memory allocated for block device.",
10+
"value": "0"
11+
}
12+
},
13+
"target_overrides": {
14+
"REALTEK_RTL8195AM": {
15+
"base-address": "0x1C0000",
16+
"size": "0x40000"
17+
}
18+
}
19+
}

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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,22 @@
3030
#include "SDBlockDevice.h"
3131
#endif
3232

33+
#if COMPONENT_FLASHIAP
34+
#include "FlashIAPBlockDevice.h"
35+
#endif
36+
3337
using namespace mbed;
3438

39+
// Align a value to a specified size.
40+
// Parameters :
41+
// val - [IN] Value.
42+
// size - [IN] Size.
43+
// Return : Aligned value.
44+
static inline uint32_t align_up(uint32_t val, uint32_t size)
45+
{
46+
return (((val - 1) / size) + 1) * size;
47+
}
48+
3549
MBED_WEAK BlockDevice *BlockDevice::get_default_instance()
3650
{
3751
#if COMPONENT_SPIF
@@ -68,6 +82,37 @@ MBED_WEAK BlockDevice *BlockDevice::get_default_instance()
6882

6983
return &default_bd;
7084

85+
#elif COMPONENT_FLASHIAP
86+
87+
#if (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE == 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS == 0xFFFFFFFF)
88+
89+
size_t flash_size;
90+
uint32_t start_address;
91+
uint32_t bottom_address;
92+
FlashIAP flash;
93+
94+
int ret = flash.init();
95+
if (ret != 0) {
96+
return 0;
97+
}
98+
99+
//Find the start of first sector after text area
100+
bottom_address = align_up(FLASHIAP_ROM_END, flash.get_sector_size(FLASHIAP_ROM_END));
101+
start_address = flash.get_flash_start();
102+
flash_size = flash.get_flash_size();
103+
104+
ret = flash.deinit();
105+
106+
static FlashIAPBlockDevice default_bd(bottom_address, start_address + flash_size - bottom_address);
107+
108+
#else
109+
110+
static FlashIAPBlockDevice default_bd;
111+
112+
#endif
113+
114+
return &default_bd;
115+
71116
#else
72117

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

93138
return &sdcard;
94139

140+
#elif COMPONENT_FLASHIAP
141+
142+
static LittleFileSystem flash("flash", BlockDevice::get_default_instance());
143+
flash.set_as_default();
144+
145+
return &flash;
146+
95147
#else
96148

97149
return NULL;

targets/targets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,7 @@
17451745
"device_name": "STM32L486RG"
17461746
},
17471747
"MTB_ADV_WISE_1570": {
1748+
"components": ["FLASHIAP"],
17481749
"inherits": ["FAMILY_STM32"],
17491750
"core": "Cortex-M4F",
17501751
"extra_labels_add": ["STM32L4", "STM32L486RG", "STM32L486xG", "WISE_1570"],

0 commit comments

Comments
 (0)