Skip to content

Commit ce13a58

Browse files
committed
Device_Update: Add LoRa firmware update support
1 parent 17dfdf6 commit ce13a58

3 files changed

Lines changed: 420 additions & 0 deletions

File tree

Firmware/RTK_Everywhere/Device_Update.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,19 @@ const DFU_BUFFER_INFO dfuBufferInfo[] =
270270
};
271271
const int dfuBufferInfoCount = sizeof(dfuBufferInfo) / sizeof(dfuBufferInfo[0]);
272272

273+
//----------------------------------------
274+
// Device specific context
275+
//----------------------------------------
276+
277+
typedef struct _DFU_STM32_CONTEXT
278+
{
279+
HardwareSerial * _stm32Serial; // ESP32 serial port for STM32 communication
280+
} DFU_STM32_CONTEXT;
281+
#define DFU_STM32_CTX_LEN sizeof(DFU_STM32_CONTEXT)
282+
283+
// Context initialization routines
284+
bool dfuLoRaCtxInit(DEVICE_FIRMWARE_CTX * ctx);
285+
273286
//----------------------------------------
274287
// Declare the device specific maximum write size
275288
//----------------------------------------
@@ -280,20 +293,27 @@ const int dfuBufferInfoCount = sizeof(dfuBufferInfo) / sizeof(dfuBufferInfo[0]);
280293
#define DFU_LG290P_BYTES (1 + 1 + 1 + 2 + 4 + DFU_LG290P_MAX_PAYLOAD_SIZE + 4 + 1)
281294
#endif // COMPILE_LG290P
282295

296+
// STM32 declarations
297+
#define DFU_STM32_MAX_PAYLOAD_SIZE 256
298+
#define DFU_STM32_BYTES (1 + DFU_STM32_MAX_PAYLOAD_SIZE + 1)
299+
283300
//----------------------------------------
284301
// Declare the forward device support routines
285302
//----------------------------------------
286303

287304
// Get firmware version
288305
String dfuEsp32GetFirmwareVersion(DEVICE_FIRMWARE_CTX * ctx);
289306
String dfuGnssGetFirmwareVersion(DEVICE_FIRMWARE_CTX * ctx);
307+
String dfuLoRaGetFirmwareVersion(DEVICE_FIRMWARE_CTX * ctx);
290308

291309
// Device reset
292310
bool dfuLg290pReset(DEVICE_FIRMWARE_CTX * ctx, uint32_t currentMsec);
311+
bool dfuLoRaReset(DEVICE_FIRMWARE_CTX * ctx, uint32_t currentMsec);
293312

294313
// Device open, prepare for writing firmware
295314
bool dfuEsp32Open(DEVICE_FIRMWARE_CTX * ctx);
296315
bool dfuLg290pOpen(DEVICE_FIRMWARE_CTX * ctx);
316+
bool dfuStm32Open(DEVICE_FIRMWARE_CTX * ctx);
297317

298318
// Device write, perform the firmware update
299319
ssize_t dfuEsp32Write(DEVICE_FIRMWARE_CTX * ctx,
@@ -302,10 +322,14 @@ ssize_t dfuEsp32Write(DEVICE_FIRMWARE_CTX * ctx,
302322
ssize_t dfuLg290pWrite(DEVICE_FIRMWARE_CTX * ctx,
303323
const uint8_t * buffer,
304324
size_t bytesToWrite);
325+
ssize_t dfuStm32Write(DEVICE_FIRMWARE_CTX * ctx,
326+
const uint8_t * buffer,
327+
size_t bytesToWrite);
305328

306329
// Device close, finalize the firmware update
307330
void dfuEsp32Close(DEVICE_FIRMWARE_CTX * ctx);
308331
void dfuLg290pClose(DEVICE_FIRMWARE_CTX * ctx);
332+
void dfuLoRaClose(DEVICE_FIRMWARE_CTX * ctx);
309333

310334
// Declare the begin routine
311335
bool deviceFirmwareUpdateBegin(bool doAll,
@@ -327,6 +351,11 @@ const DEVICE_FIRMWARE_INFO deviceFirmwareInfo[] =
327351
#ifdef COMPILE_LG290P
328352
{"LG290P", &present.gnss_lg290p, "/gnss/lg290p", "LG290P", ".pkg", dfuGnssGetFirmwareVersion, dfuLg290pReset, dfuLg290pOpen, dfuLg290pWrite, dfuLg290pClose, nullptr, 0, true, false, DFU_LG290P_BYTES, DFU_LG290P_MAX_PAYLOAD_SIZE, dfuGithub, dfuRawHead, dfuFileTree, dfuItems, dfuListEnd, dfuName, dfuNameEnd, dfuRawHead},
329353
#endif // COMPILE_LG290P
354+
355+
// LoRa devices
356+
#ifdef COMPILE_LORA
357+
{"LoRa", &present.radio_lora, "/lora/stm32wl", "LoRa_", ".bin", dfuLoRaGetFirmwareVersion, dfuLoRaReset, dfuStm32Open, dfuStm32Write, dfuLoRaClose, dfuLoRaCtxInit, DFU_STM32_CTX_LEN, false, false, DFU_STM32_BYTES, DFU_STM32_MAX_PAYLOAD_SIZE, dfuGithub, dfuRawHead, dfuFileTree, dfuItems, dfuListEnd, dfuName, dfuNameEnd, dfuRawHead},
358+
#endif // COMPILE_LORA
330359
};
331360
const int deviceFirmwareInfoCount = sizeof(deviceFirmwareInfo) / sizeof(deviceFirmwareInfo[0]);
332361

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2+
Device_Update_LoRa.ino
3+
4+
Update LoRa (STM32) firmware
5+
See https://www.st.com/resource/en/application_note/CD00264342.pdf
6+
7+
Example Linux command to covert Intel Hex files into binary files:
8+
9+
objcopy --input-target=ihex --output-target=binary --gap-fill 0xff SparkPNT_LoRa_3.0.1.hex SparkPNT_LoRa_3.0.1.bin
10+
11+
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
12+
13+
#ifdef COMPILE_LORA
14+
15+
//----------------------------------------
16+
// Perform the cleanup after the firmware download
17+
//----------------------------------------
18+
void dfuLoRaClose(DEVICE_FIRMWARE_CTX * ctx)
19+
{
20+
systemPrintf("Update Complete. Resetting IC...");
21+
22+
gpioExpanderLoraBootDisable(); // Pull BOOT0 low to exit bootloader mode on reset
23+
dfuLoRaReset(); // Power cycle LoRa to reset into normal mode
24+
}
25+
26+
//----------------------------------------
27+
// Initialize the device specific context structure
28+
//----------------------------------------
29+
bool dfuLoRaCtxInit(DEVICE_FIRMWARE_CTX * ctx)
30+
{
31+
DFU_STM32_CONTEXT * stm32Ctx;
32+
33+
stm32Ctx = (DFU_STM32_CONTEXT *)(ctx->_devCtx);
34+
stm32Ctx->_stm32Serial = SerialForLoRa;
35+
return true;
36+
}
37+
38+
//----------------------------------------
39+
// Get the firmware version
40+
//----------------------------------------
41+
String dfuLoRaGetFirmwareVersion(DEVICE_FIRMWARE_CTX * ctx)
42+
{
43+
return String(loraFirmwareVersion);
44+
}
45+
46+
//----------------------------------------
47+
// There is not a hardware reset pin exposed. Power cycle the device.
48+
//----------------------------------------
49+
void dfuLoRaReset()
50+
{
51+
gpioExpanderLoraDisable(); // Power off
52+
delay(100);
53+
gpioExpanderLoraEnable(); // Power on
54+
delay(100);
55+
}
56+
57+
//----------------------------------------
58+
// Reset the LoRa (STM32) and start the boot loader
59+
//----------------------------------------
60+
bool dfuLoRaReset(DEVICE_FIRMWARE_CTX * ctx, uint32_t currentMsec)
61+
{
62+
// Connect ESP32 UART2 to LoRa UART2 via SW3 for configuration and bootloading/firmware updates
63+
gpioExpanderSelectLoraConfigure();
64+
serialInputClear(SerialForLoRa);
65+
66+
// Pull BOOT0 high to enter bootloader mode on reset
67+
gpioExpanderLoraBootEnable();
68+
69+
// Power cycle the LoRa device to perform the reset and enter
70+
// bootloader mode
71+
dfuLoRaReset();
72+
73+
// Send 0x7F for auto-baud detection
74+
return dfuStm32Autobaud(ctx);
75+
}
76+
77+
#endif // COMPILE_LORA

0 commit comments

Comments
 (0)