diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 8fc39a4..a27935e 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -1,9 +1,12 @@ # Summary -- [Intro](./index.md) - - [Setup](./setup.md) - - [Approach](./approaches.md) - - [Running the Program](./running.md) +- [Introduction](./intro/intro.md) + - [Dev Environment](./index.md) + - [Setup](./setup.md) + - [Running the Program](./running.md) + - [Concepts](./concepts/index.md) + - [Approaches](./concepts/approaches.md) + - [Blink LED](./blinky/index.md) - [With rp-rs](./blinky/rp-rs.md) - [With embassy](./blinky/embassy.md) diff --git a/src/blinky/embassy.md b/src/blinky/embassy.md index 3946558..b4c9457 100644 --- a/src/blinky/embassy.md +++ b/src/blinky/embassy.md @@ -4,12 +4,6 @@ This example code is taken from rp235x-hal repo (It also includes additional exa ["https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples"](https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples) -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 -``` - ## The main code ```rust #![no_std] @@ -53,3 +47,16 @@ async fn main(_spawner: Spawner) { } } ``` + + +## 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 fac642b..5dae0f4 100644 --- a/src/blinky/index.md +++ b/src/blinky/index.md @@ -1,6 +1,6 @@ # Blink LED -In this section, we'll learn how to blink an LED using the Raspberry Pi Pico 2. +In this section, we'll learn how to blink an LED using the Raspberry Pi Pico 2. In embedded system programming, blinking an LED is the equivalent of "Hello, World!" - [With rp-rs](./rp-rs.md) - [With embassy](./embassy.md) diff --git a/src/blinky/rp-rs.md b/src/blinky/rp-rs.md index 971f083..19d2b95 100644 --- a/src/blinky/rp-rs.md +++ b/src/blinky/rp-rs.md @@ -4,12 +4,6 @@ This example code is taken from rp235x-hal repo (It also includes additional exa ["https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples"](https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples) -You can clone the blinky project I created and navigate to the `rprs-blinky` folder to run this version of the blink program: - -```sh -git clone https://github.com/ImplFerris/pico2-blinky -``` - ## The main code ```rust @@ -138,3 +132,22 @@ pub static PICOTOOL_ENTRIES: [hal::binary_info::EntryAddr; 5] = [ // End of file ``` + +## Clone the existing project + +You can clone the blinky project I created and navigate to the `rprs-blinky` folder to run this version of the blink program: + +```sh +git clone https://github.com/ImplFerris/pico2-blinky +cd pico2-blinky/rprs-blinky +``` + +## How to Run? + +You refer the ["Running The Program"](../running.md) section + + +## Explanation +Let's break it down and explain any parts that need clarification. + +//TODO diff --git a/src/approaches.md b/src/concepts/approaches.md similarity index 100% rename from src/approaches.md rename to src/concepts/approaches.md diff --git a/src/concepts/index.md b/src/concepts/index.md new file mode 100644 index 0000000..3d8ba51 --- /dev/null +++ b/src/concepts/index.md @@ -0,0 +1,29 @@ +# Introduction + +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) + +## #![no_std] +The `#![no_std]` attribute disables the use of the standard library (std). This is necessary most of the times for embedded systems development, where the environment typically lacks many of the resources (like an operating system, file system, or heap allocation) that the standard library assumes are available. + +**Related Resources:** +- [Rust official doc](https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute) +- [The Embedded Rust Book](https://docs.rust-embedded.org/book/intro/no-std.html) +- [Writing an OS in Rust Book](https://os.phil-opp.com/freestanding-rust-binary/#the-no-std-attribute) + +## #![no_main] +The `#![no_main]` attribute is to indicate that the program won't use the standard entry point (fn main). Instead, it provides a custom entry point, usually required when working with embedded systems where the runtime environment is minimal or non-existent. + +**Related Resources:** +- [Rust official doc](https://doc.rust-lang.org/reference/crates-and-source-files.html?highlight=no_main#the-no_main-attribute) +- [Writing an OS in Rust Book](https://os.phil-opp.com/freestanding-rust-binary/#overwriting-the-entry-point) + + +## Panic Handler +A panic handler is a function in Rust that defines what happens when your program encounters a panic. In environments without the standard library (when using no_std attribute), you need to create this function yourself using the #[panic_handler] attribute. This function must follow a specific format and can only appear once in your program. It provides details about the error, such as where it happened and why. By setting up a panic handler, you can choose how to respond to errors, like logging them for later review or stopping the program completely. + +You don't have to define your own panic handler function; you can use existing crates such as panic_halt or panic_probe instead. + +**Related Resources:** +- [Rust official doc](https://doc.rust-lang.org/nomicon/panic-handler.html) +- [The Embedded Rust Book](https://docs.rust-embedded.org/book/start/panicking.html) diff --git a/src/intro/intro.md b/src/intro/intro.md new file mode 100644 index 0000000..9d0807d --- /dev/null +++ b/src/intro/intro.md @@ -0,0 +1,19 @@ +# Introduction + +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) + +## #![no_std] +The `#![no_std]` attribute disables the use of the standard library (std). This is necessary most of the times for embedded systems development, where the environment typically lacks many of the resources (like an operating system, file system, or heap allocation) that the standard library assumes are available. + +**Related Resources:** +- [Rust official doc](https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute) +- [The Embedded Rust Book](https://docs.rust-embedded.org/book/intro/no-std.html) +- [Section from 'Writing an OS in Rust ' Book](https://os.phil-opp.com/freestanding-rust-binary/#the-no-std-attribute) + +## #![no_main] +The `#![no_main]` attribute is to indicate that the program won't use the standard entry point (fn main). Instead, it provides a custom entry point, usually required when working with embedded systems where the runtime environment is minimal or non-existent. + +**Related Resources:** +- [Rust official doc](https://doc.rust-lang.org/reference/crates-and-source-files.html?highlight=no_main#the-no_main-attribute) +- [Section from 'Writing an OS in Rust ' Book](https://os.phil-opp.com/freestanding-rust-binary/#overwriting-the-entry-point) diff --git a/src/resources.md b/src/resources.md index 65032a3..36c1df3 100644 --- a/src/resources.md +++ b/src/resources.md @@ -7,3 +7,4 @@ This section will include a list of resources I find helpful along the way. ## Other resources - [Curated list of resources for Embedded Rust](https://github.com/rust-embedded/awesome-embedded-rust) +- [Writing an OS in Rust ](https://os.phil-opp.com/): many useful concepts explained here