Skip to content

Reuse QSPIF Block Device instance from the core if exist #12

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 1 commit into from
Jul 15, 2021
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
16 changes: 12 additions & 4 deletions src/Arduino_Portenta_OTA_QSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

using namespace arduino;

#if defined (COMPONENT_4343W_FS)
extern QSPIFBlockDevice *qspi_bd;
#endif

/******************************************************************************
CTOR/DTOR
******************************************************************************/
Expand All @@ -33,7 +37,6 @@ Arduino_Portenta_OTA_QSPI::Arduino_Portenta_OTA_QSPI(StorageTypePortenta const s
: Arduino_Portenta_OTA(storage_type, data_offset)
, _bd_qspi{NULL}
, _fs_qspi{NULL}
, _block_device_qspi(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000)
{
assert(_storage_type == QSPI_FLASH_FATFS || _storage_type == QSPI_FLASH_FATFS_MBR);
}
Expand All @@ -44,13 +47,18 @@ Arduino_Portenta_OTA_QSPI::Arduino_Portenta_OTA_QSPI(StorageTypePortenta const s

bool Arduino_Portenta_OTA_QSPI::init()
{
if (_block_device_qspi.init() != QSPIF_BD_ERROR_OK)
#if !defined (COMPONENT_4343W_FS)
qspi_bd = new QSPIFBlockDevice(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
if (qspi_bd->init() != QSPIF_BD_ERROR_OK) {
Serial1.println("Error: QSPI init failure.");
return false;
}
#endif

if(_storage_type == QSPI_FLASH_FATFS)
{
_fs_qspi = new mbed::FATFileSystem("fs");
int const err_mount = _fs_qspi->mount(&_block_device_qspi);
int const err_mount = _fs_qspi->mount(qspi_bd);
if (err_mount)
{
Serial1.print("Error while mounting the filesystem. Err = ");
Expand All @@ -62,7 +70,7 @@ bool Arduino_Portenta_OTA_QSPI::init()

if (_storage_type == QSPI_FLASH_FATFS_MBR)
{
_bd_qspi = new mbed::MBRBlockDevice(reinterpret_cast<mbed::BlockDevice *>(&_block_device_qspi), _data_offset);
_bd_qspi = new mbed::MBRBlockDevice(reinterpret_cast<mbed::BlockDevice *>(qspi_bd), _data_offset);
_fs_qspi = new mbed::FATFileSystem("fs");
int const err_mount = _fs_qspi->mount(_bd_qspi);
if (err_mount) {
Expand Down
4 changes: 3 additions & 1 deletion src/Arduino_Portenta_OTA_QSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class Arduino_Portenta_OTA_QSPI : public Arduino_Portenta_OTA

mbed::BlockDevice * _bd_qspi;
mbed::FATFileSystem * _fs_qspi;
QSPIFBlockDevice _block_device_qspi;
#if !defined (COMPONENT_4343W_FS)
QSPIFBlockDevice *qspi_bd;
#endif

};

Expand Down