Skip to content

Commit 1efa4b7

Browse files
committed
fix(flash): Add support for querying hardware version on USB 3.0 ports
As noted in the linked commit (coming from pybricks/pybricksdev#98), the EEPROM version can still be read even when the brick is plugged into a USB 3.0 port. Unforunately, the CRC packets likely cannot be salvaged this way - the CRC request is longer than the CRC response and so the CRC value is overwritten inside the brick.
1 parent 5ceca38 commit 1efa4b7

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/bl_info.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ int bootloader_info(void)
5252
return ERR_COMM;
5353
}
5454

55-
// forbid looped-back packets (usb 3.0 bug; reply *is* required here)
56-
if (reply->type == VM_SYS_RQ)
57-
return ERR_USBLOOP;
55+
// Looped-back packets (e.g. reply->type == VM_SYS_RQ) are acceptable.
56+
// According to https://github.com/pybricks/pybricksdev/commit/81f310da54ff40092bb4166226f8d52f943404c5
57+
// the issue is less severe than originally anticipated. Only a part
58+
// of the response buffer is overwritten by the PC's request and
59+
// in this case the EEPROM version is preserved.
5860

59-
if (reply->type != VM_OK)
61+
if (reply->type != VM_OK && reply->type != VM_SYS_RQ)
6062
{
6163
errno = reply->ret;
6264
fputs("Operation failed.\nlast_reply=", stderr);
@@ -66,12 +68,23 @@ int bootloader_info(void)
6668
return ERR_VM;
6769
}
6870

69-
int name_idx = 0;
70-
if (1 <= reply->hardwareVersion && reply->hardwareVersion <= 6)
71-
name_idx = reply->hardwareVersion;
71+
if (reply->type == VM_OK) {
72+
int name_idx = 0;
73+
if (1 <= reply->hardwareVersion && reply->hardwareVersion <= 6)
74+
name_idx = reply->hardwareVersion;
7275

73-
printf("Hardware version : V%4.2f (%s)\n", reply->hardwareVersion / 10.0f, hw_names[name_idx]);
74-
printf("EEPROM version : V%4.2f\n", reply->eepromVersion / 10.0f);
76+
printf("Hardware version : V%4.2f (%s)\n", reply->hardwareVersion / 10.0f, hw_names[name_idx]);
77+
printf("EEPROM version : V%4.2f\n", reply->eepromVersion / 10.0f);
78+
} else { // VM_SYS_RQ
79+
// hardwareVersion is corrupted, only eepromVersion is valid.
80+
// However, in production HW versions it holds that eepromVersion == hardwareVersion
81+
int name_idx = 0;
82+
if (1 <= reply->eepromVersion && reply->eepromVersion <= 6)
83+
name_idx = reply->eepromVersion;
84+
85+
printf("Hardware version : unknown (unable to query via USB 3.0)\n");
86+
printf("EEPROM version : V%4.2f (%s)\n", reply->eepromVersion / 10.0f, hw_names[name_idx]);
87+
}
7588

7689
errmsg = "`FW_GETVERSION` was successful.";
7790
return ERR_UNK;

0 commit comments

Comments
 (0)