diff --git a/ion/src/device/bench/command/pcb_version.cpp b/ion/src/device/bench/command/pcb_version.cpp index aa30b35e5..190ea7274 100644 --- a/ion/src/device/bench/command/pcb_version.cpp +++ b/ion/src/device/bench/command/pcb_version.cpp @@ -12,11 +12,18 @@ void PCBVersion(const char * input) { return; } + /* When running the bench for a diagnostic, we must absolutely not write the + * OTP, as N0110 built prior to the PCB revision would still have their OTP + * blank and unlocked. */ +#if IN_FACTORY Board::writePCBVersion(PCB_LATEST); - if (Board::readPCBVersion() != PCB_LATEST) { + /* Read directly from memory, as when IN_FACTORY is true, the method + * readPCBVersion always returns PCB_LATEST. */ + if (Board::readPCBVersionInMemory() != PCB_LATEST) { reply(sKO); return; } +#endif reply(sOK); } diff --git a/ion/src/device/n0100/drivers/board.cpp b/ion/src/device/n0100/drivers/board.cpp index 921d872dc..cd9ebad17 100644 --- a/ion/src/device/n0100/drivers/board.cpp +++ b/ion/src/device/n0100/drivers/board.cpp @@ -234,6 +234,10 @@ PCBVersion readPCBVersion() { return PCB_LATEST; } +PCBVersion readPCBVersionInMemory() { + return PCB_LATEST; +} + void writePCBVersion(PCBVersion) {} } diff --git a/ion/src/device/n0110/drivers/board.cpp b/ion/src/device/n0110/drivers/board.cpp index 4bf47f820..c7d8391eb 100644 --- a/ion/src/device/n0110/drivers/board.cpp +++ b/ion/src/device/n0110/drivers/board.cpp @@ -379,8 +379,17 @@ constexpr int pcbVersionOTPIndex = 0; * version number. This way, devices with blank OTP are considered version 0. */ PCBVersion readPCBVersion() { - /* FIXME: When flashing for the first time after assembling the device, this - * should return PCB_LATEST. */ +#if IN_FACTORY + /* When flashing for the first time, we want all systems that depend on the + * PCB version to function correctly before flashing the PCB version. This + * way, flashing the PCB version can be done last. */ + return PCB_LATEST; +#else + return readPCBVersionInMemory(); +#endif +} + +PCBVersion readPCBVersionInMemory() { return ~*reinterpret_cast(InternalFlash::Config::OTPAddresses[pcbVersionOTPIndex]); } diff --git a/ion/src/device/shared/drivers/board.h b/ion/src/device/shared/drivers/board.h index 9c3370a84..9bbe9b62a 100644 --- a/ion/src/device/shared/drivers/board.h +++ b/ion/src/device/shared/drivers/board.h @@ -28,6 +28,7 @@ void setClockFrequency(Frequency f); typedef uint32_t PCBVersion; PCBVersion readPCBVersion(); +PCBVersion readPCBVersionInMemory(); void writePCBVersion(PCBVersion version); }