Serial DFU Procedure and Tips
Hi,
Some of you may need to use Serial DFU to transfer firmware from external MCU or PC. So I am posting this blog to might help saving your time to debug and development.
Serial DFU Sequence
- Basic Serial DFU Sequence Diagram
Basically it need to take some time between Transmit and ACK. If you don't have enough time for waiting DFU communication will be failed.
- Packet Format
-
SDK v8.0.0 ~
-
SDK ~v7.2.0
Refer your documentation where in zipped SDK which it published from SDK download site
-
Example (written based on DFU example of SDK 7.2.0 )
Transmits by PC >>>>>
<<<<< ACKs from Target Device
- Script of flashing Hex
Here is script to get raw data of two way communication. When you use this script it will be helpful to understand and analysis bidirection sequence.
-
For SDK 6.x.x : hci_dfu_send_hex
The script file placed in "SDK\nrf51822\Board\nrf6310\device_firmware_updates\hci_dfu_send_hex"
hci_dfu_send_hex.py --verbose --file ble_app_hrs.hex --port COM3
-
For SDK 7.x.x : hci_dfu_send_hex
The script file placed in "SDK\examples\dfu\hci_dfu_send_hex"
hci_dfu_send_hex.py --verbose --file ble_app_hrs.hex --port COM3
-
For SDK 8.x.x ~ : pc-nrfutil
It will be created executable file automatically by "setup.py" and copy compiled resource and executable file to python folder.
python setup.py install
Tips
- Create Executable file
“py2exe” might has an issue that fail to convert python script to windows executable file with access permission error. This way will be an option to avoid issue.
Preparation
-
Prepare icon file to embed in executable file(option)
Create executable file for windows
pyinstaller -noconsole --onefile hci_dfu_send_hex.py -i Nordic_Small.ico -n hci_dfu_send_hex
Usage Serial DFU ----------------
- ~SDK v 7.x.x
- The following is an example of how to use the script:
python hci_dfu_send_hex.py -f C:\NewFirmware\ble_app_hrs.hex -p COM7 -fc
- The following is an example of how to use the executable windows file:
hci_dfu_send_hex.exe -f C:\NewFirmware\ble_app_hrs.hex -p COM7 -fc
- The following is an example of show raw packet data :
hci_dfu_send_hex.exe -f C:\NewFirmware\ble_app_hrs.hex -p COM7 -fc -v
or
hci_dfu_send_hex.exe -f C:\NewFirmware\ble_app_hrs.hex -p COM7 -fc --verbose
- SDK v 8.x.x ~
nrfutil.exe dfu serial --package=< image_file.zip > --port=< com_port > [--flowcontrol] [--baudrate <baud_rate>]