Construction of Cortex-M development environment for TOPPERS using Raspberry Pi

Introduction

Previously an article on building a ** TOPPERS / ASP ** development environment using WindowsPC + VirtualBox + Linux "** TOPPERS / ASP Build and run ** "," ** TOPPERS / ASP (2020-03-10 version) Build and run ** ". With this method, it is necessary to install VirtualBox on a Windows PC, and installation of arbitrary applications is restricted on company-supplied PCs, etc. Since Linux runs on VirtualBox, there is a problem that the load on the Windows PC such as CPU power, memory, and HDD capacity increases. For this reason, we plan to build a development environment for TOPPERS / ASP Cortex-M on Raspberry Pi, which is thought to have a large number of users and owners, so that development can be performed without imposing a load on the Windows PC, and use it for development. I did. In addition, the Raspberry Pi is a very small microcomputer board that is easy to carry and install, and because it uses a micro SD card as a boot and operation disk, it is easy to lend and borrow the environment and copy it, so it is used by many people. I wondered if I could get it.

Building a Linux environment

Linux installation

Linux for Raspberry Pi has multiple SD card images published on the Internet, but the new version of ARM's cross-toolchain, which will be explained later, is only available for 64-bit environments ** for ARM64 ** I decided to use ** Ubuntu 20.04.1 LTS **. (Latest version as of September 30, 2020) For this reason, the Raspberry Pi used requires Raspberry Pi 3, Raspberry Pi 3+, and Raspberry Pi 4.

Download the SD card image from "Ubuntu 20.04.1 LTS" "Download 64-bit" on the download page below. Since you can download the xz format file, write the image file created by expanding it to the micro SD card using image writing software.

** 64bit Ubuntu 20.04.1 LTS for Raspberry Pi **  https://ubuntu.com/download/raspberry-pi  https://ubuntu.com/download/raspberry-pi/thank-you?version=20.04.1&architecture=arm64+raspi

network settings

In ** ubuntu 20.04 **, you can get the IP address of eth0 of the wired LAN by DHCP. You can communicate on the network by connecting the LAN cable in the network environment where the DHCP server is operating. Also, by adding a configuration file under ** / etc / netplan ** and defining the IP address etc., it is possible to operate with a fixed IP address. Below is the configuration file I use in my home environment.

/etc/netplan/99_config.yaml


network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: false
      dhcp6: false
      addresses: [192.168.0.140/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [192.168.0.1, 8.8.8.8, 8.8.4.4]

Installation of additional middleware

Once you are able to communicate over the network, use the "** apt-get install " command to download and install the following additional middleware from the Internet. Before "apt-get install", please update the download information to the latest information with the " apt-get update **" command.

net-tools
g++
libboost-all-dev
libxerces-c-dev
make
minicom
samba

Building a cross toolchain

Download a toolchain such as a cross-compiler from the ** GNU Arm Embedded Toolchain Downloads ** page and unpack it on your Raspberry Pi. This time, I used the toolchain for ** GCC10 , but there is no problem if you download and use the stable version " 9-2020-q2-update June 30, 2020 **". Download ** Linux AArch64 Tarball **.

GNU Arm Embedded Toolchain: 10-2020-q2-preview June 29, 2020 gcc-arm-none-eabi-10-2020-q2-preview-aarch64-linux.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q2/gcc-arm-none-eabi-10-2020-q2-preview-aarch64-linux.tar.bz2?revision=a7134e5c-fad8-490c-a62b-9200acca15ef&la=en&hash=12954B763712885C1DDE3318D10DF96B1606463A

After downloading the tar.bz2 format file, extract it to the installation directory specified by "-C" with the tar command. The following is an example of the command to be expanded under ** / home / ubuntu / bin **.

mkdir ~/bin
tar xjf gcc-arm-none-eabi-10-2020-q2-preview-aarch64-linux.tar.bz2 -C ~/bin

To use the toolchain expanded this time, set the path of the executable file in the environment variable PATH before building TOPPERS / ASP. In my home environment, I added the following definition to "~ / .bashrc" so that it can be used anytime after logging in.

export PATH=~/bin/gcc-arm-none-eabi-10-2020-q2-preview/bin:$PATH

Configurator change / build

Build the configurator using Configurator Release 1.9.6 to enable the TOPPERS / ASP kernel build. However, due to the following notes on the configurator page, it was not possible to build as downloaded.

Due to a current problem with the boost library for 64-bit Linux
Cfg built on 64-bit Linux does not work properly.
When using cfg on 64bit Linux, for 32bit Linux below
Use binaries or build from source on 32bit Linux
Use statically linked binaries.

In the article I wrote earlier, I built a development environment using 32-bit Linux to avoid this problem. This time, we have included a fix to avoid this problem.

Configurator Release 1.9.6 https://www.toppers.jp/download.cgi/cfg-1.9.6.tar.gz

First, download the following files from the configurator page and place them in any directory. In the following explanation, command input etc. will be described assuming that it is placed in the following directory.

/home/ubuntu/toppers

● Source deployment Extract the downloaded tar.gz file. Extracting with the following command will generate a cfg directory, and the source files etc. will be expanded under it.

tar zxf cfg-1.9.6.tar.gz

● Source deployment Change to the cfg directory.

cd cfg

● Addition of header file for libboost When building the configurator, it stops with an error due to insufficient include of the header file, so add the include definition to the toppers / text.hpp file and toppers / cpp.hpp file as follows.

toppers/text.hpp


 54 #include "toppers/text_line.hpp"
 55 #include "toppers/misc.hpp"
 56 #include <boost/next_prior.hpp>  /*※ add to*/
 57 #include <boost/utility.hpp>
 58 #include <boost/iterator/iterator_facade.hpp>

toppers/cpp.hpp


 44 #include "toppers/codeset.hpp"
 45 #include "toppers/diagnostics.hpp"
 46 #include <boost/next_prior.hpp>  /*※ add to*/
 47 #include <boost/utility.hpp>
 48 #include <boost/filesystem/path.hpp>

● Configuration execution Make pre-build environment settings for the configurator. However, since the configure script immediately after expansion contains "0x0d" in the line feed code, an error will occur as it is. Therefore, use the following command to delete unnecessary code.

mv configure configure.org
tr -d '\r' < configure.org > configure
chmod u+x configure

After correction, execute the configuration with the following command.

./configure --with-libraries=/usr/lib/aarch64-linux-gnu

After successful execution of the configure script, build the configurator with the following command. It takes less than 20 minutes on Raspberry Pi 3.

make OPTIONS=-std=c++11

If the cfg / cfg command is completed, it is successful.

cfg/cfg -v

TOPPERS Kernel Configurator version 1.9.6

ASP kernel change / configuration race

TOPPERS / ASP kernel target independent part package ** asp-1.9.3.tar.gz ** and ARM Cortex-M4 architecture / GCC dependent part package ** asp_arch_arm_m4_gcc-1.9.6.tar.gz ** ** / Download to the home / ubuntu / toppers ** directory and build the ASP kernel.

● Source deployment Extract the downloaded tar.gz file. If you expand it with the following command, the asp directory will be created and the source files etc. will be expanded under it.

cd /home/ubuntu/toppers
tar xzf asp-1.9.3.tar.gz
tar xzf asp_arch_arm_m4_gcc-1.9.6.tar.gz

● Copy of configurator Asp copies the build and created configurator to: You can create and copy the required directories with the following command.

mkdir -p  asp/cfg/cfg
cp  cfg/cfg/cfg  asp/cfg/cfg

Execute the following command, and when the version information is output, the copy is successful.

asp/cfg/cfg/cfg -v

TOPPERS Kernel Configurator version 1.9.6

● Avoiding configuration errors In the deployed ASP kernel, "** PROVIDE () **" used in the linker script used at kernel build in GNU Arm Embedded Toolchain GCC7 or later does not work as intended and is always described as "" ** hardware_init_hook = 0 ** "is enabled and the hardware_init_hook function address ** always generates a binary at address 0x0 **. This will cause the ASP kernel to jump to address 0x0 when run on the board and ** repeat the reset **. So comment out the code for hardware_init_hook as follows: The following is a modification of the linker script for stm32f401nucleo_gcc.

asp/target/stm32f401nucleo_gcc/stm32f4xx_rom.ld

 10 PROVIDE(hardware_init_hook = 0);
 11 PROVIDE(software_init_hook = 0);
 12 PROVIDE(software_term_hook = 0);
 13 STARTUP(start.o)

 10 /* PROVIDE(hardware_init_hook = 0); */
 11 PROVIDE(software_init_hook = 0);
 12 PROVIDE(software_term_hook = 0);
 13 STARTUP(start.o)

In addition, since an error will occur in the generation of cfg1_out during build as it is, add the alternative processing of "PROVIDE (hardware_init_hook = 0)" to start.S. Add the following processing to the end line of start.S as shown below.

asp/arch/arm_m_gcc/common/start.S


.weak  hardware_init_hook
        bx  lr

● ASP kernel configuration Sean Configure the ASP kernel in the directory where you build your application. This time, target the STM32F401 Nucleo-64 board and build the application build environment in the / home / ubuntu / toppers / f401 / obj directory. Create the f401 / obj directory with the following command.

cd /home/ubuntu/toppers
mkdir -p f401/obj

Use the following command to change to the f401 / obj directory and execute the configuration.

cd f401/obj
../../asp/configure -T stm32f401nucleo_gcc -dROM

It is successful when the following files are generated.

-rw-rw-r-- 1 ubuntu ubuntu 15335 Aug 30 18:22 Makefile
-rw-rw-r-- 1 ubuntu ubuntu 15652 Aug 30 18:22 sample1.c
-rw-rw-r-- 1 ubuntu ubuntu   918 Aug 30 18:22 sample1.cfg
-rw-rw-r-- 1 ubuntu ubuntu  3246 Aug 30 18:22 sample1.h

Build application

The Nucleo board can be seen as a disk drive by connecting it to your PC via USB, and you can write the program by copying the binary code generated by building to this directory. Add the .bin file generation description to the following part of the Makefile so that the binary code will be generated when building the application.

Makefile

327 $(OBJFILE): $(APPL_CFG) kernel_cfg.timestamp $(ALL_OBJS) $(LIBS_DEP)
328         $(LINK) $(CFLAGS) $(LDFLAGS) -o $(OBJFILE) $(START_OBJS) \
329                         $(APPL_OBJS) $(SYSSVC_OBJS) $(CFG_OBJS) $(ALL_LIBS) $(END_OBJS)
330         $(NM) -n $(OBJFILE) > $(OBJNAME).syms
331         $(OBJCOPY) -O srec -S $(OBJFILE) $(OBJNAME).srec
332         $(CFG) --pass 3 --kernel asp $(INCLUDES) \

327 $(OBJFILE): $(APPL_CFG) kernel_cfg.timestamp $(ALL_OBJS) $(LIBS_DEP)
328         $(LINK) $(CFLAGS) $(LDFLAGS) -o $(OBJFILE) $(START_OBJS) \
329                         $(APPL_OBJS) $(SYSSVC_OBJS) $(CFG_OBJS) $(ALL_LIBS) $(END_OBJS)
330         $(NM) -n $(OBJFILE) > $(OBJNAME).syms
331         $(OBJCOPY) -O srec -S $(OBJFILE) $(OBJNAME).srec
**332         $(OBJCOPY) -O binary -S $(OBJFILE) $(OBJNAME).bin ← ★ added**
333         $(CFG) --pass 3 --kernel asp $(INCLUDES) \

After adding, you can build the application by running make in the f401 / obj directory.

cd f401/obj
make

If the following files are generated, the build is successful.

-rwxrwxr-x 1 ubuntu ubuntu 363656 Aug 30 18:35 asp*
-rwxrwxr-x 1 ubuntu ubuntu  28442 Aug 30 18:35 asp.bin*
-rwxrwxr-x 1 ubuntu ubuntu  85392 Aug 30 18:35 asp.srec*
-rw-rw-r-- 1 ubuntu ubuntu   8109 Aug 30 18:35 asp.syms

When you copy asp.bin to the STM32F401 Nucleo-64 board and execute the program, the following message is output to the virtual COM port of the STM32F401 Nucleo-64 board.

clip1.jpg

● Copy the asp.bin file on your Windows PC By installing and setting Samba on Raspberry Pi, you can write the asp.bin file on Raspberry Pi to STM32F401-Nucleo by dragging and dropping on Explorer of Windows PC.

clip2.jpg

Operational configuration

In development using Raspberry Pi, in addition to the method of rewriting the binary file generated on Raspberry Pi to the target board via Windows PC, it is also possible to operate the Raspberry Pi alone by connecting the monitor, keyboard and target board to Raspberry Pi. Since the STM32F401-Nucleo board can be accessed from Linux as / dev / ttyACM of the virtual COM port and / dev / sda1 of the mass storage via USB connection, the syslog () output after execution from writing to the target board is also operated by Raspberry Pi alone. can.

● Operational configuration via Windows PC clip3.jpg

● Operational configuration of Raspberry Pi alone clip4.jpg

at the end

If you have a Raspberry Pi 3, Raspberry Pi 3+, or Raspberry Pi 4, why not try building the environment and building the program by following the steps described here. There are many articles and information about using the Raspberry Pi itself as a board or controller for electronic work, but I think that you will understand that it can be sufficiently used as a development environment like this time.

Recommended Posts

Construction of Cortex-M development environment for TOPPERS using Raspberry Pi
Construction of development environment for Choreonoid class
[For beginners] Django -Development environment construction-
Python development environment for macOS using venv 2016
Automatic launch of Raspberry Pi programs using Systemd
Build a Python development environment on Raspberry Pi
Build an OpenCV4 environment on Raspberry Pi using Poetry
Memorandum of understanding for environment construction of AutoML library PyCaret
Indoor monitoring using Raspberry Pi
Development environment suitable for ArcPy
Django development environment construction memo
Construction of Python local development environment Part 2 (pyenv-virtualenv, pip usage)
Cross-compiling for Raspberry Pi Zero on Debian-Try using shared libraries
[Memo] Construction of cygwin environment
Python environment construction For Mac
Python3 environment construction (for beginners)
[MEMO] [Development environment construction] Python
Memo of Linux environment construction using VirtualBox + Vagrant on Windows 10
[For organizing] Python development environment
django project development environment construction
Environment construction of python2 & 3 (OSX)
Distributed environment construction with Raspberry PI series (7: tftp route setting and startup test for each Raspberry Pi)
[MEMO] [Development environment construction] wine
[Linux] [Initial Settings] Table of Contents for Development Environment Setup
Ansible environment construction For Mac
Build a local development environment for Lambda + Python using Serverless Framework
Construction of Python local development environment Part 1 (pyenv, pyenv-virtualenv, pip installation)
Using TensorFlow in the cloud integrated development environment Cloud9 ~ Basics of usage ~
Periodically log the value of Omron environment sensor with Raspberry Pi
Environment construction of python and opencv
USB over ethernet using Raspberry pi
Start of self-made OS 1. Environment construction
[Django] Memorandum of environment construction procedure
Raspberry pi initial setting (for myself)
[Python3] Development environment construction << Windows edition >>
Try using ArUco on Raspberry Pi
Python development environment options for May 2020
Emacs settings for Python development environment
Environment construction of python3.8 on mac
Python3 TensorFlow for Mac environment construction
Emacs Python development environment construction memo
Ubuntu Desktop 20.04 development environment construction memo
Environment construction of "Tello_Video" on Ubuntu
Python3.6 environment construction (using Win environment Anaconda)
Learning history for participating in team application development in Python ~ Supplement of basic items and construction of jupyterLab environment ~
Procedure from AWS CDK (Python) development to AWS resource construction * For beginners of development
Initial settings for using GrovePi + starter kit and camera on Raspberry Pi
Logging the value of Omron environment sensor with Raspberry Pi (USB type)
Easy-to-understand explanation of Python Web application (Django) even for beginners (1) [Environment construction]
Mac OS X Mavericks 10.9.5 Development environment construction
Addition of local development environment on MacOS
Python project environment construction procedure (for windows)
Detect "brightness" using python on Raspberry Pi 3!
Construction of recommendation system using word-of-mouth doc2vec
Make Raspberry Pi speak Japanese using OpenJtalk
Try fishing for smelt with Raspberry Pi
Python3 + venv + VSCode + macOS development environment construction
About the development environment you are using
Run servomotor on Raspberry Pi 3 using python
Prepare the development environment for keyhac for Mac
Mac OS X Yosemite 10.10 Development environment construction