Skip to content

Commit e2ddcdf

Browse files
authored
Merge pull request #563 from facchinm/qspi_subclassing
[Portenta] Finally fix RTC drift and read proper information from the board
2 parents 9ce4568 + ceeeab4 commit e2ddcdf

16 files changed

+32055
-31549
lines changed
Binary file not shown.
Binary file not shown.

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/examples/STM32H747_getBootloaderInfo/STM32H747_getBootloaderInfo.ino

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
uint8_t* bootloader_data = (uint8_t*)(0x801F000);
22
uint8_t* bootloader_identification = (uint8_t*)(0x80002F0);
33

4+
#if __has_include("portenta_info.h")
5+
#include "portenta_info.h"
6+
#define GET_OTP_BOARD_INFO
7+
uint8_t* boardInfo();
8+
#endif
9+
410
void setup() {
511
Serial.begin(115200);
612
while (!Serial) {}
@@ -23,6 +29,20 @@ void setup() {
2329
Serial.println("QSPI size: " + String(bootloader_data[7]) + " MB");
2430
Serial.println("Has Video output: " + String(bootloader_data[8] == 1 ? "Yes" : "No"));
2531
Serial.println("Has Crypto chip: " + String(bootloader_data[9] == 1 ? "Yes" : "No"));
32+
33+
#ifdef GET_OTP_BOARD_INFO
34+
auto info = *((PortentaBoardInfo*)boardInfo());
35+
if (info.magic == 0xB5) {
36+
Serial.println("Secure info version: " + String(info.version));
37+
Serial.println("Secure board revision: " + String(info.revision >> 8) + "." + String(info.revision & 0xFF));
38+
Serial.println("Secure carrier identification: " + String(info.carrier >> 8) + "." + String(info.revision & 0xFF));
39+
Serial.println("Secure vid: 0x" + String(info.vid, HEX));
40+
Serial.println("Secure pid: 0x" + String(info.pid, HEX));
41+
Serial.println("Secure mac: " + String(info.mac_address[0], HEX) + ":" + String(info.mac_address[1], HEX) + ":" +
42+
String(info.mac_address[2], HEX) + ":" + String(info.mac_address[3], HEX) + ":" +
43+
String(info.mac_address[4], HEX) + ":" + String(info.mac_address[5], HEX));
44+
}
45+
#endif
2646
}
2747

2848
String getUSBSpeed(uint8_t flag) {

libraries/STM32H747_System/examples/STM32H747_manageBootloader/STM32H747_manageBootloader.ino

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
#include "LittleFileSystem.h"
55
#include "FATFileSystem.h"
66
#if defined(ARDUINO_PORTENTA_H7_M7)
7+
#include "portenta_info.h"
78
#include "portenta_bootloader.h"
89
#include "portenta_lite_bootloader.h"
910
#include "portenta_lite_connected_bootloader.h"
1011
#include "mcuboot_bootloader.h"
1112
#include "ecdsa-p256-encrypt-key.h"
1213
#include "ecdsa-p256-signing-key.h"
14+
#define GET_OTP_BOARD_INFO
1315
#elif defined(ARDUINO_NICLA_VISION)
1416
#include "nicla_vision_bootloader.h"
1517
#endif
@@ -42,6 +44,8 @@ uint8_t* bootloader_identification = (uint8_t*)(BOOTLOADER_ADDR + bootloader_ide
4244
const unsigned char* bootloader_ptr = &bootloader_mbed_bin[0];
4345
long bootloader_len = bootloader_mbed_bin_len;
4446

47+
uint8_t* boardInfo();
48+
4549
void setup() {
4650
Serial.begin(115200);
4751
while (!Serial) {}
@@ -65,6 +69,20 @@ void setup() {
6569
Serial.println("Has Video output: " + String(bootloader_data[8] == 1 ? "Yes" : "No"));
6670
Serial.println("Has Crypto chip: " + String(bootloader_data[9] == 1 ? "Yes" : "No"));
6771

72+
#ifdef GET_OTP_BOARD_INFO
73+
auto info = *((PortentaBoardInfo*)boardInfo());
74+
if (info.magic == 0xB5) {
75+
Serial.println("Secure info version: " + String(info.version));
76+
Serial.println("Secure board revision: " + String(info.revision >> 8) + "." + String(info.revision & 0xFF));
77+
Serial.println("Secure carrier identification: " + String(info.carrier >> 8) + "." + String(info.revision & 0xFF));
78+
Serial.println("Secure vid: 0x" + String(info.vid, HEX));
79+
Serial.println("Secure pid: 0x" + String(info.pid, HEX));
80+
Serial.println("Secure mac: " + String(info.mac_address[0], HEX) + ":" + String(info.mac_address[1], HEX) + ":" +
81+
String(info.mac_address[2], HEX) + ":" + String(info.mac_address[3], HEX) + ":" +
82+
String(info.mac_address[4], HEX) + ":" + String(info.mac_address[5], HEX));
83+
}
84+
#endif
85+
6886
video_available = bootloader_data[8];
6987
wifi_available = bootloader_data[5];
7088

libraries/STM32H747_System/examples/STM32H747_manageBootloader/portenta_bootloader.h

Lines changed: 10580 additions & 10519 deletions
Large diffs are not rendered by default.

libraries/STM32H747_System/examples/STM32H747_manageBootloader/portenta_lite_bootloader.h

Lines changed: 10576 additions & 10515 deletions
Large diffs are not rendered by default.

libraries/STM32H747_System/examples/STM32H747_manageBootloader/portenta_lite_connected_bootloader.h

Lines changed: 10576 additions & 10515 deletions
Large diffs are not rendered by default.

libraries/STM32H747_System/src/Portenta_System.cpp

Lines changed: 1 addition & 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

libraries/STM32H747_System/src/Portenta_System.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class Portenta_System: public STM32H747
1212
Portenta_System() {};
1313
virtual bool begin();
1414
virtual bool enterLowPower();
15+
String getBoardRevision();
16+
uint16_t getCarrierSpecs();
1517
};
1618

1719
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
From a316902eaa2b438e71a40f0992fc8094058eaa63 Mon Sep 17 00:00:00 2001
2+
From: Martino Facchin <m.facchin@arduino.cc>
3+
Date: Fri, 23 Sep 2022 09:51:20 +0200
4+
Subject: [PATCH] QSPI: make _qspi object protected to allow subclassing
5+
6+
---
7+
.../COMPONENT_QSPIF/include/QSPIF/QSPIFBlockDevice.h | 2 ++
8+
1 file changed, 2 insertions(+)
9+
10+
diff --git a/storage/blockdevice/COMPONENT_QSPIF/include/QSPIF/QSPIFBlockDevice.h b/storage/blockdevice/COMPONENT_QSPIF/include/QSPIF/QSPIFBlockDevice.h
11+
index 2903ecad32..695a396197 100644
12+
--- a/storage/blockdevice/COMPONENT_QSPIF/include/QSPIF/QSPIFBlockDevice.h
13+
+++ b/storage/blockdevice/COMPONENT_QSPIF/include/QSPIF/QSPIFBlockDevice.h
14+
@@ -340,9 +340,11 @@ private:
15+
QSPIF_BP_CLEAR_SR, // Clear protection bits in status register 1
16+
};
17+
18+
+protected:
19+
// QSPI Driver Object
20+
mbed::QSPI _qspi;
21+
22+
+private:
23+
// Static List of different QSPI based Flash devices csel that already exist
24+
// Each QSPI Flash device csel can have only 1 QSPIFBlockDevice instance
25+
// _devices_mutex is used to lock csel list - only one QSPIFBlockDevice instance per csel is allowed
26+
--
27+
2.37.3
28+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
From 92907dc0a3dec975e250f753fbc72a2b57639565 Mon Sep 17 00:00:00 2001
2+
From: Martino Facchin <m.facchin@arduino.cc>
3+
Date: Wed, 28 Sep 2022 17:27:56 +0200
4+
Subject: [PATCH 178/179] STM32H747: linker: set bootloader_info section for
5+
all bootloaders
6+
7+
---
8+
.../TARGET_STM32H747xI_CM7/TOOLCHAIN_GCC_ARM/STM32H747xI_CM7.ld | 2 +-
9+
1 file changed, 1 insertion(+), 1 deletion(-)
10+
11+
diff --git a/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_STM32H747xI_CM7/TOOLCHAIN_GCC_ARM/STM32H747xI_CM7.ld b/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_STM32H747xI_CM7/TOOLCHAIN_GCC_ARM/STM32H747xI_CM7.ld
12+
index 3e84731230..2914967e38 100644
13+
--- a/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_STM32H747xI_CM7/TOOLCHAIN_GCC_ARM/STM32H747xI_CM7.ld
14+
+++ b/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_STM32H747xI_CM7/TOOLCHAIN_GCC_ARM/STM32H747xI_CM7.ld
15+
@@ -113,7 +113,7 @@ SECTIONS
16+
*(SORT(.dtors.*))
17+
*(.dtors)
18+
19+
-#if defined(MCUBOOT_BOOTLOADER_BUILD) && ( defined(TARGET_PORTENTA_H7_M7) || defined(TARGET_NICLA_VISION))
20+
+#if (defined(MCUBOOT_BOOTLOADER_BUILD) || defined(BOOTLOADER_BUILD)) && (defined(TARGET_PORTENTA_H7_M7) || defined(TARGET_NICLA_VISION))
21+
*ltrans0*.o(.rodata*)
22+
*ltrans1*.o(.rodata*)
23+
*ltrans2*.o(.rodata*)
24+
--
25+
2.37.3
26+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
From 98eef4b565d5701b55e58388b14d45f1776e0430 Mon Sep 17 00:00:00 2001
2+
From: Martino Facchin <m.facchin@arduino.cc>
3+
Date: Wed, 28 Sep 2022 17:28:59 +0200
4+
Subject: [PATCH 179/179] STM32: RTC: allow runtime clock source selection
5+
6+
---
7+
targets/TARGET_STM/rtc_api.c | 80 +++++++++++++++++++++---------------
8+
1 file changed, 46 insertions(+), 34 deletions(-)
9+
10+
diff --git a/targets/TARGET_STM/rtc_api.c b/targets/TARGET_STM/rtc_api.c
11+
index 3fb6cc7320..4b0d386e39 100644
12+
--- a/targets/TARGET_STM/rtc_api.c
13+
+++ b/targets/TARGET_STM/rtc_api.c
14+
@@ -44,6 +44,14 @@ static int RTC_inited = 0;
15+
16+
static RTC_HandleTypeDef RtcHandle;
17+
18+
+MBED_WEAK bool isLSEAvailableAndPrecise() {
19+
+#if MBED_CONF_TARGET_LSE_AVAILABLE
20+
+ return true;
21+
+#else
22+
+ return false;
23+
+#endif
24+
+}
25+
+
26+
void rtc_init(void)
27+
{
28+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
29+
@@ -73,44 +81,48 @@ void rtc_init(void)
30+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
31+
error("PeriphClkInitStruct RTC failed with HSE\n");
32+
}
33+
-#elif (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_LSE_OR_LSI) && MBED_CONF_TARGET_LSE_AVAILABLE
34+
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
35+
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
36+
-#if MBED_CONF_TARGET_LSE_BYPASS
37+
- RCC_OscInitStruct.LSEState = RCC_LSE_BYPASS;
38+
-#else
39+
- RCC_OscInitStruct.LSEState = RCC_LSE_ON;
40+
-#endif
41+
-
42+
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
43+
- error("Cannot initialize RTC with LSE\n");
44+
- }
45+
+#elif (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_LSE_OR_LSI)
46+
+
47+
+ // Request if LSE is precise (fallback to WEAK implementation in case)
48+
+ if (isLSEAvailableAndPrecise()) {
49+
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
50+
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
51+
+ #if MBED_CONF_TARGET_LSE_BYPASS
52+
+ RCC_OscInitStruct.LSEState = RCC_LSE_BYPASS;
53+
+ #else
54+
+ RCC_OscInitStruct.LSEState = RCC_LSE_ON;
55+
+ #endif
56+
+
57+
+ if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
58+
+ error("Cannot initialize RTC with LSE\n");
59+
+ }
60+
61+
- __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
62+
+ __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
63+
64+
- PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
65+
- PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
66+
- if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
67+
- error("PeriphClkInitStruct RTC failed with LSE\n");
68+
- }
69+
-#else /* Fallback to LSI */
70+
-#if TARGET_STM32WB
71+
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI1;
72+
-#else
73+
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
74+
-#endif
75+
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
76+
- RCC_OscInitStruct.LSIState = RCC_LSI_ON;
77+
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
78+
- error("Cannot initialize RTC with LSI\n");
79+
- }
80+
+ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
81+
+ PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
82+
+ if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
83+
+ error("PeriphClkInitStruct RTC failed with LSE\n");
84+
+ }
85+
+ } else {
86+
+ #if TARGET_STM32WB
87+
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI1;
88+
+ #else
89+
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
90+
+ #endif
91+
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
92+
+ RCC_OscInitStruct.LSIState = RCC_LSI_ON;
93+
+ if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
94+
+ error("Cannot initialize RTC with LSI\n");
95+
+ }
96+
97+
- __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
98+
+ __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
99+
100+
- PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
101+
- PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
102+
- if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
103+
- error("PeriphClkInitStruct RTC failed with LSI\n");
104+
+ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
105+
+ PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
106+
+ if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
107+
+ error("PeriphClkInitStruct RTC failed with LSI\n");
108+
+ }
109+
}
110+
#endif /* MBED_CONF_TARGET_RTC_CLOCK_SOURCE */
111+
#if defined(DUAL_CORE) && (TARGET_STM32H7)
112+
--
113+
2.37.3
114+
372 Bytes
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#define OTP_QSPI_MAGIC 0xB5
2+
3+
typedef struct {
4+
uint8_t magic;
5+
uint8_t version;
6+
union {
7+
uint16_t board_functionalities;
8+
struct {
9+
uint8_t usb_high_speed :1;
10+
uint8_t ethernet :1;
11+
uint8_t wifi :1;
12+
uint8_t video :1;
13+
uint8_t nxp_crypto :1;
14+
uint8_t mchp_crypto :1;
15+
} _board_functionalities;
16+
};
17+
uint16_t revision;
18+
uint16_t carrier;
19+
uint8_t external_ram_size;
20+
uint8_t external_flash_size;
21+
uint16_t vid;
22+
uint16_t pid;
23+
uint8_t mac_address[6];
24+
uint8_t mac_address_2[6];
25+
} PortentaBoardInfo;
26+
27+
typedef struct {
28+
uint8_t magic;
29+
uint8_t version;
30+
uint8_t clock_source;
31+
uint8_t usb_speed;
32+
uint8_t ethernet;
33+
uint8_t wifi;
34+
uint8_t ram_size;
35+
uint8_t qspi_size;
36+
uint8_t video;
37+
uint8_t crypto;
38+
uint8_t extclock;
39+
} PortentaBootloaderInfo;

0 commit comments

Comments
 (0)