Previous journal: | Next journal: |
---|---|
0092-2023-06-08.md | 0094-2023-06-12.md |
Ref: https://www.raspberrypi.com/documentation/microcontrollers/c_sdk.html
I'll do this under my Linux VM first.
sudo adduser zerotoasic dialout
- Log out desktop completely and log back in.
- Plug in Pi Pico and pass thru to Linux VM. Optionally make it permanent.
Can check if it engaged properly by looking at tail of
dmesg -T
; expect it mounted as/dev/ttyACM0
. - Run
minicom -o -D /dev/ttyACM0
- From "hello world" UF2 firmware in last journal, we see it's printing "Hello, world!"
- Start following the guide from "Quick-start your own project"...
sudo apt update
- Install CMake and GCC cross compiler:
NOTE: This needs ~2.3GB of disk!
sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
-
NOTE: Can also override PICO_SDK_PATH by passing
cd ~/anton git clone https://github.com/raspberrypi/pico-sdk.git echo "export PICO_SDK_PATH=$(realpath pico-sdk)" >> ~/.bashrc export PICO_SDK_PATH=$(realpath pico-sdk) cd pico-sdk git submodule update --init # Needed for TinyUSB.
-DPICO_SDK_PATH=...
tocmake
-
NOTE: This is now found here: https://github.com/algofoogle/sandpit/tree/master/pi_pico/pico_hello
cd sandpit mkdir -p pi_pico/pico_hello cd pi_pico/pico_hello
- We'll basically rip off the hello_world USB example...
cp $PICO_SDK_PATH/external/pico_sdk_import.cmake .
- NOTE: CMake is used for making Makefiles...
- Create CMake file
CMakeLists.txt
:cmake_minimum_required(VERSION 3.13) # initialize the SDK based on PICO_SDK_PATH # note: this must happen before project() include(pico_sdk_import.cmake) project(pico_hello) # initialize the Raspberry Pi Pico SDK pico_sdk_init() # rest of your project... if (TARGET tinyusb_device) # I guess this specifies the target binary (or that there should be one) # and specifies hello_usb.c as the source file? add_executable(pico_hello hello_usb.c ) # Pull in common dependencies, # i.e. add pico_stdlib library which aggregates commonly used features: target_link_libraries(pico_hello pico_stdlib) # Enable USB output, disable UART output. # Does this just affect linking or does it configure RP2040 modes...? pico_enable_stdio_usb(pico_hello 1) pico_enable_stdio_uart(pico_hello 0) # Create map/bin/hex/uf2 file etc. in addition to ELF: pico_add_extra_outputs(pico_hello) elseif(PICO_ON_DEVICE) message(WARNING "not building hello_usb because TinyUSB submodule is not initialized in the SDK") endif()
- Create
hello_usb.c
:#include <stdio.h> #include "pico/stdlib.h" int main() { stdio_init_all(); for (int c = 0; ; ++c) { printf("Oh, hello there! This is iteration %d\n", c); sleep_ms(500); } return 0; }
-
This builds a suitable Makefile and supporting stuff.
mkdir build cd build cmake .. #NOTE: If targeting Pico W, do: cmake -DPICO_BOARD=pico_w ..
make pico_hello
-- see below for output.- We now have:
-rwxrwxr-x 1 zerotoasic zerotoasic 32344 Jun 9 15:20 pico_hello.bin -rw-rw-r-- 1 zerotoasic zerotoasic 596936 Jun 9 15:20 pico_hello.dis -rwxrwxr-x 1 zerotoasic zerotoasic 76548 Jun 9 15:20 pico_hello.elf -rw-rw-r-- 1 zerotoasic zerotoasic 250304 Jun 9 15:20 pico_hello.elf.map -rw-rw-r-- 1 zerotoasic zerotoasic 91025 Jun 9 15:20 pico_hello.hex -rw-rw-r-- 1 zerotoasic zerotoasic 65024 Jun 9 15:20 pico_hello.uf2
- Unplug Pico, hold BOOTSEL and plug in, then add Pico as permanent USB pass-thru for VM. Note that this needs to be done separately for BOOTSEL mode and running firmware mode.
- Replug while holding BOOTSTEL, and while Windows might still play a USB sound, it should then show up in the Linux VM, accompanied by this dmesg output:
[Fri Jun 9 15:24:01 2023] usb 1-1: new full-speed USB device number 5 using ohci-pci [Fri Jun 9 15:24:02 2023] usb 1-1: New USB device found, idVendor=2e8a, idProduct=0003, bcdDevice= 1.00 [Fri Jun 9 15:24:02 2023] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [Fri Jun 9 15:24:02 2023] usb 1-1: Product: RP2 Boot [Fri Jun 9 15:24:02 2023] usb 1-1: Manufacturer: Raspberry Pi [Fri Jun 9 15:24:02 2023] usb 1-1: SerialNumber: E0C912952D54 [Fri Jun 9 15:24:02 2023] usb-storage 1-1:1.0: USB Mass Storage device detected [Fri Jun 9 15:24:02 2023] scsi host3: usb-storage 1-1:1.0 [Fri Jun 9 15:24:03 2023] scsi 3:0:0:0: Direct-Access RPI RP2 2 PQ: 0 ANSI: 2 [Fri Jun 9 15:24:03 2023] sd 3:0:0:0: Attached scsi generic sg2 type 0 [Fri Jun 9 15:24:03 2023] sd 3:0:0:0: [sdb] 262144 512-byte logical blocks: (134 MB/128 MiB) [Fri Jun 9 15:24:03 2023] sd 3:0:0:0: [sdb] Write Protect is off [Fri Jun 9 15:24:03 2023] sd 3:0:0:0: [sdb] Mode Sense: 03 00 00 00 [Fri Jun 9 15:24:03 2023] sd 3:0:0:0: [sdb] No Caching mode page found [Fri Jun 9 15:24:03 2023] sd 3:0:0:0: [sdb] Assuming drive cache: write through [Fri Jun 9 15:24:03 2023] sdb: sdb1 [Fri Jun 9 15:24:03 2023] sd 3:0:0:0: [sdb] Attached SCSI removable disk
- Device shows up in Ubuntu Desktop, so now copy in UF2 file we just built:
cp pico_hello.uf2 /media/zerotoasic/RPI-RP2/
- Device should reconnect, and so long as it is still passed thru to the VM, run
minicom -o -D /dev/ttyACM0
and expect to see something like:... Oh, hello there! This is iteration 225 Oh, hello there! This is iteration 226 Oh, hello there! This is iteration 227 Oh, hello there! This is iteration 228 ...
- See other Pi Pico C examples: https://github.com/raspberrypi/pico-examples
Click here to show the log
Scanning dependencies of target bs2_default
[ 1%] Building ASM object pico-sdk/src/rp2_common/boot_stage2/CMakeFiles/bs2_default.dir/compile_time_choice.S.obj
[ 2%] Linking ASM executable bs2_default.elf
[ 2%] Built target bs2_default
Scanning dependencies of target bs2_default_padded_checksummed_asm
[ 3%] Generating bs2_default.bin
[ 4%] Generating bs2_default_padded_checksummed.S
[ 4%] Built target bs2_default_padded_checksummed_asm
Scanning dependencies of target ELF2UF2Build
[ 6%] Creating directories for 'ELF2UF2Build'
[ 7%] No download step for 'ELF2UF2Build'
[ 8%] No patch step for 'ELF2UF2Build'
[ 9%] No update step for 'ELF2UF2Build'
[ 10%] Performing configure step for 'ELF2UF2Build'
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zerotoasic/anton/sandpit/pi_pico/pico_hello/build/elf2uf2
[ 12%] Performing build step for 'ELF2UF2Build'
Scanning dependencies of target elf2uf2
[ 50%] Building CXX object CMakeFiles/elf2uf2.dir/main.cpp.o
[100%] Linking CXX executable elf2uf2
[100%] Built target elf2uf2
[ 13%] No install step for 'ELF2UF2Build'
[ 14%] Completed 'ELF2UF2Build'
[ 14%] Built target ELF2UF2Build
Scanning dependencies of target pico_hello
[ 15%] Building C object CMakeFiles/pico_hello.dir/hello_usb.c.obj
[ 17%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_stdlib/stdlib.c.obj
[ 18%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_gpio/gpio.c.obj
[ 19%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_platform/platform.c.obj
[ 20%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_claim/claim.c.obj
[ 21%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_sync/sync.c.obj
[ 23%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_irq/irq.c.obj
[ 24%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_irq/irq_handler_chain.S.obj
[ 25%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/common/pico_sync/sem.c.obj
[ 26%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/common/pico_sync/lock_core.c.obj
[ 28%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/common/pico_sync/mutex.c.obj
[ 29%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/common/pico_sync/critical_section.c.obj
[ 30%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/common/pico_time/time.c.obj
[ 31%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/common/pico_time/timeout_helper.c.obj
[ 32%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_timer/timer.c.obj
[ 34%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/common/pico_util/datetime.c.obj
[ 35%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/common/pico_util/pheap.c.obj
[ 36%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/common/pico_util/queue.c.obj
[ 37%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_uart/uart.c.obj
[ 39%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_clocks/clocks.c.obj
[ 40%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_pll/pll.c.obj
[ 41%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_vreg/vreg.c.obj
[ 42%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_watchdog/watchdog.c.obj
[ 43%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_xosc/xosc.c.obj
[ 45%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_divider/divider.S.obj
[ 46%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_runtime/runtime.c.obj
[ 47%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_printf/printf.c.obj
[ 48%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S.obj
[ 50%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_bootrom/bootrom.c.obj
[ 51%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_divider/divider.S.obj
[ 52%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_double/double_aeabi.S.obj
[ 53%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_double/double_init_rom.c.obj
[ 54%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_double/double_math.c.obj
[ 56%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_double/double_v1_rom_shim.S.obj
[ 57%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_int64_ops/pico_int64_ops_aeabi.S.obj
[ 58%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_float/float_aeabi.S.obj
[ 59%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_float/float_init_rom.c.obj
[ 60%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_float/float_math.c.obj
[ 62%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_float/float_v1_rom_shim.S.obj
[ 63%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_malloc/pico_malloc.c.obj
[ 64%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_mem_ops/mem_ops_aeabi.S.obj
[ 65%] Building ASM object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_standard_link/crt0.S.obj
[ 67%] Building CXX object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_standard_link/new_delete.cpp.obj
[ 68%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_standard_link/binary_info.c.obj
[ 69%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj
[ 70%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_stdio_usb/reset_interface.c.obj
[ 71%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c.obj
[ 73%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c.obj
[ 74%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_unique_id/unique_id.c.obj
[ 75%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/hardware_flash/flash.c.obj
[ 76%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c.obj
[ 78%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c.obj
[ 79%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/device/usbd.c.obj
[ 80%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/device/usbd_control.c.obj
[ 81%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/audio/audio_device.c.obj
[ 82%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/cdc/cdc_device.c.obj
[ 84%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/dfu/dfu_device.c.obj
[ 85%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/dfu/dfu_rt_device.c.obj
[ 86%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/hid/hid_device.c.obj
[ 87%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/midi/midi_device.c.obj
[ 89%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/msc/msc_device.c.obj
[ 90%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/net/ecm_rndis_device.c.obj
[ 91%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/net/ncm_device.c.obj
[ 92%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/usbtmc/usbtmc_device.c.obj
[ 93%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/vendor/vendor_device.c.obj
[ 95%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/class/video/video_device.c.obj
[ 96%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/tusb.c.obj
[ 97%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/lib/tinyusb/src/common/tusb_fifo.c.obj
[ 98%] Building C object CMakeFiles/pico_hello.dir/home/zerotoasic/anton/pico-sdk/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c.obj
[100%] Linking CXX executable pico_hello.elf
[100%] Built target pico_hello