Description how to set up an Ada development environment for Raspberry Pico or similar rp2040/rp2350 boards
create separate pages for Windows and Linux or do it in parallel?
flowchart LR
id1[Alire]
id2[Build Essentials]
id3[OpenOCD]
id4[Toolchain]
id5[IDE]
id1 --> id2 --> id3 --> id4 --> id5
Alire is the Ada package manager. It manages dependancies between libraries and tools. Download the latest version from their Github repository.
The installer creates a desktop icon that starts a Powershell. The PATH is automatically extended for the alr binary.
The downloaded archive essentially contains the only file bin/alr. You better extract it being in your home directory. The installation path ~/bin/ is already in your PATH most probably.
You need several other tools and libraries besides a compiler and an editor like make, git for version control, unzip, libusb, etc.
On the first invocation of alr it proposes to download Msys2 and associated tools for you. If you already have Msys2 you can configure Alire to use the preinstalled Msys2. In that case I recommend to add the Alire installation directory to you PATH, e.g. in your .profile.
Linux already has all the necessary tools. In case you are missing something install it with your Linux package manager.
$ apt install build-essential gitThe standard way to install your binaries on the Pico board is to copy an uf2 file to it. I highly recommend, however, to use a debugger via the Serial Wire Debug (SWD) interface. You first need the software OpenOCD and a second Pico that works as a debug probe. The standard package managers for Windows and Linux provide at least version 0.12 that works with the rp2040 chips. Second, you need the GNU debugging program gdb.
The stock OpenOCD distributions V0.12 (Windows and Linux as well) has a nasty bug in that stops timers. See here. A solution is the upstrewam sources and in the fork of the Raspberry Foundation. Perhaps there is also a version of OpenOCD that gets installed through the VSCode extension that does not show the problem, to be confirmed.
pacman -S mingw-w64-ucrt-x86_64-openocd
pacman -S mingw-w64-ucrt-x86_64-gdbAs explained in the official guide, you need to make sure that the right USB drivers are being used. Download Zadig from http://zadig.akeo.ie and run it. First select Options / List all devices from the menu. Then you can chose Picoprobe (Interface 2) and make sure it's using the libusb-win32 driver.
apt install openocd gdbYou can find further information about OpenOCD on Debian at their wiki.
See the setup guide on how to install software and how to wire the second Pico board.
Run the command
alr toolchain --select
and select the line gnat_arm_elf. If you are asked to select gprbuild pick the newest one.
(this is taken almost verbatim from Jeremy Grosser's site).
Use Alire to create a skeleton project and add a dependency on pico_bsp.
alr init --bin hello_pico
cd hello_pico
alr with pico_bsp
Next, edit hello_pico.gpr to import pico_bsp and add the Target, Runtime, and Linker configuration near the top.
with "config/hello_pico_config.gpr";
with "pico_bsp.gpr"; -- < add
project Hello_Pico is
for Target use "arm-eabi"; -- < add
for Runtime ("Ada") use "light-cortex-m0p"; -- < add
package Linker is -- < add
for Switches ("Ada") use Pico_BSP.Linker_Switches; -- < add
end Linker; -- < add
for Source_Dirs use ("src/", "config/");
Build the project.
alr build --development
If the build was successful, there will be an ELF binary in ./bin/hello_pico.
You first have to upload the generated elf file to the target board. Connect the Pico_Probe via USB to your computer and the SWD wires from the Pico_Probe to the corresponding pins on your target Pico. You can then upload the program using OpenOCD.
openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -s tcl -c "adapter speed 5000" -c "program bin/hello_pico verify reset exit"
openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -s tcl -c "set USE_CORE 0" -c "adapter speed 5000"
set USE_CORE 0 should circumvent a problem when debugging timers
adapter speed 5000 increases communication speed to the target
Another workaround is to set timer_hw->dbgpause (what is that in Ada?) to 0 in your startup code.
