diff options
Diffstat (limited to 'examples')
47 files changed, 657 insertions, 163 deletions
diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml index 30b67b7b2..068474e7a 100644 --- a/examples/nrf-rtos-trace/Cargo.toml +++ b/examples/nrf-rtos-trace/Cargo.toml | |||
| @@ -34,3 +34,6 @@ log = { version = "0.4.17", optional = true } | |||
| 34 | [[bin]] | 34 | [[bin]] |
| 35 | name = "rtos_trace" | 35 | name = "rtos_trace" |
| 36 | required-features = ["nightly"] | 36 | required-features = ["nightly"] |
| 37 | |||
| 38 | [profile.release] | ||
| 39 | debug = 2 | ||
diff --git a/examples/nrf52840-rtic/Cargo.toml b/examples/nrf52840-rtic/Cargo.toml index ded3b7db8..715f1ecfe 100644 --- a/examples/nrf52840-rtic/Cargo.toml +++ b/examples/nrf52840-rtic/Cargo.toml | |||
| @@ -19,3 +19,6 @@ cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-sing | |||
| 19 | cortex-m-rt = "0.7.0" | 19 | cortex-m-rt = "0.7.0" |
| 20 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 20 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 21 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 21 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 22 | |||
| 23 | [profile.release] | ||
| 24 | debug = 2 | ||
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml index 9b41ec5ab..780aaeac2 100644 --- a/examples/nrf52840/Cargo.toml +++ b/examples/nrf52840/Cargo.toml | |||
| @@ -57,5 +57,5 @@ embedded-hal-async = { version = "0.2.0-alpha.2", optional = true } | |||
| 57 | num-integer = { version = "0.1.45", default-features = false } | 57 | num-integer = { version = "0.1.45", default-features = false } |
| 58 | microfft = "0.5.0" | 58 | microfft = "0.5.0" |
| 59 | 59 | ||
| 60 | [patch.crates-io] | 60 | [profile.release] |
| 61 | lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" } | 61 | debug = 2 |
diff --git a/examples/nrf5340/Cargo.toml b/examples/nrf5340/Cargo.toml index f1d45f336..b0e51dcf4 100644 --- a/examples/nrf5340/Cargo.toml +++ b/examples/nrf5340/Cargo.toml | |||
| @@ -53,3 +53,6 @@ rand = { version = "0.8.4", default-features = false } | |||
| 53 | embedded-storage = "0.3.0" | 53 | embedded-storage = "0.3.0" |
| 54 | usbd-hid = "0.6.0" | 54 | usbd-hid = "0.6.0" |
| 55 | serde = { version = "1.0.136", default-features = false } | 55 | serde = { version = "1.0.136", default-features = false } |
| 56 | |||
| 57 | [profile.release] | ||
| 58 | debug = 2 | ||
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index c812cb3ee..8c61dc5e1 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml | |||
| @@ -53,7 +53,4 @@ pio = "0.2.1" | |||
| 53 | rand = { version = "0.8.5", default-features = false } | 53 | rand = { version = "0.8.5", default-features = false } |
| 54 | 54 | ||
| 55 | [profile.release] | 55 | [profile.release] |
| 56 | debug = true | 56 | debug = 2 |
| 57 | |||
| 58 | [patch.crates-io] | ||
| 59 | lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" } | ||
diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs index c001d6440..a6d6144be 100644 --- a/examples/rp/src/bin/pio_async.rs +++ b/examples/rp/src/bin/pio_async.rs | |||
| @@ -8,7 +8,6 @@ use embassy_executor::Spawner; | |||
| 8 | use embassy_rp::bind_interrupts; | 8 | use embassy_rp::bind_interrupts; |
| 9 | use embassy_rp::peripherals::PIO0; | 9 | use embassy_rp::peripherals::PIO0; |
| 10 | use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine}; | 10 | use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine}; |
| 11 | use embassy_rp::relocate::RelocatedProgram; | ||
| 12 | use fixed::traits::ToFixed; | 11 | use fixed::traits::ToFixed; |
| 13 | use fixed_macro::types::U56F8; | 12 | use fixed_macro::types::U56F8; |
| 14 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -29,9 +28,8 @@ fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, | |||
| 29 | ".wrap", | 28 | ".wrap", |
| 30 | ); | 29 | ); |
| 31 | 30 | ||
| 32 | let relocated = RelocatedProgram::new(&prg.program); | ||
| 33 | let mut cfg = Config::default(); | 31 | let mut cfg = Config::default(); |
| 34 | cfg.use_program(&pio.load_program(&relocated), &[]); | 32 | cfg.use_program(&pio.load_program(&prg.program), &[]); |
| 35 | let out_pin = pio.make_pio_pin(pin); | 33 | let out_pin = pio.make_pio_pin(pin); |
| 36 | cfg.set_out_pins(&[&out_pin]); | 34 | cfg.set_out_pins(&[&out_pin]); |
| 37 | cfg.set_set_pins(&[&out_pin]); | 35 | cfg.set_set_pins(&[&out_pin]); |
| @@ -65,9 +63,8 @@ fn setup_pio_task_sm1<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, | |||
| 65 | ".wrap", | 63 | ".wrap", |
| 66 | ); | 64 | ); |
| 67 | 65 | ||
| 68 | let relocated = RelocatedProgram::new(&prg.program); | ||
| 69 | let mut cfg = Config::default(); | 66 | let mut cfg = Config::default(); |
| 70 | cfg.use_program(&pio.load_program(&relocated), &[]); | 67 | cfg.use_program(&pio.load_program(&prg.program), &[]); |
| 71 | cfg.clock_divider = (U56F8!(125_000_000) / 2000).to_fixed(); | 68 | cfg.clock_divider = (U56F8!(125_000_000) / 2000).to_fixed(); |
| 72 | cfg.shift_in.auto_fill = true; | 69 | cfg.shift_in.auto_fill = true; |
| 73 | cfg.shift_in.direction = ShiftDirection::Right; | 70 | cfg.shift_in.direction = ShiftDirection::Right; |
| @@ -96,9 +93,8 @@ fn setup_pio_task_sm2<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, | |||
| 96 | "irq 3 [15]", | 93 | "irq 3 [15]", |
| 97 | ".wrap", | 94 | ".wrap", |
| 98 | ); | 95 | ); |
| 99 | let relocated = RelocatedProgram::new(&prg.program); | ||
| 100 | let mut cfg = Config::default(); | 96 | let mut cfg = Config::default(); |
| 101 | cfg.use_program(&pio.load_program(&relocated), &[]); | 97 | cfg.use_program(&pio.load_program(&prg.program), &[]); |
| 102 | cfg.clock_divider = (U56F8!(125_000_000) / 2000).to_fixed(); | 98 | cfg.clock_divider = (U56F8!(125_000_000) / 2000).to_fixed(); |
| 103 | sm.set_config(&cfg); | 99 | sm.set_config(&cfg); |
| 104 | } | 100 | } |
diff --git a/examples/rp/src/bin/pio_dma.rs b/examples/rp/src/bin/pio_dma.rs index 9ab72e1f3..86e5017ac 100644 --- a/examples/rp/src/bin/pio_dma.rs +++ b/examples/rp/src/bin/pio_dma.rs | |||
| @@ -8,7 +8,6 @@ use embassy_executor::Spawner; | |||
| 8 | use embassy_futures::join::join; | 8 | use embassy_futures::join::join; |
| 9 | use embassy_rp::peripherals::PIO0; | 9 | use embassy_rp::peripherals::PIO0; |
| 10 | use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection}; | 10 | use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection}; |
| 11 | use embassy_rp::relocate::RelocatedProgram; | ||
| 12 | use embassy_rp::{bind_interrupts, Peripheral}; | 11 | use embassy_rp::{bind_interrupts, Peripheral}; |
| 13 | use fixed::traits::ToFixed; | 12 | use fixed::traits::ToFixed; |
| 14 | use fixed_macro::types::U56F8; | 13 | use fixed_macro::types::U56F8; |
| @@ -46,9 +45,8 @@ async fn main(_spawner: Spawner) { | |||
| 46 | ".wrap", | 45 | ".wrap", |
| 47 | ); | 46 | ); |
| 48 | 47 | ||
| 49 | let relocated = RelocatedProgram::new(&prg.program); | ||
| 50 | let mut cfg = Config::default(); | 48 | let mut cfg = Config::default(); |
| 51 | cfg.use_program(&common.load_program(&relocated), &[]); | 49 | cfg.use_program(&common.load_program(&prg.program), &[]); |
| 52 | cfg.clock_divider = (U56F8!(125_000_000) / U56F8!(10_000)).to_fixed(); | 50 | cfg.clock_divider = (U56F8!(125_000_000) / U56F8!(10_000)).to_fixed(); |
| 53 | cfg.shift_in = ShiftConfig { | 51 | cfg.shift_in = ShiftConfig { |
| 54 | auto_fill: true, | 52 | auto_fill: true, |
diff --git a/examples/rp/src/bin/pio_hd44780.rs b/examples/rp/src/bin/pio_hd44780.rs index 8aedd24b6..d80c5c24b 100644 --- a/examples/rp/src/bin/pio_hd44780.rs +++ b/examples/rp/src/bin/pio_hd44780.rs | |||
| @@ -14,7 +14,6 @@ use embassy_rp::pio::{ | |||
| 14 | Config, Direction, FifoJoin, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine, | 14 | Config, Direction, FifoJoin, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine, |
| 15 | }; | 15 | }; |
| 16 | use embassy_rp::pwm::{self, Pwm}; | 16 | use embassy_rp::pwm::{self, Pwm}; |
| 17 | use embassy_rp::relocate::RelocatedProgram; | ||
| 18 | use embassy_rp::{bind_interrupts, into_ref, Peripheral, PeripheralRef}; | 17 | use embassy_rp::{bind_interrupts, into_ref, Peripheral, PeripheralRef}; |
| 19 | use embassy_time::{Duration, Instant, Timer}; | 18 | use embassy_time::{Duration, Instant, Timer}; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -127,9 +126,8 @@ impl<'l> HD44780<'l> { | |||
| 127 | 126 | ||
| 128 | sm0.set_pin_dirs(Direction::Out, &[&rs, &rw, &e, &db4, &db5, &db6, &db7]); | 127 | sm0.set_pin_dirs(Direction::Out, &[&rs, &rw, &e, &db4, &db5, &db6, &db7]); |
| 129 | 128 | ||
| 130 | let relocated = RelocatedProgram::new(&prg.program); | ||
| 131 | let mut cfg = Config::default(); | 129 | let mut cfg = Config::default(); |
| 132 | cfg.use_program(&common.load_program(&relocated), &[&e]); | 130 | cfg.use_program(&common.load_program(&prg.program), &[&e]); |
| 133 | cfg.clock_divider = 125u8.into(); | 131 | cfg.clock_divider = 125u8.into(); |
| 134 | cfg.set_out_pins(&[&db4, &db5, &db6, &db7]); | 132 | cfg.set_out_pins(&[&db4, &db5, &db6, &db7]); |
| 135 | cfg.shift_out = ShiftConfig { | 133 | cfg.shift_out = ShiftConfig { |
| @@ -201,9 +199,8 @@ impl<'l> HD44780<'l> { | |||
| 201 | "# | 199 | "# |
| 202 | ); | 200 | ); |
| 203 | 201 | ||
| 204 | let relocated = RelocatedProgram::new(&prg.program); | ||
| 205 | let mut cfg = Config::default(); | 202 | let mut cfg = Config::default(); |
| 206 | cfg.use_program(&common.load_program(&relocated), &[&e]); | 203 | cfg.use_program(&common.load_program(&prg.program), &[&e]); |
| 207 | cfg.clock_divider = 8u8.into(); // ~64ns/insn | 204 | cfg.clock_divider = 8u8.into(); // ~64ns/insn |
| 208 | cfg.set_jmp_pin(&db7); | 205 | cfg.set_jmp_pin(&db7); |
| 209 | cfg.set_set_pins(&[&rs, &rw]); | 206 | cfg.set_set_pins(&[&rs, &rw]); |
diff --git a/examples/rp/src/bin/pio_uart.rs b/examples/rp/src/bin/pio_uart.rs new file mode 100644 index 000000000..5fddbe292 --- /dev/null +++ b/examples/rp/src/bin/pio_uart.rs | |||
| @@ -0,0 +1,392 @@ | |||
| 1 | //! This example shows how to use the PIO module in the RP2040 chip to implement a duplex UART. | ||
| 2 | //! The PIO module is a very powerful peripheral that can be used to implement many different | ||
| 3 | //! protocols. It is a very flexible state machine that can be programmed to do almost anything. | ||
| 4 | //! | ||
| 5 | //! This example opens up a USB device that implements a CDC ACM serial port. It then uses the | ||
| 6 | //! PIO module to implement a UART that is connected to the USB serial port. This allows you to | ||
| 7 | //! communicate with a device connected to the RP2040 over USB serial. | ||
| 8 | |||
| 9 | #![no_std] | ||
| 10 | #![no_main] | ||
| 11 | #![feature(type_alias_impl_trait)] | ||
| 12 | #![feature(async_fn_in_trait)] | ||
| 13 | |||
| 14 | use defmt::{info, panic, trace}; | ||
| 15 | use embassy_executor::Spawner; | ||
| 16 | use embassy_futures::join::{join, join3}; | ||
| 17 | use embassy_rp::bind_interrupts; | ||
| 18 | use embassy_rp::peripherals::{PIO0, USB}; | ||
| 19 | use embassy_rp::pio::InterruptHandler as PioInterruptHandler; | ||
| 20 | use embassy_rp::usb::{Driver, Instance, InterruptHandler}; | ||
| 21 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 22 | use embassy_sync::pipe::Pipe; | ||
| 23 | use embassy_usb::class::cdc_acm::{CdcAcmClass, Receiver, Sender, State}; | ||
| 24 | use embassy_usb::driver::EndpointError; | ||
| 25 | use embassy_usb::{Builder, Config}; | ||
| 26 | use embedded_io::asynch::{Read, Write}; | ||
| 27 | use {defmt_rtt as _, panic_probe as _}; | ||
| 28 | |||
| 29 | use crate::uart::PioUart; | ||
| 30 | use crate::uart_rx::PioUartRx; | ||
| 31 | use crate::uart_tx::PioUartTx; | ||
| 32 | |||
| 33 | bind_interrupts!(struct Irqs { | ||
| 34 | USBCTRL_IRQ => InterruptHandler<USB>; | ||
| 35 | PIO0_IRQ_0 => PioInterruptHandler<PIO0>; | ||
| 36 | }); | ||
| 37 | |||
| 38 | #[embassy_executor::main] | ||
| 39 | async fn main(_spawner: Spawner) { | ||
| 40 | info!("Hello there!"); | ||
| 41 | |||
| 42 | let p = embassy_rp::init(Default::default()); | ||
| 43 | |||
| 44 | // Create the driver, from the HAL. | ||
| 45 | let driver = Driver::new(p.USB, Irqs); | ||
| 46 | |||
| 47 | // Create embassy-usb Config | ||
| 48 | let mut config = Config::new(0xc0de, 0xcafe); | ||
| 49 | config.manufacturer = Some("Embassy"); | ||
| 50 | config.product = Some("PIO UART example"); | ||
| 51 | config.serial_number = Some("12345678"); | ||
| 52 | config.max_power = 100; | ||
| 53 | config.max_packet_size_0 = 64; | ||
| 54 | |||
| 55 | // Required for windows compatibility. | ||
| 56 | // https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/kconfig/CONFIG_CDC_ACM_IAD.html#help | ||
| 57 | config.device_class = 0xEF; | ||
| 58 | config.device_sub_class = 0x02; | ||
| 59 | config.device_protocol = 0x01; | ||
| 60 | config.composite_with_iads = true; | ||
| 61 | |||
| 62 | // Create embassy-usb DeviceBuilder using the driver and config. | ||
| 63 | // It needs some buffers for building the descriptors. | ||
| 64 | let mut device_descriptor = [0; 256]; | ||
| 65 | let mut config_descriptor = [0; 256]; | ||
| 66 | let mut bos_descriptor = [0; 256]; | ||
| 67 | let mut control_buf = [0; 64]; | ||
| 68 | |||
| 69 | let mut state = State::new(); | ||
| 70 | |||
| 71 | let mut builder = Builder::new( | ||
| 72 | driver, | ||
| 73 | config, | ||
| 74 | &mut device_descriptor, | ||
| 75 | &mut config_descriptor, | ||
| 76 | &mut bos_descriptor, | ||
| 77 | &mut control_buf, | ||
| 78 | ); | ||
| 79 | |||
| 80 | // Create classes on the builder. | ||
| 81 | let class = CdcAcmClass::new(&mut builder, &mut state, 64); | ||
| 82 | |||
| 83 | // Build the builder. | ||
| 84 | let mut usb = builder.build(); | ||
| 85 | |||
| 86 | // Run the USB device. | ||
| 87 | let usb_fut = usb.run(); | ||
| 88 | |||
| 89 | // PIO UART setup | ||
| 90 | let uart = PioUart::new(9600, p.PIO0, p.PIN_4, p.PIN_5); | ||
| 91 | let (mut uart_tx, mut uart_rx) = uart.split(); | ||
| 92 | |||
| 93 | // Pipe setup | ||
| 94 | let usb_pipe: Pipe<NoopRawMutex, 20> = Pipe::new(); | ||
| 95 | let mut usb_pipe_writer = usb_pipe.writer(); | ||
| 96 | let mut usb_pipe_reader = usb_pipe.reader(); | ||
| 97 | |||
| 98 | let uart_pipe: Pipe<NoopRawMutex, 20> = Pipe::new(); | ||
| 99 | let mut uart_pipe_writer = uart_pipe.writer(); | ||
| 100 | let mut uart_pipe_reader = uart_pipe.reader(); | ||
| 101 | |||
| 102 | let (mut usb_tx, mut usb_rx) = class.split(); | ||
| 103 | |||
| 104 | // Read + write from USB | ||
| 105 | let usb_future = async { | ||
| 106 | loop { | ||
| 107 | info!("Wait for USB connection"); | ||
| 108 | usb_rx.wait_connection().await; | ||
| 109 | info!("Connected"); | ||
| 110 | let _ = join( | ||
| 111 | usb_read(&mut usb_rx, &mut uart_pipe_writer), | ||
| 112 | usb_write(&mut usb_tx, &mut usb_pipe_reader), | ||
| 113 | ) | ||
| 114 | .await; | ||
| 115 | info!("Disconnected"); | ||
| 116 | } | ||
| 117 | }; | ||
| 118 | |||
| 119 | // Read + write from UART | ||
| 120 | let uart_future = join( | ||
| 121 | uart_read(&mut uart_rx, &mut usb_pipe_writer), | ||
| 122 | uart_write(&mut uart_tx, &mut uart_pipe_reader), | ||
| 123 | ); | ||
| 124 | |||
| 125 | // Run everything concurrently. | ||
| 126 | // If we had made everything `'static` above instead, we could do this using separate tasks instead. | ||
| 127 | join3(usb_fut, usb_future, uart_future).await; | ||
| 128 | } | ||
| 129 | |||
| 130 | struct Disconnected {} | ||
| 131 | |||
| 132 | impl From<EndpointError> for Disconnected { | ||
| 133 | fn from(val: EndpointError) -> Self { | ||
| 134 | match val { | ||
| 135 | EndpointError::BufferOverflow => panic!("Buffer overflow"), | ||
| 136 | EndpointError::Disabled => Disconnected {}, | ||
| 137 | } | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | /// Read from the USB and write it to the UART TX pipe | ||
| 142 | async fn usb_read<'d, T: Instance + 'd>( | ||
| 143 | usb_rx: &mut Receiver<'d, Driver<'d, T>>, | ||
| 144 | uart_pipe_writer: &mut embassy_sync::pipe::Writer<'_, NoopRawMutex, 20>, | ||
| 145 | ) -> Result<(), Disconnected> { | ||
| 146 | let mut buf = [0; 64]; | ||
| 147 | loop { | ||
| 148 | let n = usb_rx.read_packet(&mut buf).await?; | ||
| 149 | let data = &buf[..n]; | ||
| 150 | trace!("USB IN: {:x}", data); | ||
| 151 | uart_pipe_writer.write(data).await; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | /// Read from the USB TX pipe and write it to the USB | ||
| 156 | async fn usb_write<'d, T: Instance + 'd>( | ||
| 157 | usb_tx: &mut Sender<'d, Driver<'d, T>>, | ||
| 158 | usb_pipe_reader: &mut embassy_sync::pipe::Reader<'_, NoopRawMutex, 20>, | ||
| 159 | ) -> Result<(), Disconnected> { | ||
| 160 | let mut buf = [0; 64]; | ||
| 161 | loop { | ||
| 162 | let n = usb_pipe_reader.read(&mut buf).await; | ||
| 163 | let data = &buf[..n]; | ||
| 164 | trace!("USB OUT: {:x}", data); | ||
| 165 | usb_tx.write_packet(&data).await?; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | /// Read from the UART and write it to the USB TX pipe | ||
| 170 | async fn uart_read( | ||
| 171 | uart_rx: &mut PioUartRx<'_>, | ||
| 172 | usb_pipe_writer: &mut embassy_sync::pipe::Writer<'_, NoopRawMutex, 20>, | ||
| 173 | ) -> ! { | ||
| 174 | let mut buf = [0; 64]; | ||
| 175 | loop { | ||
| 176 | let n = uart_rx.read(&mut buf).await.expect("UART read error"); | ||
| 177 | if n == 0 { | ||
| 178 | continue; | ||
| 179 | } | ||
| 180 | let data = &buf[..n]; | ||
| 181 | trace!("UART IN: {:x}", buf); | ||
| 182 | usb_pipe_writer.write(data).await; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | /// Read from the UART TX pipe and write it to the UART | ||
| 187 | async fn uart_write( | ||
| 188 | uart_tx: &mut PioUartTx<'_>, | ||
| 189 | uart_pipe_reader: &mut embassy_sync::pipe::Reader<'_, NoopRawMutex, 20>, | ||
| 190 | ) -> ! { | ||
| 191 | let mut buf = [0; 64]; | ||
| 192 | loop { | ||
| 193 | let n = uart_pipe_reader.read(&mut buf).await; | ||
| 194 | let data = &buf[..n]; | ||
| 195 | trace!("UART OUT: {:x}", data); | ||
| 196 | let _ = uart_tx.write(&data).await; | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | mod uart { | ||
| 201 | use embassy_rp::peripherals::PIO0; | ||
| 202 | use embassy_rp::pio::{Pio, PioPin}; | ||
| 203 | use embassy_rp::Peripheral; | ||
| 204 | |||
| 205 | use crate::uart_rx::PioUartRx; | ||
| 206 | use crate::uart_tx::PioUartTx; | ||
| 207 | use crate::Irqs; | ||
| 208 | |||
| 209 | pub struct PioUart<'a> { | ||
| 210 | tx: PioUartTx<'a>, | ||
| 211 | rx: PioUartRx<'a>, | ||
| 212 | } | ||
| 213 | |||
| 214 | impl<'a> PioUart<'a> { | ||
| 215 | pub fn new( | ||
| 216 | baud: u64, | ||
| 217 | pio: impl Peripheral<P = PIO0> + 'a, | ||
| 218 | tx_pin: impl PioPin, | ||
| 219 | rx_pin: impl PioPin, | ||
| 220 | ) -> PioUart<'a> { | ||
| 221 | let Pio { | ||
| 222 | mut common, sm0, sm1, .. | ||
| 223 | } = Pio::new(pio, Irqs); | ||
| 224 | |||
| 225 | let tx = PioUartTx::new(&mut common, sm0, tx_pin, baud); | ||
| 226 | let rx = PioUartRx::new(&mut common, sm1, rx_pin, baud); | ||
| 227 | |||
| 228 | PioUart { tx, rx } | ||
| 229 | } | ||
| 230 | |||
| 231 | pub fn split(self) -> (PioUartTx<'a>, PioUartRx<'a>) { | ||
| 232 | (self.tx, self.rx) | ||
| 233 | } | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | mod uart_tx { | ||
| 238 | use core::convert::Infallible; | ||
| 239 | |||
| 240 | use embassy_rp::gpio::Level; | ||
| 241 | use embassy_rp::peripherals::PIO0; | ||
| 242 | use embassy_rp::pio::{Common, Config, Direction, FifoJoin, PioPin, ShiftDirection, StateMachine}; | ||
| 243 | use embedded_io::asynch::Write; | ||
| 244 | use embedded_io::Io; | ||
| 245 | use fixed::traits::ToFixed; | ||
| 246 | use fixed_macro::types::U56F8; | ||
| 247 | |||
| 248 | pub struct PioUartTx<'a> { | ||
| 249 | sm_tx: StateMachine<'a, PIO0, 0>, | ||
| 250 | } | ||
| 251 | |||
| 252 | impl<'a> PioUartTx<'a> { | ||
| 253 | pub fn new( | ||
| 254 | common: &mut Common<'a, PIO0>, | ||
| 255 | mut sm_tx: StateMachine<'a, PIO0, 0>, | ||
| 256 | tx_pin: impl PioPin, | ||
| 257 | baud: u64, | ||
| 258 | ) -> Self { | ||
| 259 | let prg = pio_proc::pio_asm!( | ||
| 260 | r#" | ||
| 261 | .side_set 1 opt | ||
| 262 | |||
| 263 | ; An 8n1 UART transmit program. | ||
| 264 | ; OUT pin 0 and side-set pin 0 are both mapped to UART TX pin. | ||
| 265 | |||
| 266 | pull side 1 [7] ; Assert stop bit, or stall with line in idle state | ||
| 267 | set x, 7 side 0 [7] ; Preload bit counter, assert start bit for 8 clocks | ||
| 268 | bitloop: ; This loop will run 8 times (8n1 UART) | ||
| 269 | out pins, 1 ; Shift 1 bit from OSR to the first OUT pin | ||
| 270 | jmp x-- bitloop [6] ; Each loop iteration is 8 cycles. | ||
| 271 | "# | ||
| 272 | ); | ||
| 273 | let tx_pin = common.make_pio_pin(tx_pin); | ||
| 274 | sm_tx.set_pins(Level::High, &[&tx_pin]); | ||
| 275 | sm_tx.set_pin_dirs(Direction::Out, &[&tx_pin]); | ||
| 276 | |||
| 277 | let mut cfg = Config::default(); | ||
| 278 | |||
| 279 | cfg.set_out_pins(&[&tx_pin]); | ||
| 280 | cfg.use_program(&common.load_program(&prg.program), &[&tx_pin]); | ||
| 281 | cfg.shift_out.auto_fill = false; | ||
| 282 | cfg.shift_out.direction = ShiftDirection::Right; | ||
| 283 | cfg.fifo_join = FifoJoin::TxOnly; | ||
| 284 | cfg.clock_divider = (U56F8!(125_000_000) / (8 * baud)).to_fixed(); | ||
| 285 | sm_tx.set_config(&cfg); | ||
| 286 | sm_tx.set_enable(true); | ||
| 287 | |||
| 288 | Self { sm_tx } | ||
| 289 | } | ||
| 290 | |||
| 291 | pub async fn write_u8(&mut self, data: u8) { | ||
| 292 | self.sm_tx.tx().wait_push(data as u32).await; | ||
| 293 | } | ||
| 294 | } | ||
| 295 | |||
| 296 | impl Io for PioUartTx<'_> { | ||
| 297 | type Error = Infallible; | ||
| 298 | } | ||
| 299 | |||
| 300 | impl Write for PioUartTx<'_> { | ||
| 301 | async fn write(&mut self, buf: &[u8]) -> Result<usize, Infallible> { | ||
| 302 | for byte in buf { | ||
| 303 | self.write_u8(*byte).await; | ||
| 304 | } | ||
| 305 | Ok(buf.len()) | ||
| 306 | } | ||
| 307 | } | ||
| 308 | } | ||
| 309 | |||
| 310 | mod uart_rx { | ||
| 311 | use core::convert::Infallible; | ||
| 312 | |||
| 313 | use embassy_rp::gpio::Level; | ||
| 314 | use embassy_rp::peripherals::PIO0; | ||
| 315 | use embassy_rp::pio::{Common, Config, Direction, FifoJoin, PioPin, ShiftDirection, StateMachine}; | ||
| 316 | use embedded_io::asynch::Read; | ||
| 317 | use embedded_io::Io; | ||
| 318 | use fixed::traits::ToFixed; | ||
| 319 | use fixed_macro::types::U56F8; | ||
| 320 | |||
| 321 | pub struct PioUartRx<'a> { | ||
| 322 | sm_rx: StateMachine<'a, PIO0, 1>, | ||
| 323 | } | ||
| 324 | |||
| 325 | impl<'a> PioUartRx<'a> { | ||
| 326 | pub fn new( | ||
| 327 | common: &mut Common<'a, PIO0>, | ||
| 328 | mut sm_rx: StateMachine<'a, PIO0, 1>, | ||
| 329 | rx_pin: impl PioPin, | ||
| 330 | baud: u64, | ||
| 331 | ) -> Self { | ||
| 332 | let prg = pio_proc::pio_asm!( | ||
| 333 | r#" | ||
| 334 | ; Slightly more fleshed-out 8n1 UART receiver which handles framing errors and | ||
| 335 | ; break conditions more gracefully. | ||
| 336 | ; IN pin 0 and JMP pin are both mapped to the GPIO used as UART RX. | ||
| 337 | |||
| 338 | start: | ||
| 339 | wait 0 pin 0 ; Stall until start bit is asserted | ||
| 340 | set x, 7 [10] ; Preload bit counter, then delay until halfway through | ||
| 341 | rx_bitloop: ; the first data bit (12 cycles incl wait, set). | ||
| 342 | in pins, 1 ; Shift data bit into ISR | ||
| 343 | jmp x-- rx_bitloop [6] ; Loop 8 times, each loop iteration is 8 cycles | ||
| 344 | jmp pin good_rx_stop ; Check stop bit (should be high) | ||
| 345 | |||
| 346 | irq 4 rel ; Either a framing error or a break. Set a sticky flag, | ||
| 347 | wait 1 pin 0 ; and wait for line to return to idle state. | ||
| 348 | jmp start ; Don't push data if we didn't see good framing. | ||
| 349 | |||
| 350 | good_rx_stop: ; No delay before returning to start; a little slack is | ||
| 351 | push ; important in case the TX clock is slightly too fast. | ||
| 352 | "# | ||
| 353 | ); | ||
| 354 | let mut cfg = Config::default(); | ||
| 355 | cfg.use_program(&common.load_program(&prg.program), &[]); | ||
| 356 | |||
| 357 | let rx_pin = common.make_pio_pin(rx_pin); | ||
| 358 | sm_rx.set_pins(Level::High, &[&rx_pin]); | ||
| 359 | cfg.set_in_pins(&[&rx_pin]); | ||
| 360 | cfg.set_jmp_pin(&rx_pin); | ||
| 361 | sm_rx.set_pin_dirs(Direction::In, &[&rx_pin]); | ||
| 362 | |||
| 363 | cfg.clock_divider = (U56F8!(125_000_000) / (8 * baud)).to_fixed(); | ||
| 364 | cfg.shift_out.auto_fill = false; | ||
| 365 | cfg.shift_out.direction = ShiftDirection::Right; | ||
| 366 | cfg.fifo_join = FifoJoin::RxOnly; | ||
| 367 | sm_rx.set_config(&cfg); | ||
| 368 | sm_rx.set_enable(true); | ||
| 369 | |||
| 370 | Self { sm_rx } | ||
| 371 | } | ||
| 372 | |||
| 373 | pub async fn read_u8(&mut self) -> u8 { | ||
| 374 | self.sm_rx.rx().wait_pull().await as u8 | ||
| 375 | } | ||
| 376 | } | ||
| 377 | |||
| 378 | impl Io for PioUartRx<'_> { | ||
| 379 | type Error = Infallible; | ||
| 380 | } | ||
| 381 | |||
| 382 | impl Read for PioUartRx<'_> { | ||
| 383 | async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Infallible> { | ||
| 384 | let mut i = 0; | ||
| 385 | while i < buf.len() { | ||
| 386 | buf[i] = self.read_u8().await; | ||
| 387 | i += 1; | ||
| 388 | } | ||
| 389 | Ok(i) | ||
| 390 | } | ||
| 391 | } | ||
| 392 | } | ||
diff --git a/examples/rp/src/bin/pio_ws2812.rs b/examples/rp/src/bin/pio_ws2812.rs index 3de2bd48d..bc87016ec 100644 --- a/examples/rp/src/bin/pio_ws2812.rs +++ b/examples/rp/src/bin/pio_ws2812.rs | |||
| @@ -12,7 +12,6 @@ use embassy_rp::peripherals::PIO0; | |||
| 12 | use embassy_rp::pio::{ | 12 | use embassy_rp::pio::{ |
| 13 | Common, Config, FifoJoin, Instance, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine, | 13 | Common, Config, FifoJoin, Instance, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine, |
| 14 | }; | 14 | }; |
| 15 | use embassy_rp::relocate::RelocatedProgram; | ||
| 16 | use embassy_rp::{bind_interrupts, clocks, into_ref, Peripheral, PeripheralRef}; | 15 | use embassy_rp::{bind_interrupts, clocks, into_ref, Peripheral, PeripheralRef}; |
| 17 | use embassy_time::{Duration, Timer}; | 16 | use embassy_time::{Duration, Timer}; |
| 18 | use fixed::types::U24F8; | 17 | use fixed::types::U24F8; |
| @@ -73,8 +72,7 @@ impl<'d, P: Instance, const S: usize, const N: usize> Ws2812<'d, P, S, N> { | |||
| 73 | cfg.set_out_pins(&[&out_pin]); | 72 | cfg.set_out_pins(&[&out_pin]); |
| 74 | cfg.set_set_pins(&[&out_pin]); | 73 | cfg.set_set_pins(&[&out_pin]); |
| 75 | 74 | ||
| 76 | let relocated = RelocatedProgram::new(&prg); | 75 | cfg.use_program(&pio.load_program(&prg), &[&out_pin]); |
| 77 | cfg.use_program(&pio.load_program(&relocated), &[&out_pin]); | ||
| 78 | 76 | ||
| 79 | // Clock config, measured in kHz to avoid overflows | 77 | // Clock config, measured in kHz to avoid overflows |
| 80 | // TODO CLOCK_FREQ should come from embassy_rp | 78 | // TODO CLOCK_FREQ should come from embassy_rp |
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index 92933ab50..42adede10 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml | |||
| @@ -23,3 +23,6 @@ clap = { version = "3.0.0-beta.5", features = ["derive"] } | |||
| 23 | rand_core = { version = "0.6.3", features = ["std"] } | 23 | rand_core = { version = "0.6.3", features = ["std"] } |
| 24 | heapless = { version = "0.7.5", default-features = false } | 24 | heapless = { version = "0.7.5", default-features = false } |
| 25 | static_cell = { version = "1.1", features = ["nightly"]} | 25 | static_cell = { version = "1.1", features = ["nightly"]} |
| 26 | |||
| 27 | [profile.release] | ||
| 28 | debug = 2 | ||
diff --git a/examples/stm32c0/Cargo.toml b/examples/stm32c0/Cargo.toml index 26837abef..8534921ab 100644 --- a/examples/stm32c0/Cargo.toml +++ b/examples/stm32c0/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32c031c6 to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32c031c6", "memory-x", "unstable-pac", "exti"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32c031c6", "memory-x", "unstable-pac", "exti"] } | ||
| 12 | 13 | ||
| 13 | defmt = "0.3" | 14 | defmt = "0.3" |
| 14 | defmt-rtt = "0.4" | 15 | defmt-rtt = "0.4" |
| @@ -19,3 +20,6 @@ embedded-hal = "0.2.6" | |||
| 19 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 20 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 20 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 21 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 21 | heapless = { version = "0.7.5", default-features = false } | 22 | heapless = { version = "0.7.5", default-features = false } |
| 23 | |||
| 24 | [profile.release] | ||
| 25 | debug = 2 | ||
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index b7b5eaa99..46b6db45c 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml | |||
| @@ -7,6 +7,8 @@ license = "MIT OR Apache-2.0" | |||
| 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
| 8 | 8 | ||
| 9 | [dependencies] | 9 | [dependencies] |
| 10 | # Change stm32f091rc to your chip name, if necessary. | ||
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] } | ||
| 10 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 12 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 11 | cortex-m-rt = "0.7.0" | 13 | cortex-m-rt = "0.7.0" |
| 12 | defmt = "0.3" | 14 | defmt = "0.3" |
| @@ -15,5 +17,7 @@ panic-probe = "0.3" | |||
| 15 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 17 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 16 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } | 18 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } |
| 17 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 19 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 18 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] } | ||
| 19 | static_cell = { version = "1.1", features = ["nightly"]} | 20 | static_cell = { version = "1.1", features = ["nightly"]} |
| 21 | |||
| 22 | [profile.release] | ||
| 23 | debug = 2 | ||
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml index 29cad5b67..5d32992cd 100644 --- a/examples/stm32f1/Cargo.toml +++ b/examples/stm32f1/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32f103c8 to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any", "unstable-traits" ] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any", "unstable-traits" ] } | ||
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 13 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 14 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 14 | 15 | ||
| @@ -25,3 +26,6 @@ nb = "1.0.0" | |||
| 25 | 26 | ||
| 26 | [profile.dev] | 27 | [profile.dev] |
| 27 | opt-level = "s" | 28 | opt-level = "s" |
| 29 | |||
| 30 | [profile.release] | ||
| 31 | debug = 2 | ||
diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml index 652210c7f..9857fb631 100644 --- a/examples/stm32f2/Cargo.toml +++ b/examples/stm32f2/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32f207zg to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | ||
| 12 | 13 | ||
| 13 | defmt = "0.3" | 14 | defmt = "0.3" |
| 14 | defmt-rtt = "0.4" | 15 | defmt-rtt = "0.4" |
| @@ -20,3 +21,6 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } | |||
| 20 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 21 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 21 | heapless = { version = "0.7.5", default-features = false } | 22 | heapless = { version = "0.7.5", default-features = false } |
| 22 | nb = "1.0.0" | 23 | nb = "1.0.0" |
| 24 | |||
| 25 | [profile.release] | ||
| 26 | debug = 2 | ||
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml index 489d0ff4c..bd594d16a 100644 --- a/examples/stm32f3/Cargo.toml +++ b/examples/stm32f3/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32f303ze to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | ||
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 13 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 14 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 14 | 15 | ||
| @@ -24,3 +25,6 @@ heapless = { version = "0.7.5", default-features = false } | |||
| 24 | nb = "1.0.0" | 25 | nb = "1.0.0" |
| 25 | embedded-storage = "0.3.0" | 26 | embedded-storage = "0.3.0" |
| 26 | static_cell = { version = "1.1", features = ["nightly"]} | 27 | static_cell = { version = "1.1", features = ["nightly"]} |
| 28 | |||
| 29 | [profile.release] | ||
| 30 | debug = 2 | ||
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index c1c821364..fdd3b7d4f 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32f429zi to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc", "chrono"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers", "arch-cortex-m", "executor-thread", "executor-interrupt"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc", "chrono"] } | ||
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 13 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } | 14 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } |
| 14 | 15 | ||
diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs index 08bed88db..f84f74d30 100644 --- a/examples/stm32f4/src/bin/can.rs +++ b/examples/stm32f4/src/bin/can.rs | |||
| @@ -40,10 +40,13 @@ async fn main(_spawner: Spawner) { | |||
| 40 | 40 | ||
| 41 | can.as_mut() | 41 | can.as_mut() |
| 42 | .modify_config() | 42 | .modify_config() |
| 43 | .set_bit_timing(0x001c0003) // http://www.bittiming.can-wiki.info/ | ||
| 44 | .set_loopback(true) // Receive own frames | 43 | .set_loopback(true) // Receive own frames |
| 45 | .set_silent(true) | 44 | .set_silent(true) |
| 46 | .enable(); | 45 | .leave_disabled(); |
| 46 | |||
| 47 | can.set_bitrate(1_000_000); | ||
| 48 | |||
| 49 | can.enable().await; | ||
| 47 | 50 | ||
| 48 | let mut i: u8 = 0; | 51 | let mut i: u8 = 0; |
| 49 | loop { | 52 | loop { |
diff --git a/examples/stm32f4/src/bin/dac.rs b/examples/stm32f4/src/bin/dac.rs index 3a6216712..aaedcfecc 100644 --- a/examples/stm32f4/src/bin/dac.rs +++ b/examples/stm32f4/src/bin/dac.rs | |||
| @@ -14,11 +14,11 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 14 | info!("Hello World, dude!"); | 14 | info!("Hello World, dude!"); |
| 15 | 15 | ||
| 16 | let mut dac = DacCh1::new(p.DAC, NoDma, p.PA4); | 16 | let mut dac = DacCh1::new(p.DAC, NoDma, p.PA4); |
| 17 | unwrap!(dac.set_trigger_enable(false)); | ||
| 17 | 18 | ||
| 18 | loop { | 19 | loop { |
| 19 | for v in 0..=255 { | 20 | for v in 0..=255 { |
| 20 | unwrap!(dac.set(Value::Bit8(to_sine_wave(v)))); | 21 | unwrap!(dac.set(Value::Bit8(to_sine_wave(v)))); |
| 21 | dac.trigger(); | ||
| 22 | } | 22 | } |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs index 7c5902052..4f130c26b 100644 --- a/examples/stm32f4/src/bin/pwm.rs +++ b/examples/stm32f4/src/bin/pwm.rs | |||
| @@ -4,9 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; | ||
| 8 | use embassy_stm32::pwm::Channel; | ||
| 9 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 8 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | ||
| 9 | use embassy_stm32::timer::Channel; | ||
| 10 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
diff --git a/examples/stm32f4/src/bin/pwm_complementary.rs b/examples/stm32f4/src/bin/pwm_complementary.rs index a8a68ed6e..8cc2a4117 100644 --- a/examples/stm32f4/src/bin/pwm_complementary.rs +++ b/examples/stm32f4/src/bin/pwm_complementary.rs | |||
| @@ -4,10 +4,10 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::pwm::complementary_pwm::{ComplementaryPwm, ComplementaryPwmPin}; | ||
| 8 | use embassy_stm32::pwm::simple_pwm::PwmPin; | ||
| 9 | use embassy_stm32::pwm::Channel; | ||
| 10 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 8 | use embassy_stm32::timer::complementary_pwm::{ComplementaryPwm, ComplementaryPwmPin}; | ||
| 9 | use embassy_stm32::timer::simple_pwm::PwmPin; | ||
| 10 | use embassy_stm32::timer::Channel; | ||
| 11 | use embassy_time::{Duration, Timer}; | 11 | use embassy_time::{Duration, Timer}; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index 84d7b79c5..a379cbbe3 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32f767zi to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f767zi", "memory-x", "unstable-pac", "time-driver-any", "exti"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } | ||
| 12 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } | 13 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } |
| 13 | embedded-io = { version = "0.4.0", features = ["async"] } | 14 | embedded-io = { version = "0.4.0", features = ["async"] } |
| 14 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 15 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| @@ -27,3 +28,6 @@ rand_core = "0.6.3" | |||
| 27 | critical-section = "1.1" | 28 | critical-section = "1.1" |
| 28 | embedded-storage = "0.3.0" | 29 | embedded-storage = "0.3.0" |
| 29 | static_cell = { version = "1.1", features = ["nightly"]} | 30 | static_cell = { version = "1.1", features = ["nightly"]} |
| 31 | |||
| 32 | [profile.release] | ||
| 33 | debug = 2 | ||
diff --git a/examples/stm32f7/build.rs b/examples/stm32f7/build.rs index 2b5d412a9..8cd32d7ed 100644 --- a/examples/stm32f7/build.rs +++ b/examples/stm32f7/build.rs | |||
| @@ -1,43 +1,5 @@ | |||
| 1 | //! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs | 1 | fn main() { |
| 2 | use std::fs::File; | ||
| 3 | use std::io::prelude::*; | ||
| 4 | use std::path::PathBuf; | ||
| 5 | use std::{env, io}; | ||
| 6 | |||
| 7 | #[derive(Debug)] | ||
| 8 | enum Error { | ||
| 9 | Env(env::VarError), | ||
| 10 | Io(io::Error), | ||
| 11 | } | ||
| 12 | |||
| 13 | impl From<env::VarError> for Error { | ||
| 14 | fn from(error: env::VarError) -> Self { | ||
| 15 | Self::Env(error) | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | impl From<io::Error> for Error { | ||
| 20 | fn from(error: io::Error) -> Self { | ||
| 21 | Self::Io(error) | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | fn main() -> Result<(), Error> { | ||
| 26 | println!("cargo:rerun-if-changed=build.rs"); | ||
| 27 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 28 | |||
| 29 | let out_dir = env::var("OUT_DIR")?; | ||
| 30 | let out_dir = PathBuf::from(out_dir); | ||
| 31 | |||
| 32 | let memory_x = include_bytes!("memory.x").as_ref(); | ||
| 33 | File::create(out_dir.join("memory.x"))?.write_all(memory_x)?; | ||
| 34 | |||
| 35 | // Tell Cargo where to find the file. | ||
| 36 | println!("cargo:rustc-link-search={}", out_dir.display()); | ||
| 37 | |||
| 38 | println!("cargo:rustc-link-arg-bins=--nmagic"); | 2 | println!("cargo:rustc-link-arg-bins=--nmagic"); |
| 39 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | 3 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); |
| 40 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | 4 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); |
| 41 | |||
| 42 | Ok(()) | ||
| 43 | } | 5 | } |
diff --git a/examples/stm32f7/memory.x b/examples/stm32f7/memory.x deleted file mode 100644 index 899f7a4b8..000000000 --- a/examples/stm32f7/memory.x +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | /* For STM32F765,767,768,769,777,778,779 devices */ | ||
| 2 | MEMORY | ||
| 3 | { | ||
| 4 | /* NOTE K = KiBi = 1024 bytes */ | ||
| 5 | FLASH : ORIGIN = 0x08000000, LENGTH = 2M | ||
| 6 | RAM : ORIGIN = 0x20000000, LENGTH = 368K + 16K | ||
| 7 | } | ||
| 8 | |||
| 9 | /* This is where the call stack will be allocated. */ | ||
| 10 | /* The stack is of the full descending type. */ | ||
| 11 | /* NOTE Do NOT modify `_stack_start` unless you know what you are doing */ | ||
| 12 | _stack_start = ORIGIN(RAM) + LENGTH(RAM); | ||
diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml index c88282d91..b4dfe3c6b 100644 --- a/examples/stm32g0/Cargo.toml +++ b/examples/stm32g0/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32g071rb to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } | ||
| 12 | 13 | ||
| 13 | defmt = "0.3" | 14 | defmt = "0.3" |
| 14 | defmt-rtt = "0.4" | 15 | defmt-rtt = "0.4" |
| @@ -19,3 +20,6 @@ embedded-hal = "0.2.6" | |||
| 19 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 20 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 20 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 21 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 21 | heapless = { version = "0.7.5", default-features = false } | 22 | heapless = { version = "0.7.5", default-features = false } |
| 23 | |||
| 24 | [profile.release] | ||
| 25 | debug = 2 | ||
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml index 18bd03c39..cf3e2ce9b 100644 --- a/examples/stm32g4/Cargo.toml +++ b/examples/stm32g4/Cargo.toml | |||
| @@ -5,11 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32g491re to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } | ||
| 12 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | ||
| 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 14 | 14 | ||
| 15 | defmt = "0.3" | 15 | defmt = "0.3" |
| @@ -21,3 +21,6 @@ embedded-hal = "0.2.6" | |||
| 21 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 21 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 22 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 22 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 23 | heapless = { version = "0.7.5", default-features = false } | 23 | heapless = { version = "0.7.5", default-features = false } |
| 24 | |||
| 25 | [profile.release] | ||
| 26 | debug = 2 | ||
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs index 8f7842ed7..b5a9b9952 100644 --- a/examples/stm32g4/src/bin/pwm.rs +++ b/examples/stm32g4/src/bin/pwm.rs | |||
| @@ -4,9 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; | ||
| 8 | use embassy_stm32::pwm::Channel; | ||
| 9 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 8 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | ||
| 9 | use embassy_stm32::timer::Channel; | ||
| 10 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml index 227bc28b4..51d3bad1f 100644 --- a/examples/stm32h5/Cargo.toml +++ b/examples/stm32h5/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32h563zi to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h563zi", "memory-x", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h563zi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } | ||
| 12 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] } | 13 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] } |
| 13 | embedded-io = { version = "0.4.0", features = ["async"] } | 14 | embedded-io = { version = "0.4.0", features = ["async"] } |
| 14 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 15 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
diff --git a/examples/stm32h5/memory.x b/examples/stm32h5/memory.x deleted file mode 100644 index 456061509..000000000 --- a/examples/stm32h5/memory.x +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | FLASH : ORIGIN = 0x08000000, LENGTH = 0x200000 | ||
| 4 | RAM : ORIGIN = 0x20000000, LENGTH = 0x50000 | ||
| 5 | } | ||
diff --git a/examples/stm32h7/.cargo/config.toml b/examples/stm32h7/.cargo/config.toml index 5f680dbce..4160bf855 100644 --- a/examples/stm32h7/.cargo/config.toml +++ b/examples/stm32h7/.cargo/config.toml | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | [target.thumbv7em-none-eabihf] | 1 | [target.thumbv7em-none-eabihf] |
| 2 | runner = 'probe-rs run --chip STM32H743ZITx' | 2 | runner = 'probe-rs run --chip STM32H7A3ZITxQ' |
| 3 | 3 | ||
| 4 | [build] | 4 | [build] |
| 5 | target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) | 5 | target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) |
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index 768702fa9..3c1232e67 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32h743bi to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "memory-x", "unstable-pac", "unstable-traits"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } | ||
| 12 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] } | 13 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] } |
| 13 | embedded-io = { version = "0.4.0", features = ["async"] } | 14 | embedded-io = { version = "0.4.0", features = ["async"] } |
| 14 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 15 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
diff --git a/examples/stm32h7/memory.x b/examples/stm32h7/memory.x deleted file mode 100644 index 026b14b9b..000000000 --- a/examples/stm32h7/memory.x +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | FLASH : ORIGIN = 0x8000000, LENGTH = 1024K | ||
| 4 | RAM : ORIGIN = 0x24000000, LENGTH = 384K | ||
| 5 | } | ||
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index 586b4154b..ee078286b 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs | |||
| @@ -21,11 +21,11 @@ fn main() -> ! { | |||
| 21 | let p = embassy_stm32::init(config); | 21 | let p = embassy_stm32::init(config); |
| 22 | 22 | ||
| 23 | let mut dac = DacCh1::new(p.DAC1, NoDma, p.PA4); | 23 | let mut dac = DacCh1::new(p.DAC1, NoDma, p.PA4); |
| 24 | unwrap!(dac.set_trigger_enable(false)); | ||
| 24 | 25 | ||
| 25 | loop { | 26 | loop { |
| 26 | for v in 0..=255 { | 27 | for v in 0..=255 { |
| 27 | unwrap!(dac.set(Value::Bit8(to_sine_wave(v)))); | 28 | unwrap!(dac.set(Value::Bit8(to_sine_wave(v)))); |
| 28 | dac.trigger(); | ||
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| 31 | } | 31 | } |
diff --git a/examples/stm32h7/src/bin/dac_dma.rs b/examples/stm32h7/src/bin/dac_dma.rs new file mode 100644 index 000000000..a9cb5d1ed --- /dev/null +++ b/examples/stm32h7/src/bin/dac_dma.rs | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_stm32::dac::{DacChannel, ValueArray}; | ||
| 8 | use embassy_stm32::pac::timer::vals::{Mms, Opm}; | ||
| 9 | use embassy_stm32::peripherals::{TIM6, TIM7}; | ||
| 10 | use embassy_stm32::rcc::low_level::RccPeripheral; | ||
| 11 | use embassy_stm32::time::{mhz, Hertz}; | ||
| 12 | use embassy_stm32::timer::low_level::Basic16bitInstance; | ||
| 13 | use micromath::F32Ext; | ||
| 14 | use {defmt_rtt as _, panic_probe as _}; | ||
| 15 | |||
| 16 | pub type Dac1Type = | ||
| 17 | embassy_stm32::dac::DacCh1<'static, embassy_stm32::peripherals::DAC1, embassy_stm32::peripherals::DMA1_CH3>; | ||
| 18 | |||
| 19 | pub type Dac2Type = | ||
| 20 | embassy_stm32::dac::DacCh2<'static, embassy_stm32::peripherals::DAC1, embassy_stm32::peripherals::DMA1_CH4>; | ||
| 21 | |||
| 22 | #[embassy_executor::main] | ||
| 23 | async fn main(spawner: Spawner) { | ||
| 24 | let mut config = embassy_stm32::Config::default(); | ||
| 25 | config.rcc.sys_ck = Some(mhz(400)); | ||
| 26 | config.rcc.hclk = Some(mhz(100)); | ||
| 27 | config.rcc.pll1.q_ck = Some(mhz(100)); | ||
| 28 | |||
| 29 | // Initialize the board and obtain a Peripherals instance | ||
| 30 | let p: embassy_stm32::Peripherals = embassy_stm32::init(config); | ||
| 31 | |||
| 32 | // Obtain two independent channels (p.DAC1 can only be consumed once, though!) | ||
| 33 | let (dac_ch1, dac_ch2) = embassy_stm32::dac::Dac::new(p.DAC1, p.DMA1_CH3, p.DMA1_CH4, p.PA4, p.PA5).split(); | ||
| 34 | |||
| 35 | spawner.spawn(dac_task1(dac_ch1)).ok(); | ||
| 36 | spawner.spawn(dac_task2(dac_ch2)).ok(); | ||
| 37 | } | ||
| 38 | |||
| 39 | #[embassy_executor::task] | ||
| 40 | async fn dac_task1(mut dac: Dac1Type) { | ||
| 41 | let data: &[u8; 256] = &calculate_array::<256>(); | ||
| 42 | |||
| 43 | info!("TIM6 frequency is {}", TIM6::frequency()); | ||
| 44 | const FREQUENCY: Hertz = Hertz::hz(200); | ||
| 45 | |||
| 46 | // Compute the reload value such that we obtain the FREQUENCY for the sine | ||
| 47 | let reload: u32 = (TIM6::frequency().0 / FREQUENCY.0) / data.len() as u32; | ||
| 48 | |||
| 49 | // Depends on your clock and on the specific chip used, you may need higher or lower values here | ||
| 50 | if reload < 10 { | ||
| 51 | error!("Reload value {} below threshold!", reload); | ||
| 52 | } | ||
| 53 | |||
| 54 | dac.select_trigger(embassy_stm32::dac::Ch1Trigger::Tim6).unwrap(); | ||
| 55 | dac.enable_channel().unwrap(); | ||
| 56 | |||
| 57 | TIM6::enable(); | ||
| 58 | TIM6::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); | ||
| 59 | TIM6::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); | ||
| 60 | TIM6::regs().cr1().modify(|w| { | ||
| 61 | w.set_opm(Opm::DISABLED); | ||
| 62 | w.set_cen(true); | ||
| 63 | }); | ||
| 64 | |||
| 65 | debug!( | ||
| 66 | "TIM6 Frequency {}, Target Frequency {}, Reload {}, Reload as u16 {}, Samples {}", | ||
| 67 | TIM6::frequency(), | ||
| 68 | FREQUENCY, | ||
| 69 | reload, | ||
| 70 | reload as u16, | ||
| 71 | data.len() | ||
| 72 | ); | ||
| 73 | |||
| 74 | // Loop technically not necessary if DMA circular mode is enabled | ||
| 75 | loop { | ||
| 76 | info!("Loop DAC1"); | ||
| 77 | if let Err(e) = dac.write(ValueArray::Bit8(data), true).await { | ||
| 78 | error!("Could not write to dac: {}", e); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | #[embassy_executor::task] | ||
| 84 | async fn dac_task2(mut dac: Dac2Type) { | ||
| 85 | let data: &[u8; 256] = &calculate_array::<256>(); | ||
| 86 | |||
| 87 | info!("TIM7 frequency is {}", TIM7::frequency()); | ||
| 88 | |||
| 89 | const FREQUENCY: Hertz = Hertz::hz(600); | ||
| 90 | let reload: u32 = (TIM7::frequency().0 / FREQUENCY.0) / data.len() as u32; | ||
| 91 | |||
| 92 | if reload < 10 { | ||
| 93 | error!("Reload value {} below threshold!", reload); | ||
| 94 | } | ||
| 95 | |||
| 96 | TIM7::enable(); | ||
| 97 | TIM7::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); | ||
| 98 | TIM7::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); | ||
| 99 | TIM7::regs().cr1().modify(|w| { | ||
| 100 | w.set_opm(Opm::DISABLED); | ||
| 101 | w.set_cen(true); | ||
| 102 | }); | ||
| 103 | |||
| 104 | dac.select_trigger(embassy_stm32::dac::Ch2Trigger::Tim7).unwrap(); | ||
| 105 | |||
| 106 | debug!( | ||
| 107 | "TIM7 Frequency {}, Target Frequency {}, Reload {}, Reload as u16 {}, Samples {}", | ||
| 108 | TIM7::frequency(), | ||
| 109 | FREQUENCY, | ||
| 110 | reload, | ||
| 111 | reload as u16, | ||
| 112 | data.len() | ||
| 113 | ); | ||
| 114 | |||
| 115 | if let Err(e) = dac.write(ValueArray::Bit8(data), true).await { | ||
| 116 | error!("Could not write to dac: {}", e); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | fn to_sine_wave(v: u8) -> u8 { | ||
| 121 | if v >= 128 { | ||
| 122 | // top half | ||
| 123 | let r = 3.14 * ((v - 128) as f32 / 128.0); | ||
| 124 | (r.sin() * 128.0 + 127.0) as u8 | ||
| 125 | } else { | ||
| 126 | // bottom half | ||
| 127 | let r = 3.14 + 3.14 * (v as f32 / 128.0); | ||
| 128 | (r.sin() * 128.0 + 127.0) as u8 | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | fn calculate_array<const N: usize>() -> [u8; N] { | ||
| 133 | let mut res = [0; N]; | ||
| 134 | let mut i = 0; | ||
| 135 | while i < N { | ||
| 136 | res[i] = to_sine_wave(i as u8); | ||
| 137 | i += 1; | ||
| 138 | } | ||
| 139 | res | ||
| 140 | } | ||
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index d360df085..45b0872b5 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -6,8 +6,8 @@ use defmt::*; | |||
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::gpio::low_level::AFType; | 7 | use embassy_stm32::gpio::low_level::AFType; |
| 8 | use embassy_stm32::gpio::Speed; | 8 | use embassy_stm32::gpio::Speed; |
| 9 | use embassy_stm32::pwm::*; | ||
| 10 | use embassy_stm32::time::{khz, mhz, Hertz}; | 9 | use embassy_stm32::time::{khz, mhz, Hertz}; |
| 10 | use embassy_stm32::timer::*; | ||
| 11 | use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef}; | 11 | use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef}; |
| 12 | use embassy_time::{Duration, Timer}; | 12 | use embassy_time::{Duration, Timer}; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index c5c0dd290..adf2ea9ce 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs | |||
| @@ -4,9 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; | ||
| 8 | use embassy_stm32::pwm::Channel; | ||
| 9 | use embassy_stm32::time::{khz, mhz}; | 7 | use embassy_stm32::time::{khz, mhz}; |
| 8 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | ||
| 9 | use embassy_stm32::timer::Channel; | ||
| 10 | use embassy_stm32::Config; | 10 | use embassy_stm32::Config; |
| 11 | use embassy_time::{Duration, Timer}; | 11 | use embassy_time::{Duration, Timer}; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index 747cec7bf..c325751c6 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml | |||
| @@ -10,10 +10,11 @@ nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstab | |||
| 10 | "embassy-lora", "lora-phy", "lorawan-device", "lorawan", "embedded-io/async"] | 10 | "embassy-lora", "lora-phy", "lorawan-device", "lorawan", "embedded-io/async"] |
| 11 | 11 | ||
| 12 | [dependencies] | 12 | [dependencies] |
| 13 | # Change stm32l072cz to your chip name, if necessary. | ||
| 14 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } | ||
| 13 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 15 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 14 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 16 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 15 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 17 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 16 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } | ||
| 17 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true } | 18 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true } |
| 18 | lora-phy = { version = "1", optional = true } | 19 | lora-phy = { version = "1", optional = true } |
| 19 | lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"], optional = true } | 20 | lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"], optional = true } |
| @@ -33,5 +34,5 @@ heapless = { version = "0.7.5", default-features = false } | |||
| 33 | embedded-hal = "0.2.6" | 34 | embedded-hal = "0.2.6" |
| 34 | static_cell = "1.1" | 35 | static_cell = "1.1" |
| 35 | 36 | ||
| 36 | [patch.crates-io] | 37 | [profile.release] |
| 37 | lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" } | 38 | debug = 2 |
diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml index dcca1cc3d..329d44cac 100644 --- a/examples/stm32l1/Cargo.toml +++ b/examples/stm32l1/Cargo.toml | |||
| @@ -20,3 +20,6 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } | |||
| 20 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 20 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 21 | heapless = { version = "0.7.5", default-features = false } | 21 | heapless = { version = "0.7.5", default-features = false } |
| 22 | embedded-storage = "0.3.0" | 22 | embedded-storage = "0.3.0" |
| 23 | |||
| 24 | [profile.release] | ||
| 25 | debug = 2 | ||
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index c55558518..3b27d8e81 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml | |||
| @@ -5,11 +5,12 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32l4s5vi to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "memory-x", "time-driver-any", "exti", "unstable-traits", "chrono"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } |
| 12 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits", "chrono"] } | ||
| 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 14 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 14 | 15 | ||
| 15 | defmt = "0.3" | 16 | defmt = "0.3" |
| @@ -26,3 +27,6 @@ heapless = { version = "0.7.5", default-features = false } | |||
| 26 | chrono = { version = "^0.4", default-features = false } | 27 | chrono = { version = "^0.4", default-features = false } |
| 27 | 28 | ||
| 28 | micromath = "2.0.0" | 29 | micromath = "2.0.0" |
| 30 | |||
| 31 | [profile.release] | ||
| 32 | debug = 2 | ||
diff --git a/examples/stm32l4/build.rs b/examples/stm32l4/build.rs index 30691aa97..8cd32d7ed 100644 --- a/examples/stm32l4/build.rs +++ b/examples/stm32l4/build.rs | |||
| @@ -1,34 +1,4 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | 1 | fn main() { |
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | 2 | println!("cargo:rustc-link-arg-bins=--nmagic"); |
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | 3 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); |
| 34 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | 4 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); |
diff --git a/examples/stm32l4/memory.x b/examples/stm32l4/memory.x deleted file mode 100644 index eb87d1b54..000000000 --- a/examples/stm32l4/memory.x +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | /* These values correspond to the STM32L4S5 */ | ||
| 5 | FLASH : ORIGIN = 0x08000000, LENGTH = 1024K | ||
| 6 | RAM : ORIGIN = 0x20000000, LENGTH = 128K | ||
| 7 | } | ||
diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs index ade43eb35..0193a248e 100644 --- a/examples/stm32l4/src/bin/dac.rs +++ b/examples/stm32l4/src/bin/dac.rs | |||
| @@ -13,11 +13,11 @@ fn main() -> ! { | |||
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | let mut dac = DacCh1::new(p.DAC1, NoDma, p.PA4); | 15 | let mut dac = DacCh1::new(p.DAC1, NoDma, p.PA4); |
| 16 | unwrap!(dac.set_trigger_enable(false)); | ||
| 16 | 17 | ||
| 17 | loop { | 18 | loop { |
| 18 | for v in 0..=255 { | 19 | for v in 0..=255 { |
| 19 | unwrap!(dac.set(Value::Bit8(to_sine_wave(v)))); | 20 | unwrap!(dac.set(Value::Bit8(to_sine_wave(v)))); |
| 20 | dac.trigger(); | ||
| 21 | } | 21 | } |
| 22 | } | 22 | } |
| 23 | } | 23 | } |
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index 54911482e..1afd00398 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32l552ze to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } | ||
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 13 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } | 14 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } |
| 14 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 15 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| @@ -26,3 +27,6 @@ heapless = { version = "0.7.5", default-features = false } | |||
| 26 | rand_core = { version = "0.6.3", default-features = false } | 27 | rand_core = { version = "0.6.3", default-features = false } |
| 27 | embedded-io = { version = "0.4.0", features = ["async"] } | 28 | embedded-io = { version = "0.4.0", features = ["async"] } |
| 28 | static_cell = { version = "1.1", features = ["nightly"]} | 29 | static_cell = { version = "1.1", features = ["nightly"]} |
| 30 | |||
| 31 | [profile.release] | ||
| 32 | debug = 2 | ||
diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml index 835e32940..db251eafe 100644 --- a/examples/stm32u5/Cargo.toml +++ b/examples/stm32u5/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32u585ai to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } | ||
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 13 | 14 | ||
| 14 | defmt = "0.3" | 15 | defmt = "0.3" |
| @@ -22,3 +23,6 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa | |||
| 22 | heapless = { version = "0.7.5", default-features = false } | 23 | heapless = { version = "0.7.5", default-features = false } |
| 23 | 24 | ||
| 24 | micromath = "2.0.0" | 25 | micromath = "2.0.0" |
| 26 | |||
| 27 | [profile.release] | ||
| 28 | debug = 2 | ||
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml index 7c0b83e65..1a5aff352 100644 --- a/examples/stm32wb/Cargo.toml +++ b/examples/stm32wb/Cargo.toml | |||
| @@ -5,11 +5,12 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32wb55rg to your chip name in both dependencies, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti"] } | ||
| 10 | embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", features = ["defmt", "stm32wb55rg"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 11 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 12 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 13 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti"] } | ||
| 12 | embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", features = ["defmt", "stm32wb55rg"] } | ||
| 13 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "udp", "medium-ieee802154", "nightly"], optional=true } | 14 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "udp", "medium-ieee802154", "nightly"], optional=true } |
| 14 | 15 | ||
| 15 | defmt = "0.3" | 16 | defmt = "0.3" |
| @@ -50,4 +51,7 @@ required-features = ["ble"] | |||
| 50 | 51 | ||
| 51 | [[bin]] | 52 | [[bin]] |
| 52 | name = "gatt_server" | 53 | name = "gatt_server" |
| 53 | required-features = ["ble"] \ No newline at end of file | 54 | required-features = ["ble"] |
| 55 | |||
| 56 | [profile.release] | ||
| 57 | debug = 2 | ||
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml index e2c66f456..48b69c8d0 100644 --- a/examples/stm32wl/Cargo.toml +++ b/examples/stm32wl/Cargo.toml | |||
| @@ -5,10 +5,11 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32wl55jc-cm4 to your chip name, if necessary. | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti", "chrono"] } | ||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti", "chrono"] } | ||
| 12 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } |
| 13 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } | 14 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } |
| 14 | lora-phy = { version = "1" } | 15 | lora-phy = { version = "1" } |
| @@ -27,5 +28,5 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa | |||
| 27 | heapless = { version = "0.7.5", default-features = false } | 28 | heapless = { version = "0.7.5", default-features = false } |
| 28 | chrono = { version = "^0.4", default-features = false } | 29 | chrono = { version = "^0.4", default-features = false } |
| 29 | 30 | ||
| 30 | [patch.crates-io] | 31 | [profile.release] |
| 31 | lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" } | 32 | debug = 2 |
diff --git a/examples/wasm/Cargo.toml b/examples/wasm/Cargo.toml index 3679e3857..2791cc341 100644 --- a/examples/wasm/Cargo.toml +++ b/examples/wasm/Cargo.toml | |||
| @@ -17,3 +17,6 @@ wasm-bindgen = "0.2" | |||
| 17 | web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] } | 17 | web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] } |
| 18 | log = "0.4.11" | 18 | log = "0.4.11" |
| 19 | critical-section = { version = "1.1", features = ["std"] } | 19 | critical-section = { version = "1.1", features = ["std"] } |
| 20 | |||
| 21 | [profile.release] | ||
| 22 | debug = 2 | ||
