Skip to content

Commit d621bf2

Browse files
authored
Merge pull request #96 from tridge/pr-check-devinfo
check bootloader dev info for right eeprom address
2 parents e361395 + 08125a0 commit d621bf2

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Src/main.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,11 +1721,49 @@ void runBrushedLoop()
17211721
}
17221722
#endif
17231723

1724+
1725+
/*
1726+
check device info from the bootloader, confirming pin code and eeprom location
1727+
*/
1728+
static void checkDeviceInfo(void)
1729+
{
1730+
#define DEVINFO_MAGIC1 0x5925e3da
1731+
#define DEVINFO_MAGIC2 0x4eb863d9
1732+
1733+
const struct devinfo {
1734+
uint32_t magic1;
1735+
uint32_t magic2;
1736+
const uint8_t deviceInfo[9];
1737+
} *devinfo = (struct devinfo *)(0x1000 - 32);
1738+
if (devinfo->magic1 != DEVINFO_MAGIC1 ||
1739+
devinfo->magic2 != DEVINFO_MAGIC2) {
1740+
// bootloader does not support this feature, nothing to do
1741+
return;
1742+
}
1743+
// change eeprom_address based on the code in the bootloaders device info
1744+
switch (devinfo->deviceInfo[4]) {
1745+
case 0x1f:
1746+
eeprom_address = 0x08007c00;
1747+
break;
1748+
case 0x35:
1749+
eeprom_address = 0x0800f800;
1750+
break;
1751+
case 0x2b:
1752+
eeprom_address = 0x0801f800;
1753+
break;
1754+
}
1755+
1756+
// TODO: check pin code and reboot to bootloader if incorrect
1757+
1758+
}
1759+
17241760
int main(void)
17251761
{
17261762

17271763
initAfterJump();
17281764

1765+
checkDeviceInfo();
1766+
17291767
initCorePeripherals();
17301768

17311769
enableCorePeripherals();

0 commit comments

Comments
 (0)