PF1550 Driver
API reference
Loading...
Searching...
No Matches
pf1550_diagnostics.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cstddef>
31#include <cstdint>
32
33#include "pf1550_registers.hpp"
34
35namespace pf1550 {
36
43enum class RailId : uint8_t {
44 Sw1 = 0,
45 Sw2 = 1,
46 Sw3 = 2,
47 Ldo1 = 3,
48 Ldo2 = 4,
49 Ldo3 = 5,
50 Vsnvs = 6,
51 COUNT = 7,
52};
53
65enum class FaultSeverity : uint8_t {
66 kInfo = 0,
67 kWarning = 1,
68 kCritical = 2,
69 kMcuKill = 3,
70};
71
79struct FaultFlags {
80 uint32_t value{0};
81
82 // ---- Switching regulator (per-rail HS / LS current limits) ----
83 static constexpr uint32_t kSw1Ls = 1u << 0;
84 static constexpr uint32_t kSw1Hs = 1u << 1;
85 static constexpr uint32_t kSw2Ls = 1u << 2;
86 static constexpr uint32_t kSw2Hs = 1u << 3;
87 static constexpr uint32_t kSw3Ls = 1u << 4;
88 static constexpr uint32_t kSw3Hs = 1u << 5;
89
90 // ---- LDO faults ----
91 static constexpr uint32_t kLdo1Fault = 1u << 8;
92 static constexpr uint32_t kLdo2Fault = 1u << 9;
93 static constexpr uint32_t kLdo3Fault = 1u << 10;
94
95 // ---- Temperature (TEMP_INT_STAT0, Table 102) ----
96 static constexpr uint32_t kTempWarn = 1u << 12;
97 static constexpr uint32_t kTempShdn = 1u << 13;
98
99 // ---- Misc system events (MISC_INT_STAT0, Table 108) ----
100 static constexpr uint32_t kPwrOn = 1u << 16;
101 static constexpr uint32_t kVsysLow = 1u << 17;
102 static constexpr uint32_t kVsysOv = 1u << 18;
103 static constexpr uint32_t kWdiAssert = 1u << 19;
104 static constexpr uint32_t kResetBmcu = 1u << 20;
105
106 // ---- Charger / VBUS ----
107 static constexpr uint32_t kChgFault = 1u << 24;
108 static constexpr uint32_t kVbusInval = 1u << 25;
109 static constexpr uint32_t kBattOv = 1u << 26;
110
111 // ---- Driver-internal (I²C path) ----
112 static constexpr uint32_t kI2cReadFail = 1u << 30;
113 static constexpr uint32_t kI2cWriteFail = 1u << 31;
114
115 [[nodiscard]] constexpr bool Any() const noexcept { return value != 0; }
116 [[nodiscard]] constexpr bool Has(uint32_t mask) const noexcept { return (value & mask) != 0; }
117 constexpr void Set(uint32_t mask) noexcept { value |= mask; }
118 constexpr void Clear(uint32_t mask) noexcept { value &= ~mask; }
119};
120
125 uint8_t ctrl_reg{0};
126 uint8_t volt_reg{0};
127 uint16_t set_voltage_mv{0};
128 bool enabled_run{false};
129 bool enabled_stby{false};
130 bool stat_latched{false};
131 bool sense_live{false};
132};
133
155
171
176constexpr RailId FaultRail(uint32_t single_flag) noexcept {
177 if (single_flag == FaultFlags::kSw1Ls || single_flag == FaultFlags::kSw1Hs) return RailId::Sw1;
178 if (single_flag == FaultFlags::kSw2Ls || single_flag == FaultFlags::kSw2Hs) return RailId::Sw2;
179 if (single_flag == FaultFlags::kSw3Ls || single_flag == FaultFlags::kSw3Hs) return RailId::Sw3;
180 if (single_flag == FaultFlags::kLdo1Fault) return RailId::Ldo1;
181 if (single_flag == FaultFlags::kLdo2Fault) return RailId::Ldo2;
182 if (single_flag == FaultFlags::kLdo3Fault) return RailId::Ldo3;
183 return RailId::COUNT;
184}
185
193constexpr FaultSeverity FaultSeverityPortentaH7(uint32_t single_flag) noexcept {
194 switch (single_flag) {
195 // MCU is powered from SW3 → losing SW3 kills the MCU.
198 // LDO1 (1.0 V) feeds the SOC core analog and MIPI bridge — losing it
199 // crashes the platform.
201 // LDO3 (1.2 V) feeds Ethernet PHY VDDCR and DSI core.
205
206 // SW1 (+3V1SW) feeds USB/ULPI, SDRAM, ETH PHY and LDO inputs — losing it
207 // takes USB / network down but MCU can still run on SW3+SW3-derived
208 // domains. It IS however necessary for LDO outputs.
211 // SW2 feeds carrier +3V3 only; MCU keeps running.
214 // LDO2 (1.8 V) for USB PHY — USB dies, MCU survives.
220
227
228 // No valid VBUS (VBUS_VALID clear, Table 153) is the normal state when running from the battery.
232 default:
234 }
235}
236
242 for (uint32_t bit = 0; bit < 32; ++bit) {
243 const uint32_t mask = 1u << bit;
244 if ((fl.value & mask) == 0) continue;
245 const auto sev = FaultSeverityPortentaH7(mask);
246 if (static_cast<uint8_t>(sev) > static_cast<uint8_t>(worst)) {
247 worst = sev;
248 }
249 }
250 return worst;
251}
252
254constexpr const char* RailName(RailId id) noexcept {
255 switch (id) {
256 case RailId::Sw1: return "SW1";
257 case RailId::Sw2: return "SW2";
258 case RailId::Sw3: return "SW3";
259 case RailId::Ldo1: return "LDO1";
260 case RailId::Ldo2: return "LDO2";
261 case RailId::Ldo3: return "LDO3";
262 case RailId::Vsnvs: return "VSNVS";
263 default: return "?";
264 }
265}
266
268constexpr const char* PmicStateName(PmicState s) noexcept {
269 switch (s) {
270 case PmicState::Wait: return "Wait";
271 case PmicState::Run: return "Run";
272 case PmicState::Standby: return "Standby";
273 case PmicState::Sleep: return "Sleep";
274 case PmicState::RegsDisable: return "RegsDisable";
275 default: return "Unknown";
276 }
277}
278
280constexpr const char* ChargerStateName(ChargerState s) noexcept {
281 switch (s) {
282 case ChargerState::PreCharge: return "PreCharge";
283 case ChargerState::FastCC: return "FastCC";
284 case ChargerState::FastCV: return "FastCV";
285 case ChargerState::EndOfCharge: return "EndOfCharge";
286 case ChargerState::Done: return "Done";
287 case ChargerState::TimerFault: return "TimerFault";
288 case ChargerState::ThermSuspend: return "ThermSuspend";
289 case ChargerState::Off: return "Off";
290 case ChargerState::BatteryOv: return "BatteryOv";
291 case ChargerState::TempShutdown: return "TempShutdown";
292 case ChargerState::LinearOnly: return "LinearOnly";
293 default: return "Unknown";
294 }
295}
296
298constexpr const char* FaultSeverityName(FaultSeverity s) noexcept {
299 switch (s) {
300 case FaultSeverity::kInfo: return "info";
301 case FaultSeverity::kWarning: return "warn";
302 case FaultSeverity::kCritical: return "critical";
303 case FaultSeverity::kMcuKill: return "mcu-kill";
304 default: return "?";
305 }
306}
307
308} // namespace pf1550
Definition pf1550.hpp:40
RailId
Logical identifier for each independently-controllable PF1550 output.
Definition pf1550_diagnostics.hpp:43
@ Ldo3
LDO3 — Portenta +1V2 (STM32 DSI, ETH PHY).
@ Sw2
SW2 / BUCK2 — Portenta +3V3 / carrier VOUT.
@ Sw3
SW3 / BUCK3 — Portenta +3V1 VCORE (MCU + QSPI).
@ Ldo2
LDO2 — Portenta +1V8 (USB PHY, MIPI).
@ Sw1
SW1 / BUCK1 — Portenta +3V1SW (feeds LDO inputs).
@ Vsnvs
VSNVS — RTC / backup LDO (≤2 mA).
@ Ldo1
LDO1 — Portenta +1V0 (MIPI bridge analog).
constexpr const char * ChargerStateName(ChargerState s) noexcept
Human-readable name for a ChargerState enumerator.
Definition pf1550_diagnostics.hpp:280
constexpr FaultSeverity FaultSeverityPortentaH7(uint32_t single_flag) noexcept
Classify the severity of a Portenta H7 eval fault.
Definition pf1550_diagnostics.hpp:193
constexpr RailId FaultRail(uint32_t single_flag) noexcept
Map a single fault flag to the rail it relates to, or RailId::COUNT if the fault is system-wide.
Definition pf1550_diagnostics.hpp:176
constexpr const char * PmicStateName(PmicState s) noexcept
Human-readable name for a PmicState enumerator.
Definition pf1550_diagnostics.hpp:268
constexpr const char * FaultSeverityName(FaultSeverity s) noexcept
Human-readable name for a FaultSeverity.
Definition pf1550_diagnostics.hpp:298
FaultSeverity
Severity classification for a fault.
Definition pf1550_diagnostics.hpp:65
PmicState
STATE_INFO[5:0] values (Reg 0x67) describing the PMIC state machine.
Definition pf1550_registers.hpp:226
@ Wait
Wait / start-up before regulators are sequenced.
@ RegsDisable
REGS_DISABLE — all regulators off (post PWRON long-press).
@ Sleep
SLEEP / LPSR — minimal regulators.
@ Standby
STANDBY — standby-enabled regulators only.
@ Run
RUN — all OTP-sequenced regulators enabled.
ChargerState
CHG_SNS[3:0] values (Reg 0x87) describing the charger sub-state.
Definition pf1550_registers.hpp:236
@ LinearOnly
Linear-only mode, no charge.
@ TempShutdown
Off because TJ > TSHDN.
@ FastCC
Fast-charge constant-current.
@ ThermSuspend
Thermistor suspend.
@ PreCharge
Precharge mode (V_BATT < V_PRECHG.LB).
@ EndOfCharge
End-of-charge (I_BAT = I_EOC).
@ Off
Input invalid or charger disabled.
@ BatteryOv
Battery overvoltage.
@ TimerFault
Timer fault.
@ Done
Done — battery full.
@ FastCV
Fast-charge constant-voltage.
constexpr FaultSeverity WorstSeverityPortentaH7(FaultFlags fl) noexcept
Return the worst-case severity across an aggregated bitmask.
Definition pf1550_diagnostics.hpp:240
constexpr const char * RailName(RailId id) noexcept
Human-readable rail label ("SW1", "LDO2", …).
Definition pf1550_diagnostics.hpp:254
NXP PF1550 family I2C register map, bit-field constants, and OTP keys.
Full diagnostic snapshot returned by PF1550::ReadDiagnosticSnapshot().
Definition pf1550_diagnostics.hpp:140
uint8_t state_info_reg
Reg 0x67 raw.
Definition pf1550_diagnostics.hpp:146
uint8_t otp_flavor
Reg 0x01 — 0x00 for A0EP.
Definition pf1550_diagnostics.hpp:144
uint8_t vbus_sns_reg
Reg 0x86.
Definition pf1550_diagnostics.hpp:150
uint16_t vbus_in_limit_ma
Decoded VBUS input current limit (mA).
Definition pf1550_diagnostics.hpp:151
uint8_t silicon_rev
Reg 0x02.
Definition pf1550_diagnostics.hpp:143
FaultFlags faults
Aggregated latched + sense conditions.
Definition pf1550_diagnostics.hpp:152
RailDiagnostics rails[static_cast< size_t >(RailId::COUNT)]
Definition pf1550_diagnostics.hpp:153
PmicState state
Decoded STATE_INFO[5:0].
Definition pf1550_diagnostics.hpp:147
ChargerState charger
Decoded CHG_SNS[3:0].
Definition pf1550_diagnostics.hpp:149
uint8_t device_id
Reg 0x00 — must equal 0x7C.
Definition pf1550_diagnostics.hpp:142
bool read_ok
All required I²C reads succeeded.
Definition pf1550_diagnostics.hpp:141
uint8_t int_category
Reg 0x06 — top-level interrupt summary.
Definition pf1550_diagnostics.hpp:145
uint8_t chg_sense_reg
Reg 0x87 raw.
Definition pf1550_diagnostics.hpp:148
Bitset of latched fault flags.
Definition pf1550_diagnostics.hpp:79
static constexpr uint32_t kBattOv
Definition pf1550_diagnostics.hpp:109
static constexpr uint32_t kTempShdn
THERM125I: die crossed 125 °C.
Definition pf1550_diagnostics.hpp:97
static constexpr uint32_t kLdo3Fault
Definition pf1550_diagnostics.hpp:93
static constexpr uint32_t kSw1Ls
Definition pf1550_diagnostics.hpp:83
static constexpr uint32_t kVbusInval
Definition pf1550_diagnostics.hpp:108
constexpr bool Any() const noexcept
Definition pf1550_diagnostics.hpp:115
static constexpr uint32_t kSw3Ls
Definition pf1550_diagnostics.hpp:87
static constexpr uint32_t kVsysLow
LOW_SYS_WARN_I: VSYS crossed LOW_SYS_WARN.
Definition pf1550_diagnostics.hpp:101
static constexpr uint32_t kChgFault
Definition pf1550_diagnostics.hpp:107
static constexpr uint32_t kTempWarn
THERM110I: die crossed 110 °C.
Definition pf1550_diagnostics.hpp:96
static constexpr uint32_t kLdo1Fault
Definition pf1550_diagnostics.hpp:91
constexpr void Set(uint32_t mask) noexcept
Definition pf1550_diagnostics.hpp:117
static constexpr uint32_t kLdo2Fault
Definition pf1550_diagnostics.hpp:92
static constexpr uint32_t kSw2Hs
Definition pf1550_diagnostics.hpp:86
uint32_t value
Definition pf1550_diagnostics.hpp:80
static constexpr uint32_t kPwrOn
PWRON_I: power-on button event.
Definition pf1550_diagnostics.hpp:100
static constexpr uint32_t kSw1Hs
Definition pf1550_diagnostics.hpp:84
constexpr bool Has(uint32_t mask) const noexcept
Definition pf1550_diagnostics.hpp:116
constexpr void Clear(uint32_t mask) noexcept
Definition pf1550_diagnostics.hpp:118
static constexpr uint32_t kI2cReadFail
Definition pf1550_diagnostics.hpp:112
static constexpr uint32_t kVsysOv
SYS_OVLO_I: VSYS crossed SYS_OVLO.
Definition pf1550_diagnostics.hpp:102
static constexpr uint32_t kI2cWriteFail
Definition pf1550_diagnostics.hpp:113
static constexpr uint32_t kSw3Hs
Definition pf1550_diagnostics.hpp:88
static constexpr uint32_t kWdiAssert
Never set: the PF1550 has no WDI interrupt bit.
Definition pf1550_diagnostics.hpp:103
static constexpr uint32_t kResetBmcu
Never set: the PF1550 has no RESETBMCU interrupt bit.
Definition pf1550_diagnostics.hpp:104
static constexpr uint32_t kSw2Ls
Definition pf1550_diagnostics.hpp:85
Per-rail status snapshot (latched + live + control byte).
Definition pf1550_diagnostics.hpp:124
uint8_t ctrl_reg
Raw SWn_CTRL, LDOn_CTRL or (VSNVS) VSNVS_CTRL byte.
Definition pf1550_diagnostics.hpp:125
bool sense_live
Live current-limit / fault sense bit set.
Definition pf1550_diagnostics.hpp:131
bool enabled_stby
STBY_EN bit set.
Definition pf1550_diagnostics.hpp:129
bool enabled_run
EN bit set.
Definition pf1550_diagnostics.hpp:128
uint16_t set_voltage_mv
Decoded target voltage in mV.
Definition pf1550_diagnostics.hpp:127
bool stat_latched
Any latched fault on this rail since last clear.
Definition pf1550_diagnostics.hpp:130
uint8_t volt_reg
Raw voltage register byte (RUN mode); 0 for VSNVS, which has none.
Definition pf1550_diagnostics.hpp:126
Result of a power self-test pass.
Definition pf1550_diagnostics.hpp:162
bool state_run
Definition pf1550_diagnostics.hpp:165
DiagnosticSnapshot snapshot
Definition pf1550_diagnostics.hpp:169
FaultFlags faults
Sticky fault snapshot at the time of test.
Definition pf1550_diagnostics.hpp:168
bool device_id_ok
Definition pf1550_diagnostics.hpp:164
bool all_rails_enabled
Definition pf1550_diagnostics.hpp:166
FaultSeverity worst_severity
Definition pf1550_diagnostics.hpp:167
bool ran
Definition pf1550_diagnostics.hpp:163