Skip to content

Commit

Permalink
docs: Update tempaltes docs
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez committed Jul 10, 2023
1 parent 500f02c commit 1108c87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Now that we know how to [generate a std project], let's inspect what the generat

When creating a project from [esp-idf-template] with the following answers:
- Which MCU to target? · `esp32c3`
- Use template default values? · `true`
- Configure advanced template options? · `false`

For this explanation we will use the default values, if you want further modifications, see the [additional prompts] when not using default values.

Expand Down
21 changes: 14 additions & 7 deletions src/writing-your-own-application/generate-project/esp-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project contains and try to understand every part of it.

When creating a project from [esp-template] with the following answers:
- Which MCU to target? · `esp32c3`
- Use template default values? · `true`
- Configure advanced template options? · `false`

For this explanation we will use the default values, if you want further modifications, see the [additional prompts] when not using default values.

Expand Down Expand Up @@ -59,15 +59,22 @@ use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::Time
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let mut system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
// Disable the RTC and TIMG watchdog timers
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let mut wdt1 = timer_group1.wdt;
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
rtc.swd.disable();
rtc.rwdt.disable();
wdt0.disable();
Expand Down Expand Up @@ -96,15 +103,15 @@ That is quite a lot of code. Let's see what it is good for.
- `let peripherals = Peripherals::take().unwrap();`
- HAL drivers usually take ownership of peripherals accessed via the PAC
- Here we take all the peripherals from the PAC to pass them to the HAL drivers later
- `let system = peripherals.SYSTEM.split();`
- `let mut system = peripherals.SYSTEM.split();`
- Sometimes a peripheral (here the System peripheral) is coarse-grained and doesn't exactly fit the HAL drivers - so here we split the System peripheral into smaller pieces which get passed to the drivers
- `let clocks = ClockControl::boot_defaults(system.clock_control).freeze();`
- Here we configure the system clocks - in this case, we are fine with the defaults
- We freeze the clocks, which means we cannot change them later
- Some drivers need a reference to the clocks to know how to calculate rates and durations
- The next block of code instantiates some peripherals (namely RTC and the two timer groups) to disable the watchdog, which is armed after boot
- Without that code, the SoC would reboot after some time
- There is another way to prevent the reboot: [feeding](https://docs.rs/esp32c3-hal/0.2.0/esp32c3_hal/prelude/trait._embedded_hal_watchdog_Watchdog.html#tymethod.feed) the watchdog
- There is another way to prevent the reboot: [feeding](https://docs.rs/esp32c3-hal/0.10.0/esp32c3_hal/prelude/trait._embedded_hal_watchdog_Watchdog.html#tymethod.feed) the watchdog
- `println!("Hello world!");`
- Prints "Hello Wolrd!"
- `loop {}`
Expand Down
2 changes: 1 addition & 1 deletion src/writing-your-own-application/generate-project/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Both templates are based on [cargo-generate], a tool that allows you to create a
2. Generate a project based in one of the templates:
- esp-template:
```shell
cargo generate -a esp-rs/esp-template
cargo generate esp-rs/esp-template
```
See [Understanding esp-template] for more details on the template project.
- esp-idf-template:
Expand Down

0 comments on commit 1108c87

Please sign in to comment.