aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMatteo Meluzzi <[email protected]>2025-10-02 10:53:31 +0200
committerMatteo Meluzzi <[email protected]>2025-10-02 10:53:31 +0200
commit828a8df18d04877df1f55f04354980b28ff2f2f8 (patch)
treec4fa405f5eba7a14b6d435d6cc746c9e0dc52632 /examples
parent176649e71ad442ca9856af6c11989b0b2f228c4b (diff)
parent194a721d0eab929a2af0a2a4e45ca8e70e0d3f0a (diff)
Merge branch 'main' into 17-add-support-for-boot-protocol
Diffstat (limited to 'examples')
-rw-r--r--examples/boot/application/nrf/Cargo.toml4
-rw-r--r--examples/lpc55s69/src/bin/usart_async.rs70
-rw-r--r--examples/mimxrt1011/Cargo.toml2
-rw-r--r--examples/mimxrt1062-evk/Cargo.toml2
-rw-r--r--examples/mimxrt6/Cargo.toml2
-rw-r--r--examples/nrf-rtos-trace/Cargo.toml2
-rw-r--r--examples/nrf51/Cargo.toml2
-rw-r--r--examples/nrf52810/Cargo.toml2
-rw-r--r--examples/nrf52810/src/bin/saadc_lowpower.rs62
-rw-r--r--examples/nrf52840-edf/Cargo.toml2
-rw-r--r--examples/nrf52840-rtic/Cargo.toml2
-rw-r--r--examples/nrf52840/Cargo.toml3
-rw-r--r--examples/nrf52840/src/bin/ethernet_enc28j60.rs2
-rw-r--r--examples/nrf52840/src/bin/rtc.rs56
-rw-r--r--examples/nrf52840/src/bin/sixlowpan.rs2
-rw-r--r--examples/nrf52840/src/bin/uart_split.rs2
-rw-r--r--examples/nrf52840/src/bin/usb_ethernet.rs2
-rw-r--r--examples/nrf52840/src/bin/usb_serial.rs6
-rw-r--r--examples/nrf52840/src/bin/usb_serial_multitask.rs2
-rw-r--r--examples/nrf52840/src/bin/usb_serial_winusb.rs6
-rw-r--r--examples/nrf52840/src/bin/wifi_esp_hosted.rs2
-rw-r--r--examples/nrf5340/Cargo.toml2
-rw-r--r--examples/nrf54l15/Cargo.toml2
-rw-r--r--examples/nrf9151/ns/Cargo.toml2
-rw-r--r--examples/nrf9151/s/Cargo.toml2
-rw-r--r--examples/nrf9160/Cargo.toml2
-rw-r--r--examples/nrf9160/src/bin/modem_tcp_client.rs2
-rw-r--r--examples/rp235x/src/bin/multicore_stack_overflow.rs72
-rw-r--r--examples/stm32f4/src/bin/mco.rs18
-rw-r--r--examples/stm32h5/src/bin/mco.rs29
-rw-r--r--examples/stm32h7/src/bin/camera.rs11
-rw-r--r--examples/stm32h7/src/bin/mco.rs10
-rw-r--r--examples/stm32h7rs/src/bin/mco.rs10
-rw-r--r--examples/stm32l4/src/bin/mco.rs10
34 files changed, 365 insertions, 42 deletions
diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml
index b0cc63a6c..f5f89ecb5 100644
--- a/examples/boot/application/nrf/Cargo.toml
+++ b/examples/boot/application/nrf/Cargo.toml
@@ -9,9 +9,9 @@ publish = false
9embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } 9embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" }
10embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "arch-cortex-m", "executor-thread"] } 10embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "arch-cortex-m", "executor-thread"] }
11embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [] } 11embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [] }
12embassy-nrf = { version = "0.7.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", ] } 12embassy-nrf = { version = "0.8.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", ] }
13embassy-boot = { version = "0.6.1", path = "../../../../embassy-boot", features = [] } 13embassy-boot = { version = "0.6.1", path = "../../../../embassy-boot", features = [] }
14embassy-boot-nrf = { version = "0.8.0", path = "../../../../embassy-boot-nrf", features = [] } 14embassy-boot-nrf = { version = "0.9.0", path = "../../../../embassy-boot-nrf", features = [] }
15embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } 15embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" }
16 16
17defmt = { version = "1.0.1", optional = true } 17defmt = { version = "1.0.1", optional = true }
diff --git a/examples/lpc55s69/src/bin/usart_async.rs b/examples/lpc55s69/src/bin/usart_async.rs
new file mode 100644
index 000000000..b06abd477
--- /dev/null
+++ b/examples/lpc55s69/src/bin/usart_async.rs
@@ -0,0 +1,70 @@
1#![no_std]
2#![no_main]
3
4use core::str::from_utf8_mut;
5
6use defmt::*;
7use embassy_executor::Spawner;
8use embassy_nxp::bind_interrupts;
9use embassy_nxp::gpio::{Level, Output};
10use embassy_nxp::peripherals::USART2;
11use embassy_nxp::usart::{Config, InterruptHandler, Usart};
12use embassy_time::Timer;
13use {defmt_rtt as _, panic_halt as _};
14
15bind_interrupts!(struct Irqs {
16 FLEXCOMM2 => InterruptHandler<USART2>;
17 }
18);
19
20#[embassy_executor::task]
21async fn blinky_task(mut led: Output<'static>) {
22 loop {
23 info!("[TASK] led off!");
24 led.set_high();
25 Timer::after_millis(500).await;
26
27 info!("[TASK] led on!");
28 led.set_low();
29 Timer::after_millis(500).await;
30 }
31}
32
33#[embassy_executor::main]
34async fn main(spawner: Spawner) {
35 let p = embassy_nxp::init(Default::default());
36 let mut usart = Usart::new(
37 p.USART2,
38 p.PIO0_27,
39 p.PIO1_24,
40 Irqs,
41 p.DMA_CH11,
42 p.DMA_CH10,
43 Config::default(),
44 );
45 let led = Output::new(p.PIO1_6, Level::Low);
46 spawner.spawn(blinky_task(led).unwrap());
47 info!("[MAIN] Entering main loop");
48 loop {
49 let tx_buf = b"Hello, Ferris!";
50 let mut rx_buf = [0u8; 14];
51 info!("[MAIN] Write a message");
52 usart.write(tx_buf).await.unwrap();
53 Timer::after_millis(500).await;
54
55 info!("[MAIN] Read a message");
56 match usart.read(&mut rx_buf).await {
57 Ok(_) => match from_utf8_mut(&mut rx_buf) {
58 Ok(str) => {
59 info!("[MAIN] The message is: {}", str);
60 }
61 Err(_) => {
62 error!("[MAIN] Error in converting to UTF8");
63 }
64 },
65 Err(e) => warn!("[MAIN] Error: {}", e),
66 }
67
68 Timer::after_millis(500).await;
69 }
70}
diff --git a/examples/mimxrt1011/Cargo.toml b/examples/mimxrt1011/Cargo.toml
index 488f3167b..3038f5d4d 100644
--- a/examples/mimxrt1011/Cargo.toml
+++ b/examples/mimxrt1011/Cargo.toml
@@ -2,7 +2,7 @@
2name = "embassy-imxrt1011-examples" 2name = "embassy-imxrt1011-examples"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2021"
5license = "MIT or Apache-2.0" 5license = "MIT OR Apache-2.0"
6publish = false 6publish = false
7 7
8[dependencies] 8[dependencies]
diff --git a/examples/mimxrt1062-evk/Cargo.toml b/examples/mimxrt1062-evk/Cargo.toml
index ec6c5c872..82a24490d 100644
--- a/examples/mimxrt1062-evk/Cargo.toml
+++ b/examples/mimxrt1062-evk/Cargo.toml
@@ -2,7 +2,7 @@
2name = "embassy-imxrt1062-evk-examples" 2name = "embassy-imxrt1062-evk-examples"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2021"
5license = "MIT or Apache-2.0" 5license = "MIT OR Apache-2.0"
6publish = false 6publish = false
7 7
8[dependencies] 8[dependencies]
diff --git a/examples/mimxrt6/Cargo.toml b/examples/mimxrt6/Cargo.toml
index 28de9d273..3f7ad8485 100644
--- a/examples/mimxrt6/Cargo.toml
+++ b/examples/mimxrt6/Cargo.toml
@@ -2,7 +2,7 @@
2name = "embassy-imxrt-examples" 2name = "embassy-imxrt-examples"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2021"
5license = "MIT or Apache-2.0" 5license = "MIT OR Apache-2.0"
6publish = false 6publish = false
7 7
8[dependencies] 8[dependencies]
diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml
index c9eeaaac7..d2d0ae093 100644
--- a/examples/nrf-rtos-trace/Cargo.toml
+++ b/examples/nrf-rtos-trace/Cargo.toml
@@ -19,7 +19,7 @@ log = [
19embassy-sync = { version = "0.7.2", path = "../../embassy-sync" } 19embassy-sync = { version = "0.7.2", path = "../../embassy-sync" }
20embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "rtos-trace"] } 20embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "rtos-trace"] }
21embassy-time = { version = "0.5.0", path = "../../embassy-time" } 21embassy-time = { version = "0.5.0", path = "../../embassy-time" }
22embassy-nrf = { version = "0.7.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } 22embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
23 23
24cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } 24cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
25cortex-m-rt = "0.7.0" 25cortex-m-rt = "0.7.0"
diff --git a/examples/nrf51/Cargo.toml b/examples/nrf51/Cargo.toml
index dded6de59..082d85e5b 100644
--- a/examples/nrf51/Cargo.toml
+++ b/examples/nrf51/Cargo.toml
@@ -8,7 +8,7 @@ publish = false
8[dependencies] 8[dependencies]
9embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } 9embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
10embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 10embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
11embassy-nrf = { version = "0.7.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "gpiote", "time-driver-rtc1", "unstable-pac", "time", "rt"] } 11embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "gpiote", "time-driver-rtc1", "unstable-pac", "time", "rt"] }
12 12
13defmt = "1.0.1" 13defmt = "1.0.1"
14defmt-rtt = "1.0.0" 14defmt-rtt = "1.0.0"
diff --git a/examples/nrf52810/Cargo.toml b/examples/nrf52810/Cargo.toml
index aa1a4bf73..7835320e5 100644
--- a/examples/nrf52810/Cargo.toml
+++ b/examples/nrf52810/Cargo.toml
@@ -10,7 +10,7 @@ embassy-futures = { version = "0.1.2", path = "../../embassy-futures" }
10embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } 11embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
12embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 12embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
13embassy-nrf = { version = "0.7.0", path = "../../embassy-nrf", features = ["defmt", "nrf52810", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } 13embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["defmt", "nrf52810", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
14 14
15defmt = "1.0.1" 15defmt = "1.0.1"
16defmt-rtt = "1.0.0" 16defmt-rtt = "1.0.0"
diff --git a/examples/nrf52810/src/bin/saadc_lowpower.rs b/examples/nrf52810/src/bin/saadc_lowpower.rs
new file mode 100644
index 000000000..d7e7f09a4
--- /dev/null
+++ b/examples/nrf52810/src/bin/saadc_lowpower.rs
@@ -0,0 +1,62 @@
1//! Run SAADC on multiple pins only every 3rd time, to show anomaly 241 workaround.
2//!
3//! To correctly measure the MCU current on the NRF52DK follow the instructions
4//! <https://docs.nordicsemi.com/bundle/ug_nrf52832_dk/page/UG/dk/prepare_board.html>
5//! otherwise you will measure the whole board, including the segger j-link chip for example
6
7#![no_std]
8#![no_main]
9
10use defmt::info;
11use embassy_executor::Spawner;
12use embassy_nrf::gpio::{Level, Output, OutputDrive};
13use embassy_nrf::saadc::{Oversample, Saadc};
14use embassy_nrf::{bind_interrupts, saadc};
15use embassy_time::Timer;
16use {defmt_rtt as _, panic_probe as _};
17
18bind_interrupts!(struct Irqs {
19 SAADC => saadc::InterruptHandler;
20});
21
22#[embassy_executor::main]
23async fn main(_p: Spawner) {
24 let mut p = embassy_nrf::init(Default::default());
25
26 // For PPK2 digital channel plot to track when SAADC is on/off.
27 let mut ppk2_d0 = Output::new(p.P0_27, Level::Low, OutputDrive::Standard);
28 let mut num_loops: usize = 0;
29 loop {
30 num_loops += 1;
31 if num_loops.is_multiple_of(3) {
32 ppk2_d0.set_high();
33 let battery_pin = p.P0_02.reborrow();
34 let sensor1_pin = p.P0_03.reborrow();
35 let mut adc_config = saadc::Config::default();
36 adc_config.oversample = Oversample::OVER4X;
37 let battery = saadc::ChannelConfig::single_ended(battery_pin);
38 let sensor1 = saadc::ChannelConfig::single_ended(sensor1_pin);
39 let mut saadc = Saadc::new(p.SAADC.reborrow(), Irqs, adc_config, [battery, sensor1]);
40 // Indicated: wait for ADC calibration.
41 saadc.calibrate().await;
42 let mut buf = [0; 2];
43 info!("sampling...");
44 saadc.sample(&mut buf).await;
45 info!("data: {:x}", buf);
46
47 // Sleep to show the high power usage on the plot, even though sampling is done.
48 Timer::after_millis(100).await;
49 ppk2_d0.set_low();
50 // disable the following line to show the anomaly on the power profiler plot.
51 core::mem::drop(saadc);
52 // Sleep to show the power usage when drop did not happen.
53 Timer::after_millis(100).await;
54 // worst case drop happens here
55 } else {
56 info!("waiting");
57 }
58 // Sleep for 1 second. The executor ensures the core sleeps with a WFE when it has nothing to do.
59 // During this sleep, the nRF chip should only use ~3uA
60 Timer::after_secs(1).await;
61 }
62}
diff --git a/examples/nrf52840-edf/Cargo.toml b/examples/nrf52840-edf/Cargo.toml
index 1e8803233..67a624d6d 100644
--- a/examples/nrf52840-edf/Cargo.toml
+++ b/examples/nrf52840-edf/Cargo.toml
@@ -9,7 +9,7 @@ publish = false
9# NOTE: "scheduler-deadline" and "embassy-time-driver" features are enabled 9# NOTE: "scheduler-deadline" and "embassy-time-driver" features are enabled
10embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "scheduler-deadline", "embassy-time-driver"] } 10embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "scheduler-deadline", "embassy-time-driver"] }
11embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 11embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
12embassy-nrf = { version = "0.7.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } 12embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
13 13
14defmt = "1.0.1" 14defmt = "1.0.1"
15defmt-rtt = "1.0.0" 15defmt-rtt = "1.0.0"
diff --git a/examples/nrf52840-rtic/Cargo.toml b/examples/nrf52840-rtic/Cargo.toml
index f6937c263..d860626a1 100644
--- a/examples/nrf52840-rtic/Cargo.toml
+++ b/examples/nrf52840-rtic/Cargo.toml
@@ -12,7 +12,7 @@ embassy-futures = { version = "0.1.2", path = "../../embassy-futures" }
12embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } 12embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] }
13embassy-time = { version = "0.5.0", path = "../../embassy-time", features = [ "defmt", "defmt-timestamp-uptime"] } 13embassy-time = { version = "0.5.0", path = "../../embassy-time", features = [ "defmt", "defmt-timestamp-uptime"] }
14embassy-time-queue-utils = { version = "0.3.0", path = "../../embassy-time-queue-utils", features = ["generic-queue-8"] } 14embassy-time-queue-utils = { version = "0.3.0", path = "../../embassy-time-queue-utils", features = ["generic-queue-8"] }
15embassy-nrf = { version = "0.7.0", path = "../../embassy-nrf", features = [ "defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } 15embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = [ "defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
16 16
17defmt = "1.0.1" 17defmt = "1.0.1"
18defmt-rtt = "1.0.0" 18defmt-rtt = "1.0.0"
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml
index 452e83b7e..5b3e176c0 100644
--- a/examples/nrf52840/Cargo.toml
+++ b/examples/nrf52840/Cargo.toml
@@ -10,7 +10,7 @@ embassy-futures = { version = "0.1.2", path = "../../embassy-futures" }
10embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } 11embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
12embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 12embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
13embassy-nrf = { version = "0.7.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time", "net-driver"] } 13embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time", "net-driver"] }
14embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet","udp", "medium-ieee802154", "proto-ipv6"] } 14embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet","udp", "medium-ieee802154", "proto-ipv6"] }
15embassy-usb = { version = "0.5.1", path = "../../embassy-usb", features = ["defmt"] } 15embassy-usb = { version = "0.5.1", path = "../../embassy-usb", features = ["defmt"] }
16embedded-io = { version = "0.6.0", features = ["defmt-03"] } 16embedded-io = { version = "0.6.0", features = ["defmt-03"] }
@@ -35,6 +35,7 @@ embedded-hal-async = { version = "1.0" }
35embedded-hal-bus = { version = "0.1", features = ["async"] } 35embedded-hal-bus = { version = "0.1", features = ["async"] }
36num-integer = { version = "0.1.45", default-features = false } 36num-integer = { version = "0.1.45", default-features = false }
37microfft = "0.5.0" 37microfft = "0.5.0"
38portable-atomic = "1"
38 39
39[profile.release] 40[profile.release]
40debug = 2 41debug = 2
diff --git a/examples/nrf52840/src/bin/ethernet_enc28j60.rs b/examples/nrf52840/src/bin/ethernet_enc28j60.rs
index 3bb255a72..e59afd37f 100644
--- a/examples/nrf52840/src/bin/ethernet_enc28j60.rs
+++ b/examples/nrf52840/src/bin/ethernet_enc28j60.rs
@@ -25,7 +25,7 @@ bind_interrupts!(struct Irqs {
25async fn net_task( 25async fn net_task(
26 mut runner: embassy_net::Runner< 26 mut runner: embassy_net::Runner<
27 'static, 27 'static,
28 Enc28j60<ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static>, Delay>, Output<'static>>, 28 Enc28j60<ExclusiveDevice<Spim<'static>, Output<'static>, Delay>, Output<'static>>,
29 >, 29 >,
30) -> ! { 30) -> ! {
31 runner.run().await 31 runner.run().await
diff --git a/examples/nrf52840/src/bin/rtc.rs b/examples/nrf52840/src/bin/rtc.rs
new file mode 100644
index 000000000..9d475df7f
--- /dev/null
+++ b/examples/nrf52840/src/bin/rtc.rs
@@ -0,0 +1,56 @@
1#![no_std]
2#![no_main]
3
4use core::cell::RefCell;
5
6use embassy_executor::Spawner;
7use embassy_nrf::gpio::{Level, Output, OutputDrive};
8use embassy_nrf::interrupt;
9use embassy_nrf::rtc::Rtc;
10use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
11use embassy_sync::blocking_mutex::Mutex;
12use portable_atomic::AtomicU64;
13use {defmt_rtt as _, panic_probe as _};
14
15// 64 bit counter which will never overflow.
16static TICK_COUNTER: AtomicU64 = AtomicU64::new(0);
17static RTC: Mutex<CriticalSectionRawMutex, RefCell<Option<Rtc<'static>>>> = Mutex::new(RefCell::new(None));
18
19#[embassy_executor::main]
20async fn main(_spawner: Spawner) {
21 defmt::println!("nRF52840 RTC example");
22 let p = embassy_nrf::init(Default::default());
23 let mut led = Output::new(p.P0_13, Level::High, OutputDrive::Standard);
24 // Counter resolution is 125 ms.
25 let mut rtc = Rtc::new(p.RTC0, (1 << 12) - 1).unwrap();
26 rtc.enable_interrupt(embassy_nrf::rtc::Interrupt::Tick, true);
27 rtc.enable_event(embassy_nrf::rtc::Interrupt::Tick);
28 rtc.enable();
29 RTC.lock(|r| {
30 let mut rtc_borrow = r.borrow_mut();
31 *rtc_borrow = Some(rtc);
32 });
33
34 let mut last_counter_val = 0;
35 loop {
36 let current = TICK_COUNTER.load(core::sync::atomic::Ordering::Relaxed);
37 if current != last_counter_val {
38 led.toggle();
39 last_counter_val = current;
40 }
41 }
42}
43
44#[interrupt]
45fn RTC0() {
46 // For 64-bit, we do not need to worry about overflowing, at least not for realistic program
47 // lifetimes.
48 TICK_COUNTER.fetch_add(1, core::sync::atomic::Ordering::Relaxed);
49 RTC.lock(|r| {
50 let mut rtc_borrow = r.borrow_mut();
51 rtc_borrow
52 .as_mut()
53 .unwrap()
54 .reset_event(embassy_nrf::rtc::Interrupt::Tick);
55 });
56}
diff --git a/examples/nrf52840/src/bin/sixlowpan.rs b/examples/nrf52840/src/bin/sixlowpan.rs
index 00a597366..12e385e01 100644
--- a/examples/nrf52840/src/bin/sixlowpan.rs
+++ b/examples/nrf52840/src/bin/sixlowpan.rs
@@ -21,7 +21,7 @@ bind_interrupts!(struct Irqs {
21}); 21});
22 22
23#[embassy_executor::task] 23#[embassy_executor::task]
24async fn ieee802154_task(runner: net::Runner<'static, peripherals::RADIO>) -> ! { 24async fn ieee802154_task(runner: net::Runner<'static>) -> ! {
25 runner.run().await 25 runner.run().await
26} 26}
27 27
diff --git a/examples/nrf52840/src/bin/uart_split.rs b/examples/nrf52840/src/bin/uart_split.rs
index 51af90727..d75143126 100644
--- a/examples/nrf52840/src/bin/uart_split.rs
+++ b/examples/nrf52840/src/bin/uart_split.rs
@@ -52,7 +52,7 @@ async fn main(spawner: Spawner) {
52} 52}
53 53
54#[embassy_executor::task] 54#[embassy_executor::task]
55async fn reader(mut rx: UarteRx<'static, UARTE0>) { 55async fn reader(mut rx: UarteRx<'static>) {
56 let mut buf = [0; 8]; 56 let mut buf = [0; 8];
57 loop { 57 loop {
58 info!("reading..."); 58 info!("reading...");
diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs
index 87aa4c6c5..a75b967b4 100644
--- a/examples/nrf52840/src/bin/usb_ethernet.rs
+++ b/examples/nrf52840/src/bin/usb_ethernet.rs
@@ -22,7 +22,7 @@ bind_interrupts!(struct Irqs {
22 RNG => rng::InterruptHandler<peripherals::RNG>; 22 RNG => rng::InterruptHandler<peripherals::RNG>;
23}); 23});
24 24
25type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; 25type MyDriver = Driver<'static, HardwareVbusDetect>;
26 26
27const MTU: usize = 1514; 27const MTU: usize = 1514;
28 28
diff --git a/examples/nrf52840/src/bin/usb_serial.rs b/examples/nrf52840/src/bin/usb_serial.rs
index 8d05df791..e7c2d0854 100644
--- a/examples/nrf52840/src/bin/usb_serial.rs
+++ b/examples/nrf52840/src/bin/usb_serial.rs
@@ -5,7 +5,7 @@ use defmt::{info, panic};
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_futures::join::join; 6use embassy_futures::join::join;
7use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect}; 7use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect};
8use embassy_nrf::usb::{Driver, Instance}; 8use embassy_nrf::usb::Driver;
9use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; 9use embassy_nrf::{bind_interrupts, pac, peripherals, usb};
10use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; 10use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
11use embassy_usb::driver::EndpointError; 11use embassy_usb::driver::EndpointError;
@@ -89,9 +89,7 @@ impl From<EndpointError> for Disconnected {
89 } 89 }
90} 90}
91 91
92async fn echo<'d, T: Instance + 'd, P: VbusDetect + 'd>( 92async fn echo<'d, V: VbusDetect + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, V>>) -> Result<(), Disconnected> {
93 class: &mut CdcAcmClass<'d, Driver<'d, T, P>>,
94) -> Result<(), Disconnected> {
95 let mut buf = [0; 64]; 93 let mut buf = [0; 64];
96 loop { 94 loop {
97 let n = class.read_packet(&mut buf).await?; 95 let n = class.read_packet(&mut buf).await?;
diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs
index 00a91a233..b6a983854 100644
--- a/examples/nrf52840/src/bin/usb_serial_multitask.rs
+++ b/examples/nrf52840/src/bin/usb_serial_multitask.rs
@@ -17,7 +17,7 @@ bind_interrupts!(struct Irqs {
17 CLOCK_POWER => usb::vbus_detect::InterruptHandler; 17 CLOCK_POWER => usb::vbus_detect::InterruptHandler;
18}); 18});
19 19
20type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; 20type MyDriver = Driver<'static, HardwareVbusDetect>;
21 21
22#[embassy_executor::task] 22#[embassy_executor::task]
23async fn usb_task(mut device: UsbDevice<'static, MyDriver>) { 23async fn usb_task(mut device: UsbDevice<'static, MyDriver>) {
diff --git a/examples/nrf52840/src/bin/usb_serial_winusb.rs b/examples/nrf52840/src/bin/usb_serial_winusb.rs
index 8a20ce673..e30e08a01 100644
--- a/examples/nrf52840/src/bin/usb_serial_winusb.rs
+++ b/examples/nrf52840/src/bin/usb_serial_winusb.rs
@@ -5,7 +5,7 @@ use defmt::{info, panic};
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_futures::join::join; 6use embassy_futures::join::join;
7use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect}; 7use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect};
8use embassy_nrf::usb::{Driver, Instance}; 8use embassy_nrf::usb::Driver;
9use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; 9use embassy_nrf::{bind_interrupts, pac, peripherals, usb};
10use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; 10use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
11use embassy_usb::driver::EndpointError; 11use embassy_usb::driver::EndpointError;
@@ -108,9 +108,7 @@ impl From<EndpointError> for Disconnected {
108 } 108 }
109} 109}
110 110
111async fn echo<'d, T: Instance + 'd, P: VbusDetect + 'd>( 111async fn echo<'d, V: VbusDetect + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, V>>) -> Result<(), Disconnected> {
112 class: &mut CdcAcmClass<'d, Driver<'d, T, P>>,
113) -> Result<(), Disconnected> {
114 let mut buf = [0; 64]; 112 let mut buf = [0; 64];
115 loop { 113 loop {
116 let n = class.read_packet(&mut buf).await?; 114 let n = class.read_packet(&mut buf).await?;
diff --git a/examples/nrf52840/src/bin/wifi_esp_hosted.rs b/examples/nrf52840/src/bin/wifi_esp_hosted.rs
index 2dd9abfaa..1bc35746a 100644
--- a/examples/nrf52840/src/bin/wifi_esp_hosted.rs
+++ b/examples/nrf52840/src/bin/wifi_esp_hosted.rs
@@ -27,7 +27,7 @@ bind_interrupts!(struct Irqs {
27async fn wifi_task( 27async fn wifi_task(
28 runner: hosted::Runner< 28 runner: hosted::Runner<
29 'static, 29 'static,
30 ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static>, Delay>, 30 ExclusiveDevice<Spim<'static>, Output<'static>, Delay>,
31 Input<'static>, 31 Input<'static>,
32 Output<'static>, 32 Output<'static>,
33 >, 33 >,
diff --git a/examples/nrf5340/Cargo.toml b/examples/nrf5340/Cargo.toml
index 425015667..256fee08d 100644
--- a/examples/nrf5340/Cargo.toml
+++ b/examples/nrf5340/Cargo.toml
@@ -10,7 +10,7 @@ embassy-futures = { version = "0.1.2", path = "../../embassy-futures" }
10embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] } 11embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
12embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 12embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
13embassy-nrf = { version = "0.7.0", path = "../../embassy-nrf", features = ["defmt", "nrf5340-app-s", "time-driver-rtc1", "gpiote", "unstable-pac"] } 13embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["defmt", "nrf5340-app-s", "time-driver-rtc1", "gpiote", "unstable-pac"] }
14embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] } 14embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] }
15embassy-usb = { version = "0.5.1", path = "../../embassy-usb", features = ["defmt"] } 15embassy-usb = { version = "0.5.1", path = "../../embassy-usb", features = ["defmt"] }
16embedded-io-async = { version = "0.6.1" } 16embedded-io-async = { version = "0.6.1" }
diff --git a/examples/nrf54l15/Cargo.toml b/examples/nrf54l15/Cargo.toml
index 7f67b41f6..9c24cdab4 100644
--- a/examples/nrf54l15/Cargo.toml
+++ b/examples/nrf54l15/Cargo.toml
@@ -8,7 +8,7 @@ publish = false
8[dependencies] 8[dependencies]
9embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } 9embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
10embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 10embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
11embassy-nrf = { version = "0.7.0", path = "../../embassy-nrf", features = ["defmt", "nrf54l15-app-s", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } 11embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["defmt", "nrf54l15-app-s", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
12 12
13defmt = "1.0.1" 13defmt = "1.0.1"
14defmt-rtt = "1.0.0" 14defmt-rtt = "1.0.0"
diff --git a/examples/nrf9151/ns/Cargo.toml b/examples/nrf9151/ns/Cargo.toml
index 8e420477f..89a6c7c94 100644
--- a/examples/nrf9151/ns/Cargo.toml
+++ b/examples/nrf9151/ns/Cargo.toml
@@ -8,7 +8,7 @@ publish = false
8[dependencies] 8[dependencies]
9embassy-executor = { version = "0.9.0", path = "../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } 9embassy-executor = { version = "0.9.0", path = "../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
10embassy-time = { version = "0.5.0", path = "../../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 10embassy-time = { version = "0.5.0", path = "../../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
11embassy-nrf = { version = "0.7.0", path = "../../../embassy-nrf", features = ["defmt", "nrf9120-ns", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } 11embassy-nrf = { version = "0.8.0", path = "../../../embassy-nrf", features = ["defmt", "nrf9120-ns", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
12 12
13defmt = "1.0.1" 13defmt = "1.0.1"
14defmt-rtt = "1.0.0" 14defmt-rtt = "1.0.0"
diff --git a/examples/nrf9151/s/Cargo.toml b/examples/nrf9151/s/Cargo.toml
index e4ca85553..870311c5d 100644
--- a/examples/nrf9151/s/Cargo.toml
+++ b/examples/nrf9151/s/Cargo.toml
@@ -8,7 +8,7 @@ publish = false
8[dependencies] 8[dependencies]
9embassy-executor = { version = "0.9.0", path = "../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } 9embassy-executor = { version = "0.9.0", path = "../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
10embassy-time = { version = "0.5.0", path = "../../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 10embassy-time = { version = "0.5.0", path = "../../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
11embassy-nrf = { version = "0.7.0", path = "../../../embassy-nrf", features = ["defmt", "nrf9120-s", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } 11embassy-nrf = { version = "0.8.0", path = "../../../embassy-nrf", features = ["defmt", "nrf9120-s", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
12 12
13defmt = "1.0.1" 13defmt = "1.0.1"
14defmt-rtt = "1.0.0" 14defmt-rtt = "1.0.0"
diff --git a/examples/nrf9160/Cargo.toml b/examples/nrf9160/Cargo.toml
index d7b63a7ac..274e26dd6 100644
--- a/examples/nrf9160/Cargo.toml
+++ b/examples/nrf9160/Cargo.toml
@@ -8,7 +8,7 @@ publish = false
8[dependencies] 8[dependencies]
9embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } 9embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
10embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 10embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
11embassy-nrf = { version = "0.7.0", path = "../../embassy-nrf", features = ["defmt", "nrf9160-s", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } 11embassy-nrf = { version = "0.8.0", path = "../../embassy-nrf", features = ["defmt", "nrf9160-s", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
12embassy-net-nrf91 = { version = "0.1.0", path = "../../embassy-net-nrf91", features = ["defmt"] } 12embassy-net-nrf91 = { version = "0.1.0", path = "../../embassy-net-nrf91", features = ["defmt"] }
13embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "proto-ipv4", "medium-ip"] } 13embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "proto-ipv4", "medium-ip"] }
14 14
diff --git a/examples/nrf9160/src/bin/modem_tcp_client.rs b/examples/nrf9160/src/bin/modem_tcp_client.rs
index 7d4815699..460a4cfae 100644
--- a/examples/nrf9160/src/bin/modem_tcp_client.rs
+++ b/examples/nrf9160/src/bin/modem_tcp_client.rs
@@ -32,7 +32,7 @@ bind_interrupts!(struct Irqs {
32}); 32});
33 33
34#[embassy_executor::task] 34#[embassy_executor::task]
35async fn trace_task(mut uart: BufferedUarteTx<'static, peripherals::SERIAL0>, reader: TraceReader<'static>) -> ! { 35async fn trace_task(mut uart: BufferedUarteTx<'static>, reader: TraceReader<'static>) -> ! {
36 let mut rx = [0u8; 1024]; 36 let mut rx = [0u8; 1024];
37 loop { 37 loop {
38 let n = reader.read(&mut rx[..]).await; 38 let n = reader.read(&mut rx[..]).await;
diff --git a/examples/rp235x/src/bin/multicore_stack_overflow.rs b/examples/rp235x/src/bin/multicore_stack_overflow.rs
new file mode 100644
index 000000000..dba44aa23
--- /dev/null
+++ b/examples/rp235x/src/bin/multicore_stack_overflow.rs
@@ -0,0 +1,72 @@
1//! This example tests stack overflow handling on core1 of the RP235x chip.
2
3#![no_std]
4#![no_main]
5
6use defmt::*;
7use embassy_executor::Executor;
8use embassy_rp::gpio::{Level, Output};
9use embassy_rp::multicore::{spawn_core1, Stack};
10use embassy_time::Timer;
11use static_cell::StaticCell;
12use {defmt_rtt as _, panic_probe as _};
13
14const CORE1_STACK_LENGTH: usize = 4096;
15
16static mut CORE1_STACK: Stack<CORE1_STACK_LENGTH> = Stack::new();
17static EXECUTOR0: StaticCell<Executor> = StaticCell::new();
18static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
19
20#[cortex_m_rt::entry]
21fn main() -> ! {
22 let p = embassy_rp::init(Default::default());
23 let led = Output::new(p.PIN_25, Level::Low);
24
25 spawn_core1(
26 p.CORE1,
27 unsafe { &mut *core::ptr::addr_of_mut!(CORE1_STACK) },
28 move || {
29 let executor1 = EXECUTOR1.init(Executor::new());
30 executor1.run(|spawner| spawner.spawn(unwrap!(core1_task())));
31 },
32 );
33
34 let executor0 = EXECUTOR0.init(Executor::new());
35 executor0.run(|spawner| spawner.spawn(unwrap!(core0_task(led))));
36}
37
38#[embassy_executor::task]
39async fn core0_task(mut led: Output<'static>) {
40 info!("Hello from core 0");
41 loop {
42 info!("core 0 still alive");
43 led.set_high();
44 Timer::after_millis(500).await;
45 led.set_low();
46 Timer::after_millis(500).await;
47 }
48}
49
50fn blow_my_stack() {
51 // Allocating an array a little larger than our stack should ensure a stack overflow when it is used.
52 let t = [0u8; CORE1_STACK_LENGTH + 64];
53
54 info!("Array initialised without error");
55 // We need to use black_box to otherwise the compiler is too smart and will optimise all of this away.
56 // We shouldn't get to this code - the initialisation above will touch the stack guard.
57 for ref i in t {
58 let _data = core::hint::black_box(*i) + 1;
59 }
60}
61
62#[embassy_executor::task]
63async fn core1_task() {
64 info!("Hello from core 1");
65
66 blow_my_stack();
67
68 loop {
69 info!("core 1 still alive");
70 Timer::after_millis(1000).await;
71 }
72}
diff --git a/examples/stm32f4/src/bin/mco.rs b/examples/stm32f4/src/bin/mco.rs
index eb7bb6261..a2e229770 100644
--- a/examples/stm32f4/src/bin/mco.rs
+++ b/examples/stm32f4/src/bin/mco.rs
@@ -4,7 +4,7 @@
4use defmt::*; 4use defmt::*;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_stm32::gpio::{Level, Output, Speed}; 6use embassy_stm32::gpio::{Level, Output, Speed};
7use embassy_stm32::rcc::{Mco, Mco1Source, Mco2Source, McoPrescaler}; 7use embassy_stm32::rcc::{Mco, Mco1Source, Mco2Source, McoConfig, McoPrescaler};
8use embassy_time::Timer; 8use embassy_time::Timer;
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
@@ -13,8 +13,20 @@ async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default()); 13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let _mco1 = Mco::new(p.MCO1, p.PA8, Mco1Source::HSI, McoPrescaler::DIV1); 16 let config_mco1 = {
17 let _mco2 = Mco::new(p.MCO2, p.PC9, Mco2Source::PLL, McoPrescaler::DIV4); 17 let mut config = McoConfig::default();
18 config.prescaler = McoPrescaler::DIV1;
19 config
20 };
21
22 let config_mco2 = {
23 let mut config = McoConfig::default();
24 config.prescaler = McoPrescaler::DIV4;
25 config
26 };
27
28 let _mco1 = Mco::new(p.MCO1, p.PA8, Mco1Source::HSI, config_mco1);
29 let _mco2 = Mco::new(p.MCO2, p.PC9, Mco2Source::PLL, config_mco2);
18 let mut led = Output::new(p.PB7, Level::High, Speed::Low); 30 let mut led = Output::new(p.PB7, Level::High, Speed::Low);
19 31
20 loop { 32 loop {
diff --git a/examples/stm32h5/src/bin/mco.rs b/examples/stm32h5/src/bin/mco.rs
new file mode 100644
index 000000000..1137ba25c
--- /dev/null
+++ b/examples/stm32h5/src/bin/mco.rs
@@ -0,0 +1,29 @@
1#![no_std]
2#![no_main]
3
4use defmt::*;
5use embassy_executor::Spawner;
6use embassy_stm32::gpio::Speed;
7use embassy_stm32::rcc::{Mco, Mco2Source, McoConfig};
8use {defmt_rtt as _, panic_probe as _};
9
10#[embassy_executor::main]
11async fn main(_spawner: Spawner) {
12 let p = embassy_stm32::init(Default::default());
13
14 /* Default "VeryHigh" drive strength and prescaler DIV1 */
15 // let _mco = Mco::new(p.MCO2, p.PC9, Mco2Source::SYS, McoConfig::default());
16
17 /* Choose Speed::Low drive strength */
18 let config = {
19 let mut config = McoConfig::default();
20 config.speed = Speed::Low;
21 config
22 };
23
24 let _mco = Mco::new(p.MCO2, p.PC9, Mco2Source::SYS, config);
25
26 info!("Clock out with low drive strength set on Master Clock Out 2 pin as AF on PC9");
27
28 loop {}
29}
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs
index 8f2e265d6..039008d17 100644
--- a/examples/stm32h7/src/bin/camera.rs
+++ b/examples/stm32h7/src/bin/camera.rs
@@ -5,7 +5,7 @@ use embassy_executor::Spawner;
5use embassy_stm32::dcmi::{self, *}; 5use embassy_stm32::dcmi::{self, *};
6use embassy_stm32::gpio::{Level, Output, Speed}; 6use embassy_stm32::gpio::{Level, Output, Speed};
7use embassy_stm32::i2c::I2c; 7use embassy_stm32::i2c::I2c;
8use embassy_stm32::rcc::{Mco, Mco1Source, McoPrescaler}; 8use embassy_stm32::rcc::{Mco, Mco1Source, McoConfig, McoPrescaler};
9use embassy_stm32::{bind_interrupts, i2c, peripherals, Config}; 9use embassy_stm32::{bind_interrupts, i2c, peripherals, Config};
10use embassy_time::Timer; 10use embassy_time::Timer;
11use ov7725::*; 11use ov7725::*;
@@ -48,7 +48,14 @@ async fn main(_spawner: Spawner) {
48 let p = embassy_stm32::init(config); 48 let p = embassy_stm32::init(config);
49 49
50 defmt::info!("Hello World!"); 50 defmt::info!("Hello World!");
51 let mco = Mco::new(p.MCO1, p.PA8, Mco1Source::HSI, McoPrescaler::DIV3); 51
52 let mco_config = {
53 let mut config = McoConfig::default();
54 config.prescaler = McoPrescaler::DIV3;
55 config
56 };
57
58 let mco = Mco::new(p.MCO1, p.PA8, Mco1Source::HSI, mco_config);
52 59
53 let mut led = Output::new(p.PE3, Level::High, Speed::Low); 60 let mut led = Output::new(p.PE3, Level::High, Speed::Low);
54 let cam_i2c = I2c::new(p.I2C1, p.PB8, p.PB9, Irqs, p.DMA1_CH1, p.DMA1_CH2, Default::default()); 61 let cam_i2c = I2c::new(p.I2C1, p.PB8, p.PB9, Irqs, p.DMA1_CH1, p.DMA1_CH2, Default::default());
diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs
index a6ee27625..cafcb90f6 100644
--- a/examples/stm32h7/src/bin/mco.rs
+++ b/examples/stm32h7/src/bin/mco.rs
@@ -4,7 +4,7 @@
4use defmt::*; 4use defmt::*;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_stm32::gpio::{Level, Output, Speed}; 6use embassy_stm32::gpio::{Level, Output, Speed};
7use embassy_stm32::rcc::{Mco, Mco1Source, McoPrescaler}; 7use embassy_stm32::rcc::{Mco, Mco1Source, McoConfig, McoPrescaler};
8use embassy_time::Timer; 8use embassy_time::Timer;
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
@@ -15,7 +15,13 @@ async fn main(_spawner: Spawner) {
15 15
16 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
17 17
18 let _mco = Mco::new(p.MCO1, p.PA8, Mco1Source::HSI, McoPrescaler::DIV8); 18 let config = {
19 let mut config = McoConfig::default();
20 config.prescaler = McoPrescaler::DIV8;
21 config
22 };
23
24 let _mco = Mco::new(p.MCO1, p.PA8, Mco1Source::HSI, config);
19 25
20 loop { 26 loop {
21 info!("high"); 27 info!("high");
diff --git a/examples/stm32h7rs/src/bin/mco.rs b/examples/stm32h7rs/src/bin/mco.rs
index a6ee27625..cafcb90f6 100644
--- a/examples/stm32h7rs/src/bin/mco.rs
+++ b/examples/stm32h7rs/src/bin/mco.rs
@@ -4,7 +4,7 @@
4use defmt::*; 4use defmt::*;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_stm32::gpio::{Level, Output, Speed}; 6use embassy_stm32::gpio::{Level, Output, Speed};
7use embassy_stm32::rcc::{Mco, Mco1Source, McoPrescaler}; 7use embassy_stm32::rcc::{Mco, Mco1Source, McoConfig, McoPrescaler};
8use embassy_time::Timer; 8use embassy_time::Timer;
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
@@ -15,7 +15,13 @@ async fn main(_spawner: Spawner) {
15 15
16 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
17 17
18 let _mco = Mco::new(p.MCO1, p.PA8, Mco1Source::HSI, McoPrescaler::DIV8); 18 let config = {
19 let mut config = McoConfig::default();
20 config.prescaler = McoPrescaler::DIV8;
21 config
22 };
23
24 let _mco = Mco::new(p.MCO1, p.PA8, Mco1Source::HSI, config);
19 25
20 loop { 26 loop {
21 info!("high"); 27 info!("high");
diff --git a/examples/stm32l4/src/bin/mco.rs b/examples/stm32l4/src/bin/mco.rs
index 36c002952..4cdeaa440 100644
--- a/examples/stm32l4/src/bin/mco.rs
+++ b/examples/stm32l4/src/bin/mco.rs
@@ -4,7 +4,7 @@
4use defmt::*; 4use defmt::*;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_stm32::gpio::{Level, Output, Speed}; 6use embassy_stm32::gpio::{Level, Output, Speed};
7use embassy_stm32::rcc::{Mco, McoPrescaler, McoSource}; 7use embassy_stm32::rcc::{Mco, McoConfig, McoPrescaler, McoSource};
8use embassy_time::Timer; 8use embassy_time::Timer;
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
@@ -13,7 +13,13 @@ async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default()); 13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let _mco = Mco::new(p.MCO, p.PA8, McoSource::HSI, McoPrescaler::DIV1); 16 let config = {
17 let mut config = McoConfig::default();
18 config.prescaler = McoPrescaler::DIV1;
19 config
20 };
21
22 let _mco = Mco::new(p.MCO, p.PA8, McoSource::HSI, config);
17 23
18 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 24 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
19 25