Skip to content

Kytezign/zig_pico_sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

The goal here is mostly for me to have a reference for setting up the pico sdk build environment with zig.
If it helps other people, I'll be happy but it's not necessarily the goal - I'm far from an expert. I'm not sure on the limitations of this method yet either but there probably are some. All that being said the general Idea is that a main .h file will include the needed API references from the pico_sdk. Then that would get translated into a module that can be imported in the implementation code. Additionally, there are convenience functions for automating cmake calls as part of the zig build flow. It also can create a picotool load step to automatically load the generated file into the device. See this USB KVM project for a more complicated usage example: https://github.com/Kytezign/USBKVM

Usage

Import pico_build.zig into a build.zig script. Then use the provided functions to setup a zig/ pico-sdk build flow.
It should also work for autocomplete with zls but it's been a little fickle so your mileage may vary. See comments in example for more details around usage or ask and I'm happy to try to help.

Known Issues

us_to_ms

There is a bug in translation of the us_to_ms function which is called in get_ms_since_boot. My work around is to use get_us_since_boot and do the conversion to ms in my code. (divide by 1000)

Other Setup notes (Arch based)

Install build tools for Archlinux

`sudo pacman -Syu git cmake arm-none-eabi-binutils usbutils`
`sudo pacman -Syu arm-none-eabi-gcc arm-none-eabi-newlib arm-none-eabi-gdb`

cdc device communication

USB Utils is apparently required to enable ttyusb devices but I'm not 100% sure how that works. Just make sure they show up and you are in the right group uucp for Arch 2024. Reboot after adding the user to the group

Clone SDK Repo

Get/generate personal access token from github to clone git clone https://github.com/raspberrypi/pico-sdk

Add the sdk path to env PICO_SDK_PATH Done using Systemd environment var controls (as an example): ~/.config/environment.d/66-env.conf

PICO_SDK_PATH=$HOME/path_to_sdk
PATH=$HOME/path_to_picotool_binary:$PATH

Reference: https://wiki.archlinux.org/title/Systemd/User#Environment_variables

picotool (for load step)

Picotool must be available in the path. (can be built locally - see env above to add to path). https://github.com/raspberrypi/picotool Arch specific udev rules (2024) verify before running...: sudo cp udev/99-picotool.rules /etc/udev/rules.d/99-picotool.rules Reference: https://wiki.archlinux.org/title/Udev

Other References

Potential next steps

  • Build with zig cc.
  • Or just link with zig?
  • Can we add documentation to the zig translation?
    • Thinking just copy the previous c comment as a /// comment in zig could work well enough
    • Might be best to update this in translate-c directly
  • Optimization exploration
    • Link level optimization
    • Controlling compiling in non-debug mode in both zig and cmake

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published