In recent events many have found there selfs at home and not being able to go to office. For me physically this was not something new as I have been working remote for caple of years now and I wanted to show one less known feature of Segger JLink which provides programming interface over the internet as the device you are programming is sitting next to you on the bench.
For this example I will use the nRF52-DK development board from Nordic Semi. This board has nRF52832 SoC onboard which has Arm® Cortex®-M4 32-bit processor with FPU, 64 MHz, and 512 kB flash/64 kB RAM memory. This will be important later on when we need to figure out the start address for the application firmware.
There are three ways how to do programming with JLink and you can read more about it on Segger website. I will demonstrate the "LAN" way, where the device is connected to one computer using the JLink programmator and I am programming that chip over LAN connection.
- picture source: link
The computer with the target device has Windows 10 OS and it is a simple process to start the JLink server on it. After installing JLink software search for SEGGER J-Link Remote Server and start the application. On first configuration windows select parameters as in the picture:
After the configuration, the server has started and the IP address in my case is as shown in the picture. To be able to see what is happening with the server enables the show log configuration for easier tracking.
On the client-side main development, the machine is using Ubuntu 18.04 LTS OS. This will allow us to easily create scripts that will help us to achieve firmware download over LAN.
First it is necessary to install Segger J-Link software package. After that connection with the server need to be established so the firmware can be downloaded. To do that you can call JLink software from the command line with IP address of server machine as a parameter, for example:
$ JLinkExe ip 192.168.13.229
This will get you a connected command line into the remote terminal. You can then start configuration manually in the Jlink terminal by typing connect
or help
for more information. But the goal is to this in one "click".
This is why we will create a script called flash_remote.sh with all the commands you would manually type to program MCU on the server-side.
si SWD
Speed 4000
device nrf52832_xxaa
connect
loadbin _build/nrf52832_xxaa.bin 0x00026000
r
exit
To explain each line so the script is more understandable:
si SWD
- configures that JLink uses SWD for programming and debuggingSpeed 4000
- configures SWD speed (4000 default value)device nrf52832_xxaa
- configures the target device, you can set your ownconnect
- JLink is connecting to the device with previously set parametersloadbin _build/nrf52832_xxaa 0x00026000
- loadbin command will take two parameters, first location of application bin file and second start address in memory, and flash the firmware. Start address can be found in the chip documentation or in the linker file of the MCU (for nRF52 devices memmory)
now we can call JLink software with next parameters:
$ JLinkExe ip 192.168.13.229 flash_remote.sh
and the programm will be downloaded to the MCU.
West is a tool created within the Zephyr RTOS project and among other things, it is used for building and flashing the target MCU. More about the west can be found on the link. Since west does everything for us and calls the required software, jLink in our case, we need to call just one command:
west flash -r jlink --tool-opt="ip xxx.xxx.x.xxx"
command explanation:
west
- command nameflash
- command parameter to flash the device-r
- runner, we choosejlink
instead ofnrfjprog
which is default for nRF dev boards--tool-opt
- Additional options for JLink Commander, and our additional option is the IP address of the machine with jLink and remote jLink server running.
with this command, you can flash Zephyr projects to the remote devices.
- this example was done for a Linux client and in theory it should work on Windows client as well, but it has not been tested.
- https://iosoft.blog/category/nordic-nrf52/
- http://wiki.hivetool.org/NRF52840_Development
- https://docs.electronut.in/papyr/programming_guide/#upload-hex-file
- https://aurabindo.in/nordic-and-open-source-goodness/
- https://diyiot.wordpress.com/2015/11/29/ble-application-with-nrf51822-firmware-flashing/
- https://www.segger.com/products/debug-probes/j-link/tools/j-link-remote-server/
- https://docs.zephyrproject.org/latest/guides/west/index.html