embassy async counter is working properlywell

This commit is contained in:
Priec
2025-10-15 12:06:55 +02:00
parent e19a5853b5
commit 92d97206da
10 changed files with 1584 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
#![no_std]
#![no_main]
#![deny(
clippy::mem_forget,
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
holding buffers for the duration of a data transfer."
)]
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::{
clock::CpuClock,
gpio::{Level, Output, OutputConfig},
timer::timg::TimerGroup,
};
use log::info;
extern crate alloc;
esp_bootloader_esp_idf::esp_app_desc!();
#[embassy_executor::task]
async fn led_blink_task(mut led: Output<'static>) {
loop {
led.toggle();
info!("LED toggled");
Timer::after(Duration::from_secs(1)).await;
}
}
#[esp_hal_embassy::main]
async fn main(spawner: Spawner) {
esp_println::logger::init_logger_from_env();
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
esp_alloc::heap_allocator!(size: 64 * 1024);
let timer_group1 = TimerGroup::new(peripherals.TIMG1);
esp_hal_embassy::init(timer_group1.timer0);
let gpio4 = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
info!("Embassy initialized!");
// Spawn LED blink task - runs independently
spawner.spawn(led_blink_task(gpio4)).unwrap();
// CPU does other work here
let mut counter: u8 = 230;
loop {
info!("CPU doing other work: {}", counter);
counter = counter.wrapping_add(1);
Timer::after(Duration::from_millis(300)).await;
}
}

View File

@@ -0,0 +1 @@
#![no_std]