Using Raspberry Pi for Embedded Systems Development — Part 1

<rawat.s>
20 min readJun 27, 2021

I have been exploring the Raspberry Pi 4 Model B Single-Board Computer (SBC) for a while and I want to use it as a low-cost small-sized computer for different purposes.

Recently, I have installed the Raspbian OS (ARM 64-bit or “aarch64”) on one of my Raspberry Pi 4 boards (4 GB RAM, 32 GB microSD storage) and started exploring how to use it at home as a host computer for embedded systems development and how to offload some development tasks from my old x86_64 Windows 10 notebook to the Raspberry Pi computer.

In this blog I want to share my experiences about using various software and hardware tools for microcontroller programming, code debugging and firmware flashing.

List of Topics:

  • System Information
  • VNC Remote Access (GUI Desktop) from Microsoft Windows
  • The Arduino Software IDE (for aarch64)
  • The xPack GNU Arm Embedded GCC (for aarch64)
  • The CMSIS-DAP / DAP-Link Debug Probe
  • The xPack OpenOCD Software (for aarch64)
  • Firmware Flashing for SAMD21 with OpenOCD and CMSIS-DAP
  • Command-Line Tools for ST-Link/V2 Programmer
  • MicroPython Firmware Flashing for STM32 using ST-Link/V2
  • Using STM32F411CEU6 for CMSIS-DAP
  • The SEGGER J-Link Software (for aarch64)
  • The SEGGER Embedded Studio for ARM (for aarch64)
  • The VS Code IDE with PlatformIO Extension (for aarch64)
  • The VS Code IDE with Arduino Extension (for aarch64)

[>] System Information

.

Here is the information about the Raspberry Pi 4 that I used.

# check the OS version
$ uname -s -r -o -m
Linux 5.10.44-v8+ aarch64 GNU/Linux
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Note:

[>] VNC Remote Access from Microsoft Windows

.

To allow remote access to the Raspberry Pi (RPi) via VNC, you have to enable the RealVNC Server on the RPi:

$ sudo raspi-config

Go to “Interface Options” → “VNC” to enable the RealVNC server (default port: 5900).

On a Windows computer, you can use VNC Viewer (such as TightVNC Viewer or RealVNC Viewer) to access the RPi board by specifying the IP address of the RPi to be connected remotely.

You can specify the hostname of the RPi instead of its actual IP address. The default hostname for RPi is “raspberrypi.local”.

VNC Viewer on Windows 10
Raspberry Pi Desktop, accessed from Windows 10 via VNC Client

Note: You can change the display resolution by using the command xrandr:

# Change to resolution such as 1024x768, 1280x720 or 1280x960.
$ xrandr --fb 1280x720

[>] The Arduino Software IDE

.

Arduino users can download and install Arduino IDE Software for Raspberry Pi 4 (ARM 64-bit, aarch64) as follows. Note that the version of Arduino software used in this example is v1.8.15. As of the writing time, the Arduino IDE 2.0 beta (2.0.0-beta.7) doesn’t support the ARM 64-bit platform.

Arduino IDE — Download Web Page
# Download the Arduino IDE software for ARM 64-bit
# https://www.arduino.cc/en/software
$ wget -c -q https://downloads.arduino.cc/arduino-1.8.15-linuxaarch64.tar.xz
# Download Arduino IDE software
$ ARDUINO_VERSION=arduino-1.8.15
$ ARDUINO_FILE=${ARDUINO_VERSION}-linuxaarch64.tar.xz
$ wget -c -q
https://downloads.arduino.cc/${ARDUINO_FILE}
# Extract the tar.xz file to /opt
$ sudo tar -xf ${ARDUINO_FILE} -C /opt
$ cd /opt/${ARDUINO_VERSION}
# Install the Arduino software
$ sudo ./install.sh
# Run the Arduino IDE software
$ arduino > /dev/null 2>&1 &

In GUI Desktop mode, you can start the Arduino IDE from the menu: Programming → Arduino IDE.

Installation of Arduino Core Packages via Board Managers

Additional Board Managers can be added (e.g. for ESP32 support).

You can see all installed tools required by the Arduino IDE for different Arduino Board Managers under ~/.arduino15.

$ tree -L 2 ~/.arduino15/packages/arduino/tools
/home/pi/.arduino15/packages/arduino/tools
├── arduinoOTA
│ └── 1.2.1
├── arm-none-eabi-gcc
│ └── 7-2017q4
├── bossac
│ ├── 1.7.0-arduino3
│ └── 1.9.1-arduino2
├── CMSIS
│ └── 4.5.0
├── CMSIS-Atmel
│ └── 1.2.0
├── dfu-util
│ └── 0.10.0-arduino1
├── openocd
│ ├── 0.10.0-arduino7
│ └── 0.11.0-arduino2
└── rp2040tools
└── 1.0.2
Using Arduino IDE software on RPi 4 (Ubuntu Desktop 20.04 LTS)

In case you want to use the Raspberry Pi Pico RP2040 board, then create a udev rules file, for example: /etc/udev/rules.d/40-rp2040.rules and add the following text line:

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", MODE="664", GROUP="plugdev", TAG+="uaccess"

Update and reload the udev rules so that any non-root user can access the device (without sudo):

$ sudo udevadm control --reload-rules
$ sudo udevadm trigger

After you have installed the udev rules file, the Pico device is accessible by any non-root user (without sudo).

[>] The xPack GNU Arm Embedded GCC

.

If you plan to program ARM-Cortex-M Series microcontrollers using the C/C++ programming language, it is highly recommended to install a cross-compilation toolchain for ARM.

You can use the GNU Arm Embedded GCC software provided by the xPack Project, which is also used by the Eclipse Embedded CDT.

Steps to download and install the XPACK GNU Arm Embedded GCC software for ARM 64-bit computer:

# Download the .tar.gz file from github
$ wget -c https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v10.2.1-1.1/xpack-arm-none-eabi-gcc-10.2.1-1.1-linux-arm64.tar.gz
# Extract the .tar.gz file and move the directory to /opt
$ tar xfz ./xpack-arm-none-eabi-gcc-10.2.1-1.1-linux-arm64.tar.gz
$ sudo mv ./xpack-arm-none-eabi-gcc-10.2.1-1.1 /opt/

Edit the ~/.profile file:

$ nano ~/.profile

Add / append the following line to update the $PATH environment variable and save the change to file (to save and exit the nano editor, type Ctrl+O to save file and Ctrl+X to exit)

PATH="$PATH:/opt/xpack-arm-none-eabi-gcc-10.2.1-1.1/bin"

Reload ~/.profile:

$ source ~/.profile

Next, try to run the arm-none-eabi-gcc command:

$ which arm-none-eabi-gcc
/opt/xpack-arm-none-eabi-gcc-10.2.1-1.1/bin/arm-none-eabi-gcc
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (xPack GNU Arm Embedded GCC, 64-bit) 10.2.1 20201103 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
...

Now, the GNU Arm Embedded GCC software is successfully installed.

Note: As an alternative to the software provided by XPACK, you can use the GNU Arm Embedded Toolchain provided by Arm Ltd. (Official download page https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads).

Steps for software installation are listed below:

# Download the tar.bz2 file
$ wget -c
https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
# Extract the .tar.bz2 file to the directory /opt
$ sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2 -C /opt
# Try to run the 'arm-none-eabi-gcc' command:
$ /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10-2020-q4-major) 10.2.1 20201103 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
....

[>] The CMSIS / DAP-Link Debug Probe

.

I have bought a “nanoDAP-HSDAP-Link debug probe (based on the Atmel SAM3U2C) from MUSE Lab (China) and I can use it as as a CMSIS-DAP debug probe for ARM Cortex-M based MCUs (flashing and/or debugging tasks).

Connect the debug probe to one of the USB ports of the RPi and run the following command to check whether the USB device is visible and ready to use:

# Check the DAP-Link debugger (MUSELab Atmel SAM3U) 
$ lsusb | grep "0d28:0204"
Bus 001 Device 017: ID 0d28:0204 NXP ARM mbed
nanoDAP-HS Debug Probe by MUSE Lab

Create a new udev rules file for DAP-Link: /etc/udev/rules.d/50-cmsis-dap.rules with the following text line (a single line):

SUBSYSTEM=="usb", ATTR{idVendor}=="0d28", ATTR{idProduct}=="0204", MODE:="666"

Apply the rules:

$ sudo udevadm control --reload-rules
$ sudo udevadm trigger

[>] The XPACK OpenOCD

.

In the example, the OpenOCD software will be used together with the DAP-Link debug probe for flashing MCU firmware. The following are the steps for OpenOCD installation (ARM 64-bit version).

# Steps for downloading and installing XPACK OpenOCD tools from
# https://github.com/xpack-dev-tools/openocd-xpack/releases
# Download the XPACK OpenOCD package
$ wget -c -q https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.11.0-1/xpack-openocd-0.11.0-1-linux-arm64.tar.gz
# Extract the .tar.gz file
$ tar xfz xpack-openocd-0.11.0-1-linux-arm64.tar.gz
# Move the xpack-openocd directory to /opt
$ sudo mv ./xpack-openocd-0.11.0-1 /opt/

Append the following line to ~/.profile

PATH="$PATH:/opt/xpack-openocd-0.11.0-1/bin"

Reload ~/.profile:

$ source ~/.profile

Try to run the openocd command:

$ which openocd
/opt/xpack-openocd-0.11.0-1/bin/openocd
$ openocd --version
xPack OpenOCD, aarch64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-16:47)
...

[>] Firmware Flashing for SAMD21 with OpenOCD

.

As a demo, the DAP-Link / CMSIS-DAP debug probe and the OpenOCD software tool will be used to re-flash the bootloader for a SAMD21-based Arduino-Zero compatible board. There are two different Arduino bootloaders for SAMD21 available for selection.

  1. Download SAMD21 Bootloaders

Adafruit Bootloader (Option 1)

# Download the Adafruit UF2 bootloader for SAMD21
# https://github.com/adafruit/uf2-samdx1/releases/
$ wget -c -q https://github.com/adafruit/uf2-samdx1/releases/download/v3.13.0/bootloader-zero-v3.13.0.bin
$ BOOTLOADER_FILE=./bootloader-zero-v3.13.0.bin

Arduino Bootloader (Option 2)

# Download the Arduino SAMD21 SAM-BA Bootloader
$ wget https://github.com/arduino/ArduinoCore-samd/raw/master/bootloaders/zero/samd21_sam_ba.bin
$ BOOTLOADER_FILE=./samd21_sam_ba.bin

2) Create and edit a new configuration file ./openocd.cfg for OpenOCD:

Edit and save the configuration file (./openocd.cfg) with the following contents.

source [find interface/cmsis-dap.cfg]
#source [find interface/jlink.cfg]
transport select swd
set CHIPNAME at91samd21g18
set CPUTAPID 0x0bc11477
set ENDIAN little
telnet_port disabled
reset_config srst_nogate
adapter srst delay 100
adapter srst pulse_width 100
source [find target/at91samdXX.cfg]

This configuration file will be used for flashing the bootloader firmware to an Arduino Zero compatible microcontroller board (I used the RobotDyn SAMD21 M0-Mini board).

Cortex-Debug / Program Connector
Cortex Debug Connector vs. JTAG connector

3) Prepare the hardware for firmware flashing.

Hardware Setting: “M0-Mini” SAMD21 board and “nanoDAP-HS” CMSIS-Compatible Debug Probe

4) Run the OpenOCD command line to erase and flash the bootloader specified by the ${BOOTLOADER_FILE} environment variable.

# Flash the SAMD21 (Arduino Zero) bootloader using XPACK OpenOCD
$ sudo /opt/xpack-openocd-0.11.0-1/bin/openocd -d2 \
-f ./openocd.cfg \
-c "init; targets; reset halt;" \
-c "at91samd chip-erase;" \
-c "reset halt;" \
-c "program ${BOOTLOADER_FILE} verify;" \
-c "reset; shutdown"

The sample output of the command is shown below:

Arduino SAMD21 Firmware Flashing with OpenOCD

Now, you can use the Arduino IDE software to write an Arduino sketch and upload it to the SAMD21 board via USB.

Connect the SAMD21 board to the RPi and run the following command to detect the device (flashed with Arduino bootloader):

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 040: ID 2341:804d Arduino SA
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

An Arduino sketch is provided below as as example:

// on-board LEDs (used for TX/RX activity indication)
#define LED1 25 // PB03
#define LED2 26 // PA7
#define INTERVAL_MSEC (100)uint32_t ts; // used to save timestampvoid setup() {
SerialUSB.begin(115200);
while (!SerialUSB) {}
pinMode( LED1, OUTPUT );
pinMode( LED2, OUTPUT );
digitalWrite( LED1, HIGH ); // LED1 output high
digitalWrite( LED2, LOW ); // LED2 output low
ts = millis(); // get current timestamp (in msec)
SerialUSB.println("SAMD M0-Mini (Arduino-Zero Compatible)" );
}
void loop() {
if ( millis() - ts >= INTERVAL_MSEC ) {
ts += INTERVAL_MSEC;
digitalWrite( LED1, !digitalRead(LED1) );
digitalWrite( LED2, !digitalRead(LED2) );
}
}

Verify the demo sketch:

Upload the demo sketch:

Open the Arduino Serial Monitor to receive the incoming message from the Arduino board via the serial port (/dev/ttyACM0):

[>] Command-Line Tools for ST-Link/V2 Programmer

.

If you want to use ST-Link V2 USB dongle for flashing firmware to STM32 microcontrollers, you can install and use the stlink-tools software package.

1) Install the stlink-tools (v1.5.1) package:

$ sudo apt install stlink-tools

2) Connect the ST-Link/V2 USB Dongle to the USB port of the RPi.

Note that you have to connect the STM32 board with the ST-Link/V2 USB dongle using the SWD interface with four pins (+3.3V, SWDIO, SWCLK and GND pins).

Note that the target MCU board shown in the picture is the WeAct Studio STM32F411CEU6 board.

3) Run the following command line to detect the ST-Link/V2 device.

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 020: ID 0483:3748 STMicroelectronics ST-LINK/V2
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Download the udev rules files (*.rules) for ST-Link devices from: https://github.com/stlink-org/stlink/tree/develop/config/udev/rules.d/

Save the files to /etc/udev/rules.d/ and apply the rules:

$ sudo udevadm control --reload-rules
$ sudo udevadm trigger

[>] MicroPython Firmware Flashing for STM32

.

If you want to use MicroPython for STM32, the next step is to use the stlink-tools software and the ST-Link/V2 programmer for flashing the MicroPython firmware. In this example, the target microcontroller to be used is the STM32F411CEU6.

1) Detect the ST-Link/V2 programmer and the target MCU.

$ sudo st-info --probe
Found 1 stlink programmers
serial: 543f6a06503f56492959063f
openocd: "\x54\x3f\x6a\x06\x50\x3f\x56\x49\x29\x59\x06\x3f"
flash: 524288 (pagesize: 16384)
sram: 131072
chipid: 0x0431
descr: F4 device (low power) - stm32f411re

2) Check the size of on-chip Flash and SRAM inside the STM32F411CEU6 (512KB Flash, 128KB SRAM):

$ sudo st-info --flash
0x80000
$ sudo st-info --sram
0x20000

3) Erase the on-chip Flash memory of the STM32 device:

$ sudo st-flash erase
st-flash 1.5.1
2021-06-24T14:11:51 INFO common.c: Loading device parameters....
2021-06-24T14:11:51 INFO common.c: Device connected is: F4 device (low power) - stm32f411re, id 0x10006431
2021-06-24T14:11:51 INFO common.c: SRAM size: 0x20000 bytes (128 KiB), Flash: 0x80000 bytes (512 KiB) in pages of 16384 bytes
Mass erasing.......

4) Download MicroPython firmware for the STM32F411CEU6 (select the firmware file firmware_internal_rom_stm32f411_v1.14–7.hex) and flash the firmware to the target device.

# Convert the firmware file from .hex to .bin
$ cp ./firmware_internal_rom_stm32f411_v1.14-7.hex firmware.hex
$ arm-none-eabi-objcopy -I ihex ./firmware.hex \
-O binary ./firmware.bin
$ sudo st-flash write ./firmware.bin 0x8000000st-flash 1.5.1
2021-06-24T14:27:20 INFO common.c: Loading device parameters....
2021-06-24T14:27:20 INFO common.c: Device connected is: F4 device (low power) - stm32f411re, id 0x10006431
2021-06-24T14:27:20 INFO common.c: SRAM size: 0x20000 bytes (128 KiB), Flash: 0x80000 bytes (512 KiB) in pages of 16384 bytes
2021-06-24T14:27:20 INFO common.c: Attempting to write 457192 (0x6f9e8) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08060000 erasedEraseFlash - Sector:0x7 Size:0x20000
2021-06-24T14:27:30 INFO common.c: Finished erasing 8 pages of 131072 (0x20000) bytes
2021-06-24T14:27:30 INFO common.c: Starting Flash write for F2/F4/L4
2021-06-24T14:27:30 INFO flash_loader.c: Successfully loaded flash loader in sram
enabling 32-bit flash writes
size: 32768
size: 32768
size: 32768
size: 32768
size: 32768
size: 32768
size: 32768
size: 32768
size: 32768
size: 32768
size: 32768
size: 32768
size: 32768
size: 31208
2021-06-24T14:27:36 INFO common.c: Starting verification of write complete
2021-06-24T14:27:40 INFO common.c: Flash written and verified! jolly good!

5) Disconnect the ST-Link/V2 dongle and use a USB Type-C cable to connect the STM32 board to the RPi.

The MicroPython-STM32 device will appear as a new USB Mass Storage drive on the RPi.

6) Install Thonny IDE (Python-based)

You can install and use the Thonny IDE on the RPi for writing MicroPython code and uploading the script file to the MicroPython-STM32 device.

# Install Thonny IDE 
$ sudo apt install thonny
# Run the Thonny IDE
$ thonny &

Go to the menu “Run → Select Interpreter…” and then select “MicroPython (generic)” and the Virtual COM Port for the MicroPython device ( → /dev/ttyACM0).

You can edit the main.py script file in the MicroPython device and run the code in this file.

[>] Using STM32F411CEU6 for CMSIS-DAP

.

You can convert the WeAct Studio STM32F411CEU6 board into a low-cost CMSIS-DAP debug probe (SWD only, no JTAG support).

1) Download the CMSIS-DAP firmware for STM32F4x1, which is provided by WeActTc:

$ wget -c -q https://github.com/WeActTC/MiniSTM32F4x1/raw/master/SDK/CMSIS-DAP/CMSIS-DAP_WeActStudio.hex

2) Convert the firmware file from .hex to .bin:

$ cp CMSIS-DAP_WeActStudio.hex firmware.hex
$ arm-none-eabi-objcopy -I ihex firmware.hex -O binary firmware.bin

3) Flash the firmware to the STM32F411CEU6 device using the ST-Link/V2 programmer:

# Erase the flash first
$ sudo st-flash erase
# Write the firmware file to the target
$ sudo st-flash write firmware.bin 0x8000000
st-flash 1.5.1
2021-06-23T21:21:40 INFO common.c: Loading device parameters....
2021-06-23T21:21:40 INFO common.c: Device connected is: F4 device (low power) - stm32f411re, id 0x10006431
2021-06-23T21:21:40 INFO common.c: SRAM size: 0x20000 bytes (128 KiB), Flash: 0x80000 bytes (512 KiB) in pages of 16384 bytes
2021-06-23T21:21:40 INFO common.c: Attempting to write 35016 (0x88c8) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08008000 erasedEraseFlash - Sector:0x2 Size:0x4000
2021-06-23T21:21:41 INFO common.c: Finished erasing 3 pages of 16384 (0x4000) bytes
2021-06-23T21:21:41 INFO common.c: Starting Flash write for F2/F4/L4
2021-06-23T21:21:41 INFO flash_loader.c: Successfully loaded flash loader in sram
enabling 32-bit flash writes
size: 32768
size: 2248
2021-06-23T21:21:41 INFO common.c: Starting verification of write complete
2021-06-23T21:21:41 INFO common.c: Flash written and verified! jolly good!

4) Disconnect the ST-Link programmer from the RPi, connect the STM32F411CEU6 to the USB port of the RPi and run the following command line to detect the CMSIS-DAP device.

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 019: ID c251:f001 Keil Software, Inc.
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Note that the CMSIS-DAP firmware for STM32 which is provided by WeAct Studio is based on the ARM-Keil USB Stack (MDK Middleware).

Now, the CMSIS-DAP device is ready for use. You can use the OpenOCD tool to connect to the device.

$ export PATH="$PATH:/opt/xpack/xpack-openocd-0.11.0-1/bin/"$ openocd -f interface/cmsis-dap.cfg
xPack OpenOCD, aarch64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-16:47)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: FW Version = 2.0.0
Error: CMSIS-DAP: JTAG not supported

[>] The SEGGER J-Link Software

.

If you have a SEGGER debug probe (J-Link / J-Link OB / J-Link EDU Mini), you may want to install SEGGER’s J-Link Software and Documentation Pack (for ARM 64-bit).

First, open the following URL with the web browser and download the software. In this example, I selected the version 7.23b (2021–06–09):
https://www.segger.com/downloads/jlink/JLink_Linux_V723b_arm64.tgz

# Extract the .tgz file
$ tar vxf ./JLink_Linux_V723b_arm64.tgz
# move the JLink directory to /opt
$ sudo mv ./JLink_Linux_V723b_arm64 /opt/
$ sudo chmod a-w /opt/JLink_Linux_V723b_arm64
# Install the udev file for J-Link devices
$ cd /opt/JLink_Linux_V723b_arm64/
$ sudo cp ./99-jlink.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules
$ sudo udevadm trigger

Next, connect the SEGGER J-Link debug probe ( Vendor ID =1366, Product ID=0105 ) to the USB port of the RPi and run the following command line:

# Detect / list the SEGGER J-Link device (J-Link V9)
$ lsusb | grep SEGGER
Bus 001 Device 009: ID 1366:0105 SEGGER

Now, you can use the J-Link commands such as JLinkExe under the directory/opt/JLink_Linux_V723b_arm64/.

[>] The SEGGER Embedded Studio for ARM

.

If you have a J-Link debug probe, you can try the “SEGGER Embedded Studio for ARM” software. This software is free for non-commercial use” and is available for different OSes, including ARM 64-bit Linux OS (aarch64).

1) Download and install the software:

# Download SEGGER Embedded Studio for ARM / 64-bit ARM (~716MB)
# https://www.segger.com/downloads/embedded-studio/
$ wget -c "https://dl.segger.com/files/embedded-studio/Setup_EmbeddedStudio_ARM_v550a_linux_arm64.tar.gz"
# Extract the .tar.gz file
$ tar xfz ./Setup_EmbeddedStudio_ARM_v550a_linux_arm64.tar.gz
# Install the Embedded Studio to /opt/
$ cd arm_segger_embedded_studio_550a_linux_arm64/
$ sudo ./install_segger_embedded_studio

2) Click the Next button during the installation process:

Accept the Agreement before proceeding with the installation
Select the installation directory
Select to install J-Link udev rules file

3) Click the Next button to complete the installation process.

Note that the udev rules file for J-Link is located at /etc/udev/rules.d/99-jlink.rules.

4) After the installation, run the following command to start the SEGGER Embedded Studio IDE:

# Run the Embedded Studio 
$ /opt/segger_embedded_studio_for_arm_5.50a/bin/emStudio &

When you use the Embedded Studio IDE for the first time, the default demo project “Hello” (for a generic ARM Cortex-M3 CPU) is loaded automatically. You can compile / build the project and start debugging using the built-in ARM simulator.

Embedded Studio IDE and the “Hello” demo project
Project “Hello” Options — Code Generation
Debug Session using the Simulator

If you want to learn more about this software, please consult the manual (a PDF file → https://www.segger.com/downloads/embedded-studio/EmbeddedStudio_Manual)

[>] The VS Code IDE with PlatformIO Extension

.

Visual Studio Code (VS Code) is another open-source IDE that can be installed on the Raspberry Pi 64-bit. With an extension such as PlatformIO, it lets you write and build Arduino sketches.

Note that besides the Platform IO extension you can install and use the Visual Studio Code extension for Arduino provided by Microsoft.

Steps for installation are shown below:

1) Install the VS Code using the following command line:

$ sudo apt install code

2) Start the VS Code from the menu list: Programming → Visual Studio Code.

3) Search and Install VS Code Extension such as C/C++ provided by Microsoft.

4) Search and install the PlatformIO extension:

5) Go to “PIO Home” by clicking on the HOME icon on the bottom left side of the icon bar and create a new PlatformIO project for Arduino (Click on “+New Project”).

6) Complete all steps in the Project Wizard: specify the project name, select the target Arduino board (e.g. Arduino Uno) and select the framework (Arduino).

This project (named “blink”) requires the atmelavr platform which will be automatically downloaded and installed under ~/.platformio/platforms.

$ tree -L 2 ~/.platformio/platforms//home/pi/.platformio/platforms/
└── atmelavr
├── boards
├── builder
├── examples
├── LICENSE
├── platform.json
├── platform.py
├── __pycache__
└── README.md
5 directories, 4 files

Save the current workspace: “File → Save Workspace As …” and specify the workspace name (e.g. uno.code-workspace).

You can view the project directory by running the following command:

$ tree -a -L 4 ~/Documents/PlatformIO/Projects/home/pi/Documents/PlatformIO/Projects
└── blink
├── .gitignore
├── include
│ └── README
├── lib
│ └── README
├── .pio
│ └── build
│ ├── project.checksum
│ ├── uno
│ └── uno.code-workspace
├── platformio.ini
├── src
│ └── main.cpp
├── test
│ └── README
└── .vscode
├── c_cpp_properties.json
├── extensions.json
└── launch.json
9 directories, 11 files

7) Write the demo source code (“LED Blink”) in the main.cpp file and build the project.

#include <Arduino.h>#define LED_PIN  LED_BUILTINvoid setup() {
pinMode( LED_PIN, OUTPUT );
}
void loop() {
digitalWrite( LED_PIN, !digitalRead( LED_PIN) );
delay(500);
}

Now, you have successfully built the Arduino demo project using the VS Code + PlatformIO extension.

If an Arduino Uno board is available to you, you can upload the .hex to the target board.

It is recommended to download and install the udev rules file provided by PlatformIO: 99-platformio-udev.rules.

$ wget -c https://github.com/platformio/platformio-core/raw/develop/scripts/99-platformio-udev.rules
$ sudo mv 99-platformio-udev.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules
$ sudo udevadm trigger

[>] The VS Code IDE with Arduino Extension

.

As mentioned before, the Visual Studio Code extension for Arduino can also be used. However, the Arduino IDE or the Arduino CLI is required to be already installed.

1) Open the VS Code and search for the extension “Arduino” and click the button “Install”.

You can press F1 or Ctrl + Shift + P to open command palette, select Install Extension and type vscode-arduino.

After the installation, this extension provides several commands in the Command Palette (to see possible commands: press F1 or Ctrl + Shift + P).

2) Configure the Arduino extension by clicking the menu “File → Settings” and then click the “User” Tab: “Extensions” → “Arduino Configuration…”

3) Edit the .vscode/settings.json file, save the change and restart the VS Code.

You have to specify the correct path (arduino.path) to the installed Arduino IDE software in your system.

{
"workbench.colorTheme": "Default Dark+",
"arduino.path": "/opt/arduino-1.8.15/",
"arduino.defaultBaudRate": 115200,
"arduino.additionalUrls": ""
}

4) Open folder for creating a new Arduino sketch (e.g. uno_led_blink).

5) Press F1 and run the task “Arduino: initialize”, create a new Arduino sketch file (.ino) and choose the Arduino board (e.g. Arduino Uno).

You can also edit the setting file (.vscode/arduino.json) for the current Arduino sketch:

{
"sketch": "uno_led_blink.ino",
"board": "arduino:avr:uno",
"output": "./build",
"port": "/dev/ttyACM0",
"intelliSenseGen": "global"
}

Now you can verify and upload the sketch to the Uno board (chosen as the target board, connected to the /dev/ttyACM0 port):

Update: 2021–06–30

--

--