forked from arduino-libraries/Arduino_Portenta_OTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduino_Portenta_OTA_QSPI.cpp
102 lines (84 loc) · 3.07 KB
/
Arduino_Portenta_OTA_QSPI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
This file is part of Arduino_Portenta_OTA.
Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
This software is released under the GNU General Public License version 3,
which covers the main part of arduino-cli.
The terms of this license can be found at:
https://www.gnu.org/licenses/gpl-3.0.en.html
You can be released from the requirements of the above licenses by purchasing
a commercial license. Buying such a license is mandatory if you want to modify or
otherwise use the software for commercial activities involving the Arduino
software without disclosing the source code of your own applications. To purchase
a commercial license, send an email to [email protected].
*/
/******************************************************************************
INCLUDE
******************************************************************************/
#include "Arduino_Portenta_OTA_Config.h"
#if defined(ARDUINO_PORTENTA_OTA_QSPI_SUPPORT)
#include "Arduino_Portenta_OTA_QSPI.h"
#include <assert.h>
using namespace arduino;
/******************************************************************************
CTOR/DTOR
******************************************************************************/
Arduino_Portenta_OTA_QSPI::Arduino_Portenta_OTA_QSPI(StorageTypePortenta const storage_type, uint32_t const data_offset)
: Arduino_Portenta_OTA(storage_type, data_offset)
, _bd_qspi{NULL}
, _fs_qspi{NULL}
{
assert(_storage_type == QSPI_FLASH_FATFS || _storage_type == QSPI_FLASH_FATFS_MBR);
}
/******************************************************************************
PUBLIC MEMBER FUNCTIONS
******************************************************************************/
bool Arduino_Portenta_OTA_QSPI::init()
{
#if defined (COMPONENT_4343W_FS)
_bd_raw_qspi = mbed::BlockDevice::get_default_instance();
#else
_bd_raw_qspi = new QSPIFBlockDevice(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
#endif
if (_bd_raw_qspi->init() != QSPIF_BD_ERROR_OK) {
Debug.print(DBG_ERROR, F("Error: QSPI init failure."));
return false;
}
if(_storage_type == QSPI_FLASH_FATFS)
{
_fs_qspi = new mbed::FATFileSystem("fs");
int const err_mount = _fs_qspi->mount(_bd_raw_qspi);
if (err_mount)
{
Debug.print(DBG_ERROR, F("Error while mounting the filesystem. Err = %d"), err_mount);
return false;
}
return true;
}
if (_storage_type == QSPI_FLASH_FATFS_MBR)
{
_bd_qspi = new mbed::MBRBlockDevice(_bd_raw_qspi, _data_offset);
_fs_qspi = new mbed::FATFileSystem("fs");
int const err_mount = _fs_qspi->mount(_bd_qspi);
if (err_mount) {
Debug.print(DBG_ERROR, F("Error while mounting the filesystem. Err = %d"), err_mount);
return false;
}
return true;
}
return false;
}
bool Arduino_Portenta_OTA_QSPI::open()
{
DIR * dir = NULL;
if ((dir = opendir("/fs")) != NULL)
{
if (Arduino_Portenta_OTA::findProgramLength(dir, _program_length))
{
closedir(dir);
return true;
}
closedir(dir);
}
return false;
}
#endif /* ARDUINO_PORTENTA_OTA_QSPI_SUPPORT */