Skip to content

Repository files navigation

Rapid Pico C V1.0

ezgif-71ae7d307d8e3e63

This is a "Raspberry Pi Pico 2" C/C++ (and assembly) starter project (in/out) for ARM or RISC-V, optimized for iteration time and convenience. This is much better than the standard method (unplug cable, plug in cable while pressing button, drag and drop .uf2 file). The setup work is still improvable, feedback is welcome.

Key lines for best iteration (1 sec build, ~4sec for upload):

  ./build.sh
  picotool load -x build/picow_blink.elf
  putty -serial /dev/ttyACM0 -sercfg 115200,8,n,1,N

or better use alias (todo: put in a new setup.sh)

  alias b="./build.sh"
  alias u="picotool load -x build/picow_blink.elf"
  alias p="putty -serial /dev/ttyACM0 -sercfg 115200,8,n,1,N"
  b
  u
  p
  u && sleep 2 && p

You can use the host PC keyboard and see the output in a window (latest code logs CPU): puTTY

Why Raspberry Pi Pico 2 W

The ~7$ hardware features a (2-core) and RISC-V(2-core) at 150 MHz, 520KB SRAM and 4MB Flash memory. It's tiny and low power which means you can use USB or a battery and no need for a fan. You can get the Wifi + Bluetooth variant (W) which I did but mind the code to address the LED needs minor adjustment. You start programming with Python and play with cheap attachable custom hardware (displays, sound in/out, buttons, motors, sensors). If you need more performance you can program in C/C++ or assembly. No OS (it's a Micro controller, no Micro processor) or other services make the performance very stable. Simple coprocessors can be used for custom tasks e.g. output 15bit color to a VG display. The older Pico 1 specs are a bit lower but suitable for most use cases.

Hardware and Software requirements

IMG_9676
  • USB data cable (USB power cable is not enough)
  • Raspberry Pi Pico 2 W (RP2350, Wifi)
  • Tested on Ubuntu x64, should be easy to adapt to other OS
  • Text editor or IDE e.g. VSCode, Notepad++ (yes, that is an option on Ubuntu)

How to the code locally

  • Get the code from the terminal is one option (into Documents/code/RapidPicoC)
  cd ~/Documents
  mkdir code
  cd code
  git clone git@github.com:Kosmokleaner/RapidPicoC.git
  cd RapidPicoC
  chmod +x clean.sh
  chmod +x build.sh

C code explained

  • On board LED blinking, keyboard input and text output
  // init
  stdio_init_all();
  if (cyw43_arch_init()) { printf("Wi-Fi init failed"); return -1; }

  while (true)
  {
     // wifi LED, change for non W model
     cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, cnt % 2);
     sleep_ms(250);
     // connect with PuTTY for keyboard input
     int c = getchar_timeout_us(0);
     if (c == 27)
         reset_usb_boot(0, 0); // reboot
     cnt++;
     // connect with PuTTY for output
     printf("cnt:%d\n", cnt); 
  }

Build

  • compile and link
  ./build.sh
  • for profiling the build time
  time ./build.sh

Method 1: Simple upload (physical, needed the first time): bootsel

  • If needed, unplug Raspberry Pi Pico from USB (Pico side is fragile connection, better to other side)
  • While pushing button on Pico, plug in USB data cable (to put the device into bootsel mode)
  • A new device should appear in "Files", if not, the cable might not be a "data" cable
  • Find the output file in build/.uf2
  • Drag and drop the file to the device

Method 2: Better itertion time for upload: using picotool

We need "picotool" and I found prebuilt versions but none had the required USB support compiled in.

  • If needed / once
  cd ~/Documents/code
  git clone --recursive https://github.com/raspberrypi/pico-sdk.git
  export PICO_SDK_PATH=~/Documents/code/pico-sdk
  sudo apt install build-essential cmake pkg-config libusb-1.0-0-dev
  cd ~/Documents
  mkdir code
  cd code
  git clone https://github.com/raspberrypi/picotool.git
  cd picotool
  mkdir build
  cd build
  cmake -DCMAKE_BUILD_TYPE=Release ..
  cmake --build . -j$(nproc)
  # to not have to use sudo and require password
  cd ../udev
  sudo cp 60-picotool.rules /etc/udev/rules.d/ 
  sudo udevadm control --reload

You should be able to run the picotool from the build folder. You can reference it like this:

  ~/Documents/code/picotool/build/picotool

For more convenience you can make a symbolic link (export does not work with sudo and path adds unwanted files)

  sudo ln -s ~/Documents/code/picotool/build/picotool /usr/local/bin/picotool
  • upload (works only if in bootsel mode, needs sudo or 60-picotool.rules applied)
  picotool load -x build/picow_blink.elf

To quickly get back into bootself mode use Putty and press ESC, see C code:

  reset_usb_boot(0, 0);

Keyboard input and text output

  • If needed, install Putty SSH client
  putty -serial /dev/ttyACM0 -sercfg 115200,8,n,1,N
  • to find connection settings, likely: /dev/ttyS0 115200
  sudo dmesg | grep tty
  • Start Putty from terminal
  putty -serial /dev/ttyACM0 -sercfg 115200,8,n,1,N
  • Or start Putty from terminal from Apps
puttyUI
  • The app has USB stdin/stdout support because of the following lines in CMakeList.txt
  pico_enable_stdio_usb(picow_blink 1)
  pico_enable_stdio_uart(picow_blink 0)

How to adapt for RISC-V

The Raspberry Pico 2 has a ARM and a RISC-V CPU, you can choose which one to target with compiler settings.

This line in the compiler log shows the target CPU architecture:

  Pico Platform (PICO_PLATFORM) is 'rp2350-arm-s'.

You can change it in CMakeLists.txt:

# "ARM" or "RISCV"
set(MY_CPU_TARGET "ARM")
  • Install the RISV-V compiler once
  kdir -p ~/.pico-sdk/riscv
  cd ~/.pico-sdk/riscv
  wget https://github.com/raspberrypi/pico-sdk-tools/releases/download/v2.0.0-5/riscv-  toolchain-14-x86_64-lin.tar.gz
  tar xf riscv-toolchain-14-x86_64-lin.tar.gz
  • run ./clear.sh
  • Change the CMakeList.txt, uncomment those lines
set(PICO_TOOLCHAIN_PATH ~/.pico-sdk/riscv)
set(PICO_PLATFORM rp2350-riscv)

How to adapt for Pico 1 or Pico 2 or no Wifi

! untested !

Adjust the following line (_w is for Wifi)

set(PICO_BOARD pico2_w CACHE STRING "Board type")

Versions

  • 6/13/2026 initial release
  • 6/14/2026 V0.9 added MY_CPU_TARGET
  • 6/14/2026 V0.95 removed need for sudo on upload
  • 6/14/2026 V1.0 delay first printf to be after PuTTY is connected, added RISC-V and ARM inline assembly

Todo

  • Fix code for non Wifi model and Pico 1
  • Make putty line part of .sh
  • put alias into .sh (use source ./build.sh)
  • better keyboard handling, console?

About

Raspberry Pi Pico C starter project optimized for iteration time (no USB plugin and button pressing)

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages