Skip to content

Commit 43e3939

Browse files
authored
Merge pull request #12 from pennam/qspi_init
Reuse QSPIF Block Device instance from the core if exist
2 parents 36bd62b + 1c932fb commit 43e3939

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/Arduino_Portenta_OTA_QSPI.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
using namespace arduino;
2727

28+
#if defined (COMPONENT_4343W_FS)
29+
extern QSPIFBlockDevice *qspi_bd;
30+
#endif
31+
2832
/******************************************************************************
2933
CTOR/DTOR
3034
******************************************************************************/
@@ -33,7 +37,6 @@ Arduino_Portenta_OTA_QSPI::Arduino_Portenta_OTA_QSPI(StorageTypePortenta const s
3337
: Arduino_Portenta_OTA(storage_type, data_offset)
3438
, _bd_qspi{NULL}
3539
, _fs_qspi{NULL}
36-
, _block_device_qspi(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000)
3740
{
3841
assert(_storage_type == QSPI_FLASH_FATFS || _storage_type == QSPI_FLASH_FATFS_MBR);
3942
}
@@ -44,13 +47,18 @@ Arduino_Portenta_OTA_QSPI::Arduino_Portenta_OTA_QSPI(StorageTypePortenta const s
4447

4548
bool Arduino_Portenta_OTA_QSPI::init()
4649
{
47-
if (_block_device_qspi.init() != QSPIF_BD_ERROR_OK)
50+
#if !defined (COMPONENT_4343W_FS)
51+
qspi_bd = new QSPIFBlockDevice(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
52+
if (qspi_bd->init() != QSPIF_BD_ERROR_OK) {
53+
Serial1.println("Error: QSPI init failure.");
4854
return false;
55+
}
56+
#endif
4957

5058
if(_storage_type == QSPI_FLASH_FATFS)
5159
{
5260
_fs_qspi = new mbed::FATFileSystem("fs");
53-
int const err_mount = _fs_qspi->mount(&_block_device_qspi);
61+
int const err_mount = _fs_qspi->mount(qspi_bd);
5462
if (err_mount)
5563
{
5664
Serial1.print("Error while mounting the filesystem. Err = ");
@@ -62,7 +70,7 @@ bool Arduino_Portenta_OTA_QSPI::init()
6270

6371
if (_storage_type == QSPI_FLASH_FATFS_MBR)
6472
{
65-
_bd_qspi = new mbed::MBRBlockDevice(reinterpret_cast<mbed::BlockDevice *>(&_block_device_qspi), _data_offset);
73+
_bd_qspi = new mbed::MBRBlockDevice(reinterpret_cast<mbed::BlockDevice *>(qspi_bd), _data_offset);
6674
_fs_qspi = new mbed::FATFileSystem("fs");
6775
int const err_mount = _fs_qspi->mount(_bd_qspi);
6876
if (err_mount) {

src/Arduino_Portenta_OTA_QSPI.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class Arduino_Portenta_OTA_QSPI : public Arduino_Portenta_OTA
4747

4848
mbed::BlockDevice * _bd_qspi;
4949
mbed::FATFileSystem * _fs_qspi;
50-
QSPIFBlockDevice _block_device_qspi;
50+
#if !defined (COMPONENT_4343W_FS)
51+
QSPIFBlockDevice *qspi_bd;
52+
#endif
5153

5254
};
5355

0 commit comments

Comments
 (0)