diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 5eebb40..ea7c0bb 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -2,14 +2,13 @@ - [Introduction](./index.md) - [Dev Environment](./setup.md) + - [Quick Start](./quick-start.md) - [Running the Program](./running.md) - - [Concepts](./concepts/index.md) - - [Approaches](./concepts/approaches.md) - [Blink LED](./blinky/index.md) - - [With RP HAL](./blinky/rp-hal.md) - - [PWM](./blinky/pwm.md) - - [Watchdog](./blinky/watchdog.md) - - [With Embassy](./blinky/embassy.md) + - [Dim LED with RP HAL](./blinky/rp-hal.md) + - [Basic concepts](./blinky/no-std-main.md) + - [PWM](./blinky/pwm.md) + - [Watchdog](./blinky/watchdog.md) - [Using External LED](./blinky/external-led.md) - [Resources](./resources.md) diff --git a/src/blinky/embassy.md b/src/blinky/embassy.md deleted file mode 100644 index ddad576..0000000 --- a/src/blinky/embassy.md +++ /dev/null @@ -1,64 +0,0 @@ -# Blink LED with Embassy Framework - -This example code is taken from rp235x-hal repo (It also includes additional examples beyond just the blink examples): - -["https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples"](https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples) - -It creates a blinking effect by toggling the pin's output state between high and low. - -## The main code -```rust -#![no_std] -#![no_main] - -use embassy_executor::Spawner; -use embassy_rp::block::ImageDef; -use embassy_rp::gpio; -use embassy_time::Timer; -use gpio::{Level, Output}; -use {defmt_rtt as _, panic_probe as _}; - -#[link_section = ".start_block"] -#[used] -pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe(); - -// Program metadata for `picotool info`. -// This isn't needed, but it's recomended to have these minimal entries. -#[link_section = ".bi_entries"] -#[used] -pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [ - embassy_rp::binary_info::rp_program_name!(c"Blinky Example"), - embassy_rp::binary_info::rp_program_description!( - c"This example tests the RP Pico on board LED, connected to gpio 25" - ), - embassy_rp::binary_info::rp_cargo_version!(), - embassy_rp::binary_info::rp_program_build_attribute!(), -]; - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_rp::init(Default::default()); - let mut led = Output::new(p.PIN_25, Level::Low); - - loop { - led.set_high(); - Timer::after_millis(500).await; - - led.set_low(); - Timer::after_millis(500).await; - } -} -``` - - -## Clone the existing project -You can clone the blinky project I created and navigate to the `embassy-blinky` folder to run this version of the blink program: - -```sh -git clone https://github.com/ImplFerris/pico2-blinky -cd pico2-blinky/embassy-blinky -``` - -## How to Run? - -You refer the ["Running The Program"](../running.md) section diff --git a/src/blinky/index.md b/src/blinky/index.md index b55b417..6ede5e3 100644 --- a/src/blinky/index.md +++ b/src/blinky/index.md @@ -7,9 +7,3 @@ In this section, we'll learn how to blink an LED using the Raspberry Pi Pico 2. The onboard LED of the Pico is connected to GPIO pin 25 (based on the datasheet). To make it blink, we toggle the pin between high and low states at regular intervals. This turns the LED on and off, producing a blinking effect. pico2 - -## Choosing the crate -You can develop using two main approaches: the RP HAL or the Embassy framework. - -- [With RP HAL](./rp-hal.md) -- [With embassy](./embassy.md) diff --git a/src/concepts/index.md b/src/blinky/no-std-main.md similarity index 99% rename from src/concepts/index.md rename to src/blinky/no-std-main.md index 3d8ba51..17c1c28 100644 --- a/src/concepts/index.md +++ b/src/blinky/no-std-main.md @@ -1,4 +1,4 @@ -# Introduction +# Basic Concepts If you haven't read "The Embedded Rust Book" yet, I highly recommend you to check it out. [https://docs.rust-embedded.org/book/intro/index.html](https://docs.rust-embedded.org/book/intro/index.html) diff --git a/src/blinky/rp-hal.md b/src/blinky/rp-hal.md index 531d555..aa7e679 100644 --- a/src/blinky/rp-hal.md +++ b/src/blinky/rp-hal.md @@ -1,5 +1,7 @@ # Blink (Dimming) LED Program with RP HAL +rp-hal is an Embedded-HAL for RP series microcontrollers, and can be used as an alternative to the Embassy framework for pico. + This example code is taken from rp235x-hal repo (It also includes additional examples beyond just the blink examples): ["https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples"](https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples) diff --git a/src/concepts/approaches.md b/src/concepts/approaches.md deleted file mode 100644 index dac8622..0000000 --- a/src/concepts/approaches.md +++ /dev/null @@ -1,10 +0,0 @@ -## Approaches for Raspberry Pi Pico 2 - - -### 1. RP HAL -[**rp-hal**](https://github.com/rp-rs/rp-hal) is a Rust Embedded Hardware Abstraction Layer (HAL) designed specifically for the RP series microcontrollers. - -### 2. Embassy -[**Embassy**](https://github.com/embassy-rs/embassy) is a modern embedded framework that utilizes Rust and asynchronous programming. - -"Embassy is the next-generation framework for embedded applications. Write safe, correct and energy-efficient embedded code faster, using the Rust programming language, its async facilities, and the Embassy libraries." diff --git a/src/quick-start.md b/src/quick-start.md new file mode 100644 index 0000000..5daad8b --- /dev/null +++ b/src/quick-start.md @@ -0,0 +1,42 @@ +# Quick Start + +Before diving into the theory and concepts of how everything works, let's jump straight into action. Use this simple code to turn on the onboard LED of the Pico2. + +### Blink LED with Embassy Framework +[Embassy framework](https://github.com/embassy-rs/embassy) is a robust framework for developing asynchronous embedded applications in Rust. + +This example code is taken from rp235x-hal repo (It also includes additional examples beyond just the blink examples): ["https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples"](https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples) + +It creates a blinking effect by toggling the pin's output state between high and low. + +## The code snippet +This is not the entire code. There are things you have to initialize and import crates. +```rust +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); + + // The onboard LED is actually connected to pin 25 + let mut led = Output::new(p.PIN_25, Level::Low); + + loop { + led.set_high(); // <- Turn on the LED + Timer::after_millis(500).await; + + led.set_low(); // <- Turn off the LED + Timer::after_millis(500).await; + } +} +``` + +## Clone the Quick start project +You can clone the blinky project I created and navigate to the project folder and run it. + +```sh +git clone https://github.com/ImplFerris/pico2-quick +cd pico2-quick +``` + +## How to Run? + +You refer the ["Running The Program"](../running.md) section diff --git a/src/running.md b/src/running.md index 0c1f17a..9b8ee2f 100644 --- a/src/running.md +++ b/src/running.md @@ -1,9 +1,11 @@ # Running the program -Before we explore further examples, let’s cover the general steps to build and run any program on the Raspberry Pi Pico 2. +Before we explore further examples, let’s cover the general steps to build and run any program on the Raspberry Pi Pico 2. The Pico 2 contains both ARM Cortex-M33 and Hazard3 RISC-V processors, and we'll provide instructions for both architectures. -Note: These commands should be run from your project folder. This is included here as a general step to avoid repetition. If you haven't created a project yet, begin with the Blink LED section. +Note: These commands should be run from your project folder. This is included here as a general step to avoid repetition. If you haven't created a project yet, begin with the Quick Start or Blink LED section. ## Build and Run for ARM +Use this command to build and run programs on the Raspberry Pi Pico 2 in ARM mode, utilizing the Cortex-M33 processors. + ```sh # build the program cargo build --target=thumbv8m.main-none-eabihf @@ -22,6 +24,8 @@ cargo run --target=thumbv8m.main-none-eabihf ## Build and Run for RISC-V +Use this command to build and run programs on the Raspberry Pi Pico 2 n RISC-V mode, utilizing the Hazard3 processors. + ```sh # build the program cargo build --target=riscv32imac-unknown-none-elf