Skip to content

Commit

Permalink
feat: Update projects to latest deps
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez committed Apr 19, 2024
1 parent 713cfec commit 4e4fe17
Show file tree
Hide file tree
Showing 34 changed files with 1,225 additions and 1,715 deletions.
301 changes: 123 additions & 178 deletions advanced/stack-overflow-detection/Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions advanced/stack-overflow-detection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
esp-hal = { version = "0.16.1", features = ["esp32c3"] }
esp-backtrace = { version = "0.11.0", features = ["esp32c3", "panic-handler", "exception-handler", "println"] }
esp-println = { version = "0.9.0", features = ["esp32c3", "uart"] }
esp-hal = { version = "0.17.0", features = ["esp32c3"] }
esp-backtrace = { version = "0.11.1", features = ["esp32c3", "panic-handler", "exception-handler", "println"] }
esp-println = { version = "0.9.1", features = ["esp32c3", "uart"] }
critical-section = "1.1.2"
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ use core::cell::RefCell;

use critical_section::Mutex;
use esp_backtrace as _;
use esp_println::println;
use esp_hal::{
assist_debug::DebugAssist,
clock::ClockControl,
interrupt,
peripherals::{self, Peripherals},
prelude::*,
assist_debug::DebugAssist, clock::ClockControl, peripherals::Peripherals, prelude::*,
};
use esp_println::println;

#[entry]
fn main() -> ! {
Expand All @@ -21,7 +17,7 @@ fn main() -> ! {
let _ = ClockControl::boot_defaults(system.clock_control).freeze();

// get the debug assist driver
let da = DebugAssist::new(peripherals.ASSIST_DEBUG);
let da = DebugAssist::new(peripherals.ASSIST_DEBUG, Some(interrupt_handler));

// set up stack overflow protection
install_stack_guard(da, 4096);
Expand Down Expand Up @@ -71,18 +67,13 @@ fn install_stack_guard(mut da: DebugAssist<'static>, safe_area_size: u32) {
da.enable_region0_monitor(stack_low, stack_low + safe_area_size, true, true);

critical_section::with(|cs| DA.borrow_ref_mut(cs).replace(da));
interrupt::enable(
peripherals::Interrupt::ASSIST_DEBUG,
interrupt::Priority::Priority1,
)
.unwrap();
}
// ANCHOR_END: debug_assists

// ANCHOR: interrupt
// ANCHOR: handler
#[interrupt]
fn ASSIST_DEBUG() {
#[handler(priority = esp_hal::interrupt::Priority::min())]
fn interrupt_handler() {
// ANCHOR_END: interrupt

critical_section::with(|cs| {
Expand Down
13 changes: 6 additions & 7 deletions advanced/stack-overflow-detection/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ use core::cell::RefCell;

use critical_section::Mutex;
use esp_backtrace as _;
use esp_println::println;
use esp_hal::{
assist_debug::DebugAssist,
clock::ClockControl,
interrupt,
peripherals::{self, Peripherals},
prelude::*,
assist_debug::DebugAssist, clock::ClockControl, peripherals::Peripherals, prelude::*,
};
use esp_println::println;

#[entry]
fn main() -> ! {
Expand All @@ -21,7 +17,7 @@ fn main() -> ! {
let _ = ClockControl::boot_defaults(system.clock_control).freeze();

// get the debug assist driver
let da = DebugAssist::new(peripherals.ASSIST_DEBUG);
let da = DebugAssist::new(peripherals.ASSIST_DEBUG, Some(interrupt_handler));

boom();

Expand Down Expand Up @@ -50,3 +46,6 @@ fn deadly_recursion(data: [u8; 2048]) {

deadly_recursion([0u8; 2048]);
}

#[handler(priority = esp_hal::interrupt::Priority::min())]
fn interrupt_handler() {}
21 changes: 3 additions & 18 deletions book/src/03_4_interrupt.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ We need the `Mutex` to make access to the button safe.

> Please note that this is not the Mutex you might know from `libstd` but it's the Mutex from [`critical-section`] (and that's why we need to add it as a dependency).
✅ We need to call [`listen`][listen] on the button pin to configure the peripheral to raise interrupts. We can raise interrupts for [different events][events] - here we want to raise the interrupt on the falling edge.
✅ We need to set the interrupt handler for the GPIO interrupts.

✅ Let's add a [`critical-section`], using the `with()` method and enable an interrupt:
✅ Let's add a [`critical-section`], using the `with()` method and enable an interrupt for falling edges:

```rust,ignore
{{#include ../../intro/button-interrupt/examples/button-interrupt.rs:critical_section}}
Expand All @@ -43,26 +43,11 @@ In this line we move our button into the `static BUTTON` for the interrupt handl
The code running inside the `critical_section::with` closure runs within a critical section,
`cs` is a token that you can use to "prove" that to some API.

✅ Enable the interrupt:

```rust,ignore
{{#include ../../intro/button-interrupt/examples/button-interrupt.rs:interrupt}}
```

First parameter here is the kind of interrupt we want. There are several [possible interrupts].
The second parameter, chooses the priority, in our case, we choosed `Priority3`. Priority dictates which interrupts are runned first in case of several interrupts being triggered at the same time.

✅ Enable interrupts: This can be achived by: `riscv::interrupt::enable`, but this is an unsafe
function, hence it needs to be run inside an `unsafe` block.

The interrupt handler is defined via the `#[interrupt]` macro.
The interrupt handler is defined via the `#[handler]` macro.
Here, the name of the function must match the interrupt.

[listen]: https://docs.esp-rs.org/esp-hal/esp-hal/0.16.1/esp32c3/esp_hal/gpio/trait.Pin.html#method.listen
[Interrupts]: https://docs.rust-embedded.org/book/start/interrupts.html
[`critical-section`]: https://crates.io/crates/critical-section
[possible interrupts]: https://docs.esp-rs.org/esp-hal/esp-hal/0.16.1/esp32c3/esp32c3/enum.Interrupt.html
[events]: https://docs.esp-rs.org/esp-hal/esp-hal/0.16.1/esp32c3/esp_hal/gpio/enum.Event.html

## Simulation

Expand Down
4 changes: 2 additions & 2 deletions book/src/03_5_dma_spi.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Now we are free to let the CPU do other things while the SPI transfer is in prog

✅ Wait for the transfer to complete and get back the buffers and the driver instance

As mentioned before the buffers and the driver are moved into the `Transfer`. If we want to access the received data and transfer more data we need to get them back.
As mentioned before the buffers and the driver are moved into the `Transfer`.

```rust,ignore
{{#include ../../intro/dma/examples/dma.rs:transfer-wait}}
Expand All @@ -88,4 +88,4 @@ While using DMA needs more effort than letting the CPU do all the work it's not
> However, if the amount of data to transfer is bigger, then the time needed to setup the transfer is negligible compared to the time the CPU could use to do useful things in parallel.
[SPI]: https://en.wikipedia.org/wiki/Serial_Peripheral_Interface
[linked list]: https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf#page=59
[linked list]: https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf#page=59
Loading

0 comments on commit 4e4fe17

Please sign in to comment.