rp-pico2w-examples
rp-pico2w-examples copied to clipboard
A collection of Rust examples for the RP2030 Wireless board
Raspberry Pi Pico2 W examples
This Rust repo was created to demonstrate a simple network interaction between two rp pico2w dev boards (RP2350) with minimal external circuitry required. Specifically we don't even need a probe (debugger).
Setup
Install Rust on your machine.
Add the armv8 cross compiler to the rust toolchain
rustup target add thumbv8m.main-none-eabihf
Install the elf2uf2-rs tool to help you flash the pico. This tool has been modified to support RP2350 microcontrollers.
cargo install --git https://github.com/ninjasource/elf2uf2-rs.git --branch pico2-support --force
How to run the examples
See 01_logs.rs for instructions on how the pico bootloader works.
cargo run --bin 01_logs --release
Troubleshooting
Error running: Error: "Unable to find mounted pico"
Reason: The pico2 cannot be detected in bootloader mode by the host.
Solution: Unplug the pico, hold down the BOOTSEL button while plugging it back in. You can then release the button and the device should remain in boot mode. You may need to mount the drive if your machine does not automatically do so already.
Error accessing serial port on linux
Reason: libudev needs to be installed (see serialport crate for more)
Solution:
sudo apt install libudev-dev
Reason: your serial port needs root access.
Error: After Found pico serial on /dev/ttyACM0 message nothing happens and the program eventually terminates.
Solution: look up how to access your serial port without root on your distro
What is the memory.x file?
One of the last steps in compilation is linking which is the process of assigning physical memory addresses to variables and code.
On a computer with an operating system the OS uses virtual memory but embedded systems like the rp-pico don't have an OS
and we need to create an executable with physical memory addresses in the correct locations that are expected by the pico.
The memory.x file is the the developer facing linker script that tells the linker when RAM and FLASH physically start.
If you look at .cargo/config.toml you will see a whole bunch of linker scripts referenced there. The link.x script references memory.x.
How can this be compiled on a PC and run on a pico?
Rust supports cross compilation and this is setup in the .cargo/config.toml file with the following config:
[build]
target = "thumbv8m.main-none-eabihf"
Send test data to the pico2w
In Linux (using netcat to fire and forget ipv4 udp packet):
echo -n "on" | nc -4u -w0 192.168.1.99 47900
echo -n "off" | nc -4u -w0 192.168.1.99 47900
Ideas to work on when you finish all the examples
Morse code:
Get your pico to flash with morse code when sent text over USB serial.
TCP/IP:
Experiment with opening a TCP/IP connection rather than using UDP.
Internet access:
Instead of connecting to the sandbox wifi, connect to a wifi network that has access to the internet and attempt to make some http calls. The pico2w is an extremely low power device which can be left on all the time. This makes it ideal for checking RSS feeds or, say, looking up Transport-For-London bus times.
See: https://tfl.gov.uk/info-for/open-data-users/api-documentation
For example: https://api.tfl.gov.uk/StopPoint/490013767D/arrivals