User:Brendlefly62/Radxa x4 N100 sbc with RP2040/Use the RP2040 Microcontroller

From Gentoo Wiki
Jump to:navigation Jump to:search

Using the RP2040 Microcontroller[1][2][3]

Use of the RP2040 requires a toolchain appropriate for use with the rp2040's coretex-M0 cpu and the raspberry pi foundation's software development kit for the pico-sdk. The VSCode IDE can also be used to develop code for this device but is beyond the scope of this project. Documented below, are procedures that can be used to build the appropriate toolchain with crossdev, download and use the sdk to modify and compile the sdk's standard example programs and flash them to the RP2040 on this sbc.

These references may be useful

Crossdev[4]

(see also Gentoo Wiki Crossdev) A toolchain is needed for arm-none-eabi, but the sdk will require a g++ compiler (which is disabled by default), so first initialize a crossdev target for arm-non-eabi, then edit the USE flags in it's package.use file, and finally recompile its gcc

Get crossdev and make a repo for its cross-toolchains

root #emerge -av crossdev
root #eselect repository add crossdev git https://github.com/alphallc/crossdev/

alphallc's crossdev overlay is empty, but this process will create a tree in /var/db/repos/crossdev

Use crossdev to create a toolchain for arm-none-eabi

If normally using distcc and/or ccache, it maybe necessary to temporarily disable these by removing distcc/ccache locations from PATH and from FEATURES. Here, the alias "nodist_path" does the former, and the command below does the latter explicity, while "-S" builds the latest stable tools--

root #nodist_path
root #FEATURES="${FEATURES} -distcc" crossdev -S --target arm-none-eabi

Now enable c++ in package.use --

root #nano /etc/portage/package.use/cross-arm-none-eabi
Important
In the default file, the cross-arm-none-eabi/gcc line contains both a "cxx" and later a "-cxx" flag which overrides its predecessor. Remove the "-cxx" flag
FILE /etc/portage/package.use/cross-arm-none-eabi
cross-arm-none-eabi/binutils multilib
#cross-arm-none-eabi/gcc cxx ... -cxx ...
cross-arm-none-eabi/gcc cxx -openmp -fortran -hardened -default-stack-clash-protection -ssp -sanitize -vtv -selinux -d -objc -objc++ -objc-gc -vtv -fortran -go -jit -openmp -sanitize -zstd -zlib multilib
cross-arm-none-eabi/newlib -selinux -libraries multilib

Now recompile the arm-none-eabi gcc --

root #emerge -av1 cross-arm-none-eabi/gcc

Raspberry Pi pico-sdk[5][6][7]

user $cd pico-sdk/
user $git submodule update --init

Raspberry Pi pico-examples[8]

Clone the Raspberry Pi foundations's repository of example programs for the pico (RP2040 microcontroller) --

user $git clone https://github.com/raspberrypi/pico-examples.git --branch master

Now build the example programs using the cross-toolchain and sdk --

user $mkdir build; cd build
user $export PICO_SDK_PATH=/home/joe/pico-sdk/
user $cmake .. && make -j$(nproc)

For demonstration in this project, verify that this produced a blink program --

user $find ./ -iname 'blink.uf2'
./blink/blink.uf2

Create a new blink program[9][10]

To create a new Blink program, consult Write a new blink program

Validate serial and PWM with a new pwm fan control program[11]

To write a new program to validate both UART serial communication and PWM functionality, consult Validate serial and PWM with a new pwm fan control program

Referemces