Skip to content

Commit 0a31c7f

Browse files
committed
Modify UM980 firmware update path
Use LittleFS so that the UM980 can be updated regardless of resets or terminal open/close. Built on similar STM32 pass through technique.
1 parent 1a6196a commit 0a31c7f

File tree

3 files changed

+154
-52
lines changed

3 files changed

+154
-52
lines changed

Firmware/RTK_Everywhere/LoRa.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ void removeUpdateLoraFirmware()
385385

386386
// Force UART connection to LoRa radio for firmware update on the next boot by creating updateLoraFirmware.txt in
387387
// LittleFS
388-
bool forceLoRaPassthrough()
388+
bool createLoRaPassthrough()
389389
{
390390
if (online.fs == false)
391391
return false;

Firmware/RTK_Everywhere/UM980.ino

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,3 +1149,148 @@ void um980MenuConstellations()
11491149
}
11501150

11511151
#endif // COMPILE_UM980
1152+
1153+
// Check if updateUm980Firmware.txt exists
1154+
bool checkUpdateUm980Firmware()
1155+
{
1156+
if (online.fs == false)
1157+
return false;
1158+
1159+
if (LittleFS.exists("/updateUm980Firmware.txt"))
1160+
{
1161+
if (settings.debugGnss)
1162+
systemPrintln("LittleFS updateUm980Firmware.txt exists");
1163+
1164+
// We do not remove the file here. See removeupdateUm980Firmware().
1165+
1166+
return true;
1167+
}
1168+
1169+
return false;
1170+
}
1171+
1172+
void removeUpdateUm980Firmware()
1173+
{
1174+
if (online.fs == false)
1175+
return;
1176+
1177+
if (LittleFS.exists("/updateUm980Firmware.txt"))
1178+
{
1179+
if (settings.debugGnss)
1180+
systemPrintln("Removing updateUm980Firmware.txt ");
1181+
1182+
LittleFS.remove("/updateUm980Firmware.txt");
1183+
}
1184+
}
1185+
1186+
// Force UART connection to UM980 for firmware update on the next boot by creating updateUm980Firmware.txt in
1187+
// LittleFS
1188+
bool createUm980Passthrough()
1189+
{
1190+
if (online.fs == false)
1191+
return false;
1192+
1193+
if (LittleFS.exists("/updateUm980Firmware.txt"))
1194+
{
1195+
if (settings.debugGnss)
1196+
systemPrintln("LittleFS updateUm980Firmware.txt already exists");
1197+
return true;
1198+
}
1199+
1200+
File updateUm980Firmware = LittleFS.open("/updateUm980Firmware.txt", FILE_WRITE);
1201+
updateUm980Firmware.close();
1202+
1203+
if (LittleFS.exists("/updateUm980Firmware.txt"))
1204+
return true;
1205+
1206+
if (settings.debugGnss)
1207+
systemPrintln("Unable to create updateUm980Firmware.txt on LittleFS");
1208+
return false;
1209+
}
1210+
1211+
void beginUm980FirmwareUpdate()
1212+
{
1213+
// Note: We cannot increase the bootloading speed beyond 115200 because
1214+
// we would need to alter the UM980 baud, then save to NVM, then allow the UM980 to reset.
1215+
// This is workable, but the next time the RTK Torch resets, it assumes communication at 115200bps
1216+
// This fails and communication is broken. We could program in some logic that attempts comm at 460800
1217+
// then reconfigures the UM980 to 115200bps, then resets, but autobaud detection in the UM980 library is
1218+
// not yet supported.
1219+
1220+
// Stop all UART tasks
1221+
tasksStopGnssUart();
1222+
1223+
systemPrintln();
1224+
systemPrintln("Entering UM980 direct connect for firmware update and configuration. Disconnect this terminal "
1225+
"connection. Use "
1226+
"UPrecise to update the firmware. Baudrate: 115200bps. Press the power button to return "
1227+
"to normal operation.");
1228+
systemFlush();
1229+
1230+
// Make sure ESP-UART1 is connected to UM980
1231+
muxSelectUm980();
1232+
1233+
if (serialGNSS == nullptr)
1234+
serialGNSS = new HardwareSerial(2); // Use UART2 on the ESP32 for communication with the GNSS module
1235+
1236+
serialGNSS->begin(115200, SERIAL_8N1, pin_GnssUart_RX, pin_GnssUart_TX);
1237+
1238+
// UPrecise needs to query the device before entering bootload mode
1239+
// Wait for UPrecise to send bootloader trigger (character T followed by character @) before resetting UM980
1240+
bool inBootMode = false;
1241+
1242+
// Echo everything to/from UM980
1243+
while (1)
1244+
{
1245+
// Data coming from UM980 to external USB
1246+
if (serialGNSS->available())
1247+
Serial.write(serialGNSS->read());
1248+
1249+
// Data coming from external USB to UM980
1250+
if (Serial.available())
1251+
{
1252+
byte incoming = Serial.read();
1253+
serialGNSS->write(incoming);
1254+
1255+
// Detect bootload sequence
1256+
if (inBootMode == false && incoming == 'T')
1257+
{
1258+
byte nextIncoming = Serial.peek();
1259+
if (nextIncoming == '@')
1260+
{
1261+
// Reset UM980
1262+
um980Reset();
1263+
delay(25);
1264+
um980Boot();
1265+
1266+
inBootMode = true;
1267+
}
1268+
}
1269+
}
1270+
1271+
if (digitalRead(pin_powerButton) == HIGH)
1272+
{
1273+
while (digitalRead(pin_powerButton) == HIGH)
1274+
delay(100);
1275+
1276+
// Remove file and reset to exit pass-through mode
1277+
removeUpdateUm980Firmware();
1278+
1279+
// Beep to indicate exit
1280+
beepOn();
1281+
delay(300);
1282+
beepOff();
1283+
delay(100);
1284+
beepOn();
1285+
delay(300);
1286+
beepOff();
1287+
1288+
systemPrintln("Exiting UM980 passthrough mode");
1289+
systemFlush(); // Complete prints
1290+
1291+
ESP.restart();
1292+
}
1293+
}
1294+
1295+
systemFlush(); // Complete prints
1296+
}

Firmware/RTK_Everywhere/menuSystem.ino

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -519,59 +519,16 @@ void menuDebugHardware()
519519
}
520520
else if (incoming == 13 && present.gnss_um980)
521521
{
522-
// Note: We cannot increase the bootloading speed beyond 115200 because
523-
// we would need to alter the UM980 baud, then save to NVM, then allow the UM980 to reset.
524-
// This is workable, but the next time the RTK Torch resets, it assumes communication at 115200bps
525-
// This fails and communication is broken. We could program in some logic that attempts comm at 460800
526-
// then reconfigures the UM980 to 115200bps, then resets, but autobaud detection in the UM980 library is
527-
// not yet supported.
528-
529-
// Stop all UART tasks
530-
tasksStopGnssUart();
531-
532-
systemPrintln("Entering UM980 direct connect at 115200bps for firmware update and configuration. Use "
533-
"UPrecise to update "
534-
"the firmware. Power cycle RTK Torch to "
535-
"return to normal operation.");
536-
537-
// Make sure ESP-UART1 is connected to UM980
538-
digitalWrite(pin_muxA, LOW);
539-
540-
// UPrecise needs to query the device before entering bootload mode
541-
// Wait for UPrecise to send bootloader trigger (character T followed by character @) before resetting UM980
542-
bool inBootMode = false;
543-
544-
// Echo everything to/from UM980
545-
while (1)
522+
// Create a file in LittleFS
523+
if (createUm980Passthrough() == true)
546524
{
547-
// Data coming from UM980 to external USB
548-
if (serialGNSS->available())
549-
systemWrite(serialGNSS->read());
550-
551-
// Data coming from external USB to UM980
552-
if (systemAvailable())
553-
{
554-
byte incoming = systemRead();
555-
serialGNSS->write(incoming);
556-
557-
// Detect bootload sequence
558-
if (inBootMode == false && incoming == 'T')
559-
{
560-
byte nextIncoming = Serial.peek();
561-
if (nextIncoming == '@')
562-
{
563-
// Reset UM980
564-
um980Reset();
565-
delay(25);
566-
um980Boot();
525+
systemPrintln();
526+
systemPrintln("UM980 passthrough mode has been recorded to LittleFS. Device will now reset.");
527+
systemFlush(); // Complete prints
567528

568-
inBootMode = true;
569-
}
570-
}
571-
}
529+
ESP.restart();
572530
}
573531
}
574-
575532
else if (incoming == 14)
576533
{
577534
settings.enablePsram ^= 1;
@@ -586,10 +543,10 @@ void menuDebugHardware()
586543
}
587544
else if (incoming == 17 && present.radio_lora)
588545
{
589-
if (forceLoRaPassthrough() == true)
546+
if (createLoRaPassthrough() == true)
590547
{
591548
systemPrintln();
592-
systemPrintln("Passthrough mode has been recorded to LittleFS. Device will now reset.");
549+
systemPrintln("STM32 passthrough mode has been recorded to LittleFS. Device will now reset.");
593550
systemFlush(); // Complete prints
594551

595552
ESP.restart();

0 commit comments

Comments
 (0)