From 0c77a43ed533f96736f25b4a74600b385df29ffc Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Thu, 2 May 2024 14:34:26 +0300 Subject: [PATCH 01/12] Bump source esp-hal version to 0.17.0 --- esp-ieee802154/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-ieee802154/Cargo.toml b/esp-ieee802154/Cargo.toml index d19cc9b..0949ca2 100644 --- a/esp-ieee802154/Cargo.toml +++ b/esp-ieee802154/Cargo.toml @@ -13,7 +13,7 @@ test = false [dependencies] byte = "0.2.6" critical-section = "1.1.2" -esp-hal = "0.16.1" +esp-hal = "0.17.0" heapless = "0.8.0" ieee802154 = "0.6.1" log = "0.4.20" From e38d067a50681a20a069c89e3a8d71c48ba1934e Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Thu, 2 May 2024 14:35:21 +0300 Subject: [PATCH 02/12] Bump examples esp-hal version to 0.17.0 --- esp-ieee802154-examples/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-ieee802154-examples/Cargo.toml b/esp-ieee802154-examples/Cargo.toml index ed231b7..77b14c5 100644 --- a/esp-ieee802154-examples/Cargo.toml +++ b/esp-ieee802154-examples/Cargo.toml @@ -8,7 +8,7 @@ publish = false esp-backtrace = { version = "0.11.1", features = ["panic-handler", "exception-handler", "println"] } esp-ieee802154 = { version = "0.1.0", path = "../esp-ieee802154" } esp-println = { version = "0.9.1", features = ["log"] } -esp-hal = "0.16.1" +esp-hal = "0.17.0" heapless = "0.8.0" ieee802154 = "0.6.1" log = "0.4.20" From 93b60acc1d38db7d56afeb81c9e947a70f082111 Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Thu, 2 May 2024 15:02:38 +0300 Subject: [PATCH 03/12] Fixed esp-hal interrupt code for v0.17.0 This change in the code base was due to the changes in the esp-hal module. Credit to MabezDev for pointing it out: https://github.com/esp-rs/esp-hal/blob/main/esp-hal/CHANGELOG.md#changed-1 --- esp-ieee802154/src/raw.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/esp-ieee802154/src/raw.rs b/esp-ieee802154/src/raw.rs index 1838f30..bf8290d 100644 --- a/esp-ieee802154/src/raw.rs +++ b/esp-ieee802154/src/raw.rs @@ -15,9 +15,9 @@ use crate::{ pib::*, }; use esp_hal::{ - interrupt::{self, Priority}, + interrupt, + interrupt::Priority, peripherals::Interrupt, - prelude::interrupt, system::{RadioClockControl, RadioClockController, RadioPeripherals}, }; @@ -343,7 +343,6 @@ fn next_operation() { } } -#[interrupt] fn ZB_MAC() { log::trace!("ZB_MAC interrupt"); From 04020e0e287e89428dfbfc1fb9c1dc2e4dc2e6c6 Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Thu, 2 May 2024 15:09:14 +0300 Subject: [PATCH 04/12] Changed the implementation to use the handler Reference: https://github.com/esp-rs/esp-hal/releases/tag/v0.17.0 --- esp-ieee802154/src/raw.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esp-ieee802154/src/raw.rs b/esp-ieee802154/src/raw.rs index bf8290d..46f1696 100644 --- a/esp-ieee802154/src/raw.rs +++ b/esp-ieee802154/src/raw.rs @@ -18,6 +18,7 @@ use esp_hal::{ interrupt, interrupt::Priority, peripherals::Interrupt, + prelude::handler, system::{RadioClockControl, RadioClockController, RadioPeripherals}, }; @@ -343,6 +344,7 @@ fn next_operation() { } } +#[handler] fn ZB_MAC() { log::trace!("ZB_MAC interrupt"); From 5cf1cdf8d8c3305272c38a234203592751082407 Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Thu, 2 May 2024 16:11:28 +0300 Subject: [PATCH 05/12] Updated dependencies Due to esp-hal 0.17.0 version changes the UART and Delay methods are locked behind the "embedded-hal" feature as shown in those 2 files from the source codes: v0.17.0 https://github.com/esp-rs/esp-hal/blob/fd1c7b4fc799e581d4f3e03ecf7dc5cee4567e75/esp-hal/src/uart.rs#L1465-L1474 v0.16.1 https://github.com/esp-rs/esp-hal/blob/92e3ea576ba28dda3a29bb4b37398c0d74c55120/esp-hal/src/uart.rs#L1263-L1272 This makes it so its mandatory to include the embedded-hal external crate to the examples projects in order to migrate esp-hal to version 0.17.0. --- esp-ieee802154-examples/Cargo.toml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/esp-ieee802154-examples/Cargo.toml b/esp-ieee802154-examples/Cargo.toml index 77b14c5..f2f52d6 100644 --- a/esp-ieee802154-examples/Cargo.toml +++ b/esp-ieee802154-examples/Cargo.toml @@ -5,13 +5,15 @@ edition = "2021" publish = false [dependencies] -esp-backtrace = { version = "0.11.1", features = ["panic-handler", "exception-handler", "println"] } -esp-ieee802154 = { version = "0.1.0", path = "../esp-ieee802154" } -esp-println = { version = "0.9.1", features = ["log"] } -esp-hal = "0.17.0" -heapless = "0.8.0" -ieee802154 = "0.6.1" -log = "0.4.20" +esp-backtrace = { version = "0.11.1", features = ["panic-handler", "exception-handler", "println"] } +esp-ieee802154 = { version = "0.1.0", path = "../esp-ieee802154" } +esp-println = { version = "0.9.1", features = ["log"] } +esp-hal = "0.17.0" +heapless = "0.8.0" +ieee802154 = "0.6.1" +log = "0.4.20" +embedded-hal = "1.0.0" +embedded-hal-nb = "1.0.0" [features] esp32c6 = ["esp-hal/esp32c6", "esp-backtrace/esp32c6", "esp-ieee802154/esp32c6", "esp-println/esp32c6"] From 8a22d87bf7f93a067a26e2e17794566d1e1096d2 Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Thu, 2 May 2024 16:20:22 +0300 Subject: [PATCH 06/12] Added necessary embedded-hal traits for esp-hal Read the message from the previous commit about adding embedded-hal These are what the errors prior to the commit consisted of: ``` error[E0599]: no method named `delay_ms` found for struct `Delay` in the current scope /home/hutao/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embedded-hal-1.0.0/src/delay.rs:31:8 help: trait `DelayNs` which provides `delay_ms` is implemented but not in scope; perhaps you want to import it | 4 + use embedded_hal::delay::DelayNs; ``` --- esp-ieee802154-examples/examples/send_broadcast_frame.rs | 4 +++- esp-ieee802154-examples/examples/send_frame.rs | 3 ++- esp-ieee802154-examples/examples/sniffer.rs | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/esp-ieee802154-examples/examples/send_broadcast_frame.rs b/esp-ieee802154-examples/examples/send_broadcast_frame.rs index 393a08b..a52c977 100644 --- a/esp-ieee802154-examples/examples/send_broadcast_frame.rs +++ b/esp-ieee802154-examples/examples/send_broadcast_frame.rs @@ -1,8 +1,10 @@ #![no_std] #![no_main] +use embedded_hal::delay::DelayNs; +use embedded_hal_nb::serial::Read; use esp_backtrace as _; -use esp_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay}; +use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, prelude::*}; use esp_ieee802154::*; use esp_println::println; use ieee802154::mac::{Header, PanId, ShortAddress}; diff --git a/esp-ieee802154-examples/examples/send_frame.rs b/esp-ieee802154-examples/examples/send_frame.rs index 724f400..262c37e 100644 --- a/esp-ieee802154-examples/examples/send_frame.rs +++ b/esp-ieee802154-examples/examples/send_frame.rs @@ -1,8 +1,9 @@ #![no_std] #![no_main] +use embedded_hal::delay::DelayNs; use esp_backtrace as _; -use esp_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay}; +use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, prelude::*}; use esp_ieee802154::*; use esp_println::println; use ieee802154::mac::{Header, PanId, ShortAddress}; diff --git a/esp-ieee802154-examples/examples/sniffer.rs b/esp-ieee802154-examples/examples/sniffer.rs index df458a4..b0b7a56 100644 --- a/esp-ieee802154-examples/examples/sniffer.rs +++ b/esp-ieee802154-examples/examples/sniffer.rs @@ -1,9 +1,10 @@ #![no_std] #![no_main] +use embedded_hal_nb::serial::Read; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, peripherals::Peripherals, prelude::*, reset::software_reset, Uart, + clock::ClockControl, peripherals::Peripherals, prelude::*, reset::software_reset, uart::Uart, }; use esp_ieee802154::*; use esp_println::println; From 69815624956bfb12d799fa6190c93cdcde274255 Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Thu, 2 May 2024 17:03:34 +0300 Subject: [PATCH 07/12] Set the priority directly in the handler --- esp-ieee802154/src/raw.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/esp-ieee802154/src/raw.rs b/esp-ieee802154/src/raw.rs index 46f1696..4193c67 100644 --- a/esp-ieee802154/src/raw.rs +++ b/esp-ieee802154/src/raw.rs @@ -15,9 +15,7 @@ use crate::{ pib::*, }; use esp_hal::{ - interrupt, interrupt::Priority, - peripherals::Interrupt, prelude::handler, system::{RadioClockControl, RadioClockController, RadioPeripherals}, }; @@ -144,7 +142,6 @@ fn ieee802154_mac_init() { // memset(s_rx_frame, 0, sizeof(s_rx_frame)); // s_ieee802154_state = IEEE802154_STATE_IDLE; - interrupt::enable(Interrupt::ZB_MAC, Priority::Priority1).unwrap(); unsafe { esp_hal::riscv::interrupt::enable(); } @@ -344,7 +341,7 @@ fn next_operation() { } } -#[handler] +#[handler(priority = "Priority::Priority1")] fn ZB_MAC() { log::trace!("ZB_MAC interrupt"); From 6a649fb1f29f6b226f5fdd289720d7d5ec646514 Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Fri, 3 May 2024 09:59:06 +0300 Subject: [PATCH 08/12] Manually registered the handler For reference: "Handlers are not automatically registered anymore in esp-hal 0.17" - Credit to @bjoernQ on GitHub for pointing it out Source: https://github.com/esp-rs/esp-ieee802154/pull/24#discussion_r1588800002 --- esp-ieee802154/src/raw.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/esp-ieee802154/src/raw.rs b/esp-ieee802154/src/raw.rs index 4193c67..5c85b98 100644 --- a/esp-ieee802154/src/raw.rs +++ b/esp-ieee802154/src/raw.rs @@ -143,8 +143,12 @@ fn ieee802154_mac_init() { // s_ieee802154_state = IEEE802154_STATE_IDLE; unsafe { - esp_hal::riscv::interrupt::enable(); + esp_hal::interrupt::bind_interrupt( + esp_hal::peripherals::Interrupt::ZB_MAC, + ZB_MAC.handler(), + ); } + esp_hal::interrupt::enable(esp_hal::peripherals::Interrupt::ZB_MAC, ZB_MAC.priority()).unwrap(); } fn ieee802154_set_txrx_pti(txrx_scene: Ieee802154TxRxScene) { From 2adbe924783b207bc19cdffb3663b76ccd99eb3b Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Fri, 3 May 2024 10:06:12 +0300 Subject: [PATCH 09/12] Removed unused Read import --- esp-ieee802154-examples/examples/send_broadcast_frame.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/esp-ieee802154-examples/examples/send_broadcast_frame.rs b/esp-ieee802154-examples/examples/send_broadcast_frame.rs index a52c977..58a3117 100644 --- a/esp-ieee802154-examples/examples/send_broadcast_frame.rs +++ b/esp-ieee802154-examples/examples/send_broadcast_frame.rs @@ -2,7 +2,6 @@ #![no_main] use embedded_hal::delay::DelayNs; -use embedded_hal_nb::serial::Read; use esp_backtrace as _; use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, prelude::*}; use esp_ieee802154::*; From 1eff13fc59172732fa7e0a9c067539a2cb32842d Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Fri, 3 May 2024 10:08:08 +0300 Subject: [PATCH 10/12] Changed the send_broadcast_frame delay to millis For reference: https://github.com/esp-rs/esp-ieee802154/pull/24#discussion_r1588800674 --- esp-ieee802154-examples/examples/send_broadcast_frame.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/esp-ieee802154-examples/examples/send_broadcast_frame.rs b/esp-ieee802154-examples/examples/send_broadcast_frame.rs index 58a3117..6a64543 100644 --- a/esp-ieee802154-examples/examples/send_broadcast_frame.rs +++ b/esp-ieee802154-examples/examples/send_broadcast_frame.rs @@ -1,7 +1,6 @@ #![no_std] #![no_main] -use embedded_hal::delay::DelayNs; use esp_backtrace as _; use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, prelude::*}; use esp_ieee802154::*; @@ -16,7 +15,7 @@ fn main() -> ! { let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::max(system.clock_control).freeze(); - let mut delay = Delay::new(&clocks); + let delay = Delay::new(&clocks); println!("Start"); @@ -58,7 +57,7 @@ fn main() -> ! { .ok(); println!("Send frame with sequence number {seq_number}"); - delay.delay_ms(1000u32); + delay.delay_millis(1000u32); seq_number = seq_number.wrapping_add(1); } } From 611af43285ae83a011039c404b21ab6a2c60f578 Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Fri, 3 May 2024 10:09:03 +0300 Subject: [PATCH 11/12] Changed the send_frame delay to millis For reference: https://github.com/esp-rs/esp-ieee802154/pull/24#discussion_r1588800674 --- esp-ieee802154-examples/examples/send_frame.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/esp-ieee802154-examples/examples/send_frame.rs b/esp-ieee802154-examples/examples/send_frame.rs index 262c37e..dc8dbbd 100644 --- a/esp-ieee802154-examples/examples/send_frame.rs +++ b/esp-ieee802154-examples/examples/send_frame.rs @@ -1,7 +1,6 @@ #![no_std] #![no_main] -use embedded_hal::delay::DelayNs; use esp_backtrace as _; use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, prelude::*}; use esp_ieee802154::*; @@ -16,7 +15,7 @@ fn main() -> ! { let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::max(system.clock_control).freeze(); - let mut delay = Delay::new(&clocks); + let delay = Delay::new(&clocks); println!("Start"); @@ -59,7 +58,7 @@ fn main() -> ! { .ok(); println!("Send frame with sequence number {seq_number}"); - delay.delay_ms(1000u32); + delay.delay_millis(1000u32); seq_number = seq_number.wrapping_add(1); } } From 900215abea4709eddfa891d74f07ccb85edb69c1 Mon Sep 17 00:00:00 2001 From: 1Kill2Steal Date: Fri, 3 May 2024 10:09:18 +0300 Subject: [PATCH 12/12] Removed no longer needed embedded-hal dependency --- esp-ieee802154-examples/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/esp-ieee802154-examples/Cargo.toml b/esp-ieee802154-examples/Cargo.toml index f2f52d6..b5e4c8c 100644 --- a/esp-ieee802154-examples/Cargo.toml +++ b/esp-ieee802154-examples/Cargo.toml @@ -12,7 +12,6 @@ esp-hal = "0.17.0" heapless = "0.8.0" ieee802154 = "0.6.1" log = "0.4.20" -embedded-hal = "1.0.0" embedded-hal-nb = "1.0.0" [features]