Month: February 2022

Using USBDM programmer on Linux

Few days ago I bought a DEMO9S12NE64 kit on eBay and soon realized that I need a BDM programmer. Whoa, times fly, it was yesterday (about 20 years ago) that I was playing with BDM programmer on Linux over parallel port. Then I just bought a USBDM and when I plugged it on Linux and ran dmesg:

[ 9304.940188] usb 1-2: new full-speed USB device number 8 using xhci_hcd
[ 9305.091381] usb 1-2: New USB device found, idVendor=16d0, idProduct=0567, bcdDevice= 4.10
[ 9305.091394] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 9305.091401] usb 1-2: Product: USBDM RS08,HCS08,HCS12,CF-V1 BDM
[ 9305.091405] usb 1-2: Manufacturer: pgo
[ 9305.091409] usb 1-2: SerialNumber: USBDM-JMxx-0001

Then I downloaded a usbdm_4.12.1.262-1-x86_64.deb but it was using some only libraries that doesn’t exist currently Ubuntu Linux. The solution was compiling it from source code:

$ git clone
$ cd usbdm-eclipse-makefiles-build
$ ./LinuxPackages
$ ./MakeAll
$ ./CreateDebFile
$ sudo dpkg -i ../usbdm_4.12.1.270-1-x86_64.deb

This is the output log of the installation:

Selecting previously unselected package usbdm.
(Reading database ... 338275 files and directories currently installed.)
Preparing to unpack .../usbdm_4.12.1.270-1-x86_64.deb ...
Unpacking usbdm (4.12-1) ...
Setting up usbdm (4.12-1) ...

Checking for Eclipse directories
Looking for Eclipse in '/usr/local/eclipse*' - Not Found
Looking for Eclipse in '/opt/eclipse*' - Not Found
Looking for Eclipse in '/usr/lib/eclipse*' - Not Found
Looking for Eclipse in '/opt/cpp-neon/eclipse*' - Not Found
Looking for Eclipse in '/root/eclipse/cpp-2019-09/eclipse' - Not Found
Looking for Eclipse in '/root/eclipse/cpp-2019-06/eclipse' - Not Found
Looking for Eclipse in '/root/eclipse/cpp-2019-03/eclipse' - Not Found

Checking for KDS directories
Looking for Freescale KDS in '/usr/local/Freescale/KDS_*' - Not Found
Looking for Freescale KDS in '/opt/Freescale/KDS_*' - Not Found

Checking for Codewarrior directory
Looking for Codewarrior in '/usr/local/Freescale/CodeWarrior_MCU_10.2' - Not Found
Looking for Codewarrior in '/opt/Freescale/CodeWarrior_MCU_10.2' - Not Found
Processing triggers for mailcap (3.69ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu2) ...
Processing triggers for man-db (2.9.4-2) ...

Compiling NuttX to RaspberryPi Pico

$ git clone
$ sudo mv pico-sdk /opt/
$ cd /opt/pico-sdk/
$ git reset --hard 26653ea81e340
$ export PICO_SDK_PATH=/opt/pico-sdk
$ cd ~/nuttxspace/nuttx
$ ./tools/ raspberrypi-pico:usbnsh
$ make -j

After nuttx.uf2 is created, press and hold the BOOTSEL button of the board and connect the USB cable. A new virtual disk will appear on your computer. Just copy the nuttx.uf2 to it.

The board will reset and if you type dmesg on your computer you will see:

[ 2141.219090] cdc_acm 1-3:1.0: ttyACM0: USB ACM device
[ 2141.219118] usbcore: registered new interface driver cdc_acm
[ 2141.219120] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters

Use minicom or other serial console tool to open /dev/ttyACM0 at 115200 8n1 and press ENTER 3 times, you will see:

NuttShell (NSH) NuttX-10.2.0
nsh> ?
help usage: help [-v] []

. cd df free mkrd reboot test unset
[ cp echo help mount rm time usleep
? cmp env hexdump mv rmdir true xd
basename dirname exec kill printf set truncate
break date exit ls ps sleep uname
cat dd false mkdir pwd source umount

Builtin Apps:
getprime hello nsh ostest sh
nsh> uname -a
NuttX 10.2.0 cc8ab23550 Feb 9 2022 09:35:01 arm raspberrypi-pico
nsh> getprime
Set thread priority to 10
Set thread policy to SCHED_RR
Start thread #0
thread #0 started, looking for primes < 10000, doing 10 run(s) thread #0 finished, found 1230 primes, last one was 9973 Done getprime took 12810 msec nsh>

Flashing NuttX RTOS on Olimex-P405 using JlinkExe

$ JLinkExe -if swd
SEGGER J-Link Commander V6.80d (Compiled Jun 26 2020 17:19:52)
DLL version V6.80d, compiled Jun 26 2020 17:19:40

Connecting to J-Link via USB…O.K.
Firmware: J-Link V11 compiled Jun 9 2020 13:38:27
Hardware version: V11.00
S/N: xxxxxxxx
License(s): GDB

Type "connect" to establish a target connection, '?' for help
Please specify device / core. : STM32L496RE
Type '?' for selection dialog
Specify target interface speed [kHz]. : 4000 kHz
Device "STM32F405RG" selected.

Connecting to target via SWD
Found SW-DP with ID 0x2BA01477
Found SW-DP with ID 0x2BA01477
DPIDR: 0x2BA01477
Scanning AP map to find all available APs
AP[1]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x24770011)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
Found Cortex-M4 r0p1, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM
Cortex-M4 identified.
J-Link>loadbin nuttx.bin, 0
Halting CPU for downloading file.
Downloading file [nuttx.bin]…
Comparing flash [100%] Done.
Erasing flash [100%] Done.
Programming flash [100%] Done.
J-Link: Flash download: Bank 0 @ 0x08000000: 1 range affected (32768 bytes)
J-Link: Flash download: Total: 0.898s (Prepare: 0.014s, Compare: 0.020s, Erase: 0.751s, Program & Verify: 0.109s, Restore: 0.002s)
J-Link: Flash download: Program & Verify speed: 293 KB/s

How to avoid TIMEOUT in ARP SEND on NuttX?

If you are configuring the NuttX network and you are receiving this error:

arp_send: ERROR: arp_wait failed: -116

Something could be wrong in your network configuration. It is strange that the only other reference I found to this error was in this nice blog:

Beside incorrect network configuration (i.e. your device IP or router/gateway IP are incorrect) this error can happen because the default timeout is only 20ms:

int "ARP re-send delay"
default 20
Wait this number of milliseconds after sending the ARP request
before checking if the IP address mapping is present in the ARP
table. This time should be related to the maximum round trip time
on the network since it is basically the time from when an ARP
request is sent until the response is received.

Try to increase it to 100, 200 or even 500 (if your network is really bad) and this error will not show up.