Ratio Packets: Part 3 Setting up a rpi-2040 Compiler / VS Code Setup.

Ratio Packets: Part 3 Setting up a rpi-2040 Compiler / VS Code Setup.

Ratio Packets: Part 3 Setting up a rpi-2040 Compiler / VS Code Setup.

In the previous article we could see some of the issues of trying to directly handle and bit toggle a GPIO pin on the Raspberry Pi.  Two issues occurred:

  • The Raspberry Pi OS is not a RTOS and there was some instances where packet toggling interruption occurred. You can see in the screen shot some bits were missed that were programmed to a frequency of 1.116 Mhz for standard bits and 657 Khz for a king bit.
  • The Raspberry Pi GPIO addresses change at run-time every time a device accesses them -  and some handling is required in order to decipher the current address to drive or clear a pin (here)

One [can] program a RPI-2040 in python as it holds a direct interpreter.  A excellent application named 'thonny' can do this.  

sudo apt install thonny

It can automatically connect to the RPI and upload the code.

However since python is interpretated and approximately 25x slower for now we will code this in C.

We can base the information off this excellent guide here - and install the prerequisites.

mkdir ~/raspberry-pi-pico
cd ~/raspberry-pi-pico
wget https://raw.githubusercontent.com/raspberrypi/pico-setup/master/pico_setup.sh
chmod +x pico_setup.sh

This does a lot on the raspberry pi 4 and took about 5-10 minutes depending on your clock:

Now setup and add openocd

cd ~/raspberry-pi-pico/pico
git clone https://github.com/raspberrypi/openocd.git --branch rp2040 --depth=1
cd openocd
./configure --enable-picoprobe --enable-ftdi --enable-sysfsgpio --enable-bcm2835gpio
sudo make install​

Once this was all finally completed you need a 'sudo reboot'  and vscode wants only a user access.

Adding a folder to the current workspace - then adding main.c:

Considering that this is all running onboard a raspberry pi 4 with only 2GB of RAM and being accessed remotely via a ssh -X X11 connection it all actually works fairly seamlessly.

We build the main.c and CMakeLists.txt files.  When you select to run and debug it - VSCode will give you several options:

There was a number of issues fixing pathing around the #include "pico/stdio.h" and include paths but was able to get it to work utilizing 'quick fix' suggestion:

None of this was working so we stepped back and reinstalled the rpi library from it's scratch at: https://github.com/pimoroni/pimoroni-pico/blob/main/setting-up-the-pico-sdk.md

This will take a long time to compile on the raspberry pi:

To be continued:

Linux Rocks Every Day