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.
- I’m compiling my program on an Ubuntu (Linux) laptop using GCC (version 10.5.0)
- 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
- I then cloned the latest version of the Raspberry Pi SDK:
git clone https://github.com/raspberrypi/pico-sdk.git
- I also cloned the latest version of the PicoCalc SDK:
git clone --recursive https://github.com/clockworkpi/PicoCalc.git picocalc-sdk
- 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 .
- 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 }
- 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
- 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.
- 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!