RAK19713 Firmware & Flashing
This section explains how to flash a RAK19713 (MiniPCIe RAK4630) using a RAK7391 running RAKPiOS. The same steps apply to any RAK4630-based device connected via USB to ARM64 hardware running Debian, such as a Raspberry Pi.
Throughout this page, the RAK19713 is referenced as /dev/rak19713, which is the udev symlink defined in the RAK19713 Quick Start Guide.
Choosing the Right Flashing Method
The RAK19713 supports multiple firmware flashing methods. The appropriate method depends on the target operation and the current state of the device. Refer to the table below for selection guidance:
| Task | When to use | Interface | Tool |
|---|---|---|---|
| Flash RUI3 AT Firmware | Restore the factory AT command set firmware | RAKDAP1 (SWD) | pyOCD |
| Flash the Arduino Bootloader | One-time preparation for USB flashing of custom firmware | RAKDAP1 (SWD) | pyOCD |
| Flash Custom Firmware (PlatformIO) | Build and upload your own application from source | USB (DFU) | PlatformIO |
| Flash a Pre-built Binary (DFU) | Upload a firmware .zip you already have | USB (DFU) | nrfutil |
The first two tasks use the RAKDAP1 debugger and write directly to the chip, so they work even on a blank or bricked board. The last two flash over USB and require the Arduino or RUIv3 bootloaders to be installed first.
Requirements
Hardware
The following hardware is used in this example:
- RAK19713 module
- RAK7391 CM4 Carrier Board running RAKPiOS or a similar OS
- RAKDAP1 DAPLink Tool
- (optional) A jig to easily connect the RAKDAP1 to the board
Software
Tool installation is covered in the Tool Installation appendix at the end of this page. Each task below lists the specific tools it requires.
GPIO Control
GPIO pins on the RAK7391 are used to control the RAK19713 module, including reset and DFU mode operations. This section is referenced by the USB-based flashing tasks.
The RAK19713 board in a MiniPCIe slot of the RAK7391 WisGate Connect can be reset by asserting the proper RESET GPIO.
In addition to the USB interface, the RAK19713 board outputs the RAK4630 signals for RESET (pin 22) and IO3 (pin 13). The RESET pin is controlled by GPIO17 (slot 1) and GPIO6 (slot 2) of the RAK7391 board.
To reset the board in slot 1, run:
gpioset 0 17=0 ; sleep 0.1
gpioset 0 17=1 ; sleep 0.1
To enter DFU mode for flashing an application, repeat the reset sequence twice:
gpioset 0 17=0 ; sleep 0.1
gpioset 0 17=1 ; sleep 0.1
gpioset 0 17=0 ; sleep 0.1
gpioset 0 17=1 ; sleep 0.1
If your board is in slot 2, use the same command, replacing 17 with 6.
Flash RUI3 AT Firmware
Use this task to install (or restore) the factory RUI3 AT Command Set firmware, for example if you've overwritten it with a custom build and want to roll back.
RUI3 AT Firmware Requirements
- RAKDAP1 connected to the RAK19713 JLink header
- pyOCD installed
A jig with pogo-pins is strongly recommended to avoid temporarily soldering cables to the JLink connector.
RUI3 AT Firmware Steps
- Connect the RAKDAP1 to the RAK7391 USB2 (white) port. It will be automatically recognized as NXP ARM mbed. You can confirm detection with
lsusbanddmesg:
Click to view expected lsusb / dmesg output
rak@rakpios:~ $ lsusb
Bus 003 Device 006: ID 1a86:7523 QinHeng Electronics CH340 serial converter
Bus 003 Device 005: ID 1a86:7523 QinHeng Electronics CH340 serial converter
Bus 003 Device 004: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 003 Device 003: ID 0483:5740 STMicroelectronics Virtual COM Port
Bus 003 Device 012: ID 0d28:0204 NXP ARM mbed
Bus 003 Device 002: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
rak@rakpios:~ $ dmesg
...
[14608.312311] usb 3-1.1: new full-speed USB device number 13 using dwc2
[14608.534838] usb 3-1.1: New USB device found, idVendor=0d28, idProduct=0204, bcdDevice= 1.00
[14608.534861] usb 3-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[14608.534877] usb 3-1.1: Product: DAPLink CMSIS-DAP
[14608.534886] usb 3-1.1: Manufacturer: ARM
[14608.534894] usb 3-1.1: SerialNumber: 0700000100400029520000054e525943a5a5a5a597969908
[14608.540853] usb-storage 3-1.1:1.0: USB Mass Storage device detected
[14608.541512] scsi host0: usb-storage 3-1.1:1.0
[14608.544887] cdc_acm 3-1.1:1.1: ttyACM1: USB ACM device
...
rak@rakpios:~ $ ls -la /dev/ttyACM1
crw-rw---- 1 root dialout 166, 1 Jul 15 13:53 /dev/ttyACM1
On RAKPiOS, the default user already belongs to the dialout group, providing write access to the port. If your user is not in the group, add it and reboot before proceeding.
- Download and flash the latest RUI3 AT Command Set firmware:
wget https://downloads.rakwireless.com/RUI/RUI3/Image/RAK4631_latest_final.hex
pyocd flash -t nrf52840 RAK4631_latest_final.hex
- Remove the RAKDAP1, switch off the RAK7391, install the RAK19713 into a MiniPCIe slot, connect the antennas, and boot the board.
- Use picocom (
sudo apt install picocom) to verify the firmware is running. Any other serial monitor will also work.
rak@rakpios:~ $ picocom -b 115200 /dev/rak19713
Once connected, type [C-a] [C-h] to view picocom's available commands. The terminal will display the RUI3 banner:
Type [C-a] [C-h] to see available commands
Terminal ready
AT+VER=RUI_4.2.1_RAK4631
OK
AT+CLIVER=1.5.13
OK
AT+APIVER=3.2.10
OK
Flash the Arduino Bootloader
Use this task to prepare a RAK19713 for USB-based flashing of custom firmware. This replaces the factory RUI3 image with the WisBlock Arduino bootloader. Once installed, you can flash firmware over USB without needing the RAKDAP1 again.
Arduino Bootloader Requirements
- RAKDAP1 connected to the RAK19713 JLink header (see Flash RUI3 AT Firmware for wiring and verification)
- pyOCD installed
This process is required only once per board. After the Arduino bootloader is installed, the RAK19713 can be moved to a MiniPCIe slot and flashed over USB using PlatformIO or nrfutil.
Arduino Bootloader Steps
- With the RAKDAP1 connected to both the RAK19713 and the RAK7391 USB2 (white) port, download and flash the WisBlock Arduino bootloader:
wget https://github.com/RAKWireless/WisBlock/releases/download/0.4.2/WisCore_RAK4631_Board_Bootloader.hex
pyocd flash -t nrf52840 WisCore_RAK4631_Board_Bootloader.hex
- Remove the RAKDAP1, install the RAK19713 into a MiniPCIe slot of the RAK7391, and boot the carrier board. The RAK19713 is now ready to accept firmware over USB.
Flash Custom Firmware (PlatformIO)
Use this task to build your own application from source and flash it over USB. The example below creates a minimal "blink" project to verify that the toolchain is correctly set up.
Custom Firmware (PlatformIO) Requirements
- Arduino bootloader installed on the RAK19713
- PlatformIO installed
- RAK19713 installed in a MiniPCIe slot of the RAK7391
Custom Firmware (PlatformIO) Steps
- Create a project with the following blink code:
mkdir blink
cd blink
platformio project init -b nrf52840_dk
cat << EOF >> src/main.ino
#include <Arduino.h>
#include <Adafruit_TinyUSB.h>
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
uint8_t state = digitalRead(LED_BUILTIN);
state = !state;
digitalWrite(LED_BUILTIN, state);
delay(500);
}
EOF
- Apply the RAK4630-specific patches for the RAK19713 board:
wget https://github.com/RAKWireless/WisBlock/raw/refs/heads/master/PlatformIO/RAK_PATCH_V2.zip
unzip RAK_PATCH_V2.zip
ln -s RAK_PATCH_V2/rakwireless
cat << EOF > platformio.ini
[platformio]
boards_dir = rakwireless/boards
[env:rak4630]
platform = nordicnrf52
board = rak4630
framework = arduino
platform_packages = toolchain-gccarmnoneeabi@~1.90301.0
build_src_filter = \${env.build_src_filter}+<../rakwireless/variants/rak4630>
build_flags = -I rakwireless/variants/rak4630
EOF
- Build the project with the RAK4630 configuration:
platformio run
- Flash the firmware to the RAK19713:
platformio run -t upload
The green LED on the RAK19713 should now blink at 1 Hz, confirming a successful flash.
Flash a Pre-Built Binary (DFU)
Use this task when you already have a firmware .zip package (generated by PlatformIO, Arduino IDE, or another tool) and want to flash it without rebuilding from source. The .zip contains the manifest, firmware code, and metadata expected by the Nordic DFU protocol.
Pre-Built Binary (DFU) Requirements
- Arduino bootloader installed on the RAK19713
- nrfutil installed
- RAK19713 installed in a MiniPCIe slot of the RAK7391
- A firmware
.zipfile (for example,firmware.zip) available on the host
Pre-Built Binary (DFU) Steps
-
Put the board into DFU mode by running the reset sequence twice, with approximately 100 ms between each transition. Refer to the GPIO Control section for the slot-to-GPIO mapping.
-
Upload the binary with adafruit-nrfutil:
gpioset 0 17=0 ; sleep 0.1
gpioset 0 17=1 ; sleep 0.1
gpioset 0 17=0 ; sleep 0.1
gpioset 0 17=1 ; sleep 0.1
adafruit-nrfutil dfu serial -p /dev/rak19713 -b 115200 --singlebank -pkg firmware.zip
Make sure the device port (/dev/rak19713 in this example) and the firmware image name (firmware.zip) match your setup.
Tool Installation
This appendix collects the installation steps for the tools referenced by the flashing tasks above. You only need to install the tools required by the tasks you plan to run.
pyOCD
pyOCD is the recommended tool on Linux for flashing the Nordic chip at a low level through a RAKDAP1, including both the bootloader and application firmware.
- Install pyOCD and add the nRF52840 pack:
pip install pyocd --break-system-packages
pyocd pack install nrf52840
- Download and install the CMSIS-DAP udev rules so pyOCD can detect the RAKDAP1:
wget https://raw.githubusercontent.com/pyocd/pyOCD/refs/heads/main/udev/50-cmsis-dap.rules
sudo mv 50-cmsis-dap.rules /etc/udev/rules.d/
sudo service udev restart
PlatformIO
PlatformIO is used to build and flash custom firmware. Although it integrates with IDEs like VSCode, the headless PlatformIO Core is sufficient for the flashing tasks on this page.
- Download and run the PlatformIO installer:
wget -O get-platformio.py https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
python3 get-platformio.py
- Create symbolic links for convenient access:
ln -s ~/.platformio/penv/bin/platformio ~/.local/bin/platformio
ln -s ~/.platformio/penv/bin/pio ~/.local/bin/pio
ln -s ~/.platformio/penv/bin/piodebuggdb ~/.local/bin/piodebuggdb
- Add the PlatformIO udev rules:
curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/system/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
sudo service udev restart
RAK4630-specific configuration (board definition and patches) is applied later as part of the Flash Custom Firmware (PlatformIO) task.
nrfutil
nrfutil is the tool provided by Nordic Semiconductor for flashing their microcontrollers over DFU. On Linux, the original version may not work with current Python versions, so use the Adafruit-maintained fork, which matches the version used by PlatformIO:
pip install adafruit-nrfutil --break-system-packages
