Skip to content

Commit

Permalink
concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
ImplFerris committed Oct 20, 2024
1 parent 46ce64f commit 8469095
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 17 deletions.
11 changes: 7 additions & 4 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
19 changes: 13 additions & 6 deletions src/blinky/embassy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/blinky/index.md
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 19 additions & 6 deletions src/blinky/rp-rs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
File renamed without changes.
29 changes: 29 additions & 0 deletions src/concepts/index.md
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 19 additions & 0 deletions src/intro/intro.md
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions src/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8469095

Please sign in to comment.