Skip to content

Commit ca309f1

Browse files
committed
Provide getSecureFlashData() APi for Portenta
1 parent 270f7cd commit ca309f1

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

cores/arduino/mbed/storage/blockdevice/COMPONENT_QSPIF/include/QSPIF/QSPIFBlockDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,11 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
340340
QSPIF_BP_CLEAR_SR, // Clear protection bits in status register 1
341341
};
342342

343+
protected:
343344
// QSPI Driver Object
344345
mbed::QSPI _qspi;
345346

347+
private:
346348
// Static List of different QSPI based Flash devices csel that already exist
347349
// Each QSPI Flash device csel can have only 1 QSPIFBlockDevice instance
348350
// _devices_mutex is used to lock csel list - only one QSPIFBlockDevice instance per csel is allowed

libraries/STM32H747_System/src/Portenta_System.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Portenta_System.h"
44
#include "Wire.h"
55
#include "mbed.h"
6+
#include "SecureQSPI.h"
67

78
#define PMIC_ADDRESS 0x08
89

@@ -15,6 +16,14 @@ bool arduino::Portenta_System::enterLowPower() {
1516
/* TO DO */
1617
}
1718

19+
// 8Kbit secure OTP area (on MX25L12833F)
20+
bool arduino::Portenta_System::getSecureFlashData(void* buf, size_t size) {
21+
static SecureQSPIFBlockDevice root;
22+
root.init();
23+
auto ret = root.readSecure(buf, 0, size > 512 ? 512 : size);
24+
return ret == 0;
25+
}
26+
1827
arduino::Portenta_System Portenta;
1928

2029
#endif

libraries/STM32H747_System/src/Portenta_System.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Portenta_System: public STM32H747
1212
Portenta_System() {};
1313
virtual bool begin();
1414
virtual bool enterLowPower();
15+
bool getSecureFlashData(void* buf, size_t size);
1516
};
1617

1718
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "Arduino.h"
2+
#include "QSPIFBlockDevice.h"
3+
4+
class SecureQSPIFBlockDevice: public QSPIFBlockDevice {
5+
public:
6+
virtual int readSecure(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size) {
7+
int ret = 0;
8+
ret &= _qspi.command_transfer(0xB1, -1, nullptr, 0, nullptr, 0);
9+
ret &= read(buffer, addr, size);
10+
ret &= _qspi.command_transfer(0xC1, -1, nullptr, 0, nullptr, 0);
11+
return ret;
12+
}
13+
};

0 commit comments

Comments
 (0)