Compare commits
20 Commits
e249c39c7b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb533fcdac | ||
|
|
02971bd9e1 | ||
|
|
e6e22818e4 | ||
|
|
4f21d03822 | ||
|
|
31bc689c69 | ||
|
|
1c0a5672b3 | ||
|
|
92d97206da | ||
|
|
e19a5853b5 | ||
|
|
8af5dcbede | ||
|
|
200f37d794 | ||
|
|
dc05d3ed37 | ||
|
|
1a0c27afb2 | ||
|
|
737b4b1dfe | ||
|
|
4e9566678a | ||
|
|
75f038262b | ||
|
|
3181081b09 | ||
|
|
e132980c82 | ||
|
|
83b6465dc6 | ||
|
|
b4e86bded6 | ||
|
|
73cbf7f912 |
2
datasheet.txt
Normal file
2
datasheet.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf
|
||||||
|
https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf
|
||||||
27
final/Cargo.lock
generated
27
final/Cargo.lock
generated
@@ -336,7 +336,7 @@ dependencies = [
|
|||||||
"embassy-time 0.5.0",
|
"embassy-time 0.5.0",
|
||||||
"embedded-io-async",
|
"embedded-io-async",
|
||||||
"embedded-nal-async",
|
"embedded-nal-async",
|
||||||
"heapless",
|
"heapless 0.8.0",
|
||||||
"log",
|
"log",
|
||||||
"managed",
|
"managed",
|
||||||
"smoltcp",
|
"smoltcp",
|
||||||
@@ -359,7 +359,7 @@ dependencies = [
|
|||||||
"embedded-io-async",
|
"embedded-io-async",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"heapless",
|
"heapless 0.8.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -373,7 +373,7 @@ dependencies = [
|
|||||||
"embedded-io-async",
|
"embedded-io-async",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"heapless",
|
"heapless 0.8.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -425,7 +425,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "dc55c748d16908a65b166d09ce976575fb8852cf60ccd06174092b41064d8f83"
|
checksum = "dc55c748d16908a65b166d09ce976575fb8852cf60ccd06174092b41064d8f83"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"embassy-executor",
|
"embassy-executor",
|
||||||
"heapless",
|
"heapless 0.8.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -561,7 +561,7 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
"esp-config",
|
"esp-config",
|
||||||
"esp-println",
|
"esp-println",
|
||||||
"heapless",
|
"heapless 0.8.0",
|
||||||
"semihosting",
|
"semihosting",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -942,6 +942,16 @@ dependencies = [
|
|||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heapless"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1edcd5a338e64688fbdcb7531a846cfd3476a54784dcb918a0844682bc7ada5"
|
||||||
|
dependencies = [
|
||||||
|
"hash32",
|
||||||
|
"stable_deref_trait",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -1185,7 +1195,9 @@ dependencies = [
|
|||||||
"defmt-rtt",
|
"defmt-rtt",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"embassy-executor",
|
"embassy-executor",
|
||||||
|
"embassy-futures",
|
||||||
"embassy-net",
|
"embassy-net",
|
||||||
|
"embassy-sync 0.7.2",
|
||||||
"embassy-time 0.5.0",
|
"embassy-time 0.5.0",
|
||||||
"embedded-io",
|
"embedded-io",
|
||||||
"embedded-io-async",
|
"embedded-io-async",
|
||||||
@@ -1196,6 +1208,7 @@ dependencies = [
|
|||||||
"esp-hal-embassy",
|
"esp-hal-embassy",
|
||||||
"esp-println",
|
"esp-println",
|
||||||
"esp-wifi",
|
"esp-wifi",
|
||||||
|
"heapless 0.9.1",
|
||||||
"log",
|
"log",
|
||||||
"rust-mqtt",
|
"rust-mqtt",
|
||||||
"smoltcp",
|
"smoltcp",
|
||||||
@@ -1279,7 +1292,7 @@ dependencies = [
|
|||||||
"defmt 0.3.100",
|
"defmt 0.3.100",
|
||||||
"embedded-io",
|
"embedded-io",
|
||||||
"embedded-io-async",
|
"embedded-io-async",
|
||||||
"heapless",
|
"heapless 0.8.0",
|
||||||
"rand_core 0.6.4",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1347,7 +1360,7 @@ dependencies = [
|
|||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"heapless",
|
"heapless 0.8.0",
|
||||||
"log",
|
"log",
|
||||||
"managed",
|
"managed",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ smoltcp = { version = "0.12.0", default-features = false, features = [
|
|||||||
static_cell = "2.1.1"
|
static_cell = "2.1.1"
|
||||||
rust-mqtt = { version = "0.3.0", default-features = false, features = ["no_std"] }
|
rust-mqtt = { version = "0.3.0", default-features = false, features = ["no_std"] }
|
||||||
defmt-rtt = "1.0.0"
|
defmt-rtt = "1.0.0"
|
||||||
|
embassy-futures = "0.1.2"
|
||||||
|
embassy-sync = "0.7.2"
|
||||||
|
heapless = "0.9.1"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// src/bin/main.rs
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![deny(
|
#![deny(
|
||||||
@@ -6,18 +8,22 @@
|
|||||||
)]
|
)]
|
||||||
|
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_futures::select::{select, Either};
|
||||||
use embassy_net::{Runner, StackResources};
|
use embassy_net::{Runner, StackResources};
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use esp_alloc as _;
|
use esp_alloc as _;
|
||||||
use esp_backtrace as _;
|
use esp_backtrace as _;
|
||||||
use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup};
|
use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup};
|
||||||
use esp_wifi::{
|
use esp_wifi::{
|
||||||
EspWifiController,
|
|
||||||
init,
|
init,
|
||||||
wifi::{ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiState},
|
wifi::{ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiState},
|
||||||
|
EspWifiController,
|
||||||
};
|
};
|
||||||
use log::info;
|
use log::info;
|
||||||
use projekt_final::mqtt::client::mqtt_task;
|
use rust_mqtt::packet::v5::publish_packet::QualityOfService;
|
||||||
|
use projekt_final::mqtt::client::{
|
||||||
|
mqtt_events, mqtt_publish, mqtt_subscribe, mqtt_task, IncomingMsg,
|
||||||
|
};
|
||||||
use defmt_rtt as _;
|
use defmt_rtt as _;
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
@@ -52,7 +58,8 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
init(timg0.timer0, rng.clone()).unwrap()
|
init(timg0.timer0, rng.clone()).unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
let (controller, interfaces) = esp_wifi::wifi::new(&esp_wifi_ctrl, peripherals.WIFI).unwrap();
|
let (controller, interfaces) =
|
||||||
|
esp_wifi::wifi::new(&esp_wifi_ctrl, peripherals.WIFI).unwrap();
|
||||||
|
|
||||||
let wifi_interface = interfaces.sta;
|
let wifi_interface = interfaces.sta;
|
||||||
|
|
||||||
@@ -94,8 +101,42 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
spawner.spawn(mqtt_task(stack)).expect("failed to spawn MQTT task");
|
spawner.spawn(mqtt_task(stack)).expect("failed to spawn MQTT task");
|
||||||
info!("MQTT task started");
|
info!("MQTT task started");
|
||||||
|
|
||||||
|
mqtt_publish("esp32/topic", b"hello from ESP32 (init)", QualityOfService::QoS1, false).await;
|
||||||
|
info!("Sent initial MQTT message");
|
||||||
|
|
||||||
|
mqtt_subscribe("esp32/topic").await;
|
||||||
|
|
||||||
|
// Get a receiver for incoming MQTT messages
|
||||||
|
let mqtt_rx = mqtt_events();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
Timer::after(Duration::from_secs(60)).await;
|
// Drive both: either process an MQTT message or publish periodically
|
||||||
|
match select(mqtt_rx.receive(), Timer::after(Duration::from_secs(5))).await
|
||||||
|
{
|
||||||
|
// Received inbound MQTT message (from broker)
|
||||||
|
Either::First(msg) => {
|
||||||
|
handle_incoming(msg);
|
||||||
|
}
|
||||||
|
// Time-based example publish
|
||||||
|
Either::Second(_) => {
|
||||||
|
// mqtt_publish(
|
||||||
|
// "esp32/topic",
|
||||||
|
// b"hello from main",
|
||||||
|
// QualityOfService::QoS1,
|
||||||
|
// false,
|
||||||
|
// )
|
||||||
|
// .await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_incoming(msg: IncomingMsg) {
|
||||||
|
if let Ok(txt) = core::str::from_utf8(&msg.payload) {
|
||||||
|
info!("MAIN RX [{}]: {}", msg.topic.as_str(), txt);
|
||||||
|
info!("Received MQTT message -> topic: '{}', payload: '{}'", msg.topic.as_str(), txt);
|
||||||
|
} else {
|
||||||
|
info!("MAIN RX [{}]: {:?}", msg.topic.as_str(), msg.payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// src/mqtt/client.rs
|
// src/mqtt/client.rs
|
||||||
|
use embassy_futures::select::{select, Either};
|
||||||
use embassy_net::{tcp::TcpSocket, Stack};
|
use embassy_net::{tcp::TcpSocket, Stack};
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use log::info;
|
use log::info;
|
||||||
@@ -9,9 +10,22 @@ use rust_mqtt::packet::v5::reason_codes::ReasonCode;
|
|||||||
use rust_mqtt::utils::rng_generator::CountingRng;
|
use rust_mqtt::utils::rng_generator::CountingRng;
|
||||||
use static_cell::ConstStaticCell;
|
use static_cell::ConstStaticCell;
|
||||||
|
|
||||||
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
|
use embassy_sync::channel::{Channel, Receiver};
|
||||||
|
|
||||||
|
use heapless::{String as HString, Vec as HVec};
|
||||||
|
|
||||||
use crate::mqtt::config::mqtt_broker_endpoint;
|
use crate::mqtt::config::mqtt_broker_endpoint;
|
||||||
|
|
||||||
const RECONNECT_DELAY_SECS: u64 = 5;
|
const RECONNECT_DELAY_SECS: u64 = 5;
|
||||||
|
const KEEPALIVE_SECS: u64 = 60;
|
||||||
|
const PING_PERIOD: Duration = Duration::from_secs(KEEPALIVE_SECS / 2);
|
||||||
|
|
||||||
|
// Limits for small, static buffers (no heap)
|
||||||
|
pub const TOPIC_MAX: usize = 128;
|
||||||
|
pub const PAYLOAD_MAX: usize = 512;
|
||||||
|
const COMMAND_QUEUE: usize = 8;
|
||||||
|
const EVENT_QUEUE: usize = 8;
|
||||||
|
|
||||||
// TCP socket buffers (for embassy-net TcpSocket)
|
// TCP socket buffers (for embassy-net TcpSocket)
|
||||||
static TCP_RX_BUFFER: ConstStaticCell<[u8; 2048]> = ConstStaticCell::new([0; 2048]);
|
static TCP_RX_BUFFER: ConstStaticCell<[u8; 2048]> = ConstStaticCell::new([0; 2048]);
|
||||||
@@ -21,16 +35,72 @@ static TCP_TX_BUFFER: ConstStaticCell<[u8; 2048]> = ConstStaticCell::new([0; 204
|
|||||||
static MQTT_TX_BUF: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0; 1024]);
|
static MQTT_TX_BUF: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0; 1024]);
|
||||||
static MQTT_RX_BUF: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0; 1024]);
|
static MQTT_RX_BUF: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0; 1024]);
|
||||||
|
|
||||||
// Type alias for clarity in helper functions
|
// Tie TcpSocket lifetime to session
|
||||||
// NOTE: Tie the TcpSocket lifetime to the session (not 'static), and
|
|
||||||
// the MQTT buffers lifetime to 'a. This resolves the E0521 error.
|
|
||||||
// The const 8 is the MAX_PROPERTIES generic used by rust-mqtt config.
|
|
||||||
type Client<'a, 'net> = MqttClient<'a, TcpSocket<'net>, 8, CountingRng>;
|
type Client<'a, 'net> = MqttClient<'a, TcpSocket<'net>, 8, CountingRng>;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct PublishMsg {
|
||||||
|
topic: HString<TOPIC_MAX>,
|
||||||
|
payload: HVec<u8, PAYLOAD_MAX>,
|
||||||
|
qos: QualityOfService,
|
||||||
|
retain: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
enum MqttCommand {
|
||||||
|
Publish(PublishMsg),
|
||||||
|
Subscribe(HString<TOPIC_MAX>),
|
||||||
|
}
|
||||||
|
|
||||||
|
static CMD_CHAN: Channel<CriticalSectionRawMutex, MqttCommand, COMMAND_QUEUE> = Channel::new();
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct IncomingMsg {
|
||||||
|
pub topic: HString<TOPIC_MAX>,
|
||||||
|
pub payload: HVec<u8, PAYLOAD_MAX>,
|
||||||
|
}
|
||||||
|
|
||||||
|
static EVT_CHAN: Channel<CriticalSectionRawMutex, IncomingMsg, EVENT_QUEUE> = Channel::new();
|
||||||
|
|
||||||
|
// Public API for main
|
||||||
|
pub async fn mqtt_publish(
|
||||||
|
topic: &str,
|
||||||
|
payload: &[u8],
|
||||||
|
qos: QualityOfService,
|
||||||
|
retain: bool,
|
||||||
|
) {
|
||||||
|
let mut t: HString<TOPIC_MAX> = HString::new();
|
||||||
|
let _ = t.push_str(&topic[..core::cmp::min(topic.len(), TOPIC_MAX)]);
|
||||||
|
let mut p: HVec<u8, PAYLOAD_MAX> = HVec::new();
|
||||||
|
let take = core::cmp::min(payload.len(), PAYLOAD_MAX);
|
||||||
|
let _ = p.extend_from_slice(&payload[..take]);
|
||||||
|
|
||||||
|
CMD_CHAN
|
||||||
|
.send(MqttCommand::Publish(PublishMsg {
|
||||||
|
topic: t,
|
||||||
|
payload: p,
|
||||||
|
qos,
|
||||||
|
retain,
|
||||||
|
}))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn mqtt_subscribe(topic: &str) {
|
||||||
|
let mut t: HString<TOPIC_MAX> = HString::new();
|
||||||
|
let _ = t.push_str(&topic[..core::cmp::min(topic.len(), TOPIC_MAX)]);
|
||||||
|
CMD_CHAN.send(MqttCommand::Subscribe(t)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Receiver for incoming MQTT messages
|
||||||
|
pub fn mqtt_events(
|
||||||
|
) -> Receiver<'static, CriticalSectionRawMutex, IncomingMsg, EVENT_QUEUE> {
|
||||||
|
EVT_CHAN.receiver()
|
||||||
|
}
|
||||||
|
|
||||||
fn build_client_config() -> ClientConfig<'static, 8, CountingRng> {
|
fn build_client_config() -> ClientConfig<'static, 8, CountingRng> {
|
||||||
let rng = CountingRng(0);
|
let rng = CountingRng(0);
|
||||||
let mut cfg: ClientConfig<'static, 8, _> = ClientConfig::new(MqttVersion::MQTTv5, rng);
|
let mut cfg: ClientConfig<'static, 8, _> = ClientConfig::new(MqttVersion::MQTTv5, rng);
|
||||||
cfg.keep_alive = 60;
|
cfg.keep_alive = KEEPALIVE_SECS as u16;
|
||||||
cfg.add_client_id("esp32-client");
|
cfg.add_client_id("esp32-client");
|
||||||
cfg
|
cfg
|
||||||
}
|
}
|
||||||
@@ -63,28 +133,84 @@ async fn connect_mqtt(client: &mut Client<'_, '_>) -> Result<(), ReasonCode> {
|
|||||||
client.connect_to_broker().await
|
client.connect_to_broker().await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn publish_once(client: &mut Client<'_, '_>) -> Result<(), ReasonCode> {
|
// While connected, handle publishes, subscribes, ping, and incoming messages
|
||||||
client
|
async fn connected_loop(client: &mut Client<'_, '_>) -> Result<(), ReasonCode> {
|
||||||
.send_message(
|
// Subscribe to a default topic on connect (optional). You can remove this
|
||||||
"esp32/topic",
|
// if you always subscribe from main via mqtt_subscribe().
|
||||||
b"hello from esp32",
|
let default_topic = "esp32/topic";
|
||||||
QualityOfService::QoS1,
|
match client.subscribe_to_topic(default_topic).await {
|
||||||
false,
|
Ok(_) => info!("Subscribed to '{}'", default_topic),
|
||||||
)
|
Err(e) => {
|
||||||
.await
|
info!("Default subscribe failed: {:?}", e);
|
||||||
}
|
// Not fatal: continue
|
||||||
|
}
|
||||||
async fn ping_loop(client: &mut Client<'_, '_>) -> Result<(), ReasonCode> {
|
}
|
||||||
loop {
|
|
||||||
if let Err(reason) = client.send_ping().await {
|
loop {
|
||||||
info!("MQTT ping failed: {:?}", reason);
|
// Nested select so we react to incoming publishes ASAP, while still
|
||||||
return Err(reason);
|
// sending keepalive pings on schedule and servicing commands.
|
||||||
|
let in_or_ping = async {
|
||||||
|
select(client.receive_message(), Timer::after(PING_PERIOD)).await
|
||||||
|
};
|
||||||
|
|
||||||
|
match select(CMD_CHAN.receive(), in_or_ping).await {
|
||||||
|
// Command from main (publish/subscribe)
|
||||||
|
Either::First(cmd) => match cmd {
|
||||||
|
MqttCommand::Publish(m) => {
|
||||||
|
if let Err(e) = client
|
||||||
|
.send_message(
|
||||||
|
m.topic.as_str(),
|
||||||
|
&m.payload,
|
||||||
|
m.qos,
|
||||||
|
m.retain,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MqttCommand::Subscribe(topic) => {
|
||||||
|
match client.subscribe_to_topic(topic.as_str()).await {
|
||||||
|
Ok(_) => info!("Subscribed to '{}'", topic.as_str()),
|
||||||
|
Err(e) => {
|
||||||
|
info!(
|
||||||
|
"Subscribe failed for '{}': {:?}",
|
||||||
|
topic.as_str(),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Either an incoming publish or the ping timer fired
|
||||||
|
Either::Second(e) => match e {
|
||||||
|
// Got a PUBLISH from broker
|
||||||
|
Either::First(Ok((topic, msg))) => {
|
||||||
|
let mut t: HString<TOPIC_MAX> = HString::new();
|
||||||
|
let _ = t.push_str(
|
||||||
|
&topic[..core::cmp::min(topic.len(), TOPIC_MAX)],
|
||||||
|
);
|
||||||
|
let mut p: HVec<u8, PAYLOAD_MAX> = HVec::new();
|
||||||
|
let take = core::cmp::min(msg.len(), PAYLOAD_MAX);
|
||||||
|
let _ = p.extend_from_slice(&msg[..take]);
|
||||||
|
EVT_CHAN
|
||||||
|
.send(IncomingMsg { topic: t, payload: p })
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
Either::First(Err(e)) => {
|
||||||
|
info!("MQTT receive error (reconnect): {:?}", e);
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
Either::Second(_) => {
|
||||||
|
client.send_ping().await?;
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
Timer::after(Duration::from_secs(30)).await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// One full MQTT session: TCP connect -> MQTT connect -> (optional) publish -> ping loop
|
// Full session: TCP connect -> MQTT connect -> connected loop
|
||||||
async fn run_one_session(
|
async fn run_one_session(
|
||||||
stack: Stack<'static>,
|
stack: Stack<'static>,
|
||||||
tcp_rx: &mut [u8],
|
tcp_rx: &mut [u8],
|
||||||
@@ -92,13 +218,11 @@ async fn run_one_session(
|
|||||||
mqtt_tx: &mut [u8],
|
mqtt_tx: &mut [u8],
|
||||||
mqtt_rx: &mut [u8],
|
mqtt_rx: &mut [u8],
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
// Build socket and connect TCP
|
|
||||||
let mut socket = TcpSocket::new(stack, tcp_rx, tcp_tx);
|
let mut socket = TcpSocket::new(stack, tcp_rx, tcp_tx);
|
||||||
if connect_tcp(&mut socket).await.is_err() {
|
if connect_tcp(&mut socket).await.is_err() {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build client and connect MQTT
|
|
||||||
let mut client = build_client(socket, mqtt_tx, mqtt_rx);
|
let mut client = build_client(socket, mqtt_tx, mqtt_rx);
|
||||||
match connect_mqtt(&mut client).await {
|
match connect_mqtt(&mut client).await {
|
||||||
Ok(_) => info!("MQTT CONNACK received"),
|
Ok(_) => info!("MQTT CONNACK received"),
|
||||||
@@ -108,14 +232,7 @@ async fn run_one_session(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optional demo publish (same behavior as before)
|
connected_loop(&mut client).await.map_err(|_| ())
|
||||||
match publish_once(&mut client).await {
|
|
||||||
Ok(_) => info!("MQTT PUBLISH sent"),
|
|
||||||
Err(reason) => info!("MQTT publish failed: {:?}", reason),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keepalive. Any error ends the session; outer loop will reconnect.
|
|
||||||
ping_loop(&mut client).await.map_err(|_| ())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
@@ -123,10 +240,10 @@ pub async fn mqtt_task(stack: Stack<'static>) {
|
|||||||
info!("MQTT task starting...");
|
info!("MQTT task starting...");
|
||||||
|
|
||||||
// Take static buffers once and reuse across reconnects
|
// Take static buffers once and reuse across reconnects
|
||||||
let mut tcp_rx = TCP_RX_BUFFER.take();
|
let tcp_rx = TCP_RX_BUFFER.take();
|
||||||
let mut tcp_tx = TCP_TX_BUFFER.take();
|
let tcp_tx = TCP_TX_BUFFER.take();
|
||||||
let mut mqtt_tx = MQTT_TX_BUF.take();
|
let mqtt_tx = MQTT_TX_BUF.take();
|
||||||
let mut mqtt_rx = MQTT_RX_BUF.take();
|
let mqtt_rx = MQTT_RX_BUF.take();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let _ = run_one_session(
|
let _ = run_one_session(
|
||||||
|
|||||||
33
flake.nix
33
flake.nix
@@ -21,28 +21,37 @@
|
|||||||
gcc
|
gcc
|
||||||
gnumake
|
gnumake
|
||||||
rustup
|
rustup
|
||||||
|
rust-analyzer
|
||||||
cargo-espflash
|
cargo-espflash
|
||||||
espup
|
espup
|
||||||
|
mosquitto
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
echo ">>> ESP32 DevShell (esp-hal only)"
|
echo ">>> ESP32 DevShell (esp-hal only)"
|
||||||
|
|
||||||
if [ ! -d "$HOME/.espup" ]; then
|
if [ ! -d "$HOME/.espup" ]; then
|
||||||
echo "Running espup install..."
|
echo "Running espup install..."
|
||||||
espup install
|
espup install
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Activate Xtensa Rust toolchain
|
# Ensure the real rust-analyzer from Nix is used (not rustup's shim)
|
||||||
export RUSTUP_TOOLCHAIN=esp
|
export PATH=${pkgs.rust-analyzer}/bin:$PATH
|
||||||
|
|
||||||
|
# Keep ESP toolchain binaries on PATH for building/flashing
|
||||||
|
# (do NOT set RUSTUP_TOOLCHAIN=esp globally; that breaks rust-analyzer)
|
||||||
export PATH=$HOME/.rustup/toolchains/esp/bin:$PATH
|
export PATH=$HOME/.rustup/toolchains/esp/bin:$PATH
|
||||||
|
|
||||||
# Add GCC/binutils path for xtensa-esp32-elf-gcc
|
# Add GCC/binutils path for xtensa-esp32-elf-gcc
|
||||||
export PATH=$HOME/.rustup/toolchains/esp/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin:$PATH
|
export PATH=$HOME/.rustup/toolchains/esp/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin:$PATH
|
||||||
|
|
||||||
echo "Xtensa Rust toolchain ready."
|
# Helpers that force the ESP toolchain explicitly when needed
|
||||||
rustc --version
|
alias cargo-esp="RUSTUP_TOOLCHAIN=esp cargo"
|
||||||
which xtensa-esp32-elf-gcc || echo "⚠️ xtensa-esp32-elf-gcc not found in PATH"
|
alias rustc-esp="RUSTUP_TOOLCHAIN=esp rustc"
|
||||||
|
|
||||||
|
echo "Xtensa Rust toolchain ready."
|
||||||
|
rustc --version
|
||||||
|
which xtensa-esp32-elf-gcc || echo "⚠️ xtensa-esp32-elf-gcc not found in PATH"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
# MQTT Implementation Notes
|
|
||||||
|
|
||||||
* WiFi connection runs in a separate task with auto-reconnect functionality
|
|
||||||
* Network stack operates in a dedicated packet processing task
|
|
||||||
* MQTT uses TCP socket connection (MqttClient wraps this socket)
|
|
||||||
* ClientConfig specifies: MQTT version, QoS levels, client ID
|
|
||||||
* Standard flow: connect_to_broker() → send_message() or subscribe()
|
|
||||||
|
|
||||||
## Implementation:
|
|
||||||
1. Perform DNS lookup for broker hostname
|
|
||||||
2. Establish TCP socket connection
|
|
||||||
3. Create MqttClient with configuration
|
|
||||||
4. Implement connect, publish, and subscribe logic
|
|
||||||
16
test_LED2/.cargo/config.toml
Normal file
16
test_LED2/.cargo/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[target.xtensa-esp32-none-elf]
|
||||||
|
runner = "espflash flash --monitor --chip esp32"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
ESP_LOG="info"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-nostartfiles",
|
||||||
|
"-Z", "stack-protector=all",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "xtensa-esp32-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["alloc", "core"]
|
||||||
2
test_LED2/.env_temp
Normal file
2
test_LED2/.env_temp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SSID = "nazov_wifi_siete"
|
||||||
|
PASSWORD = "heslo_od_wifi"
|
||||||
20
test_LED2/.gitignore
vendored
Normal file
20
test_LED2/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
.vscode/
|
||||||
|
.zed/
|
||||||
|
.helix/
|
||||||
|
.env
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
1343
test_LED2/Cargo.lock
generated
Normal file
1343
test_LED2/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
68
test_LED2/Cargo.toml
Normal file
68
test_LED2/Cargo.toml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "test1"
|
||||||
|
rust-version = "1.86"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "test1"
|
||||||
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||||
|
esp-hal = { version = "=1.0.0-rc.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"log-04",
|
||||||
|
"unstable",
|
||||||
|
] }
|
||||||
|
log = "0.4.27"
|
||||||
|
embedded-io = "0.6.1"
|
||||||
|
embedded-io-async = "0.6.1"
|
||||||
|
esp-alloc = "0.8.0"
|
||||||
|
esp-backtrace = { version = "0.17.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"exception-handler",
|
||||||
|
"panic-handler",
|
||||||
|
"println",
|
||||||
|
] }
|
||||||
|
esp-println = { version = "0.15.0", features = ["esp32", "log-04"] }
|
||||||
|
# for more networking protocol support see https://crates.io/crates/edge-net
|
||||||
|
critical-section = "1.2.0"
|
||||||
|
embassy-executor = { version = "0.7.0", features = [
|
||||||
|
"log",
|
||||||
|
"task-arena-size-20480",
|
||||||
|
] }
|
||||||
|
embassy-time = { version = "0.4.0", features = ["log"] }
|
||||||
|
esp-hal-embassy = { version = "0.9.0", features = ["esp32", "log-04"] }
|
||||||
|
smoltcp = { version = "0.12.0", default-features = false, features = [
|
||||||
|
"log",
|
||||||
|
"medium-ethernet",
|
||||||
|
"multicast",
|
||||||
|
"proto-dhcpv4",
|
||||||
|
"proto-dns",
|
||||||
|
"proto-ipv4",
|
||||||
|
"socket-dns",
|
||||||
|
"socket-icmp",
|
||||||
|
"socket-raw",
|
||||||
|
"socket-tcp",
|
||||||
|
"socket-udp",
|
||||||
|
] }
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
heapless = "0.9.1"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Rust debug is too slow.
|
||||||
|
# For debug builds always builds with some optimization
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 's'
|
||||||
|
overflow-checks = false
|
||||||
9
test_LED2/Makefile
Normal file
9
test_LED2/Makefile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.PHONY: all build flash
|
||||||
|
|
||||||
|
all: build flash
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
flash:
|
||||||
|
cargo espflash flash --release --monitor
|
||||||
65
test_LED2/build.rs
Normal file
65
test_LED2/build.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
fn main() {
|
||||||
|
// load .env and pass SSID/PASSWORD to compiler
|
||||||
|
if let Ok(dotenv_path) = dotenvy::dotenv() {
|
||||||
|
// Only rebuild if .env changes
|
||||||
|
println!("cargo:rerun-if-changed={}", dotenv_path.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(ssid) = std::env::var("SSID") {
|
||||||
|
println!("cargo:rustc-env=SSID={}", ssid);
|
||||||
|
}
|
||||||
|
if let Ok(password) = std::env::var("PASSWORD") {
|
||||||
|
println!("cargo:rustc-env=PASSWORD={}", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
linker_be_nice();
|
||||||
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn linker_be_nice() {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
let kind = &args[1];
|
||||||
|
let what = &args[2];
|
||||||
|
|
||||||
|
match kind.as_str() {
|
||||||
|
"undefined-symbol" => match what.as_str() {
|
||||||
|
"_defmt_timestamp" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"_stack_start" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"esp_wifi_preempt_enable"
|
||||||
|
| "esp_wifi_preempt_yield_task"
|
||||||
|
| "esp_wifi_preempt_task_create" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide an external scheduler.");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
// we don't have anything helpful for "missing-lib" yet
|
||||||
|
_ => {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-Wl,--error-handling-script={}",
|
||||||
|
std::env::current_exe().unwrap().display()
|
||||||
|
);
|
||||||
|
}
|
||||||
2
test_LED2/rust-toolchain.toml
Normal file
2
test_LED2/rust-toolchain.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "esp"
|
||||||
49
test_LED2/src/bin/main.rs
Normal file
49
test_LED2/src/bin/main.rs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#![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::gpio::{Output, Level, OutputConfig};
|
||||||
|
use esp_hal::clock::CpuClock;
|
||||||
|
use esp_hal::timer::timg::TimerGroup;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
// This creates a default app-descriptor required by the esp-idf bootloader.
|
||||||
|
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
||||||
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
|
#[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 timer0 = TimerGroup::new(peripherals.TIMG1);
|
||||||
|
esp_hal_embassy::init(timer0.timer0);
|
||||||
|
|
||||||
|
// Initialize GPIO4 as output (starts LOW)
|
||||||
|
let mut gpio4 = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
|
||||||
|
|
||||||
|
info!("Embassy initialized!");
|
||||||
|
loop {
|
||||||
|
gpio4.set_high();
|
||||||
|
info!("GPIO4 ON");
|
||||||
|
Timer::after(Duration::from_secs(1)).await;
|
||||||
|
|
||||||
|
gpio4.set_low();
|
||||||
|
info!("GPIO4 OFF");
|
||||||
|
Timer::after(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
|
||||||
|
}
|
||||||
1
test_LED2/src/lib.rs
Normal file
1
test_LED2/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#![no_std]
|
||||||
16
test_LED3_timer/.cargo/config.toml
Normal file
16
test_LED3_timer/.cargo/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[target.xtensa-esp32-none-elf]
|
||||||
|
runner = "espflash flash --monitor --chip esp32"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
ESP_LOG="info"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-nostartfiles",
|
||||||
|
"-Z", "stack-protector=all",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "xtensa-esp32-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["alloc", "core"]
|
||||||
2
test_LED3_timer/.env_temp
Normal file
2
test_LED3_timer/.env_temp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SSID = "nazov_wifi_siete"
|
||||||
|
PASSWORD = "heslo_od_wifi"
|
||||||
20
test_LED3_timer/.gitignore
vendored
Normal file
20
test_LED3_timer/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
.vscode/
|
||||||
|
.zed/
|
||||||
|
.helix/
|
||||||
|
.env
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
1343
test_LED3_timer/Cargo.lock
generated
Normal file
1343
test_LED3_timer/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
68
test_LED3_timer/Cargo.toml
Normal file
68
test_LED3_timer/Cargo.toml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "test1"
|
||||||
|
rust-version = "1.86"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "test1"
|
||||||
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||||
|
esp-hal = { version = "=1.0.0-rc.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"log-04",
|
||||||
|
"unstable",
|
||||||
|
] }
|
||||||
|
log = "0.4.27"
|
||||||
|
embedded-io = "0.6.1"
|
||||||
|
embedded-io-async = "0.6.1"
|
||||||
|
esp-alloc = "0.8.0"
|
||||||
|
esp-backtrace = { version = "0.17.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"exception-handler",
|
||||||
|
"panic-handler",
|
||||||
|
"println",
|
||||||
|
] }
|
||||||
|
esp-println = { version = "0.15.0", features = ["esp32", "log-04"] }
|
||||||
|
# for more networking protocol support see https://crates.io/crates/edge-net
|
||||||
|
critical-section = "1.2.0"
|
||||||
|
embassy-executor = { version = "0.7.0", features = [
|
||||||
|
"log",
|
||||||
|
"task-arena-size-20480",
|
||||||
|
] }
|
||||||
|
embassy-time = { version = "0.4.0", features = ["log"] }
|
||||||
|
esp-hal-embassy = { version = "0.9.0", features = ["esp32", "log-04"] }
|
||||||
|
smoltcp = { version = "0.12.0", default-features = false, features = [
|
||||||
|
"log",
|
||||||
|
"medium-ethernet",
|
||||||
|
"multicast",
|
||||||
|
"proto-dhcpv4",
|
||||||
|
"proto-dns",
|
||||||
|
"proto-ipv4",
|
||||||
|
"socket-dns",
|
||||||
|
"socket-icmp",
|
||||||
|
"socket-raw",
|
||||||
|
"socket-tcp",
|
||||||
|
"socket-udp",
|
||||||
|
] }
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
heapless = "0.9.1"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Rust debug is too slow.
|
||||||
|
# For debug builds always builds with some optimization
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 's'
|
||||||
|
overflow-checks = false
|
||||||
12
test_LED3_timer/Makefile
Normal file
12
test_LED3_timer/Makefile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
.PHONY: all build flash
|
||||||
|
|
||||||
|
all: build flash
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
flash:
|
||||||
|
cargo espflash flash --release --monitor
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo espflash erase-flash
|
||||||
65
test_LED3_timer/build.rs
Normal file
65
test_LED3_timer/build.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
fn main() {
|
||||||
|
// load .env and pass SSID/PASSWORD to compiler
|
||||||
|
if let Ok(dotenv_path) = dotenvy::dotenv() {
|
||||||
|
// Only rebuild if .env changes
|
||||||
|
println!("cargo:rerun-if-changed={}", dotenv_path.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(ssid) = std::env::var("SSID") {
|
||||||
|
println!("cargo:rustc-env=SSID={}", ssid);
|
||||||
|
}
|
||||||
|
if let Ok(password) = std::env::var("PASSWORD") {
|
||||||
|
println!("cargo:rustc-env=PASSWORD={}", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
linker_be_nice();
|
||||||
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn linker_be_nice() {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
let kind = &args[1];
|
||||||
|
let what = &args[2];
|
||||||
|
|
||||||
|
match kind.as_str() {
|
||||||
|
"undefined-symbol" => match what.as_str() {
|
||||||
|
"_defmt_timestamp" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"_stack_start" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"esp_wifi_preempt_enable"
|
||||||
|
| "esp_wifi_preempt_yield_task"
|
||||||
|
| "esp_wifi_preempt_task_create" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide an external scheduler.");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
// we don't have anything helpful for "missing-lib" yet
|
||||||
|
_ => {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-Wl,--error-handling-script={}",
|
||||||
|
std::env::current_exe().unwrap().display()
|
||||||
|
);
|
||||||
|
}
|
||||||
2
test_LED3_timer/rust-toolchain.toml
Normal file
2
test_LED3_timer/rust-toolchain.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "esp"
|
||||||
66
test_LED3_timer/src/bin/main.rs
Normal file
66
test_LED3_timer/src/bin/main.rs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#![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::Timer,
|
||||||
|
timer::timg::TimerGroup,
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
// This creates a default app-descriptor required by the esp-idf bootloader.
|
||||||
|
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
||||||
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
|
#[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);
|
||||||
|
let timer0 = timer_group1.timer0;
|
||||||
|
|
||||||
|
// Initialize GPIO4 as output (starts LOW)
|
||||||
|
let mut gpio4 = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
|
||||||
|
|
||||||
|
info!("Embassy initialized!");
|
||||||
|
loop {
|
||||||
|
gpio4.set_high();
|
||||||
|
info!("GPIO4 ON");
|
||||||
|
|
||||||
|
// Start timer for 1 second and block until done
|
||||||
|
let duration = Duration::from_secs(1);
|
||||||
|
timer0.load_value(duration).unwrap();
|
||||||
|
timer0.start();
|
||||||
|
info!("{:?}", duration);
|
||||||
|
|
||||||
|
// Wait until timer completes
|
||||||
|
while !timer0.is_interrupt_set() {}
|
||||||
|
timer0.clear_interrupt();
|
||||||
|
|
||||||
|
gpio4.set_low();
|
||||||
|
info!("GPIO4 OFF");
|
||||||
|
|
||||||
|
// Start timer for 1 second and block until done
|
||||||
|
timer0.load_value(duration).unwrap();
|
||||||
|
timer0.start();
|
||||||
|
|
||||||
|
while !timer0.is_interrupt_set() {}
|
||||||
|
timer0.clear_interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
1
test_LED3_timer/src/lib.rs
Normal file
1
test_LED3_timer/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#![no_std]
|
||||||
16
test_LED4_soft_interrupt/.cargo/config.toml
Normal file
16
test_LED4_soft_interrupt/.cargo/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[target.xtensa-esp32-none-elf]
|
||||||
|
runner = "espflash flash --monitor --chip esp32"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
ESP_LOG="info"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-nostartfiles",
|
||||||
|
"-Z", "stack-protector=all",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "xtensa-esp32-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["alloc", "core"]
|
||||||
2
test_LED4_soft_interrupt/.env_temp
Normal file
2
test_LED4_soft_interrupt/.env_temp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SSID = "nazov_wifi_siete"
|
||||||
|
PASSWORD = "heslo_od_wifi"
|
||||||
20
test_LED4_soft_interrupt/.gitignore
vendored
Normal file
20
test_LED4_soft_interrupt/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
.vscode/
|
||||||
|
.zed/
|
||||||
|
.helix/
|
||||||
|
.env
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
1343
test_LED4_soft_interrupt/Cargo.lock
generated
Normal file
1343
test_LED4_soft_interrupt/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
68
test_LED4_soft_interrupt/Cargo.toml
Normal file
68
test_LED4_soft_interrupt/Cargo.toml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "test1"
|
||||||
|
rust-version = "1.86"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "test1"
|
||||||
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||||
|
esp-hal = { version = "=1.0.0-rc.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"log-04",
|
||||||
|
"unstable",
|
||||||
|
] }
|
||||||
|
log = "0.4.27"
|
||||||
|
embedded-io = "0.6.1"
|
||||||
|
embedded-io-async = "0.6.1"
|
||||||
|
esp-alloc = "0.8.0"
|
||||||
|
esp-backtrace = { version = "0.17.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"exception-handler",
|
||||||
|
"panic-handler",
|
||||||
|
"println",
|
||||||
|
] }
|
||||||
|
esp-println = { version = "0.15.0", features = ["esp32", "log-04"] }
|
||||||
|
# for more networking protocol support see https://crates.io/crates/edge-net
|
||||||
|
critical-section = "1.2.0"
|
||||||
|
embassy-executor = { version = "0.7.0", features = [
|
||||||
|
"log",
|
||||||
|
"task-arena-size-20480",
|
||||||
|
] }
|
||||||
|
embassy-time = { version = "0.4.0", features = ["log"] }
|
||||||
|
esp-hal-embassy = { version = "0.9.0", features = ["esp32", "log-04"] }
|
||||||
|
smoltcp = { version = "0.12.0", default-features = false, features = [
|
||||||
|
"log",
|
||||||
|
"medium-ethernet",
|
||||||
|
"multicast",
|
||||||
|
"proto-dhcpv4",
|
||||||
|
"proto-dns",
|
||||||
|
"proto-ipv4",
|
||||||
|
"socket-dns",
|
||||||
|
"socket-icmp",
|
||||||
|
"socket-raw",
|
||||||
|
"socket-tcp",
|
||||||
|
"socket-udp",
|
||||||
|
] }
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
heapless = "0.9.1"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Rust debug is too slow.
|
||||||
|
# For debug builds always builds with some optimization
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 's'
|
||||||
|
overflow-checks = false
|
||||||
12
test_LED4_soft_interrupt/Makefile
Normal file
12
test_LED4_soft_interrupt/Makefile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
.PHONY: all build flash
|
||||||
|
|
||||||
|
all: build flash
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
flash:
|
||||||
|
cargo espflash flash --release --monitor
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo espflash erase-flash
|
||||||
65
test_LED4_soft_interrupt/build.rs
Normal file
65
test_LED4_soft_interrupt/build.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
fn main() {
|
||||||
|
// load .env and pass SSID/PASSWORD to compiler
|
||||||
|
if let Ok(dotenv_path) = dotenvy::dotenv() {
|
||||||
|
// Only rebuild if .env changes
|
||||||
|
println!("cargo:rerun-if-changed={}", dotenv_path.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(ssid) = std::env::var("SSID") {
|
||||||
|
println!("cargo:rustc-env=SSID={}", ssid);
|
||||||
|
}
|
||||||
|
if let Ok(password) = std::env::var("PASSWORD") {
|
||||||
|
println!("cargo:rustc-env=PASSWORD={}", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
linker_be_nice();
|
||||||
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn linker_be_nice() {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
let kind = &args[1];
|
||||||
|
let what = &args[2];
|
||||||
|
|
||||||
|
match kind.as_str() {
|
||||||
|
"undefined-symbol" => match what.as_str() {
|
||||||
|
"_defmt_timestamp" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"_stack_start" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"esp_wifi_preempt_enable"
|
||||||
|
| "esp_wifi_preempt_yield_task"
|
||||||
|
| "esp_wifi_preempt_task_create" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide an external scheduler.");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
// we don't have anything helpful for "missing-lib" yet
|
||||||
|
_ => {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-Wl,--error-handling-script={}",
|
||||||
|
std::env::current_exe().unwrap().display()
|
||||||
|
);
|
||||||
|
}
|
||||||
2
test_LED4_soft_interrupt/rust-toolchain.toml
Normal file
2
test_LED4_soft_interrupt/rust-toolchain.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "esp"
|
||||||
55
test_LED4_soft_interrupt/src/bin/main.rs
Normal file
55
test_LED4_soft_interrupt/src/bin/main.rs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
test_LED4_soft_interrupt/src/lib.rs
Normal file
1
test_LED4_soft_interrupt/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#![no_std]
|
||||||
16
test_LED5_hard_interrupt/.cargo/config.toml
Normal file
16
test_LED5_hard_interrupt/.cargo/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[target.xtensa-esp32-none-elf]
|
||||||
|
runner = "espflash flash --monitor --chip esp32"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
ESP_LOG="info"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-nostartfiles",
|
||||||
|
"-Z", "stack-protector=all",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "xtensa-esp32-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["alloc", "core"]
|
||||||
2
test_LED5_hard_interrupt/.env_temp
Normal file
2
test_LED5_hard_interrupt/.env_temp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SSID = "nazov_wifi_siete"
|
||||||
|
PASSWORD = "heslo_od_wifi"
|
||||||
20
test_LED5_hard_interrupt/.gitignore
vendored
Normal file
20
test_LED5_hard_interrupt/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
.vscode/
|
||||||
|
.zed/
|
||||||
|
.helix/
|
||||||
|
.env
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
1343
test_LED5_hard_interrupt/Cargo.lock
generated
Normal file
1343
test_LED5_hard_interrupt/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
64
test_LED5_hard_interrupt/Cargo.toml
Normal file
64
test_LED5_hard_interrupt/Cargo.toml
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "test1"
|
||||||
|
rust-version = "1.86"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "test1"
|
||||||
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||||
|
esp-hal = { version = "=1.0.0-rc.0", features = ["esp32", "log-04", "rt", "unstable"] }
|
||||||
|
log = "0.4.27"
|
||||||
|
embedded-io = "0.6.1"
|
||||||
|
embedded-io-async = "0.6.1"
|
||||||
|
esp-alloc = "0.8.0"
|
||||||
|
esp-backtrace = { version = "0.17.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"exception-handler",
|
||||||
|
"panic-handler",
|
||||||
|
"println",
|
||||||
|
] }
|
||||||
|
esp-println = { version = "0.15.0", features = ["esp32", "log-04"] }
|
||||||
|
# for more networking protocol support see https://crates.io/crates/edge-net
|
||||||
|
critical-section = "1.2.0"
|
||||||
|
embassy-executor = { version = "0.7.0", features = [
|
||||||
|
"log",
|
||||||
|
"task-arena-size-20480",
|
||||||
|
] }
|
||||||
|
embassy-time = { version = "0.4.0", features = ["log"] }
|
||||||
|
esp-hal-embassy = { version = "0.9.0", features = ["esp32", "log-04"] }
|
||||||
|
smoltcp = { version = "0.12.0", default-features = false, features = [
|
||||||
|
"log",
|
||||||
|
"medium-ethernet",
|
||||||
|
"multicast",
|
||||||
|
"proto-dhcpv4",
|
||||||
|
"proto-dns",
|
||||||
|
"proto-ipv4",
|
||||||
|
"socket-dns",
|
||||||
|
"socket-icmp",
|
||||||
|
"socket-raw",
|
||||||
|
"socket-tcp",
|
||||||
|
"socket-udp",
|
||||||
|
] }
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
heapless = "0.9.1"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Rust debug is too slow.
|
||||||
|
# For debug builds always builds with some optimization
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 's'
|
||||||
|
overflow-checks = false
|
||||||
12
test_LED5_hard_interrupt/Makefile
Normal file
12
test_LED5_hard_interrupt/Makefile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
.PHONY: all build flash
|
||||||
|
|
||||||
|
all: build flash
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
flash:
|
||||||
|
cargo espflash flash --release --monitor
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo espflash erase-flash
|
||||||
65
test_LED5_hard_interrupt/build.rs
Normal file
65
test_LED5_hard_interrupt/build.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
fn main() {
|
||||||
|
// load .env and pass SSID/PASSWORD to compiler
|
||||||
|
if let Ok(dotenv_path) = dotenvy::dotenv() {
|
||||||
|
// Only rebuild if .env changes
|
||||||
|
println!("cargo:rerun-if-changed={}", dotenv_path.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(ssid) = std::env::var("SSID") {
|
||||||
|
println!("cargo:rustc-env=SSID={}", ssid);
|
||||||
|
}
|
||||||
|
if let Ok(password) = std::env::var("PASSWORD") {
|
||||||
|
println!("cargo:rustc-env=PASSWORD={}", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
linker_be_nice();
|
||||||
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn linker_be_nice() {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
let kind = &args[1];
|
||||||
|
let what = &args[2];
|
||||||
|
|
||||||
|
match kind.as_str() {
|
||||||
|
"undefined-symbol" => match what.as_str() {
|
||||||
|
"_defmt_timestamp" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"_stack_start" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"esp_wifi_preempt_enable"
|
||||||
|
| "esp_wifi_preempt_yield_task"
|
||||||
|
| "esp_wifi_preempt_task_create" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide an external scheduler.");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
// we don't have anything helpful for "missing-lib" yet
|
||||||
|
_ => {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-Wl,--error-handling-script={}",
|
||||||
|
std::env::current_exe().unwrap().display()
|
||||||
|
);
|
||||||
|
}
|
||||||
2
test_LED5_hard_interrupt/rust-toolchain.toml
Normal file
2
test_LED5_hard_interrupt/rust-toolchain.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "esp"
|
||||||
87
test_LED5_hard_interrupt/src/bin/main.rs
Normal file
87
test_LED5_hard_interrupt/src/bin/main.rs
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#![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::Timer,
|
||||||
|
interrupt,
|
||||||
|
peripherals,
|
||||||
|
timer::timg::TimerGroup,
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
use core::cell::RefCell;
|
||||||
|
use critical_section::Mutex;
|
||||||
|
use esp_hal::handler;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
// This creates a default app-descriptor required by the esp-idf bootloader.
|
||||||
|
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
||||||
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
|
static mut INTERRUPT_FIRED: bool = false;
|
||||||
|
static TIMER0: Mutex<RefCell<Option<esp_hal::timer::timg::Timer<'static>>>> = Mutex::new(RefCell::new(None));
|
||||||
|
|
||||||
|
#[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);
|
||||||
|
let timer0 = timer_group1.timer0;
|
||||||
|
|
||||||
|
timer0.set_interrupt_handler(TG1_T0_LEVEL);
|
||||||
|
timer0.clear_interrupt();
|
||||||
|
timer0.load_value(Duration::from_secs(1)).unwrap();
|
||||||
|
timer0.enable_interrupt(true);
|
||||||
|
timer0.enable_auto_reload(true);
|
||||||
|
timer0.start();
|
||||||
|
|
||||||
|
// Store timer in the static safely
|
||||||
|
critical_section::with(|cs| {
|
||||||
|
TIMER0.borrow_ref_mut(cs).replace(timer0);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize GPIO4 as output (starts LOW)
|
||||||
|
let mut gpio4 = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
|
||||||
|
|
||||||
|
info!("Embassy initialized!");
|
||||||
|
loop {
|
||||||
|
|
||||||
|
info!("info!");
|
||||||
|
// let mut counter = 0;
|
||||||
|
// while counter < 10000000 {
|
||||||
|
// counter += 1;
|
||||||
|
// }
|
||||||
|
if unsafe { INTERRUPT_FIRED } {
|
||||||
|
gpio4.toggle();
|
||||||
|
info!("tick");
|
||||||
|
unsafe { INTERRUPT_FIRED = false; }
|
||||||
|
}
|
||||||
|
esp_hal::delay::Delay::new().delay_millis(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[handler]
|
||||||
|
fn TG1_T0_LEVEL() {
|
||||||
|
critical_section::with(|cs| {
|
||||||
|
if let Some(timer) = TIMER0.borrow_ref_mut(cs).as_mut() {
|
||||||
|
|
||||||
|
timer.clear_interrupt();
|
||||||
|
unsafe { INTERRUPT_FIRED = true; }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
1
test_LED5_hard_interrupt/src/lib.rs
Normal file
1
test_LED5_hard_interrupt/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#![no_std]
|
||||||
16
test_LED6_async_hard_interrupt/.cargo/config.toml
Normal file
16
test_LED6_async_hard_interrupt/.cargo/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[target.xtensa-esp32-none-elf]
|
||||||
|
runner = "espflash flash --monitor --chip esp32"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
ESP_LOG="info"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-nostartfiles",
|
||||||
|
"-Z", "stack-protector=all",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "xtensa-esp32-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["alloc", "core"]
|
||||||
2
test_LED6_async_hard_interrupt/.env_temp
Normal file
2
test_LED6_async_hard_interrupt/.env_temp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SSID = "nazov_wifi_siete"
|
||||||
|
PASSWORD = "heslo_od_wifi"
|
||||||
20
test_LED6_async_hard_interrupt/.gitignore
vendored
Normal file
20
test_LED6_async_hard_interrupt/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
.vscode/
|
||||||
|
.zed/
|
||||||
|
.helix/
|
||||||
|
.env
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
1350
test_LED6_async_hard_interrupt/Cargo.lock
generated
Normal file
1350
test_LED6_async_hard_interrupt/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
65
test_LED6_async_hard_interrupt/Cargo.toml
Normal file
65
test_LED6_async_hard_interrupt/Cargo.toml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "test1"
|
||||||
|
rust-version = "1.86"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "test1"
|
||||||
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||||
|
esp-hal = { version = "=1.0.0-rc.0", features = ["esp32", "log-04", "rt", "unstable"] }
|
||||||
|
log = "0.4.27"
|
||||||
|
embedded-io = "0.6.1"
|
||||||
|
embedded-io-async = "0.6.1"
|
||||||
|
esp-alloc = "0.8.0"
|
||||||
|
esp-backtrace = { version = "0.17.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"exception-handler",
|
||||||
|
"panic-handler",
|
||||||
|
"println",
|
||||||
|
] }
|
||||||
|
esp-println = { version = "0.15.0", features = ["esp32", "log-04"] }
|
||||||
|
# for more networking protocol support see https://crates.io/crates/edge-net
|
||||||
|
critical-section = "1.2.0"
|
||||||
|
embassy-executor = { version = "0.7.0", features = [
|
||||||
|
"log",
|
||||||
|
"task-arena-size-20480",
|
||||||
|
] }
|
||||||
|
embassy-time = { version = "0.4.0", features = ["log"] }
|
||||||
|
esp-hal-embassy = { version = "0.9.0", features = ["esp32", "log-04"] }
|
||||||
|
smoltcp = { version = "0.12.0", default-features = false, features = [
|
||||||
|
"log",
|
||||||
|
"medium-ethernet",
|
||||||
|
"multicast",
|
||||||
|
"proto-dhcpv4",
|
||||||
|
"proto-dns",
|
||||||
|
"proto-ipv4",
|
||||||
|
"socket-dns",
|
||||||
|
"socket-icmp",
|
||||||
|
"socket-raw",
|
||||||
|
"socket-tcp",
|
||||||
|
"socket-udp",
|
||||||
|
] }
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
heapless = "0.9.1"
|
||||||
|
embassy-sync = "0.7.2"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Rust debug is too slow.
|
||||||
|
# For debug builds always builds with some optimization
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 's'
|
||||||
|
overflow-checks = false
|
||||||
12
test_LED6_async_hard_interrupt/Makefile
Normal file
12
test_LED6_async_hard_interrupt/Makefile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
.PHONY: all build flash
|
||||||
|
|
||||||
|
all: build flash
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
flash:
|
||||||
|
cargo espflash flash --release --monitor
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo espflash erase-flash
|
||||||
65
test_LED6_async_hard_interrupt/build.rs
Normal file
65
test_LED6_async_hard_interrupt/build.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
fn main() {
|
||||||
|
// load .env and pass SSID/PASSWORD to compiler
|
||||||
|
if let Ok(dotenv_path) = dotenvy::dotenv() {
|
||||||
|
// Only rebuild if .env changes
|
||||||
|
println!("cargo:rerun-if-changed={}", dotenv_path.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(ssid) = std::env::var("SSID") {
|
||||||
|
println!("cargo:rustc-env=SSID={}", ssid);
|
||||||
|
}
|
||||||
|
if let Ok(password) = std::env::var("PASSWORD") {
|
||||||
|
println!("cargo:rustc-env=PASSWORD={}", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
linker_be_nice();
|
||||||
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn linker_be_nice() {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
let kind = &args[1];
|
||||||
|
let what = &args[2];
|
||||||
|
|
||||||
|
match kind.as_str() {
|
||||||
|
"undefined-symbol" => match what.as_str() {
|
||||||
|
"_defmt_timestamp" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"_stack_start" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"esp_wifi_preempt_enable"
|
||||||
|
| "esp_wifi_preempt_yield_task"
|
||||||
|
| "esp_wifi_preempt_task_create" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide an external scheduler.");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
// we don't have anything helpful for "missing-lib" yet
|
||||||
|
_ => {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-Wl,--error-handling-script={}",
|
||||||
|
std::env::current_exe().unwrap().display()
|
||||||
|
);
|
||||||
|
}
|
||||||
2
test_LED6_async_hard_interrupt/rust-toolchain.toml
Normal file
2
test_LED6_async_hard_interrupt/rust-toolchain.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "esp"
|
||||||
89
test_LED6_async_hard_interrupt/src/bin/main.rs
Normal file
89
test_LED6_async_hard_interrupt/src/bin/main.rs
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
#![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_sync::signal::Signal;
|
||||||
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
|
use embassy_time::Duration;
|
||||||
|
use esp_backtrace as _;
|
||||||
|
use esp_hal::{
|
||||||
|
clock::CpuClock,
|
||||||
|
gpio::{Level, Output, OutputConfig},
|
||||||
|
timer::Timer as HalTimer,
|
||||||
|
interrupt,
|
||||||
|
peripherals,
|
||||||
|
timer::timg::TimerGroup,
|
||||||
|
time::Duration as HalDuration,
|
||||||
|
};
|
||||||
|
use core::cell::RefCell;
|
||||||
|
use critical_section::Mutex;
|
||||||
|
use esp_hal::handler;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
// This creates a default app-descriptor required by the esp-idf bootloader.
|
||||||
|
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
||||||
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
|
static SIGNAL: Signal<CriticalSectionRawMutex, ()> = Signal::new();
|
||||||
|
static TIMER0: Mutex<RefCell<Option<esp_hal::timer::timg::Timer<'static>>>> = Mutex::new(RefCell::new(None));
|
||||||
|
|
||||||
|
#[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_group0 = TimerGroup::new(peripherals.TIMG0);
|
||||||
|
esp_hal_embassy::init(timer_group0.timer0);
|
||||||
|
|
||||||
|
let timer_group1 = TimerGroup::new(peripherals.TIMG1);
|
||||||
|
let timer0 = timer_group1.timer0;
|
||||||
|
|
||||||
|
timer0.set_interrupt_handler(TG1_T0_LEVEL);
|
||||||
|
timer0.clear_interrupt();
|
||||||
|
timer0.load_value(HalDuration::from_secs(1)).unwrap();
|
||||||
|
timer0.enable_interrupt(true);
|
||||||
|
timer0.enable_auto_reload(true);
|
||||||
|
timer0.start();
|
||||||
|
|
||||||
|
// Store timer in the static safely
|
||||||
|
critical_section::with(|cs| {
|
||||||
|
TIMER0.borrow_ref_mut(cs).replace(timer0);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize GPIO4 as output (starts LOW)
|
||||||
|
let gpio4 = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
|
||||||
|
|
||||||
|
spawner.spawn(led_task(gpio4)).unwrap();
|
||||||
|
|
||||||
|
info!("Embassy initialized!");
|
||||||
|
loop {
|
||||||
|
embassy_time::Timer::after(Duration::from_secs(5)).await;
|
||||||
|
info!("x");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn led_task(mut gpio4: Output<'static>) {
|
||||||
|
loop {
|
||||||
|
SIGNAL.wait().await;
|
||||||
|
gpio4.toggle();
|
||||||
|
info!("tick");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[handler]
|
||||||
|
fn TG1_T0_LEVEL() {
|
||||||
|
critical_section::with(|cs| {
|
||||||
|
if let Some(timer) = TIMER0.borrow_ref_mut(cs).as_mut() {
|
||||||
|
timer.clear_interrupt();
|
||||||
|
SIGNAL.signal(());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
1
test_LED6_async_hard_interrupt/src/lib.rs
Normal file
1
test_LED6_async_hard_interrupt/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#![no_std]
|
||||||
16
test_LED_pwm/.cargo/config.toml
Normal file
16
test_LED_pwm/.cargo/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[target.xtensa-esp32-none-elf]
|
||||||
|
runner = "espflash flash --monitor --chip esp32"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
ESP_LOG="info"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-nostartfiles",
|
||||||
|
"-Z", "stack-protector=all",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "xtensa-esp32-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["alloc", "core"]
|
||||||
2
test_LED_pwm/.env_temp
Normal file
2
test_LED_pwm/.env_temp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SSID = "nazov_wifi_siete"
|
||||||
|
PASSWORD = "heslo_od_wifi"
|
||||||
20
test_LED_pwm/.gitignore
vendored
Normal file
20
test_LED_pwm/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
.vscode/
|
||||||
|
.zed/
|
||||||
|
.helix/
|
||||||
|
.env
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
1343
test_LED_pwm/Cargo.lock
generated
Normal file
1343
test_LED_pwm/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
68
test_LED_pwm/Cargo.toml
Normal file
68
test_LED_pwm/Cargo.toml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "test1"
|
||||||
|
rust-version = "1.86"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "test1"
|
||||||
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||||
|
esp-hal = { version = "=1.0.0-rc.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"log-04",
|
||||||
|
"unstable",
|
||||||
|
] }
|
||||||
|
log = "0.4.27"
|
||||||
|
embedded-io = "0.6.1"
|
||||||
|
embedded-io-async = "0.6.1"
|
||||||
|
esp-alloc = "0.8.0"
|
||||||
|
esp-backtrace = { version = "0.17.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"exception-handler",
|
||||||
|
"panic-handler",
|
||||||
|
"println",
|
||||||
|
] }
|
||||||
|
esp-println = { version = "0.15.0", features = ["esp32", "log-04"] }
|
||||||
|
# for more networking protocol support see https://crates.io/crates/edge-net
|
||||||
|
critical-section = "1.2.0"
|
||||||
|
embassy-executor = { version = "0.7.0", features = [
|
||||||
|
"log",
|
||||||
|
"task-arena-size-20480",
|
||||||
|
] }
|
||||||
|
embassy-time = { version = "0.4.0", features = ["log"] }
|
||||||
|
esp-hal-embassy = { version = "0.9.0", features = ["esp32", "log-04"] }
|
||||||
|
smoltcp = { version = "0.12.0", default-features = false, features = [
|
||||||
|
"log",
|
||||||
|
"medium-ethernet",
|
||||||
|
"multicast",
|
||||||
|
"proto-dhcpv4",
|
||||||
|
"proto-dns",
|
||||||
|
"proto-ipv4",
|
||||||
|
"socket-dns",
|
||||||
|
"socket-icmp",
|
||||||
|
"socket-raw",
|
||||||
|
"socket-tcp",
|
||||||
|
"socket-udp",
|
||||||
|
] }
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
heapless = "0.9.1"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Rust debug is too slow.
|
||||||
|
# For debug builds always builds with some optimization
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 's'
|
||||||
|
overflow-checks = false
|
||||||
9
test_LED_pwm/Makefile
Normal file
9
test_LED_pwm/Makefile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.PHONY: all build flash
|
||||||
|
|
||||||
|
all: build flash
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
flash:
|
||||||
|
cargo espflash flash --release --monitor
|
||||||
65
test_LED_pwm/build.rs
Normal file
65
test_LED_pwm/build.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
fn main() {
|
||||||
|
// load .env and pass SSID/PASSWORD to compiler
|
||||||
|
if let Ok(dotenv_path) = dotenvy::dotenv() {
|
||||||
|
// Only rebuild if .env changes
|
||||||
|
println!("cargo:rerun-if-changed={}", dotenv_path.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(ssid) = std::env::var("SSID") {
|
||||||
|
println!("cargo:rustc-env=SSID={}", ssid);
|
||||||
|
}
|
||||||
|
if let Ok(password) = std::env::var("PASSWORD") {
|
||||||
|
println!("cargo:rustc-env=PASSWORD={}", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
linker_be_nice();
|
||||||
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn linker_be_nice() {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
let kind = &args[1];
|
||||||
|
let what = &args[2];
|
||||||
|
|
||||||
|
match kind.as_str() {
|
||||||
|
"undefined-symbol" => match what.as_str() {
|
||||||
|
"_defmt_timestamp" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"_stack_start" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"esp_wifi_preempt_enable"
|
||||||
|
| "esp_wifi_preempt_yield_task"
|
||||||
|
| "esp_wifi_preempt_task_create" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide an external scheduler.");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
// we don't have anything helpful for "missing-lib" yet
|
||||||
|
_ => {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-Wl,--error-handling-script={}",
|
||||||
|
std::env::current_exe().unwrap().display()
|
||||||
|
);
|
||||||
|
}
|
||||||
2
test_LED_pwm/rust-toolchain.toml
Normal file
2
test_LED_pwm/rust-toolchain.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "esp"
|
||||||
76
test_LED_pwm/src/bin/main.rs
Normal file
76
test_LED_pwm/src/bin/main.rs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#![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;
|
||||||
|
use esp_hal::timer::timg::TimerGroup;
|
||||||
|
use esp_hal::ledc::{Ledc, LowSpeed, LSGlobalClkSource};
|
||||||
|
use esp_hal::ledc::channel::{self, ChannelIFace};
|
||||||
|
use esp_hal::ledc::timer::{self, TimerIFace};
|
||||||
|
use esp_hal::time::Rate;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
// This creates a default app-descriptor required by the esp-idf bootloader.
|
||||||
|
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
||||||
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
|
#[esp_hal_embassy::main]
|
||||||
|
async fn main(spawner: Spawner) {
|
||||||
|
// generator version: 0.5.0
|
||||||
|
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 timer0 = TimerGroup::new(peripherals.TIMG1);
|
||||||
|
esp_hal_embassy::init(timer0.timer0);
|
||||||
|
|
||||||
|
info!("Embassy initialized!");
|
||||||
|
|
||||||
|
|
||||||
|
// LEDC initialization
|
||||||
|
let mut ledc = Ledc::new(peripherals.LEDC);
|
||||||
|
ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
|
||||||
|
|
||||||
|
let mut lstimer0 = ledc.timer::<LowSpeed>(timer::Number::Timer0);
|
||||||
|
lstimer0.configure(timer::config::Config {
|
||||||
|
duty: timer::config::Duty::Duty5Bit,
|
||||||
|
clock_source: timer::LSClockSource::APBClk,
|
||||||
|
frequency: Rate::from_khz(24),
|
||||||
|
}).unwrap();
|
||||||
|
|
||||||
|
let led = peripherals.GPIO4;
|
||||||
|
let mut channel0 = ledc.channel(channel::Number::Channel0, led);
|
||||||
|
channel0.configure(channel::config::Config {
|
||||||
|
timer: &lstimer0,
|
||||||
|
duty_pct: 10,
|
||||||
|
pin_config: channel::config::PinConfig::PushPull,
|
||||||
|
}).unwrap();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
// channel0.start_duty_fade(0, 100, 1000).unwrap();
|
||||||
|
// while channel0.is_duty_fade_running() {}
|
||||||
|
// channel0.start_duty_fade(100, 0, 1000).unwrap();
|
||||||
|
// while channel0.is_duty_fade_running() {}
|
||||||
|
|
||||||
|
channel0.set_duty(100).unwrap();
|
||||||
|
info!("LED ON");
|
||||||
|
Timer::after(Duration::from_secs(1)).await;
|
||||||
|
|
||||||
|
channel0.set_duty(0).unwrap();
|
||||||
|
info!("LED OFF");
|
||||||
|
Timer::after(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
|
||||||
|
}
|
||||||
1
test_LED_pwm/src/lib.rs
Normal file
1
test_LED_pwm/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#![no_std]
|
||||||
16
test_uart/.cargo/config.toml
Normal file
16
test_uart/.cargo/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[target.xtensa-esp32-none-elf]
|
||||||
|
runner = "espflash flash --monitor --chip esp32"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
ESP_LOG="info"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-nostartfiles",
|
||||||
|
"-Z", "stack-protector=all",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "xtensa-esp32-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["alloc", "core"]
|
||||||
2
test_uart/.env_temp
Normal file
2
test_uart/.env_temp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SSID = "nazov_wifi_siete"
|
||||||
|
PASSWORD = "heslo_od_wifi"
|
||||||
20
test_uart/.gitignore
vendored
Normal file
20
test_uart/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
.vscode/
|
||||||
|
.zed/
|
||||||
|
.helix/
|
||||||
|
.env
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
1343
test_uart/Cargo.lock
generated
Normal file
1343
test_uart/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
68
test_uart/Cargo.toml
Normal file
68
test_uart/Cargo.toml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "test1"
|
||||||
|
rust-version = "1.86"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "test1"
|
||||||
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||||
|
esp-hal = { version = "=1.0.0-rc.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"log-04",
|
||||||
|
"unstable",
|
||||||
|
] }
|
||||||
|
log = "0.4.27"
|
||||||
|
embedded-io = "0.6.1"
|
||||||
|
embedded-io-async = "0.6.1"
|
||||||
|
esp-alloc = "0.8.0"
|
||||||
|
esp-backtrace = { version = "0.17.0", features = [
|
||||||
|
"esp32",
|
||||||
|
"exception-handler",
|
||||||
|
"panic-handler",
|
||||||
|
"println",
|
||||||
|
] }
|
||||||
|
esp-println = { version = "0.15.0", features = ["esp32", "log-04"] }
|
||||||
|
# for more networking protocol support see https://crates.io/crates/edge-net
|
||||||
|
critical-section = "1.2.0"
|
||||||
|
embassy-executor = { version = "0.7.0", features = [
|
||||||
|
"log",
|
||||||
|
"task-arena-size-20480",
|
||||||
|
] }
|
||||||
|
embassy-time = { version = "0.4.0", features = ["log"] }
|
||||||
|
esp-hal-embassy = { version = "0.9.0", features = ["esp32", "log-04"] }
|
||||||
|
smoltcp = { version = "0.12.0", default-features = false, features = [
|
||||||
|
"log",
|
||||||
|
"medium-ethernet",
|
||||||
|
"multicast",
|
||||||
|
"proto-dhcpv4",
|
||||||
|
"proto-dns",
|
||||||
|
"proto-ipv4",
|
||||||
|
"socket-dns",
|
||||||
|
"socket-icmp",
|
||||||
|
"socket-raw",
|
||||||
|
"socket-tcp",
|
||||||
|
"socket-udp",
|
||||||
|
] }
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
heapless = "0.9.1"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Rust debug is too slow.
|
||||||
|
# For debug builds always builds with some optimization
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 's'
|
||||||
|
overflow-checks = false
|
||||||
9
test_uart/Makefile
Normal file
9
test_uart/Makefile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.PHONY: all build flash
|
||||||
|
|
||||||
|
all: build flash
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
flash:
|
||||||
|
cargo espflash flash --release --monitor
|
||||||
65
test_uart/build.rs
Normal file
65
test_uart/build.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
fn main() {
|
||||||
|
// load .env and pass SSID/PASSWORD to compiler
|
||||||
|
if let Ok(dotenv_path) = dotenvy::dotenv() {
|
||||||
|
// Only rebuild if .env changes
|
||||||
|
println!("cargo:rerun-if-changed={}", dotenv_path.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(ssid) = std::env::var("SSID") {
|
||||||
|
println!("cargo:rustc-env=SSID={}", ssid);
|
||||||
|
}
|
||||||
|
if let Ok(password) = std::env::var("PASSWORD") {
|
||||||
|
println!("cargo:rustc-env=PASSWORD={}", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
linker_be_nice();
|
||||||
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn linker_be_nice() {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
let kind = &args[1];
|
||||||
|
let what = &args[2];
|
||||||
|
|
||||||
|
match kind.as_str() {
|
||||||
|
"undefined-symbol" => match what.as_str() {
|
||||||
|
"_defmt_timestamp" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"_stack_start" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"esp_wifi_preempt_enable"
|
||||||
|
| "esp_wifi_preempt_yield_task"
|
||||||
|
| "esp_wifi_preempt_task_create" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide an external scheduler.");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
// we don't have anything helpful for "missing-lib" yet
|
||||||
|
_ => {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-Wl,--error-handling-script={}",
|
||||||
|
std::env::current_exe().unwrap().display()
|
||||||
|
);
|
||||||
|
}
|
||||||
2
test_uart/rust-toolchain.toml
Normal file
2
test_uart/rust-toolchain.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "esp"
|
||||||
40
test_uart/src/bin/main.rs
Normal file
40
test_uart/src/bin/main.rs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#![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;
|
||||||
|
use esp_hal::timer::timg::TimerGroup;
|
||||||
|
use esp_hal::peripherals;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
// This creates a default app-descriptor required by the esp-idf bootloader.
|
||||||
|
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
||||||
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
|
#[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 timer0 = TimerGroup::new(peripherals.TIMG1);
|
||||||
|
esp_hal_embassy::init(timer0.timer0);
|
||||||
|
|
||||||
|
info!("Embassy initialized!");
|
||||||
|
loop {
|
||||||
|
Timer::after(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
|
||||||
|
}
|
||||||
1
test_uart/src/lib.rs
Normal file
1
test_uart/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#![no_std]
|
||||||
Reference in New Issue
Block a user