diff options
| author | jrmoulton <[email protected]> | 2025-06-10 15:47:54 -0600 |
|---|---|---|
| committer | jrmoulton <[email protected]> | 2025-06-10 15:48:36 -0600 |
| commit | cfad9798ff99d4de0571a512d156b5fe1ef1d427 (patch) | |
| tree | fc3bf670f82d139de19466cddad1e909db7f3d2e /examples/stm32h7/src/bin | |
| parent | fc342915e6155dec7bafa3e135da7f37a9a07f5c (diff) | |
| parent | 6186d111a5c150946ee5b7e9e68d987a38c1a463 (diff) | |
merge new embassy changes
Diffstat (limited to 'examples/stm32h7/src/bin')
| -rw-r--r-- | examples/stm32h7/src/bin/adc_dma.rs | 4 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/dac.rs | 3 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/dac_dma.rs | 8 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/eth.rs | 21 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/eth_client.rs | 25 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/eth_client_mii.rs | 25 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/i2c_shared.rs | 6 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/low_level_timer_api.rs | 14 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/pwm.rs | 19 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/sai.rs | 21 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/sdmmc.rs | 2 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/spi_bdma.rs | 9 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/usb_serial.rs | 7 |
13 files changed, 78 insertions, 86 deletions
diff --git a/examples/stm32h7/src/bin/adc_dma.rs b/examples/stm32h7/src/bin/adc_dma.rs index 0b905d227..f06b5d06e 100644 --- a/examples/stm32h7/src/bin/adc_dma.rs +++ b/examples/stm32h7/src/bin/adc_dma.rs | |||
| @@ -8,7 +8,7 @@ use embassy_stm32::Config; | |||
| 8 | use embassy_time::Timer; | 8 | use embassy_time::Timer; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 10 | ||
| 11 | #[link_section = ".ram_d3"] | 11 | #[unsafe(link_section = ".ram_d3")] |
| 12 | static mut DMA_BUF: [u16; 2] = [0; 2]; | 12 | static mut DMA_BUF: [u16; 2] = [0; 2]; |
| 13 | 13 | ||
| 14 | #[embassy_executor::main] | 14 | #[embassy_executor::main] |
| @@ -57,7 +57,7 @@ async fn main(_spawner: Spawner) { | |||
| 57 | 57 | ||
| 58 | loop { | 58 | loop { |
| 59 | adc.read( | 59 | adc.read( |
| 60 | &mut dma, | 60 | dma.reborrow(), |
| 61 | [ | 61 | [ |
| 62 | (&mut vrefint_channel, SampleTime::CYCLES387_5), | 62 | (&mut vrefint_channel, SampleTime::CYCLES387_5), |
| 63 | (&mut pc0, SampleTime::CYCLES810_5), | 63 | (&mut pc0, SampleTime::CYCLES810_5), |
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index a6f969aba..27df80336 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use cortex_m_rt::entry; | 4 | use cortex_m_rt::entry; |
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_stm32::dac::{DacCh1, Value}; | 6 | use embassy_stm32::dac::{DacCh1, Value}; |
| 7 | use embassy_stm32::dma::NoDma; | ||
| 8 | use embassy_stm32::Config; | 7 | use embassy_stm32::Config; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| @@ -44,7 +43,7 @@ fn main() -> ! { | |||
| 44 | } | 43 | } |
| 45 | let p = embassy_stm32::init(config); | 44 | let p = embassy_stm32::init(config); |
| 46 | 45 | ||
| 47 | let mut dac = DacCh1::new(p.DAC1, NoDma, p.PA4); | 46 | let mut dac = DacCh1::new_blocking(p.DAC1, p.PA4); |
| 48 | 47 | ||
| 49 | loop { | 48 | loop { |
| 50 | for v in 0..=255 { | 49 | for v in 0..=255 { |
diff --git a/examples/stm32h7/src/bin/dac_dma.rs b/examples/stm32h7/src/bin/dac_dma.rs index 3a9887e3c..8314754bc 100644 --- a/examples/stm32h7/src/bin/dac_dma.rs +++ b/examples/stm32h7/src/bin/dac_dma.rs | |||
| @@ -4,11 +4,13 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::dac::{DacCh1, DacCh2, ValueArray}; | 6 | use embassy_stm32::dac::{DacCh1, DacCh2, ValueArray}; |
| 7 | use embassy_stm32::mode::Async; | ||
| 7 | use embassy_stm32::pac::timer::vals::Mms; | 8 | use embassy_stm32::pac::timer::vals::Mms; |
| 8 | use embassy_stm32::peripherals::{DAC1, DMA1_CH3, DMA1_CH4, TIM6, TIM7}; | 9 | use embassy_stm32::peripherals::{DAC1, TIM6, TIM7}; |
| 9 | use embassy_stm32::rcc::frequency; | 10 | use embassy_stm32::rcc::frequency; |
| 10 | use embassy_stm32::time::Hertz; | 11 | use embassy_stm32::time::Hertz; |
| 11 | use embassy_stm32::timer::low_level::Timer; | 12 | use embassy_stm32::timer::low_level::Timer; |
| 13 | use embassy_stm32::Peri; | ||
| 12 | use micromath::F32Ext; | 14 | use micromath::F32Ext; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 16 | ||
| @@ -56,7 +58,7 @@ async fn main(spawner: Spawner) { | |||
| 56 | } | 58 | } |
| 57 | 59 | ||
| 58 | #[embassy_executor::task] | 60 | #[embassy_executor::task] |
| 59 | async fn dac_task1(tim: TIM6, mut dac: DacCh1<'static, DAC1, DMA1_CH3>) { | 61 | async fn dac_task1(tim: Peri<'static, TIM6>, mut dac: DacCh1<'static, DAC1, Async>) { |
| 60 | let data: &[u8; 256] = &calculate_array::<256>(); | 62 | let data: &[u8; 256] = &calculate_array::<256>(); |
| 61 | 63 | ||
| 62 | info!("TIM6 frequency is {}", frequency::<TIM6>()); | 64 | info!("TIM6 frequency is {}", frequency::<TIM6>()); |
| @@ -99,7 +101,7 @@ async fn dac_task1(tim: TIM6, mut dac: DacCh1<'static, DAC1, DMA1_CH3>) { | |||
| 99 | } | 101 | } |
| 100 | 102 | ||
| 101 | #[embassy_executor::task] | 103 | #[embassy_executor::task] |
| 102 | async fn dac_task2(tim: TIM7, mut dac: DacCh2<'static, DAC1, DMA1_CH4>) { | 104 | async fn dac_task2(tim: Peri<'static, TIM7>, mut dac: DacCh2<'static, DAC1, Async>) { |
| 103 | let data: &[u8; 256] = &calculate_array::<256>(); | 105 | let data: &[u8; 256] = &calculate_array::<256>(); |
| 104 | 106 | ||
| 105 | info!("TIM7 frequency is {}", frequency::<TIM6>()); | 107 | info!("TIM7 frequency is {}", frequency::<TIM6>()); |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index b2f8ed91e..fc14c1a70 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -4,15 +4,13 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_net::tcp::TcpSocket; | 6 | use embassy_net::tcp::TcpSocket; |
| 7 | use embassy_net::{Ipv4Address, Stack, StackResources}; | 7 | use embassy_net::{Ipv4Address, StackResources}; |
| 8 | use embassy_stm32::eth::generic_smi::GenericSMI; | 8 | use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; |
| 9 | use embassy_stm32::eth::{Ethernet, PacketQueue}; | ||
| 10 | use embassy_stm32::peripherals::ETH; | 9 | use embassy_stm32::peripherals::ETH; |
| 11 | use embassy_stm32::rng::Rng; | 10 | use embassy_stm32::rng::Rng; |
| 12 | use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; | 11 | use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; |
| 13 | use embassy_time::Timer; | 12 | use embassy_time::Timer; |
| 14 | use embedded_io_async::Write; | 13 | use embedded_io_async::Write; |
| 15 | use rand_core::RngCore; | ||
| 16 | use static_cell::StaticCell; | 14 | use static_cell::StaticCell; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 16 | ||
| @@ -21,11 +19,11 @@ bind_interrupts!(struct Irqs { | |||
| 21 | RNG => rng::InterruptHandler<peripherals::RNG>; | 19 | RNG => rng::InterruptHandler<peripherals::RNG>; |
| 22 | }); | 20 | }); |
| 23 | 21 | ||
| 24 | type Device = Ethernet<'static, ETH, GenericSMI>; | 22 | type Device = Ethernet<'static, ETH, GenericPhy>; |
| 25 | 23 | ||
| 26 | #[embassy_executor::task] | 24 | #[embassy_executor::task] |
| 27 | async fn net_task(stack: &'static Stack<Device>) -> ! { | 25 | async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { |
| 28 | stack.run().await | 26 | runner.run().await |
| 29 | } | 27 | } |
| 30 | 28 | ||
| 31 | #[embassy_executor::main] | 29 | #[embassy_executor::main] |
| @@ -79,7 +77,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 79 | p.PG13, // TX_D0: Transmit Bit 0 | 77 | p.PG13, // TX_D0: Transmit Bit 0 |
| 80 | p.PB13, // TX_D1: Transmit Bit 1 | 78 | p.PB13, // TX_D1: Transmit Bit 1 |
| 81 | p.PG11, // TX_EN: Transmit Enable | 79 | p.PG11, // TX_EN: Transmit Enable |
| 82 | GenericSMI::new(0), | 80 | GenericPhy::new_auto(), |
| 83 | mac_addr, | 81 | mac_addr, |
| 84 | ); | 82 | ); |
| 85 | 83 | ||
| @@ -91,12 +89,11 @@ async fn main(spawner: Spawner) -> ! { | |||
| 91 | //}); | 89 | //}); |
| 92 | 90 | ||
| 93 | // Init network stack | 91 | // Init network stack |
| 94 | static STACK: StaticCell<Stack<Device>> = StaticCell::new(); | ||
| 95 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | 92 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); |
| 96 | let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); | 93 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 97 | 94 | ||
| 98 | // Launch network task | 95 | // Launch network task |
| 99 | unwrap!(spawner.spawn(net_task(&stack))); | 96 | unwrap!(spawner.spawn(net_task(runner))); |
| 100 | 97 | ||
| 101 | // Ensure DHCP configuration is up before trying connect | 98 | // Ensure DHCP configuration is up before trying connect |
| 102 | stack.wait_config_up().await; | 99 | stack.wait_config_up().await; |
| @@ -108,7 +105,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 108 | let mut tx_buffer = [0; 1024]; | 105 | let mut tx_buffer = [0; 1024]; |
| 109 | 106 | ||
| 110 | loop { | 107 | loop { |
| 111 | let mut socket = TcpSocket::new(&stack, &mut rx_buffer, &mut tx_buffer); | 108 | let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer); |
| 112 | 109 | ||
| 113 | socket.set_timeout(Some(embassy_time::Duration::from_secs(10))); | 110 | socket.set_timeout(Some(embassy_time::Duration::from_secs(10))); |
| 114 | 111 | ||
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 274c24ab1..46301a478 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs | |||
| @@ -1,19 +1,19 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; | ||
| 5 | |||
| 4 | use defmt::*; | 6 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 6 | use embassy_net::tcp::client::{TcpClient, TcpClientState}; | 8 | use embassy_net::tcp::client::{TcpClient, TcpClientState}; |
| 7 | use embassy_net::{Stack, StackResources}; | 9 | use embassy_net::StackResources; |
| 8 | use embassy_stm32::eth::generic_smi::GenericSMI; | 10 | use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; |
| 9 | use embassy_stm32::eth::{Ethernet, PacketQueue}; | ||
| 10 | use embassy_stm32::peripherals::ETH; | 11 | use embassy_stm32::peripherals::ETH; |
| 11 | use embassy_stm32::rng::Rng; | 12 | use embassy_stm32::rng::Rng; |
| 12 | use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; | 13 | use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; |
| 13 | use embassy_time::Timer; | 14 | use embassy_time::Timer; |
| 14 | use embedded_io_async::Write; | 15 | use embedded_io_async::Write; |
| 15 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; | 16 | use embedded_nal_async::TcpConnect; |
| 16 | use rand_core::RngCore; | ||
| 17 | use static_cell::StaticCell; | 17 | use static_cell::StaticCell; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| 19 | 19 | ||
| @@ -22,11 +22,11 @@ bind_interrupts!(struct Irqs { | |||
| 22 | RNG => rng::InterruptHandler<peripherals::RNG>; | 22 | RNG => rng::InterruptHandler<peripherals::RNG>; |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | type Device = Ethernet<'static, ETH, GenericSMI>; | 25 | type Device = Ethernet<'static, ETH, GenericPhy>; |
| 26 | 26 | ||
| 27 | #[embassy_executor::task] | 27 | #[embassy_executor::task] |
| 28 | async fn net_task(stack: &'static Stack<Device>) -> ! { | 28 | async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { |
| 29 | stack.run().await | 29 | runner.run().await |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | #[embassy_executor::main] | 32 | #[embassy_executor::main] |
| @@ -79,7 +79,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 79 | p.PG13, | 79 | p.PG13, |
| 80 | p.PB13, | 80 | p.PB13, |
| 81 | p.PG11, | 81 | p.PG11, |
| 82 | GenericSMI::new(0), | 82 | GenericPhy::new_auto(), |
| 83 | mac_addr, | 83 | mac_addr, |
| 84 | ); | 84 | ); |
| 85 | 85 | ||
| @@ -91,12 +91,11 @@ async fn main(spawner: Spawner) -> ! { | |||
| 91 | //}); | 91 | //}); |
| 92 | 92 | ||
| 93 | // Init network stack | 93 | // Init network stack |
| 94 | static STACK: StaticCell<Stack<Device>> = StaticCell::new(); | ||
| 95 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | 94 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); |
| 96 | let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); | 95 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 97 | 96 | ||
| 98 | // Launch network task | 97 | // Launch network task |
| 99 | unwrap!(spawner.spawn(net_task(stack))); | 98 | unwrap!(spawner.spawn(net_task(runner))); |
| 100 | 99 | ||
| 101 | // Ensure DHCP configuration is up before trying connect | 100 | // Ensure DHCP configuration is up before trying connect |
| 102 | stack.wait_config_up().await; | 101 | stack.wait_config_up().await; |
| @@ -104,7 +103,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 104 | info!("Network task initialized"); | 103 | info!("Network task initialized"); |
| 105 | 104 | ||
| 106 | let state: TcpClientState<1, 1024, 1024> = TcpClientState::new(); | 105 | let state: TcpClientState<1, 1024, 1024> = TcpClientState::new(); |
| 107 | let client = TcpClient::new(&stack, &state); | 106 | let client = TcpClient::new(stack, &state); |
| 108 | 107 | ||
| 109 | loop { | 108 | loop { |
| 110 | // You need to start a server on the host machine, for example: `nc -l 8000` | 109 | // You need to start a server on the host machine, for example: `nc -l 8000` |
diff --git a/examples/stm32h7/src/bin/eth_client_mii.rs b/examples/stm32h7/src/bin/eth_client_mii.rs index aa6544f41..99cd1a158 100644 --- a/examples/stm32h7/src/bin/eth_client_mii.rs +++ b/examples/stm32h7/src/bin/eth_client_mii.rs | |||
| @@ -1,19 +1,19 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; | ||
| 5 | |||
| 4 | use defmt::*; | 6 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 6 | use embassy_net::tcp::client::{TcpClient, TcpClientState}; | 8 | use embassy_net::tcp::client::{TcpClient, TcpClientState}; |
| 7 | use embassy_net::{Stack, StackResources}; | 9 | use embassy_net::StackResources; |
| 8 | use embassy_stm32::eth::generic_smi::GenericSMI; | 10 | use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; |
| 9 | use embassy_stm32::eth::{Ethernet, PacketQueue}; | ||
| 10 | use embassy_stm32::peripherals::ETH; | 11 | use embassy_stm32::peripherals::ETH; |
| 11 | use embassy_stm32::rng::Rng; | 12 | use embassy_stm32::rng::Rng; |
| 12 | use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; | 13 | use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; |
| 13 | use embassy_time::Timer; | 14 | use embassy_time::Timer; |
| 14 | use embedded_io_async::Write; | 15 | use embedded_io_async::Write; |
| 15 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; | 16 | use embedded_nal_async::TcpConnect; |
| 16 | use rand_core::RngCore; | ||
| 17 | use static_cell::StaticCell; | 17 | use static_cell::StaticCell; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| 19 | 19 | ||
| @@ -22,11 +22,11 @@ bind_interrupts!(struct Irqs { | |||
| 22 | RNG => rng::InterruptHandler<peripherals::RNG>; | 22 | RNG => rng::InterruptHandler<peripherals::RNG>; |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | type Device = Ethernet<'static, ETH, GenericSMI>; | 25 | type Device = Ethernet<'static, ETH, GenericPhy>; |
| 26 | 26 | ||
| 27 | #[embassy_executor::task] | 27 | #[embassy_executor::task] |
| 28 | async fn net_task(stack: &'static Stack<Device>) -> ! { | 28 | async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { |
| 29 | stack.run().await | 29 | runner.run().await |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | #[embassy_executor::main] | 32 | #[embassy_executor::main] |
| @@ -84,7 +84,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 84 | p.PC2, | 84 | p.PC2, |
| 85 | p.PE2, | 85 | p.PE2, |
| 86 | p.PG11, | 86 | p.PG11, |
| 87 | GenericSMI::new(1), | 87 | GenericPhy::new_auto(), |
| 88 | mac_addr, | 88 | mac_addr, |
| 89 | ); | 89 | ); |
| 90 | info!("Device created"); | 90 | info!("Device created"); |
| @@ -97,12 +97,11 @@ async fn main(spawner: Spawner) -> ! { | |||
| 97 | //}); | 97 | //}); |
| 98 | 98 | ||
| 99 | // Init network stack | 99 | // Init network stack |
| 100 | static STACK: StaticCell<Stack<Device>> = StaticCell::new(); | ||
| 101 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | 100 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); |
| 102 | let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); | 101 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 103 | 102 | ||
| 104 | // Launch network task | 103 | // Launch network task |
| 105 | unwrap!(spawner.spawn(net_task(stack))); | 104 | unwrap!(spawner.spawn(net_task(runner))); |
| 106 | 105 | ||
| 107 | // Ensure DHCP configuration is up before trying connect | 106 | // Ensure DHCP configuration is up before trying connect |
| 108 | stack.wait_config_up().await; | 107 | stack.wait_config_up().await; |
| @@ -110,7 +109,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 110 | info!("Network task initialized"); | 109 | info!("Network task initialized"); |
| 111 | 110 | ||
| 112 | let state: TcpClientState<1, 1024, 1024> = TcpClientState::new(); | 111 | let state: TcpClientState<1, 1024, 1024> = TcpClientState::new(); |
| 113 | let client = TcpClient::new(&stack, &state); | 112 | let client = TcpClient::new(stack, &state); |
| 114 | 113 | ||
| 115 | loop { | 114 | loop { |
| 116 | // You need to start a server on the host machine, for example: `nc -l 8000` | 115 | // You need to start a server on the host machine, for example: `nc -l 8000` |
diff --git a/examples/stm32h7/src/bin/i2c_shared.rs b/examples/stm32h7/src/bin/i2c_shared.rs index 321b35a3e..ec5757284 100644 --- a/examples/stm32h7/src/bin/i2c_shared.rs +++ b/examples/stm32h7/src/bin/i2c_shared.rs | |||
| @@ -10,8 +10,10 @@ use embassy_stm32::i2c::{self, I2c}; | |||
| 10 | use embassy_stm32::mode::Async; | 10 | use embassy_stm32::mode::Async; |
| 11 | use embassy_stm32::time::Hertz; | 11 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::{bind_interrupts, peripherals}; | 12 | use embassy_stm32::{bind_interrupts, peripherals}; |
| 13 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 13 | use embassy_sync::blocking_mutex::NoopMutex; | 14 | use embassy_sync::blocking_mutex::NoopMutex; |
| 14 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 16 | use embedded_hal_1::i2c::I2c as _; | ||
| 15 | use static_cell::StaticCell; | 17 | use static_cell::StaticCell; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 19 | ||
| @@ -31,7 +33,7 @@ bind_interrupts!(struct Irqs { | |||
| 31 | }); | 33 | }); |
| 32 | 34 | ||
| 33 | #[embassy_executor::task] | 35 | #[embassy_executor::task] |
| 34 | async fn temperature(mut i2c: impl embedded_hal_1::i2c::I2c + 'static) { | 36 | async fn temperature(mut i2c: I2cDevice<'static, NoopRawMutex, I2c<'static, Async>>) { |
| 35 | let mut data = [0u8; 2]; | 37 | let mut data = [0u8; 2]; |
| 36 | 38 | ||
| 37 | loop { | 39 | loop { |
| @@ -48,7 +50,7 @@ async fn temperature(mut i2c: impl embedded_hal_1::i2c::I2c + 'static) { | |||
| 48 | } | 50 | } |
| 49 | 51 | ||
| 50 | #[embassy_executor::task] | 52 | #[embassy_executor::task] |
| 51 | async fn humidity(mut i2c: impl embedded_hal_1::i2c::I2c + 'static) { | 53 | async fn humidity(mut i2c: I2cDevice<'static, NoopRawMutex, I2c<'static, Async>>) { |
| 52 | let mut data = [0u8; 6]; | 54 | let mut data = [0u8; 6]; |
| 53 | 55 | ||
| 54 | loop { | 56 | loop { |
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index b796996ea..8de31ea5b 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -7,7 +7,7 @@ use embassy_stm32::gpio::{AfType, Flex, OutputType, Speed}; | |||
| 7 | use embassy_stm32::time::{khz, Hertz}; | 7 | use embassy_stm32::time::{khz, Hertz}; |
| 8 | use embassy_stm32::timer::low_level::{OutputCompareMode, Timer as LLTimer}; | 8 | use embassy_stm32::timer::low_level::{OutputCompareMode, Timer as LLTimer}; |
| 9 | use embassy_stm32::timer::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance32bit4Channel}; | 9 | use embassy_stm32::timer::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance32bit4Channel}; |
| 10 | use embassy_stm32::{into_ref, Config, Peripheral}; | 10 | use embassy_stm32::{Config, Peri}; |
| 11 | use embassy_time::Timer; | 11 | use embassy_time::Timer; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| @@ -66,15 +66,13 @@ pub struct SimplePwm32<'d, T: GeneralInstance32bit4Channel> { | |||
| 66 | 66 | ||
| 67 | impl<'d, T: GeneralInstance32bit4Channel> SimplePwm32<'d, T> { | 67 | impl<'d, T: GeneralInstance32bit4Channel> SimplePwm32<'d, T> { |
| 68 | pub fn new( | 68 | pub fn new( |
| 69 | tim: impl Peripheral<P = T> + 'd, | 69 | tim: Peri<'d, T>, |
| 70 | ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd, | 70 | ch1: Peri<'d, impl Channel1Pin<T>>, |
| 71 | ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd, | 71 | ch2: Peri<'d, impl Channel2Pin<T>>, |
| 72 | ch3: impl Peripheral<P = impl Channel3Pin<T>> + 'd, | 72 | ch3: Peri<'d, impl Channel3Pin<T>>, |
| 73 | ch4: impl Peripheral<P = impl Channel4Pin<T>> + 'd, | 73 | ch4: Peri<'d, impl Channel4Pin<T>>, |
| 74 | freq: Hertz, | 74 | freq: Hertz, |
| 75 | ) -> Self { | 75 | ) -> Self { |
| 76 | into_ref!(ch1, ch2, ch3, ch4); | ||
| 77 | |||
| 78 | let af1 = ch1.af_num(); | 76 | let af1 = ch1.af_num(); |
| 79 | let af2 = ch2.af_num(); | 77 | let af2 = ch2.af_num(); |
| 80 | let af3 = ch3.af_num(); | 78 | let af3 = ch3.af_num(); |
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index 1e48ba67b..a1c53fc3f 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs | |||
| @@ -6,7 +6,6 @@ use embassy_executor::Spawner; | |||
| 6 | use embassy_stm32::gpio::OutputType; | 6 | use embassy_stm32::gpio::OutputType; |
| 7 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 8 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | 8 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; |
| 9 | use embassy_stm32::timer::Channel; | ||
| 10 | use embassy_stm32::Config; | 9 | use embassy_stm32::Config; |
| 11 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -37,22 +36,22 @@ async fn main(_spawner: Spawner) { | |||
| 37 | let p = embassy_stm32::init(config); | 36 | let p = embassy_stm32::init(config); |
| 38 | info!("Hello World!"); | 37 | info!("Hello World!"); |
| 39 | 38 | ||
| 40 | let ch1 = PwmPin::new_ch1(p.PA6, OutputType::PushPull); | 39 | let ch1_pin = PwmPin::new_ch1(p.PA6, OutputType::PushPull); |
| 41 | let mut pwm = SimplePwm::new(p.TIM3, Some(ch1), None, None, None, khz(10), Default::default()); | 40 | let mut pwm = SimplePwm::new(p.TIM3, Some(ch1_pin), None, None, None, khz(10), Default::default()); |
| 42 | let max = pwm.get_max_duty(); | 41 | let mut ch1 = pwm.ch1(); |
| 43 | pwm.enable(Channel::Ch1); | 42 | ch1.enable(); |
| 44 | 43 | ||
| 45 | info!("PWM initialized"); | 44 | info!("PWM initialized"); |
| 46 | info!("PWM max duty {}", max); | 45 | info!("PWM max duty {}", ch1.max_duty_cycle()); |
| 47 | 46 | ||
| 48 | loop { | 47 | loop { |
| 49 | pwm.set_duty(Channel::Ch1, 0); | 48 | ch1.set_duty_cycle_fully_off(); |
| 50 | Timer::after_millis(300).await; | 49 | Timer::after_millis(300).await; |
| 51 | pwm.set_duty(Channel::Ch1, max / 4); | 50 | ch1.set_duty_cycle_fraction(1, 4); |
| 52 | Timer::after_millis(300).await; | 51 | Timer::after_millis(300).await; |
| 53 | pwm.set_duty(Channel::Ch1, max / 2); | 52 | ch1.set_duty_cycle_fraction(1, 2); |
| 54 | Timer::after_millis(300).await; | 53 | Timer::after_millis(300).await; |
| 55 | pwm.set_duty(Channel::Ch1, max - 1); | 54 | ch1.set_duty_cycle(ch1.max_duty_cycle() - 1); |
| 56 | Timer::after_millis(300).await; | 55 | Timer::after_millis(300).await; |
| 57 | } | 56 | } |
| 58 | } | 57 | } |
diff --git a/examples/stm32h7/src/bin/sai.rs b/examples/stm32h7/src/bin/sai.rs index f6735e235..01937593a 100644 --- a/examples/stm32h7/src/bin/sai.rs +++ b/examples/stm32h7/src/bin/sai.rs | |||
| @@ -16,9 +16,9 @@ const DMA_BUFFER_LENGTH: usize = HALF_DMA_BUFFER_LENGTH * 2; // 2 half-blocks | |||
| 16 | const SAMPLE_RATE: u32 = 48000; | 16 | const SAMPLE_RATE: u32 = 48000; |
| 17 | 17 | ||
| 18 | //DMA buffer must be in special region. Refer https://embassy.dev/book/#_stm32_bdma_only_working_out_of_some_ram_regions | 18 | //DMA buffer must be in special region. Refer https://embassy.dev/book/#_stm32_bdma_only_working_out_of_some_ram_regions |
| 19 | #[link_section = ".sram1_bss"] | 19 | #[unsafe(link_section = ".sram1_bss")] |
| 20 | static mut TX_BUFFER: GroundedArrayCell<u32, DMA_BUFFER_LENGTH> = GroundedArrayCell::uninit(); | 20 | static mut TX_BUFFER: GroundedArrayCell<u32, DMA_BUFFER_LENGTH> = GroundedArrayCell::uninit(); |
| 21 | #[link_section = ".sram1_bss"] | 21 | #[unsafe(link_section = ".sram1_bss")] |
| 22 | static mut RX_BUFFER: GroundedArrayCell<u32, DMA_BUFFER_LENGTH> = GroundedArrayCell::uninit(); | 22 | static mut RX_BUFFER: GroundedArrayCell<u32, DMA_BUFFER_LENGTH> = GroundedArrayCell::uninit(); |
| 23 | 23 | ||
| 24 | #[embassy_executor::main] | 24 | #[embassy_executor::main] |
| @@ -81,8 +81,9 @@ async fn main(_spawner: Spawner) { | |||
| 81 | rx_config.sync_output = false; | 81 | rx_config.sync_output = false; |
| 82 | 82 | ||
| 83 | let tx_buffer: &mut [u32] = unsafe { | 83 | let tx_buffer: &mut [u32] = unsafe { |
| 84 | TX_BUFFER.initialize_all_copied(0); | 84 | let buf = &mut *core::ptr::addr_of_mut!(TX_BUFFER); |
| 85 | let (ptr, len) = TX_BUFFER.get_ptr_len(); | 85 | buf.initialize_all_copied(0); |
| 86 | let (ptr, len) = buf.get_ptr_len(); | ||
| 86 | core::slice::from_raw_parts_mut(ptr, len) | 87 | core::slice::from_raw_parts_mut(ptr, len) |
| 87 | }; | 88 | }; |
| 88 | 89 | ||
| @@ -98,21 +99,23 @@ async fn main(_spawner: Spawner) { | |||
| 98 | ); | 99 | ); |
| 99 | 100 | ||
| 100 | let rx_buffer: &mut [u32] = unsafe { | 101 | let rx_buffer: &mut [u32] = unsafe { |
| 101 | RX_BUFFER.initialize_all_copied(0); | 102 | let buf = &mut *core::ptr::addr_of_mut!(RX_BUFFER); |
| 102 | let (ptr, len) = RX_BUFFER.get_ptr_len(); | 103 | buf.initialize_all_copied(0); |
| 104 | let (ptr, len) = buf.get_ptr_len(); | ||
| 103 | core::slice::from_raw_parts_mut(ptr, len) | 105 | core::slice::from_raw_parts_mut(ptr, len) |
| 104 | }; | 106 | }; |
| 105 | 107 | ||
| 106 | let mut sai_receiver = Sai::new_synchronous(sub_block_rx, p.PE3, p.DMA1_CH1, rx_buffer, rx_config); | 108 | let mut sai_receiver = Sai::new_synchronous(sub_block_rx, p.PE3, p.DMA1_CH1, rx_buffer, rx_config); |
| 107 | 109 | ||
| 108 | sai_receiver.start(); | 110 | sai_receiver.start().unwrap(); |
| 109 | sai_transmitter.start(); | ||
| 110 | 111 | ||
| 111 | let mut buf = [0u32; HALF_DMA_BUFFER_LENGTH]; | 112 | let mut buf = [0u32; HALF_DMA_BUFFER_LENGTH]; |
| 112 | 113 | ||
| 113 | loop { | 114 | loop { |
| 114 | sai_receiver.read(&mut buf).await.unwrap(); | 115 | // write() must be called before read() to start the master (transmitter) |
| 116 | // clock used by the receiver | ||
| 115 | sai_transmitter.write(&buf).await.unwrap(); | 117 | sai_transmitter.write(&buf).await.unwrap(); |
| 118 | sai_receiver.read(&mut buf).await.unwrap(); | ||
| 116 | } | 119 | } |
| 117 | } | 120 | } |
| 118 | 121 | ||
diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs index abe2d4ba7..96840d8ff 100644 --- a/examples/stm32h7/src/bin/sdmmc.rs +++ b/examples/stm32h7/src/bin/sdmmc.rs | |||
| @@ -53,7 +53,7 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 53 | // Should print 400kHz for initialization | 53 | // Should print 400kHz for initialization |
| 54 | info!("Configured clock: {}", sdmmc.clock().0); | 54 | info!("Configured clock: {}", sdmmc.clock().0); |
| 55 | 55 | ||
| 56 | unwrap!(sdmmc.init_card(mhz(25)).await); | 56 | unwrap!(sdmmc.init_sd_card(mhz(25)).await); |
| 57 | 57 | ||
| 58 | let card = unwrap!(sdmmc.card()); | 58 | let card = unwrap!(sdmmc.card()); |
| 59 | 59 | ||
diff --git a/examples/stm32h7/src/bin/spi_bdma.rs b/examples/stm32h7/src/bin/spi_bdma.rs index 43fb6b41c..5a7dff572 100644 --- a/examples/stm32h7/src/bin/spi_bdma.rs +++ b/examples/stm32h7/src/bin/spi_bdma.rs | |||
| @@ -16,16 +16,17 @@ use static_cell::StaticCell; | |||
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 17 | ||
| 18 | // Defined in memory.x | 18 | // Defined in memory.x |
| 19 | #[link_section = ".ram_d3"] | 19 | #[unsafe(link_section = ".ram_d3")] |
| 20 | static mut RAM_D3: GroundedArrayCell<u8, 256> = GroundedArrayCell::uninit(); | 20 | static mut RAM_D3: GroundedArrayCell<u8, 256> = GroundedArrayCell::uninit(); |
| 21 | 21 | ||
| 22 | #[embassy_executor::task] | 22 | #[embassy_executor::task] |
| 23 | async fn main_task(mut spi: spi::Spi<'static, Async>) { | 23 | async fn main_task(mut spi: spi::Spi<'static, Async>) { |
| 24 | let (read_buffer, write_buffer) = unsafe { | 24 | let (read_buffer, write_buffer) = unsafe { |
| 25 | RAM_D3.initialize_all_copied(0); | 25 | let ram = &mut *core::ptr::addr_of_mut!(RAM_D3); |
| 26 | ram.initialize_all_copied(0); | ||
| 26 | ( | 27 | ( |
| 27 | RAM_D3.get_subslice_mut_unchecked(0, 128), | 28 | ram.get_subslice_mut_unchecked(0, 128), |
| 28 | RAM_D3.get_subslice_mut_unchecked(128, 128), | 29 | ram.get_subslice_mut_unchecked(128, 128), |
| 29 | ) | 30 | ) |
| 30 | }; | 31 | }; |
| 31 | 32 | ||
diff --git a/examples/stm32h7/src/bin/usb_serial.rs b/examples/stm32h7/src/bin/usb_serial.rs index 65ae597d4..50bb964da 100644 --- a/examples/stm32h7/src/bin/usb_serial.rs +++ b/examples/stm32h7/src/bin/usb_serial.rs | |||
| @@ -67,13 +67,6 @@ async fn main(_spawner: Spawner) { | |||
| 67 | config.product = Some("USB-serial example"); | 67 | config.product = Some("USB-serial example"); |
| 68 | config.serial_number = Some("12345678"); | 68 | config.serial_number = Some("12345678"); |
| 69 | 69 | ||
| 70 | // Required for windows compatibility. | ||
| 71 | // https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/kconfig/CONFIG_CDC_ACM_IAD.html#help | ||
| 72 | config.device_class = 0xEF; | ||
| 73 | config.device_sub_class = 0x02; | ||
| 74 | config.device_protocol = 0x01; | ||
| 75 | config.composite_with_iads = true; | ||
| 76 | |||
| 77 | // Create embassy-usb DeviceBuilder using the driver and config. | 70 | // Create embassy-usb DeviceBuilder using the driver and config. |
| 78 | // It needs some buffers for building the descriptors. | 71 | // It needs some buffers for building the descriptors. |
| 79 | let mut config_descriptor = [0; 256]; | 72 | let mut config_descriptor = [0; 256]; |
