Multiprotocol firmware is compiled using the Arduino IDE. The guide below will walk you through all the steps to compile and upload your customized firmware.
**These instructions are for the STM32 version of the Multiprotocol module.** If you are Compling for the Arduino ATmega328p version of the Multiprotocol Module please go to the dedicated [ATmega328](Compiling.md) page.
## Index
1. [Tools Required](#tools-required)
1. [Preparation](#preparation)
1. [Install the Arduino IDE](#install-the-arduino-ide)
1. [Download the Multiprotocol source and open the project](#download-the-multiprotocol-source-and-open-the-project)
1. [Install the Multi 4-in-1 board](#install-the-multi-4-in-1-board)
1. [Configure the Arduino IDE](#configure-the-arduino-ide)
1. [Configure the firmware](#configure-the-firmware)
1. [Verify the firmware](#verify-the-firmware)
1. [Preparing to upload the firmware](#preparing-to-upload-the-firmware)
1. [Connect the programmer](#connect-the-programmer)
1. [Select an upload method](#select-an-upload-method)
The USB-TTL adapter can be either FTDI or CH340G, as long as it works. It should have a switch or jumper to select 3.3V or 5V, which **must** be set to **3.3V**.
The 4-pin header needs to be soldered onto the board as indicated by the red rectangle:
**Note:** The Banggood STM32 module most likely already has the header pin in place.
## Preparation
### Install the Arduino IDE
1. Download and install the Arduino IDE. The currently supported Arduino version is 1.8.5, available for [Windows]( https://www.arduino.cc/download_handler.php?f=/arduino-1.8.5-windows.exe) and [Mac OSX](https://www.arduino.cc/download_handler.php?f=/arduino-1.8.5-macosx.zip)
### Download the Multiprotocol source and open the project
1. Either
1. Download the zip file with the Multiprotocol module source code from [here](https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/archive/master.zip) and unzip and copy the source code folder **Multiprotocol** to a location of your choosing, or
1. Clone the project using Git or Github Desktop, then
1. Double-click the **Multiprotocol.ino** file in the **Multiprotocol** folder to open the project in the Arduino IDE
1. Follow [these instructions](/BootLoaders/README.md) to install the **Multi 4-in-1 STM32 Board** in the Arduino IDE
### Configure the Arduino IDE
1. Under **Tools -> Board** select **Multi 4-in-1 (STM32FC103)**
1. Under **Tools -> Programmer** select **stm32flash (FTDI)**
## Configure the firmware
The STM32 module has more than enough flash space for all the available protocols so, unlike the Atmega328p-based module, it is not necessary to disable unused protocols.
You can still disable protocols if you wish, and you may also enable or disable other optional Multiprotocol features.
## Verify the firmware
To check that the program will compile correctly and fit in the Atmega click **Sketch -> Verify/Compile**, or press **Ctrl+R**.
If there are errors, carefully read it, go to the line number indicated and correct your typo.
If there are no errors and you see output like this:
```
Sketch uses 68564 bytes (52%) of program storage space. Maximum is 131072 bytes.
Global variables use 4064 bytes (19%) of dynamic memory, leaving 16416 bytes for local variables. Maximum is 20480 bytes.
```
You can proceed to the next step.
## Preparing to upload the firmware
If you have already burned the bootloader, and are simply recompiling firmware to re-flash using your TX or USB cable, you can skip this step and go straight to [Flash from TX](#flash-from-tx) or [Upload via USB](#upload-via-usb).
### Select an Upload Method
There are three methods to upload firmware to an STM32 module:
* **Flash from TX** - highly recommended, uses maintenance mode in radios running ersky9x to upload the firmware
* **Upload via USB** - uses the USB port on the module
* **Upload via Serial (FTDI)** - uses the serial interface on the module via a USB-to-TTL adapter
**Note:** 'Flash from TX' is only available with radios running ersky9x r221e2 or newer
**Flash from TX** is highly recommended if your transmitter supports it, **Upload via USB** is recommended for all others. **Upload via Serial** can be used if your module does not have a working USB port and your transmitter does not run ersky9x.
It is **strongly** recommended that you power your module from the transmitter when flashing it. This ensures that the module cannot be inadvertently supplied with 5V, which will damage the RF modules. This guide assumes that you will follow that advice, and instructs you to leave the V+ pin on the USB-to-TTL adapter disconnected. You may choose to ignore that advice at your own risk!
The wiring for the USB-to-TTL adapter is:
* USB-to-TTL TX pin <-> Module RX pin
* USB-to-TTL RX pin <-> Module TX pin
* USB-to-TTL GND pin <-> Module GND pin
* USB-to-TTL VC pin <->**Not Connected**
**It is critical to ensure that the USB-to-TTL adapter is set to 3.3V**.
If you have selected either **Flash from TX** or **Upload via USB** the module will need to install the appropriate bootloader, which is selected automatically based on the Upload Method selection.
The bootloader only needs to be installed once unless you decide to switch from one upload method to the other.
| Bridge pins 1 and 2 as shown by the yellow jumper wire. | Bridge the left-most pins of the 6-pin header as shown by the yellow jumper. | Bridge pins 1 and 2 as shown by the blue jumper. |
Follow the instructions which apply to the **Upload method** you previously selected.
* [Flash from TX](#flash-from-tx)
* [Upload via USB](#upload-via-usb)
* [Upload via Serial](#upload-via-serial)
## Flash from TX
1. Click **Sketch -> Export compiled Binary**, or press **Ctrl+Alt+S**
1. Locate the file named **multifw.bin** in the **Multiprotocol** folder
1. Follow the instructions [here](/docs/Flash_from_Tx.md) to upload the firmware using your radio
## Upload via USB
The **Upload via USB** bootloader enables your PC to detect the Multiprotocol module as a **Maple DFU** device. It will not be detected as a USB serial device until the firmware is uploaded to it, when it will be detected as a **Maple Serial** device.
In order for these devices to be correctly identified in Windows it is necessary to install drivers. This only needs to be done once.
### Install the Maple USB drivers
##### Windows 7 or newer:
1. Open the folder where you unzipped or cloned the Multiprotocol project
1. Browse to **\BootLoaders\Boards\stm32\drivers**
1. Run **install-drivers.bat**
1. Follow the prompts to install the two drivers
##### Windows XP or older
1. Download and install the legacy Windows XP drivers from [here](https://github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/drivers/win/win_xp_legacy)
**NOTE:** If you have installed the drivers and your module is not detected as a Maple device it most likely does not have a USB bootloader installed. Ready-made modules from Banggood **do not** come with a USB bootloader installed. You will need to follow the procedure to [Burn a USB bootloader](#burn-the-bootloader) before you can upload firmware.
1. Connect the USB cable to the Multiprotocol module
1. Verify that a Maple device appears in Device Manager (**Maple DFU** for a module with only a bootloader, **Maple Serial** for a module with a bootloader and firmware)
1. In the Arduino IDE click **Sketch -> Upload**, or press **Ctrl+U**
You should see output similar to this:
```
Sketch uses 68564 bytes (52%) of program storage space. Maximum is 131072 bytes.
Global variables use 4064 bytes (19%) of dynamic memory, leaving 16416 bytes for local variables. Maximum is 20480 bytes.
**Note:** The line `Reset via USB Serial Failed! Did you select the right serial port?` is expected because the uploader initially looks for a Maple Serial device, which isn't yet available, before failing back to Maple DFU. That error only appears the first time and won't appear when re-flashing firmware. The final line warning, stating that the device could not be reset, is also expected.
For subsequent firmware uploads you need only repeat steps 1-3 above, ensuring that you first select the correct COM port, which should be labelled **COMx (Multi 4-in-1 (STM32F103CB))**.
Wrote and verified address 0x0800f534 (100.00%) Done.
Starting execution at address 0x08000000... done.
```
Once the firmware has uploaded, remove the **BOOT0** jumper and disconnect the USB-to-TTL adapter.
## Flashing pre-compiled binaries
Pre-compiled binaries are availale [here](https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/releases).
- **Multiprotocol_V1.X.X_STM32.bin** files are for transmitters with support for hardware telemetry inversion, such as Turnigy 9X, 9XR, 9X+.
- **Multiprotocol_V1.X.X_STM32_INV.bin** files are for tranismitters which require telemetry inverted in the module firmware, such as Taranis.
If you want to flash a pre-compiled binary file (like the Release .bin files) you will use the same USB-to-TTL adapter as [above](#connect-the-programmer).
You will also need to download the **ST Flash Loader Demonstrator** from [here](http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-programmers/flasher-stm32.html)
Run the **ST Flash Loader Demonstrator** program. There are many tutorials on the web on how to use this program, for example [here](http://www.scienceprog.com/flashing-programs-to-stm32-embedded-bootloader).
You can report your problem using the [GitHub issue](https://github.com/midelic/DIY-Multiprotocol-TX-Module/issues) system or go to the [Main thread on RCGROUPS](http://www.rcgroups.com/forums/showthread.php?t=2165676) to ask your question.
Please provide the following information:
- Multiprotocol code version
- STM32 version
- TX type
- Using PPM or Serial, if using er9x or ersky9x the version in use
- Different led status (multimodule and model)
- Explanation of the behavior and reproduction steps