Skip to content

Commit 60c85b0

Browse files
authored
Merge pull request #27 from benlye/0.5.0
Merge 0.5.0 work
2 parents 7207053 + be56d54 commit 60c85b0

34 files changed

+1739
-196
lines changed

doc/New_Bootloader.md

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# New MULTI-Module Bootloader
2+
3+
If you have:
4+
* A radio with an internal MULTI-Module (e.g. T16, T18, TX16S), or
5+
* A Jumper JP4IN1-SE or RadioBoss JP4IN1 MULTI-Module, or
6+
* Any other MULTI-Module which is identified as a CP2102 device when you plug it, or
7+
* Any Atmega32p-based MULTI-Module
8+
9+
You can stop reading now - this does not matter to you.
10+
11+
**If you have a Jumper JP4IN1, iRangeX IRX4, Banggood, or any other STM32 MULTI-Module, please read this information - if you use the USB port on your module, you will need to take action!**
12+
13+
If you want to cut to the chase, skip to the [what you need to do](#what-you-need-to-do) section.
14+
15+
## Introduction
16+
The latest version of Flash Multi, v0.5.0, gives you the ability to flash a new bootloader to your MULTI-Module.
17+
18+
The new bootloader changes the behaviour of the USB port on your MULTI-module when you plug the module into a computer.
19+
20+
| Action | Old Bootloader (COM Port Mode) | New Bootloader (Sticky DFU Mode) |
21+
| --- | --- | --- |
22+
| Connect the module to the computer, radio is off | Module starts in DFU mode then switches to COM port mode | Module starts in DFU mode and stays in DFU mode |
23+
| Connect the module to the computer, radio is on | Computer will detect a USB COM port | Computer will detect an unidentified device |
24+
25+
## Reason for Change
26+
Historically, the MULTI-Module firmware has always included code to make the USB COM port work when the module is running. However, the USB COM port is only used in two ways:
27+
* Switching the module to firmware update (DFU) mode when it is being flashed by using Flash Multi or the Arduino IDE
28+
* Debug output when running a debug-enabled build (typically only used by developers)
29+
30+
And, there is never need for an internal MULTI-Module to have the USB COM port code, but it was always included. When this decision was made the firmware was around 80KB, and we had plenty of free space in the 128KB available flash on the STM32 MCU.
31+
32+
Fast-forward three years and we have all but run out of space in the STM32. In an effort to free some space up, we are removing USB support from the firmware. **This change saves 5KB of flash.** This may not seem like much, but it's room for several more protocols.
33+
34+
**Firmware without USB support will start to be released later in 2020.**
35+
36+
Because we're removing the mechanism that would allow flashing tools to put the module into DFU mode, we have to provide a different way to do that.
37+
38+
This is where the new bootloader comes in - it keeps the module in DFU mode when it is plugged in via USB, removing the need to use the COM port to switch it into DFU mode.
39+
40+
## What you need to do
41+
**You will need to use Flash Multi to upgrade the bootloader on your MULTI-Module _before_ you flash firmware which does not have USB support.**
42+
43+
### Upgrading to the new bootloader
44+
There is a one-time process to update the bootloader on the module. After the bootloader upgrade you will need to flash new firmware to your module.
45+
46+
1. Launch Flash Multi
47+
1. Tell Flash Multi to use the new bootloader:
48+
1. Click **Advanced** -> **Settings** -> **USB Port Mode** -> **Sticky DFU Mode (New)**
49+
1. Plug your module in
50+
1. Ensure that the correct COM port is selected
51+
1. Flash the new bootloader to your module:
52+
1. Click **Advanced** -> **Actions** -> **Flash Module Bootloader**
53+
1. Wait for the red LED to go out
54+
1. Unplug the module
55+
56+
**You must pay attention to the instructions. DO NOT unplug the module until the red LED has gone out for at least two seconds.**
57+
58+
You will now need to write new MULTI-Module firmware to the module in the normal way:
59+
1. Check that the COM port is set to **DFU Device**
60+
1. Select the firmware file
61+
1. Click **Write Module**
62+
63+
You will get a warning reminding you that you needed to update the bootloader, you may check the box to stop the message showing again.
64+
65+
Once you have written new firmware to your module, if you unplug it and plug it back in, the module should stay in DFU mode with the red LED blinking continuously.
66+
67+
## Frequently Asked Questions
68+
## When should I update the bootloader?
69+
You can do it any time after the release of Flash Multi v0.5.0. The new bootloader works with all previous MULTI-Module firmware releases.
70+
71+
### If I only ever flash my MULTI-Module from the radio do I have to do the bootloader update?
72+
No, you don't have to do it. You can also wait and do it later if you want to.
73+
74+
### How do I know which bootloader my MULTI-Module has?
75+
Plug it in via USB
76+
* If the red LED blinks rapidly then starts to blink slowly and the green LED comes on you have the old bootloader
77+
* If the red LED blinks rapidly continuously you have the new bootloader
78+
* If the green LED comes on and the red LED stays off you have a module which does not use the bootloader for the USB port
79+
80+
### I flashed new firmware without USB support from the radio and now my USB port doesn't work, how do I fix it?
81+
You have the old bootloader. Use Flash Multi to flash the module bootloader, as explained above. You will have to unplug and replug the module when instructed.
82+
83+
### I have to unplug and re-plug my module every time I flash it, how do I fix it?
84+
You have the old bootloader. Use Flash Multi to flash the module bootloader, as explained above. You will have to unplug and replug the module when instructed.
85+
86+
### Why doesn't this apply to JP4IN1-SE or Radioboss modules?
87+
They use a different USB interface which does not use DFU mode to flash firmware. They will work happily with the old or new bootloaders and do not require updating this way.
88+
89+
### Why doesn't this apply to radios with internal modules?
90+
Because internal modules don't have USB ports they do not require any update to work properly with the new firmware which does not have USB support.
File renamed without changes.
8 KB
Binary file not shown.

linux/flash-multi

+51-21
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ shopt -s extglob
1919
# *********************************************************************
2020

2121
# Define the script version
22-
VERSION=0.4.3
22+
VERSION=0.5.0
2323

2424
# Write the script header
2525
printf "flash-multi $VERSION\n\nThis program is Free Software and has NO WARRANTY.\nhttps://github.com/benlye/flash-multi/\n\n";
2626

2727
# Prepare simple help text to display when needed
28-
USAGE="Usage: flash-multi [options] -f [firmware file] -p [serial device]\n\nOptions:\n -h Print this message and exit\n -r Read and display the firmware file information and exit\n -s Don't prompt for confirmation\n\n"
28+
USAGE="Usage: flash-multi [options] -f [firmware file] -p [serial device]\n\nOptions:\n -h Print this message and exit\n -l Install legacy bootloader\n -r Read and display the firmware file information and exit\n -s Don't prompt for confirmation\n -b Baud rate (57600, 115200, 500000)\n\n"
2929

3030
# Get the command line options
31-
while getopts ":f:p:hrs" opt; do
31+
while getopts ":f:p:b:hrsl" opt; do
3232
case $opt in
3333
f) FWFILE="$OPTARG"
3434
;;
@@ -38,8 +38,12 @@ while getopts ":f:p:hrs" opt; do
3838
;;
3939
r) SHOWINFO="True"
4040
;;
41+
l) LEGACY="True"
42+
;;
4143
s) SILENT="True"
4244
;;
45+
b) BAUDRATE="$OPTARG"
46+
;;
4347
\?) printf "Invalid argument -$OPTARG\n\n"; >&2
4448
;;
4549
:) printf "Missing value for argument -$OPTARG\n\n"; >&2
@@ -65,6 +69,17 @@ if [ ! -r "$FWFILE" ]; then
6569
exit 2;
6670
fi
6771

72+
# Die if the baud rate isn't valid
73+
if [ "x" != "x$BAUDRATE" ] && [ $BAUDRATE != "57600" ] && [ $BAUDRATE != "115200" ] && [ $BAUDRATE != "500000" ] ; then
74+
printf "ERROR: $BAUDRATE is not a valid baud rate!\n\n";
75+
exit 2;
76+
fi
77+
78+
# Set the baud rate for stm32flash
79+
if [ "x" == "x$BAUDRATE" ]; then
80+
BAUDRATE=115200
81+
fi
82+
6883
function confirm() {
6984
while true; do
7085
read -p "$1 [Y]es or [N]o: "
@@ -261,13 +276,21 @@ function get_signature()
261276
return;
262277
fi
263278

279+
# Determine if the specified firmware file contains support for the STM32 USB port
280+
if grep -q $GREP_ARGS 'M\x00a\x00p\x00l\x00e\x00\x12\x03L\x00e\x00a\x00f\x00L\x00a\x00b\x00s' "$FWFILE"; then
281+
FW_USBSERIAL_SUPPORT="True"
282+
else
283+
FW_USBSERIAL_SUPPORT="False"
284+
fi
285+
264286
# Show the firmware information
265287
printf "Multi Firmware Version: $SIG_VERSION_STRING ($SIG_BOARD_TYPE_NAME)\n";
266288
printf "Expected Channel Order: $FW_CHANNEL_ORDER\n";
267289
printf "Multi Telemetry Type: $FW_TELEMETRY_TYPE\n";
268290
printf "Invert Telemetry Enabled: $FW_INVERT_TELEMETRY_ENABLED\n";
269291
printf "Flash From Radio Enabled: $FW_CHECK_FOR_BOOTLOADER_ENABLED\n";
270292
printf "Bootloader Enabled: $FW_BOOTLOADER_SUPPORT\n";
293+
printf "USB Serial Support: $FW_USBSERIAL_SUPPORT\n";
271294
printf "Serial Debug Enabled: $FW_DEBUG_SERIAL_ENABLED\n\n";
272295
}
273296

@@ -385,19 +408,20 @@ if [[ $SIG_BOARD_TYPE_NAME == "AVR" ]]; then
385408
exit 0
386409
fi
387410

388-
389411
# STM32 Module Flashing
390412
# Set the path to the bootloader file
391-
BOOTLOADERFILE="$DIR/bootloader/StmMulti4in1.bin"
413+
if [[ $LEGACY == "True" ]]; then
414+
BOOTLOADERFILE="$DIR/bootloader/StmMulti4in1_Legacy.bin"
415+
else
416+
BOOTLOADERFILE="$DIR/bootloader/StmMulti4in1_StickyDfu.bin"
417+
fi
392418

393-
# Determine if the specified firmware file contains support for the STM32 USB port
394-
if grep -q $GREP_ARGS 'M\x00a\x00p\x00l\x00e\x00\x12\x03L\x00e\x00a\x00f\x00L\x00a\x00b\x00s' "$FWFILE"; then
395-
HAS_USB_SUPPORT=true;
419+
# Set the parameters according to bootloader support
420+
if [ $FW_BOOTLOADER_SUPPORT == "True" ]; then
396421
MAX_FILE_SIZE=120832
397422
FLASH_START=8
398423
EXEC_ADDR=0x8002000
399424
else
400-
HAS_USB_SUPPORT=false;
401425
MAX_FILE_SIZE=129024
402426
FLASH_START=0
403427
EXEC_ADDR=0x8000000
@@ -421,25 +445,25 @@ then
421445
fi
422446

423447
STEP=1
424-
[ "$HAS_USB_SUPPORT" == true ] && NUM_STEPS=3 || NUM_STEPS=2;
448+
[ $FW_BOOTLOADER_SUPPORT == "True" ] && NUM_STEPS=3 || NUM_STEPS=2;
425449

426450
printf "[$STEP/$NUM_STEPS] Erasing flash...\n"
427-
printf "$STM32_FLASH -o -S 0x8000000:129024 -b 115200 \"$PORT\"\n"
428-
"${STM32_FLASH}" -o -S 0x8000000:129024 -b 115200 "$PORT"
451+
printf "$STM32_FLASH -o -S 0x8000000:129024 -b $BAUDRATE \"$PORT\"\n"
452+
"${STM32_FLASH}" -o -S 0x8000000:129024 -b $BAUDRATE "$PORT"
429453
[ $? -ne 0 ] && printf "ERROR: Failed to erase flash!\n\n" && exit 3;
430454
STEP=$((STEP+1))
431455

432-
if [ "$HAS_USB_SUPPORT" == true ] ; then
456+
if [ $FW_BOOTLOADER_SUPPORT == "True" ] ; then
433457
printf "[$STEP/$NUM_STEPS] Writing bootloader...\n"
434-
printf "$STM32_FLASH -v -e 0 -g 0x8000000 -b 115200 -w \"$BOOTLOADERFILE\" \"$PORT\"\n"
435-
"${STM32_FLASH}" -v -e 0 -g 0x8000000 -b 115200 -w "$BOOTLOADERFILE" "$PORT"
458+
printf "$STM32_FLASH -v -e 0 -g 0x8000000 -b $BAUDRATE -w \"$BOOTLOADERFILE\" \"$PORT\"\n"
459+
"${STM32_FLASH}" -v -e 0 -g 0x8000000 -b $BAUDRATE -w "$BOOTLOADERFILE" "$PORT"
436460
[ $? -ne 0 ] && printf "ERROR: Failed to write bootloader!\n\n" && exit 3;
437461
STEP=$((STEP+1))
438462
fi
439463

440464
printf "[$STEP/$NUM_STEPS] Writing firmware...\n"
441-
printf "$STM32_FLASH -v -s $FLASH_START -e 0 -g $EXEC_ADDR -b 115200 -w \"$FWFILE\" \"$PORT\"\n"
442-
"${STM32_FLASH}" -v -s $FLASH_START -e 0 -g $EXEC_ADDR -b 115200 -w "$FWFILE" "$PORT"
465+
printf "$STM32_FLASH -v -s $FLASH_START -e 0 -g $EXEC_ADDR -b $BAUDRATE -w \"$FWFILE\" \"$PORT\"\n"
466+
"${STM32_FLASH}" -v -s $FLASH_START -e 0 -g $EXEC_ADDR -b $BAUDRATE -w "$FWFILE" "$PORT"
443467
[ $? -ne 0 ] && printf "ERROR: Failed to write firmware!\n\n" && exit 3;
444468

445469
else
@@ -454,10 +478,16 @@ else
454478
printf "ERROR: Required tool $DFU_UTIL does not exist or is not executable!\n\n"; exit 3;
455479
fi
456480

457-
# Die if the firmware file doesn't contain USB code
458-
if [ "$HAS_USB_SUPPORT" == false ]; then
459-
printf "ERROR: Specified firmware file was not compiled with USB support.\nFlashing this file would make the MULTI-Module unusable.\n\n";
460-
exit 9;
481+
# Warn if the firmware file doesn't contain USB code
482+
if [ $FW_USBSERIAL_SUPPORT == "False" ]; then
483+
printf "WARNING: Specified firmware file was not compiled with USB support.\n";
484+
printf " You MUST update the MULTI-module bootloader to the latest version BEFORE writing this firmware.\n\n";
485+
printf " See https://github.com/benlye/flash-multi/blob/master/doc/New_Bootloader.md for more information.\n\n";
486+
487+
if [[ "no" == $(confirm "Proceed with firmware update?") ]]; then
488+
printf "\nFirmware update aborted.\n\n"
489+
exit 9;
490+
fi
461491
fi
462492

463493
STEP=1;

linux/multi-bootreloader

+11-5
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,23 @@ shopt -s extglob
1919
# *********************************************************************
2020

2121
# Define the script version
22-
VERSION=0.1.0
22+
VERSION=0.2.0
2323

2424
# Write the script header
2525
printf "multi-bootreloader $VERSION\n\nThis program is Free Software and has NO WARRANTY.\nhttps://github.com/benlye/flash-multi/\n\n";
2626

2727
# Prepare simple help text to display when needed
28-
USAGE="Usage: multi-bootreloader [options] -p [serial device]\n\nOptions:\n -h Print this message and exit\n -s Don't prompt for confirmation\n\n"
28+
USAGE="Usage: multi-bootreloader [options] -p [serial device]\n\nOptions:\n -h Print this message and exit\n -l Install legacy bootloader\n\n"
2929

3030
# Get the command line options
31-
while getopts ":f:p:h" opt; do
31+
while getopts ":f:p:hl" opt; do
3232
case $opt in
3333
f) FWFILE="$OPTARG"
3434
;;
3535
p) PORT="$OPTARG"
3636
;;
37+
l) LEGACY="True"
38+
;;
3739
h) printf "$USAGE"; exit 1
3840
;;
3941
\?) printf "Invalid argument -$OPTARG\n\n"; >&2
@@ -43,8 +45,12 @@ while getopts ":f:p:h" opt; do
4345
esac
4446
done
4547

46-
# FWFILE is BootReloader.bin
47-
FWFILE=./tools/BootReloader.bin
48+
# Pick the bootreloader file
49+
if [[ $LEGACY == "True" ]]; then
50+
FWFILE=./tools/BootReloader_Legacy.bin
51+
else
52+
FWFILE=./tools/BootReloader_StickyDfu.bin
53+
fi
4854

4955
# Die if the firmware file doesn't exist
5056
if [ ! -f "$FWFILE" ]; then
File renamed without changes.
20.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)