User Tools

Site Tools


Firmware updates using the Modbus RTU communication interface

Bootloader configuration

In order to perform firmware updates with the OpenBLT through the Modbus RTU communication interface, double-check that this communication interface is configured in “blt_conf.h”, by adding the following configuration macros and fine-tune them to your desired values. Refer to the comments for details:

/** \brief Enable/disable RS485 transport layer. */
#define BOOT_COM_MBRTU_ENABLE            (1)
/** \brief Configure the desired communication speed. */
#define BOOT_COM_MBRTU_BAUDRATE          (57600)
/** \brief Configure the desired number of stopbits (1 or 2). */
#define BOOT_COM_MBRTU_STOPBITS          (1)
/** \brief Configure the desired parity (0 for none, 1 for odd, 2 for even). */
#define BOOT_COM_MBRTU_PARITY            (2)
/** \brief Configure number of bytes in the target->host data packet. */
#define BOOT_COM_MBRTU_TX_MAX_DATA       (129)
/** \brief Configure number of bytes in the host->target data packet. */
#define BOOT_COM_MBRTU_RX_MAX_DATA       (129)
/** \brief Select the desired UART peripheral as a zero based index. */
/** \brief The 8-bit node identifier of this node. Should be between 1 and 247. */
#define BOOT_COM_MBRTU_NODE_ID           (1)

After making configuration changes, rebuild the bootloader.

Using MicroBoot

The MicroBoot utility needs to be configured to connect to the correct COM-port and to communication at the correct baudrate:

  • Start MicroBoot by double-clicking “\Host\MicroBoot.exe” (on Linux it is “\Host\MicroBoot”).
  • Click the “Settings”-button and select “XCP on Modbus RTU” from the “Interface selection” dropdown box.
  • Select the PC's communication device that the board is connected to and configure the communication settings and destination node ID to match the settings you made in “blt_conf.h” of the bootloader.

Once you saved the settings by clicking the “OK”-button, MicroBoot is now ready for action!

After building your user program, its S-record formatted firmware file can be downloaded to the remaining flash memory using the bootloader. In MicroBoot click the “Browse”-button and select your user program's firmware file. For the demo programs, this one is typically located in the “.\Prog\bin\” or “.\Prog\Debug\” directory. Once the firmware file was selected, the download should automatically start.

Once the download completed, the newly programmed software will be started by the bootloader. For the demo program's you can verify this by checking that the LED blinks. Congratulations! That's all there is to using the bootloader.

Using BootCommander

The BootCommander command line interface (CLI) program allows you to configure all communication settings via options on the command line:

XCP on Modbus RTU settings (xcp_mbrtu):
  -d=[name]        Name of the communication device. For example COM1 or
                   /dev/ttyUSB0 (Mandatory).
  -b=[value]       The communication speed, a.k.a baudrate in bits per
                   second, as a 32-bit value (Default = 57600).
                   Supported values: 9600, 19200, 38400, 57600, 115200.
  -pa=[value]      The UART parity bit configuration as a 8-bit value.
                   (Default = 2).
                   Supported values: 0 (none), 1 (odd), 2 (even).
  -sb=[value]      The number of UART stopbits as a 8-bit value.
                   (Default = 1).
                   Supported values: 1, 2.
  -da=[value]      Destination address, i.e. the node ID of the receiver,
                   as a 8-bit value (Default = 1).
                   Supported values: between 1 and 247.

The following example demonstrates how to call BootCommander for making a firmware update with one of the demo programs. Just correct the “-d” option to select the PC’s communication device that the board is connected to. On Linux, change COMx to the full path of the communication device, for example /dev/ttyUSB0.

BootCommander -s=xcp -t=xcp_mbrtu -d=COM5 -b=57600 -pa=2 -sb=1 -da=1 demoprog_stm32f446.srec

The example assumes that the S-record of the demo user program is located in the same directory as where the BootCommander executable itself resides. If not, then simply prepend the absolute (or relative) directory to the name of the S-record firmware file.

RS485 transceiver management

You can use RS232 or RS485 as the physical communication link for firmware updates via Modbus RTU. In the case of RS485, your system will feature an RS485 transceiver. Most RS485 transceivers require you to explicitly enable and disable the transmitter/receiver using a microcontroller digital output.

You can implement this logic in hook-function MbRtuDriverOutputControlHook() in “hooks.c”. You can copy-paste this template function as a starting point:

** \brief     Controls the state of the DE/NRE GPIO pin on an RS485 transceiver.
** \param     enable When enable is BLT_TRUE, the pin should go logic high to enable the
**            driver output. When enable is BLT_FALSE, the pin should go logic low to
**            enable the receiver input.
** \return    none.
void MbRtuDriverOutputControlHook(blt_bool enable)
  /* Should the driver output be enabled (transmit)? */
  if (enable == BLT_TRUE)
    /* TODO If needed, set DE and NRE pins to high to enable the driver output. */
  /* The receiver output should be enabled (receive). */
    /* TODO If needed, set DE and NRE pins to low to enable the receiver input. */
} /*** end of MbRtuDriverOutputControlHook ***/

Note that when using RS232 as the communication link, you still need to implement this function to prevent a linker error. Yet, you can use the empty template as specified above.


Depending on the configuration of the bootloader, there might be a delay between a system reset and the actual start of the user program. This is needed by design for the bootloader's backdoor functionality. Check configurable BOOT_BACKDOOR_ENTRY_TIMEOUT_MS in “blt_conf.h” for the exact delay time.

To prevent having to run MicroBoot/BootCommander with super user privileges under Linux, add yourself to the dialout group. Example for Debian/Ubuntu distributions:

sudo usermod -G dialout -a $USER
manual/modbus_rtu_demo.txt · Last modified: 2023/12/04 22:07 by voorburg