WB Modbus Devices Firmware Update/en: различия между версиями

Материал из Wiren Board
(Новая страница: «== Utility for WB-mcu-fw-flasher firmware ==»)
(не показано 67 промежуточных версий 3 участников)
Строка 1: Строка 1:
<languages/>
<languages/>
== General Information ==
Wiren Board modbus devices have a [[Bootloader |bootloader]], which allows updating firmware via RS-485/Modbus RTU. In bootloader mode, the main functions of the device are disabled, and the communication parameters in bootloader mode are fixed and do not depend on the values in the device memory: 9600 8N2.


The firmware itself is released in the format of releases, which are linked to [[Wiren_Board_Software#releases|controller software releases]], but have a different cycle:
{{DISPLAYTITLE:Загрузка прошивок на устройства Wiren Board}}
*'''testing''' — firmware that has passed internal testing lands here, available to users of the controller's testing release;
*'''stable''' — three weeks after being published in testing and with no error reports, the firmware is considered stable. At this point, it becomes available to users of the stable release of the controller. If there were major changes in the firmware that affected the device's core functions, the firmware may be slightly delayed in testing.


On the page of each device there is a link to the list of firmware changes, where firmware in testing is marked with the "testing" marker. Firmware without a mark is considered stable.
== Firmware bootloader ==


Distributing firmware updates by releases helps prevent a situation where a new firmware version, without undergoing thorough testing, ends up in a very critical installation. If the new firmware requires new features in the controller's software, either these features will be included in the stable software release along with the firmware, or the firmware update will be delayed in testing until the required features appear in the software.
The new versions of our devices have a firmware bootloader. It allows you to update the firmware of our devices/Wiren Board modules via RS-485/Modbus RTU. The bootloader mode, in which it is possible to update the firmware, has been added to the devices.  


To update devices connected via a WB-MGE gateway or a similar device, use the socat redirection, [[WB FAQ/modbus-modules-behind-gateway | instructions]].
In the bootloader mode, the main functionality of the device is disabled. '''Communication parameters in the bootloader mode are fixed and do not depend on the values in the device memory: 9600 8N2.'''


== Automatic firmware update ==
[[Image:Wb-fw-mcu-updater example 1.png|500px|thumb|right|Example of wb-fw-mcu-updater operation]]
{{note|info|When updating the firmware, IR commands stored in WB-MSW and WB-MIR devices are deleted. We recommend saving command banks before updating using the [[WB-MSx Consumer IR Manual#Reading/Writing Command Banks|script]].}}
Automatic firmware update is performed using the utility [[Wb-mcu-fw-updater|wb-mcu-fw-updater]] preinstalled on Wiren Board controllers, allowing you to install the latest version of the software on all connected devices at once or separately on each one. The device model and new firmware will be automatically identified.


The utility only works on our controller and requires internet access. If you do not have internet or our controller, refer to the section [[#manual|Manual Update]].
== Entering bootloader mode ==


Updating firmware on devices connected to WB-MGE and WM-MIO-E gateways is also performed [[WB_Modbus_Devices_Firmware_Update#Обновление_прошивки_устройств,_подключенных_к_шлюзам_WB-MGE_и_WM-MIO-E |manually with displaying the network port to local]].
[[Special:MyLanguage/Файл:Bootloader.gif||right||Bootloader mode indication]]
The device enters bootloader mode if:
* the device has the correct firmware — the first 2 seconds after power on, the device operates in bootloader mode;
* the device does not have the correct firmware (for example, there was a failure when updating the firmware) — in this case, the bootloader mode is constantly active;
* when the main program in the holding-register 129 (0x81) was recorded 1 — in this case, the device is rebooted and remains in bootloader mode for 120 seconds.


=== Updating all devices on the bus ===
Bootloader mode indication: the device Status indicator rarely flashes. When you download a new firmware, indicator stops changing state.
You can update all devices configured in the '''Serial Devices Configuration''' section of the [[Wiren Board Web Interface|web interface]]
# Connect the devices via the [[RS-485|RS-485 bus]] to the controller.
# [[RS-485:Configuration via Web Interface|Configure the connected devices]] in the web interface.
# Open the controller's console via [[SSH]].
# Update all configured devices with the following command:
#:<syntaxhighlight lang="bash">
wb-mcu-fw-updater update-all
</syntaxhighlight>


=== Updating a Single Device ===
To update only one device:
# Connect the device via RS-485 to the controller.
# Determine the [[Wiren Board Device Modbus Address | Modbus address]] of the device you want to update.
# Open the controller console via [[SSH]].
# Run the utility <code>wb-mcu-fw-updater</code> with the following parameters: the <code>update-fw</code> key, as well as the port and Modbus address.


For example, let's update the firmware of a device with a modbus address of <code>70</code> connected to port <code>/dev/ttyRS485-1</code>:
== Firmware ==
<syntaxhighlight lang="bash">
wb-mcu-fw-updater update-fw /dev/ttyRS485-1 -a70
</syntaxhighlight>


For the full list of parameters and examples of usage, refer to the [[Wb-mcu-fw-updater | utility page]].
Writing firmware in the memory device is performed by a loader that gets its Modbus RTU. Firmware is stored in files with extension '''.wbfw'''. Currently available firmwares are available on request.


== Manual Update ==
{{Anchor|manual}}
=== Features ===
This method is used if:
* there is no internet access at the object,
* you do not have a controller,
* you are updating the firmware of devices, [[WB_Modbus_Devices_Firmware_Update#Firmware_Update_for_Devices_Connected_to_WB-MGE_and_WB-MIO-E_Gateways|connected through WB-MGE and WB-MIO-E gateways]].


In all other cases, use the [[WB_Modbus_Devices_Firmware_Update#Automatic_Update |automatic update]].
== Device signatures ==


Manual update can be done with the utility '''[[wb-mcu-fw-flasher#Installing the Utility|wb-mcu-fw-flasher]]''', which needs to be installed beforehand. The installation method varies and depends on the operating system being used.


=== Device preparation ===
When flashing at the factory, the signature — the name of the hardware type of the device — is recorded into the memory of the device. When overwriting the firmware, the current signature is compared with the firmware signature. Writing new firmware is possible only if the signatures match.


Devices can be flashed in the following ways:
* by the device's Modbus address.
* by the broadcast address, which is <code>0</code>.


To flash multiple devices on the bus, you need to sequentially switch them to the [[Bootloader MOD|bootloader mode]] and flash them.
== Modbus ==


=== Firmware upload to the device ===
To upload the firmware, follow these steps:
# Connect the device via [[RS-485 | RS-485 bus]] to the controller or other equipment where the firmware utility is installed.
{{Wbincludes:Prepare modbus_client}}
# Download the firmware file for your device from the repository following the [[Firmware Repository For Wiren Board Modbus Devices | instructions]].
# Upload the firmware file to the [[View controller files from your computer | controller]] or other device.
# Go to the folder with the firmware file and execute the command:
#:* on the controller or a Linux computer:
#:<syntaxhighlight lang="bash">
wb-mcu-fw-flasher -j -d /dev/ttyRS485-1 -a25 -f ./firmware.wbfw
</syntaxhighlight>
#:* on a Windows computer:
#:<syntaxhighlight lang="bash">
wb-mcu-fw-flasher_1.0.3.exe -j -d COM1 -a25 -f firmware.wbfw
</syntaxhighlight>
# If you executed the command from the controller, start the wb-mqtt-serial driver.


In the above command, using the <code>-j</code> flag, we switched the device connected to the port <code>/dev/ttyRS485-1</code> (<code>COM1</code>) with address <code>25</code> to bootloader mode and then flashed it.
The device loader receives firmware via Modbus RTU. In the bootloader mode, the communication parameters are fixed and do not depend on the previous values in the device memory: 9600 8N2. According to the Modbus protocol, the device can be set to bootloader mode, if 1 is written to the holding register 129 (0x81) during the operation of the main program. In this scenario, the device restarts and remains in bootloader mode for 120 seconds.


A successful firmware update process looks like this:
The Modbus address of the bootloader firmware device should be selected as follows:
<syntaxhighlight lang="bash">
~# wb-mcu-fw-flasher -j -d /dev/ttyRS485-1 -a 25 -f mr6c__1.15.5_master_971fe50.wbfw 
  /dev/ttyRS485-1 opened successfully.
  Send jump to bootloader command and wait 2 seconds...
  Ok, device will jump to bootloader.
  mr6c__1.15.5_master_971fe50.wbfw opened successfully, size 14720 bytes


  <div lang="ru" dir="ltr" class="mw-content-ltr">
# The main address for the firmware is the address specified in the device memory: that is, it is the standard address to which the device responds from the main program.
Sending info block... OK
# To flash a device using a broadcast address of 0. This is a less preferred method.
</div>


  <div lang="ru" dir="ltr" class="mw-content-ltr">
Sending data block 108 of 108... OK.
  All done!
</syntaxhighlight>
</div>


If the device signature and firmware file do not match, you will receive an error message:
== Utility for WB-mcu-fw-flasher firmware ==
<syntaxhighlight lang="bash">
Sending info block...
  Error while sending info block: Slave device or server failure
  Data format is invalid or firmware signature doesn't match the device
</syntaxhighlight>


== Restoring the device firmware ==
Для передачи прошивки на устройства используется утилита wb-mcu-fw-flasher, запускаемая с контроллера Wiren Board (или компьютера с Linux или Windows).  
{{Anchor|fw-recovery}}
If an error occurred during the update, the device will enter the [[Wbincludes:Bootloader MOD | bootloader mode]] and you can restore its firmware.


=== Automatically ===
Для установки утилиты '''на контроллер Wiren Board''' выполните команды:
To automatically restore the firmware of one or multiple devices, you can use the utility wb-mcu-fw-updater in the modes '''recover''' and '''recover-all'''.
<pre>
apt-get update
apt-get install wb-mcu-fw-flasher
</pre>


To recover the device with address <code>10</code> and connected to port <code>/dev/ttyRS485-1</code>, execute the command:
Версию утилиты для '''MS Windows''' можно скачать по этой ссылке: [[Special:MyLanguage/Media: Wb-mcu-fw-flasher_1.0.2.zip | Wb-mcu-fw-flasher_1.0.2.zip]]
<syntaxhighlight lang="bash">
wb-mcu-fw-updater recover /dev/ttyRS485-1 -a 10
</syntaxhighlight>


For more information on the recover and recover-all modes, read the documentation in [[Wb-mcu-fw-updater#Modes|the documentation]].
Для установки на '''компьютер с Debian''' скачайте пакет отсюда: [[Special:MyLanguage/Media: Wb-mcu-fw-flasher_1.0.2_amd64-all.deb | Wb-mcu-fw-flasher_1.0.2_amd64-all.deb]]
и выполните команды в директории, гуда загрузился пакет пакет.
<pre>
apt-get update
apt-get install libmodbus5
dpkg -i Wb-mcu-fw-flasher_1.0.2_amd64-all.deb


=== Manually ===
</pre>
If you cannot use [[wb-mcu-fw-updater]], you can restore the firmware of devices using the service utility [[wb-mcu-fw-flasher]]. This method can also be used by Windows computer users.


To do this, you will need the utility itself and the firmware file:
# Connect the device via the [[RS-485 | RS-485 bus]] to the controller or other equipment where the firmware utility is installed.
{{Wbincludes:Prepare modbus_client}}
# [[Firmware Repository For Wiren Board Modbus Devices | Download]] the firmware file for your device from the repository.
# Upload the firmware file to the [[View controller files from your computer | controller]] or other device with the firmware utility installed.
# Go to the folder with firmware and execute the command:
#* on a Linux-based controller or computer:
#:<syntaxhighlight lang="bash">
wb-mcu-fw-flasher -d /dev/ttyRS485-1 -a 25 -f ./firmware.wbfw
</syntaxhighlight>
#* on a Windows-based computer:
#:<syntaxhighlight lang="bash">
wb-mcu-fw-flasher_1.0.3.exe -d COM1 -a 25 -f firmware.wbfw
</syntaxhighlight>


Here we flashed the device in bootloader mode with Modbus address <code>25</code> connected to port <code>/dev/ttyRS485-1</code> (<code>COM1</code>) using the file <code>firmware.wbfw</code>.
Опции запуска утилиты wb-mcu-fw-flasher:
{| class="wikitable"
! Параметр !! Описание !! Значение по умолчанию
|-
| -d || Устройство последовательного порта ||
|-
| -f || Файл прошивки ||
|-
| -a || Адрес Modbus || 1
|-
| -j || Отправить на устройство команду перехода в режим загрузчика ||
|-
| -r || Адрес holding-регистра для перехода в режим загрузчика || 129
|-
| -D || Включить режим отладки ||
|}


==Updating firmware of devices connected to WB-MGE and WB-MIO-E gateways==
Пример:
[[Image:superport-config.png|350px|thumb|right|Gateway settings for firmware update]]
<pre>
To update the firmware of a Wiren Board device connected to the [[WB-MGE_v.2_Modbus-Ethernet_Interface_Converter|WB-MGE]] and [[WB-MIO-E_v.2_Modbus_Interface_Converter|WB-MIO-E]] gateways via RS-485, it can only be done manually using the [[Wb-mcu-fw-flasher|wb-mcu-fw-flasher]] utility. However, first, you need to convert the network port to a local one using the [[Socat|socat]] utility.
wb-mcu-fw-flasher -j -d /dev/ttyRS485-1 -a 25 -f WB-MR-MR6C_MCU3_3_1.9.4.wbfw
</pre>


The gateway must be set to TCP Server/None mode (for WB-MGE v2, WB-MIO-E v2) or TCP Server mode (for WB-MGE v1, WB-MIO-E v1).
Пример для Windows:
<pre>
wb-mcu-fw-flasher.exe -j -d COM10 -a 25 -f WB-MR-MR6C_MCU3_3_1.9.4.wbfw
</pre>


===Update at any connection speed===
Здесь COM10 — имя виртуального последовательного порта, которое присвоено адаптеру USB RS-485.


Connection settings can be any, !if! only:


*Version of wb-mcu-fw-flasher is not less than '''1.3.0''' (available in [[testing|testing]]),
== Прошивка устройств ==
*The current firmware version of the device supports '''131''' registers (see Change logs on device pages),
*The current bootloader version is not lower than '''1.3.0'''.


'''Otherwise, the update can only be performed with standard 9600N2 connection settings.'''
'''При прошивке с контроллера остановите wb-mqtt-serial:'''
<pre>
service wb-mqtt-serial stop
</pre>


Below is an example with the following input data:
Подключите устройство к RS-485.


*Gateway WB-MGE (WB-MIO-E), configured for Modbus over TCP and having IP address 192.168.0.7, port 23.
Если вы не знаете точного аппаратного типа устройства, то его сигнатуру можно прочесть командой:
*Modbus device Wiren Board with address 14.
<pre>
*Connection speed is 115200 kbit/s.
export mbusaddr=1;  echo  -e `modbus_client --debug -mrtu -pnone -s2 /dev/ttyRS485-1 -a$mbusaddr -t0x03 -r290 -c 12 | grep Data | sed -e 's/0x00/\x/g' -e 's/Data://' -e 's/s//g'`|  xxd -r -p && echo ''
</pre>   
Задайте адрес прошиваемого устройства в переменной mbusaddr.


{{note|info|'''Attention!''' In your case, the settings may be different.}}
В выводе команды вы получите сигнатуру устройства, например, '''wbmr6c'''.


#Prepare the firmware file and install the socat utility if it is not installed:
Выберите подходящую прошивку, например, WB-MR-MR6C_MCU3_3_1.9.4.wbfw.
#:<syntaxhighlight lang="bash">
apt install socat
</syntaxhighlight>
#Connect twice to the controller via SSH, you should have two windows open: the first one for creating a socat tunnel, the second one for sending commands to the device.
#Stop wb-mqtt-serial:
#:<syntaxhighlight lang="bash">
systemctl stop wb-mqtt-serial
</syntaxhighlight>
#In the first window, start redirecting with socat using the current connection settings:
#:<syntaxhighlight lang="bash">
socat -d -d -d -x PTY,raw,b115200,parenb=0,cstopb=2,cs8,link=/dev/ttyRS485-5 tcp:192.168.0.7:23
</syntaxhighlight>
#In the second window, start the device firmware update with the wb-mcu-fw-flasher utility, using the -J parameter. Specify the firmware file prepared earlier:
#:<syntaxhighlight lang="bash">
wb-mcu-fw-flasher -J -d /dev/ttyRS485-5 -a14 -f ./firmware.wbfw
</syntaxhighlight>
#Start wb-mqtt-serial
#:<syntaxhighlight lang="bash">
systemctl start wb-mqtt-serial
</syntaxhighlight>


===Updating with default connection settings===
Прошейте устройство командой:
This instruction is used for devices where the current bootloader version is below '''1.3.0''' and/or the current firmware does not support '''131''' register.  
<pre>
wb-mcu-fw-flasher -j -d /dev/ttyRS485-1 -a 25 -f WB-MR-MR6C_MCU3_3_1.9.4.wbfw
</pre>
Успешный процесс прошивки выглядит следующим образом:
<pre>
  wb-mcu-fw-flasher -j -d /dev/ttyRS485-1 -a 1 -f WB-MR-MR6C_MCU3_3_1.9.4.wbfw         
  /dev/ttyRS485-1 opened successfully.
  Send jump to bootloader command and wait 2 seconds...
  Error: Connection timed out.
  May be device already in bootloader, try to send firmware...
  WB-MR-MR6C_MCU3_3_1.9.4.wbfw opened successfully, size 12136 bytes
  Sending info block... OK
  Sending data block 89 of 89... OK.
  All done!
</pre>


In this case, the update can only be performed at a speed of '''9600N2''', by specifying the <code>-j</code> parameter for the wb-mcu-fw-flasher utility. If different connection settings are used, they must first be changed to the standard ones.
'''После успешной прошивки устройство само выйдет из режима загрузчика и перезапустится в основной программе.'''


We also recommend updating the bootloader if its version is
Пример ошибки при несовпадении сигнатуры:
1.3.0
<pre>
. This will allow you to update the firmware at any speed of connection [[WB_Modbus_Devices_Firmware_Update#Обновление_на_любой_скорости_соединения |any connection speed]].
Sending info block...
Error while sending info block: Slave device or server failure
Data format is invalid or firmware signature doesn't match the device
</pre>


Let's consider a synthetic example of firmware update for devices, where non-standard connection settings are used:
*WB-MGE (WB-MIO-E) gateway configured for Modbus over TCP with IP address 192.168.0.7, port 23.
*Connected to the gateway is WB-MDM3 device with address 58.
*Device and gateway settings are set to a speed of 115200 kbit/s.


{{note|info| '''Attention!''' The instructions consider an example in which the devices operate at a speed of '''115200 8N2'''. In your case, the connection settings may be different.}}
=== Прошивка устройств по широковещательному Modbus-адресу 0 ===
To update the firmware:
#Connect to the controller twice via [[SSH |SSH]], you should have two windows open: the first to create a socat tunnel, the second to send commands to the device.
#Stop wb-mqtt-serial:
#:<syntaxhighlight lang="bash">
systemctl stop wb-mqtt-serial
</syntaxhighlight>
#In the first window, start the redirect:
#:<syntaxhighlight lang="bash">
socat -d -d -d -x PTY,raw,b115200,parenb=0,cstopb=2,cs8,link=/dev/ttyRS485-5 tcp:192.168.0.7:23
</syntaxhighlight>
#:if you have a stable release up to and including wb-2207, instead of the b115200 parameter, use <code>ispeed=115200,ospeed=115200</code> .
#In the second window, change the device port speed to 9600 kbps:
#:<syntaxhighlight lang="bash">
modbus_client --debug -mrtu -b115200 -pnone -s2 /dev/ttyRS485-5 -a58 -t0x06 -r110 96
</syntaxhighlight>
#In the first window, terminate the socat connection with <kbd>Ctrl</kbd> + <kbd>C</kbd> .
#In [[socat#Configuring a gateway for firmware updates | gateway settings]] set the port speed to 9600 kbps.
#In the first window, restart socat forwarding with the new connection parameters:
#:<syntaxhighlight lang="bash">
socat -d -d -d -x PTY,raw,b9600,parenb=0,cstopb=2,cs8,link=/dev/ttyRS485-5 tcp:192.168.0.7:23
</syntaxhighlight>
#:if you have a stable release up to and including wb-2207, instead of the b9600 parameter, use <code>ispeed=9600,ospeed=9600</code> .
#In the second window, run the device firmware update, for example, with the wb-mcu-fw-flasher utility ([[WB_Modbus_Devices_Firmware_Update#Manual_update|full instructions]]):
#:<syntaxhighlight lang="bash">
wb-mcu-fw-flasher -j -d /dev/ttyRS485-5 -a25 -f ./firmware.wbfw
</syntaxhighlight>
#After finishing the firmware, return the old speed of 115200 kbps to the device:
#:<syntaxhighlight lang="bash">
modbus_client --debug -mrtu -b9600 -pnone -s2 /dev/ttyRS485-5 -a58 -t0x06 -r110 1152
</syntaxhighlight>
#In the first window, break the socat connection with <kbd>Ctrl</kbd> + <kbd>C</kbd> .
#In the gateway settings, change the port speed from 9600 kbps to 115200 kbps.
#Connect the gateway to the controller via Ethernet.
#Run wb-mqtt-serial
#:<syntaxhighlight lang="bash">
systemctl start wb-mqtt-serial
</syntaxhighlight>


If you need to flash several devices, you can first modify their speed, reconfigure the gateway, and then flash them one by one, restore their original speed, and reconfigure the gateway again.
Bootloader позволяет загружать прошивку на устройства но Modbus-адресу 0. Для этого устройство должно быть единственным устройством на шине и находится в режиме загрузчика.


===Configuring the gateway for updating the firmware===


The easiest way to change the gateway settings is to connect to its built-in web interface. To do this, you need to:
=== Прошивка нескольких устройств на шине ===


#connect the gateway to the computer using a UTP cable directly or through a router,
Возможна прошивка нескольких устройств, подключенных к шине. Устройства должны быть переведены в режим загрузчика и прошиваться по отдельности с указанием нешироковещательного Modbus-адреса. Прошивка устройств с одинаковым адресом возможна, если в режиме загрузчика находится только одно из них. Устройства прошиваются по очереди.
#assign a static IP address to the computer in the gateway network, for example, 192.168.0.201,
#open a browser and enter the gateway's IP address, by default 192.168.0.7.


==  Useful links ==
'''Внимание!''' Прошивка устройств, находящимся в режиме загрузчика и имеющим одинаковый modbus-адрес, или же прошивка нескольких устройств, находящихся в режиме загрузчика по адресу 0 не будет выполнена; имеющаяся прошивка на устройствах будет испорчена.
* [[Restore factory settings Wiren Board Modbus device | Restoring access — resetting communication settings]]
* [[Wiren Board Device Modbus Address | Modbus address of the Wiren Board device]]
* [[wb-mcu-fw-updater | Firmware update and recovery utility wb-mcu-fw-updater]]
* [[wb-mcu-fw-flasher | Service utility wb-mcu-fw-flasher]]
* [[Firmware Repository For Wiren Board Modbus Devices | Firmware repository for Wiren Board Modbus devices]]

Версия 16:07, 25 апреля 2019

Другие языки:

Внимание: Отображаемое название «Загрузка прошивок на устройства Wiren Board» переопределяет ранее заданное отображаемое название «Modbus Devices Firmware Update».

Firmware bootloader

The new versions of our devices have a firmware bootloader. It allows you to update the firmware of our devices/Wiren Board modules via RS-485/Modbus RTU. The bootloader mode, in which it is possible to update the firmware, has been added to the devices.

In the bootloader mode, the main functionality of the device is disabled. Communication parameters in the bootloader mode are fixed and do not depend on the values in the device memory: 9600 8N2.


Entering bootloader mode

|right||Bootloader mode indication The device enters bootloader mode if:

  • the device has the correct firmware — the first 2 seconds after power on, the device operates in bootloader mode;
  • the device does not have the correct firmware (for example, there was a failure when updating the firmware) — in this case, the bootloader mode is constantly active;
  • when the main program in the holding-register 129 (0x81) was recorded 1 — in this case, the device is rebooted and remains in bootloader mode for 120 seconds.

Bootloader mode indication: the device Status indicator rarely flashes. When you download a new firmware, indicator stops changing state.


Firmware

Writing firmware in the memory device is performed by a loader that gets its Modbus RTU. Firmware is stored in files with extension .wbfw. Currently available firmwares are available on request.


Device signatures

When flashing at the factory, the signature — the name of the hardware type of the device — is recorded into the memory of the device. When overwriting the firmware, the current signature is compared with the firmware signature. Writing new firmware is possible only if the signatures match.


Modbus

The device loader receives firmware via Modbus RTU. In the bootloader mode, the communication parameters are fixed and do not depend on the previous values in the device memory: 9600 8N2. According to the Modbus protocol, the device can be set to bootloader mode, if 1 is written to the holding register 129 (0x81) during the operation of the main program. In this scenario, the device restarts and remains in bootloader mode for 120 seconds.

The Modbus address of the bootloader firmware device should be selected as follows:

  1. The main address for the firmware is the address specified in the device memory: that is, it is the standard address to which the device responds from the main program.
  2. To flash a device using a broadcast address of 0. This is a less preferred method.


Utility for WB-mcu-fw-flasher firmware

Для передачи прошивки на устройства используется утилита wb-mcu-fw-flasher, запускаемая с контроллера Wiren Board (или компьютера с Linux или Windows).

Для установки утилиты на контроллер Wiren Board выполните команды:

apt-get update
apt-get install wb-mcu-fw-flasher

Версию утилиты для MS Windows можно скачать по этой ссылке: Wb-mcu-fw-flasher_1.0.2.zip

Для установки на компьютер с Debian скачайте пакет отсюда: Wb-mcu-fw-flasher_1.0.2_amd64-all.deb и выполните команды в директории, гуда загрузился пакет пакет.

apt-get update
apt-get install libmodbus5
dpkg -i Wb-mcu-fw-flasher_1.0.2_amd64-all.deb


Опции запуска утилиты wb-mcu-fw-flasher:

Параметр Описание Значение по умолчанию
-d Устройство последовательного порта
-f Файл прошивки
-a Адрес Modbus 1
-j Отправить на устройство команду перехода в режим загрузчика
-r Адрес holding-регистра для перехода в режим загрузчика 129
-D Включить режим отладки

Пример:

wb-mcu-fw-flasher -j -d /dev/ttyRS485-1 -a 25 -f WB-MR-MR6C_MCU3_3_1.9.4.wbfw

Пример для Windows:

wb-mcu-fw-flasher.exe -j -d COM10 -a 25 -f WB-MR-MR6C_MCU3_3_1.9.4.wbfw

Здесь COM10 — имя виртуального последовательного порта, которое присвоено адаптеру USB RS-485.


Прошивка устройств

При прошивке с контроллера остановите wb-mqtt-serial:

service wb-mqtt-serial stop

Подключите устройство к RS-485.

Если вы не знаете точного аппаратного типа устройства, то его сигнатуру можно прочесть командой:

export mbusaddr=1;  echo  -e `modbus_client --debug -mrtu -pnone -s2 /dev/ttyRS485-1 -a$mbusaddr -t0x03 -r290 -c 12 | grep Data | sed -e 's/0x00/\x/g' -e 's/Data://' -e 's/s//g'`|  xxd -r -p && echo ''

Задайте адрес прошиваемого устройства в переменной mbusaddr.

В выводе команды вы получите сигнатуру устройства, например, wbmr6c.

Выберите подходящую прошивку, например, WB-MR-MR6C_MCU3_3_1.9.4.wbfw.

Прошейте устройство командой:

wb-mcu-fw-flasher -j -d /dev/ttyRS485-1 -a 25 -f WB-MR-MR6C_MCU3_3_1.9.4.wbfw

Успешный процесс прошивки выглядит следующим образом:

   wb-mcu-fw-flasher -j -d /dev/ttyRS485-1 -a 1 -f WB-MR-MR6C_MCU3_3_1.9.4.wbfw          
   /dev/ttyRS485-1 opened successfully.
   Send jump to bootloader command and wait 2 seconds...
   Error: Connection timed out.
   May be device already in bootloader, try to send firmware...
   WB-MR-MR6C_MCU3_3_1.9.4.wbfw opened successfully, size 12136 bytes
   Sending info block... OK
   Sending data block 89 of 89... OK.
   All done!

После успешной прошивки устройство само выйдет из режима загрузчика и перезапустится в основной программе.

Пример ошибки при несовпадении сигнатуры:

Sending info block...
Error while sending info block: Slave device or server failure 
Data format is invalid or firmware signature doesn't match the device


Прошивка устройств по широковещательному Modbus-адресу 0

Bootloader позволяет загружать прошивку на устройства но Modbus-адресу 0. Для этого устройство должно быть единственным устройством на шине и находится в режиме загрузчика.


Прошивка нескольких устройств на шине

Возможна прошивка нескольких устройств, подключенных к шине. Устройства должны быть переведены в режим загрузчика и прошиваться по отдельности с указанием нешироковещательного Modbus-адреса. Прошивка устройств с одинаковым адресом возможна, если в режиме загрузчика находится только одно из них. Устройства прошиваются по очереди.

Внимание! Прошивка устройств, находящимся в режиме загрузчика и имеющим одинаковый modbus-адрес, или же прошивка нескольких устройств, находящихся в режиме загрузчика по адресу 0 не будет выполнена; имеющаяся прошивка на устройствах будет испорчена.