Rust Embassy: Difference between revisions
Jump to navigation
Jump to search
Created page with "=Introduction= After spending some time on RTOS I wanted to compare using Rust to do the same thing. Embassy seem more used than the non-std rust. In fact getting the bluetooth to work seem too hard =Getting Started= For the older wroom-32 boards, they use xtensa chips. For this we need to install the toolchain <syntaxhighlight lang="bash"> cargo install espup espup install # To install Espressif Rust ecosystem . $HOME/export-esp.sh # This add stuff to the path </syntaxh..." |
|||
Line 8: | Line 8: | ||
. $HOME/export-esp.sh # This add stuff to the path | . $HOME/export-esp.sh # This add stuff to the path | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Once done we can create a project with | |||
<syntaxhighlight lang="bash"> | |||
cargo install esp-generate | |||
esp-generate --chip esp32 esp-blink | |||
</syntaxhighlight> | |||
=Blinky= | |||
The template provides this | |||
<syntaxhighlight lang="rs"> | |||
#![no_std] | |||
#![no_main] | |||
use embassy_executor::Spawner; | |||
use embassy_time::{Duration, Timer}; | |||
use esp_backtrace as _; | |||
use esp_hal::prelude::*; | |||
use log::info; | |||
#[main] | |||
async fn main(spawner: Spawner) { | |||
let peripherals = esp_hal::init({ | |||
let mut config = esp_hal::Config::default(); | |||
config.cpu_clock = CpuClock::max(); | |||
config | |||
}); | |||
esp_println::logger::init_logger_from_env(); | |||
let timer0 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1); | |||
esp_hal_embassy::init(timer0.timer0); | |||
info!("Embassy initialized!"); | |||
// TODO: Spawn some tasks | |||
let _ = spawner; | |||
loop { | |||
info!("Hello world!"); | |||
Timer::after(Duration::from_secs(1)).await; | |||
} | |||
} | |||
</syntaxhighlight> | |||
Could not find and led on my board so I used pin 23. |
Revision as of 23:42, 30 December 2024
Introduction
After spending some time on RTOS I wanted to compare using Rust to do the same thing. Embassy seem more used than the non-std rust. In fact getting the bluetooth to work seem too hard
Getting Started
For the older wroom-32 boards, they use xtensa chips. For this we need to install the toolchain
cargo install espup
espup install # To install Espressif Rust ecosystem
. $HOME/export-esp.sh # This add stuff to the path
Once done we can create a project with
cargo install esp-generate
esp-generate --chip esp32 esp-blink
Blinky
The template provides this
#![no_std]
#![no_main]
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::prelude::*;
use log::info;
#[main]
async fn main(spawner: Spawner) {
let peripherals = esp_hal::init({
let mut config = esp_hal::Config::default();
config.cpu_clock = CpuClock::max();
config
});
esp_println::logger::init_logger_from_env();
let timer0 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1);
esp_hal_embassy::init(timer0.timer0);
info!("Embassy initialized!");
// TODO: Spawn some tasks
let _ = spawner;
loop {
info!("Hello world!");
Timer::after(Duration::from_secs(1)).await;
}
}
Could not find and led on my board so I used pin 23.