Compiling Hello World (C) for the PicoCalc

Hi, I’m trying to learn how to compile C programs for the PicoCalc. I decided to start by compiling the simplest possible C program that displays “Hello World” to the screen, waits a while, then exits. Unfortunately, when I run my program, the PicoCalc freezes with the message: “STAT: Launching app…”. Can anyone tell me how to compile C programs for the PicoCalc?

Here’s what I’ve done.

  1. I’m compiling my program on an Ubuntu (Linux) laptop using GCC (version 10.5.0)
  2. I installed the following dependencies:
sudo apt install cmake python3 build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
  1. I then cloned the latest version of the Raspberry Pi SDK:
git clone https://github.com/raspberrypi/pico-sdk.git
  1. I also cloned the latest version of the PicoCalc SDK:
git clone --recursive https://github.com/clockworkpi/PicoCalc.git picocalc-sdk
  1. I then created a folder to store my Hello world program and copied over the Pico SDK CMake file:
mkdir picocalc-test
cd picocalc-test/
cp ../pico-sdk/external/pico_sdk_import.cmake .
cp -r /home/larry/Projects/picocalc-sdk/Code/picocalc_helloworld .
  1. I then wrote the following C program and stored it into “hello_world.c”:
  1 #include <stdio.h>
  2 #include <string.h>
  3 #include "pico/stdlib.h"
  4 #include "hardware/gpio.h"
  5 #include "hardware/clocks.h"
  6 #include "i2ckbd.h"
  7 #include "lcdspi.h"
  8 #include "psram_spi.h"
  9 #include "pwm_sound.h"
 10 
 11 int main() {
 12   set_sys_clock_khz(133000, true);
 13   stdio_init_all(); 
 14   init_i2c_kbd();
 15   lcd_init();
 16   lcd_clear();
 17   lcd_print_string("Hello World PicoCalc\n");
 18   while (1) {
 19     int c = lcd_getc(0);
 20     if(c != -1 && c > 0) {
 21       lcd_putc(0,c);
 22     }
 23     sleep_ms(20);
 24   }
 25 
 26   printf("Hello, world!\n");
 27   return 0;
 28 }
  1. I then compiled the program using CMake:
PICO_SDK_PATH=/home/larry/Projects/pico-sdk/ cmake -S . -B build -DPICO_BOARD=pico
cmake --build build --target hello_world
  1. This produced a folder named “build” that contained many files and folders. I copied “build/hello_world.bin” and “build/hello_world.uf2” into the “firmware” and “firmware/UF2” folders on the SD card that came with my PicoCalc respectively.
  2. When I reinserted the SD card into my PicoCalc, I saw an entry for my hello_world program and tried to run it. This resulted in the frozen error I described above.

Any help would be appreciated. I’m sure that many other programmers are new to PicoCalc development and would benefit from clear instructions being posted here.

Thanks!

The bootloader that comes preinstalled on the picocalc is limited and won’t execute a binary unless it’s built in a particular convoluted manner. It’s more trouble than it’s worth and you should get rid of it.

You can flash your uf2 directly to the pico in bootsel mode, overwriting the bootloader and running it directly.

Or you can install the improved replacement uf2loader (UF2 Loader release) which can load standard uf2 files without any faffing about.

You are amazing. Thanks for the UF2 Loader.

I bundled everything that I used to create a hello world C program together into a Git repo along with step by step instructions. Hope this helps everyone else!

2 Likes

Hey, thanks for the reference!

I put that starter kit (SDK?) out there to give C/C++ folks a running start with their PicoCalc. I am hoping folks will grab what they need or learn from it. It is definitely not a perfect fit for every project.

My desire is to see more very cool stuff for the PicoCalc.

1 Like