User:Brendlefly62/Radxa x4 N100 sbc with RP2040/Use the RP2040 Microcontroller
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
- Gentoo forums post regarding successful use of rpi pico and pico-sdk
- Gentoo Forums discussion of rpi pico (rp2040 )
- radxa documentation of c sdk examples (incl blink.c and Temperature.py)
- radxa documentation of procedures (hw & sw) to "reboot" the rp2040
- github repository for pico-sdk
- github repository for pico-examples
- Gentoo wiki for ARM (crossdev, Enable_hardfloat_support, etc.)
- Raspberry Pi rp2040 datasheet (pdf)
- Raspberry Pi pico data sheet (pdf)
- youTube video showing how it is done on ubuntu
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
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
/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 $
git clone https://github.com/raspberrypi/pico-sdk.git
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
- ↑ https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf
- ↑ https://datasheets.raspberrypi.org/pico/getting-started-with-pico.pdf
- ↑ https://www.youtube.com/watch?v=rUkpIG_3D9k
- ↑ ARM
- ↑ https://github.com/raspberrypi/pico-sdk#quick-start-your-own-project
- ↑ https://forums.gentoo.org/viewtopic-t-1134474-start-0.html
- ↑ https://forums.gentoo.org/viewtopic-p-8734951.html?sid=e340ef1c346252d518007863854b9ba6
- ↑ https://github.com/raspberrypi/pico-examples
- ↑ https://docs.radxa.com/en/x/x4/software/c_sdk_examples
- ↑ https://docs.radxa.com/en/x/x4/software/flash?flash_way=Software
- ↑ https://docs.radxa.com/en/x/x4/software/c_sdk_examples?type=PWM