In the last post of this series, we looked at how to write a minimal Rust program for the Raspberry Pi Pico. In this post, we'll expand on that code to implement the indication LED.
Table of Contents
- Flowchart
- Requirements
Implementation
- Clock Configuration
- PLL Programming
- Timer
- LED
- Interrupt
- Results
Flowchart
Now we'll configure the XOSC. We first expose it's registers by taking ownership of it.
let xosc = dp.XOSC;
We then configure the crystal oscillator by setting the frequency range of the XOSC and setting the start-up delay time.
Instructions for setting the startup delay can be found in the reference manual. The start-up delay value is calculated using the below formula.
start up delay=(fCrystal×tStable)÷256
start\ up\ delay = (fCrystal \times tStable) \div 256
start up delay=(fCrystal×tStable)÷256
With a 12MHz XOSC and a desired 1ms wait time, our calculated start-up delay time will be:
(12×106)×(1×10−3)256=47{(12 \times 10^6) \times (1 \times 10^-3) \over 256} = 47 256(12×106)×(1×10−3)=47
xosc.ctrl().modify(|_, w| w.freq_range()._1_15mhz());// Set freq. range
xosc.startup().write(|w| unsafe { w.delay().bits(47) });// Set the startup delay
Enable the XOSC and wait for it to stabilize.
xosc.ctrl().modify(|_, w| w.enable().enable());// Enable the xosc
while xosc().status.read().stable().bit_is_clear() {}// Await stabilization
With the XOSC running, we now need to configure the clocks and PLLs.
First create handles for the clocks and PLLS. We'll also need one for the resets.
let clocks = dp.CLOCKS;
let pll_sys = dp.PLL_SYS;
let resets = dp.RESETS;
Before using a peripheral it must first be deasserted.
resets.reset().modify(|_, w| w
.pll_sys().clear_bit()// deassert pll sys
);
PLL programming
The PLL runs from the reference clock, in this case a 12 MHz crystal oscillator, and multiplies it to attain higher frequencies.
github page.
All the changes from the minimum program from the last part can be viewed in
Next we'll configure the Pico's UART to enable us receive commands remotely via Bluetooth.
SOCIAL SHARE CARD GENERATOR