aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/rp/src/bin/adc.rs8
-rw-r--r--examples/rp/src/bin/blinky.rs4
-rw-r--r--examples/rp/src/bin/button.rs4
-rw-r--r--examples/rp/src/bin/flash.rs2
-rw-r--r--examples/rp/src/bin/gpio_async.rs6
-rw-r--r--examples/rp/src/bin/gpout.rs4
-rw-r--r--examples/rp/src/bin/i2c_async.rs5
-rw-r--r--examples/rp/src/bin/i2c_blocking.rs5
-rw-r--r--examples/rp/src/bin/lora_lorawan.rs1
-rw-r--r--examples/rp/src/bin/lora_p2p_receive.rs1
-rw-r--r--examples/rp/src/bin/lora_p2p_send.rs1
-rw-r--r--examples/rp/src/bin/lora_p2p_send_multicore.rs1
-rw-r--r--examples/rp/src/bin/multicore.rs4
-rw-r--r--examples/rp/src/bin/pio_async.rs11
-rw-r--r--examples/rp/src/bin/pio_dma.rs2
-rw-r--r--examples/rp/src/bin/pio_hd44780.rs3
-rw-r--r--examples/rp/src/bin/pio_ws2812.rs3
-rw-r--r--examples/rp/src/bin/pwm.rs4
-rw-r--r--examples/rp/src/bin/rtc.rs46
-rw-r--r--examples/rp/src/bin/spi.rs4
-rw-r--r--examples/rp/src/bin/spi_async.rs3
-rw-r--r--examples/rp/src/bin/spi_display.rs5
-rw-r--r--examples/rp/src/bin/uart.rs6
-rw-r--r--examples/rp/src/bin/uart_buffered_split.rs6
-rw-r--r--examples/rp/src/bin/uart_unidir.rs6
-rw-r--r--examples/rp/src/bin/usb_ethernet.rs4
-rw-r--r--examples/rp/src/bin/usb_logger.rs4
-rw-r--r--examples/rp/src/bin/usb_serial.rs4
-rw-r--r--examples/rp/src/bin/watchdog.rs4
-rw-r--r--examples/rp/src/bin/wifi_ap_tcp_server.rs3
-rw-r--r--examples/rp/src/bin/wifi_blinky.rs4
-rw-r--r--examples/rp/src/bin/wifi_scan.rs3
-rw-r--r--examples/rp/src/bin/wifi_tcp_server.rs3
-rw-r--r--examples/stm32wb/Cargo.toml5
-rw-r--r--examples/stm32wb/src/bin/gatt_server.rs397
-rw-r--r--examples/stm32wl/.cargo/config.toml2
-rw-r--r--examples/stm32wl/Cargo.toml5
-rw-r--r--examples/stm32wl/src/bin/rtc.rs43
38 files changed, 616 insertions, 10 deletions
diff --git a/examples/rp/src/bin/adc.rs b/examples/rp/src/bin/adc.rs
index 65069cde1..81a8b8340 100644
--- a/examples/rp/src/bin/adc.rs
+++ b/examples/rp/src/bin/adc.rs
@@ -1,3 +1,6 @@
1//! This example test the ADC (Analog to Digital Conversion) of the RS2040 pin 26, 27 and 28.
2//! It also reads the temperature sensor in the chip.
3
1#![no_std] 4#![no_std]
2#![no_main] 5#![no_main]
3#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
@@ -38,5 +41,8 @@ async fn main(_spawner: Spawner) {
38 41
39fn convert_to_celsius(raw_temp: u16) -> f32 { 42fn convert_to_celsius(raw_temp: u16) -> f32 {
40 // According to chapter 4.9.5. Temperature Sensor in RP2040 datasheet 43 // According to chapter 4.9.5. Temperature Sensor in RP2040 datasheet
41 27.0 - (raw_temp as f32 * 3.3 / 4096.0 - 0.706) / 0.001721 as f32 44 let temp = 27.0 - (raw_temp as f32 * 3.3 / 4096.0 - 0.706) / 0.001721;
45 let sign = if temp < 0.0 { -1.0 } else { 1.0 };
46 let rounded_temp_x10: i16 = ((temp * 10.0) + 0.5 * sign) as i16;
47 (rounded_temp_x10 as f32) / 10.0
42} 48}
diff --git a/examples/rp/src/bin/blinky.rs b/examples/rp/src/bin/blinky.rs
index 7aa36a19f..295b000f3 100644
--- a/examples/rp/src/bin/blinky.rs
+++ b/examples/rp/src/bin/blinky.rs
@@ -1,3 +1,7 @@
1//! This example test the RP Pico on board LED.
2//!
3//! It does not work with the RP Pico W board. See wifi_blinky.rs.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs
index 0d246c093..d7aa89410 100644
--- a/examples/rp/src/bin/button.rs
+++ b/examples/rp/src/bin/button.rs
@@ -1,3 +1,7 @@
1//! This example uses the RP Pico on board LED to test input pin 28. This is not the button on the board.
2//!
3//! It does not work with the RP Pico W board. Use wifi_blinky.rs and add input pin.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/flash.rs b/examples/rp/src/bin/flash.rs
index 19076150c..4c4982acc 100644
--- a/examples/rp/src/bin/flash.rs
+++ b/examples/rp/src/bin/flash.rs
@@ -1,3 +1,5 @@
1//! This example test the flash connected to the RP2040 chip.
2
1#![no_std] 3#![no_std]
2#![no_main] 4#![no_main]
3#![feature(type_alias_impl_trait)] 5#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/gpio_async.rs b/examples/rp/src/bin/gpio_async.rs
index 52d13a9d5..bf58044d5 100644
--- a/examples/rp/src/bin/gpio_async.rs
+++ b/examples/rp/src/bin/gpio_async.rs
@@ -1,3 +1,7 @@
1//! This example shows how async gpio can be used with a RP2040.
2//!
3//! The LED on the RP Pico W board is connected differently. See wifi_blinky.rs.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
@@ -9,8 +13,6 @@ use embassy_time::{Duration, Timer};
9use gpio::{Input, Level, Output, Pull}; 13use gpio::{Input, Level, Output, Pull};
10use {defmt_rtt as _, panic_probe as _}; 14use {defmt_rtt as _, panic_probe as _};
11 15
12/// This example shows how async gpio can be used with a RP2040.
13///
14/// It requires an external signal to be manually triggered on PIN 16. For 16/// It requires an external signal to be manually triggered on PIN 16. For
15/// example, this could be accomplished using an external power source with a 17/// example, this could be accomplished using an external power source with a
16/// button so that it is possible to toggle the signal from low to high. 18/// button so that it is possible to toggle the signal from low to high.
diff --git a/examples/rp/src/bin/gpout.rs b/examples/rp/src/bin/gpout.rs
index 64461fc5f..0a3b5fa98 100644
--- a/examples/rp/src/bin/gpout.rs
+++ b/examples/rp/src/bin/gpout.rs
@@ -1,3 +1,7 @@
1//! This example shows how GPOUT (General purpose clock outputs) can toggle a output pin.
2//!
3//! The LED on the RP Pico W board is connected differently. Add a LED and resistor to another pin.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/i2c_async.rs b/examples/rp/src/bin/i2c_async.rs
index cf3cf742c..93224bc43 100644
--- a/examples/rp/src/bin/i2c_async.rs
+++ b/examples/rp/src/bin/i2c_async.rs
@@ -1,3 +1,8 @@
1//! This example shows how to communicate asynchronous using i2c with external chips.
2//!
3//! Example written for the [`MCP23017 16-Bit I2C I/O Expander with Serial Interface`] chip.
4//! (https://www.microchip.com/en-us/product/mcp23017)
5
1#![no_std] 6#![no_std]
2#![no_main] 7#![no_main]
3#![feature(type_alias_impl_trait)] 8#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/i2c_blocking.rs b/examples/rp/src/bin/i2c_blocking.rs
index 7623e33c8..1c8c2039d 100644
--- a/examples/rp/src/bin/i2c_blocking.rs
+++ b/examples/rp/src/bin/i2c_blocking.rs
@@ -1,3 +1,8 @@
1//! This example shows how to communicate using i2c with external chips.
2//!
3//! Example written for the [`MCP23017 16-Bit I2C I/O Expander with Serial Interface`] chip.
4//! (https://www.microchip.com/en-us/product/mcp23017)
5
1#![no_std] 6#![no_std]
2#![no_main] 7#![no_main]
3#![feature(type_alias_impl_trait)] 8#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/lora_lorawan.rs b/examples/rp/src/bin/lora_lorawan.rs
index a9c84bf95..d631fafa1 100644
--- a/examples/rp/src/bin/lora_lorawan.rs
+++ b/examples/rp/src/bin/lora_lorawan.rs
@@ -1,5 +1,6 @@
1//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. 1//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
2//! It demonstrates LoRaWAN join functionality. 2//! It demonstrates LoRaWAN join functionality.
3
3#![no_std] 4#![no_std]
4#![no_main] 5#![no_main]
5#![macro_use] 6#![macro_use]
diff --git a/examples/rp/src/bin/lora_p2p_receive.rs b/examples/rp/src/bin/lora_p2p_receive.rs
index 250419202..396d669de 100644
--- a/examples/rp/src/bin/lora_p2p_receive.rs
+++ b/examples/rp/src/bin/lora_p2p_receive.rs
@@ -1,5 +1,6 @@
1//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. 1//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
2//! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example. 2//! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example.
3
3#![no_std] 4#![no_std]
4#![no_main] 5#![no_main]
5#![macro_use] 6#![macro_use]
diff --git a/examples/rp/src/bin/lora_p2p_send.rs b/examples/rp/src/bin/lora_p2p_send.rs
index 3a0544b17..a0f70fa5c 100644
--- a/examples/rp/src/bin/lora_p2p_send.rs
+++ b/examples/rp/src/bin/lora_p2p_send.rs
@@ -1,5 +1,6 @@
1//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. 1//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
2//! It demonstrates LORA P2P send functionality. 2//! It demonstrates LORA P2P send functionality.
3
3#![no_std] 4#![no_std]
4#![no_main] 5#![no_main]
5#![macro_use] 6#![macro_use]
diff --git a/examples/rp/src/bin/lora_p2p_send_multicore.rs b/examples/rp/src/bin/lora_p2p_send_multicore.rs
index eef2f7a53..89a62818d 100644
--- a/examples/rp/src/bin/lora_p2p_send_multicore.rs
+++ b/examples/rp/src/bin/lora_p2p_send_multicore.rs
@@ -1,5 +1,6 @@
1//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. 1//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
2//! It demonstrates LORA P2P send functionality using the second core, with data provided by the first core. 2//! It demonstrates LORA P2P send functionality using the second core, with data provided by the first core.
3
3#![no_std] 4#![no_std]
4#![no_main] 5#![no_main]
5#![macro_use] 6#![macro_use]
diff --git a/examples/rp/src/bin/multicore.rs b/examples/rp/src/bin/multicore.rs
index 57278dd6c..893b724bf 100644
--- a/examples/rp/src/bin/multicore.rs
+++ b/examples/rp/src/bin/multicore.rs
@@ -1,3 +1,7 @@
1//! This example shows how to send messages between the two cores in the RP2040 chip.
2//!
3//! The LED on the RP Pico W board is connected differently. See wifi_blinky.rs.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs
index 69034c92a..c001d6440 100644
--- a/examples/rp/src/bin/pio_async.rs
+++ b/examples/rp/src/bin/pio_async.rs
@@ -1,3 +1,5 @@
1//! This example shows powerful PIO module in the RP2040 chip.
2
1#![no_std] 3#![no_std]
2#![no_main] 4#![no_main]
3#![feature(type_alias_impl_trait)] 5#![feature(type_alias_impl_trait)]
@@ -54,7 +56,14 @@ fn setup_pio_task_sm1<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
54 // Setupm sm1 56 // Setupm sm1
55 57
56 // Read 0b10101 repeatedly until ISR is full 58 // Read 0b10101 repeatedly until ISR is full
57 let prg = pio_proc::pio_asm!(".origin 8", "set x, 0x15", ".wrap_target", "in x, 5 [31]", ".wrap",); 59 let prg = pio_proc::pio_asm!(
60 //
61 ".origin 8",
62 "set x, 0x15",
63 ".wrap_target",
64 "in x, 5 [31]",
65 ".wrap",
66 );
58 67
59 let relocated = RelocatedProgram::new(&prg.program); 68 let relocated = RelocatedProgram::new(&prg.program);
60 let mut cfg = Config::default(); 69 let mut cfg = Config::default();
diff --git a/examples/rp/src/bin/pio_dma.rs b/examples/rp/src/bin/pio_dma.rs
index 80c963556..9ab72e1f3 100644
--- a/examples/rp/src/bin/pio_dma.rs
+++ b/examples/rp/src/bin/pio_dma.rs
@@ -1,3 +1,5 @@
1//! This example shows powerful PIO module in the RP2040 chip.
2
1#![no_std] 3#![no_std]
2#![no_main] 4#![no_main]
3#![feature(type_alias_impl_trait)] 5#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/pio_hd44780.rs b/examples/rp/src/bin/pio_hd44780.rs
index 0a4514a66..8aedd24b6 100644
--- a/examples/rp/src/bin/pio_hd44780.rs
+++ b/examples/rp/src/bin/pio_hd44780.rs
@@ -1,3 +1,6 @@
1//! This example shows powerful PIO module in the RP2040 chip to communicate with a HD44780 display.
2//! See (https://www.sparkfun.com/datasheets/LCD/HD44780.pdf)
3
1#![no_std] 4#![no_std]
2#![no_main] 5#![no_main]
3#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/pio_ws2812.rs b/examples/rp/src/bin/pio_ws2812.rs
index 4a111e7aa..3de2bd48d 100644
--- a/examples/rp/src/bin/pio_ws2812.rs
+++ b/examples/rp/src/bin/pio_ws2812.rs
@@ -1,3 +1,6 @@
1//! This example shows powerful PIO module in the RP2040 chip to communicate with WS2812 LED modules.
2//! See (https://www.sparkfun.com/categories/tags/ws2812)
3
1#![no_std] 4#![no_std]
2#![no_main] 5#![no_main]
3#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/pwm.rs b/examples/rp/src/bin/pwm.rs
index 2b3d5d97a..9d919287c 100644
--- a/examples/rp/src/bin/pwm.rs
+++ b/examples/rp/src/bin/pwm.rs
@@ -1,3 +1,7 @@
1//! This example shows how to use PWM (Pulse Width Modulation) in the RP2040 chip.
2//!
3//! The LED on the RP Pico W board is connected differently. Add a LED and resistor to another pin.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/rtc.rs b/examples/rp/src/bin/rtc.rs
new file mode 100644
index 000000000..15aa8243f
--- /dev/null
+++ b/examples/rp/src/bin/rtc.rs
@@ -0,0 +1,46 @@
1//! This example shows how to use RTC (Real Time Clock) in the RP2040 chip.
2
3#![no_std]
4#![no_main]
5#![feature(type_alias_impl_trait)]
6
7use defmt::*;
8use embassy_executor::Spawner;
9use embassy_rp::rtc::{DateTime, DayOfWeek, Rtc};
10use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _};
12
13#[embassy_executor::main]
14async fn main(_spawner: Spawner) {
15 let p = embassy_rp::init(Default::default());
16 info!("Wait for 20s");
17
18 let mut rtc = Rtc::new(p.RTC);
19
20 if !rtc.is_running() {
21 info!("Start RTC");
22 let now = DateTime {
23 year: 2000,
24 month: 1,
25 day: 1,
26 day_of_week: DayOfWeek::Saturday,
27 hour: 0,
28 minute: 0,
29 second: 0,
30 };
31 rtc.set_datetime(now).unwrap();
32 }
33
34 Timer::after(Duration::from_millis(20000)).await;
35
36 if let Ok(dt) = rtc.now() {
37 info!(
38 "Now: {}-{:02}-{:02} {}:{:02}:{:02}",
39 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
40 );
41 }
42
43 info!("Reboot.");
44 Timer::after(Duration::from_millis(200)).await;
45 cortex_m::peripheral::SCB::sys_reset();
46}
diff --git a/examples/rp/src/bin/spi.rs b/examples/rp/src/bin/spi.rs
index a830a17a2..602348f7a 100644
--- a/examples/rp/src/bin/spi.rs
+++ b/examples/rp/src/bin/spi.rs
@@ -1,3 +1,7 @@
1//! This example shows how to use SPI (Serial Peripheral Interface) in the RP2040 chip.
2//!
3//! Example for resistive touch sensor in Waveshare Pico-ResTouch
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/spi_async.rs b/examples/rp/src/bin/spi_async.rs
index 671a9caaf..328074e8b 100644
--- a/examples/rp/src/bin/spi_async.rs
+++ b/examples/rp/src/bin/spi_async.rs
@@ -1,3 +1,6 @@
1//! This example shows how to use SPI (Serial Peripheral Interface) in the RP2040 chip.
2//! No specific hardware is specified in this example. If you connect pin 11 and 12 you should get the same data back.
3
1#![no_std] 4#![no_std]
2#![no_main] 5#![no_main]
3#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/spi_display.rs b/examples/rp/src/bin/spi_display.rs
index 2fd201595..26c258e1c 100644
--- a/examples/rp/src/bin/spi_display.rs
+++ b/examples/rp/src/bin/spi_display.rs
@@ -1,3 +1,8 @@
1//! This example shows how to use SPI (Serial Peripheral Interface) in the RP2040 chip.
2//!
3//! Example written for a display using the ST7789 chip. Possibly the Waveshare Pico-ResTouch
4//! (https://www.waveshare.com/wiki/Pico-ResTouch-LCD-2.8)
5
1#![no_std] 6#![no_std]
2#![no_main] 7#![no_main]
3#![feature(type_alias_impl_trait)] 8#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/uart.rs b/examples/rp/src/bin/uart.rs
index 05177a6b4..451c3c396 100644
--- a/examples/rp/src/bin/uart.rs
+++ b/examples/rp/src/bin/uart.rs
@@ -1,3 +1,9 @@
1//! This example shows how to use UART (Universal asynchronous receiver-transmitter) in the RP2040 chip.
2//!
3//! No specific hardware is specified in this example. Only output on pin 0 is tested.
4//! The Raspberry Pi Debug Probe (https://www.raspberrypi.com/products/debug-probe/) could be used
5//! with its UART port.
6
1#![no_std] 7#![no_std]
2#![no_main] 8#![no_main]
3#![feature(type_alias_impl_trait)] 9#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/uart_buffered_split.rs b/examples/rp/src/bin/uart_buffered_split.rs
index 9df99bd58..735201718 100644
--- a/examples/rp/src/bin/uart_buffered_split.rs
+++ b/examples/rp/src/bin/uart_buffered_split.rs
@@ -1,3 +1,9 @@
1//! This example shows how to use UART (Universal asynchronous receiver-transmitter) in the RP2040 chip.
2//!
3//! No specific hardware is specified in this example. If you connect pin 0 and 1 you should get the same data back.
4//! The Raspberry Pi Debug Probe (https://www.raspberrypi.com/products/debug-probe/) could be used
5//! with its UART port.
6
1#![no_std] 7#![no_std]
2#![no_main] 8#![no_main]
3#![feature(type_alias_impl_trait)] 9#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/uart_unidir.rs b/examples/rp/src/bin/uart_unidir.rs
index c0943a1b8..c1515a911 100644
--- a/examples/rp/src/bin/uart_unidir.rs
+++ b/examples/rp/src/bin/uart_unidir.rs
@@ -1,5 +1,9 @@
1//! test TX-only and RX-only UARTs. You need to connect GPIO0 to GPIO5 for 1//! This example shows how to use UART (Universal asynchronous receiver-transmitter) in the RP2040 chip.
2//!
3//! Test TX-only and RX-only on two different UARTs. You need to connect GPIO0 to GPIO5 for
2//! this to work 4//! this to work
5//! The Raspberry Pi Debug Probe (https://www.raspberrypi.com/products/debug-probe/) could be used
6//! with its UART port.
3 7
4#![no_std] 8#![no_std]
5#![no_main] 9#![no_main]
diff --git a/examples/rp/src/bin/usb_ethernet.rs b/examples/rp/src/bin/usb_ethernet.rs
index 91d1ec8e7..0a08f667e 100644
--- a/examples/rp/src/bin/usb_ethernet.rs
+++ b/examples/rp/src/bin/usb_ethernet.rs
@@ -1,3 +1,7 @@
1//! This example shows how to use USB (Universal Serial Bus) in the RP2040 chip.
2//!
3//! This is a CDC-NCM class implementation, aka Ethernet over USB.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/usb_logger.rs b/examples/rp/src/bin/usb_logger.rs
index 7c90d0ca3..9c5e6897d 100644
--- a/examples/rp/src/bin/usb_logger.rs
+++ b/examples/rp/src/bin/usb_logger.rs
@@ -1,3 +1,7 @@
1//! This example shows how to use USB (Universal Serial Bus) in the RP2040 chip.
2//!
3//! This creates the possibility to send log::info/warn/error/debug! to USB serial port.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/usb_serial.rs b/examples/rp/src/bin/usb_serial.rs
index ca728536c..164e2052d 100644
--- a/examples/rp/src/bin/usb_serial.rs
+++ b/examples/rp/src/bin/usb_serial.rs
@@ -1,3 +1,7 @@
1//! This example shows how to use USB (Universal Serial Bus) in the RP2040 chip.
2//!
3//! This creates a USB serial port that echos.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/watchdog.rs b/examples/rp/src/bin/watchdog.rs
index ece5cfe38..fe5eaf926 100644
--- a/examples/rp/src/bin/watchdog.rs
+++ b/examples/rp/src/bin/watchdog.rs
@@ -1,3 +1,7 @@
1//! This example shows how to use Watchdog in the RP2040 chip.
2//!
3//! It does not work with the RP Pico W board. See wifi_blinky.rs or connect external LED and resistor.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/wifi_ap_tcp_server.rs b/examples/rp/src/bin/wifi_ap_tcp_server.rs
index 3e41f83be..e3e393445 100644
--- a/examples/rp/src/bin/wifi_ap_tcp_server.rs
+++ b/examples/rp/src/bin/wifi_ap_tcp_server.rs
@@ -1,3 +1,6 @@
1//! This example uses the RP Pico W board Wifi chip (cyw43).
2//! Creates an Access point Wifi network and creates a TCP endpoint on port 1234.
3
1#![no_std] 4#![no_std]
2#![no_main] 5#![no_main]
3#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/wifi_blinky.rs b/examples/rp/src/bin/wifi_blinky.rs
index 6eb207af6..33d43788c 100644
--- a/examples/rp/src/bin/wifi_blinky.rs
+++ b/examples/rp/src/bin/wifi_blinky.rs
@@ -1,3 +1,7 @@
1//! This example test the RP Pico W on board LED.
2//!
3//! It does not work with the RP Pico board. See blinky.rs.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/wifi_scan.rs b/examples/rp/src/bin/wifi_scan.rs
index aef18aa24..743fab617 100644
--- a/examples/rp/src/bin/wifi_scan.rs
+++ b/examples/rp/src/bin/wifi_scan.rs
@@ -1,3 +1,6 @@
1//! This example uses the RP Pico W board Wifi chip (cyw43).
2//! Scans Wifi for ssid names.
3
1#![no_std] 4#![no_std]
2#![no_main] 5#![no_main]
3#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs
index 4fce74a66..0223a3636 100644
--- a/examples/rp/src/bin/wifi_tcp_server.rs
+++ b/examples/rp/src/bin/wifi_tcp_server.rs
@@ -1,3 +1,6 @@
1//! This example uses the RP Pico W board Wifi chip (cyw43).
2//! Connects to specified Wifi network and creates a TCP endpoint on port 1234.
3
1#![no_std] 4#![no_std]
2#![no_main] 5#![no_main]
3#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml
index f23c8afa6..becf2d3fb 100644
--- a/examples/stm32wb/Cargo.toml
+++ b/examples/stm32wb/Cargo.toml
@@ -43,5 +43,6 @@ required-features = ["mac"]
43name = "eddystone_beacon" 43name = "eddystone_beacon"
44required-features = ["ble"] 44required-features = ["ble"]
45 45
46[patch.crates-io] 46[[bin]]
47stm32wb-hci = { git = "https://github.com/OueslatiGhaith/stm32wb-hci", rev = "9f663be"} \ No newline at end of file 47name = "gatt_server"
48required-features = ["ble"] \ No newline at end of file
diff --git a/examples/stm32wb/src/bin/gatt_server.rs b/examples/stm32wb/src/bin/gatt_server.rs
new file mode 100644
index 000000000..7621efb11
--- /dev/null
+++ b/examples/stm32wb/src/bin/gatt_server.rs
@@ -0,0 +1,397 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use core::time::Duration;
6
7use defmt::*;
8use embassy_executor::Spawner;
9use embassy_stm32::bind_interrupts;
10use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
11use embassy_stm32_wpan::hci::event::command::{CommandComplete, ReturnParameters};
12use embassy_stm32_wpan::hci::host::uart::{Packet, UartHci};
13use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType};
14use embassy_stm32_wpan::hci::types::AdvertisingType;
15use embassy_stm32_wpan::hci::vendor::stm32wb::command::gap::{
16 AddressType, AuthenticationRequirements, DiscoverableParameters, GapCommands, IoCapability, LocalName, Pin, Role,
17 SecureConnectionSupport,
18};
19use embassy_stm32_wpan::hci::vendor::stm32wb::command::gatt::{
20 AddCharacteristicParameters, AddServiceParameters, CharacteristicEvent, CharacteristicPermission,
21 CharacteristicProperty, EncryptionKeySize, GattCommands, ServiceType, UpdateCharacteristicValueParameters, Uuid,
22 WriteResponseParameters,
23};
24use embassy_stm32_wpan::hci::vendor::stm32wb::command::hal::{ConfigData, HalCommands, PowerLevel};
25use embassy_stm32_wpan::hci::vendor::stm32wb::event::{self, AttributeHandle, Stm32Wb5xEvent};
26use embassy_stm32_wpan::hci::{BdAddr, Event};
27use embassy_stm32_wpan::lhci::LhciC1DeviceInformationCcrp;
28use embassy_stm32_wpan::sub::ble::Ble;
29use embassy_stm32_wpan::TlMbox;
30use {defmt_rtt as _, panic_probe as _};
31
32bind_interrupts!(struct Irqs{
33 IPCC_C1_RX => ReceiveInterruptHandler;
34 IPCC_C1_TX => TransmitInterruptHandler;
35});
36
37const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7;
38
39#[embassy_executor::main]
40async fn main(_spawner: Spawner) {
41 /*
42 How to make this work:
43
44 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
45 - Download and Install STM32CubeProgrammer.
46 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
47 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
48 - Open STM32CubeProgrammer
49 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
50 - Once complete, click connect to connect to the device.
51 - On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
52 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
53 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
54 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
55 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
56 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
57 - Select "Start Wireless Stack".
58 - Disconnect from the device.
59 - In the examples folder for stm32wb, modify the memory.x file to match your target device.
60 - Run this example.
61
62 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
63 */
64
65 let p = embassy_stm32::init(Default::default());
66 info!("Hello World!");
67
68 let config = Config::default();
69 let mut mbox = TlMbox::init(p.IPCC, Irqs, config);
70
71 let sys_event = mbox.sys_subsystem.read().await;
72 info!("sys event: {}", sys_event.payload());
73
74 mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
75
76 info!("resetting BLE...");
77 mbox.ble_subsystem.reset().await;
78 let response = mbox.ble_subsystem.read().await;
79 defmt::debug!("{}", response);
80
81 info!("config public address...");
82 mbox.ble_subsystem
83 .write_config_data(&ConfigData::public_address(get_bd_addr()).build())
84 .await;
85 let response = mbox.ble_subsystem.read().await;
86 defmt::debug!("{}", response);
87
88 info!("config random address...");
89 mbox.ble_subsystem
90 .write_config_data(&ConfigData::random_address(get_random_addr()).build())
91 .await;
92 let response = mbox.ble_subsystem.read().await;
93 defmt::debug!("{}", response);
94
95 info!("config identity root...");
96 mbox.ble_subsystem
97 .write_config_data(&ConfigData::identity_root(&get_irk()).build())
98 .await;
99 let response = mbox.ble_subsystem.read().await;
100 defmt::debug!("{}", response);
101
102 info!("config encryption root...");
103 mbox.ble_subsystem
104 .write_config_data(&ConfigData::encryption_root(&get_erk()).build())
105 .await;
106 let response = mbox.ble_subsystem.read().await;
107 defmt::debug!("{}", response);
108
109 info!("config tx power level...");
110 mbox.ble_subsystem.set_tx_power_level(PowerLevel::ZerodBm).await;
111 let response = mbox.ble_subsystem.read().await;
112 defmt::debug!("{}", response);
113
114 info!("GATT init...");
115 mbox.ble_subsystem.init_gatt().await;
116 let response = mbox.ble_subsystem.read().await;
117 defmt::debug!("{}", response);
118
119 info!("GAP init...");
120 mbox.ble_subsystem
121 .init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH)
122 .await;
123 let response = mbox.ble_subsystem.read().await;
124 defmt::debug!("{}", response);
125
126 info!("set IO capabilities...");
127 mbox.ble_subsystem.set_io_capability(IoCapability::DisplayConfirm).await;
128 let response = mbox.ble_subsystem.read().await;
129 defmt::debug!("{}", response);
130
131 info!("set authentication requirements...");
132 mbox.ble_subsystem
133 .set_authentication_requirement(&AuthenticationRequirements {
134 bonding_required: false,
135 keypress_notification_support: false,
136 mitm_protection_required: false,
137 encryption_key_size_range: (8, 16),
138 fixed_pin: Pin::Requested,
139 identity_address_type: AddressType::Public,
140 secure_connection_support: SecureConnectionSupport::Optional,
141 })
142 .await
143 .unwrap();
144 let response = mbox.ble_subsystem.read().await;
145 defmt::debug!("{}", response);
146
147 info!("set scan response data...");
148 mbox.ble_subsystem.le_set_scan_response_data(b"TXTX").await.unwrap();
149 let response = mbox.ble_subsystem.read().await;
150 defmt::debug!("{}", response);
151
152 info!("set scan response data...");
153 mbox.ble_subsystem.le_set_scan_response_data(b"TXTX").await.unwrap();
154 let response = mbox.ble_subsystem.read().await;
155 defmt::debug!("{}", response);
156
157 defmt::info!("initializing services and characteristics...");
158 let mut ble_context = init_gatt_services(&mut mbox.ble_subsystem).await.unwrap();
159 defmt::info!("{}", ble_context);
160
161 let discovery_params = DiscoverableParameters {
162 advertising_type: AdvertisingType::ConnectableUndirected,
163 advertising_interval: Some((Duration::from_millis(100), Duration::from_millis(100))),
164 address_type: OwnAddressType::Public,
165 filter_policy: AdvertisingFilterPolicy::AllowConnectionAndScan,
166 local_name: Some(LocalName::Complete(b"TXTX")),
167 advertising_data: &[],
168 conn_interval: (None, None),
169 };
170
171 info!("set discoverable...");
172 mbox.ble_subsystem.set_discoverable(&discovery_params).await.unwrap();
173 let response = mbox.ble_subsystem.read().await;
174 defmt::debug!("{}", response);
175
176 loop {
177 let response = mbox.ble_subsystem.read().await;
178 defmt::debug!("{}", response);
179
180 if let Ok(Packet::Event(event)) = response {
181 match event {
182 Event::LeConnectionComplete(_) => {
183 defmt::info!("connected");
184 }
185 Event::DisconnectionComplete(_) => {
186 defmt::info!("disconnected");
187 ble_context.is_subscribed = false;
188 mbox.ble_subsystem.set_discoverable(&discovery_params).await.unwrap();
189 }
190 Event::Vendor(vendor_event) => match vendor_event {
191 Stm32Wb5xEvent::AttReadPermitRequest(read_req) => {
192 defmt::info!("read request received {}, allowing", read_req);
193 mbox.ble_subsystem.allow_read(read_req.conn_handle).await
194 }
195 Stm32Wb5xEvent::AttWritePermitRequest(write_req) => {
196 defmt::info!("write request received {}, allowing", write_req);
197 mbox.ble_subsystem
198 .write_response(&WriteResponseParameters {
199 conn_handle: write_req.conn_handle,
200 attribute_handle: write_req.attribute_handle,
201 status: Ok(()),
202 value: write_req.value(),
203 })
204 .await
205 .unwrap()
206 }
207 Stm32Wb5xEvent::GattAttributeModified(attribute) => {
208 defmt::info!("{}", ble_context);
209 if attribute.attr_handle.0 == ble_context.chars.notify.0 + 2 {
210 if attribute.data()[0] == 0x01 {
211 defmt::info!("subscribed");
212 ble_context.is_subscribed = true;
213 } else {
214 defmt::info!("unsubscribed");
215 ble_context.is_subscribed = false;
216 }
217 }
218 }
219 _ => {}
220 },
221 _ => {}
222 }
223 }
224 }
225}
226
227fn get_bd_addr() -> BdAddr {
228 let mut bytes = [0u8; 6];
229
230 let lhci_info = LhciC1DeviceInformationCcrp::new();
231 bytes[0] = (lhci_info.uid64 & 0xff) as u8;
232 bytes[1] = ((lhci_info.uid64 >> 8) & 0xff) as u8;
233 bytes[2] = ((lhci_info.uid64 >> 16) & 0xff) as u8;
234 bytes[3] = lhci_info.device_type_id;
235 bytes[4] = (lhci_info.st_company_id & 0xff) as u8;
236 bytes[5] = (lhci_info.st_company_id >> 8 & 0xff) as u8;
237
238 BdAddr(bytes)
239}
240
241fn get_random_addr() -> BdAddr {
242 let mut bytes = [0u8; 6];
243
244 let lhci_info = LhciC1DeviceInformationCcrp::new();
245 bytes[0] = (lhci_info.uid64 & 0xff) as u8;
246 bytes[1] = ((lhci_info.uid64 >> 8) & 0xff) as u8;
247 bytes[2] = ((lhci_info.uid64 >> 16) & 0xff) as u8;
248 bytes[3] = 0;
249 bytes[4] = 0x6E;
250 bytes[5] = 0xED;
251
252 BdAddr(bytes)
253}
254
255const BLE_CFG_IRK: [u8; 16] = [
256 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
257];
258const BLE_CFG_ERK: [u8; 16] = [
259 0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, 0x21, 0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, 0x21,
260];
261
262fn get_irk() -> EncryptionKey {
263 EncryptionKey(BLE_CFG_IRK)
264}
265
266fn get_erk() -> EncryptionKey {
267 EncryptionKey(BLE_CFG_ERK)
268}
269
270#[derive(defmt::Format)]
271pub struct BleContext {
272 pub service_handle: AttributeHandle,
273 pub chars: CharHandles,
274 pub is_subscribed: bool,
275}
276
277#[derive(defmt::Format)]
278pub struct CharHandles {
279 pub read: AttributeHandle,
280 pub write: AttributeHandle,
281 pub notify: AttributeHandle,
282}
283
284pub async fn init_gatt_services(ble_subsystem: &mut Ble) -> Result<BleContext, ()> {
285 let service_handle = gatt_add_service(ble_subsystem, Uuid::Uuid16(0x500)).await?;
286
287 let read = gatt_add_char(
288 ble_subsystem,
289 service_handle,
290 Uuid::Uuid16(0x501),
291 CharacteristicProperty::READ,
292 Some(b"Hello from embassy!"),
293 )
294 .await?;
295
296 let write = gatt_add_char(
297 ble_subsystem,
298 service_handle,
299 Uuid::Uuid16(0x502),
300 CharacteristicProperty::WRITE_WITHOUT_RESPONSE | CharacteristicProperty::WRITE | CharacteristicProperty::READ,
301 None,
302 )
303 .await?;
304
305 let notify = gatt_add_char(
306 ble_subsystem,
307 service_handle,
308 Uuid::Uuid16(0x503),
309 CharacteristicProperty::NOTIFY | CharacteristicProperty::READ,
310 None,
311 )
312 .await?;
313
314 Ok(BleContext {
315 service_handle,
316 is_subscribed: false,
317 chars: CharHandles { read, write, notify },
318 })
319}
320
321async fn gatt_add_service(ble_subsystem: &mut Ble, uuid: Uuid) -> Result<AttributeHandle, ()> {
322 ble_subsystem
323 .add_service(&AddServiceParameters {
324 uuid,
325 service_type: ServiceType::Primary,
326 max_attribute_records: 8,
327 })
328 .await;
329 let response = ble_subsystem.read().await;
330 defmt::debug!("{}", response);
331
332 if let Ok(Packet::Event(Event::CommandComplete(CommandComplete {
333 return_params:
334 ReturnParameters::Vendor(event::command::ReturnParameters::GattAddService(event::command::GattService {
335 service_handle,
336 ..
337 })),
338 ..
339 }))) = response
340 {
341 Ok(service_handle)
342 } else {
343 Err(())
344 }
345}
346
347async fn gatt_add_char(
348 ble_subsystem: &mut Ble,
349 service_handle: AttributeHandle,
350 characteristic_uuid: Uuid,
351 characteristic_properties: CharacteristicProperty,
352 default_value: Option<&[u8]>,
353) -> Result<AttributeHandle, ()> {
354 ble_subsystem
355 .add_characteristic(&AddCharacteristicParameters {
356 service_handle,
357 characteristic_uuid,
358 characteristic_properties,
359 characteristic_value_len: 32,
360 security_permissions: CharacteristicPermission::empty(),
361 gatt_event_mask: CharacteristicEvent::all(),
362 encryption_key_size: EncryptionKeySize::with_value(7).unwrap(),
363 is_variable: true,
364 })
365 .await;
366 let response = ble_subsystem.read().await;
367 defmt::debug!("{}", response);
368
369 if let Ok(Packet::Event(Event::CommandComplete(CommandComplete {
370 return_params:
371 ReturnParameters::Vendor(event::command::ReturnParameters::GattAddCharacteristic(
372 event::command::GattCharacteristic {
373 characteristic_handle, ..
374 },
375 )),
376 ..
377 }))) = response
378 {
379 if let Some(value) = default_value {
380 ble_subsystem
381 .update_characteristic_value(&UpdateCharacteristicValueParameters {
382 service_handle,
383 characteristic_handle,
384 offset: 0,
385 value,
386 })
387 .await
388 .unwrap();
389
390 let response = ble_subsystem.read().await;
391 defmt::debug!("{}", response);
392 }
393 Ok(characteristic_handle)
394 } else {
395 Err(())
396 }
397}
diff --git a/examples/stm32wl/.cargo/config.toml b/examples/stm32wl/.cargo/config.toml
index 4f8094ff2..ee416fcbc 100644
--- a/examples/stm32wl/.cargo/config.toml
+++ b/examples/stm32wl/.cargo/config.toml
@@ -3,7 +3,7 @@
3runner = "probe-rs run --chip STM32WLE5JCIx" 3runner = "probe-rs run --chip STM32WLE5JCIx"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabihf" 6target = "thumbv7em-none-eabi"
7 7
8[env] 8[env]
9DEFMT_LOG = "trace" 9DEFMT_LOG = "trace"
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml
index 99f68387f..e2c66f456 100644
--- a/examples/stm32wl/Cargo.toml
+++ b/examples/stm32wl/Cargo.toml
@@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0"
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti", "chrono"] }
12embassy-embedded-hal = {version = "0.1.0", path = "../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" }
13embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } 13embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] }
14lora-phy = { version = "1" } 14lora-phy = { version = "1" }
15lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"] } 15lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"] }
@@ -25,6 +25,7 @@ embedded-storage = "0.3.0"
25panic-probe = { version = "0.3", features = ["print-defmt"] } 25panic-probe = { version = "0.3", features = ["print-defmt"] }
26futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 26futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
27heapless = { version = "0.7.5", default-features = false } 27heapless = { version = "0.7.5", default-features = false }
28chrono = { version = "^0.4", default-features = false }
28 29
29[patch.crates-io] 30[patch.crates-io]
30lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" } 31lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" }
diff --git a/examples/stm32wl/src/bin/rtc.rs b/examples/stm32wl/src/bin/rtc.rs
new file mode 100644
index 000000000..e11825499
--- /dev/null
+++ b/examples/stm32wl/src/bin/rtc.rs
@@ -0,0 +1,43 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use chrono::{NaiveDate, NaiveDateTime};
6use defmt::*;
7use embassy_executor::Spawner;
8use embassy_stm32::rcc::{self, ClockSrc};
9use embassy_stm32::rtc::{Rtc, RtcConfig};
10use embassy_stm32::Config;
11use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _};
13
14#[embassy_executor::main]
15async fn main(_spawner: Spawner) {
16 let p = {
17 let mut config = Config::default();
18 config.rcc.mux = ClockSrc::HSE32;
19 config.rcc.rtc_mux = rcc::RtcClockSource::LSE32;
20 config.rcc.enable_rtc_apb = true;
21 embassy_stm32::init(config)
22 };
23 info!("Hello World!");
24
25 let now = NaiveDate::from_ymd_opt(2020, 5, 15)
26 .unwrap()
27 .and_hms_opt(10, 30, 15)
28 .unwrap();
29
30 let mut rtc = Rtc::new(
31 p.RTC,
32 RtcConfig::default().clock_config(embassy_stm32::rtc::RtcClockSource::LSE),
33 );
34 info!("Got RTC! {:?}", now.timestamp());
35
36 rtc.set_datetime(now.into()).expect("datetime not set");
37
38 // In reality the delay would be much longer
39 Timer::after(Duration::from_millis(20000)).await;
40
41 let then: NaiveDateTime = rtc.now().unwrap().into();
42 info!("Got RTC! {:?}", then.timestamp());
43}