Skip to content

Commit bcbba61

Browse files
authored
Merge pull request #582 from pennam/secure-info-sketch
Update STM32H747_getBootloaderInfo sketch to read all OTP data
2 parents 59d1c30 + 0881063 commit bcbba61

File tree

1 file changed

+70
-16
lines changed

1 file changed

+70
-16
lines changed

Diff for: libraries/STM32H747_System/examples/STM32H747_getBootloaderInfo/STM32H747_getBootloaderInfo.ino

+70-16
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ uint8_t* bootloader_identification = (uint8_t*)(0x80002F0);
33

44
#if __has_include("portenta_info.h")
55
#include "portenta_info.h"
6-
#define GET_OTP_BOARD_INFO
7-
uint8_t* boardInfo();
6+
#define GET_PORENTA_OTP_BOARD_INFO
7+
PortentaBoardInfo *info;
8+
PortentaBoardInfo* boardInfo();
9+
#endif
10+
11+
#if __has_include("opta_info.h")
12+
#include "opta_info.h"
13+
#define GET_OPTA_OTP_BOARD_INFO
14+
OptaBoardInfo *info;
15+
OptaBoardInfo* boardInfo();
816
#endif
917

1018
void setup() {
@@ -21,6 +29,66 @@ void setup() {
2129
Serial.println(currentBootloaderIdentifier);
2230
Serial.println("Magic Number (validation): " + String(bootloader_data[0], HEX));
2331
Serial.println("Bootloader version: " + String(bootloader_data[1]));
32+
33+
#if defined(GET_PORENTA_OTP_BOARD_INFO)
34+
printPortentaSecureInfo();
35+
#elif defined(GET_OPTA_OTP_BOARD_INFO)
36+
printOptaSecureInfo();
37+
#else
38+
printBootloaderInfo();
39+
#endif
40+
}
41+
42+
#if defined(GET_PORENTA_OTP_BOARD_INFO)
43+
void printPortentaSecureInfo() {
44+
info = boardInfo();
45+
if (info->magic == 0xB5) {
46+
Serial.println("Secure info version: " + String(info->version));
47+
Serial.println("USB Speed: " + String(info->_board_functionalities.usb_high_speed == 1 ? "USB 2.0/Hi-Speed (480 Mbps)" : "USB 1.1/Full-Speed (12 Mbps)"));
48+
Serial.println("Has Ethernet: " + String(info->_board_functionalities.ethernet == 1 ? "Yes" : "No"));
49+
Serial.println("Has WiFi module: " + String(info->_board_functionalities.wifi == 1 ? "Yes" : "No"));
50+
Serial.println("Has Video output: " + String(info->_board_functionalities.video == 1 ? "Yes" : "No"));
51+
Serial.println("Has SE050 crypto: " + String(info->_board_functionalities.nxp_crypto == 1 ? "Yes" : "No"));
52+
Serial.println("Has ATECC crypto: " + String(info->_board_functionalities.mchp_crypto == 1 ? "Yes" : "No"));
53+
Serial.println("RAM size: " + getRAMSize(info->external_ram_size));
54+
Serial.println("QSPI size: " + String(info->external_flash_size) + " MB");
55+
Serial.println("Secure board revision: " + String(info->revision >> 8) + "." + String(info->revision & 0xFF));
56+
Serial.println("Secure carrier identification: " + String(info->carrier >> 8) + "." + String(info->revision & 0xFF));
57+
Serial.println("Secure vid: 0x" + String(info->vid, HEX));
58+
Serial.println("Secure pid: 0x" + String(info->pid, HEX));
59+
Serial.println("Secure mac: " + String(info->mac_address[0], HEX) + ":" + String(info->mac_address[1], HEX) + ":" +
60+
String(info->mac_address[2], HEX) + ":" + String(info->mac_address[3], HEX) + ":" +
61+
String(info->mac_address[4], HEX) + ":" + String(info->mac_address[5], HEX));
62+
} else {
63+
Serial.println("No secure info available");
64+
printBootloaderInfo();
65+
}
66+
}
67+
#endif
68+
69+
#if defined(GET_OPTA_OTP_BOARD_INFO)
70+
void printOptaSecureInfo() {
71+
info = boardInfo();
72+
if (info->magic == 0xB5) {
73+
Serial.println("Secure info version: " + String(info->version));
74+
Serial.println("Has Ethernet: " + String(info->_board_functionalities.ethernet == 1 ? "Yes" : "No"));
75+
Serial.println("Has WiFi module: " + String(info->_board_functionalities.wifi == 1 ? "Yes" : "No"));
76+
Serial.println("Has RS485: " + String(info->_board_functionalities.rs485 == 1 ? "Yes" : "No"));
77+
Serial.println("QSPI size: " + String(info->external_flash_size) + " MB");
78+
Serial.println("Secure board revision: " + String(info->revision >> 8) + "." + String(info->revision & 0xFF));
79+
Serial.println("Secure vid: 0x" + String(info->vid, HEX));
80+
Serial.println("Secure pid: 0x" + String(info->pid, HEX));
81+
Serial.println("Secure mac: " + String(info->mac_address[0], HEX) + ":" + String(info->mac_address[1], HEX) + ":" +
82+
String(info->mac_address[2], HEX) + ":" + String(info->mac_address[3], HEX) + ":" +
83+
String(info->mac_address[4], HEX) + ":" + String(info->mac_address[5], HEX));
84+
} else {
85+
Serial.println("No secure info available");
86+
printBootloaderInfo();
87+
}
88+
}
89+
#endif
90+
91+
void printBootloaderInfo() {
2492
Serial.println("Clock source: " + getClockSource(bootloader_data[2]));
2593
Serial.println("USB Speed: " + getUSBSpeed(bootloader_data[3]));
2694
Serial.println("Has Ethernet: " + String(bootloader_data[4] == 1 ? "Yes" : "No"));
@@ -29,20 +97,6 @@ void setup() {
2997
Serial.println("QSPI size: " + String(bootloader_data[7]) + " MB");
3098
Serial.println("Has Video output: " + String(bootloader_data[8] == 1 ? "Yes" : "No"));
3199
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
46100
}
47101

48102
String getUSBSpeed(uint8_t flag) {

0 commit comments

Comments
 (0)