aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Smith <[email protected]>2022-08-19 00:53:06 -0400
committerQuentin Smith <[email protected]>2022-08-19 00:53:41 -0400
commit71e468681b1c074e06276d34ff00e36169c632f5 (patch)
treece86220caabbdc044720df8efb23de7bc4c36ea0
parent2edf532f8d8ce048137990bf74b07759428ed7c1 (diff)
parentaefa5275a2ab2cac6caef599e7adb76ce1beeddd (diff)
Merge branch 'master' of https://github.com/embassy-rs/embassy into rtos-trace
-rw-r--r--.vscode/settings.json2
-rw-r--r--README.md10
-rwxr-xr-xci.sh38
-rwxr-xr-xci_stable.sh66
-rw-r--r--docs/antora.yml2
-rw-r--r--docs/modules/ROOT/examples/basic/Cargo.toml1
-rw-r--r--docs/modules/ROOT/examples/basic/src/main.rs9
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs6
-rw-r--r--docs/modules/ROOT/images/bootloader_flash.pngbin0 -> 32147 bytes
-rw-r--r--docs/modules/ROOT/nav.adoc12
-rw-r--r--docs/modules/ROOT/pages/basic_application.adoc20
-rw-r--r--docs/modules/ROOT/pages/bootloader.adoc5
-rw-r--r--docs/modules/ROOT/pages/getting_started.adoc6
-rw-r--r--docs/modules/ROOT/pages/hal.adoc5
-rw-r--r--docs/modules/ROOT/pages/index.adoc18
-rw-r--r--docs/modules/ROOT/pages/runtime.adoc4
-rw-r--r--docs/modules/ROOT/pages/traits.adoc8
-rw-r--r--embassy-boot/boot/Cargo.toml5
-rw-r--r--embassy-boot/nrf/Cargo.toml8
-rw-r--r--embassy-boot/stm32/Cargo.toml8
-rw-r--r--embassy-cortex-m/Cargo.toml6
-rw-r--r--embassy-cortex-m/src/executor.rs6
-rw-r--r--embassy-cortex-m/src/interrupt.rs7
-rw-r--r--embassy-embedded-hal/Cargo.toml7
-rw-r--r--embassy-executor/Cargo.toml42
-rw-r--r--embassy-executor/README.md11
-rw-r--r--embassy-executor/src/arch/cortex_m.rs (renamed from embassy-executor/src/executor/arch/cortex_m.rs)0
-rw-r--r--embassy-executor/src/arch/riscv32.rs (renamed from embassy-executor/src/executor/arch/riscv32.rs)0
-rw-r--r--embassy-executor/src/arch/std.rs (renamed from embassy-executor/src/executor/arch/std.rs)0
-rw-r--r--embassy-executor/src/arch/wasm.rs (renamed from embassy-executor/src/executor/arch/wasm.rs)0
-rw-r--r--embassy-executor/src/arch/xtensa.rs (renamed from embassy-executor/src/executor/arch/xtensa.rs)0
-rw-r--r--embassy-executor/src/executor/mod.rs44
-rw-r--r--embassy-executor/src/fmt.rs3
-rw-r--r--embassy-executor/src/lib.rs41
-rw-r--r--embassy-executor/src/raw/mod.rs (renamed from embassy-executor/src/executor/raw/mod.rs)49
-rw-r--r--embassy-executor/src/raw/run_queue.rs (renamed from embassy-executor/src/executor/raw/run_queue.rs)0
-rw-r--r--embassy-executor/src/raw/timer_queue.rs (renamed from embassy-executor/src/executor/raw/timer_queue.rs)2
-rw-r--r--embassy-executor/src/raw/util.rs (renamed from embassy-executor/src/executor/raw/util.rs)0
-rw-r--r--embassy-executor/src/raw/waker.rs (renamed from embassy-executor/src/executor/raw/waker.rs)2
-rw-r--r--embassy-executor/src/spawner.rs (renamed from embassy-executor/src/executor/spawner.rs)0
-rw-r--r--embassy-hal-common/Cargo.toml1
-rw-r--r--embassy-lora/Cargo.toml6
-rw-r--r--embassy-lora/src/lib.rs2
-rw-r--r--embassy-lora/src/sx127x/sx127x_lora/mod.rs2
-rw-r--r--embassy-macros/Cargo.toml3
-rw-r--r--embassy-macros/src/macros/cortex_m_interrupt_take.rs8
-rw-r--r--embassy-macros/src/macros/main.rs81
-rw-r--r--embassy-macros/src/macros/task.rs10
-rw-r--r--embassy-macros/src/util/mod.rs1
-rw-r--r--embassy-macros/src/util/path.rs41
-rw-r--r--embassy-net/Cargo.toml32
-rw-r--r--embassy-net/src/lib.rs5
-rw-r--r--embassy-net/src/stack.rs2
-rw-r--r--embassy-net/src/tcp.rs171
-rw-r--r--embassy-net/src/udp.rs157
-rw-r--r--embassy-nrf/Cargo.toml10
-rw-r--r--embassy-nrf/src/chips/nrf52805.rs2
-rw-r--r--embassy-nrf/src/chips/nrf52810.rs2
-rw-r--r--embassy-nrf/src/chips/nrf52811.rs2
-rw-r--r--embassy-nrf/src/chips/nrf52820.rs2
-rw-r--r--embassy-nrf/src/chips/nrf52832.rs2
-rw-r--r--embassy-nrf/src/chips/nrf52833.rs2
-rw-r--r--embassy-nrf/src/chips/nrf52840.rs2
-rw-r--r--embassy-nrf/src/chips/nrf5340_app.rs2
-rw-r--r--embassy-nrf/src/chips/nrf5340_net.rs2
-rw-r--r--embassy-nrf/src/chips/nrf9160.rs2
-rw-r--r--embassy-nrf/src/lib.rs2
-rw-r--r--embassy-nrf/src/time_driver.rs4
-rw-r--r--embassy-nrf/src/twim.rs4
-rw-r--r--embassy-rp/Cargo.toml12
-rw-r--r--embassy-rp/src/dma.rs6
-rw-r--r--embassy-rp/src/interrupt.rs2
-rw-r--r--embassy-rp/src/lib.rs2
-rw-r--r--embassy-rp/src/timer.rs4
-rw-r--r--embassy-rp/src/uart.rs401
-rw-r--r--embassy-stm32/Cargo.toml13
-rw-r--r--embassy-stm32/build.rs2
-rw-r--r--embassy-stm32/src/gpio.rs8
-rw-r--r--embassy-stm32/src/i2c/v1.rs36
-rw-r--r--embassy-stm32/src/i2c/v2.rs36
-rw-r--r--embassy-stm32/src/interrupt.rs3
-rw-r--r--embassy-stm32/src/lib.rs2
-rw-r--r--embassy-stm32/src/rcc/u5.rs6
-rw-r--r--embassy-stm32/src/sdmmc/mod.rs9
-rw-r--r--embassy-stm32/src/subghz/mod.rs2
-rw-r--r--embassy-stm32/src/subghz/timeout.rs4
-rw-r--r--embassy-stm32/src/subghz/tx_params.rs18
-rw-r--r--embassy-stm32/src/time_driver.rs6
-rw-r--r--embassy-stm32/src/usb/usb.rs2
-rw-r--r--embassy-time/Cargo.toml54
-rw-r--r--embassy-time/src/delay.rs (renamed from embassy-executor/src/time/delay.rs)2
-rw-r--r--embassy-time/src/driver.rs (renamed from embassy-executor/src/time/driver.rs)44
-rw-r--r--embassy-time/src/driver_std.rs (renamed from embassy-executor/src/time/driver_std.rs)2
-rw-r--r--embassy-time/src/driver_wasm.rs (renamed from embassy-executor/src/time/driver_wasm.rs)2
-rw-r--r--embassy-time/src/duration.rs (renamed from embassy-executor/src/time/duration.rs)0
-rw-r--r--embassy-time/src/fmt.rs225
-rw-r--r--embassy-time/src/instant.rs (renamed from embassy-executor/src/time/instant.rs)0
-rw-r--r--embassy-time/src/lib.rs (renamed from embassy-executor/src/time/mod.rs)28
-rw-r--r--embassy-time/src/timer.rs (renamed from embassy-executor/src/time/timer.rs)23
-rw-r--r--embassy-usb-hid/Cargo.toml6
-rw-r--r--embassy-usb-ncm/Cargo.toml4
-rw-r--r--embassy-usb-serial/Cargo.toml4
-rw-r--r--embassy-usb/Cargo.toml4
-rw-r--r--embassy-util/Cargo.toml11
-rw-r--r--embassy-util/src/channel/signal.rs3
-rw-r--r--examples/boot/application/nrf/Cargo.toml5
-rw-r--r--examples/boot/application/nrf/src/bin/a.rs5
-rw-r--r--examples/boot/application/nrf/src/bin/b.rs7
-rw-r--r--examples/boot/application/stm32f3/Cargo.toml5
-rw-r--r--examples/boot/application/stm32f3/src/bin/a.rs5
-rw-r--r--examples/boot/application/stm32f3/src/bin/b.rs8
-rw-r--r--examples/boot/application/stm32f7/Cargo.toml5
-rw-r--r--examples/boot/application/stm32f7/src/bin/a.rs5
-rw-r--r--examples/boot/application/stm32f7/src/bin/b.rs8
-rw-r--r--examples/boot/application/stm32h7/Cargo.toml5
-rw-r--r--examples/boot/application/stm32h7/src/bin/a.rs5
-rw-r--r--examples/boot/application/stm32h7/src/bin/b.rs8
-rw-r--r--examples/boot/application/stm32l0/Cargo.toml5
-rw-r--r--examples/boot/application/stm32l0/src/bin/a.rs7
-rw-r--r--examples/boot/application/stm32l0/src/bin/b.rs8
-rw-r--r--examples/boot/application/stm32l1/Cargo.toml5
-rw-r--r--examples/boot/application/stm32l1/src/bin/a.rs7
-rw-r--r--examples/boot/application/stm32l1/src/bin/b.rs8
-rw-r--r--examples/boot/application/stm32l4/Cargo.toml5
-rw-r--r--examples/boot/application/stm32l4/src/bin/a.rs5
-rw-r--r--examples/boot/application/stm32l4/src/bin/b.rs8
-rw-r--r--examples/boot/application/stm32wl/Cargo.toml5
-rw-r--r--examples/boot/application/stm32wl/src/bin/a.rs5
-rw-r--r--examples/boot/application/stm32wl/src/bin/b.rs8
-rw-r--r--examples/boot/bootloader/nrf/Cargo.toml2
-rw-r--r--examples/boot/bootloader/stm32/Cargo.toml2
-rw-r--r--examples/nrf-rtos-trace/Cargo.toml22
-rw-r--r--examples/nrf-rtos-trace/src/bin/rtos_trace.rs8
-rw-r--r--examples/nrf/Cargo.toml5
-rw-r--r--examples/nrf/src/bin/awaitable_timer.rs7
-rw-r--r--examples/nrf/src/bin/blinky.rs8
-rw-r--r--examples/nrf/src/bin/buffered_uart.rs7
-rw-r--r--examples/nrf/src/bin/channel.rs8
-rw-r--r--examples/nrf/src/bin/channel_sender_receiver.rs8
-rw-r--r--examples/nrf/src/bin/executor_fairness_test.rs8
-rw-r--r--examples/nrf/src/bin/gpiote_channel.rs6
-rw-r--r--examples/nrf/src/bin/gpiote_port.rs6
-rw-r--r--examples/nrf/src/bin/multiprio.rs2
-rw-r--r--examples/nrf/src/bin/mutex.rs8
-rw-r--r--examples/nrf/src/bin/nvmc.rs8
-rw-r--r--examples/nrf/src/bin/ppi.rs6
-rw-r--r--examples/nrf/src/bin/pubsub.rs7
-rw-r--r--examples/nrf/src/bin/pwm.rs8
-rw-r--r--examples/nrf/src/bin/pwm_double_sequence.rs8
-rw-r--r--examples/nrf/src/bin/pwm_sequence.rs8
-rw-r--r--examples/nrf/src/bin/pwm_sequence_ppi.rs6
-rw-r--r--examples/nrf/src/bin/pwm_sequence_ws2812b.rs8
-rw-r--r--examples/nrf/src/bin/pwm_servo.rs8
-rw-r--r--examples/nrf/src/bin/qdec.rs7
-rw-r--r--examples/nrf/src/bin/qspi.rs7
-rw-r--r--examples/nrf/src/bin/qspi_lowpower.rs9
-rw-r--r--examples/nrf/src/bin/raw_spawn.rs6
-rw-r--r--examples/nrf/src/bin/rng.rs7
-rw-r--r--examples/nrf/src/bin/saadc.rs9
-rw-r--r--examples/nrf/src/bin/saadc_continuous.rs11
-rw-r--r--examples/nrf/src/bin/self_spawn.rs8
-rw-r--r--examples/nrf/src/bin/self_spawn_current_executor.rs8
-rw-r--r--examples/nrf/src/bin/spim.rs7
-rw-r--r--examples/nrf/src/bin/temp.rs9
-rw-r--r--examples/nrf/src/bin/timer.rs8
-rw-r--r--examples/nrf/src/bin/twim.rs7
-rw-r--r--examples/nrf/src/bin/twim_lowpower.rs9
-rw-r--r--examples/nrf/src/bin/uart.rs7
-rw-r--r--examples/nrf/src/bin/uart_idle.rs7
-rw-r--r--examples/nrf/src/bin/uart_split.rs7
-rw-r--r--examples/nrf/src/bin/usb_ethernet.rs7
-rw-r--r--examples/nrf/src/bin/usb_hid_keyboard.rs7
-rw-r--r--examples/nrf/src/bin/usb_hid_mouse.rs9
-rw-r--r--examples/nrf/src/bin/usb_serial.rs7
-rw-r--r--examples/nrf/src/bin/usb_serial_multitask.rs7
-rw-r--r--examples/nrf/src/bin/wdt.rs6
-rw-r--r--examples/rp/Cargo.toml6
-rw-r--r--examples/rp/src/bin/blinky.rs9
-rw-r--r--examples/rp/src/bin/button.rs6
-rw-r--r--examples/rp/src/bin/gpio_async.rs9
-rw-r--r--examples/rp/src/bin/spi.rs7
-rw-r--r--examples/rp/src/bin/spi_display.rs9
-rw-r--r--examples/rp/src/bin/uart.rs13
-rw-r--r--examples/std/Cargo.toml6
-rw-r--r--examples/std/src/bin/net.rs2
-rw-r--r--examples/std/src/bin/net_udp.rs109
-rw-r--r--examples/std/src/bin/serial.rs2
-rw-r--r--examples/std/src/bin/tick.rs4
-rw-r--r--examples/stm32f0/Cargo.toml5
-rw-r--r--examples/stm32f0/src/bin/hello.rs8
-rw-r--r--examples/stm32f1/Cargo.toml5
-rw-r--r--examples/stm32f1/src/bin/adc.rs8
-rw-r--r--examples/stm32f1/src/bin/blinky.rs8
-rw-r--r--examples/stm32f1/src/bin/hello.rs14
-rw-r--r--examples/stm32f1/src/bin/usb_serial.rs14
-rw-r--r--examples/stm32f2/Cargo.toml5
-rw-r--r--examples/stm32f2/src/bin/blinky.rs8
-rw-r--r--examples/stm32f2/src/bin/pll.rs18
-rw-r--r--examples/stm32f3/Cargo.toml5
-rw-r--r--examples/stm32f3/src/bin/blinky.rs8
-rw-r--r--examples/stm32f3/src/bin/button_events.rs8
-rw-r--r--examples/stm32f3/src/bin/button_exti.rs6
-rw-r--r--examples/stm32f3/src/bin/flash.rs6
-rw-r--r--examples/stm32f3/src/bin/hello.rs14
-rw-r--r--examples/stm32f3/src/bin/multiprio.rs2
-rw-r--r--examples/stm32f3/src/bin/spi_dma.rs6
-rw-r--r--examples/stm32f3/src/bin/usart_dma.rs6
-rw-r--r--examples/stm32f3/src/bin/usb_serial.rs16
-rw-r--r--examples/stm32f4/Cargo.toml5
-rw-r--r--examples/stm32f4/src/bin/adc.rs8
-rw-r--r--examples/stm32f4/src/bin/blinky.rs8
-rw-r--r--examples/stm32f4/src/bin/button_exti.rs6
-rw-r--r--examples/stm32f4/src/bin/dac.rs6
-rw-r--r--examples/stm32f4/src/bin/flash.rs6
-rw-r--r--examples/stm32f4/src/bin/hello.rs14
-rw-r--r--examples/stm32f4/src/bin/multiprio.rs2
-rw-r--r--examples/stm32f4/src/bin/pwm.rs8
-rw-r--r--examples/stm32f4/src/bin/sdmmc.rs13
-rw-r--r--examples/stm32f4/src/bin/spi_dma.rs6
-rw-r--r--examples/stm32f4/src/bin/usart_buffered.rs7
-rw-r--r--examples/stm32f4/src/bin/usart_dma.rs6
-rw-r--r--examples/stm32f4/src/bin/wdt.rs8
-rw-r--r--examples/stm32f7/Cargo.toml7
-rw-r--r--examples/stm32f7/src/bin/adc.rs8
-rw-r--r--examples/stm32f7/src/bin/blinky.rs8
-rw-r--r--examples/stm32f7/src/bin/button_exti.rs6
-rw-r--r--examples/stm32f7/src/bin/eth.rs14
-rw-r--r--examples/stm32f7/src/bin/flash.rs8
-rw-r--r--examples/stm32f7/src/bin/hello.rs14
-rw-r--r--examples/stm32f7/src/bin/sdmmc.rs12
-rw-r--r--examples/stm32f7/src/bin/usart_dma.rs6
-rw-r--r--examples/stm32g0/Cargo.toml5
-rw-r--r--examples/stm32g0/src/bin/blinky.rs8
-rw-r--r--examples/stm32g0/src/bin/button_exti.rs6
-rw-r--r--examples/stm32g4/Cargo.toml5
-rw-r--r--examples/stm32g4/src/bin/blinky.rs8
-rw-r--r--examples/stm32g4/src/bin/button_exti.rs6
-rw-r--r--examples/stm32g4/src/bin/pwm.rs8
-rw-r--r--examples/stm32h7/Cargo.toml10
-rw-r--r--examples/stm32h7/src/bin/adc.rs14
-rw-r--r--examples/stm32h7/src/bin/blinky.rs8
-rw-r--r--examples/stm32h7/src/bin/button_exti.rs6
-rw-r--r--examples/stm32h7/src/bin/camera.rs41
-rw-r--r--examples/stm32h7/src/bin/dac.rs14
-rw-r--r--examples/stm32h7/src/bin/eth.rs15
-rw-r--r--examples/stm32h7/src/bin/eth_client.rs122
-rw-r--r--examples/stm32h7/src/bin/flash.rs8
-rw-r--r--examples/stm32h7/src/bin/fmc.rs14
-rw-r--r--examples/stm32h7/src/bin/low_level_timer_api.rs14
-rw-r--r--examples/stm32h7/src/bin/mco.rs8
-rw-r--r--examples/stm32h7/src/bin/pwm.rs15
-rw-r--r--examples/stm32h7/src/bin/rng.rs6
-rw-r--r--examples/stm32h7/src/bin/sdmmc.rs13
-rw-r--r--examples/stm32h7/src/bin/signal.rs8
-rw-r--r--examples/stm32h7/src/bin/spi.rs16
-rw-r--r--examples/stm32h7/src/bin/spi_dma.rs16
-rw-r--r--examples/stm32h7/src/bin/usart.rs2
-rw-r--r--examples/stm32h7/src/bin/usart_dma.rs2
-rw-r--r--examples/stm32h7/src/bin/usart_split.rs6
-rw-r--r--examples/stm32l0/Cargo.toml5
-rw-r--r--examples/stm32l0/src/bin/blinky.rs8
-rw-r--r--examples/stm32l0/src/bin/button.rs6
-rw-r--r--examples/stm32l0/src/bin/button_exti.rs14
-rw-r--r--examples/stm32l0/src/bin/flash.rs6
-rw-r--r--examples/stm32l0/src/bin/lorawan.rs11
-rw-r--r--examples/stm32l0/src/bin/raw_spawn.rs6
-rw-r--r--examples/stm32l0/src/bin/spi.rs6
-rw-r--r--examples/stm32l0/src/bin/usart_dma.rs6
-rw-r--r--examples/stm32l0/src/bin/usart_irq.rs7
-rw-r--r--examples/stm32l1/Cargo.toml5
-rw-r--r--examples/stm32l1/src/bin/blinky.rs8
-rw-r--r--examples/stm32l1/src/bin/flash.rs6
-rw-r--r--examples/stm32l1/src/bin/spi.rs6
-rw-r--r--examples/stm32l4/Cargo.toml5
-rw-r--r--examples/stm32l4/src/bin/adc.rs2
-rw-r--r--examples/stm32l4/src/bin/blinky.rs8
-rw-r--r--examples/stm32l4/src/bin/button_exti.rs6
-rw-r--r--examples/stm32l4/src/bin/i2c.rs18
-rw-r--r--examples/stm32l4/src/bin/i2c_blocking_async.rs18
-rw-r--r--examples/stm32l4/src/bin/i2c_dma.rs18
-rw-r--r--examples/stm32l4/src/bin/rng.rs12
-rw-r--r--examples/stm32l4/src/bin/spi_blocking_async.rs6
-rw-r--r--examples/stm32l4/src/bin/spi_dma.rs6
-rw-r--r--examples/stm32l4/src/bin/usart_dma.rs6
-rw-r--r--examples/stm32l5/Cargo.toml5
-rw-r--r--examples/stm32l5/src/bin/button_exti.rs6
-rw-r--r--examples/stm32l5/src/bin/rng.rs12
-rw-r--r--examples/stm32l5/src/bin/usb_ethernet.rs15
-rw-r--r--examples/stm32l5/src/bin/usb_hid_mouse.rs15
-rw-r--r--examples/stm32l5/src/bin/usb_serial.rs15
-rw-r--r--examples/stm32u5/Cargo.toml5
-rw-r--r--examples/stm32u5/src/bin/blinky.rs8
-rw-r--r--examples/stm32wb/Cargo.toml5
-rw-r--r--examples/stm32wb/src/bin/blinky.rs8
-rw-r--r--examples/stm32wb/src/bin/button_exti.rs6
-rw-r--r--examples/stm32wl/Cargo.toml5
-rw-r--r--examples/stm32wl/src/bin/blinky.rs8
-rw-r--r--examples/stm32wl/src/bin/button_exti.rs6
-rw-r--r--examples/stm32wl/src/bin/flash.rs6
-rw-r--r--examples/stm32wl/src/bin/lorawan.rs11
-rw-r--r--examples/stm32wl/src/bin/subghz.rs11
-rw-r--r--examples/wasm/Cargo.toml5
-rw-r--r--examples/wasm/src/lib.rs4
-rw-r--r--rust-toolchain.toml2
-rw-r--r--stm32-metapac/Cargo.toml2
-rw-r--r--tests/rp/Cargo.toml5
-rw-r--r--tests/rp/src/bin/gpio.rs6
-rw-r--r--tests/rp/src/bin/gpio_async.rs8
-rw-r--r--tests/stm32/Cargo.toml5
-rw-r--r--tests/stm32/src/bin/gpio.rs8
-rw-r--r--tests/stm32/src/bin/spi.rs8
-rw-r--r--tests/stm32/src/bin/spi_dma.rs8
-rw-r--r--tests/stm32/src/bin/timer.rs10
-rw-r--r--tests/stm32/src/bin/usart.rs8
-rw-r--r--tests/stm32/src/bin/usart_dma.rs8
315 files changed, 2534 insertions, 1345 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 1ac3fc513..d6ce75c99 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,9 +1,7 @@
1{ 1{
2 "editor.formatOnSave": true, 2 "editor.formatOnSave": true,
3 "rust-analyzer.checkOnSave.allFeatures": false,
4 "rust-analyzer.checkOnSave.allTargets": false, 3 "rust-analyzer.checkOnSave.allTargets": false,
5 "rust-analyzer.checkOnSave.noDefaultFeatures": true, 4 "rust-analyzer.checkOnSave.noDefaultFeatures": true,
6 "rust-analyzer.cargo.allFeatures": false,
7 "rust-analyzer.cargo.noDefaultFeatures": true, 5 "rust-analyzer.cargo.noDefaultFeatures": true,
8 "rust-analyzer.procMacro.enable": true, 6 "rust-analyzer.procMacro.enable": true,
9 "rust-analyzer.cargo.target": "thumbv7em-none-eabi", 7 "rust-analyzer.cargo.target": "thumbv7em-none-eabi",
diff --git a/README.md b/README.md
index 423740674..4dbbb5f51 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ Rust's <a href="https://rust-lang.github.io/async-book/">async/await</a> allows
16 - <a href="https://docs.embassy.dev/embassy-nrf/">embassy-nrf</a>, for the Nordic Semiconductor nRF52, nRF53, nRF91 series. 16 - <a href="https://docs.embassy.dev/embassy-nrf/">embassy-nrf</a>, for the Nordic Semiconductor nRF52, nRF53, nRF91 series.
17 17
18- **Time that Just Works** - 18- **Time that Just Works** -
19No more messing with hardware timers. <a href="https://docs.embassy.dev/embassy/git/thumbv7em-none-eabihf/time/index.html">embassy_executor::time</a> provides Instant, Duration and Timer types that are globally available and never overflow. 19No more messing with hardware timers. <a href="https://docs.embassy.dev/embassy-time">embassy_time</a> provides Instant, Duration and Timer types that are globally available and never overflow.
20 20
21- **Real-time ready** - 21- **Real-time ready** -
22Tasks on the same async executor run cooperatively, but you can create multiple executors with different priorities, so that higher priority tasks preempt lower priority ones. See the <a href="https://github.com/embassy-rs/embassy/blob/master/examples/nrf/src/bin/multiprio.rs">example</a>. 22Tasks on the same async executor run cooperatively, but you can create multiple executors with different priorities, so that higher priority tasks preempt lower priority ones. See the <a href="https://github.com/embassy-rs/embassy/blob/master/examples/nrf/src/bin/multiprio.rs">example</a>.
@@ -44,8 +44,8 @@ The <a href="https://github.com/embassy-rs/nrf-softdevice">nrf-softdevice</a> cr
44 44
45```rust,ignore 45```rust,ignore
46use defmt::info; 46use defmt::info;
47use embassy_executor::executor::Spawner; 47use embassy_executor::Spawner;
48use embassy_executor::time::{Duration, Timer}; 48use embassy_time::{Duration, Timer};
49use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pin, Pull}; 49use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pin, Pull};
50use embassy_nrf::Peripherals; 50use embassy_nrf::Peripherals;
51 51
@@ -65,7 +65,9 @@ async fn blink(pin: AnyPin) {
65 65
66// Main is itself an async task as well. 66// Main is itself an async task as well.
67#[embassy_executor::main] 67#[embassy_executor::main]
68async fn main(spawner: Spawner, p: Peripherals) { 68async fn main(spawner: Spawner) {
69 let p = embassy_nrf::init(Default::default());
70
69 // Spawned tasks run in the background, concurrently. 71 // Spawned tasks run in the background, concurrently.
70 spawner.spawn(blink(p.P0_13.degrade())).unwrap(); 72 spawner.spawn(blink(p.P0_13.degrade())).unwrap();
71 73
diff --git a/ci.sh b/ci.sh
index 6ec2410f7..77a8a7e27 100755
--- a/ci.sh
+++ b/ci.sh
@@ -54,25 +54,25 @@ cargo batch \
54 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,unstable-traits,log \ 54 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,unstable-traits,log \
55 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,unstable-traits \ 55 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,unstable-traits \
56 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly \ 56 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly \
57 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f410tb,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 57 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f410tb,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
58 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f411ce,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 58 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f411ce,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
59 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f429zi,log,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 59 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f429zi,log,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
60 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 60 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
61 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h7b3ai,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 61 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h7b3ai,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
62 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l476vg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 62 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l476vg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
63 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wb15cc,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 63 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wb15cc,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
64 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l072cz,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 64 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l072cz,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
65 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l041f6,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 65 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l041f6,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
66 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32l151cb-a,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 66 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32l151cb-a,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
67 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f398ve,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 67 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f398ve,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
68 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32g0c1ve,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 68 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32g0c1ve,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
69 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f217zg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 69 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f217zg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
70 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features nightly,stm32l552ze,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 70 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features nightly,stm32l552ze,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
71 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32wl54jc-cm0p,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 71 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32wl54jc-cm0p,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
72 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wle5ub,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 72 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wle5ub,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
73 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f107vc,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 73 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f107vc,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
74 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f103re,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 74 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f103re,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
75 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f100c4,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 75 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f100c4,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
76 --- build --release --manifest-path embassy-boot/nrf/Cargo.toml --target thumbv7em-none-eabi --features embassy-nrf/nrf52840 \ 76 --- build --release --manifest-path embassy-boot/nrf/Cargo.toml --target thumbv7em-none-eabi --features embassy-nrf/nrf52840 \
77 --- build --release --manifest-path embassy-boot/stm32/Cargo.toml --target thumbv7em-none-eabi --features embassy-stm32/stm32wl55jc-cm4 \ 77 --- build --release --manifest-path embassy-boot/stm32/Cargo.toml --target thumbv7em-none-eabi --features embassy-stm32/stm32wl55jc-cm4 \
78 --- build --release --manifest-path docs/modules/ROOT/examples/basic/Cargo.toml --target thumbv7em-none-eabi \ 78 --- build --release --manifest-path docs/modules/ROOT/examples/basic/Cargo.toml --target thumbv7em-none-eabi \
diff --git a/ci_stable.sh b/ci_stable.sh
index 7521827d8..d388cfee3 100755
--- a/ci_stable.sh
+++ b/ci_stable.sh
@@ -30,38 +30,38 @@ cargo batch \
30 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features unstable-traits,defmt \ 30 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features unstable-traits,defmt \
31 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features unstable-traits,log \ 31 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features unstable-traits,log \
32 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi \ 32 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi \
33 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g473cc,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 33 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g473cc,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
34 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g491re,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 34 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g491re,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
35 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 35 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
36 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 36 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
37 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55uc-cm4,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 37 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55uc-cm4,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
38 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l4r9zi,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 38 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l4r9zi,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
39 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f303vc,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 39 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f303vc,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
40 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,embassy-executor/time-tick-32768hz \ 40 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,embassy-time?/tick-32768hz \
41 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 41 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
42 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,embassy-executor/time-tick-32768hz \ 42 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,embassy-time?/tick-32768hz \
43 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 43 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
44 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,embassy-executor/time-tick-32768hz \ 44 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,embassy-time?/tick-32768hz \
45 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 45 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
46 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,embassy-executor/time-tick-32768hz \ 46 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,embassy-time?/tick-32768hz \
47 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 47 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
48 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,embassy-executor/time-tick-32768hz \ 48 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,embassy-time?/tick-32768hz \
49 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 49 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
50 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,embassy-executor/time-tick-32768hz \ 50 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,embassy-time?/tick-32768hz \
51 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 51 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
52 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ 52 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \
53 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 53 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
54 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,embassy-executor/time-tick-32768hz \ 54 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,embassy-time?/tick-32768hz \
55 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 55 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
56 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ 56 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \
57 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 57 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
58 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ 58 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \
59 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 59 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
60 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ 60 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \
61 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 61 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
62 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ 62 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \
63 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 63 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
64 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ 64 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \
65 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ 65 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \
66 --- build --release --manifest-path examples/nrf/Cargo.toml --target thumbv7em-none-eabi --no-default-features --out-dir out/examples/nrf --bin raw_spawn \ 66 --- build --release --manifest-path examples/nrf/Cargo.toml --target thumbv7em-none-eabi --no-default-features --out-dir out/examples/nrf --bin raw_spawn \
67 --- build --release --manifest-path examples/stm32l0/Cargo.toml --target thumbv6m-none-eabi --no-default-features --out-dir out/examples/stm32l0 --bin raw_spawn \ 67 --- build --release --manifest-path examples/stm32l0/Cargo.toml --target thumbv6m-none-eabi --no-default-features --out-dir out/examples/stm32l0 --bin raw_spawn \
diff --git a/docs/antora.yml b/docs/antora.yml
index 807c97c3f..9a00fa820 100644
--- a/docs/antora.yml
+++ b/docs/antora.yml
@@ -1,4 +1,4 @@
1name: embassy 1name: ROOT
2title: Embassy 2title: Embassy
3version: dev 3version: dev
4nav: 4nav:
diff --git a/docs/modules/ROOT/examples/basic/Cargo.toml b/docs/modules/ROOT/examples/basic/Cargo.toml
index 59e1a437a..ae124a871 100644
--- a/docs/modules/ROOT/examples/basic/Cargo.toml
+++ b/docs/modules/ROOT/examples/basic/Cargo.toml
@@ -6,6 +6,7 @@ version = "0.1.0"
6 6
7[dependencies] 7[dependencies]
8embassy-executor = { version = "0.1.0", path = "../../../../../embassy-executor", features = ["defmt", "nightly"] } 8embassy-executor = { version = "0.1.0", path = "../../../../../embassy-executor", features = ["defmt", "nightly"] }
9embassy-time = { version = "0.1.0", path = "../../../../../embassy-time", features = ["defmt", "nightly"] }
9embassy-nrf = { version = "0.1.0", path = "../../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "nightly"] } 10embassy-nrf = { version = "0.1.0", path = "../../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "nightly"] }
10 11
11defmt = "0.3" 12defmt = "0.3"
diff --git a/docs/modules/ROOT/examples/basic/src/main.rs b/docs/modules/ROOT/examples/basic/src/main.rs
index cec39fd91..04170db55 100644
--- a/docs/modules/ROOT/examples/basic/src/main.rs
+++ b/docs/modules/ROOT/examples/basic/src/main.rs
@@ -3,11 +3,10 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_nrf::gpio::{Level, Output, OutputDrive}; 7use embassy_nrf::gpio::{Level, Output, OutputDrive};
9use embassy_nrf::peripherals::P0_13; 8use embassy_nrf::peripherals::P0_13;
10use embassy_nrf::Peripherals; 9use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _}; // global logger 10use {defmt_rtt as _, panic_probe as _}; // global logger
12 11
13#[embassy_executor::task] 12#[embassy_executor::task]
@@ -21,7 +20,9 @@ async fn blinker(mut led: Output<'static, P0_13>, interval: Duration) {
21} 20}
22 21
23#[embassy_executor::main] 22#[embassy_executor::main]
24async fn main(spawner: Spawner, p: Peripherals) { 23async fn main(spawner: Spawner) {
24 let p = embassy_nrf::init(Default::default());
25
25 let led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); 26 let led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
26 unwrap!(spawner.spawn(blinker(led, Duration::from_millis(300)))); 27 unwrap!(spawner.spawn(blinker(led, Duration::from_millis(300))));
27} 28}
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs
index b944a7994..8df632240 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs
+++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs
@@ -2,14 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use embassy_executor::executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_stm32::exti::ExtiInput; 6use embassy_stm32::exti::ExtiInput;
7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
8use embassy_stm32::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::main] 10#[embassy_executor::main]
12async fn main(_s: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner) {
12 let p = embassy_stm32::init(Default::default());
13 let mut led = Output::new(p.PB14, Level::Low, Speed::VeryHigh); 13 let mut led = Output::new(p.PB14, Level::Low, Speed::VeryHigh);
14 let mut button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13); 14 let mut button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13);
15 15
diff --git a/docs/modules/ROOT/images/bootloader_flash.png b/docs/modules/ROOT/images/bootloader_flash.png
new file mode 100644
index 000000000..635783b05
--- /dev/null
+++ b/docs/modules/ROOT/images/bootloader_flash.png
Binary files differ
diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
index a45da1958..86f2996f1 100644
--- a/docs/modules/ROOT/nav.adoc
+++ b/docs/modules/ROOT/nav.adoc
@@ -1,10 +1,10 @@
1* xref:runtime.adoc[Runtime]
2* xref:traits.adoc[APIs]
3* xref:hal.adoc[Hardware Abstraction Layer]
4** xref:nrf.adoc[nRF]
5** xref:stm32.adoc[STM32]
6* xref:bootloader.adoc[Bootloader]
7* xref:getting_started.adoc[Getting started] 1* xref:getting_started.adoc[Getting started]
8** xref:basic_application.adoc[Basic application] 2** xref:basic_application.adoc[Basic application]
9** xref:layer_by_layer.adoc[Layer by Layer] 3** xref:layer_by_layer.adoc[Layer by Layer]
4* xref:runtime.adoc[Executor]
5* xref:hal.adoc[HAL]
6** xref:nrf.adoc[nRF]
7** xref:stm32.adoc[STM32]
8* xref:bootloader.adoc[Bootloader]
9
10* xref:examples.adoc[Examples] 10* xref:examples.adoc[Examples]
diff --git a/docs/modules/ROOT/pages/basic_application.adoc b/docs/modules/ROOT/pages/basic_application.adoc
index a8875aa93..4dc4a6359 100644
--- a/docs/modules/ROOT/pages/basic_application.adoc
+++ b/docs/modules/ROOT/pages/basic_application.adoc
@@ -21,7 +21,7 @@ Then, what follows are some declarations on how to deal with panics and faults.
21 21
22[source,rust] 22[source,rust]
23---- 23----
24include::example$basic/src/main.rs[lines="5..6"] 24include::example$basic/src/main.rs[lines="11..12"]
25---- 25----
26 26
27=== Task declaration 27=== Task declaration
@@ -30,7 +30,7 @@ After a bit of import declaration, the tasks run by the application should be de
30 30
31[source,rust] 31[source,rust]
32---- 32----
33include::example$basic/src/main.rs[lines="18..27"] 33include::example$basic/src/main.rs[lines="13..22"]
34---- 34----
35 35
36An embassy task must be declared `async`, and may NOT take generic arguments. In this case, we are handed the LED that should be blinked and the interval of the blinking. 36An embassy task must be declared `async`, and may NOT take generic arguments. In this case, we are handed the LED that should be blinked and the interval of the blinking.
@@ -39,32 +39,32 @@ NOTE: Notice that there is no busy waiting going on in this task. It is using th
39 39
40=== Main 40=== Main
41 41
42The main entry point of an Embassy application is defined using the `#[embassy::main]` macro. The entry point is also required to take a `Spawner` and a `Peripherals` argument. 42The main entry point of an Embassy application is defined using the `#[embassy_executor::main]` macro. The entry point is also required to take a `Spawner` and a `Peripherals` argument.
43 43
44The `Spawner` is the way the main application spawns other tasks. The `Peripherals` type holds all peripherals that the application may use. In this case, we want to configure one of the pins as a GPIO output driving the LED: 44The `Spawner` is the way the main application spawns other tasks. The `Peripherals` type comes from the HAL and holds all peripherals that the application may use. In this case, we want to configure one of the pins as a GPIO output driving the LED:
45 45
46[source,rust] 46[source,rust]
47---- 47----
48include::example$basic/src/main.rs[lines="28..-1"] 48include::example$basic/src/main.rs[lines="23..-1"]
49---- 49----
50 50
51`#[embassy::main]` takes an optional `config` paramter specifying a function that returns an instance of HAL's `Config` struct. For example: 51`#[embassy_executor::main]` takes an optional `config` parameter specifying a function that returns an instance of HAL's `Config` struct. For example:
52 52
53```rust 53```rust
54fn embassy_config() -> embassy_nrf::config::Config { 54fn embassy_config() -> embassy_nrf::config::Config {
55 embassy_nrf::config::Config::default() 55 embassy_nrf::config::Config::default()
56} 56}
57 57
58#[embassy::main(config = "embassy_config()")] 58#[embassy_executor::main(config = "embassy_config()")]
59async fn main(_spawner: embassy::executor::Spawner, p: embassy_nrf::Peripherals) { 59async fn main(_spawner: Spawner, p: embassy_nrf::Peripherals) {
60 // ... 60 // ...
61} 61}
62``` 62```
63 63
64What happens when the `blinker` task have been spawned and main returns? Well, the main entry point is actually just like any other task, except that you can only have one and it takes some specific type arguments. The magic lies within the `#[embassy::main]` macro. The macro does the following: 64What happens when the `blinker` task have been spawned and main returns? Well, the main entry point is actually just like any other task, except that you can only have one and it takes some specific type arguments. The magic lies within the `#[embassy::main]` macro. The macro does the following:
65 65
66. Creates an Embassy Executor instance 66. Creates an Embassy Executor
67. Initializes the microcontroller to get the `Peripherals` 67. Initializes the microcontroller HAL to get the `Peripherals`
68. Defines a main task for the entry point 68. Defines a main task for the entry point
69. Runs the executor spawning the main task 69. Runs the executor spawning the main task
70 70
diff --git a/docs/modules/ROOT/pages/bootloader.adoc b/docs/modules/ROOT/pages/bootloader.adoc
index 3df2daf51..ae92e9d5d 100644
--- a/docs/modules/ROOT/pages/bootloader.adoc
+++ b/docs/modules/ROOT/pages/bootloader.adoc
@@ -20,7 +20,10 @@ In general, the bootloader works on any platform that implements the `embedded-s
20 20
21== Design 21== Design
22 22
23The bootloader divides the storage into 4 main partitions, configured by a linker script: 23image::bootloader_flash.png[Bootloader flash layout]
24
25The bootloader divides the storage into 4 main partitions, configurable when creating the bootloader
26instance or via linker scripts:
24 27
25* BOOTLOADER - Where the bootloader is placed. The bootloader itself consumes about 8kB of flash. 28* BOOTLOADER - Where the bootloader is placed. The bootloader itself consumes about 8kB of flash.
26* ACTIVE - Where the main application is placed. The bootloader will attempt to load the application at the start of this partition. This partition is only written to by the bootloader. 29* ACTIVE - Where the main application is placed. The bootloader will attempt to load the application at the start of this partition. This partition is only written to by the bootloader.
diff --git a/docs/modules/ROOT/pages/getting_started.adoc b/docs/modules/ROOT/pages/getting_started.adoc
index 23102b3b5..f3492a3d0 100644
--- a/docs/modules/ROOT/pages/getting_started.adoc
+++ b/docs/modules/ROOT/pages/getting_started.adoc
@@ -46,15 +46,13 @@ You can run an example by opening a terminal and entering the following commands
46[source, bash] 46[source, bash]
47---- 47----
48cd examples/nrf 48cd examples/nrf
49DEFMT_LOG=info cargo run --bin blinky --release 49cargo run --bin blinky --release
50---- 50----
51 51
52IMPORTANT: The DEFMT_LOG environment variable controls the example log verbosity. If you do not specify it, you will not see anything logged to the console.
53
54== Whats next? 52== Whats next?
55 53
56Congratulations, you have your first Embassy application running! Here are some alternatives on where to go from here: 54Congratulations, you have your first Embassy application running! Here are some alternatives on where to go from here:
57 55
58* Read more about the xref:runtime.adoc[runtime]. 56* Read more about the xref:runtime.adoc[executor].
59* Read more about the xref:hal.adoc[HAL]. 57* Read more about the xref:hal.adoc[HAL].
60* Start xref:basic_application.adoc[writing your application]. 58* Start xref:basic_application.adoc[writing your application].
diff --git a/docs/modules/ROOT/pages/hal.adoc b/docs/modules/ROOT/pages/hal.adoc
index 0b15e2fce..de4ab33be 100644
--- a/docs/modules/ROOT/pages/hal.adoc
+++ b/docs/modules/ROOT/pages/hal.adoc
@@ -1,9 +1,10 @@
1= Hardware Abstraction Layer (HAL) 1= Hardware Abstraction Layer (HAL)
2 2
3Embassy provides HAL's for several microcontroller families: 3Embassy provides HALs for several microcontroller families:
4 4
5* `embassy-nrf` for the nRF microcontrollers from Nordic Semiconductor 5* `embassy-nrf` for the nRF microcontrollers from Nordic Semiconductor
6* `embassy-stm32` for STM32 microcontrollers from ST Microelectronics 6* `embassy-stm32` for STM32 microcontrollers from ST Microelectronics
7* `embassy-rp` for the Raspberry Pi RP2040 microcontrollers 7* `embassy-rp` for the Raspberry Pi RP2040 microcontrollers
8 8
9These HALs implement async/await functionality for most peripherals while also implementing the async traits in Embassy. 9These HALs implement async/await functionality for most peripherals while also implementing the
10async traits in `embedded-hal-async`. You can also use these HALs with another executor.
diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc
index 9a14e465d..0a17c6739 100644
--- a/docs/modules/ROOT/pages/index.adoc
+++ b/docs/modules/ROOT/pages/index.adoc
@@ -15,6 +15,20 @@ In Rust, non-blocking operations can be implemented using async-await. Async-awa
15 15
16== What is Embassy? 16== What is Embassy?
17 17
18Embassy is an executor and a Hardware Access Layer (HAL). The executor is a scheduler that generally executes a fixed number of tasks, allocated at startup, though more can be added later. The HAL is an API that you can use to access peripherals, such as USART, UART, I2C, SPI, CAN, and USB. Embassy provides implementations of both async and blocking APIs where it makes sense. DMA (Direct Memory Access) is an example where async is a good fit, whereas GPIO states are a better fit for a blocking API. 18The Embassy project consists of several crates that you can use together or independently:
19 19
20Embassy may also provide a system timer that you can use for both async and blocking delays. For less than one microsecond, blocking delays should be used because the cost of context-switching is too high and the executor will be unable to provide accurate timing. 20* **Executor** - The link:https://docs.embassy.dev/embassy-executor/[embassy-executor] is an async/await executor that generally executes a fixed number of tasks, allocated at startup, though more can be added later. The HAL is an API that you can use to access peripherals, such as USART, UART, I2C, SPI, CAN, and USB. Embassy provides implementations of both async and blocking APIs where it makes sense. DMA (Direct Memory Access) is an example where async is a good fit, whereas GPIO states are a better fit for a blocking API. The executor may also provide a system timer that you can use for both async and blocking delays. For less than one microsecond, blocking delays should be used because the cost of context-switching is too high and the executor will be unable to provide accurate timing.
21
22* **Hardware Abstraction Layers** - HALs implement safe, idiomatic Rust APIs to use the hardware capabilities, so raw register manipulation is not needed. The Embassy project maintains HALs for select hardware, but you can still use HALs from other projects with Embassy.
23** link:https://docs.embassy.dev/embassy-stm32/[embassy-stm32], for all STM32 microcontroller families.
24** link:https://docs.embassy.dev/embassy-nrf/[embassy-nrf], for the Nordic Semiconductor nRF52, nRF53, nRF91 series.
25
26* **Networking** - The link:https://docs.embassy.dev/embassy-net/[embassy-net] network stack implements extensive networking functionality, including Ethernet, IP, TCP, UDP, ICMP and DHCP. Async drastically simplifies managing timeouts and serving multiple connections concurrently.
27
28* **Bluetooth** - The link:https://github.com/embassy-rs/nrf-softdevice[nrf-softdevice] crate provides Bluetooth Low Energy 4.x and 5.x support for nRF52 microcontrollers.
29
30* **LoRa** - link:https://docs.embassy.dev/embassy-lora/[embassy-lora] supports LoRa networking on STM32WL wireless microcontrollers and Semtech SX127x transceivers.
31
32* **USB** - link:https://docs.embassy.dev/embassy-usb/[embassy-usb] implements a device-side USB stack. Implementations for common classes such as USB serial (CDC ACM) and USB HID are available, and a rich builder API allows building your own.
33
34* **Bootloader and DFU** - link:https://github.com/embassy-rs/embassy/tree/master/embassy-boot[embassy-boot] is a lightweight bootloader supporting firmware application upgrades in a power-fail-safe way, with trial boots and rollbacks.
diff --git a/docs/modules/ROOT/pages/runtime.adoc b/docs/modules/ROOT/pages/runtime.adoc
index 0adaa21a0..a7d6a8d0c 100644
--- a/docs/modules/ROOT/pages/runtime.adoc
+++ b/docs/modules/ROOT/pages/runtime.adoc
@@ -1,6 +1,6 @@
1= Embassy runtime 1= Embassy executor
2 2
3The Embassy runtime is an async/await executor designed for embedded usage along with support functionality for interrupts and timers. 3The Embassy executor is an async/await executor designed for embedded usage along with support functionality for interrupts and timers.
4 4
5== Features 5== Features
6 6
diff --git a/docs/modules/ROOT/pages/traits.adoc b/docs/modules/ROOT/pages/traits.adoc
deleted file mode 100644
index 38b8f2862..000000000
--- a/docs/modules/ROOT/pages/traits.adoc
+++ /dev/null
@@ -1,8 +0,0 @@
1= Embassy Traits
2
3Embassy provides a set of traits and types specifically designed for `async` usage. Many of these futures will be upstreamed to the `embedded-hal` crate at some point in the future, probably when the required GAT (Generic Associated Types) feature is stabilized in Rust.
4
5* `embassy::io`: `AsyncBufRead`, `AsyncWrite`. Traits for byte-stream IO, essentially `no_std` compatible versions of `futures::io`. The primary reason for re-defining these traits is that the `futures::io` variant requires `std::io::Error`, which does not work in the `no_std` environment.
6* `embassy::time`: Time `Driver` trait that is implemented for different platforms. Time in Embassy is represented using the `Duration` and `Instant` types.
7
8These traits are implemented by the platform-specific crates, such as `embassy-nrf` or `embassy-stm32`.
diff --git a/embassy-boot/boot/Cargo.toml b/embassy-boot/boot/Cargo.toml
index abb7bb5c2..9c2e72be5 100644
--- a/embassy-boot/boot/Cargo.toml
+++ b/embassy-boot/boot/Cargo.toml
@@ -4,6 +4,11 @@ name = "embassy-boot"
4version = "0.1.0" 4version = "0.1.0"
5description = "Bootloader using Embassy" 5description = "Bootloader using Embassy"
6 6
7[package.metadata.embassy_docs]
8src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-v$VERSION/embassy-boot/boot/src/"
9src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-boot/boot/src/"
10target = "thumbv7em-none-eabi"
11
7[lib] 12[lib]
8 13
9[dependencies] 14[dependencies]
diff --git a/embassy-boot/nrf/Cargo.toml b/embassy-boot/nrf/Cargo.toml
index 5dc3ce52b..b06e8102c 100644
--- a/embassy-boot/nrf/Cargo.toml
+++ b/embassy-boot/nrf/Cargo.toml
@@ -4,6 +4,12 @@ name = "embassy-boot-nrf"
4version = "0.1.0" 4version = "0.1.0"
5description = "Bootloader lib for nRF chips" 5description = "Bootloader lib for nRF chips"
6 6
7[package.metadata.embassy_docs]
8src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-nrf-v$VERSION/embassy-boot/nrf/src/"
9src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-boot/nrf/src/"
10features = ["embassy-nrf/nrf52840"]
11target = "thumbv7em-none-eabi"
12
7[lib] 13[lib]
8 14
9[dependencies] 15[dependencies]
@@ -12,7 +18,7 @@ defmt = { version = "0.3", optional = true }
12embassy-util = { path = "../../embassy-util" } 18embassy-util = { path = "../../embassy-util" }
13embassy-nrf = { path = "../../embassy-nrf", default-features = false, features = ["nightly"] } 19embassy-nrf = { path = "../../embassy-nrf", default-features = false, features = ["nightly"] }
14embassy-boot = { path = "../boot", default-features = false } 20embassy-boot = { path = "../boot", default-features = false }
15cortex-m = { version = "0.7" } 21cortex-m = { version = "0.7.6" }
16cortex-m-rt = { version = "0.7" } 22cortex-m-rt = { version = "0.7" }
17embedded-storage = "0.3.0" 23embedded-storage = "0.3.0"
18embedded-storage-async = "0.3.0" 24embedded-storage-async = "0.3.0"
diff --git a/embassy-boot/stm32/Cargo.toml b/embassy-boot/stm32/Cargo.toml
index eab8d160a..d8f492531 100644
--- a/embassy-boot/stm32/Cargo.toml
+++ b/embassy-boot/stm32/Cargo.toml
@@ -4,6 +4,12 @@ name = "embassy-boot-stm32"
4version = "0.1.0" 4version = "0.1.0"
5description = "Bootloader lib for STM32 chips" 5description = "Bootloader lib for STM32 chips"
6 6
7[package.metadata.embassy_docs]
8src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-nrf-v$VERSION/embassy-boot/stm32/src/"
9src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-boot/stm32/src/"
10features = ["embassy-stm32/stm32f429zi"]
11target = "thumbv7em-none-eabi"
12
7[lib] 13[lib]
8 14
9[dependencies] 15[dependencies]
@@ -14,7 +20,7 @@ log = { version = "0.4", optional = true }
14embassy-util = { path = "../../embassy-util" } 20embassy-util = { path = "../../embassy-util" }
15embassy-stm32 = { path = "../../embassy-stm32", default-features = false, features = ["nightly"] } 21embassy-stm32 = { path = "../../embassy-stm32", default-features = false, features = ["nightly"] }
16embassy-boot = { path = "../boot", default-features = false } 22embassy-boot = { path = "../boot", default-features = false }
17cortex-m = { version = "0.7" } 23cortex-m = { version = "0.7.6" }
18cortex-m-rt = { version = "0.7" } 24cortex-m-rt = { version = "0.7" }
19embedded-storage = "0.3.0" 25embedded-storage = "0.3.0"
20embedded-storage-async = "0.3.0" 26embedded-storage-async = "0.3.0"
diff --git a/embassy-cortex-m/Cargo.toml b/embassy-cortex-m/Cargo.toml
index 454f34e0b..1f16da31b 100644
--- a/embassy-cortex-m/Cargo.toml
+++ b/embassy-cortex-m/Cargo.toml
@@ -39,8 +39,8 @@ embassy-util = { version = "0.1.0", path = "../embassy-util" }
39embassy-executor = { version = "0.1.0", path = "../embassy-executor"} 39embassy-executor = { version = "0.1.0", path = "../embassy-executor"}
40embassy-macros = { version = "0.1.0", path = "../embassy-macros"} 40embassy-macros = { version = "0.1.0", path = "../embassy-macros"}
41embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common"} 41embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common"}
42atomic-polyfill = "0.1.5" 42atomic-polyfill = "1.0.1"
43critical-section = "0.2.5" 43critical-section = "1.1"
44cfg-if = "1.0.0" 44cfg-if = "1.0.0"
45cortex-m = "0.7.3" 45cortex-m = "0.7.6"
46 46
diff --git a/embassy-cortex-m/src/executor.rs b/embassy-cortex-m/src/executor.rs
index 4a3fa9903..80c452f84 100644
--- a/embassy-cortex-m/src/executor.rs
+++ b/embassy-cortex-m/src/executor.rs
@@ -1,7 +1,7 @@
1//! Executor specific to cortex-m devices. 1//! Executor specific to cortex-m devices.
2use core::marker::PhantomData; 2use core::marker::PhantomData;
3 3
4pub use embassy_executor::executor::*; 4pub use embassy_executor::*;
5 5
6use crate::interrupt::{Interrupt, InterruptExt}; 6use crate::interrupt::{Interrupt, InterruptExt};
7 7
@@ -60,11 +60,11 @@ impl<I: Interrupt> InterruptExecutor<I> {
60 /// The executor keeps running in the background through the interrupt. 60 /// The executor keeps running in the background through the interrupt.
61 /// 61 ///
62 /// This returns a [`SendSpawner`] you can use to spawn tasks on it. A [`SendSpawner`] 62 /// This returns a [`SendSpawner`] you can use to spawn tasks on it. A [`SendSpawner`]
63 /// is returned instead of a [`Spawner`](embassy_executor::executor::Spawner) because the executor effectively runs in a 63 /// is returned instead of a [`Spawner`](embassy_executor::Spawner) because the executor effectively runs in a
64 /// different "thread" (the interrupt), so spawning tasks on it is effectively 64 /// different "thread" (the interrupt), so spawning tasks on it is effectively
65 /// sending them. 65 /// sending them.
66 /// 66 ///
67 /// To obtain a [`Spawner`](embassy_executor::executor::Spawner) for this executor, use [`Spawner::for_current_executor()`](embassy_executor::executor::Spawner::for_current_executor()) from 67 /// To obtain a [`Spawner`](embassy_executor::Spawner) for this executor, use [`Spawner::for_current_executor()`](embassy_executor::Spawner::for_current_executor()) from
68 /// a task running in it. 68 /// a task running in it.
69 /// 69 ///
70 /// This function requires `&'static mut self`. This means you have to store the 70 /// This function requires `&'static mut self`. This means you have to store the
diff --git a/embassy-cortex-m/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs
index 7358caa46..1df8671b9 100644
--- a/embassy-cortex-m/src/interrupt.rs
+++ b/embassy-cortex-m/src/interrupt.rs
@@ -6,6 +6,13 @@ use cortex_m::peripheral::NVIC;
6use embassy_hal_common::Peripheral; 6use embassy_hal_common::Peripheral;
7pub use embassy_macros::cortex_m_interrupt_take as take; 7pub use embassy_macros::cortex_m_interrupt_take as take;
8 8
9/// Do not use. Used for macros and HALs only. Not covered by semver guarantees.
10#[doc(hidden)]
11pub mod _export {
12 pub use atomic_polyfill as atomic;
13 pub use embassy_macros::{cortex_m_interrupt as interrupt, cortex_m_interrupt_declare as declare};
14}
15
9/// Implementation detail, do not use outside embassy crates. 16/// Implementation detail, do not use outside embassy crates.
10#[doc(hidden)] 17#[doc(hidden)]
11pub struct Handler { 18pub struct Handler {
diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml
index f245783cf..866666871 100644
--- a/embassy-embedded-hal/Cargo.toml
+++ b/embassy-embedded-hal/Cargo.toml
@@ -3,6 +3,13 @@ name = "embassy-embedded-hal"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2021"
5 5
6
7[package.metadata.embassy_docs]
8src_base = "https://github.com/embassy-rs/embassy/blob/embassy-embedded-hal-v$VERSION/embassy-embedded-hal/src/"
9src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-embedded-hal/src/"
10features = ["nightly", "std"]
11target = "thumbv7em-none-eabi"
12
6[features] 13[features]
7std = [] 14std = []
8# Enable nightly-only features 15# Enable nightly-only features
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml
index ca00f2e71..7d5c4a045 100644
--- a/embassy-executor/Cargo.toml
+++ b/embassy-executor/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2021"
7[package.metadata.embassy_docs] 7[package.metadata.embassy_docs]
8src_base = "https://github.com/embassy-rs/embassy/blob/embassy-executor-v$VERSION/embassy-executor/src/" 8src_base = "https://github.com/embassy-rs/embassy/blob/embassy-executor-v$VERSION/embassy-executor/src/"
9src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-executor/src/" 9src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-executor/src/"
10features = ["nightly", "defmt", "unstable-traits", "time", "time-tick-1mhz"] 10features = ["nightly", "defmt", "unstable-traits"]
11flavors = [ 11flavors = [
12 { name = "std", target = "x86_64-unknown-linux-gnu", features = ["std"] }, 12 { name = "std", target = "x86_64-unknown-linux-gnu", features = ["std"] },
13 { name = "wasm", target = "wasm32-unknown-unknown", features = ["wasm"] }, 13 { name = "wasm", target = "wasm32-unknown-unknown", features = ["wasm"] },
@@ -22,33 +22,13 @@ flavors = [
22 22
23[features] 23[features]
24default = [] 24default = []
25std = ["time", "time-tick-1mhz", "embassy-macros/std"] 25std = ["embassy-macros/std"]
26wasm = ["wasm-bindgen", "js-sys", "embassy-macros/wasm", "wasm-timer", "time", "time-tick-1mhz"] 26wasm = ["dep:wasm-bindgen", "dep:js-sys", "embassy-macros/wasm"]
27 27
28# Enable nightly-only features 28# Enable nightly-only features
29nightly = ["embedded-hal-async"] 29nightly = []
30 30
31# Implement embedded-hal 1.0 alpha and embedded-hal-async traits. 31integrated-timers = ["dep:embassy-time"]
32# Implement embedded-hal-async traits if `nightly` is set as well.
33unstable-traits = ["embedded-hal-1"]
34
35# Display a timestamp of the number of seconds since startup next to defmt log messages
36# To use this you must have a time driver provided.
37defmt-timestamp-uptime = ["defmt"]
38
39# Enable `embassy_executor::time` module.
40# NOTE: This feature is only intended to be enabled by crates providing the time driver implementation.
41# Enabling it directly without supplying a time driver will fail to link.
42time = []
43
44# Set the `embassy_executor::time` tick rate.
45# NOTE: This feature is only intended to be enabled by crates providing the time driver implementation.
46# If you're not writing your own driver, check the driver documentation to customize the tick rate.
47# If you're writing a driver and your tick rate is not listed here, please add it and send a PR!
48time-tick-32768hz = ["time"]
49time-tick-1000hz = ["time"]
50time-tick-1mhz = ["time"]
51time-tick-16mhz = ["time"]
52 32
53# Trace interrupt invocations with rtos-trace. 33# Trace interrupt invocations with rtos-trace.
54rtos-trace-interrupt = ["rtos-trace"] 34rtos-trace-interrupt = ["rtos-trace"]
@@ -58,17 +38,13 @@ defmt = { version = "0.3", optional = true }
58log = { version = "0.4.14", optional = true } 38log = { version = "0.4.14", optional = true }
59rtos-trace = { version = "0.1.2", optional = true } 39rtos-trace = { version = "0.1.2", optional = true }
60 40
61embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" }
62embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8", optional = true}
63embedded-hal-async = { version = "0.1.0-alpha.1", optional = true}
64
65futures-util = { version = "0.3.17", default-features = false } 41futures-util = { version = "0.3.17", default-features = false }
66embassy-macros = { version = "0.1.0", path = "../embassy-macros"} 42embassy-macros = { version = "0.1.0", path = "../embassy-macros"}
67atomic-polyfill = "0.1.5" 43embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true}
68critical-section = "0.2.5" 44atomic-polyfill = "1.0.1"
45critical-section = "1.1"
69cfg-if = "1.0.0" 46cfg-if = "1.0.0"
70 47
71# WASM dependencies 48# WASM dependencies
72wasm-bindgen = { version = "0.2.76", features = ["nightly"], optional = true } 49wasm-bindgen = { version = "0.2.76", features = ["nightly"], optional = true }
73js-sys = { version = "0.3", optional = true } 50js-sys = { version = "0.3", optional = true } \ No newline at end of file
74wasm-timer = { version = "0.2.5", optional = true } \ No newline at end of file
diff --git a/embassy-executor/README.md b/embassy-executor/README.md
new file mode 100644
index 000000000..47d0cb8a2
--- /dev/null
+++ b/embassy-executor/README.md
@@ -0,0 +1,11 @@
1# embassy-executor
2
3An async/await executor designed for embedded usage.
4
5- No `alloc`, no heap needed. Task futures are statically allocated.
6- No "fixed capacity" data structures, executor works with 1 or 1000 tasks without needing config/tuning.
7- Integrated timer queue: sleeping is easy, just do `Timer::after(Duration::from_secs(1)).await;`.
8- No busy-loop polling: CPU sleeps when there's no work to do, using interrupts or `WFE/SEV`.
9- Efficient polling: a wake will only poll the woken task, not all of them.
10- Fair: a task can't monopolize CPU time even if it's constantly being woken. All other tasks get a chance to run before a given task gets polled for the second time.
11- Creating multiple executor instances is supported, to run tasks with multiple priority levels. This allows higher-priority tasks to preempt lower-priority tasks.
diff --git a/embassy-executor/src/executor/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs
index d6e758dfb..d6e758dfb 100644
--- a/embassy-executor/src/executor/arch/cortex_m.rs
+++ b/embassy-executor/src/arch/cortex_m.rs
diff --git a/embassy-executor/src/executor/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs
index 7a7d5698c..7a7d5698c 100644
--- a/embassy-executor/src/executor/arch/riscv32.rs
+++ b/embassy-executor/src/arch/riscv32.rs
diff --git a/embassy-executor/src/executor/arch/std.rs b/embassy-executor/src/arch/std.rs
index b93ab8a79..b93ab8a79 100644
--- a/embassy-executor/src/executor/arch/std.rs
+++ b/embassy-executor/src/arch/std.rs
diff --git a/embassy-executor/src/executor/arch/wasm.rs b/embassy-executor/src/arch/wasm.rs
index 9d5aa31ed..9d5aa31ed 100644
--- a/embassy-executor/src/executor/arch/wasm.rs
+++ b/embassy-executor/src/arch/wasm.rs
diff --git a/embassy-executor/src/executor/arch/xtensa.rs b/embassy-executor/src/arch/xtensa.rs
index 20bd7b8a5..20bd7b8a5 100644
--- a/embassy-executor/src/executor/arch/xtensa.rs
+++ b/embassy-executor/src/arch/xtensa.rs
diff --git a/embassy-executor/src/executor/mod.rs b/embassy-executor/src/executor/mod.rs
deleted file mode 100644
index 45d00c568..000000000
--- a/embassy-executor/src/executor/mod.rs
+++ /dev/null
@@ -1,44 +0,0 @@
1//! Async task executor.
2//!
3//! This module provides an async/await executor designed for embedded usage.
4//!
5//! - No `alloc`, no heap needed. Task futures are statically allocated.
6//! - No "fixed capacity" data structures, executor works with 1 or 1000 tasks without needing config/tuning.
7//! - Integrated timer queue: sleeping is easy, just do `Timer::after(Duration::from_secs(1)).await;`.
8//! - No busy-loop polling: CPU sleeps when there's no work to do, using interrupts or `WFE/SEV`.
9//! - Efficient polling: a wake will only poll the woken task, not all of them.
10//! - Fair: a task can't monopolize CPU time even if it's constantly being woken. All other tasks get a chance to run before a given task gets polled for the second time.
11//! - Creating multiple executor instances is supported, to run tasks with multiple priority levels. This allows higher-priority tasks to preempt lower-priority tasks.
12
13cfg_if::cfg_if! {
14 if #[cfg(cortex_m)] {
15 #[path="arch/cortex_m.rs"]
16 mod arch;
17 pub use arch::*;
18 }
19 else if #[cfg(target_arch="riscv32")] {
20 #[path="arch/riscv32.rs"]
21 mod arch;
22 pub use arch::*;
23 }
24 else if #[cfg(all(target_arch="xtensa", feature = "nightly"))] {
25 #[path="arch/xtensa.rs"]
26 mod arch;
27 pub use arch::*;
28 }
29 else if #[cfg(feature="wasm")] {
30 #[path="arch/wasm.rs"]
31 mod arch;
32 pub use arch::*;
33 }
34 else if #[cfg(feature="std")] {
35 #[path="arch/std.rs"]
36 mod arch;
37 pub use arch::*;
38 }
39}
40
41pub mod raw;
42
43mod spawner;
44pub use spawner::*;
diff --git a/embassy-executor/src/fmt.rs b/embassy-executor/src/fmt.rs
index f8bb0a035..066970813 100644
--- a/embassy-executor/src/fmt.rs
+++ b/embassy-executor/src/fmt.rs
@@ -195,9 +195,6 @@ macro_rules! unwrap {
195 } 195 }
196} 196}
197 197
198#[cfg(feature = "defmt-timestamp-uptime")]
199defmt::timestamp! {"{=u64:us}", crate::time::Instant::now().as_micros() }
200
201#[derive(Debug, Copy, Clone, Eq, PartialEq)] 198#[derive(Debug, Copy, Clone, Eq, PartialEq)]
202pub struct NoneError; 199pub struct NoneError;
203 200
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs
index 47c0c1d64..93f2eaa6d 100644
--- a/embassy-executor/src/lib.rs
+++ b/embassy-executor/src/lib.rs
@@ -1,24 +1,46 @@
1#![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] 1#![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)]
2#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))]
3#![cfg_attr(all(feature = "nightly", target_arch = "xtensa"), feature(asm_experimental_arch))] 2#![cfg_attr(all(feature = "nightly", target_arch = "xtensa"), feature(asm_experimental_arch))]
4#![allow(clippy::new_without_default)] 3#![allow(clippy::new_without_default)]
5#![doc = include_str!("../../README.md")] 4#![doc = include_str!("../README.md")]
6#![warn(missing_docs)] 5#![warn(missing_docs)]
7 6
8// This mod MUST go first, so that the others see its macros. 7// This mod MUST go first, so that the others see its macros.
9pub(crate) mod fmt; 8pub(crate) mod fmt;
10 9
11pub mod executor;
12#[cfg(feature = "time")]
13pub mod time;
14
15#[cfg(feature = "nightly")] 10#[cfg(feature = "nightly")]
16pub use embassy_macros::{main, task}; 11pub use embassy_macros::{main, task};
17 12
13cfg_if::cfg_if! {
14 if #[cfg(cortex_m)] {
15 #[path="arch/cortex_m.rs"]
16 mod arch;
17 pub use arch::*;
18 }
19 else if #[cfg(target_arch="riscv32")] {
20 #[path="arch/riscv32.rs"]
21 mod arch;
22 pub use arch::*;
23 }
24 else if #[cfg(all(target_arch="xtensa", feature = "nightly"))] {
25 #[path="arch/xtensa.rs"]
26 mod arch;
27 pub use arch::*;
28 }
29 else if #[cfg(feature="wasm")] {
30 #[path="arch/wasm.rs"]
31 mod arch;
32 pub use arch::*;
33 }
34 else if #[cfg(feature="std")] {
35 #[path="arch/std.rs"]
36 mod arch;
37 pub use arch::*;
38 }
39}
40
18#[doc(hidden)] 41#[doc(hidden)]
19/// Implementation details for embassy macros. DO NOT USE. 42/// Implementation details for embassy macros. DO NOT USE.
20pub mod export { 43pub mod export {
21 pub use atomic_polyfill as atomic;
22 #[cfg(feature = "rtos-trace")] 44 #[cfg(feature = "rtos-trace")]
23 pub use rtos_trace::trace; 45 pub use rtos_trace::trace;
24 46
@@ -40,3 +62,8 @@ pub mod export {
40 ($($tt:tt)*) => {}; 62 ($($tt:tt)*) => {};
41 } 63 }
42} 64}
65
66pub mod raw;
67
68mod spawner;
69pub use spawner::*;
diff --git a/embassy-executor/src/executor/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index 56220d10e..c55d10699 100644
--- a/embassy-executor/src/executor/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -8,7 +8,7 @@
8//! executor wrappers in [`executor`](crate::executor) and the [`embassy_executor::task`](embassy_macros::task) macro, which are fully safe. 8//! executor wrappers in [`executor`](crate::executor) and the [`embassy_executor::task`](embassy_macros::task) macro, which are fully safe.
9 9
10mod run_queue; 10mod run_queue;
11#[cfg(feature = "time")] 11#[cfg(feature = "integrated-timers")]
12mod timer_queue; 12mod timer_queue;
13pub(crate) mod util; 13pub(crate) mod util;
14mod waker; 14mod waker;
@@ -22,6 +22,10 @@ use core::{mem, ptr};
22 22
23use atomic_polyfill::{AtomicU32, Ordering}; 23use atomic_polyfill::{AtomicU32, Ordering};
24use critical_section::CriticalSection; 24use critical_section::CriticalSection;
25#[cfg(feature = "integrated-timers")]
26use embassy_time::driver::{self, AlarmHandle};
27#[cfg(feature = "integrated-timers")]
28use embassy_time::Instant;
25#[cfg(feature = "rtos-trace")] 29#[cfg(feature = "rtos-trace")]
26use rtos_trace::trace; 30use rtos_trace::trace;
27 31
@@ -29,17 +33,13 @@ use self::run_queue::{RunQueue, RunQueueItem};
29use self::util::UninitCell; 33use self::util::UninitCell;
30pub use self::waker::task_from_waker; 34pub use self::waker::task_from_waker;
31use super::SpawnToken; 35use super::SpawnToken;
32#[cfg(feature = "time")]
33use crate::time::driver::{self, AlarmHandle};
34#[cfg(feature = "time")]
35use crate::time::Instant;
36 36
37/// Task is spawned (has a future) 37/// Task is spawned (has a future)
38pub(crate) const STATE_SPAWNED: u32 = 1 << 0; 38pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
39/// Task is in the executor run queue 39/// Task is in the executor run queue
40pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1; 40pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
41/// Task is in the executor timer queue 41/// Task is in the executor timer queue
42#[cfg(feature = "time")] 42#[cfg(feature = "integrated-timers")]
43pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2; 43pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
44 44
45/// Raw task header for use in task pointers. 45/// Raw task header for use in task pointers.
@@ -52,9 +52,9 @@ pub struct TaskHeader {
52 pub(crate) executor: Cell<*const Executor>, // Valid if state != 0 52 pub(crate) executor: Cell<*const Executor>, // Valid if state != 0
53 pub(crate) poll_fn: UninitCell<unsafe fn(NonNull<TaskHeader>)>, // Valid if STATE_SPAWNED 53 pub(crate) poll_fn: UninitCell<unsafe fn(NonNull<TaskHeader>)>, // Valid if STATE_SPAWNED
54 54
55 #[cfg(feature = "time")] 55 #[cfg(feature = "integrated-timers")]
56 pub(crate) expires_at: Cell<Instant>, 56 pub(crate) expires_at: Cell<Instant>,
57 #[cfg(feature = "time")] 57 #[cfg(feature = "integrated-timers")]
58 pub(crate) timer_queue_item: timer_queue::TimerQueueItem, 58 pub(crate) timer_queue_item: timer_queue::TimerQueueItem,
59} 59}
60 60
@@ -66,9 +66,9 @@ impl TaskHeader {
66 executor: Cell::new(ptr::null()), 66 executor: Cell::new(ptr::null()),
67 poll_fn: UninitCell::uninit(), 67 poll_fn: UninitCell::uninit(),
68 68
69 #[cfg(feature = "time")] 69 #[cfg(feature = "integrated-timers")]
70 expires_at: Cell::new(Instant::from_ticks(0)), 70 expires_at: Cell::new(Instant::from_ticks(0)),
71 #[cfg(feature = "time")] 71 #[cfg(feature = "integrated-timers")]
72 timer_queue_item: timer_queue::TimerQueueItem::new(), 72 timer_queue_item: timer_queue::TimerQueueItem::new(),
73 } 73 }
74 } 74 }
@@ -269,9 +269,9 @@ pub struct Executor {
269 signal_fn: fn(*mut ()), 269 signal_fn: fn(*mut ()),
270 signal_ctx: *mut (), 270 signal_ctx: *mut (),
271 271
272 #[cfg(feature = "time")] 272 #[cfg(feature = "integrated-timers")]
273 pub(crate) timer_queue: timer_queue::TimerQueue, 273 pub(crate) timer_queue: timer_queue::TimerQueue,
274 #[cfg(feature = "time")] 274 #[cfg(feature = "integrated-timers")]
275 alarm: AlarmHandle, 275 alarm: AlarmHandle,
276} 276}
277 277
@@ -283,9 +283,9 @@ impl Executor {
283 /// 283 ///
284 /// See [`Executor`] docs for details on `signal_fn`. 284 /// See [`Executor`] docs for details on `signal_fn`.
285 pub fn new(signal_fn: fn(*mut ()), signal_ctx: *mut ()) -> Self { 285 pub fn new(signal_fn: fn(*mut ()), signal_ctx: *mut ()) -> Self {
286 #[cfg(feature = "time")] 286 #[cfg(feature = "integrated-timers")]
287 let alarm = unsafe { unwrap!(driver::allocate_alarm()) }; 287 let alarm = unsafe { unwrap!(driver::allocate_alarm()) };
288 #[cfg(feature = "time")] 288 #[cfg(feature = "integrated-timers")]
289 driver::set_alarm_callback(alarm, signal_fn, signal_ctx); 289 driver::set_alarm_callback(alarm, signal_fn, signal_ctx);
290 290
291 Self { 291 Self {
@@ -293,9 +293,9 @@ impl Executor {
293 signal_fn, 293 signal_fn,
294 signal_ctx, 294 signal_ctx,
295 295
296 #[cfg(feature = "time")] 296 #[cfg(feature = "integrated-timers")]
297 timer_queue: timer_queue::TimerQueue::new(), 297 timer_queue: timer_queue::TimerQueue::new(),
298 #[cfg(feature = "time")] 298 #[cfg(feature = "integrated-timers")]
299 alarm, 299 alarm,
300 } 300 }
301 } 301 }
@@ -354,13 +354,13 @@ impl Executor {
354 /// somehow schedule for `poll()` to be called later, at a time you know for sure there's 354 /// somehow schedule for `poll()` to be called later, at a time you know for sure there's
355 /// no `poll()` already running. 355 /// no `poll()` already running.
356 pub unsafe fn poll(&'static self) { 356 pub unsafe fn poll(&'static self) {
357 #[cfg(feature = "time")] 357 #[cfg(feature = "integrated-timers")]
358 self.timer_queue.dequeue_expired(Instant::now(), |task| wake_task(task)); 358 self.timer_queue.dequeue_expired(Instant::now(), |task| wake_task(task));
359 359
360 self.run_queue.dequeue_all(|p| { 360 self.run_queue.dequeue_all(|p| {
361 let task = p.as_ref(); 361 let task = p.as_ref();
362 362
363 #[cfg(feature = "time")] 363 #[cfg(feature = "integrated-timers")]
364 task.expires_at.set(Instant::MAX); 364 task.expires_at.set(Instant::MAX);
365 365
366 let state = task.state.fetch_and(!STATE_RUN_QUEUED, Ordering::AcqRel); 366 let state = task.state.fetch_and(!STATE_RUN_QUEUED, Ordering::AcqRel);
@@ -383,11 +383,11 @@ impl Executor {
383 trace::task_exec_end(); 383 trace::task_exec_end();
384 384
385 // Enqueue or update into timer_queue 385 // Enqueue or update into timer_queue
386 #[cfg(feature = "time")] 386 #[cfg(feature = "integrated-timers")]
387 self.timer_queue.update(p); 387 self.timer_queue.update(p);
388 }); 388 });
389 389
390 #[cfg(feature = "time")] 390 #[cfg(feature = "integrated-timers")]
391 { 391 {
392 // If this is already in the past, set_alarm will immediately trigger the alarm. 392 // If this is already in the past, set_alarm will immediately trigger the alarm.
393 // This will cause `signal_fn` to be called, which will cause `poll()` to be called again, 393 // This will cause `signal_fn` to be called, which will cause `poll()` to be called again,
@@ -435,8 +435,9 @@ pub unsafe fn wake_task(task: NonNull<TaskHeader>) {
435 }) 435 })
436} 436}
437 437
438#[cfg(feature = "time")] 438#[cfg(feature = "integrated-timers")]
439pub(crate) unsafe fn register_timer(at: Instant, waker: &core::task::Waker) { 439#[no_mangle]
440unsafe fn _embassy_time_schedule_wake(at: Instant, waker: &core::task::Waker) {
440 let task = waker::task_from_waker(waker); 441 let task = waker::task_from_waker(waker);
441 let task = task.as_ref(); 442 let task = task.as_ref();
442 let expires_at = task.expires_at.get(); 443 let expires_at = task.expires_at.get();
@@ -448,11 +449,11 @@ impl rtos_trace::RtosTraceOSCallbacks for Executor {
448 fn task_list() { 449 fn task_list() {
449 // We don't know what tasks exist, so we can't send them. 450 // We don't know what tasks exist, so we can't send them.
450 } 451 }
451 #[cfg(feature = "time")] 452 #[cfg(feature = "integrated-timers")]
452 fn time() -> u64 { 453 fn time() -> u64 {
453 Instant::now().as_micros() 454 Instant::now().as_micros()
454 } 455 }
455 #[cfg(not(feature = "time"))] 456 #[cfg(not(feature = "integrated-timers"))]
456 fn time() -> u64 { 457 fn time() -> u64 {
457 0 458 0
458 } 459 }
diff --git a/embassy-executor/src/executor/raw/run_queue.rs b/embassy-executor/src/raw/run_queue.rs
index ed8c82a5c..ed8c82a5c 100644
--- a/embassy-executor/src/executor/raw/run_queue.rs
+++ b/embassy-executor/src/raw/run_queue.rs
diff --git a/embassy-executor/src/executor/raw/timer_queue.rs b/embassy-executor/src/raw/timer_queue.rs
index 62fcfc531..24c31892a 100644
--- a/embassy-executor/src/executor/raw/timer_queue.rs
+++ b/embassy-executor/src/raw/timer_queue.rs
@@ -4,9 +4,9 @@ use core::ptr;
4use core::ptr::NonNull; 4use core::ptr::NonNull;
5 5
6use atomic_polyfill::Ordering; 6use atomic_polyfill::Ordering;
7use embassy_time::Instant;
7 8
8use super::{TaskHeader, STATE_TIMER_QUEUED}; 9use super::{TaskHeader, STATE_TIMER_QUEUED};
9use crate::time::Instant;
10 10
11pub(crate) struct TimerQueueItem { 11pub(crate) struct TimerQueueItem {
12 next: Cell<*mut TaskHeader>, 12 next: Cell<*mut TaskHeader>,
diff --git a/embassy-executor/src/executor/raw/util.rs b/embassy-executor/src/raw/util.rs
index ed5822188..ed5822188 100644
--- a/embassy-executor/src/executor/raw/util.rs
+++ b/embassy-executor/src/raw/util.rs
diff --git a/embassy-executor/src/executor/raw/waker.rs b/embassy-executor/src/raw/waker.rs
index 6b9c03a62..5765259f2 100644
--- a/embassy-executor/src/executor/raw/waker.rs
+++ b/embassy-executor/src/raw/waker.rs
@@ -40,7 +40,7 @@ pub fn task_from_waker(waker: &Waker) -> NonNull<TaskHeader> {
40 // TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992 40 // TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992
41 let hack: &WakerHack = unsafe { mem::transmute(waker) }; 41 let hack: &WakerHack = unsafe { mem::transmute(waker) };
42 if hack.vtable != &VTABLE { 42 if hack.vtable != &VTABLE {
43 panic!("Found waker not created by the Embassy executor. `embassy_executor::time::Timer` only works with the Embassy executor.") 43 panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.")
44 } 44 }
45 45
46 // safety: we never create a waker with a null data pointer. 46 // safety: we never create a waker with a null data pointer.
diff --git a/embassy-executor/src/executor/spawner.rs b/embassy-executor/src/spawner.rs
index 25a0d7dbb..25a0d7dbb 100644
--- a/embassy-executor/src/executor/spawner.rs
+++ b/embassy-executor/src/spawner.rs
diff --git a/embassy-hal-common/Cargo.toml b/embassy-hal-common/Cargo.toml
index 4a6a61003..58f0af6ab 100644
--- a/embassy-hal-common/Cargo.toml
+++ b/embassy-hal-common/Cargo.toml
@@ -9,5 +9,4 @@ edition = "2021"
9defmt = { version = "0.3", optional = true } 9defmt = { version = "0.3", optional = true }
10log = { version = "0.4.14", optional = true } 10log = { version = "0.4.14", optional = true }
11 11
12embassy-util = { version = "0.1.0", path = "../embassy-util" }
13num-traits = { version = "0.2.14", default-features = false } 12num-traits = { version = "0.2.14", default-features = false }
diff --git a/embassy-lora/Cargo.toml b/embassy-lora/Cargo.toml
index 6c1b01e67..c7435ab3e 100644
--- a/embassy-lora/Cargo.toml
+++ b/embassy-lora/Cargo.toml
@@ -8,8 +8,8 @@ src_base = "https://github.com/embassy-rs/embassy/blob/embassy-lora-v$VERSION/em
8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-lora/src/" 8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-lora/src/"
9features = ["time", "defmt"] 9features = ["time", "defmt"]
10flavors = [ 10flavors = [
11 { name = "sx127x", target = "thumbv7em-none-eabihf", features = ["sx127x", "embassy-stm32/stm32wl55jc-cm4", "embassy-stm32/time-driver-any", "embassy-executor/time-tick-32768hz"] }, 11 { name = "sx127x", target = "thumbv7em-none-eabihf", features = ["sx127x", "embassy-stm32/stm32wl55jc-cm4", "embassy-stm32/time-driver-any", "embassy-time/tick-32768hz"] },
12 { name = "stm32wl", target = "thumbv7em-none-eabihf", features = ["stm32wl", "embassy-stm32/stm32wl55jc-cm4", "embassy-stm32/time-driver-any", "embassy-executor/time-tick-32768hz"] }, 12 { name = "stm32wl", target = "thumbv7em-none-eabihf", features = ["stm32wl", "embassy-stm32/stm32wl55jc-cm4", "embassy-stm32/time-driver-any", "embassy-time/tick-32768hz"] },
13] 13]
14 14
15[lib] 15[lib]
@@ -24,7 +24,7 @@ time = []
24defmt = { version = "0.3", optional = true } 24defmt = { version = "0.3", optional = true }
25log = { version = "0.4.14", optional = true } 25log = { version = "0.4.14", optional = true }
26 26
27embassy-executor = { version = "0.1.0", path = "../embassy-executor" } 27embassy-time = { version = "0.1.0", path = "../embassy-time" }
28embassy-util = { version = "0.1.0", path = "../embassy-util" } 28embassy-util = { version = "0.1.0", path = "../embassy-util" }
29embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } 29embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true }
30embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } 30embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" }
diff --git a/embassy-lora/src/lib.rs b/embassy-lora/src/lib.rs
index 29ea45863..1b2dd45c2 100644
--- a/embassy-lora/src/lib.rs
+++ b/embassy-lora/src/lib.rs
@@ -18,6 +18,6 @@ pub struct LoraTimer;
18impl lorawan_device::async_device::radio::Timer for LoraTimer { 18impl lorawan_device::async_device::radio::Timer for LoraTimer {
19 type DelayFuture<'m> = impl core::future::Future<Output = ()> + 'm; 19 type DelayFuture<'m> = impl core::future::Future<Output = ()> + 'm;
20 fn delay_ms<'m>(&'m mut self, millis: u64) -> Self::DelayFuture<'m> { 20 fn delay_ms<'m>(&'m mut self, millis: u64) -> Self::DelayFuture<'m> {
21 embassy_executor::time::Timer::after(embassy_executor::time::Duration::from_millis(millis)) 21 embassy_time::Timer::after(embassy_time::Duration::from_millis(millis))
22 } 22 }
23} 23}
diff --git a/embassy-lora/src/sx127x/sx127x_lora/mod.rs b/embassy-lora/src/sx127x/sx127x_lora/mod.rs
index b3636d097..aacc9da22 100644
--- a/embassy-lora/src/sx127x/sx127x_lora/mod.rs
+++ b/embassy-lora/src/sx127x/sx127x_lora/mod.rs
@@ -6,7 +6,7 @@
6#![allow(dead_code)] 6#![allow(dead_code)]
7 7
8use bit_field::BitField; 8use bit_field::BitField;
9use embassy_executor::time::{Duration, Timer}; 9use embassy_time::{Duration, Timer};
10use embedded_hal::digital::v2::OutputPin; 10use embedded_hal::digital::v2::OutputPin;
11use embedded_hal_async::spi::SpiBus; 11use embedded_hal_async::spi::SpiBus;
12 12
diff --git a/embassy-macros/Cargo.toml b/embassy-macros/Cargo.toml
index 6abafa581..19a3e9de2 100644
--- a/embassy-macros/Cargo.toml
+++ b/embassy-macros/Cargo.toml
@@ -13,8 +13,5 @@ proc-macro2 = "1.0.29"
13proc-macro = true 13proc-macro = true
14 14
15[features] 15[features]
16nrf = []
17stm32 = []
18rp = []
19std = [] 16std = []
20wasm = [] 17wasm = []
diff --git a/embassy-macros/src/macros/cortex_m_interrupt_take.rs b/embassy-macros/src/macros/cortex_m_interrupt_take.rs
index 62249807e..f6e41bcb4 100644
--- a/embassy-macros/src/macros/cortex_m_interrupt_take.rs
+++ b/embassy-macros/src/macros/cortex_m_interrupt_take.rs
@@ -16,8 +16,8 @@ pub fn run(name: syn::Ident) -> Result<TokenStream, TokenStream> {
16 static HANDLER: interrupt::Handler; 16 static HANDLER: interrupt::Handler;
17 } 17 }
18 18
19 let func = HANDLER.func.load(::embassy_executor::export::atomic::Ordering::Relaxed); 19 let func = HANDLER.func.load(interrupt::_export::atomic::Ordering::Relaxed);
20 let ctx = HANDLER.ctx.load(::embassy_executor::export::atomic::Ordering::Relaxed); 20 let ctx = HANDLER.ctx.load(interrupt::_export::atomic::Ordering::Relaxed);
21 let func: fn(*mut ()) = ::core::mem::transmute(func); 21 let func: fn(*mut ()) = ::core::mem::transmute(func);
22 ::embassy_executor::rtos_trace_interrupt! { 22 ::embassy_executor::rtos_trace_interrupt! {
23 ::embassy_executor::export::trace::isr_enter(); 23 ::embassy_executor::export::trace::isr_enter();
@@ -28,9 +28,9 @@ pub fn run(name: syn::Ident) -> Result<TokenStream, TokenStream> {
28 } 28 }
29 } 29 }
30 30
31 static TAKEN: ::embassy_executor::export::atomic::AtomicBool = ::embassy_executor::export::atomic::AtomicBool::new(false); 31 static TAKEN: interrupt::_export::atomic::AtomicBool = interrupt::_export::atomic::AtomicBool::new(false);
32 32
33 if TAKEN.compare_exchange(false, true, ::embassy_executor::export::atomic::Ordering::AcqRel, ::embassy_executor::export::atomic::Ordering::Acquire).is_err() { 33 if TAKEN.compare_exchange(false, true, interrupt::_export::atomic::Ordering::AcqRel, interrupt::_export::atomic::Ordering::Acquire).is_err() {
34 core::panic!("IRQ Already taken"); 34 core::panic!("IRQ Already taken");
35 } 35 }
36 36
diff --git a/embassy-macros/src/macros/main.rs b/embassy-macros/src/macros/main.rs
index a8c8bb0d7..52987d7d2 100644
--- a/embassy-macros/src/macros/main.rs
+++ b/embassy-macros/src/macros/main.rs
@@ -3,28 +3,12 @@ use proc_macro2::TokenStream;
3use quote::quote; 3use quote::quote;
4 4
5use crate::util::ctxt::Ctxt; 5use crate::util::ctxt::Ctxt;
6use crate::util::path::ModulePrefix;
7
8#[cfg(feature = "stm32")]
9const HAL: Option<&str> = Some("embassy_stm32");
10#[cfg(feature = "nrf")]
11const HAL: Option<&str> = Some("embassy_nrf");
12#[cfg(feature = "rp")]
13const HAL: Option<&str> = Some("embassy_rp");
14#[cfg(not(any(feature = "stm32", feature = "nrf", feature = "rp")))]
15const HAL: Option<&str> = None;
16 6
17#[derive(Debug, FromMeta)] 7#[derive(Debug, FromMeta)]
18struct Args { 8struct Args {}
19 #[darling(default)]
20 embassy_prefix: ModulePrefix,
21
22 #[allow(unused)]
23 #[darling(default)]
24 config: Option<syn::LitStr>,
25}
26 9
27pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> { 10pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> {
11 #[allow(unused_variables)]
28 let args = Args::from_list(&args).map_err(|e| e.write_errors())?; 12 let args = Args::from_list(&args).map_err(|e| e.write_errors())?;
29 13
30 let fargs = f.sig.inputs.clone(); 14 let fargs = f.sig.inputs.clone();
@@ -32,32 +16,26 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
32 let ctxt = Ctxt::new(); 16 let ctxt = Ctxt::new();
33 17
34 if f.sig.asyncness.is_none() { 18 if f.sig.asyncness.is_none() {
35 ctxt.error_spanned_by(&f.sig, "task functions must be async"); 19 ctxt.error_spanned_by(&f.sig, "main function must be async");
36 } 20 }
37 if !f.sig.generics.params.is_empty() { 21 if !f.sig.generics.params.is_empty() {
38 ctxt.error_spanned_by(&f.sig, "task functions must not be generic"); 22 ctxt.error_spanned_by(&f.sig, "main function must not be generic");
39 } 23 }
40 24
41 if HAL.is_some() && fargs.len() != 2 { 25 if fargs.len() != 1 {
42 ctxt.error_spanned_by(&f.sig, "main function must have 2 arguments"); 26 ctxt.error_spanned_by(&f.sig, "main function must have 1 argument: the spawner.");
43 }
44 if HAL.is_none() && fargs.len() != 1 {
45 ctxt.error_spanned_by(&f.sig, "main function must have 1 argument");
46 } 27 }
47 28
48 ctxt.check()?; 29 ctxt.check()?;
49 30
50 let embassy_prefix = args.embassy_prefix;
51 let embassy_prefix_lit = embassy_prefix.literal();
52 let embassy_path = embassy_prefix.append("embassy_executor").path();
53 let f_body = f.block; 31 let f_body = f.block;
54 32
55 #[cfg(feature = "wasm")] 33 #[cfg(feature = "wasm")]
56 let main = quote! { 34 let main = quote! {
57 #[wasm_bindgen::prelude::wasm_bindgen(start)] 35 #[wasm_bindgen::prelude::wasm_bindgen(start)]
58 pub fn main() -> Result<(), wasm_bindgen::JsValue> { 36 pub fn main() -> Result<(), wasm_bindgen::JsValue> {
59 static EXECUTOR: ::embassy_util::Forever<#embassy_path::executor::Executor> = ::embassy_util::Forever::new(); 37 static EXECUTOR: ::embassy_util::Forever<::embassy_executor::Executor> = ::embassy_util::Forever::new();
60 let executor = EXECUTOR.put(#embassy_path::executor::Executor::new()); 38 let executor = EXECUTOR.put(::embassy_executor::Executor::new());
61 39
62 executor.start(|spawner| { 40 executor.start(|spawner| {
63 spawner.spawn(__embassy_main(spawner)).unwrap(); 41 spawner.spawn(__embassy_main(spawner)).unwrap();
@@ -70,7 +48,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
70 #[cfg(all(feature = "std", not(feature = "wasm")))] 48 #[cfg(all(feature = "std", not(feature = "wasm")))]
71 let main = quote! { 49 let main = quote! {
72 fn main() -> ! { 50 fn main() -> ! {
73 let mut executor = #embassy_path::executor::Executor::new(); 51 let mut executor = ::embassy_executor::Executor::new();
74 let executor = unsafe { __make_static(&mut executor) }; 52 let executor = unsafe { __make_static(&mut executor) };
75 53
76 executor.run(|spawner| { 54 executor.run(|spawner| {
@@ -80,43 +58,20 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
80 }; 58 };
81 59
82 #[cfg(all(not(feature = "std"), not(feature = "wasm")))] 60 #[cfg(all(not(feature = "std"), not(feature = "wasm")))]
83 let main = { 61 let main = quote! {
84 let config = args.config.map(|s| s.parse::<syn::Expr>().unwrap()).unwrap_or_else(|| { 62 #[cortex_m_rt::entry]
85 syn::Expr::Verbatim(quote! { 63 fn main() -> ! {
86 Default::default() 64 let mut executor = ::embassy_executor::Executor::new();
65 let executor = unsafe { __make_static(&mut executor) };
66
67 executor.run(|spawner| {
68 spawner.must_spawn(__embassy_main(spawner));
87 }) 69 })
88 });
89
90 let (hal_setup, peris_arg) = match HAL {
91 Some(hal) => {
92 let embassy_hal_path = embassy_prefix.append(hal).path();
93 (
94 quote!(
95 let p = #embassy_hal_path::init(#config);
96 ),
97 quote!(p),
98 )
99 }
100 None => (quote!(), quote!()),
101 };
102
103 quote! {
104 #[cortex_m_rt::entry]
105 fn main() -> ! {
106 #hal_setup
107
108 let mut executor = #embassy_path::executor::Executor::new();
109 let executor = unsafe { __make_static(&mut executor) };
110
111 executor.run(|spawner| {
112 spawner.must_spawn(__embassy_main(spawner, #peris_arg));
113 })
114 }
115 } 70 }
116 }; 71 };
117 72
118 let result = quote! { 73 let result = quote! {
119 #[#embassy_path::task(embassy_prefix = #embassy_prefix_lit)] 74 #[::embassy_executor::task()]
120 async fn __embassy_main(#fargs) { 75 async fn __embassy_main(#fargs) {
121 #f_body 76 #f_body
122 } 77 }
diff --git a/embassy-macros/src/macros/task.rs b/embassy-macros/src/macros/task.rs
index 57087c81c..573776f8c 100644
--- a/embassy-macros/src/macros/task.rs
+++ b/embassy-macros/src/macros/task.rs
@@ -3,22 +3,16 @@ use proc_macro2::TokenStream;
3use quote::{format_ident, quote}; 3use quote::{format_ident, quote};
4 4
5use crate::util::ctxt::Ctxt; 5use crate::util::ctxt::Ctxt;
6use crate::util::path::ModulePrefix;
7 6
8#[derive(Debug, FromMeta)] 7#[derive(Debug, FromMeta)]
9struct Args { 8struct Args {
10 #[darling(default)] 9 #[darling(default)]
11 pool_size: Option<usize>, 10 pool_size: Option<usize>,
12 #[darling(default)]
13 embassy_prefix: ModulePrefix,
14} 11}
15 12
16pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> { 13pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> {
17 let args = Args::from_list(&args).map_err(|e| e.write_errors())?; 14 let args = Args::from_list(&args).map_err(|e| e.write_errors())?;
18 15
19 let embassy_prefix = args.embassy_prefix.append("embassy_executor");
20 let embassy_path = embassy_prefix.path();
21
22 let pool_size: usize = args.pool_size.unwrap_or(1); 16 let pool_size: usize = args.pool_size.unwrap_or(1);
23 17
24 let ctxt = Ctxt::new(); 18 let ctxt = Ctxt::new();
@@ -70,9 +64,9 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
70 // in the user's code. 64 // in the user's code.
71 #task_inner 65 #task_inner
72 66
73 #visibility fn #task_ident(#fargs) -> #embassy_path::executor::SpawnToken<impl Sized> { 67 #visibility fn #task_ident(#fargs) -> ::embassy_executor::SpawnToken<impl Sized> {
74 type Fut = impl ::core::future::Future + 'static; 68 type Fut = impl ::core::future::Future + 'static;
75 static POOL: #embassy_path::executor::raw::TaskPool<Fut, #pool_size> = #embassy_path::executor::raw::TaskPool::new(); 69 static POOL: ::embassy_executor::raw::TaskPool<Fut, #pool_size> = ::embassy_executor::raw::TaskPool::new();
76 unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) } 70 unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) }
77 } 71 }
78 }; 72 };
diff --git a/embassy-macros/src/util/mod.rs b/embassy-macros/src/util/mod.rs
index c2f2dfd65..28702809e 100644
--- a/embassy-macros/src/util/mod.rs
+++ b/embassy-macros/src/util/mod.rs
@@ -1,2 +1 @@
1pub mod ctxt; pub mod ctxt;
2pub mod path;
diff --git a/embassy-macros/src/util/path.rs b/embassy-macros/src/util/path.rs
deleted file mode 100644
index 00fca7bdb..000000000
--- a/embassy-macros/src/util/path.rs
+++ /dev/null
@@ -1,41 +0,0 @@
1use darling::{FromMeta, Result};
2use proc_macro2::Span;
3use syn::{LitStr, Path};
4
5#[derive(Debug)]
6pub struct ModulePrefix {
7 literal: LitStr,
8}
9
10impl ModulePrefix {
11 pub fn new(path: &str) -> Self {
12 let literal = LitStr::new(path, Span::call_site());
13 Self { literal }
14 }
15
16 pub fn append(&self, component: &str) -> ModulePrefix {
17 let mut lit = self.literal().value();
18 lit.push_str(component);
19 Self::new(lit.as_str())
20 }
21
22 pub fn path(&self) -> Path {
23 self.literal.parse().unwrap()
24 }
25
26 pub fn literal(&self) -> &LitStr {
27 &self.literal
28 }
29}
30
31impl FromMeta for ModulePrefix {
32 fn from_string(value: &str) -> Result<Self> {
33 Ok(ModulePrefix::new(value))
34 }
35}
36
37impl Default for ModulePrefix {
38 fn default() -> ModulePrefix {
39 ModulePrefix::new("::")
40 }
41}
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml
index 64cb5bd8f..9f9bb2261 100644
--- a/embassy-net/Cargo.toml
+++ b/embassy-net/Cargo.toml
@@ -7,10 +7,8 @@ edition = "2021"
7[package.metadata.embassy_docs] 7[package.metadata.embassy_docs]
8src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-v$VERSION/embassy-net/src/" 8src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-v$VERSION/embassy-net/src/"
9src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net/src/" 9src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net/src/"
10features = [ "pool-4", "defmt", "tcp", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "embassy-executor/time", "embassy-executor/time-tick-1mhz"] 10features = [ "pool-4", "defmt", "tcp", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "embassy-time/tick-1mhz"]
11flavors = [ 11target = "thumbv7em-none-eabi"
12 { name = "default", target = "thumbv7em-none-eabihf" },
13]
14 12
15[features] 13[features]
16default = [] 14default = []
@@ -18,6 +16,7 @@ std = []
18 16
19defmt = ["dep:defmt", "smoltcp/defmt"] 17defmt = ["dep:defmt", "smoltcp/defmt"]
20 18
19udp = ["smoltcp/socket-udp"]
21tcp = ["smoltcp/socket-tcp"] 20tcp = ["smoltcp/socket-tcp"]
22dns = ["smoltcp/socket-dns"] 21dns = ["smoltcp/socket-dns"]
23dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"] 22dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"]
@@ -31,23 +30,26 @@ pool-16 = []
31pool-32 = [] 30pool-32 = []
32pool-64 = [] 31pool-64 = []
33pool-128 = [] 32pool-128 = []
33unstable-traits = []
34 34
35[dependencies] 35[dependencies]
36 36
37defmt = { version = "0.3", optional = true } 37defmt = { version = "0.3", optional = true }
38log = { version = "0.4.14", optional = true } 38log = { version = "0.4.14", optional = true }
39 39
40embassy-executor = { version = "0.1.0", path = "../embassy-executor" } 40embassy-time = { version = "0.1.0", path = "../embassy-time" }
41embassy-util = { version = "0.1.0", path = "../embassy-util" } 41embassy-util = { version = "0.1.0", path = "../embassy-util" }
42embedded-io = { version = "0.3.0", features = [ "async" ] } 42embedded-io = { version = "0.3.0", features = [ "async" ] }
43 43
44managed = { version = "0.8.0", default-features = false, features = [ "map" ] } 44managed = { version = "0.8.0", default-features = false, features = [ "map" ] }
45heapless = { version = "0.7.5", default-features = false } 45heapless = { version = "0.7.5", default-features = false }
46as-slice = "0.2.1" 46as-slice = "0.2.1"
47generic-array = { version = "0.14.4", default-features = false } 47generic-array = { version = "0.14.4", default-features = false }
48stable_deref_trait = { version = "1.2.0", default-features = false } 48stable_deref_trait = { version = "1.2.0", default-features = false }
49futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } 49futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] }
50atomic-pool = "0.2.1" 50atomic-pool = "1.0"
51atomic-polyfill = "1.0.1"
52embedded-nal-async = "0.2.0"
51 53
52[dependencies.smoltcp] 54[dependencies.smoltcp]
53version = "0.8.0" 55version = "0.8.0"
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index 1c5ba103a..83d364715 100644
--- a/embassy-net/src/lib.rs
+++ b/embassy-net/src/lib.rs
@@ -16,6 +16,9 @@ pub use stack::{Config, ConfigStrategy, Stack, StackResources};
16#[cfg(feature = "tcp")] 16#[cfg(feature = "tcp")]
17pub mod tcp; 17pub mod tcp;
18 18
19#[cfg(feature = "udp")]
20pub mod udp;
21
19// smoltcp reexports 22// smoltcp reexports
20pub use smoltcp::phy::{DeviceCapabilities, Medium}; 23pub use smoltcp::phy::{DeviceCapabilities, Medium};
21pub use smoltcp::time::{Duration as SmolDuration, Instant as SmolInstant}; 24pub use smoltcp::time::{Duration as SmolDuration, Instant as SmolInstant};
@@ -24,3 +27,5 @@ pub use smoltcp::wire::{EthernetAddress, HardwareAddress};
24pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; 27pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr};
25#[cfg(feature = "proto-ipv6")] 28#[cfg(feature = "proto-ipv6")]
26pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr}; 29pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr};
30#[cfg(feature = "udp")]
31pub use smoltcp::{socket::udp::PacketMetadata, wire::IpListenEndpoint};
diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs
index 06bb732ff..4b6a7ae2a 100644
--- a/embassy-net/src/stack.rs
+++ b/embassy-net/src/stack.rs
@@ -2,7 +2,7 @@ use core::cell::UnsafeCell;
2use core::future::Future; 2use core::future::Future;
3use core::task::{Context, Poll}; 3use core::task::{Context, Poll};
4 4
5use embassy_executor::time::{Instant, Timer}; 5use embassy_time::{Instant, Timer};
6use embassy_util::waitqueue::WakerRegistration; 6use embassy_util::waitqueue::WakerRegistration;
7use futures::future::poll_fn; 7use futures::future::poll_fn;
8use futures::pin_mut; 8use futures::pin_mut;
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs
index c18391ace..910772c7d 100644
--- a/embassy-net/src/tcp.rs
+++ b/embassy-net/src/tcp.rs
@@ -181,7 +181,7 @@ impl<'a> Drop for TcpSocket<'a> {
181// ======================= 181// =======================
182 182
183#[derive(Copy, Clone)] 183#[derive(Copy, Clone)]
184pub struct TcpIo<'a> { 184struct TcpIo<'a> {
185 stack: &'a UnsafeCell<SocketStack>, 185 stack: &'a UnsafeCell<SocketStack>,
186 handle: SocketHandle, 186 handle: SocketHandle,
187} 187}
@@ -328,3 +328,172 @@ impl<'d> embedded_io::asynch::Write for TcpWriter<'d> {
328 self.io.flush() 328 self.io.flush()
329 } 329 }
330} 330}
331
332#[cfg(feature = "unstable-traits")]
333pub mod client {
334 use core::mem::MaybeUninit;
335 use core::ptr::NonNull;
336
337 use atomic_polyfill::{AtomicBool, Ordering};
338 use embedded_nal_async::IpAddr;
339
340 use super::*;
341
342 /// TCP client capable of creating up to N multiple connections with tx and rx buffers according to TX_SZ and RX_SZ.
343 pub struct TcpClient<'d, D: Device, const N: usize, const TX_SZ: usize = 1024, const RX_SZ: usize = 1024> {
344 stack: &'d Stack<D>,
345 state: &'d TcpClientState<N, TX_SZ, RX_SZ>,
346 }
347
348 impl<'d, D: Device, const N: usize, const TX_SZ: usize, const RX_SZ: usize> TcpClient<'d, D, N, TX_SZ, RX_SZ> {
349 /// Create a new TcpClient
350 pub fn new(stack: &'d Stack<D>, state: &'d TcpClientState<N, TX_SZ, RX_SZ>) -> Self {
351 Self { stack, state }
352 }
353 }
354
355 impl<'d, D: Device, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_nal_async::TcpConnect
356 for TcpClient<'d, D, N, TX_SZ, RX_SZ>
357 {
358 type Error = Error;
359 type Connection<'m> = TcpConnection<'m, N, TX_SZ, RX_SZ> where Self: 'm;
360 type ConnectFuture<'m> = impl Future<Output = Result<Self::Connection<'m>, Self::Error>> + 'm
361 where
362 Self: 'm;
363
364 fn connect<'m>(&'m self, remote: embedded_nal_async::SocketAddr) -> Self::ConnectFuture<'m> {
365 async move {
366 let addr: crate::IpAddress = match remote.ip() {
367 IpAddr::V4(addr) => crate::IpAddress::Ipv4(crate::Ipv4Address::from_bytes(&addr.octets())),
368 #[cfg(feature = "proto-ipv6")]
369 IpAddr::V6(addr) => crate::IpAddress::Ipv6(crate::Ipv6Address::from_bytes(&addr.octets())),
370 #[cfg(not(feature = "proto-ipv6"))]
371 IpAddr::V6(_) => panic!("ipv6 support not enabled"),
372 };
373 let remote_endpoint = (addr, remote.port());
374 let mut socket = TcpConnection::new(&self.stack, self.state)?;
375 socket
376 .socket
377 .connect(remote_endpoint)
378 .await
379 .map_err(|_| Error::ConnectionReset)?;
380 Ok(socket)
381 }
382 }
383 }
384
385 pub struct TcpConnection<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> {
386 socket: TcpSocket<'d>,
387 state: &'d TcpClientState<N, TX_SZ, RX_SZ>,
388 bufs: NonNull<([u8; TX_SZ], [u8; RX_SZ])>,
389 }
390
391 impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> TcpConnection<'d, N, TX_SZ, RX_SZ> {
392 fn new<D: Device>(stack: &'d Stack<D>, state: &'d TcpClientState<N, TX_SZ, RX_SZ>) -> Result<Self, Error> {
393 let mut bufs = state.pool.alloc().ok_or(Error::ConnectionReset)?;
394 Ok(Self {
395 socket: unsafe { TcpSocket::new(stack, &mut bufs.as_mut().0, &mut bufs.as_mut().1) },
396 state,
397 bufs,
398 })
399 }
400 }
401
402 impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> Drop for TcpConnection<'d, N, TX_SZ, RX_SZ> {
403 fn drop(&mut self) {
404 unsafe {
405 self.socket.close();
406 self.state.pool.free(self.bufs);
407 }
408 }
409 }
410
411 impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_io::Io
412 for TcpConnection<'d, N, TX_SZ, RX_SZ>
413 {
414 type Error = Error;
415 }
416
417 impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_io::asynch::Read
418 for TcpConnection<'d, N, TX_SZ, RX_SZ>
419 {
420 type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
421 where
422 Self: 'a;
423
424 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
425 self.socket.read(buf)
426 }
427 }
428
429 impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_io::asynch::Write
430 for TcpConnection<'d, N, TX_SZ, RX_SZ>
431 {
432 type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
433 where
434 Self: 'a;
435
436 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
437 self.socket.write(buf)
438 }
439
440 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>>
441 where
442 Self: 'a;
443
444 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
445 self.socket.flush()
446 }
447 }
448
449 /// State for TcpClient
450 pub struct TcpClientState<const N: usize, const TX_SZ: usize, const RX_SZ: usize> {
451 pool: Pool<([u8; TX_SZ], [u8; RX_SZ]), N>,
452 }
453
454 impl<const N: usize, const TX_SZ: usize, const RX_SZ: usize> TcpClientState<N, TX_SZ, RX_SZ> {
455 pub const fn new() -> Self {
456 Self { pool: Pool::new() }
457 }
458 }
459
460 unsafe impl<const N: usize, const TX_SZ: usize, const RX_SZ: usize> Sync for TcpClientState<N, TX_SZ, RX_SZ> {}
461
462 struct Pool<T, const N: usize> {
463 used: [AtomicBool; N],
464 data: [UnsafeCell<MaybeUninit<T>>; N],
465 }
466
467 impl<T, const N: usize> Pool<T, N> {
468 const VALUE: AtomicBool = AtomicBool::new(false);
469 const UNINIT: UnsafeCell<MaybeUninit<T>> = UnsafeCell::new(MaybeUninit::uninit());
470
471 const fn new() -> Self {
472 Self {
473 used: [Self::VALUE; N],
474 data: [Self::UNINIT; N],
475 }
476 }
477 }
478
479 impl<T, const N: usize> Pool<T, N> {
480 fn alloc(&self) -> Option<NonNull<T>> {
481 for n in 0..N {
482 if self.used[n].swap(true, Ordering::SeqCst) == false {
483 let p = self.data[n].get() as *mut T;
484 return Some(unsafe { NonNull::new_unchecked(p) });
485 }
486 }
487 None
488 }
489
490 /// safety: p must be a pointer obtained from self.alloc that hasn't been freed yet.
491 unsafe fn free(&self, p: NonNull<T>) {
492 let origin = self.data.as_ptr() as *mut T;
493 let n = p.as_ptr().offset_from(origin);
494 assert!(n >= 0);
495 assert!((n as usize) < N);
496 self.used[n as usize].store(false, Ordering::SeqCst);
497 }
498 }
499}
diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs
new file mode 100644
index 000000000..78b09a492
--- /dev/null
+++ b/embassy-net/src/udp.rs
@@ -0,0 +1,157 @@
1use core::cell::UnsafeCell;
2use core::mem;
3use core::task::Poll;
4
5use futures::future::poll_fn;
6use smoltcp::iface::{Interface, SocketHandle};
7use smoltcp::socket::udp::{self, PacketMetadata};
8use smoltcp::wire::{IpEndpoint, IpListenEndpoint};
9
10use super::stack::SocketStack;
11use crate::{Device, Stack};
12
13#[derive(PartialEq, Eq, Clone, Copy, Debug)]
14#[cfg_attr(feature = "defmt", derive(defmt::Format))]
15pub enum BindError {
16 /// The socket was already open.
17 InvalidState,
18 /// No route to host.
19 NoRoute,
20}
21
22#[derive(PartialEq, Eq, Clone, Copy, Debug)]
23#[cfg_attr(feature = "defmt", derive(defmt::Format))]
24pub enum Error {
25 /// No route to host.
26 NoRoute,
27}
28
29pub struct UdpSocket<'a> {
30 stack: &'a UnsafeCell<SocketStack>,
31 handle: SocketHandle,
32}
33
34impl<'a> UdpSocket<'a> {
35 pub fn new<D: Device>(
36 stack: &'a Stack<D>,
37 rx_meta: &'a mut [PacketMetadata],
38 rx_buffer: &'a mut [u8],
39 tx_meta: &'a mut [PacketMetadata],
40 tx_buffer: &'a mut [u8],
41 ) -> Self {
42 // safety: not accessed reentrantly.
43 let s = unsafe { &mut *stack.socket.get() };
44
45 let rx_meta: &'static mut [PacketMetadata] = unsafe { mem::transmute(rx_meta) };
46 let rx_buffer: &'static mut [u8] = unsafe { mem::transmute(rx_buffer) };
47 let tx_meta: &'static mut [PacketMetadata] = unsafe { mem::transmute(tx_meta) };
48 let tx_buffer: &'static mut [u8] = unsafe { mem::transmute(tx_buffer) };
49 let handle = s.sockets.add(udp::Socket::new(
50 udp::PacketBuffer::new(rx_meta, rx_buffer),
51 udp::PacketBuffer::new(tx_meta, tx_buffer),
52 ));
53
54 Self {
55 stack: &stack.socket,
56 handle,
57 }
58 }
59
60 pub fn bind<T>(&mut self, endpoint: T) -> Result<(), BindError>
61 where
62 T: Into<IpListenEndpoint>,
63 {
64 let mut endpoint = endpoint.into();
65
66 // safety: not accessed reentrantly.
67 if endpoint.port == 0 {
68 // If user didn't specify port allocate a dynamic port.
69 endpoint.port = unsafe { &mut *self.stack.get() }.get_local_port();
70 }
71
72 // safety: not accessed reentrantly.
73 match unsafe { self.with_mut(|s, _| s.bind(endpoint)) } {
74 Ok(()) => Ok(()),
75 Err(udp::BindError::InvalidState) => Err(BindError::InvalidState),
76 Err(udp::BindError::Unaddressable) => Err(BindError::NoRoute),
77 }
78 }
79
80 /// SAFETY: must not call reentrantly.
81 unsafe fn with<R>(&self, f: impl FnOnce(&udp::Socket, &Interface) -> R) -> R {
82 let s = &*self.stack.get();
83 let socket = s.sockets.get::<udp::Socket>(self.handle);
84 f(socket, &s.iface)
85 }
86
87 /// SAFETY: must not call reentrantly.
88 unsafe fn with_mut<R>(&self, f: impl FnOnce(&mut udp::Socket, &mut Interface) -> R) -> R {
89 let s = &mut *self.stack.get();
90 let socket = s.sockets.get_mut::<udp::Socket>(self.handle);
91 let res = f(socket, &mut s.iface);
92 s.waker.wake();
93 res
94 }
95
96 pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), Error> {
97 poll_fn(move |cx| unsafe {
98 self.with_mut(|s, _| match s.recv_slice(buf) {
99 Ok(x) => Poll::Ready(Ok(x)),
100 // No data ready
101 Err(udp::RecvError::Exhausted) => {
102 //s.register_recv_waker(cx.waker());
103 cx.waker().wake_by_ref();
104 Poll::Pending
105 }
106 })
107 })
108 .await
109 }
110
111 pub async fn send_to<T>(&self, buf: &[u8], remote_endpoint: T) -> Result<(), Error>
112 where
113 T: Into<IpEndpoint>,
114 {
115 let remote_endpoint = remote_endpoint.into();
116 poll_fn(move |cx| unsafe {
117 self.with_mut(|s, _| match s.send_slice(buf, remote_endpoint) {
118 // Entire datagram has been sent
119 Ok(()) => Poll::Ready(Ok(())),
120 Err(udp::SendError::BufferFull) => {
121 s.register_send_waker(cx.waker());
122 Poll::Pending
123 }
124 Err(udp::SendError::Unaddressable) => Poll::Ready(Err(Error::NoRoute)),
125 })
126 })
127 .await
128 }
129
130 pub fn endpoint(&self) -> IpListenEndpoint {
131 unsafe { self.with(|s, _| s.endpoint()) }
132 }
133
134 pub fn is_open(&self) -> bool {
135 unsafe { self.with(|s, _| s.is_open()) }
136 }
137
138 pub fn close(&mut self) {
139 unsafe { self.with_mut(|s, _| s.close()) }
140 }
141
142 pub fn may_send(&self) -> bool {
143 unsafe { self.with(|s, _| s.can_send()) }
144 }
145
146 pub fn may_recv(&self) -> bool {
147 unsafe { self.with(|s, _| s.can_recv()) }
148 }
149}
150
151impl Drop for UdpSocket<'_> {
152 fn drop(&mut self) {
153 // safety: not accessed reentrantly.
154 let s = unsafe { &mut *self.stack.get() };
155 s.sockets.remove(self.handle);
156 }
157}
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml
index 75780d417..0ef7f5bbd 100644
--- a/embassy-nrf/Cargo.toml
+++ b/embassy-nrf/Cargo.toml
@@ -16,7 +16,7 @@ flavors = [
16 16
17[features] 17[features]
18 18
19time = ["embassy-executor/time"] 19time = ["dep:embassy-time"]
20 20
21defmt = ["dep:defmt", "embassy-executor/defmt", "embassy-util/defmt", "embassy-usb?/defmt", "embedded-io?/defmt", "embassy-embedded-hal/defmt"] 21defmt = ["dep:defmt", "embassy-executor/defmt", "embassy-util/defmt", "embassy-usb?/defmt", "embedded-io?/defmt", "embassy-embedded-hal/defmt"]
22 22
@@ -57,7 +57,7 @@ _nrf5340-net = ["_nrf5340", "nrf5340-net-pac"]
57_nrf5340 = ["_gpio-p1", "_dppi"] 57_nrf5340 = ["_gpio-p1", "_dppi"]
58_nrf9160 = ["nrf9160-pac", "_dppi"] 58_nrf9160 = ["nrf9160-pac", "_dppi"]
59 59
60_time-driver = ["embassy-executor/time-tick-32768hz", "time"] 60_time-driver = ["dep:embassy-time", "embassy-time?/tick-32768hz"]
61 61
62_ppi = [] 62_ppi = []
63_dppi = [] 63_dppi = []
@@ -65,9 +65,9 @@ _gpio-p1 = []
65 65
66[dependencies] 66[dependencies]
67embassy-executor = { version = "0.1.0", path = "../embassy-executor", optional = true } 67embassy-executor = { version = "0.1.0", path = "../embassy-executor", optional = true }
68embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true }
68embassy-util = { version = "0.1.0", path = "../embassy-util" } 69embassy-util = { version = "0.1.0", path = "../embassy-util" }
69embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} 70embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]}
70embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]}
71embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } 71embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" }
72embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } 72embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" }
73embassy-usb = {version = "0.1.0", path = "../embassy-usb", optional=true } 73embassy-usb = {version = "0.1.0", path = "../embassy-usb", optional=true }
@@ -80,9 +80,9 @@ embedded-io = { version = "0.3.0", features = ["async"], optional = true }
80defmt = { version = "0.3", optional = true } 80defmt = { version = "0.3", optional = true }
81log = { version = "0.4.14", optional = true } 81log = { version = "0.4.14", optional = true }
82cortex-m-rt = ">=0.6.15,<0.8" 82cortex-m-rt = ">=0.6.15,<0.8"
83cortex-m = "0.7.3" 83cortex-m = "0.7.6"
84futures = { version = "0.3.17", default-features = false } 84futures = { version = "0.3.17", default-features = false }
85critical-section = "0.2.5" 85critical-section = "1.1"
86rand_core = "0.6.3" 86rand_core = "0.6.3"
87fixed = "1.10.0" 87fixed = "1.10.0"
88embedded-storage = "0.3.0" 88embedded-storage = "0.3.0"
diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs
index 8fca4da1a..d078fa0ad 100644
--- a/embassy-nrf/src/chips/nrf52805.rs
+++ b/embassy-nrf/src/chips/nrf52805.rs
@@ -197,7 +197,7 @@ impl_saadc_input!(P0_04, ANALOGINPUT2);
197impl_saadc_input!(P0_05, ANALOGINPUT3); 197impl_saadc_input!(P0_05, ANALOGINPUT3);
198 198
199pub mod irqs { 199pub mod irqs {
200 use embassy_macros::cortex_m_interrupt_declare as declare; 200 use embassy_cortex_m::interrupt::_export::declare;
201 201
202 use crate::pac::Interrupt as InterruptEnum; 202 use crate::pac::Interrupt as InterruptEnum;
203 203
diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs
index 538a617d2..faa52d8fb 100644
--- a/embassy-nrf/src/chips/nrf52810.rs
+++ b/embassy-nrf/src/chips/nrf52810.rs
@@ -218,7 +218,7 @@ impl_saadc_input!(P0_30, ANALOGINPUT6);
218impl_saadc_input!(P0_31, ANALOGINPUT7); 218impl_saadc_input!(P0_31, ANALOGINPUT7);
219 219
220pub mod irqs { 220pub mod irqs {
221 use embassy_macros::cortex_m_interrupt_declare as declare; 221 use embassy_cortex_m::interrupt::_export::declare;
222 222
223 use crate::pac::Interrupt as InterruptEnum; 223 use crate::pac::Interrupt as InterruptEnum;
224 224
diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs
index 808adf517..bbdf1cbe5 100644
--- a/embassy-nrf/src/chips/nrf52811.rs
+++ b/embassy-nrf/src/chips/nrf52811.rs
@@ -219,7 +219,7 @@ impl_saadc_input!(P0_30, ANALOGINPUT6);
219impl_saadc_input!(P0_31, ANALOGINPUT7); 219impl_saadc_input!(P0_31, ANALOGINPUT7);
220 220
221pub mod irqs { 221pub mod irqs {
222 use embassy_macros::cortex_m_interrupt_declare as declare; 222 use embassy_cortex_m::interrupt::_export::declare;
223 223
224 use crate::pac::Interrupt as InterruptEnum; 224 use crate::pac::Interrupt as InterruptEnum;
225 225
diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs
index 6be5bd361..dba033b0f 100644
--- a/embassy-nrf/src/chips/nrf52820.rs
+++ b/embassy-nrf/src/chips/nrf52820.rs
@@ -211,7 +211,7 @@ impl_ppi_channel!(PPI_CH30, 30 => static);
211impl_ppi_channel!(PPI_CH31, 31 => static); 211impl_ppi_channel!(PPI_CH31, 31 => static);
212 212
213pub mod irqs { 213pub mod irqs {
214 use embassy_macros::cortex_m_interrupt_declare as declare; 214 use embassy_cortex_m::interrupt::_export::declare;
215 215
216 use crate::pac::Interrupt as InterruptEnum; 216 use crate::pac::Interrupt as InterruptEnum;
217 217
diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs
index cdc644d6e..18b8eda67 100644
--- a/embassy-nrf/src/chips/nrf52832.rs
+++ b/embassy-nrf/src/chips/nrf52832.rs
@@ -235,7 +235,7 @@ impl_saadc_input!(P0_30, ANALOGINPUT6);
235impl_saadc_input!(P0_31, ANALOGINPUT7); 235impl_saadc_input!(P0_31, ANALOGINPUT7);
236 236
237pub mod irqs { 237pub mod irqs {
238 use embassy_macros::cortex_m_interrupt_declare as declare; 238 use embassy_cortex_m::interrupt::_export::declare;
239 239
240 use crate::pac::Interrupt as InterruptEnum; 240 use crate::pac::Interrupt as InterruptEnum;
241 241
diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs
index 4c3c5574d..39a0f93f9 100644
--- a/embassy-nrf/src/chips/nrf52833.rs
+++ b/embassy-nrf/src/chips/nrf52833.rs
@@ -278,7 +278,7 @@ impl_saadc_input!(P0_30, ANALOGINPUT6);
278impl_saadc_input!(P0_31, ANALOGINPUT7); 278impl_saadc_input!(P0_31, ANALOGINPUT7);
279 279
280pub mod irqs { 280pub mod irqs {
281 use embassy_macros::cortex_m_interrupt_declare as declare; 281 use embassy_cortex_m::interrupt::_export::declare;
282 282
283 use crate::pac::Interrupt as InterruptEnum; 283 use crate::pac::Interrupt as InterruptEnum;
284 284
diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs
index bdaeadb9b..e3d8f34a1 100644
--- a/embassy-nrf/src/chips/nrf52840.rs
+++ b/embassy-nrf/src/chips/nrf52840.rs
@@ -283,7 +283,7 @@ impl_saadc_input!(P0_30, ANALOGINPUT6);
283impl_saadc_input!(P0_31, ANALOGINPUT7); 283impl_saadc_input!(P0_31, ANALOGINPUT7);
284 284
285pub mod irqs { 285pub mod irqs {
286 use embassy_macros::cortex_m_interrupt_declare as declare; 286 use embassy_cortex_m::interrupt::_export::declare;
287 287
288 use crate::pac::Interrupt as InterruptEnum; 288 use crate::pac::Interrupt as InterruptEnum;
289 289
diff --git a/embassy-nrf/src/chips/nrf5340_app.rs b/embassy-nrf/src/chips/nrf5340_app.rs
index 26dc56bdb..edf800ef3 100644
--- a/embassy-nrf/src/chips/nrf5340_app.rs
+++ b/embassy-nrf/src/chips/nrf5340_app.rs
@@ -468,7 +468,7 @@ impl_saadc_input!(P0_19, ANALOGINPUT6);
468impl_saadc_input!(P0_20, ANALOGINPUT7); 468impl_saadc_input!(P0_20, ANALOGINPUT7);
469 469
470pub mod irqs { 470pub mod irqs {
471 use embassy_macros::cortex_m_interrupt_declare as declare; 471 use embassy_cortex_m::interrupt::_export::declare;
472 472
473 use crate::pac::Interrupt as InterruptEnum; 473 use crate::pac::Interrupt as InterruptEnum;
474 474
diff --git a/embassy-nrf/src/chips/nrf5340_net.rs b/embassy-nrf/src/chips/nrf5340_net.rs
index e28cfe013..ae136e09d 100644
--- a/embassy-nrf/src/chips/nrf5340_net.rs
+++ b/embassy-nrf/src/chips/nrf5340_net.rs
@@ -328,7 +328,7 @@ impl_ppi_channel!(PPI_CH30, 30 => configurable);
328impl_ppi_channel!(PPI_CH31, 31 => configurable); 328impl_ppi_channel!(PPI_CH31, 31 => configurable);
329 329
330pub mod irqs { 330pub mod irqs {
331 use embassy_macros::cortex_m_interrupt_declare as declare; 331 use embassy_cortex_m::interrupt::_export::declare;
332 332
333 use crate::pac::Interrupt as InterruptEnum; 333 use crate::pac::Interrupt as InterruptEnum;
334 334
diff --git a/embassy-nrf/src/chips/nrf9160.rs b/embassy-nrf/src/chips/nrf9160.rs
index 1a0bd10fe..a4be8564e 100644
--- a/embassy-nrf/src/chips/nrf9160.rs
+++ b/embassy-nrf/src/chips/nrf9160.rs
@@ -346,7 +346,7 @@ impl_saadc_input!(P0_19, ANALOGINPUT6);
346impl_saadc_input!(P0_20, ANALOGINPUT7); 346impl_saadc_input!(P0_20, ANALOGINPUT7);
347 347
348pub mod irqs { 348pub mod irqs {
349 use embassy_macros::cortex_m_interrupt_declare as declare; 349 use embassy_cortex_m::interrupt::_export::declare;
350 350
351 use crate::pac::Interrupt as InterruptEnum; 351 use crate::pac::Interrupt as InterruptEnum;
352 352
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index ad6c16c1f..f3b3ca0ca 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -135,8 +135,8 @@ pub use chip::pac;
135pub(crate) use chip::pac; 135pub(crate) use chip::pac;
136pub use chip::{peripherals, Peripherals}; 136pub use chip::{peripherals, Peripherals};
137pub use embassy_cortex_m::executor; 137pub use embassy_cortex_m::executor;
138pub use embassy_cortex_m::interrupt::_export::interrupt;
138pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; 139pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
139pub use embassy_macros::cortex_m_interrupt as interrupt;
140 140
141pub mod config { 141pub mod config {
142 //! Configuration options used when initializing the HAL. 142 //! Configuration options used when initializing the HAL.
diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs
index 05fa0aea8..b961d65a0 100644
--- a/embassy-nrf/src/time_driver.rs
+++ b/embassy-nrf/src/time_driver.rs
@@ -3,7 +3,7 @@ use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering};
3use core::{mem, ptr}; 3use core::{mem, ptr};
4 4
5use critical_section::CriticalSection; 5use critical_section::CriticalSection;
6use embassy_executor::time::driver::{AlarmHandle, Driver}; 6use embassy_time::driver::{AlarmHandle, Driver};
7use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex; 7use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex;
8use embassy_util::blocking_mutex::CriticalSectionMutex as Mutex; 8use embassy_util::blocking_mutex::CriticalSectionMutex as Mutex;
9 9
@@ -119,7 +119,7 @@ struct RtcDriver {
119} 119}
120 120
121const ALARM_STATE_NEW: AlarmState = AlarmState::new(); 121const ALARM_STATE_NEW: AlarmState = AlarmState::new();
122embassy_executor::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { 122embassy_time::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver {
123 period: AtomicU32::new(0), 123 period: AtomicU32::new(0),
124 alarm_count: AtomicU8::new(0), 124 alarm_count: AtomicU8::new(0),
125 alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]), 125 alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]),
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index 494abe0cc..9587d1f40 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -12,9 +12,9 @@ use core::sync::atomic::Ordering::SeqCst;
12use core::task::Poll; 12use core::task::Poll;
13 13
14use embassy_embedded_hal::SetConfig; 14use embassy_embedded_hal::SetConfig;
15#[cfg(feature = "time")]
16use embassy_executor::time::{Duration, Instant};
17use embassy_hal_common::{into_ref, PeripheralRef}; 15use embassy_hal_common::{into_ref, PeripheralRef};
16#[cfg(feature = "time")]
17use embassy_time::{Duration, Instant};
18use embassy_util::waitqueue::AtomicWaker; 18use embassy_util::waitqueue::AtomicWaker;
19use futures::future::poll_fn; 19use futures::future::poll_fn;
20 20
diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml
index 303617ffc..af7c8ee6e 100644
--- a/embassy-rp/Cargo.toml
+++ b/embassy-rp/Cargo.toml
@@ -28,17 +28,19 @@ unstable-traits = ["embedded-hal-1"]
28 28
29[dependencies] 29[dependencies]
30embassy-util = { version = "0.1.0", path = "../embassy-util" } 30embassy-util = { version = "0.1.0", path = "../embassy-util" }
31embassy-executor = { version = "0.1.0", path = "../embassy-executor", features = [ "time-tick-1mhz" ] } 31embassy-executor = { version = "0.1.0", path = "../embassy-executor" }
32embassy-time = { version = "0.1.0", path = "../embassy-time", features = [ "tick-1mhz" ] }
32embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} 33embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]}
33embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } 34embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" }
34embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } 35embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" }
35embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["rp"]} 36atomic-polyfill = "1.0.1"
36atomic-polyfill = "0.1.5"
37defmt = { version = "0.3", optional = true } 37defmt = { version = "0.3", optional = true }
38log = { version = "0.4.14", optional = true } 38log = { version = "0.4.14", optional = true }
39nb = "1.0.0"
40cfg-if = "1.0.0"
39cortex-m-rt = ">=0.6.15,<0.8" 41cortex-m-rt = ">=0.6.15,<0.8"
40cortex-m = "0.7.3" 42cortex-m = "0.7.6"
41critical-section = "0.2.5" 43critical-section = "1.1"
42futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 44futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
43 45
44rp2040-pac2 = { git = "https://github.com/embassy-rs/rp2040-pac2", rev="9ad7223a48a065e612bc7dc7be5bf5bd0b41cfc4", features = ["rt"] } 46rp2040-pac2 = { git = "https://github.com/embassy-rs/rp2040-pac2", rev="9ad7223a48a065e612bc7dc7be5bf5bd0b41cfc4", features = ["rt"] }
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs
index 235e92d7c..42c4fd13e 100644
--- a/embassy-rp/src/dma.rs
+++ b/embassy-rp/src/dma.rs
@@ -1,5 +1,7 @@
1use core::sync::atomic::{compiler_fence, Ordering}; 1use core::sync::atomic::{compiler_fence, Ordering};
2 2
3use embassy_hal_common::impl_peripheral;
4
3use crate::pac::dma::vals; 5use crate::pac::dma::vals;
4use crate::{pac, peripherals}; 6use crate::{pac, peripherals};
5 7
@@ -35,6 +37,10 @@ impl<T: Channel> Dma<T> {
35 } 37 }
36} 38}
37 39
40pub struct NoDma;
41
42impl_peripheral!(NoDma);
43
38mod sealed { 44mod sealed {
39 use super::*; 45 use super::*;
40 46
diff --git a/embassy-rp/src/interrupt.rs b/embassy-rp/src/interrupt.rs
index d652a8c71..f21a5433b 100644
--- a/embassy-rp/src/interrupt.rs
+++ b/embassy-rp/src/interrupt.rs
@@ -4,8 +4,8 @@
4//! nrf_softdevice::interrupt. Intended for switching between the two at compile-time. 4//! nrf_softdevice::interrupt. Intended for switching between the two at compile-time.
5 5
6// Re-exports 6// Re-exports
7use embassy_cortex_m::interrupt::_export::declare;
7pub use embassy_cortex_m::interrupt::*; 8pub use embassy_cortex_m::interrupt::*;
8use embassy_macros::cortex_m_interrupt_declare as declare;
9 9
10use crate::pac::Interrupt as InterruptEnum; 10use crate::pac::Interrupt as InterruptEnum;
11declare!(TIMER_IRQ_0); 11declare!(TIMER_IRQ_0);
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs
index 44150be0d..8c053a4f7 100644
--- a/embassy-rp/src/lib.rs
+++ b/embassy-rp/src/lib.rs
@@ -17,8 +17,8 @@ mod reset;
17// Reexports 17// Reexports
18 18
19pub use embassy_cortex_m::executor; 19pub use embassy_cortex_m::executor;
20pub use embassy_cortex_m::interrupt::_export::interrupt;
20pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; 21pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
21pub use embassy_macros::cortex_m_interrupt as interrupt;
22#[cfg(feature = "unstable-pac")] 22#[cfg(feature = "unstable-pac")]
23pub use rp2040_pac2 as pac; 23pub use rp2040_pac2 as pac;
24#[cfg(not(feature = "unstable-pac"))] 24#[cfg(not(feature = "unstable-pac"))]
diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs
index 142fd410d..5bc1f66c8 100644
--- a/embassy-rp/src/timer.rs
+++ b/embassy-rp/src/timer.rs
@@ -2,7 +2,7 @@ use core::cell::Cell;
2 2
3use atomic_polyfill::{AtomicU8, Ordering}; 3use atomic_polyfill::{AtomicU8, Ordering};
4use critical_section::CriticalSection; 4use critical_section::CriticalSection;
5use embassy_executor::time::driver::{AlarmHandle, Driver}; 5use embassy_time::driver::{AlarmHandle, Driver};
6use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex; 6use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex;
7use embassy_util::blocking_mutex::Mutex; 7use embassy_util::blocking_mutex::Mutex;
8 8
@@ -26,7 +26,7 @@ struct TimerDriver {
26 next_alarm: AtomicU8, 26 next_alarm: AtomicU8,
27} 27}
28 28
29embassy_executor::time_driver_impl!(static DRIVER: TimerDriver = TimerDriver{ 29embassy_time::time_driver_impl!(static DRIVER: TimerDriver = TimerDriver{
30 alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [DUMMY_ALARM; ALARM_COUNT]), 30 alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [DUMMY_ALARM; ALARM_COUNT]),
31 next_alarm: AtomicU8::new(0), 31 next_alarm: AtomicU8::new(0),
32}); 32});
diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs
index b19f043f8..6c5ab3515 100644
--- a/embassy-rp/src/uart.rs
+++ b/embassy-rp/src/uart.rs
@@ -1,42 +1,199 @@
1use core::marker::PhantomData;
2
1use embassy_hal_common::{into_ref, PeripheralRef}; 3use embassy_hal_common::{into_ref, PeripheralRef};
2use gpio::Pin;
3 4
4use crate::{gpio, pac, peripherals, Peripheral}; 5use crate::gpio::sealed::Pin;
6use crate::gpio::AnyPin;
7use crate::{pac, peripherals, Peripheral};
8
9#[derive(Clone, Copy, PartialEq, Eq, Debug)]
10pub enum DataBits {
11 DataBits5,
12 DataBits6,
13 DataBits7,
14 DataBits8,
15}
16
17impl DataBits {
18 fn bits(&self) -> u8 {
19 match self {
20 Self::DataBits5 => 0b00,
21 Self::DataBits6 => 0b01,
22 Self::DataBits7 => 0b10,
23 Self::DataBits8 => 0b11,
24 }
25 }
26}
27
28#[derive(Clone, Copy, PartialEq, Eq, Debug)]
29pub enum Parity {
30 ParityNone,
31 ParityEven,
32 ParityOdd,
33}
34
35#[derive(Clone, Copy, PartialEq, Eq, Debug)]
36pub enum StopBits {
37 #[doc = "1 stop bit"]
38 STOP1,
39 #[doc = "2 stop bits"]
40 STOP2,
41}
5 42
6#[non_exhaustive] 43#[non_exhaustive]
44#[derive(Clone, Copy, PartialEq, Eq, Debug)]
7pub struct Config { 45pub struct Config {
8 pub baudrate: u32, 46 pub baudrate: u32,
9 pub data_bits: u8, 47 pub data_bits: DataBits,
10 pub stop_bits: u8, 48 pub stop_bits: StopBits,
49 pub parity: Parity,
11} 50}
12 51
13impl Default for Config { 52impl Default for Config {
14 fn default() -> Self { 53 fn default() -> Self {
15 Self { 54 Self {
16 baudrate: 115200, 55 baudrate: 115200,
17 data_bits: 8, 56 data_bits: DataBits::DataBits8,
18 stop_bits: 1, 57 stop_bits: StopBits::STOP1,
58 parity: Parity::ParityNone,
19 } 59 }
20 } 60 }
21} 61}
22 62
63/// Serial error
64#[derive(Debug, Eq, PartialEq, Copy, Clone)]
65#[cfg_attr(feature = "defmt", derive(defmt::Format))]
66#[non_exhaustive]
67pub enum Error {
68 /// Triggered when the FIFO (or shift-register) is overflowed.
69 Overrun,
70 /// Triggered when a break is received
71 Break,
72 /// Triggered when there is a parity mismatch between what's received and
73 /// our settings.
74 Parity,
75 /// Triggered when the received character didn't have a valid stop bit.
76 Framing,
77}
78
23pub struct Uart<'d, T: Instance> { 79pub struct Uart<'d, T: Instance> {
24 inner: PeripheralRef<'d, T>, 80 tx: UartTx<'d, T>,
81 rx: UartRx<'d, T>,
82}
83
84pub struct UartTx<'d, T: Instance> {
85 phantom: PhantomData<&'d mut T>,
86}
87
88pub struct UartRx<'d, T: Instance> {
89 phantom: PhantomData<&'d mut T>,
90}
91
92impl<'d, T: Instance> UartTx<'d, T> {
93 fn new() -> Self {
94 Self { phantom: PhantomData }
95 }
96
97 pub async fn write(&mut self, _buffer: &[u8]) -> Result<(), Error> {
98 todo!()
99 }
100
101 pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> {
102 let r = T::regs();
103 unsafe {
104 for &b in buffer {
105 while r.uartfr().read().txff() {}
106 r.uartdr().write(|w| w.set_data(b));
107 }
108 }
109 Ok(())
110 }
111
112 pub fn blocking_flush(&mut self) -> Result<(), Error> {
113 let r = T::regs();
114 unsafe { while r.uartfr().read().txff() {} }
115 Ok(())
116 }
117}
118
119impl<'d, T: Instance> UartRx<'d, T> {
120 fn new() -> Self {
121 Self { phantom: PhantomData }
122 }
123
124 pub async fn read(&mut self, _buffer: &mut [u8]) -> Result<(), Error> {
125 todo!();
126 }
127
128 pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
129 let r = T::regs();
130 unsafe {
131 for b in buffer {
132 *b = loop {
133 let dr = r.uartdr().read();
134
135 if dr.oe() {
136 return Err(Error::Overrun);
137 } else if dr.be() {
138 return Err(Error::Break);
139 } else if dr.pe() {
140 return Err(Error::Parity);
141 } else if dr.fe() {
142 return Err(Error::Framing);
143 } else if dr.fe() {
144 break dr.data();
145 }
146 };
147 }
148 }
149 Ok(())
150 }
25} 151}
26 152
27impl<'d, T: Instance> Uart<'d, T> { 153impl<'d, T: Instance> Uart<'d, T> {
154 /// Create a new UART without hardware flow control
28 pub fn new( 155 pub fn new(
29 inner: impl Peripheral<P = T> + 'd, 156 uart: impl Peripheral<P = T> + 'd,
157 tx: impl Peripheral<P = impl TxPin<T>> + 'd,
158 rx: impl Peripheral<P = impl RxPin<T>> + 'd,
159 config: Config,
160 ) -> Self {
161 into_ref!(tx, rx);
162 Self::new_inner(uart, rx.map_into(), tx.map_into(), None, None, config)
163 }
164
165 /// Create a new UART with hardware flow control (RTS/CTS)
166 pub fn new_with_rtscts(
167 uart: impl Peripheral<P = T> + 'd,
30 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 168 tx: impl Peripheral<P = impl TxPin<T>> + 'd,
31 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 169 rx: impl Peripheral<P = impl RxPin<T>> + 'd,
32 cts: impl Peripheral<P = impl CtsPin<T>> + 'd, 170 cts: impl Peripheral<P = impl CtsPin<T>> + 'd,
33 rts: impl Peripheral<P = impl RtsPin<T>> + 'd, 171 rts: impl Peripheral<P = impl RtsPin<T>> + 'd,
34 config: Config, 172 config: Config,
35 ) -> Self { 173 ) -> Self {
36 into_ref!(inner, tx, rx, cts, rts); 174 into_ref!(tx, rx, cts, rts);
175 Self::new_inner(
176 uart,
177 rx.map_into(),
178 tx.map_into(),
179 Some(cts.map_into()),
180 Some(rts.map_into()),
181 config,
182 )
183 }
184
185 fn new_inner(
186 _uart: impl Peripheral<P = T> + 'd,
187 tx: PeripheralRef<'d, AnyPin>,
188 rx: PeripheralRef<'d, AnyPin>,
189 cts: Option<PeripheralRef<'d, AnyPin>>,
190 rts: Option<PeripheralRef<'d, AnyPin>>,
191 config: Config,
192 ) -> Self {
193 into_ref!(_uart);
37 194
38 unsafe { 195 unsafe {
39 let p = inner.regs(); 196 let r = T::regs();
40 197
41 let clk_base = crate::clocks::clk_peri_freq(); 198 let clk_base = crate::clocks::clk_peri_freq();
42 199
@@ -53,49 +210,217 @@ impl<'d, T: Instance> Uart<'d, T> {
53 } 210 }
54 211
55 // Load PL011's baud divisor registers 212 // Load PL011's baud divisor registers
56 p.uartibrd().write_value(pac::uart::regs::Uartibrd(baud_ibrd)); 213 r.uartibrd().write_value(pac::uart::regs::Uartibrd(baud_ibrd));
57 p.uartfbrd().write_value(pac::uart::regs::Uartfbrd(baud_fbrd)); 214 r.uartfbrd().write_value(pac::uart::regs::Uartfbrd(baud_fbrd));
58 215
59 p.uartlcr_h().write(|w| { 216 let (pen, eps) = match config.parity {
60 w.set_wlen(config.data_bits - 5); 217 Parity::ParityNone => (false, false),
61 w.set_stp2(config.stop_bits == 2); 218 Parity::ParityEven => (true, true),
62 w.set_pen(false); 219 Parity::ParityOdd => (true, false),
63 w.set_eps(false); 220 };
221
222 r.uartlcr_h().write(|w| {
223 w.set_wlen(config.data_bits.bits());
224 w.set_stp2(config.stop_bits == StopBits::STOP2);
225 w.set_pen(pen);
226 w.set_eps(eps);
64 w.set_fen(true); 227 w.set_fen(true);
65 }); 228 });
66 229
67 p.uartcr().write(|w| { 230 r.uartcr().write(|w| {
68 w.set_uarten(true); 231 w.set_uarten(true);
69 w.set_rxe(true); 232 w.set_rxe(true);
70 w.set_txe(true); 233 w.set_txe(true);
234 w.set_ctsen(cts.is_some());
235 w.set_rtsen(rts.is_some());
71 }); 236 });
72 237
73 tx.io().ctrl().write(|w| w.set_funcsel(2)); 238 tx.io().ctrl().write(|w| w.set_funcsel(2));
74 rx.io().ctrl().write(|w| w.set_funcsel(2)); 239 rx.io().ctrl().write(|w| w.set_funcsel(2));
75 cts.io().ctrl().write(|w| w.set_funcsel(2)); 240 if let Some(pin) = &cts {
76 rts.io().ctrl().write(|w| w.set_funcsel(2)); 241 pin.io().ctrl().write(|w| w.set_funcsel(2));
242 }
243 if let Some(pin) = &rts {
244 pin.io().ctrl().write(|w| w.set_funcsel(2));
245 }
246 }
247
248 Self {
249 tx: UartTx::new(),
250 rx: UartRx::new(),
77 } 251 }
78 Self { inner }
79 } 252 }
80 253
81 pub fn send(&mut self, data: &[u8]) { 254 pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> {
82 unsafe { 255 self.tx.write(buffer).await
83 let p = self.inner.regs(); 256 }
257
258 pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> {
259 self.tx.blocking_write(buffer)
260 }
84 261
85 for &byte in data { 262 pub fn blocking_flush(&mut self) -> Result<(), Error> {
86 if !p.uartfr().read().txff() { 263 self.tx.blocking_flush()
87 p.uartdr().write(|w| w.set_data(byte)); 264 }
265
266 pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
267 self.rx.read(buffer).await
268 }
269
270 pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
271 self.rx.blocking_read(buffer)
272 }
273
274 /// Split the Uart into a transmitter and receiver, which is
275 /// particuarly useful when having two tasks correlating to
276 /// transmitting and receiving.
277 pub fn split(self) -> (UartTx<'d, T>, UartRx<'d, T>) {
278 (self.tx, self.rx)
279 }
280}
281
282mod eh02 {
283 use super::*;
284
285 impl<'d, T: Instance> embedded_hal_02::serial::Read<u8> for UartRx<'d, T> {
286 type Error = Error;
287 fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> {
288 let r = T::regs();
289 unsafe {
290 let dr = r.uartdr().read();
291
292 if dr.oe() {
293 Err(nb::Error::Other(Error::Overrun))
294 } else if dr.be() {
295 Err(nb::Error::Other(Error::Break))
296 } else if dr.pe() {
297 Err(nb::Error::Other(Error::Parity))
298 } else if dr.fe() {
299 Err(nb::Error::Other(Error::Framing))
300 } else if dr.fe() {
301 Ok(dr.data())
302 } else {
303 Err(nb::Error::WouldBlock)
88 } 304 }
89 } 305 }
90 } 306 }
91 } 307 }
308
309 impl<'d, T: Instance> embedded_hal_02::blocking::serial::Write<u8> for UartTx<'d, T> {
310 type Error = Error;
311 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
312 self.blocking_write(buffer)
313 }
314 fn bflush(&mut self) -> Result<(), Self::Error> {
315 self.blocking_flush()
316 }
317 }
318
319 impl<'d, T: Instance> embedded_hal_02::serial::Read<u8> for Uart<'d, T> {
320 type Error = Error;
321 fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> {
322 embedded_hal_02::serial::Read::read(&mut self.rx)
323 }
324 }
325
326 impl<'d, T: Instance> embedded_hal_02::blocking::serial::Write<u8> for Uart<'d, T> {
327 type Error = Error;
328 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
329 self.blocking_write(buffer)
330 }
331 fn bflush(&mut self) -> Result<(), Self::Error> {
332 self.blocking_flush()
333 }
334 }
335}
336
337#[cfg(feature = "unstable-traits")]
338mod eh1 {
339 use super::*;
340
341 impl embedded_hal_1::serial::Error for Error {
342 fn kind(&self) -> embedded_hal_1::serial::ErrorKind {
343 match *self {
344 Self::Framing => embedded_hal_1::serial::ErrorKind::FrameFormat,
345 Self::Break => embedded_hal_1::serial::ErrorKind::Other,
346 Self::Overrun => embedded_hal_1::serial::ErrorKind::Overrun,
347 Self::Parity => embedded_hal_1::serial::ErrorKind::Parity,
348 }
349 }
350 }
351
352 impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for Uart<'d, T> {
353 type Error = Error;
354 }
355
356 impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for UartTx<'d, T> {
357 type Error = Error;
358 }
359
360 impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for UartRx<'d, T> {
361 type Error = Error;
362 }
363}
364
365cfg_if::cfg_if! {
366 if #[cfg(all(feature = "unstable-traits", feature = "nightly", feature = "_todo_embedded_hal_serial"))] {
367 use core::future::Future;
368
369 impl<'d, T: Instance> embedded_hal_async::serial::Write for UartTx<'d, T>
370 {
371 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
372
373 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
374 self.write(buf)
375 }
376
377 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
378
379 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
380 async move { Ok(()) }
381 }
382 }
383
384 impl<'d, T: Instance> embedded_hal_async::serial::Read for UartRx<'d, T>
385 {
386 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
387
388 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
389 self.read(buf)
390 }
391 }
392
393 impl<'d, T: Instance> embedded_hal_async::serial::Write for Uart<'d, T>
394 {
395 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
396
397 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
398 self.write(buf)
399 }
400
401 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
402
403 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
404 async move { Ok(()) }
405 }
406 }
407
408 impl<'d, T: Instance> embedded_hal_async::serial::Read for Uart<'d, T>
409 {
410 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
411
412 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
413 self.read(buf)
414 }
415 }
416 }
92} 417}
93 418
94mod sealed { 419mod sealed {
95 use super::*; 420 use super::*;
96 421
97 pub trait Instance { 422 pub trait Instance {
98 fn regs(&self) -> pac::uart::Uart; 423 fn regs() -> pac::uart::Uart;
99 } 424 }
100 pub trait TxPin<T: Instance> {} 425 pub trait TxPin<T: Instance> {}
101 pub trait RxPin<T: Instance> {} 426 pub trait RxPin<T: Instance> {}
@@ -106,23 +431,23 @@ mod sealed {
106pub trait Instance: sealed::Instance {} 431pub trait Instance: sealed::Instance {}
107 432
108macro_rules! impl_instance { 433macro_rules! impl_instance {
109 ($type:ident, $irq:ident) => { 434 ($inst:ident, $irq:ident) => {
110 impl sealed::Instance for peripherals::$type { 435 impl sealed::Instance for peripherals::$inst {
111 fn regs(&self) -> pac::uart::Uart { 436 fn regs() -> pac::uart::Uart {
112 pac::$type 437 pac::$inst
113 } 438 }
114 } 439 }
115 impl Instance for peripherals::$type {} 440 impl Instance for peripherals::$inst {}
116 }; 441 };
117} 442}
118 443
119impl_instance!(UART0, UART0); 444impl_instance!(UART0, UART0);
120impl_instance!(UART1, UART1); 445impl_instance!(UART1, UART1);
121 446
122pub trait TxPin<T: Instance>: sealed::TxPin<T> + Pin {} 447pub trait TxPin<T: Instance>: sealed::TxPin<T> + crate::gpio::Pin {}
123pub trait RxPin<T: Instance>: sealed::RxPin<T> + Pin {} 448pub trait RxPin<T: Instance>: sealed::RxPin<T> + crate::gpio::Pin {}
124pub trait CtsPin<T: Instance>: sealed::CtsPin<T> + Pin {} 449pub trait CtsPin<T: Instance>: sealed::CtsPin<T> + crate::gpio::Pin {}
125pub trait RtsPin<T: Instance>: sealed::RtsPin<T> + Pin {} 450pub trait RtsPin<T: Instance>: sealed::RtsPin<T> + crate::gpio::Pin {}
126 451
127macro_rules! impl_pin { 452macro_rules! impl_pin {
128 ($pin:ident, $instance:ident, $function:ident) => { 453 ($pin:ident, $instance:ident, $function:ident) => {
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index ff228cc85..c47ea0bca 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -10,7 +10,7 @@ src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-stm32
10# TODO: sdmmc 10# TODO: sdmmc
11# TODO: net 11# TODO: net
12# TODO: subghz 12# TODO: subghz
13features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "exti", "time-driver-any", "embassy-executor/time-tick-32768hz"] 13features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "exti", "time-driver-any", "embassy-time/tick-32768hz"]
14flavors = [ 14flavors = [
15 { regex_feature = "stm32f0.*", target = "thumbv6m-none-eabi" }, 15 { regex_feature = "stm32f0.*", target = "thumbv6m-none-eabi" },
16 { regex_feature = "stm32f1.*", target = "thumbv7m-none-eabi" }, 16 { regex_feature = "stm32f1.*", target = "thumbv7m-none-eabi" },
@@ -33,8 +33,8 @@ flavors = [
33[dependencies] 33[dependencies]
34embassy-util = { version = "0.1.0", path = "../embassy-util" } 34embassy-util = { version = "0.1.0", path = "../embassy-util" }
35embassy-executor = { version = "0.1.0", path = "../embassy-executor" } 35embassy-executor = { version = "0.1.0", path = "../embassy-executor" }
36embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true }
36embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-4"]} 37embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-4"]}
37embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] }
38embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } 38embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" }
39embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } 39embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" }
40embassy-net = { version = "0.1.0", path = "../embassy-net", optional = true } 40embassy-net = { version = "0.1.0", path = "../embassy-net", optional = true }
@@ -50,14 +50,13 @@ embedded-storage-async = { version = "0.3.0", optional = true }
50defmt = { version = "0.3", optional = true } 50defmt = { version = "0.3", optional = true }
51log = { version = "0.4.14", optional = true } 51log = { version = "0.4.14", optional = true }
52cortex-m-rt = ">=0.6.15,<0.8" 52cortex-m-rt = ">=0.6.15,<0.8"
53cortex-m = "0.7.3" 53cortex-m = "0.7.6"
54futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 54futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
55rand_core = "0.6.3" 55rand_core = "0.6.3"
56sdio-host = "0.5.0" 56sdio-host = "0.5.0"
57embedded-sdmmc = { git = "https://github.com/thalesfragoso/embedded-sdmmc-rs", branch = "async", optional = true } 57embedded-sdmmc = { git = "https://github.com/thalesfragoso/embedded-sdmmc-rs", branch = "async", optional = true }
58critical-section = "0.2.5" 58critical-section = "1.1"
59bare-metal = "1.0.0" 59atomic-polyfill = "1.0.1"
60atomic-polyfill = "0.1.5"
61stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", features = ["rt"] } 60stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", features = ["rt"] }
62vcell = "0.1.3" 61vcell = "0.1.3"
63bxcan = "0.7.0" 62bxcan = "0.7.0"
@@ -82,7 +81,7 @@ exti = []
82 81
83# Features starting with `_` are for internal use only. They're not intended 82# Features starting with `_` are for internal use only. They're not intended
84# to be enabled by other crates, and are not covered by semver guarantees. 83# to be enabled by other crates, and are not covered by semver guarantees.
85_time-driver = ["embassy-executor/time"] 84_time-driver = ["dep:embassy-time"]
86time-driver-any = ["_time-driver"] 85time-driver-any = ["_time-driver"]
87time-driver-tim2 = ["_time-driver"] 86time-driver-tim2 = ["_time-driver"]
88time-driver-tim3 = ["_time-driver"] 87time-driver-tim3 = ["_time-driver"]
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index 3b4aa5dfd..c892007a3 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -96,7 +96,7 @@ fn main() {
96 g.extend(quote! { 96 g.extend(quote! {
97 pub mod interrupt { 97 pub mod interrupt {
98 use crate::pac::Interrupt as InterruptEnum; 98 use crate::pac::Interrupt as InterruptEnum;
99 use embassy_macros::cortex_m_interrupt_declare as declare; 99 use embassy_cortex_m::interrupt::_export::declare;
100 #( 100 #(
101 declare!(#irqs); 101 declare!(#irqs);
102 )* 102 )*
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index 3c4cdb887..d794e3989 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -213,7 +213,7 @@ impl<'d, T: Pin> Drop for Flex<'d, T> {
213} 213}
214 214
215/// Pull setting for an input. 215/// Pull setting for an input.
216#[derive(Debug, Eq, PartialEq)] 216#[derive(Debug, Eq, PartialEq, Copy, Clone)]
217#[cfg_attr(feature = "defmt", derive(defmt::Format))] 217#[cfg_attr(feature = "defmt", derive(defmt::Format))]
218pub enum Pull { 218pub enum Pull {
219 None, 219 None,
@@ -235,7 +235,7 @@ impl From<Pull> for vals::Pupdr {
235} 235}
236 236
237/// Speed settings 237/// Speed settings
238#[derive(Debug)] 238#[derive(Debug, Copy, Clone)]
239#[cfg_attr(feature = "defmt", derive(defmt::Format))] 239#[cfg_attr(feature = "defmt", derive(defmt::Format))]
240pub enum Speed { 240pub enum Speed {
241 Low, 241 Low,
@@ -303,7 +303,7 @@ impl<'d, T: Pin> Input<'d, T> {
303} 303}
304 304
305/// Digital input or output level. 305/// Digital input or output level.
306#[derive(Debug, Eq, PartialEq)] 306#[derive(Debug, Eq, PartialEq, Copy, Clone)]
307#[cfg_attr(feature = "defmt", derive(defmt::Format))] 307#[cfg_attr(feature = "defmt", derive(defmt::Format))]
308pub enum Level { 308pub enum Level {
309 Low, 309 Low,
@@ -470,7 +470,7 @@ pub(crate) mod sealed {
470 use super::*; 470 use super::*;
471 471
472 /// Alternate function type settings 472 /// Alternate function type settings
473 #[derive(Debug)] 473 #[derive(Debug, Copy, Clone)]
474 #[cfg_attr(feature = "defmt", derive(defmt::Format))] 474 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
475 pub enum AFType { 475 pub enum AFType {
476 Input, 476 Input,
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs
index 613815a9c..9dc75789a 100644
--- a/embassy-stm32/src/i2c/v1.rs
+++ b/embassy-stm32/src/i2c/v1.rs
@@ -4,11 +4,28 @@ use embassy_embedded_hal::SetConfig;
4use embassy_hal_common::into_ref; 4use embassy_hal_common::into_ref;
5 5
6use crate::gpio::sealed::AFType; 6use crate::gpio::sealed::AFType;
7use crate::gpio::Pull;
7use crate::i2c::{Error, Instance, SclPin, SdaPin}; 8use crate::i2c::{Error, Instance, SclPin, SdaPin};
8use crate::pac::i2c; 9use crate::pac::i2c;
9use crate::time::Hertz; 10use crate::time::Hertz;
10use crate::Peripheral; 11use crate::Peripheral;
11 12
13#[non_exhaustive]
14#[derive(Copy, Clone)]
15pub struct Config {
16 pub sda_pullup: bool,
17 pub scl_pullup: bool,
18}
19
20impl Default for Config {
21 fn default() -> Self {
22 Self {
23 sda_pullup: false,
24 scl_pullup: false,
25 }
26 }
27}
28
12pub struct State {} 29pub struct State {}
13 30
14impl State { 31impl State {
@@ -27,6 +44,7 @@ impl<'d, T: Instance> I2c<'d, T> {
27 scl: impl Peripheral<P = impl SclPin<T>> + 'd, 44 scl: impl Peripheral<P = impl SclPin<T>> + 'd,
28 sda: impl Peripheral<P = impl SdaPin<T>> + 'd, 45 sda: impl Peripheral<P = impl SdaPin<T>> + 'd,
29 freq: Hertz, 46 freq: Hertz,
47 config: Config,
30 ) -> Self { 48 ) -> Self {
31 into_ref!(scl, sda); 49 into_ref!(scl, sda);
32 50
@@ -34,8 +52,22 @@ impl<'d, T: Instance> I2c<'d, T> {
34 T::reset(); 52 T::reset();
35 53
36 unsafe { 54 unsafe {
37 scl.set_as_af(scl.af_num(), AFType::OutputOpenDrain); 55 scl.set_as_af_pull(
38 sda.set_as_af(sda.af_num(), AFType::OutputOpenDrain); 56 scl.af_num(),
57 AFType::OutputOpenDrain,
58 match config.scl_pullup {
59 true => Pull::Up,
60 false => Pull::None,
61 },
62 );
63 sda.set_as_af_pull(
64 sda.af_num(),
65 AFType::OutputOpenDrain,
66 match config.sda_pullup {
67 true => Pull::Up,
68 false => Pull::None,
69 },
70 );
39 } 71 }
40 72
41 unsafe { 73 unsafe {
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index f8067e8b3..b4303d3d4 100644
--- a/embassy-stm32/src/i2c/v2.rs
+++ b/embassy-stm32/src/i2c/v2.rs
@@ -10,12 +10,29 @@ use futures::future::poll_fn;
10 10
11use crate::dma::NoDma; 11use crate::dma::NoDma;
12use crate::gpio::sealed::AFType; 12use crate::gpio::sealed::AFType;
13use crate::gpio::Pull;
13use crate::i2c::{Error, Instance, SclPin, SdaPin}; 14use crate::i2c::{Error, Instance, SclPin, SdaPin};
14use crate::interrupt::InterruptExt; 15use crate::interrupt::InterruptExt;
15use crate::pac::i2c; 16use crate::pac::i2c;
16use crate::time::Hertz; 17use crate::time::Hertz;
17use crate::Peripheral; 18use crate::Peripheral;
18 19
20#[non_exhaustive]
21#[derive(Copy, Clone)]
22pub struct Config {
23 pub sda_pullup: bool,
24 pub scl_pullup: bool,
25}
26
27impl Default for Config {
28 fn default() -> Self {
29 Self {
30 sda_pullup: false,
31 scl_pullup: false,
32 }
33 }
34}
35
19pub struct State { 36pub struct State {
20 waker: AtomicWaker, 37 waker: AtomicWaker,
21 chunks_transferred: AtomicUsize, 38 chunks_transferred: AtomicUsize,
@@ -46,6 +63,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
46 tx_dma: impl Peripheral<P = TXDMA> + 'd, 63 tx_dma: impl Peripheral<P = TXDMA> + 'd,
47 rx_dma: impl Peripheral<P = RXDMA> + 'd, 64 rx_dma: impl Peripheral<P = RXDMA> + 'd,
48 freq: Hertz, 65 freq: Hertz,
66 config: Config,
49 ) -> Self { 67 ) -> Self {
50 into_ref!(peri, irq, scl, sda, tx_dma, rx_dma); 68 into_ref!(peri, irq, scl, sda, tx_dma, rx_dma);
51 69
@@ -53,8 +71,22 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
53 T::reset(); 71 T::reset();
54 72
55 unsafe { 73 unsafe {
56 scl.set_as_af(scl.af_num(), AFType::OutputOpenDrain); 74 scl.set_as_af_pull(
57 sda.set_as_af(sda.af_num(), AFType::OutputOpenDrain); 75 scl.af_num(),
76 AFType::OutputOpenDrain,
77 match config.scl_pullup {
78 true => Pull::Up,
79 false => Pull::None,
80 },
81 );
82 sda.set_as_af_pull(
83 sda.af_num(),
84 AFType::OutputOpenDrain,
85 match config.sda_pullup {
86 true => Pull::Up,
87 false => Pull::None,
88 },
89 );
58 } 90 }
59 91
60 unsafe { 92 unsafe {
diff --git a/embassy-stm32/src/interrupt.rs b/embassy-stm32/src/interrupt.rs
index 9dc1f2044..b66e4c7ef 100644
--- a/embassy-stm32/src/interrupt.rs
+++ b/embassy-stm32/src/interrupt.rs
@@ -1,5 +1,4 @@
1pub use bare_metal::Mutex; 1pub use critical_section::{CriticalSection, Mutex};
2pub use critical_section::CriticalSection;
3pub use embassy_cortex_m::interrupt::*; 2pub use embassy_cortex_m::interrupt::*;
4 3
5pub use crate::_generated::interrupt::*; 4pub use crate::_generated::interrupt::*;
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 78025f3db..30ff02d56 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -75,8 +75,8 @@ pub(crate) mod _generated {
75// Reexports 75// Reexports
76pub use _generated::{peripherals, Peripherals}; 76pub use _generated::{peripherals, Peripherals};
77pub use embassy_cortex_m::executor; 77pub use embassy_cortex_m::executor;
78pub use embassy_cortex_m::interrupt::_export::interrupt;
78pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; 79pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
79pub use embassy_macros::cortex_m_interrupt as interrupt;
80#[cfg(feature = "unstable-pac")] 80#[cfg(feature = "unstable-pac")]
81pub use stm32_metapac as pac; 81pub use stm32_metapac as pac;
82#[cfg(not(feature = "unstable-pac"))] 82#[cfg(not(feature = "unstable-pac"))]
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs
index 1f7e39070..960c45322 100644
--- a/embassy-stm32/src/rcc/u5.rs
+++ b/embassy-stm32/src/rcc/u5.rs
@@ -63,7 +63,7 @@ seq_macro::seq!(N in 2..=128 {
63 match self { 63 match self {
64 PllClkDiv::NotDivided => 1, 64 PllClkDiv::NotDivided => 1,
65 #( 65 #(
66 PllClkDiv::Div~N => (N + 1), 66 PllClkDiv::Div~N => N + 1,
67 )* 67 )*
68 } 68 }
69 } 69 }
@@ -81,7 +81,7 @@ seq_macro::seq!(N in 4..=512 {
81 pub enum PllN { 81 pub enum PllN {
82 NotMultiplied, 82 NotMultiplied,
83 #( 83 #(
84 Mul~N = (N-1), 84 Mul~N = N-1,
85 )* 85 )*
86 } 86 }
87 87
@@ -90,7 +90,7 @@ seq_macro::seq!(N in 4..=512 {
90 match self { 90 match self {
91 PllN::NotMultiplied => 1, 91 PllN::NotMultiplied => 1,
92 #( 92 #(
93 PllN::Mul~N => (N + 1), 93 PllN::Mul~N => N + 1,
94 )* 94 )*
95 } 95 }
96 } 96 }
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs
index 1de4b2aa6..3ad31ec87 100644
--- a/embassy-stm32/src/sdmmc/mod.rs
+++ b/embassy-stm32/src/sdmmc/mod.rs
@@ -999,10 +999,17 @@ impl SdmmcInner {
999 fn clkcr_set_clkdiv(&self, freq: u32, width: BusWidth, ker_ck: Hertz, clock: &mut Hertz) -> Result<(), Error> { 999 fn clkcr_set_clkdiv(&self, freq: u32, width: BusWidth, ker_ck: Hertz, clock: &mut Hertz) -> Result<(), Error> {
1000 let regs = self.0; 1000 let regs = self.0;
1001 1001
1002 let width_u32 = match width {
1003 BusWidth::One => 1u32,
1004 BusWidth::Four => 4u32,
1005 BusWidth::Eight => 8u32,
1006 _ => panic!("Invalid Bus Width"),
1007 };
1008
1002 let (clkdiv, new_clock) = clk_div(ker_ck, freq)?; 1009 let (clkdiv, new_clock) = clk_div(ker_ck, freq)?;
1003 // Enforce AHB and SDMMC_CK clock relation. See RM0433 Rev 7 1010 // Enforce AHB and SDMMC_CK clock relation. See RM0433 Rev 7
1004 // Section 55.5.8 1011 // Section 55.5.8
1005 let sdmmc_bus_bandwidth = new_clock.0 * (width as u32); 1012 let sdmmc_bus_bandwidth = new_clock.0 * width_u32;
1006 assert!(ker_ck.0 > 3 * sdmmc_bus_bandwidth / 32); 1013 assert!(ker_ck.0 > 3 * sdmmc_bus_bandwidth / 32);
1007 *clock = new_clock; 1014 *clock = new_clock;
1008 1015
diff --git a/embassy-stm32/src/subghz/mod.rs b/embassy-stm32/src/subghz/mod.rs
index 4e53efed5..a74f9a6d5 100644
--- a/embassy-stm32/src/subghz/mod.rs
+++ b/embassy-stm32/src/subghz/mod.rs
@@ -504,7 +504,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
504 /// 504 ///
505 /// sg.set_standby(StandbyClk::Rc)?; 505 /// sg.set_standby(StandbyClk::Rc)?;
506 /// unsafe { sg.set_sleep(SleepCfg::default())? }; 506 /// unsafe { sg.set_sleep(SleepCfg::default())? };
507 /// embassy_executor::time::Timer::after(embassy_executor::time::Duration::from_micros(500)).await; 507 /// embassy_time::Timer::after(embassy_time::Duration::from_micros(500)).await;
508 /// unsafe { wakeup() }; 508 /// unsafe { wakeup() };
509 /// # Ok::<(), embassy_stm32::subghz::Error>(()) 509 /// # Ok::<(), embassy_stm32::subghz::Error>(())
510 /// ``` 510 /// ```
diff --git a/embassy-stm32/src/subghz/timeout.rs b/embassy-stm32/src/subghz/timeout.rs
index b8d6ad8f9..28b3b0c21 100644
--- a/embassy-stm32/src/subghz/timeout.rs
+++ b/embassy-stm32/src/subghz/timeout.rs
@@ -439,9 +439,9 @@ impl From<Timeout> for [u8; 3] {
439 } 439 }
440} 440}
441 441
442impl From<Timeout> for embassy_executor::time::Duration { 442impl From<Timeout> for embassy_time::Duration {
443 fn from(to: Timeout) -> Self { 443 fn from(to: Timeout) -> Self {
444 embassy_executor::time::Duration::from_micros(to.as_micros().into()) 444 embassy_time::Duration::from_micros(to.as_micros().into())
445 } 445 }
446} 446}
447 447
diff --git a/embassy-stm32/src/subghz/tx_params.rs b/embassy-stm32/src/subghz/tx_params.rs
index a72c060f3..cede6f2c1 100644
--- a/embassy-stm32/src/subghz/tx_params.rs
+++ b/embassy-stm32/src/subghz/tx_params.rs
@@ -44,17 +44,17 @@ impl From<RampTime> for core::time::Duration {
44 } 44 }
45} 45}
46 46
47impl From<RampTime> for embassy_executor::time::Duration { 47impl From<RampTime> for embassy_time::Duration {
48 fn from(rt: RampTime) -> Self { 48 fn from(rt: RampTime) -> Self {
49 match rt { 49 match rt {
50 RampTime::Micros10 => embassy_executor::time::Duration::from_micros(10), 50 RampTime::Micros10 => embassy_time::Duration::from_micros(10),
51 RampTime::Micros20 => embassy_executor::time::Duration::from_micros(20), 51 RampTime::Micros20 => embassy_time::Duration::from_micros(20),
52 RampTime::Micros40 => embassy_executor::time::Duration::from_micros(40), 52 RampTime::Micros40 => embassy_time::Duration::from_micros(40),
53 RampTime::Micros80 => embassy_executor::time::Duration::from_micros(80), 53 RampTime::Micros80 => embassy_time::Duration::from_micros(80),
54 RampTime::Micros200 => embassy_executor::time::Duration::from_micros(200), 54 RampTime::Micros200 => embassy_time::Duration::from_micros(200),
55 RampTime::Micros800 => embassy_executor::time::Duration::from_micros(800), 55 RampTime::Micros800 => embassy_time::Duration::from_micros(800),
56 RampTime::Micros1700 => embassy_executor::time::Duration::from_micros(1700), 56 RampTime::Micros1700 => embassy_time::Duration::from_micros(1700),
57 RampTime::Micros3400 => embassy_executor::time::Duration::from_micros(3400), 57 RampTime::Micros3400 => embassy_time::Duration::from_micros(3400),
58 } 58 }
59 } 59 }
60} 60}
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs
index 6cea43f18..7f4723162 100644
--- a/embassy-stm32/src/time_driver.rs
+++ b/embassy-stm32/src/time_driver.rs
@@ -4,8 +4,8 @@ use core::sync::atomic::{compiler_fence, Ordering};
4use core::{mem, ptr}; 4use core::{mem, ptr};
5 5
6use atomic_polyfill::{AtomicU32, AtomicU8}; 6use atomic_polyfill::{AtomicU32, AtomicU8};
7use embassy_executor::time::driver::{AlarmHandle, Driver}; 7use embassy_time::driver::{AlarmHandle, Driver};
8use embassy_executor::time::TICKS_PER_SECOND; 8use embassy_time::TICKS_PER_SECOND;
9use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex; 9use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex;
10use embassy_util::blocking_mutex::Mutex; 10use embassy_util::blocking_mutex::Mutex;
11use stm32_metapac::timer::regs; 11use stm32_metapac::timer::regs;
@@ -133,7 +133,7 @@ struct RtcDriver {
133 133
134const ALARM_STATE_NEW: AlarmState = AlarmState::new(); 134const ALARM_STATE_NEW: AlarmState = AlarmState::new();
135 135
136embassy_executor::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { 136embassy_time::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver {
137 period: AtomicU32::new(0), 137 period: AtomicU32::new(0),
138 alarm_count: AtomicU8::new(0), 138 alarm_count: AtomicU8::new(0),
139 alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]), 139 alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]),
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs
index 764b21461..3861e42d0 100644
--- a/embassy-stm32/src/usb/usb.rs
+++ b/embassy-stm32/src/usb/usb.rs
@@ -5,8 +5,8 @@ use core::sync::atomic::Ordering;
5use core::task::Poll; 5use core::task::Poll;
6 6
7use atomic_polyfill::{AtomicBool, AtomicU8}; 7use atomic_polyfill::{AtomicBool, AtomicU8};
8use embassy_executor::time::{block_for, Duration};
9use embassy_hal_common::into_ref; 8use embassy_hal_common::into_ref;
9use embassy_time::{block_for, Duration};
10use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; 10use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported};
11use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; 11use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection};
12use embassy_util::waitqueue::AtomicWaker; 12use embassy_util::waitqueue::AtomicWaker;
diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml
new file mode 100644
index 000000000..161c101fe
--- /dev/null
+++ b/embassy-time/Cargo.toml
@@ -0,0 +1,54 @@
1[package]
2name = "embassy-time"
3version = "0.1.0"
4edition = "2021"
5
6
7[package.metadata.embassy_docs]
8src_base = "https://github.com/embassy-rs/embassy/blob/embassy-time-v$VERSION/embassy-time/src/"
9src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-time/src/"
10features = ["nightly", "defmt", "unstable-traits", "std"]
11target = "x86_64-unknown-linux-gnu"
12
13[features]
14std = ["tick-1mhz"]
15wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-1mhz"]
16
17# Enable nightly-only features
18nightly = ["embedded-hal-async"]
19
20# Implement embedded-hal 1.0 alpha and embedded-hal-async traits.
21# Implement embedded-hal-async traits if `nightly` is set as well.
22unstable-traits = ["embedded-hal-1"]
23
24# Display a timestamp of the number of seconds since startup next to defmt log messages
25# To use this you must have a time driver provided.
26defmt-timestamp-uptime = ["defmt"]
27
28# Set the `embassy_time` tick rate.
29# NOTE: This feature is only intended to be enabled by crates providing the time driver implementation.
30# If you're not writing your own driver, check the driver documentation to customize the tick rate.
31# If you're writing a driver and your tick rate is not listed here, please add it and send a PR!
32tick-32768hz = []
33tick-1000hz = []
34tick-1mhz = []
35tick-16mhz = []
36
37[dependencies]
38defmt = { version = "0.3", optional = true }
39log = { version = "0.4.14", optional = true }
40
41embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" }
42embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8", optional = true}
43embedded-hal-async = { version = "0.1.0-alpha.1", optional = true}
44
45futures-util = { version = "0.3.17", default-features = false }
46embassy-macros = { version = "0.1.0", path = "../embassy-macros"}
47atomic-polyfill = "1.0.1"
48critical-section = "1.1"
49cfg-if = "1.0.0"
50
51# WASM dependencies
52wasm-bindgen = { version = "0.2.76", features = ["nightly"], optional = true }
53js-sys = { version = "0.3", optional = true }
54wasm-timer = { version = "0.2.5", optional = true } \ No newline at end of file
diff --git a/embassy-executor/src/time/delay.rs b/embassy-time/src/delay.rs
index d76ed32eb..d010fff98 100644
--- a/embassy-executor/src/time/delay.rs
+++ b/embassy-time/src/delay.rs
@@ -33,7 +33,7 @@ mod eh1 {
33 33
34cfg_if::cfg_if! { 34cfg_if::cfg_if! {
35 if #[cfg(all(feature = "unstable-traits", feature = "nightly"))] { 35 if #[cfg(all(feature = "unstable-traits", feature = "nightly"))] {
36 use crate::time::Timer; 36 use crate::Timer;
37 use core::future::Future; 37 use core::future::Future;
38 use futures_util::FutureExt; 38 use futures_util::FutureExt;
39 39
diff --git a/embassy-executor/src/time/driver.rs b/embassy-time/src/driver.rs
index 48e2f1c7d..216b27408 100644
--- a/embassy-executor/src/time/driver.rs
+++ b/embassy-time/src/driver.rs
@@ -1,17 +1,17 @@
1//! Time driver interface 1//! Time driver interface
2//! 2//!
3//! This module defines the interface a driver needs to implement to power the `embassy_executor::time` module. 3//! This module defines the interface a driver needs to implement to power the `embassy_time` module.
4//! 4//!
5//! # Implementing a driver 5//! # Implementing a driver
6//! 6//!
7//! - Define a struct `MyDriver` 7//! - Define a struct `MyDriver`
8//! - Implement [`Driver`] for it 8//! - Implement [`Driver`] for it
9//! - Register it as the global driver with [`time_driver_impl`]. 9//! - Register it as the global driver with [`time_driver_impl`].
10//! - Enable the Cargo features `embassy-executor/time` and one of `embassy-executor/time-tick-*` corresponding to the 10//! - Enable the Cargo features `embassy-executor/time` and one of `embassy-time/tick-*` corresponding to the
11//! tick rate of your driver. 11//! tick rate of your driver.
12//! 12//!
13//! If you wish to make the tick rate configurable by the end user, you should do so by exposing your own 13//! If you wish to make the tick rate configurable by the end user, you should do so by exposing your own
14//! Cargo features and having each enable the corresponding `embassy-executor/time-tick-*`. 14//! Cargo features and having each enable the corresponding `embassy-time/tick-*`.
15//! 15//!
16//! # Linkage details 16//! # Linkage details
17//! 17//!
@@ -34,10 +34,10 @@
34//! # Example 34//! # Example
35//! 35//!
36//! ``` 36//! ```
37//! use embassy_executor::time::driver::{Driver, AlarmHandle}; 37//! use embassy_time::driver::{Driver, AlarmHandle};
38//! 38//!
39//! struct MyDriver{}; // not public! 39//! struct MyDriver{}; // not public!
40//! embassy_executor::time_driver_impl!(static DRIVER: MyDriver = MyDriver{}); 40//! embassy_time::time_driver_impl!(static DRIVER: MyDriver = MyDriver{});
41//! 41//!
42//! impl Driver for MyDriver { 42//! impl Driver for MyDriver {
43//! fn now(&self) -> u64 { 43//! fn now(&self) -> u64 {
@@ -121,17 +121,25 @@ extern "Rust" {
121 fn _embassy_time_set_alarm(alarm: AlarmHandle, timestamp: u64); 121 fn _embassy_time_set_alarm(alarm: AlarmHandle, timestamp: u64);
122} 122}
123 123
124pub(crate) fn now() -> u64 { 124/// See [`Driver::now`]
125pub fn now() -> u64 {
125 unsafe { _embassy_time_now() } 126 unsafe { _embassy_time_now() }
126} 127}
128
129/// See [`Driver::allocate_alarm`]
130///
127/// Safety: it is UB to make the alarm fire before setting a callback. 131/// Safety: it is UB to make the alarm fire before setting a callback.
128pub(crate) unsafe fn allocate_alarm() -> Option<AlarmHandle> { 132pub unsafe fn allocate_alarm() -> Option<AlarmHandle> {
129 _embassy_time_allocate_alarm() 133 _embassy_time_allocate_alarm()
130} 134}
131pub(crate) fn set_alarm_callback(alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) { 135
136/// See [`Driver::set_alarm_callback`]
137pub fn set_alarm_callback(alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) {
132 unsafe { _embassy_time_set_alarm_callback(alarm, callback, ctx) } 138 unsafe { _embassy_time_set_alarm_callback(alarm, callback, ctx) }
133} 139}
134pub(crate) fn set_alarm(alarm: AlarmHandle, timestamp: u64) { 140
141/// See [`Driver::set_alarm`]
142pub fn set_alarm(alarm: AlarmHandle, timestamp: u64) {
135 unsafe { _embassy_time_set_alarm(alarm, timestamp) } 143 unsafe { _embassy_time_set_alarm(alarm, timestamp) }
136} 144}
137 145
@@ -145,26 +153,22 @@ macro_rules! time_driver_impl {
145 153
146 #[no_mangle] 154 #[no_mangle]
147 fn _embassy_time_now() -> u64 { 155 fn _embassy_time_now() -> u64 {
148 <$t as $crate::time::driver::Driver>::now(&$name) 156 <$t as $crate::driver::Driver>::now(&$name)
149 } 157 }
150 158
151 #[no_mangle] 159 #[no_mangle]
152 unsafe fn _embassy_time_allocate_alarm() -> Option<$crate::time::driver::AlarmHandle> { 160 unsafe fn _embassy_time_allocate_alarm() -> Option<$crate::driver::AlarmHandle> {
153 <$t as $crate::time::driver::Driver>::allocate_alarm(&$name) 161 <$t as $crate::driver::Driver>::allocate_alarm(&$name)
154 } 162 }
155 163
156 #[no_mangle] 164 #[no_mangle]
157 fn _embassy_time_set_alarm_callback( 165 fn _embassy_time_set_alarm_callback(alarm: $crate::driver::AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) {
158 alarm: $crate::time::driver::AlarmHandle, 166 <$t as $crate::driver::Driver>::set_alarm_callback(&$name, alarm, callback, ctx)
159 callback: fn(*mut ()),
160 ctx: *mut (),
161 ) {
162 <$t as $crate::time::driver::Driver>::set_alarm_callback(&$name, alarm, callback, ctx)
163 } 167 }
164 168
165 #[no_mangle] 169 #[no_mangle]
166 fn _embassy_time_set_alarm(alarm: $crate::time::driver::AlarmHandle, timestamp: u64) { 170 fn _embassy_time_set_alarm(alarm: $crate::driver::AlarmHandle, timestamp: u64) {
167 <$t as $crate::time::driver::Driver>::set_alarm(&$name, alarm, timestamp) 171 <$t as $crate::driver::Driver>::set_alarm(&$name, alarm, timestamp)
168 } 172 }
169 }; 173 };
170} 174}
diff --git a/embassy-executor/src/time/driver_std.rs b/embassy-time/src/driver_std.rs
index cb66f7c19..2ddb2e604 100644
--- a/embassy-executor/src/time/driver_std.rs
+++ b/embassy-time/src/driver_std.rs
@@ -6,7 +6,7 @@ use std::{mem, ptr, thread};
6 6
7use atomic_polyfill::{AtomicU8, Ordering}; 7use atomic_polyfill::{AtomicU8, Ordering};
8 8
9use crate::time::driver::{AlarmHandle, Driver}; 9use crate::driver::{AlarmHandle, Driver};
10 10
11const ALARM_COUNT: usize = 4; 11const ALARM_COUNT: usize = 4;
12 12
diff --git a/embassy-executor/src/time/driver_wasm.rs b/embassy-time/src/driver_wasm.rs
index 5f585a19a..e4497e6a2 100644
--- a/embassy-executor/src/time/driver_wasm.rs
+++ b/embassy-time/src/driver_wasm.rs
@@ -7,7 +7,7 @@ use atomic_polyfill::{AtomicU8, Ordering};
7use wasm_bindgen::prelude::*; 7use wasm_bindgen::prelude::*;
8use wasm_timer::Instant as StdInstant; 8use wasm_timer::Instant as StdInstant;
9 9
10use crate::time::driver::{AlarmHandle, Driver}; 10use crate::driver::{AlarmHandle, Driver};
11 11
12const ALARM_COUNT: usize = 4; 12const ALARM_COUNT: usize = 4;
13 13
diff --git a/embassy-executor/src/time/duration.rs b/embassy-time/src/duration.rs
index dc4f16bd4..dc4f16bd4 100644
--- a/embassy-executor/src/time/duration.rs
+++ b/embassy-time/src/duration.rs
diff --git a/embassy-time/src/fmt.rs b/embassy-time/src/fmt.rs
new file mode 100644
index 000000000..066970813
--- /dev/null
+++ b/embassy-time/src/fmt.rs
@@ -0,0 +1,225 @@
1#![macro_use]
2#![allow(unused_macros)]
3
4#[cfg(all(feature = "defmt", feature = "log"))]
5compile_error!("You may not enable both `defmt` and `log` features.");
6
7macro_rules! assert {
8 ($($x:tt)*) => {
9 {
10 #[cfg(not(feature = "defmt"))]
11 ::core::assert!($($x)*);
12 #[cfg(feature = "defmt")]
13 ::defmt::assert!($($x)*);
14 }
15 };
16}
17
18macro_rules! assert_eq {
19 ($($x:tt)*) => {
20 {
21 #[cfg(not(feature = "defmt"))]
22 ::core::assert_eq!($($x)*);
23 #[cfg(feature = "defmt")]
24 ::defmt::assert_eq!($($x)*);
25 }
26 };
27}
28
29macro_rules! assert_ne {
30 ($($x:tt)*) => {
31 {
32 #[cfg(not(feature = "defmt"))]
33 ::core::assert_ne!($($x)*);
34 #[cfg(feature = "defmt")]
35 ::defmt::assert_ne!($($x)*);
36 }
37 };
38}
39
40macro_rules! debug_assert {
41 ($($x:tt)*) => {
42 {
43 #[cfg(not(feature = "defmt"))]
44 ::core::debug_assert!($($x)*);
45 #[cfg(feature = "defmt")]
46 ::defmt::debug_assert!($($x)*);
47 }
48 };
49}
50
51macro_rules! debug_assert_eq {
52 ($($x:tt)*) => {
53 {
54 #[cfg(not(feature = "defmt"))]
55 ::core::debug_assert_eq!($($x)*);
56 #[cfg(feature = "defmt")]
57 ::defmt::debug_assert_eq!($($x)*);
58 }
59 };
60}
61
62macro_rules! debug_assert_ne {
63 ($($x:tt)*) => {
64 {
65 #[cfg(not(feature = "defmt"))]
66 ::core::debug_assert_ne!($($x)*);
67 #[cfg(feature = "defmt")]
68 ::defmt::debug_assert_ne!($($x)*);
69 }
70 };
71}
72
73macro_rules! todo {
74 ($($x:tt)*) => {
75 {
76 #[cfg(not(feature = "defmt"))]
77 ::core::todo!($($x)*);
78 #[cfg(feature = "defmt")]
79 ::defmt::todo!($($x)*);
80 }
81 };
82}
83
84macro_rules! unreachable {
85 ($($x:tt)*) => {
86 {
87 #[cfg(not(feature = "defmt"))]
88 ::core::unreachable!($($x)*);
89 #[cfg(feature = "defmt")]
90 ::defmt::unreachable!($($x)*);
91 }
92 };
93}
94
95macro_rules! panic {
96 ($($x:tt)*) => {
97 {
98 #[cfg(not(feature = "defmt"))]
99 ::core::panic!($($x)*);
100 #[cfg(feature = "defmt")]
101 ::defmt::panic!($($x)*);
102 }
103 };
104}
105
106macro_rules! trace {
107 ($s:literal $(, $x:expr)* $(,)?) => {
108 {
109 #[cfg(feature = "log")]
110 ::log::trace!($s $(, $x)*);
111 #[cfg(feature = "defmt")]
112 ::defmt::trace!($s $(, $x)*);
113 #[cfg(not(any(feature = "log", feature="defmt")))]
114 let _ = ($( & $x ),*);
115 }
116 };
117}
118
119macro_rules! debug {
120 ($s:literal $(, $x:expr)* $(,)?) => {
121 {
122 #[cfg(feature = "log")]
123 ::log::debug!($s $(, $x)*);
124 #[cfg(feature = "defmt")]
125 ::defmt::debug!($s $(, $x)*);
126 #[cfg(not(any(feature = "log", feature="defmt")))]
127 let _ = ($( & $x ),*);
128 }
129 };
130}
131
132macro_rules! info {
133 ($s:literal $(, $x:expr)* $(,)?) => {
134 {
135 #[cfg(feature = "log")]
136 ::log::info!($s $(, $x)*);
137 #[cfg(feature = "defmt")]
138 ::defmt::info!($s $(, $x)*);
139 #[cfg(not(any(feature = "log", feature="defmt")))]
140 let _ = ($( & $x ),*);
141 }
142 };
143}
144
145macro_rules! warn {
146 ($s:literal $(, $x:expr)* $(,)?) => {
147 {
148 #[cfg(feature = "log")]
149 ::log::warn!($s $(, $x)*);
150 #[cfg(feature = "defmt")]
151 ::defmt::warn!($s $(, $x)*);
152 #[cfg(not(any(feature = "log", feature="defmt")))]
153 let _ = ($( & $x ),*);
154 }
155 };
156}
157
158macro_rules! error {
159 ($s:literal $(, $x:expr)* $(,)?) => {
160 {
161 #[cfg(feature = "log")]
162 ::log::error!($s $(, $x)*);
163 #[cfg(feature = "defmt")]
164 ::defmt::error!($s $(, $x)*);
165 #[cfg(not(any(feature = "log", feature="defmt")))]
166 let _ = ($( & $x ),*);
167 }
168 };
169}
170
171#[cfg(feature = "defmt")]
172macro_rules! unwrap {
173 ($($x:tt)*) => {
174 ::defmt::unwrap!($($x)*)
175 };
176}
177
178#[cfg(not(feature = "defmt"))]
179macro_rules! unwrap {
180 ($arg:expr) => {
181 match $crate::fmt::Try::into_result($arg) {
182 ::core::result::Result::Ok(t) => t,
183 ::core::result::Result::Err(e) => {
184 ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e);
185 }
186 }
187 };
188 ($arg:expr, $($msg:expr),+ $(,)? ) => {
189 match $crate::fmt::Try::into_result($arg) {
190 ::core::result::Result::Ok(t) => t,
191 ::core::result::Result::Err(e) => {
192 ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e);
193 }
194 }
195 }
196}
197
198#[derive(Debug, Copy, Clone, Eq, PartialEq)]
199pub struct NoneError;
200
201pub trait Try {
202 type Ok;
203 type Error;
204 fn into_result(self) -> Result<Self::Ok, Self::Error>;
205}
206
207impl<T> Try for Option<T> {
208 type Ok = T;
209 type Error = NoneError;
210
211 #[inline]
212 fn into_result(self) -> Result<T, NoneError> {
213 self.ok_or(NoneError)
214 }
215}
216
217impl<T, E> Try for Result<T, E> {
218 type Ok = T;
219 type Error = E;
220
221 #[inline]
222 fn into_result(self) -> Self {
223 self
224 }
225}
diff --git a/embassy-executor/src/time/instant.rs b/embassy-time/src/instant.rs
index 6a4925f47..6a4925f47 100644
--- a/embassy-executor/src/time/instant.rs
+++ b/embassy-time/src/instant.rs
diff --git a/embassy-executor/src/time/mod.rs b/embassy-time/src/lib.rs
index b787a5cf2..a6454d55e 100644
--- a/embassy-executor/src/time/mod.rs
+++ b/embassy-time/src/lib.rs
@@ -1,3 +1,8 @@
1#![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)]
2#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))]
3#![allow(clippy::new_without_default)]
4#![warn(missing_docs)]
5
1//! Timekeeping, delays and timeouts. 6//! Timekeeping, delays and timeouts.
2//! 7//!
3//! Timekeeping is done with elapsed time since system boot. Time is represented in 8//! Timekeeping is done with elapsed time since system boot. Time is represented in
@@ -26,7 +31,7 @@
26//! like `2021-08-24 13:33:21`). 31//! like `2021-08-24 13:33:21`).
27//! 32//!
28//! If persistence across reboots is not needed, support can be built on top of 33//! If persistence across reboots is not needed, support can be built on top of
29//! `embassy_executor::time` by storing the offset between "seconds elapsed since boot" 34//! `embassy_time` by storing the offset between "seconds elapsed since boot"
30//! and "seconds since unix epoch". 35//! and "seconds since unix epoch".
31//! 36//!
32//! # Time driver 37//! # Time driver
@@ -35,12 +40,13 @@
35//! Only one driver can be active in a program. 40//! Only one driver can be active in a program.
36//! 41//!
37//! All methods and structs transparently call into the active driver. This makes it 42//! All methods and structs transparently call into the active driver. This makes it
38//! possible for libraries to use `embassy_executor::time` in a driver-agnostic way without 43//! possible for libraries to use `embassy_time` in a driver-agnostic way without
39//! requiring generic parameters. 44//! requiring generic parameters.
40//! 45//!
41//! For more details, check the [`driver`] module. 46//! For more details, check the [`driver`] module.
42 47
43#![deny(missing_docs)] 48// This mod MUST go first, so that the others see its macros.
49pub(crate) mod fmt;
44 50
45mod delay; 51mod delay;
46pub mod driver; 52pub mod driver;
@@ -50,7 +56,6 @@ mod timer;
50 56
51#[cfg(feature = "std")] 57#[cfg(feature = "std")]
52mod driver_std; 58mod driver_std;
53
54#[cfg(feature = "wasm")] 59#[cfg(feature = "wasm")]
55mod driver_wasm; 60mod driver_wasm;
56 61
@@ -59,24 +64,24 @@ pub use duration::Duration;
59pub use instant::Instant; 64pub use instant::Instant;
60pub use timer::{with_timeout, Ticker, TimeoutError, Timer}; 65pub use timer::{with_timeout, Ticker, TimeoutError, Timer};
61 66
62#[cfg(feature = "time-tick-1000hz")] 67#[cfg(feature = "tick-1000hz")]
63const TPS: u64 = 1_000; 68const TPS: u64 = 1_000;
64 69
65#[cfg(feature = "time-tick-32768hz")] 70#[cfg(feature = "tick-32768hz")]
66const TPS: u64 = 32_768; 71const TPS: u64 = 32_768;
67 72
68#[cfg(feature = "time-tick-1mhz")] 73#[cfg(feature = "tick-1mhz")]
69const TPS: u64 = 1_000_000; 74const TPS: u64 = 1_000_000;
70 75
71#[cfg(feature = "time-tick-16mhz")] 76#[cfg(feature = "tick-16mhz")]
72const TPS: u64 = 16_000_000; 77const TPS: u64 = 16_000_000;
73 78
74/// Ticks per second of the global timebase. 79/// Ticks per second of the global timebase.
75/// 80///
76/// This value is specified by the `time-tick-*` Cargo features, which 81/// This value is specified by the `tick-*` Cargo features, which
77/// should be set by the time driver. Some drivers support a fixed tick rate, others 82/// should be set by the time driver. Some drivers support a fixed tick rate, others
78/// allow you to choose a tick rate with Cargo features of their own. You should not 83/// allow you to choose a tick rate with Cargo features of their own. You should not
79/// set the `time-tick-*` features for embassy yourself as an end user. 84/// set the `tick-*` features for embassy yourself as an end user.
80pub const TICKS_PER_SECOND: u64 = TPS; 85pub const TICKS_PER_SECOND: u64 = TPS;
81 86
82const fn gcd(a: u64, b: u64) -> u64 { 87const fn gcd(a: u64, b: u64) -> u64 {
@@ -89,3 +94,6 @@ const fn gcd(a: u64, b: u64) -> u64 {
89 94
90pub(crate) const GCD_1K: u64 = gcd(TICKS_PER_SECOND, 1_000); 95pub(crate) const GCD_1K: u64 = gcd(TICKS_PER_SECOND, 1_000);
91pub(crate) const GCD_1M: u64 = gcd(TICKS_PER_SECOND, 1_000_000); 96pub(crate) const GCD_1M: u64 = gcd(TICKS_PER_SECOND, 1_000_000);
97
98#[cfg(feature = "defmt-timestamp-uptime")]
99defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() }
diff --git a/embassy-executor/src/time/timer.rs b/embassy-time/src/timer.rs
index b9cdb1be5..bd791b817 100644
--- a/embassy-executor/src/time/timer.rs
+++ b/embassy-time/src/timer.rs
@@ -1,12 +1,11 @@
1use core::future::Future; 1use core::future::Future;
2use core::pin::Pin; 2use core::pin::Pin;
3use core::task::{Context, Poll}; 3use core::task::{Context, Poll, Waker};
4 4
5use futures_util::future::{select, Either}; 5use futures_util::future::{select, Either};
6use futures_util::{pin_mut, Stream}; 6use futures_util::{pin_mut, Stream};
7 7
8use crate::executor::raw; 8use crate::{Duration, Instant};
9use crate::time::{Duration, Instant};
10 9
11/// Error returned by [`with_timeout`] on timeout. 10/// Error returned by [`with_timeout`] on timeout.
12#[derive(Debug, Clone, PartialEq, Eq)] 11#[derive(Debug, Clone, PartialEq, Eq)]
@@ -49,7 +48,7 @@ impl Timer {
49 /// # #![feature(type_alias_impl_trait)] 48 /// # #![feature(type_alias_impl_trait)]
50 /// # 49 /// #
51 /// # fn foo() {} 50 /// # fn foo() {}
52 /// use embassy_executor::time::{Duration, Timer}; 51 /// use embassy_time::{Duration, Timer};
53 /// 52 ///
54 /// #[embassy_executor::task] 53 /// #[embassy_executor::task]
55 /// async fn demo_sleep_seconds() { 54 /// async fn demo_sleep_seconds() {
@@ -73,7 +72,7 @@ impl Future for Timer {
73 if self.yielded_once && self.expires_at <= Instant::now() { 72 if self.yielded_once && self.expires_at <= Instant::now() {
74 Poll::Ready(()) 73 Poll::Ready(())
75 } else { 74 } else {
76 unsafe { raw::register_timer(self.expires_at, cx.waker()) }; 75 schedule_wake(self.expires_at, cx.waker());
77 self.yielded_once = true; 76 self.yielded_once = true;
78 Poll::Pending 77 Poll::Pending
79 } 78 }
@@ -88,7 +87,7 @@ impl Future for Timer {
88/// ``` no_run 87/// ``` no_run
89/// # #![feature(type_alias_impl_trait)] 88/// # #![feature(type_alias_impl_trait)]
90/// # 89/// #
91/// use embassy_executor::time::{Duration, Timer}; 90/// use embassy_time::{Duration, Timer};
92/// # fn foo() {} 91/// # fn foo() {}
93/// 92///
94/// #[embassy_executor::task] 93/// #[embassy_executor::task]
@@ -108,7 +107,7 @@ impl Future for Timer {
108/// ``` no_run 107/// ``` no_run
109/// # #![feature(type_alias_impl_trait)] 108/// # #![feature(type_alias_impl_trait)]
110/// # 109/// #
111/// use embassy_executor::time::{Duration, Ticker}; 110/// use embassy_time::{Duration, Ticker};
112/// use futures::StreamExt; 111/// use futures::StreamExt;
113/// # fn foo(){} 112/// # fn foo(){}
114/// 113///
@@ -144,8 +143,16 @@ impl Stream for Ticker {
144 self.expires_at += dur; 143 self.expires_at += dur;
145 Poll::Ready(Some(())) 144 Poll::Ready(Some(()))
146 } else { 145 } else {
147 unsafe { raw::register_timer(self.expires_at, cx.waker()) }; 146 schedule_wake(self.expires_at, cx.waker());
148 Poll::Pending 147 Poll::Pending
149 } 148 }
150 } 149 }
151} 150}
151
152extern "Rust" {
153 fn _embassy_time_schedule_wake(at: Instant, waker: &Waker);
154}
155
156fn schedule_wake(at: Instant, waker: &Waker) {
157 unsafe { _embassy_time_schedule_wake(at, waker) }
158}
diff --git a/embassy-usb-hid/Cargo.toml b/embassy-usb-hid/Cargo.toml
index 53b6db3da..5e9cfebf7 100644
--- a/embassy-usb-hid/Cargo.toml
+++ b/embassy-usb-hid/Cargo.toml
@@ -6,10 +6,8 @@ edition = "2021"
6[package.metadata.embassy_docs] 6[package.metadata.embassy_docs]
7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-hid-v$VERSION/embassy-usb-hid/src/" 7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-hid-v$VERSION/embassy-usb-hid/src/"
8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-hid/src/" 8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-hid/src/"
9features = ["defmt", "embassy-executor/time-tick-1mhz"] 9features = ["defmt"]
10flavors = [ 10target = "thumbv7em-none-eabi"
11 { name = "default", target = "thumbv7em-none-eabihf" },
12]
13 11
14[features] 12[features]
15default = ["usbd-hid"] 13default = ["usbd-hid"]
diff --git a/embassy-usb-ncm/Cargo.toml b/embassy-usb-ncm/Cargo.toml
index fa6fa0176..47c1f36bd 100644
--- a/embassy-usb-ncm/Cargo.toml
+++ b/embassy-usb-ncm/Cargo.toml
@@ -7,9 +7,7 @@ edition = "2021"
7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-ncm-v$VERSION/embassy-usb-ncm/src/" 7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-ncm-v$VERSION/embassy-usb-ncm/src/"
8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-ncm/src/" 8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-ncm/src/"
9features = ["defmt"] 9features = ["defmt"]
10flavors = [ 10target = "thumbv7em-none-eabi"
11 { name = "default", target = "thumbv7em-none-eabihf" },
12]
13 11
14[dependencies] 12[dependencies]
15embassy-util = { version = "0.1.0", path = "../embassy-util" } 13embassy-util = { version = "0.1.0", path = "../embassy-util" }
diff --git a/embassy-usb-serial/Cargo.toml b/embassy-usb-serial/Cargo.toml
index 495dd9fea..633610471 100644
--- a/embassy-usb-serial/Cargo.toml
+++ b/embassy-usb-serial/Cargo.toml
@@ -7,9 +7,7 @@ edition = "2021"
7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-serial-v$VERSION/embassy-usb-serial/src/" 7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-serial-v$VERSION/embassy-usb-serial/src/"
8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-serial/src/" 8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-serial/src/"
9features = ["defmt"] 9features = ["defmt"]
10flavors = [ 10target = "thumbv7em-none-eabi"
11 { name = "default", target = "thumbv7em-none-eabihf" },
12]
13 11
14[dependencies] 12[dependencies]
15embassy-util = { version = "0.1.0", path = "../embassy-util" } 13embassy-util = { version = "0.1.0", path = "../embassy-util" }
diff --git a/embassy-usb/Cargo.toml b/embassy-usb/Cargo.toml
index 98734e98f..6adbd399b 100644
--- a/embassy-usb/Cargo.toml
+++ b/embassy-usb/Cargo.toml
@@ -7,9 +7,7 @@ edition = "2021"
7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-v$VERSION/embassy-usb/src/" 7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-v$VERSION/embassy-usb/src/"
8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb/src/" 8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb/src/"
9features = ["defmt"] 9features = ["defmt"]
10flavors = [ 10target = "thumbv7em-none-eabi"
11 { name = "default", target = "thumbv7em-none-eabihf" },
12]
13 11
14[dependencies] 12[dependencies]
15embassy-util = { version = "0.1.0", path = "../embassy-util" } 13embassy-util = { version = "0.1.0", path = "../embassy-util" }
diff --git a/embassy-util/Cargo.toml b/embassy-util/Cargo.toml
index ef5acc0f0..d4708d735 100644
--- a/embassy-util/Cargo.toml
+++ b/embassy-util/Cargo.toml
@@ -7,9 +7,7 @@ edition = "2021"
7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-util-v$VERSION/embassy-util/src/" 7src_base = "https://github.com/embassy-rs/embassy/blob/embassy-util-v$VERSION/embassy-util/src/"
8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-util/src/" 8src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-util/src/"
9features = ["nightly"] 9features = ["nightly"]
10flavors = [ 10target = "thumbv7em-none-eabi"
11 { name = "default", target = "x86_64-unknown-linux-gnu" },
12]
13 11
14[features] 12[features]
15nightly = ["embedded-io/async"] 13nightly = ["embedded-io/async"]
@@ -19,8 +17,8 @@ defmt = { version = "0.3", optional = true }
19log = { version = "0.4.14", optional = true } 17log = { version = "0.4.14", optional = true }
20 18
21futures-util = { version = "0.3.17", default-features = false } 19futures-util = { version = "0.3.17", default-features = false }
22atomic-polyfill = "0.1.5" 20atomic-polyfill = "1.0.1"
23critical-section = "0.2.5" 21critical-section = "1.1"
24heapless = "0.7.5" 22heapless = "0.7.5"
25cfg-if = "1.0.0" 23cfg-if = "1.0.0"
26embedded-io = "0.3.0" 24embedded-io = "0.3.0"
@@ -30,3 +28,6 @@ futures-executor = { version = "0.3.17", features = [ "thread-pool" ] }
30futures-test = "0.3.17" 28futures-test = "0.3.17"
31futures-timer = "3.0.2" 29futures-timer = "3.0.2"
32futures-util = { version = "0.3.17", features = [ "channel" ] } 30futures-util = { version = "0.3.17", features = [ "channel" ] }
31
32# Enable critical-section implementation for std, for tests
33critical-section = { version = "1.1", features = ["std"] }
diff --git a/embassy-util/src/channel/signal.rs b/embassy-util/src/channel/signal.rs
index a58469c4f..05889f5a4 100644
--- a/embassy-util/src/channel/signal.rs
+++ b/embassy-util/src/channel/signal.rs
@@ -69,7 +69,8 @@ impl<T: Send> Signal<T> {
69 }) 69 })
70 } 70 }
71 71
72 fn poll_wait(&self, cx: &mut Context<'_>) -> Poll<T> { 72 /// Manually poll the Signal future.
73 pub fn poll_wait(&self, cx: &mut Context<'_>) -> Poll<T> {
73 critical_section::with(|_| unsafe { 74 critical_section::with(|_| unsafe {
74 let state = &mut *self.state.get(); 75 let state = &mut *self.state.get();
75 match state { 76 match state {
diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml
index dd9bcc093..ef9346639 100644
--- a/examples/boot/application/nrf/Cargo.toml
+++ b/examples/boot/application/nrf/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util" } 7embassy-util = { version = "0.1.0", path = "../../../../embassy-util" }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly"] }
9embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] } 10embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] }
10embassy-boot-nrf = { version = "0.1.0", path = "../../../../embassy-boot/nrf" } 11embassy-boot-nrf = { version = "0.1.0", path = "../../../../embassy-boot/nrf" }
11embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
@@ -15,5 +16,5 @@ defmt-rtt = { version = "0.3", optional = true }
15panic-reset = { version = "0.1.1" } 16panic-reset = { version = "0.1.1" }
16embedded-hal = { version = "0.2.6" } 17embedded-hal = { version = "0.2.6" }
17 18
18cortex-m = "0.7.3" 19cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
19cortex-m-rt = "0.7.0" 20cortex-m-rt = "0.7.0"
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs
index 3044645a8..bd8fa3246 100644
--- a/examples/boot/application/nrf/src/bin/a.rs
+++ b/examples/boot/application/nrf/src/bin/a.rs
@@ -6,15 +6,16 @@
6 6
7use embassy_boot_nrf::FirmwareUpdater; 7use embassy_boot_nrf::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner;
9use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; 10use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
10use embassy_nrf::nvmc::Nvmc; 11use embassy_nrf::nvmc::Nvmc;
11use embassy_nrf::Peripherals;
12use panic_reset as _; 12use panic_reset as _;
13 13
14static APP_B: &[u8] = include_bytes!("../../b.bin"); 14static APP_B: &[u8] = include_bytes!("../../b.bin");
15 15
16#[embassy_executor::main] 16#[embassy_executor::main]
17async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { 17async fn main(_spawner: Spawner) {
18 let p = embassy_nrf::init(Default::default());
18 let mut button = Input::new(p.P0_11, Pull::Up); 19 let mut button = Input::new(p.P0_11, Pull::Up);
19 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); 20 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
20 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); 21 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard);
diff --git a/examples/boot/application/nrf/src/bin/b.rs b/examples/boot/application/nrf/src/bin/b.rs
index 2f76d20c6..5394bf0c7 100644
--- a/examples/boot/application/nrf/src/bin/b.rs
+++ b/examples/boot/application/nrf/src/bin/b.rs
@@ -4,13 +4,14 @@
4#![feature(generic_associated_types)] 4#![feature(generic_associated_types)]
5#![feature(type_alias_impl_trait)] 5#![feature(type_alias_impl_trait)]
6 6
7use embassy_executor::time::{Duration, Timer}; 7use embassy_executor::Spawner;
8use embassy_nrf::gpio::{Level, Output, OutputDrive}; 8use embassy_nrf::gpio::{Level, Output, OutputDrive};
9use embassy_nrf::Peripherals; 9use embassy_time::{Duration, Timer};
10use panic_reset as _; 10use panic_reset as _;
11 11
12#[embassy_executor::main] 12#[embassy_executor::main]
13async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_nrf::init(Default::default());
14 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); 15 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
15 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); 16 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard);
16 17
diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml
index 313808a0d..27eafa653 100644
--- a/examples/boot/application/stm32f3/Cargo.toml
+++ b/examples/boot/application/stm32f3/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] }
10embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } 11embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
11embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
@@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true }
15panic-reset = { version = "0.1.1" } 16panic-reset = { version = "0.1.1" }
16embedded-hal = { version = "0.2.6" } 17embedded-hal = { version = "0.2.6" }
17 18
18cortex-m = "0.7.3" 19cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
19cortex-m-rt = "0.7.0" 20cortex-m-rt = "0.7.0"
20 21
21[features] 22[features]
diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs
index fd18e9373..11eecc5e2 100644
--- a/examples/boot/application/stm32f3/src/bin/a.rs
+++ b/examples/boot/application/stm32f3/src/bin/a.rs
@@ -6,16 +6,17 @@
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner;
9use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _; 13use panic_reset as _;
14 14
15static APP_B: &[u8] = include_bytes!("../../b.bin"); 15static APP_B: &[u8] = include_bytes!("../../b.bin");
16 16
17#[embassy_executor::main] 17#[embassy_executor::main]
18async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { 18async fn main(_spawner: Spawner) {
19 let p = embassy_stm32::init(Default::default());
19 let flash = Flash::unlock(p.FLASH); 20 let flash = Flash::unlock(p.FLASH);
20 let mut flash = BlockingAsync::new(flash); 21 let mut flash = BlockingAsync::new(flash);
21 22
diff --git a/examples/boot/application/stm32f3/src/bin/b.rs b/examples/boot/application/stm32f3/src/bin/b.rs
index 934f862d9..a5862b1b0 100644
--- a/examples/boot/application/stm32f3/src/bin/b.rs
+++ b/examples/boot/application/stm32f3/src/bin/b.rs
@@ -4,14 +4,14 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_executor::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_time::{Duration, Timer};
11use panic_reset as _; 10use panic_reset as _;
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 let mut led = Output::new(p.PA5, Level::High, Speed::Low); 15 let mut led = Output::new(p.PA5, Level::High, Speed::Low);
16 16
17 loop { 17 loop {
diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml
index 2a4741dc7..7de0b82d7 100644
--- a/examples/boot/application/stm32f7/Cargo.toml
+++ b/examples/boot/application/stm32f7/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] }
10embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } 11embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
11embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
@@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true }
15panic-reset = { version = "0.1.1" } 16panic-reset = { version = "0.1.1" }
16embedded-hal = { version = "0.2.6" } 17embedded-hal = { version = "0.2.6" }
17 18
18cortex-m = "0.7.3" 19cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
19cortex-m-rt = "0.7.0" 20cortex-m-rt = "0.7.0"
20 21
21[features] 22[features]
diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs
index 10d709cfd..a3b66e7c9 100644
--- a/examples/boot/application/stm32f7/src/bin/a.rs
+++ b/examples/boot/application/stm32f7/src/bin/a.rs
@@ -6,16 +6,17 @@
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner;
9use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _; 13use panic_reset as _;
14 14
15static APP_B: &[u8] = include_bytes!("../../b.bin"); 15static APP_B: &[u8] = include_bytes!("../../b.bin");
16 16
17#[embassy_executor::main] 17#[embassy_executor::main]
18async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { 18async fn main(_spawner: Spawner) {
19 let p = embassy_stm32::init(Default::default());
19 let flash = Flash::unlock(p.FLASH); 20 let flash = Flash::unlock(p.FLASH);
20 let mut flash = BlockingAsync::new(flash); 21 let mut flash = BlockingAsync::new(flash);
21 22
diff --git a/examples/boot/application/stm32f7/src/bin/b.rs b/examples/boot/application/stm32f7/src/bin/b.rs
index c89e8a310..16c94d845 100644
--- a/examples/boot/application/stm32f7/src/bin/b.rs
+++ b/examples/boot/application/stm32f7/src/bin/b.rs
@@ -4,14 +4,14 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_executor::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_time::{Duration, Timer};
11use panic_reset as _; 10use panic_reset as _;
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 Timer::after(Duration::from_millis(300)).await; 15 Timer::after(Duration::from_millis(300)).await;
16 let mut led = Output::new(p.PB7, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB7, Level::High, Speed::Low);
17 led.set_high(); 17 led.set_high();
diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml
index c6420e8ad..65d34c70b 100644
--- a/examples/boot/application/stm32h7/Cargo.toml
+++ b/examples/boot/application/stm32h7/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] }
10embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } 11embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
11embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
@@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true }
15panic-reset = { version = "0.1.1" } 16panic-reset = { version = "0.1.1" }
16embedded-hal = { version = "0.2.6" } 17embedded-hal = { version = "0.2.6" }
17 18
18cortex-m = "0.7.3" 19cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
19cortex-m-rt = "0.7.0" 20cortex-m-rt = "0.7.0"
20 21
21[features] 22[features]
diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs
index cc363bb32..0ecf60348 100644
--- a/examples/boot/application/stm32h7/src/bin/a.rs
+++ b/examples/boot/application/stm32h7/src/bin/a.rs
@@ -6,16 +6,17 @@
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner;
9use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _; 13use panic_reset as _;
14 14
15static APP_B: &[u8] = include_bytes!("../../b.bin"); 15static APP_B: &[u8] = include_bytes!("../../b.bin");
16 16
17#[embassy_executor::main] 17#[embassy_executor::main]
18async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { 18async fn main(_spawner: Spawner) {
19 let p = embassy_stm32::init(Default::default());
19 let flash = Flash::unlock(p.FLASH); 20 let flash = Flash::unlock(p.FLASH);
20 let mut flash = BlockingAsync::new(flash); 21 let mut flash = BlockingAsync::new(flash);
21 22
diff --git a/examples/boot/application/stm32h7/src/bin/b.rs b/examples/boot/application/stm32h7/src/bin/b.rs
index 3fa63bdcf..34799279c 100644
--- a/examples/boot/application/stm32h7/src/bin/b.rs
+++ b/examples/boot/application/stm32h7/src/bin/b.rs
@@ -4,14 +4,14 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_executor::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_time::{Duration, Timer};
11use panic_reset as _; 10use panic_reset as _;
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 Timer::after(Duration::from_millis(300)).await; 15 Timer::after(Duration::from_millis(300)).await;
16 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
17 led.set_high(); 17 led.set_high();
diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml
index a6936419c..8f37869e3 100644
--- a/examples/boot/application/stm32l0/Cargo.toml
+++ b/examples/boot/application/stm32l0/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] }
10embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } 11embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
11embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
@@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true }
15panic-reset = { version = "0.1.1" } 16panic-reset = { version = "0.1.1" }
16embedded-hal = { version = "0.2.6" } 17embedded-hal = { version = "0.2.6" }
17 18
18cortex-m = "0.7.3" 19cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
19cortex-m-rt = "0.7.0" 20cortex-m-rt = "0.7.0"
20 21
21[features] 22[features]
diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs
index fcf3f2ef1..f4f1d7119 100644
--- a/examples/boot/application/stm32l0/src/bin/a.rs
+++ b/examples/boot/application/stm32l0/src/bin/a.rs
@@ -6,17 +6,18 @@
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::time::{Duration, Timer}; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::Flash;
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::Peripherals; 13use embassy_time::{Duration, Timer};
14use panic_reset as _; 14use panic_reset as _;
15 15
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 16static APP_B: &[u8] = include_bytes!("../../b.bin");
17 17
18#[embassy_executor::main] 18#[embassy_executor::main]
19async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { 19async fn main(_spawner: Spawner) {
20 let p = embassy_stm32::init(Default::default());
20 let flash = Flash::unlock(p.FLASH); 21 let flash = Flash::unlock(p.FLASH);
21 let mut flash = BlockingAsync::new(flash); 22 let mut flash = BlockingAsync::new(flash);
22 23
diff --git a/examples/boot/application/stm32l0/src/bin/b.rs b/examples/boot/application/stm32l0/src/bin/b.rs
index 46e394c4c..ee40274ff 100644
--- a/examples/boot/application/stm32l0/src/bin/b.rs
+++ b/examples/boot/application/stm32l0/src/bin/b.rs
@@ -4,14 +4,14 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_executor::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_time::{Duration, Timer};
11use panic_reset as _; 10use panic_reset as _;
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 let mut led = Output::new(p.PB6, Level::High, Speed::Low); 15 let mut led = Output::new(p.PB6, Level::High, Speed::Low);
16 16
17 loop { 17 loop {
diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml
index 5e53cd5f6..6abf1986d 100644
--- a/examples/boot/application/stm32l1/Cargo.toml
+++ b/examples/boot/application/stm32l1/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] }
10embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } 11embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
11embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
@@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true }
15panic-reset = { version = "0.1.1" } 16panic-reset = { version = "0.1.1" }
16embedded-hal = { version = "0.2.6" } 17embedded-hal = { version = "0.2.6" }
17 18
18cortex-m = "0.7.3" 19cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
19cortex-m-rt = "0.7.0" 20cortex-m-rt = "0.7.0"
20 21
21[features] 22[features]
diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs
index fcf3f2ef1..f4f1d7119 100644
--- a/examples/boot/application/stm32l1/src/bin/a.rs
+++ b/examples/boot/application/stm32l1/src/bin/a.rs
@@ -6,17 +6,18 @@
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::time::{Duration, Timer}; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::Flash;
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::Peripherals; 13use embassy_time::{Duration, Timer};
14use panic_reset as _; 14use panic_reset as _;
15 15
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 16static APP_B: &[u8] = include_bytes!("../../b.bin");
17 17
18#[embassy_executor::main] 18#[embassy_executor::main]
19async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { 19async fn main(_spawner: Spawner) {
20 let p = embassy_stm32::init(Default::default());
20 let flash = Flash::unlock(p.FLASH); 21 let flash = Flash::unlock(p.FLASH);
21 let mut flash = BlockingAsync::new(flash); 22 let mut flash = BlockingAsync::new(flash);
22 23
diff --git a/examples/boot/application/stm32l1/src/bin/b.rs b/examples/boot/application/stm32l1/src/bin/b.rs
index 46e394c4c..ee40274ff 100644
--- a/examples/boot/application/stm32l1/src/bin/b.rs
+++ b/examples/boot/application/stm32l1/src/bin/b.rs
@@ -4,14 +4,14 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_executor::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_time::{Duration, Timer};
11use panic_reset as _; 10use panic_reset as _;
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 let mut led = Output::new(p.PB6, Level::High, Speed::Low); 15 let mut led = Output::new(p.PB6, Level::High, Speed::Low);
16 16
17 loop { 17 loop {
diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml
index bbb5e7e1d..6f2d12ff1 100644
--- a/examples/boot/application/stm32l4/Cargo.toml
+++ b/examples/boot/application/stm32l4/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] }
10embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } 11embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
11embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
@@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true }
15panic-reset = { version = "0.1.1" } 16panic-reset = { version = "0.1.1" }
16embedded-hal = { version = "0.2.6" } 17embedded-hal = { version = "0.2.6" }
17 18
18cortex-m = "0.7.3" 19cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
19cortex-m-rt = "0.7.0" 20cortex-m-rt = "0.7.0"
20 21
21[features] 22[features]
diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs
index f092f0239..178b2e04a 100644
--- a/examples/boot/application/stm32l4/src/bin/a.rs
+++ b/examples/boot/application/stm32l4/src/bin/a.rs
@@ -6,16 +6,17 @@
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner;
9use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _; 13use panic_reset as _;
14 14
15static APP_B: &[u8] = include_bytes!("../../b.bin"); 15static APP_B: &[u8] = include_bytes!("../../b.bin");
16 16
17#[embassy_executor::main] 17#[embassy_executor::main]
18async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { 18async fn main(_spawner: Spawner) {
19 let p = embassy_stm32::init(Default::default());
19 let flash = Flash::unlock(p.FLASH); 20 let flash = Flash::unlock(p.FLASH);
20 let mut flash = BlockingAsync::new(flash); 21 let mut flash = BlockingAsync::new(flash);
21 22
diff --git a/examples/boot/application/stm32l4/src/bin/b.rs b/examples/boot/application/stm32l4/src/bin/b.rs
index 934f862d9..a5862b1b0 100644
--- a/examples/boot/application/stm32l4/src/bin/b.rs
+++ b/examples/boot/application/stm32l4/src/bin/b.rs
@@ -4,14 +4,14 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_executor::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_time::{Duration, Timer};
11use panic_reset as _; 10use panic_reset as _;
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 let mut led = Output::new(p.PA5, Level::High, Speed::Low); 15 let mut led = Output::new(p.PA5, Level::High, Speed::Low);
16 16
17 loop { 17 loop {
diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml
index 62123a870..be97d4ebb 100644
--- a/examples/boot/application/stm32wl/Cargo.toml
+++ b/examples/boot/application/stm32wl/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] }
10embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } 11embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
11embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
@@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true }
15panic-reset = { version = "0.1.1" } 16panic-reset = { version = "0.1.1" }
16embedded-hal = { version = "0.2.6" } 17embedded-hal = { version = "0.2.6" }
17 18
18cortex-m = "0.7.3" 19cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
19cortex-m-rt = "0.7.0" 20cortex-m-rt = "0.7.0"
20 21
21[features] 22[features]
diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs
index 14408a90a..c71a42654 100644
--- a/examples/boot/application/stm32wl/src/bin/a.rs
+++ b/examples/boot/application/stm32wl/src/bin/a.rs
@@ -6,16 +6,17 @@
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner;
9use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _; 13use panic_reset as _;
14 14
15static APP_B: &[u8] = include_bytes!("../../b.bin"); 15static APP_B: &[u8] = include_bytes!("../../b.bin");
16 16
17#[embassy_executor::main] 17#[embassy_executor::main]
18async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { 18async fn main(_spawner: Spawner) {
19 let p = embassy_stm32::init(Default::default());
19 let flash = Flash::unlock(p.FLASH); 20 let flash = Flash::unlock(p.FLASH);
20 let mut flash = BlockingAsync::new(flash); 21 let mut flash = BlockingAsync::new(flash);
21 22
diff --git a/examples/boot/application/stm32wl/src/bin/b.rs b/examples/boot/application/stm32wl/src/bin/b.rs
index e565fd7c6..f9f0ffc60 100644
--- a/examples/boot/application/stm32wl/src/bin/b.rs
+++ b/examples/boot/application/stm32wl/src/bin/b.rs
@@ -4,14 +4,14 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_executor::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_time::{Duration, Timer};
11use panic_reset as _; 10use panic_reset as _;
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 let mut led = Output::new(p.PB15, Level::High, Speed::Low); 15 let mut led = Output::new(p.PB15, Level::High, Speed::Low);
16 16
17 loop { 17 loop {
diff --git a/examples/boot/bootloader/nrf/Cargo.toml b/examples/boot/bootloader/nrf/Cargo.toml
index 9683bff19..aa2a13ecb 100644
--- a/examples/boot/bootloader/nrf/Cargo.toml
+++ b/examples/boot/bootloader/nrf/Cargo.toml
@@ -10,7 +10,7 @@ defmt-rtt = { version = "0.3", optional = true }
10 10
11embassy-nrf = { path = "../../../../embassy-nrf", default-features = false, features = ["nightly"] } 11embassy-nrf = { path = "../../../../embassy-nrf", default-features = false, features = ["nightly"] }
12embassy-boot-nrf = { path = "../../../../embassy-boot/nrf", default-features = false } 12embassy-boot-nrf = { path = "../../../../embassy-boot/nrf", default-features = false }
13cortex-m = { version = "0.7" } 13cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
14cortex-m-rt = { version = "0.7" } 14cortex-m-rt = { version = "0.7" }
15cfg-if = "1.0.0" 15cfg-if = "1.0.0"
16 16
diff --git a/examples/boot/bootloader/stm32/Cargo.toml b/examples/boot/bootloader/stm32/Cargo.toml
index 4a3319528..491777103 100644
--- a/examples/boot/bootloader/stm32/Cargo.toml
+++ b/examples/boot/bootloader/stm32/Cargo.toml
@@ -10,7 +10,7 @@ defmt-rtt = { version = "0.3", optional = true }
10 10
11embassy-stm32 = { path = "../../../../embassy-stm32", default-features = false, features = ["nightly"] } 11embassy-stm32 = { path = "../../../../embassy-stm32", default-features = false, features = ["nightly"] }
12embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32", default-features = false } 12embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32", default-features = false }
13cortex-m = { version = "0.7" } 13cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
14cortex-m-rt = { version = "0.7" } 14cortex-m-rt = { version = "0.7" }
15embedded-storage = "0.3.0" 15embedded-storage = "0.3.0"
16embedded-storage-async = "0.3.0" 16embedded-storage-async = "0.3.0"
diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml
index 9c749a388..dad74235f 100644
--- a/examples/nrf-rtos-trace/Cargo.toml
+++ b/examples/nrf-rtos-trace/Cargo.toml
@@ -5,38 +5,26 @@ version = "0.1.0"
5 5
6[features] 6[features]
7default = ["log", "nightly"] 7default = ["log", "nightly"]
8nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embassy-usb-serial", "embassy-usb-hid", "embassy-usb-ncm", "embedded-io/async", "embassy-net"] 8nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unstable-traits"]
9log = [ 9log = [
10 "dep:log", 10 "dep:log",
11 "embassy-util/log", 11 "embassy-util/log",
12 "embassy-executor/log", 12 "embassy-executor/log",
13 "embassy-time/log",
13 "embassy-nrf/log", 14 "embassy-nrf/log",
14 "embassy-net/log",
15 "embassy-usb-ncm/log",
16 # Currently broken:
17 # "embassy-usb/log",
18 # "embassy-usb-serial/log",
19 # "embassy-usb-hid/log",
20] 15]
21 16
22[dependencies] 17[dependencies]
23embassy-util = { version = "0.1.0", path = "../../embassy-util" } 18embassy-util = { version = "0.1.0", path = "../../embassy-util" }
24embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features=["rtos-trace", "rtos-trace-interrupt"] } 19embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features=["rtos-trace", "rtos-trace-interrupt", "integrated-timers"] }
20embassy-time = { version = "0.1.0", path = "../../embassy-time" }
25embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } 21embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
26embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true }
27embassy-usb = { version = "0.1.0", path = "../../embassy-usb", optional = true }
28embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", optional = true }
29embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", optional = true }
30embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", optional = true }
31embedded-io = "0.3.0"
32 22
33cortex-m = "0.7.3" 23cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
34cortex-m-rt = "0.7.0" 24cortex-m-rt = "0.7.0"
35panic-probe = { version = "0.3" } 25panic-probe = { version = "0.3" }
36futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 26futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
37rand = { version = "0.8.4", default-features = false } 27rand = { version = "0.8.4", default-features = false }
38embedded-storage = "0.3.0"
39usbd-hid = "0.5.2"
40serde = { version = "1.0.136", default-features = false } 28serde = { version = "1.0.136", default-features = false }
41rtos-trace = "0.1.3" 29rtos-trace = "0.1.3"
42systemview-target = { version = "0.1.1", features = ["callbacks-app", "callbacks-os", "log", "cortex-m"] } 30systemview-target = { version = "0.1.1", features = ["callbacks-app", "callbacks-os", "log", "cortex-m"] }
diff --git a/examples/nrf-rtos-trace/src/bin/rtos_trace.rs b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs
index 5699fe8e2..7d1ad87c8 100644
--- a/examples/nrf-rtos-trace/src/bin/rtos_trace.rs
+++ b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs
@@ -4,9 +4,8 @@
4 4
5use core::task::Poll; 5use core::task::Poll;
6 6
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_executor::time::{Duration, Instant, Timer}; 8use embassy_time::{Duration, Instant, Timer};
9use embassy_nrf::Peripherals;
10#[cfg(feature = "log")] 9#[cfg(feature = "log")]
11use log::*; 10use log::*;
12use panic_probe as _; 11use panic_probe as _;
@@ -55,7 +54,8 @@ async fn run3() {
55} 54}
56 55
57#[embassy_executor::main] 56#[embassy_executor::main]
58async fn main(spawner: Spawner, _p: Peripherals) { 57async fn main(spawner: Spawner) {
58 let _p = embassy_nrf::init(Default::default());
59 LOGGER.init(); 59 LOGGER.init();
60 #[cfg(feature = "log")] 60 #[cfg(feature = "log")]
61 { 61 {
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml
index 91edbd36d..2fcc31221 100644
--- a/examples/nrf/Cargo.toml
+++ b/examples/nrf/Cargo.toml
@@ -9,7 +9,8 @@ nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unsta
9 9
10[dependencies] 10[dependencies]
11embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 11embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
12embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime"] } 12embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
13embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
13embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } 14embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
14embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } 15embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true }
15embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } 16embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true }
@@ -21,7 +22,7 @@ embedded-io = "0.3.0"
21defmt = "0.3" 22defmt = "0.3"
22defmt-rtt = "0.3" 23defmt-rtt = "0.3"
23 24
24cortex-m = "0.7.3" 25cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
25cortex-m-rt = "0.7.0" 26cortex-m-rt = "0.7.0"
26panic-probe = { version = "0.3", features = ["print-defmt"] } 27panic-probe = { version = "0.3", features = ["print-defmt"] }
27futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 28futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
diff --git a/examples/nrf/src/bin/awaitable_timer.rs b/examples/nrf/src/bin/awaitable_timer.rs
index f2c1d9fa4..b32af236c 100644
--- a/examples/nrf/src/bin/awaitable_timer.rs
+++ b/examples/nrf/src/bin/awaitable_timer.rs
@@ -3,13 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::interrupt;
7use embassy_nrf::timer::Timer; 8use embassy_nrf::timer::Timer;
8use embassy_nrf::{interrupt, Peripherals};
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
11#[embassy_executor::main] 11#[embassy_executor::main]
12async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_nrf::init(Default::default());
13 let mut t = Timer::new_awaitable(p.TIMER0, interrupt::take!(TIMER0)); 14 let mut t = Timer::new_awaitable(p.TIMER0, interrupt::take!(TIMER0));
14 // default frequency is 1MHz, so this triggers every second 15 // default frequency is 1MHz, so this triggers every second
15 t.cc(0).write(1_000_000); 16 t.cc(0).write(1_000_000);
diff --git a/examples/nrf/src/bin/blinky.rs b/examples/nrf/src/bin/blinky.rs
index 98db6546c..513f6cd82 100644
--- a/examples/nrf/src/bin/blinky.rs
+++ b/examples/nrf/src/bin/blinky.rs
@@ -2,14 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use embassy_executor::executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_executor::time::{Duration, Timer};
7use embassy_nrf::gpio::{Level, Output, OutputDrive}; 6use embassy_nrf::gpio::{Level, Output, OutputDrive};
8use embassy_nrf::Peripherals; 7use embassy_time::{Duration, Timer};
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::main] 10#[embassy_executor::main]
12async fn main(_spawner: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner) {
12 let p = embassy_nrf::init(Default::default());
13 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); 13 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
14 14
15 loop { 15 loop {
diff --git a/examples/nrf/src/bin/buffered_uart.rs b/examples/nrf/src/bin/buffered_uart.rs
index f02b7d845..ea566f4b2 100644
--- a/examples/nrf/src/bin/buffered_uart.rs
+++ b/examples/nrf/src/bin/buffered_uart.rs
@@ -3,15 +3,16 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::buffered_uarte::{BufferedUarte, State}; 7use embassy_nrf::buffered_uarte::{BufferedUarte, State};
8use embassy_nrf::{interrupt, uarte, Peripherals}; 8use embassy_nrf::{interrupt, uarte};
9use embedded_io::asynch::{BufRead, Write}; 9use embedded_io::asynch::{BufRead, Write};
10use futures::pin_mut; 10use futures::pin_mut;
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13#[embassy_executor::main] 13#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner) {
15 let p = embassy_nrf::init(Default::default());
15 let mut config = uarte::Config::default(); 16 let mut config = uarte::Config::default();
16 config.parity = uarte::Parity::EXCLUDED; 17 config.parity = uarte::Parity::EXCLUDED;
17 config.baudrate = uarte::Baudrate::BAUD115200; 18 config.baudrate = uarte::Baudrate::BAUD115200;
diff --git a/examples/nrf/src/bin/channel.rs b/examples/nrf/src/bin/channel.rs
index e97c6c5ee..195200988 100644
--- a/examples/nrf/src/bin/channel.rs
+++ b/examples/nrf/src/bin/channel.rs
@@ -3,10 +3,9 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::unwrap; 5use defmt::unwrap;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_nrf::gpio::{Level, Output, OutputDrive}; 7use embassy_nrf::gpio::{Level, Output, OutputDrive};
9use embassy_nrf::Peripherals; 8use embassy_time::{Duration, Timer};
10use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 9use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
11use embassy_util::channel::mpmc::Channel; 10use embassy_util::channel::mpmc::Channel;
12use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
@@ -29,7 +28,8 @@ async fn my_task() {
29} 28}
30 29
31#[embassy_executor::main] 30#[embassy_executor::main]
32async fn main(spawner: Spawner, p: Peripherals) { 31async fn main(spawner: Spawner) {
32 let p = embassy_nrf::init(Default::default());
33 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); 33 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
34 34
35 unwrap!(spawner.spawn(my_task())); 35 unwrap!(spawner.spawn(my_task()));
diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf/src/bin/channel_sender_receiver.rs
index bca7bb248..c9c458aec 100644
--- a/examples/nrf/src/bin/channel_sender_receiver.rs
+++ b/examples/nrf/src/bin/channel_sender_receiver.rs
@@ -3,10 +3,9 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::unwrap; 5use defmt::unwrap;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; 7use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin};
9use embassy_nrf::Peripherals; 8use embassy_time::{Duration, Timer};
10use embassy_util::blocking_mutex::raw::NoopRawMutex; 9use embassy_util::blocking_mutex::raw::NoopRawMutex;
11use embassy_util::channel::mpmc::{Channel, Receiver, Sender}; 10use embassy_util::channel::mpmc::{Channel, Receiver, Sender};
12use embassy_util::Forever; 11use embassy_util::Forever;
@@ -42,7 +41,8 @@ async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedSta
42} 41}
43 42
44#[embassy_executor::main] 43#[embassy_executor::main]
45async fn main(spawner: Spawner, p: Peripherals) { 44async fn main(spawner: Spawner) {
45 let p = embassy_nrf::init(Default::default());
46 let channel = CHANNEL.put(Channel::new()); 46 let channel = CHANNEL.put(Channel::new());
47 47
48 unwrap!(spawner.spawn(send_task(channel.sender()))); 48 unwrap!(spawner.spawn(send_task(channel.sender())));
diff --git a/examples/nrf/src/bin/executor_fairness_test.rs b/examples/nrf/src/bin/executor_fairness_test.rs
index b98454936..9ae030d07 100644
--- a/examples/nrf/src/bin/executor_fairness_test.rs
+++ b/examples/nrf/src/bin/executor_fairness_test.rs
@@ -5,9 +5,8 @@
5use core::task::Poll; 5use core::task::Poll;
6 6
7use defmt::{info, unwrap}; 7use defmt::{info, unwrap};
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_executor::time::{Duration, Instant, Timer}; 9use embassy_time::{Duration, Instant, Timer};
10use embassy_nrf::Peripherals;
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy_executor::task] 12#[embassy_executor::task]
@@ -35,7 +34,8 @@ async fn run3() {
35} 34}
36 35
37#[embassy_executor::main] 36#[embassy_executor::main]
38async fn main(spawner: Spawner, _p: Peripherals) { 37async fn main(spawner: Spawner) {
38 let _p = embassy_nrf::init(Default::default());
39 unwrap!(spawner.spawn(run1())); 39 unwrap!(spawner.spawn(run1()));
40 unwrap!(spawner.spawn(run2())); 40 unwrap!(spawner.spawn(run2()));
41 unwrap!(spawner.spawn(run3())); 41 unwrap!(spawner.spawn(run3()));
diff --git a/examples/nrf/src/bin/gpiote_channel.rs b/examples/nrf/src/bin/gpiote_channel.rs
index 65c7b4df7..5bfd02465 100644
--- a/examples/nrf/src/bin/gpiote_channel.rs
+++ b/examples/nrf/src/bin/gpiote_channel.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::gpio::{Input, Pull}; 7use embassy_nrf::gpio::{Input, Pull};
8use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; 8use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity};
9use embassy_nrf::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_nrf::init(Default::default());
14 info!("Starting!"); 14 info!("Starting!");
15 15
16 let ch1 = InputChannel::new( 16 let ch1 = InputChannel::new(
diff --git a/examples/nrf/src/bin/gpiote_port.rs b/examples/nrf/src/bin/gpiote_port.rs
index 7746a7f96..0155d539e 100644
--- a/examples/nrf/src/bin/gpiote_port.rs
+++ b/examples/nrf/src/bin/gpiote_port.rs
@@ -3,9 +3,8 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; 7use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull};
8use embassy_nrf::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::task(pool_size = 4)] 10#[embassy_executor::task(pool_size = 4)]
@@ -19,7 +18,8 @@ async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) {
19} 18}
20 19
21#[embassy_executor::main] 20#[embassy_executor::main]
22async fn main(spawner: Spawner, p: Peripherals) { 21async fn main(spawner: Spawner) {
22 let p = embassy_nrf::init(Default::default());
23 info!("Starting!"); 23 info!("Starting!");
24 24
25 let btn1 = Input::new(p.P0_11.degrade(), Pull::Up); 25 let btn1 = Input::new(p.P0_11.degrade(), Pull::Up);
diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs
index 7050da378..b653689a7 100644
--- a/examples/nrf/src/bin/multiprio.rs
+++ b/examples/nrf/src/bin/multiprio.rs
@@ -59,10 +59,10 @@
59 59
60use cortex_m_rt::entry; 60use cortex_m_rt::entry;
61use defmt::{info, unwrap}; 61use defmt::{info, unwrap};
62use embassy_executor::time::{Duration, Instant, Timer};
63use embassy_nrf::executor::{Executor, InterruptExecutor}; 62use embassy_nrf::executor::{Executor, InterruptExecutor};
64use embassy_nrf::interrupt; 63use embassy_nrf::interrupt;
65use embassy_nrf::interrupt::InterruptExt; 64use embassy_nrf::interrupt::InterruptExt;
65use embassy_time::{Duration, Instant, Timer};
66use embassy_util::Forever; 66use embassy_util::Forever;
67use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
68 68
diff --git a/examples/nrf/src/bin/mutex.rs b/examples/nrf/src/bin/mutex.rs
index 5fe7eadb9..876297883 100644
--- a/examples/nrf/src/bin/mutex.rs
+++ b/examples/nrf/src/bin/mutex.rs
@@ -3,9 +3,8 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
8use embassy_nrf::Peripherals;
9use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 8use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
10use embassy_util::mutex::Mutex; 9use embassy_util::mutex::Mutex;
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
@@ -30,7 +29,8 @@ async fn my_task() {
30} 29}
31 30
32#[embassy_executor::main] 31#[embassy_executor::main]
33async fn main(spawner: Spawner, _p: Peripherals) { 32async fn main(spawner: Spawner) {
33 let _p = embassy_nrf::init(Default::default());
34 unwrap!(spawner.spawn(my_task())); 34 unwrap!(spawner.spawn(my_task()));
35 35
36 loop { 36 loop {
diff --git a/examples/nrf/src/bin/nvmc.rs b/examples/nrf/src/bin/nvmc.rs
index 1d4387de7..75d090fbb 100644
--- a/examples/nrf/src/bin/nvmc.rs
+++ b/examples/nrf/src/bin/nvmc.rs
@@ -3,15 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_nrf::nvmc::Nvmc; 7use embassy_nrf::nvmc::Nvmc;
9use embassy_nrf::Peripherals; 8use embassy_time::{Duration, Timer};
10use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_nrf::init(Default::default());
15 info!("Hello NVMC!"); 15 info!("Hello NVMC!");
16 16
17 // probe-run breaks without this, I'm not sure why. 17 // probe-run breaks without this, I'm not sure why.
diff --git a/examples/nrf/src/bin/ppi.rs b/examples/nrf/src/bin/ppi.rs
index 9a60cc0a0..d74ce4064 100644
--- a/examples/nrf/src/bin/ppi.rs
+++ b/examples/nrf/src/bin/ppi.rs
@@ -5,16 +5,16 @@
5use core::future::pending; 5use core::future::pending;
6 6
7use defmt::info; 7use defmt::info;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; 9use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
10use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity}; 10use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity};
11use embassy_nrf::ppi::Ppi; 11use embassy_nrf::ppi::Ppi;
12use embassy_nrf::Peripherals;
13use gpiote::{OutputChannel, OutputChannelPolarity}; 12use gpiote::{OutputChannel, OutputChannelPolarity};
14use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
15 14
16#[embassy_executor::main] 15#[embassy_executor::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 16async fn main(_spawner: Spawner) {
17 let p = embassy_nrf::init(Default::default());
18 info!("Starting!"); 18 info!("Starting!");
19 19
20 let button1 = InputChannel::new( 20 let button1 = InputChannel::new(
diff --git a/examples/nrf/src/bin/pubsub.rs b/examples/nrf/src/bin/pubsub.rs
index 5f33f3e0b..1d90217f2 100644
--- a/examples/nrf/src/bin/pubsub.rs
+++ b/examples/nrf/src/bin/pubsub.rs
@@ -3,8 +3,8 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::unwrap; 5use defmt::unwrap;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
8use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 8use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
9use embassy_util::channel::pubsub::{DynSubscriber, PubSubChannel, Subscriber}; 9use embassy_util::channel::pubsub::{DynSubscriber, PubSubChannel, Subscriber};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
@@ -20,7 +20,8 @@ enum Message {
20} 20}
21 21
22#[embassy_executor::main] 22#[embassy_executor::main]
23async fn main(spawner: Spawner, _p: embassy_nrf::Peripherals) { 23async fn main(spawner: Spawner) {
24 let _p = embassy_nrf::init(Default::default());
24 defmt::info!("Hello World!"); 25 defmt::info!("Hello World!");
25 26
26 // It's good to set up the subscribers before publishing anything. 27 // It's good to set up the subscribers before publishing anything.
diff --git a/examples/nrf/src/bin/pwm.rs b/examples/nrf/src/bin/pwm.rs
index c8a083294..1698c0bc8 100644
--- a/examples/nrf/src/bin/pwm.rs
+++ b/examples/nrf/src/bin/pwm.rs
@@ -3,10 +3,9 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_nrf::pwm::{Prescaler, SimplePwm}; 7use embassy_nrf::pwm::{Prescaler, SimplePwm};
9use embassy_nrf::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12// for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='') 11// for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='')
@@ -71,7 +70,8 @@ static DUTY: [u16; 1024] = [
71]; 70];
72 71
73#[embassy_executor::main] 72#[embassy_executor::main]
74async fn main(_spawner: Spawner, p: Peripherals) { 73async fn main(_spawner: Spawner) {
74 let p = embassy_nrf::init(Default::default());
75 let mut pwm = SimplePwm::new_4ch(p.PWM0, p.P0_13, p.P0_14, p.P0_16, p.P0_15); 75 let mut pwm = SimplePwm::new_4ch(p.PWM0, p.P0_13, p.P0_14, p.P0_16, p.P0_15);
76 pwm.set_prescaler(Prescaler::Div1); 76 pwm.set_prescaler(Prescaler::Div1);
77 pwm.set_max_duty(32767); 77 pwm.set_max_duty(32767);
diff --git a/examples/nrf/src/bin/pwm_double_sequence.rs b/examples/nrf/src/bin/pwm_double_sequence.rs
index cfd8db86b..16e50e909 100644
--- a/examples/nrf/src/bin/pwm_double_sequence.rs
+++ b/examples/nrf/src/bin/pwm_double_sequence.rs
@@ -3,16 +3,16 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_nrf::pwm::{ 7use embassy_nrf::pwm::{
9 Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequencer, StartSequence, 8 Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequencer, StartSequence,
10}; 9};
11use embassy_nrf::Peripherals; 10use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
13 12
14#[embassy_executor::main] 13#[embassy_executor::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner) {
15 let p = embassy_nrf::init(Default::default());
16 let seq_words_0: [u16; 5] = [1000, 250, 100, 50, 0]; 16 let seq_words_0: [u16; 5] = [1000, 250, 100, 50, 0];
17 let seq_words_1: [u16; 4] = [50, 100, 250, 1000]; 17 let seq_words_1: [u16; 4] = [50, 100, 250, 1000];
18 18
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs
index b7a04c036..b9aca9aaa 100644
--- a/examples/nrf/src/bin/pwm_sequence.rs
+++ b/examples/nrf/src/bin/pwm_sequence.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer}; 7use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer};
9use embassy_nrf::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_nrf::init(Default::default());
14 let seq_words: [u16; 5] = [1000, 250, 100, 50, 0]; 14 let seq_words: [u16; 5] = [1000, 250, 100, 50, 0];
15 15
16 let mut config = Config::default(); 16 let mut config = Config::default();
diff --git a/examples/nrf/src/bin/pwm_sequence_ppi.rs b/examples/nrf/src/bin/pwm_sequence_ppi.rs
index f5c587c35..6594fa348 100644
--- a/examples/nrf/src/bin/pwm_sequence_ppi.rs
+++ b/examples/nrf/src/bin/pwm_sequence_ppi.rs
@@ -5,16 +5,16 @@
5use core::future::pending; 5use core::future::pending;
6 6
7use defmt::*; 7use defmt::*;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_nrf::gpio::{Input, Pull}; 9use embassy_nrf::gpio::{Input, Pull};
10use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; 10use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity};
11use embassy_nrf::ppi::Ppi; 11use embassy_nrf::ppi::Ppi;
12use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer}; 12use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer};
13use embassy_nrf::Peripherals;
14use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
15 14
16#[embassy_executor::main] 15#[embassy_executor::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 16async fn main(_spawner: Spawner) {
17 let p = embassy_nrf::init(Default::default());
18 let seq_words: [u16; 5] = [1000, 250, 100, 50, 0]; 18 let seq_words: [u16; 5] = [1000, 250, 100, 50, 0];
19 19
20 let mut config = Config::default(); 20 let mut config = Config::default();
diff --git a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs b/examples/nrf/src/bin/pwm_sequence_ws2812b.rs
index d6b3f005c..711c8a17b 100644
--- a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs
+++ b/examples/nrf/src/bin/pwm_sequence_ws2812b.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_nrf::pwm::{ 7use embassy_nrf::pwm::{
9 Config, Prescaler, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode, SingleSequencer, 8 Config, Prescaler, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode, SingleSequencer,
10}; 9};
11use embassy_nrf::Peripherals; 10use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
13 12
14// WS2812B LED light demonstration. Drives just one light. 13// WS2812B LED light demonstration. Drives just one light.
@@ -27,7 +26,8 @@ const RES: u16 = 0x8000;
27// Provides data to a WS2812b (Neopixel) LED and makes it go blue. The data 26// Provides data to a WS2812b (Neopixel) LED and makes it go blue. The data
28// line is assumed to be P1_05. 27// line is assumed to be P1_05.
29#[embassy_executor::main] 28#[embassy_executor::main]
30async fn main(_spawner: Spawner, p: Peripherals) { 29async fn main(_spawner: Spawner) {
30 let p = embassy_nrf::init(Default::default());
31 let mut config = Config::default(); 31 let mut config = Config::default();
32 config.sequence_load = SequenceLoad::Common; 32 config.sequence_load = SequenceLoad::Common;
33 config.prescaler = Prescaler::Div1; 33 config.prescaler = Prescaler::Div1;
diff --git a/examples/nrf/src/bin/pwm_servo.rs b/examples/nrf/src/bin/pwm_servo.rs
index d28a5a17e..19228f433 100644
--- a/examples/nrf/src/bin/pwm_servo.rs
+++ b/examples/nrf/src/bin/pwm_servo.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_nrf::pwm::{Prescaler, SimplePwm}; 7use embassy_nrf::pwm::{Prescaler, SimplePwm};
9use embassy_nrf::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_nrf::init(Default::default());
14 let mut pwm = SimplePwm::new_1ch(p.PWM0, p.P0_05); 14 let mut pwm = SimplePwm::new_1ch(p.PWM0, p.P0_05);
15 // sg90 microervo requires 50hz or 20ms period 15 // sg90 microervo requires 50hz or 20ms period
16 // set_period can only set down to 125khz so we cant use it directly 16 // set_period can only set down to 125khz so we cant use it directly
diff --git a/examples/nrf/src/bin/qdec.rs b/examples/nrf/src/bin/qdec.rs
index 6bda82f78..600bba07a 100644
--- a/examples/nrf/src/bin/qdec.rs
+++ b/examples/nrf/src/bin/qdec.rs
@@ -3,13 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::interrupt;
7use embassy_nrf::qdec::{self, Qdec}; 8use embassy_nrf::qdec::{self, Qdec};
8use embassy_nrf::{interrupt, Peripherals};
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
11#[embassy_executor::main] 11#[embassy_executor::main]
12async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_nrf::init(Default::default());
13 let irq = interrupt::take!(QDEC); 14 let irq = interrupt::take!(QDEC);
14 let config = qdec::Config::default(); 15 let config = qdec::Config::default();
15 let mut rotary_enc = Qdec::new(p.QDEC, irq, p.P0_31, p.P0_30, config); 16 let mut rotary_enc = Qdec::new(p.QDEC, irq, p.P0_31, p.P0_30, config);
diff --git a/examples/nrf/src/bin/qspi.rs b/examples/nrf/src/bin/qspi.rs
index 57e0fdbe2..bdcf710b8 100644
--- a/examples/nrf/src/bin/qspi.rs
+++ b/examples/nrf/src/bin/qspi.rs
@@ -3,8 +3,8 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{assert_eq, info, unwrap}; 5use defmt::{assert_eq, info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::{interrupt, qspi, Peripherals}; 7use embassy_nrf::{interrupt, qspi};
8use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
9 9
10const PAGE_SIZE: usize = 4096; 10const PAGE_SIZE: usize = 4096;
@@ -15,7 +15,8 @@ const PAGE_SIZE: usize = 4096;
15struct AlignedBuf([u8; 4096]); 15struct AlignedBuf([u8; 4096]);
16 16
17#[embassy_executor::main] 17#[embassy_executor::main]
18async fn main(_spawner: Spawner, p: Peripherals) { 18async fn main(_spawner: Spawner) {
19 let p = embassy_nrf::init(Default::default());
19 // Config for the MX25R64 present in the nRF52840 DK 20 // Config for the MX25R64 present in the nRF52840 DK
20 let mut config = qspi::Config::default(); 21 let mut config = qspi::Config::default();
21 config.read_opcode = qspi::ReadOpcode::READ4IO; 22 config.read_opcode = qspi::ReadOpcode::READ4IO;
diff --git a/examples/nrf/src/bin/qspi_lowpower.rs b/examples/nrf/src/bin/qspi_lowpower.rs
index 080b27a16..9341a2376 100644
--- a/examples/nrf/src/bin/qspi_lowpower.rs
+++ b/examples/nrf/src/bin/qspi_lowpower.rs
@@ -5,9 +5,9 @@
5use core::mem; 5use core::mem;
6 6
7use defmt::{info, unwrap}; 7use defmt::{info, unwrap};
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_executor::time::{Duration, Timer}; 9use embassy_nrf::{interrupt, qspi};
10use embassy_nrf::{interrupt, qspi, Peripherals}; 10use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13// Workaround for alignment requirements. 13// Workaround for alignment requirements.
@@ -16,7 +16,8 @@ use {defmt_rtt as _, panic_probe as _};
16struct AlignedBuf([u8; 64]); 16struct AlignedBuf([u8; 64]);
17 17
18#[embassy_executor::main] 18#[embassy_executor::main]
19async fn main(_spawner: Spawner, mut p: Peripherals) { 19async fn main(_p: Spawner) {
20 let mut p = embassy_nrf::init(Default::default());
20 let mut irq = interrupt::take!(QSPI); 21 let mut irq = interrupt::take!(QSPI);
21 22
22 loop { 23 loop {
diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs
index 9199d3aeb..415579be7 100644
--- a/examples/nrf/src/bin/raw_spawn.rs
+++ b/examples/nrf/src/bin/raw_spawn.rs
@@ -5,9 +5,9 @@ use core::mem;
5 5
6use cortex_m_rt::entry; 6use cortex_m_rt::entry;
7use defmt::{info, unwrap}; 7use defmt::{info, unwrap};
8use embassy_executor::executor::raw::TaskStorage; 8use embassy_executor::raw::TaskStorage;
9use embassy_executor::executor::Executor; 9use embassy_executor::Executor;
10use embassy_executor::time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
11use embassy_util::Forever; 11use embassy_util::Forever;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
diff --git a/examples/nrf/src/bin/rng.rs b/examples/nrf/src/bin/rng.rs
index a4314e8b9..647073949 100644
--- a/examples/nrf/src/bin/rng.rs
+++ b/examples/nrf/src/bin/rng.rs
@@ -2,14 +2,15 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use embassy_executor::executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_nrf::interrupt;
6use embassy_nrf::rng::Rng; 7use embassy_nrf::rng::Rng;
7use embassy_nrf::{interrupt, Peripherals};
8use rand::Rng as _; 8use rand::Rng as _;
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
11#[embassy_executor::main] 11#[embassy_executor::main]
12async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_nrf::init(Default::default());
13 let mut rng = Rng::new(p.RNG, interrupt::take!(RNG)); 14 let mut rng = Rng::new(p.RNG, interrupt::take!(RNG));
14 15
15 // Async API 16 // Async API
diff --git a/examples/nrf/src/bin/saadc.rs b/examples/nrf/src/bin/saadc.rs
index 65c78d842..7cf588090 100644
--- a/examples/nrf/src/bin/saadc.rs
+++ b/examples/nrf/src/bin/saadc.rs
@@ -3,14 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_nrf::interrupt;
8use embassy_nrf::saadc::{ChannelConfig, Config, Saadc}; 8use embassy_nrf::saadc::{ChannelConfig, Config, Saadc};
9use embassy_nrf::{interrupt, Peripherals}; 9use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12#[embassy_executor::main] 12#[embassy_executor::main]
13async fn main(_spawner: Spawner, mut p: Peripherals) { 13async fn main(_p: Spawner) {
14 let mut p = embassy_nrf::init(Default::default());
14 let config = Config::default(); 15 let config = Config::default();
15 let channel_config = ChannelConfig::single_ended(&mut p.P0_02); 16 let channel_config = ChannelConfig::single_ended(&mut p.P0_02);
16 let mut saadc = Saadc::new(p.SAADC, interrupt::take!(SAADC), config, [channel_config]); 17 let mut saadc = Saadc::new(p.SAADC, interrupt::take!(SAADC), config, [channel_config]);
diff --git a/examples/nrf/src/bin/saadc_continuous.rs b/examples/nrf/src/bin/saadc_continuous.rs
index d0305736f..bb50ac65e 100644
--- a/examples/nrf/src/bin/saadc_continuous.rs
+++ b/examples/nrf/src/bin/saadc_continuous.rs
@@ -3,17 +3,18 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::Duration; 7use embassy_nrf::interrupt;
8use embassy_nrf::saadc::{ChannelConfig, Config, Saadc, SamplerState}; 8use embassy_nrf::saadc::{ChannelConfig, Config, Saadc, SamplerState};
9use embassy_nrf::timer::Frequency; 9use embassy_nrf::timer::Frequency;
10use embassy_nrf::{interrupt, Peripherals}; 10use embassy_time::Duration;
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13// Demonstrates both continuous sampling and scanning multiple channels driven by a PPI linked timer 13// Demonstrates both continuous sampling and scanning multiple channels driven by a PPI linked timer
14 14
15#[embassy_executor::main] 15#[embassy_executor::main]
16async fn main(_spawner: Spawner, mut p: Peripherals) { 16async fn main(_p: Spawner) {
17 let mut p = embassy_nrf::init(Default::default());
17 let config = Config::default(); 18 let config = Config::default();
18 let channel_1_config = ChannelConfig::single_ended(&mut p.P0_02); 19 let channel_1_config = ChannelConfig::single_ended(&mut p.P0_02);
19 let channel_2_config = ChannelConfig::single_ended(&mut p.P0_03); 20 let channel_2_config = ChannelConfig::single_ended(&mut p.P0_03);
@@ -27,7 +28,7 @@ async fn main(_spawner: Spawner, mut p: Peripherals) {
27 28
28 // This delay demonstrates that starting the timer prior to running 29 // This delay demonstrates that starting the timer prior to running
29 // the task sampler is benign given the calibration that follows. 30 // the task sampler is benign given the calibration that follows.
30 embassy_executor::time::Timer::after(Duration::from_millis(500)).await; 31 embassy_time::Timer::after(Duration::from_millis(500)).await;
31 saadc.calibrate().await; 32 saadc.calibrate().await;
32 33
33 let mut bufs = [[[0; 3]; 500]; 2]; 34 let mut bufs = [[[0; 3]; 500]; 2];
diff --git a/examples/nrf/src/bin/self_spawn.rs b/examples/nrf/src/bin/self_spawn.rs
index e0152802e..196255a52 100644
--- a/examples/nrf/src/bin/self_spawn.rs
+++ b/examples/nrf/src/bin/self_spawn.rs
@@ -3,9 +3,8 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
8use embassy_nrf::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::task(pool_size = 2)] 10#[embassy_executor::task(pool_size = 2)]
@@ -16,7 +15,8 @@ async fn my_task(spawner: Spawner, n: u32) {
16} 15}
17 16
18#[embassy_executor::main] 17#[embassy_executor::main]
19async fn main(spawner: Spawner, _p: Peripherals) { 18async fn main(spawner: Spawner) {
19 let _p = embassy_nrf::init(Default::default());
20 info!("Hello World!"); 20 info!("Hello World!");
21 unwrap!(spawner.spawn(my_task(spawner, 0))); 21 unwrap!(spawner.spawn(my_task(spawner, 0)));
22} 22}
diff --git a/examples/nrf/src/bin/self_spawn_current_executor.rs b/examples/nrf/src/bin/self_spawn_current_executor.rs
index 1d8309d77..8a179886c 100644
--- a/examples/nrf/src/bin/self_spawn_current_executor.rs
+++ b/examples/nrf/src/bin/self_spawn_current_executor.rs
@@ -3,9 +3,8 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
8use embassy_nrf::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::task(pool_size = 2)] 10#[embassy_executor::task(pool_size = 2)]
@@ -16,7 +15,8 @@ async fn my_task(n: u32) {
16} 15}
17 16
18#[embassy_executor::main] 17#[embassy_executor::main]
19async fn main(spawner: Spawner, _p: Peripherals) { 18async fn main(spawner: Spawner) {
19 let _p = embassy_nrf::init(Default::default());
20 info!("Hello World!"); 20 info!("Hello World!");
21 unwrap!(spawner.spawn(my_task(0))); 21 unwrap!(spawner.spawn(my_task(0)));
22} 22}
diff --git a/examples/nrf/src/bin/spim.rs b/examples/nrf/src/bin/spim.rs
index fd741b21c..132e01660 100644
--- a/examples/nrf/src/bin/spim.rs
+++ b/examples/nrf/src/bin/spim.rs
@@ -3,13 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::gpio::{Level, Output, OutputDrive}; 7use embassy_nrf::gpio::{Level, Output, OutputDrive};
8use embassy_nrf::{interrupt, spim, Peripherals}; 8use embassy_nrf::{interrupt, spim};
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
11#[embassy_executor::main] 11#[embassy_executor::main]
12async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_nrf::init(Default::default());
13 info!("running!"); 14 info!("running!");
14 15
15 let mut config = spim::Config::default(); 16 let mut config = spim::Config::default();
diff --git a/examples/nrf/src/bin/temp.rs b/examples/nrf/src/bin/temp.rs
index 654098e0b..b06ac709e 100644
--- a/examples/nrf/src/bin/temp.rs
+++ b/examples/nrf/src/bin/temp.rs
@@ -3,14 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_nrf::interrupt;
8use embassy_nrf::temp::Temp; 8use embassy_nrf::temp::Temp;
9use embassy_nrf::{interrupt, Peripherals}; 9use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12#[embassy_executor::main] 12#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_nrf::init(Default::default());
14 let irq = interrupt::take!(TEMP); 15 let irq = interrupt::take!(TEMP);
15 let mut temp = Temp::new(p.TEMP, irq); 16 let mut temp = Temp::new(p.TEMP, irq);
16 17
diff --git a/examples/nrf/src/bin/timer.rs b/examples/nrf/src/bin/timer.rs
index 61ff1d6db..c22b5acd5 100644
--- a/examples/nrf/src/bin/timer.rs
+++ b/examples/nrf/src/bin/timer.rs
@@ -3,9 +3,8 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
8use embassy_nrf::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::task] 10#[embassy_executor::task]
@@ -25,7 +24,8 @@ async fn run2() {
25} 24}
26 25
27#[embassy_executor::main] 26#[embassy_executor::main]
28async fn main(spawner: Spawner, _p: Peripherals) { 27async fn main(spawner: Spawner) {
28 let _p = embassy_nrf::init(Default::default());
29 unwrap!(spawner.spawn(run1())); 29 unwrap!(spawner.spawn(run1()));
30 unwrap!(spawner.spawn(run2())); 30 unwrap!(spawner.spawn(run2()));
31} 31}
diff --git a/examples/nrf/src/bin/twim.rs b/examples/nrf/src/bin/twim.rs
index bb7ee9db4..a027cc1e7 100644
--- a/examples/nrf/src/bin/twim.rs
+++ b/examples/nrf/src/bin/twim.rs
@@ -7,15 +7,16 @@
7#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
8 8
9use defmt::*; 9use defmt::*;
10use embassy_executor::executor::Spawner; 10use embassy_executor::Spawner;
11use embassy_nrf::interrupt;
11use embassy_nrf::twim::{self, Twim}; 12use embassy_nrf::twim::{self, Twim};
12use embassy_nrf::{interrupt, Peripherals};
13use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
14 14
15const ADDRESS: u8 = 0x50; 15const ADDRESS: u8 = 0x50;
16 16
17#[embassy_executor::main] 17#[embassy_executor::main]
18async fn main(_spawner: Spawner, p: Peripherals) { 18async fn main(_spawner: Spawner) {
19 let p = embassy_nrf::init(Default::default());
19 info!("Initializing TWI..."); 20 info!("Initializing TWI...");
20 let config = twim::Config::default(); 21 let config = twim::Config::default();
21 let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); 22 let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0);
diff --git a/examples/nrf/src/bin/twim_lowpower.rs b/examples/nrf/src/bin/twim_lowpower.rs
index ebf3d7109..e30cc9688 100644
--- a/examples/nrf/src/bin/twim_lowpower.rs
+++ b/examples/nrf/src/bin/twim_lowpower.rs
@@ -11,16 +11,17 @@
11use core::mem; 11use core::mem;
12 12
13use defmt::*; 13use defmt::*;
14use embassy_executor::executor::Spawner; 14use embassy_executor::Spawner;
15use embassy_executor::time::{Duration, Timer}; 15use embassy_nrf::interrupt;
16use embassy_nrf::twim::{self, Twim}; 16use embassy_nrf::twim::{self, Twim};
17use embassy_nrf::{interrupt, Peripherals}; 17use embassy_time::{Duration, Timer};
18use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
19 19
20const ADDRESS: u8 = 0x50; 20const ADDRESS: u8 = 0x50;
21 21
22#[embassy_executor::main] 22#[embassy_executor::main]
23async fn main(_spawner: Spawner, mut p: Peripherals) { 23async fn main(_p: Spawner) {
24 let mut p = embassy_nrf::init(Default::default());
24 info!("Started!"); 25 info!("Started!");
25 let mut irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); 26 let mut irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0);
26 27
diff --git a/examples/nrf/src/bin/uart.rs b/examples/nrf/src/bin/uart.rs
index 5f363b69e..600f7a6ef 100644
--- a/examples/nrf/src/bin/uart.rs
+++ b/examples/nrf/src/bin/uart.rs
@@ -3,12 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::{interrupt, uarte, Peripherals}; 7use embassy_nrf::{interrupt, uarte};
8use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
9 9
10#[embassy_executor::main] 10#[embassy_executor::main]
11async fn main(_spawner: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner) {
12 let p = embassy_nrf::init(Default::default());
12 let mut config = uarte::Config::default(); 13 let mut config = uarte::Config::default();
13 config.parity = uarte::Parity::EXCLUDED; 14 config.parity = uarte::Parity::EXCLUDED;
14 config.baudrate = uarte::Baudrate::BAUD115200; 15 config.baudrate = uarte::Baudrate::BAUD115200;
diff --git a/examples/nrf/src/bin/uart_idle.rs b/examples/nrf/src/bin/uart_idle.rs
index 0f455dffd..09ec624c0 100644
--- a/examples/nrf/src/bin/uart_idle.rs
+++ b/examples/nrf/src/bin/uart_idle.rs
@@ -3,12 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::{interrupt, uarte, Peripherals}; 7use embassy_nrf::{interrupt, uarte};
8use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
9 9
10#[embassy_executor::main] 10#[embassy_executor::main]
11async fn main(_spawner: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner) {
12 let p = embassy_nrf::init(Default::default());
12 let mut config = uarte::Config::default(); 13 let mut config = uarte::Config::default();
13 config.parity = uarte::Parity::EXCLUDED; 14 config.parity = uarte::Parity::EXCLUDED;
14 config.baudrate = uarte::Baudrate::BAUD115200; 15 config.baudrate = uarte::Baudrate::BAUD115200;
diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs
index 2de5f90c1..dab8e475d 100644
--- a/examples/nrf/src/bin/uart_split.rs
+++ b/examples/nrf/src/bin/uart_split.rs
@@ -3,10 +3,10 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::peripherals::UARTE0; 7use embassy_nrf::peripherals::UARTE0;
8use embassy_nrf::uarte::UarteRx; 8use embassy_nrf::uarte::UarteRx;
9use embassy_nrf::{interrupt, uarte, Peripherals}; 9use embassy_nrf::{interrupt, uarte};
10use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 10use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
11use embassy_util::channel::mpmc::Channel; 11use embassy_util::channel::mpmc::Channel;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
@@ -14,7 +14,8 @@ use {defmt_rtt as _, panic_probe as _};
14static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); 14static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new();
15 15
16#[embassy_executor::main] 16#[embassy_executor::main]
17async fn main(spawner: Spawner, p: Peripherals) { 17async fn main(spawner: Spawner) {
18 let p = embassy_nrf::init(Default::default());
18 let mut config = uarte::Config::default(); 19 let mut config = uarte::Config::default();
19 config.parity = uarte::Parity::EXCLUDED; 20 config.parity = uarte::Parity::EXCLUDED;
20 config.baudrate = uarte::Baudrate::BAUD115200; 21 config.baudrate = uarte::Baudrate::BAUD115200;
diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs
index 93cb05907..f0a870317 100644
--- a/examples/nrf/src/bin/usb_ethernet.rs
+++ b/examples/nrf/src/bin/usb_ethernet.rs
@@ -8,12 +8,12 @@ use core::sync::atomic::{AtomicBool, Ordering};
8use core::task::Waker; 8use core::task::Waker;
9 9
10use defmt::*; 10use defmt::*;
11use embassy_executor::executor::Spawner; 11use embassy_executor::Spawner;
12use embassy_net::tcp::TcpSocket; 12use embassy_net::tcp::TcpSocket;
13use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; 13use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources};
14use embassy_nrf::rng::Rng; 14use embassy_nrf::rng::Rng;
15use embassy_nrf::usb::{Driver, PowerUsb}; 15use embassy_nrf::usb::{Driver, PowerUsb};
16use embassy_nrf::{interrupt, pac, peripherals, Peripherals}; 16use embassy_nrf::{interrupt, pac, peripherals};
17use embassy_usb::{Builder, Config, UsbDevice}; 17use embassy_usb::{Builder, Config, UsbDevice};
18use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; 18use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
19use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 19use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
@@ -82,7 +82,8 @@ async fn net_task(stack: &'static Stack<Device>) -> ! {
82} 82}
83 83
84#[embassy_executor::main] 84#[embassy_executor::main]
85async fn main(spawner: Spawner, p: Peripherals) { 85async fn main(spawner: Spawner) {
86 let p = embassy_nrf::init(Default::default());
86 let clock: pac::CLOCK = unsafe { mem::transmute(()) }; 87 let clock: pac::CLOCK = unsafe { mem::transmute(()) };
87 88
88 info!("Enabling ext hfosc..."); 89 info!("Enabling ext hfosc...");
diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs
index 863f3e5dd..cf0078eec 100644
--- a/examples/nrf/src/bin/usb_hid_keyboard.rs
+++ b/examples/nrf/src/bin/usb_hid_keyboard.rs
@@ -7,10 +7,10 @@ use core::mem;
7use core::sync::atomic::{AtomicBool, Ordering}; 7use core::sync::atomic::{AtomicBool, Ordering};
8 8
9use defmt::*; 9use defmt::*;
10use embassy_executor::executor::Spawner; 10use embassy_executor::Spawner;
11use embassy_nrf::gpio::{Input, Pin, Pull}; 11use embassy_nrf::gpio::{Input, Pin, Pull};
12use embassy_nrf::usb::{Driver, PowerUsb}; 12use embassy_nrf::usb::{Driver, PowerUsb};
13use embassy_nrf::{interrupt, pac, Peripherals}; 13use embassy_nrf::{interrupt, pac};
14use embassy_usb::control::OutResponse; 14use embassy_usb::control::OutResponse;
15use embassy_usb::{Builder, Config, DeviceStateHandler}; 15use embassy_usb::{Builder, Config, DeviceStateHandler};
16use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; 16use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State};
@@ -23,7 +23,8 @@ use {defmt_rtt as _, panic_probe as _};
23static SUSPENDED: AtomicBool = AtomicBool::new(false); 23static SUSPENDED: AtomicBool = AtomicBool::new(false);
24 24
25#[embassy_executor::main] 25#[embassy_executor::main]
26async fn main(_spawner: Spawner, p: Peripherals) { 26async fn main(_spawner: Spawner) {
27 let p = embassy_nrf::init(Default::default());
27 let clock: pac::CLOCK = unsafe { mem::transmute(()) }; 28 let clock: pac::CLOCK = unsafe { mem::transmute(()) };
28 29
29 info!("Enabling ext hfosc..."); 30 info!("Enabling ext hfosc...");
diff --git a/examples/nrf/src/bin/usb_hid_mouse.rs b/examples/nrf/src/bin/usb_hid_mouse.rs
index 88bf87bd6..7cd2ece17 100644
--- a/examples/nrf/src/bin/usb_hid_mouse.rs
+++ b/examples/nrf/src/bin/usb_hid_mouse.rs
@@ -6,10 +6,10 @@
6use core::mem; 6use core::mem;
7 7
8use defmt::*; 8use defmt::*;
9use embassy_executor::executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_executor::time::{Duration, Timer};
11use embassy_nrf::usb::{Driver, PowerUsb}; 10use embassy_nrf::usb::{Driver, PowerUsb};
12use embassy_nrf::{interrupt, pac, Peripherals}; 11use embassy_nrf::{interrupt, pac};
12use embassy_time::{Duration, Timer};
13use embassy_usb::control::OutResponse; 13use embassy_usb::control::OutResponse;
14use embassy_usb::{Builder, Config}; 14use embassy_usb::{Builder, Config};
15use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; 15use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State};
@@ -18,7 +18,8 @@ use usbd_hid::descriptor::{MouseReport, SerializedDescriptor};
18use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
19 19
20#[embassy_executor::main] 20#[embassy_executor::main]
21async fn main(_spawner: Spawner, p: Peripherals) { 21async fn main(_spawner: Spawner) {
22 let p = embassy_nrf::init(Default::default());
22 let clock: pac::CLOCK = unsafe { mem::transmute(()) }; 23 let clock: pac::CLOCK = unsafe { mem::transmute(()) };
23 24
24 info!("Enabling ext hfosc..."); 25 info!("Enabling ext hfosc...");
diff --git a/examples/nrf/src/bin/usb_serial.rs b/examples/nrf/src/bin/usb_serial.rs
index 7d233d24d..a68edb329 100644
--- a/examples/nrf/src/bin/usb_serial.rs
+++ b/examples/nrf/src/bin/usb_serial.rs
@@ -6,9 +6,9 @@
6use core::mem; 6use core::mem;
7 7
8use defmt::{info, panic}; 8use defmt::{info, panic};
9use embassy_executor::executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_nrf::usb::{Driver, Instance, PowerUsb, UsbSupply}; 10use embassy_nrf::usb::{Driver, Instance, PowerUsb, UsbSupply};
11use embassy_nrf::{interrupt, pac, Peripherals}; 11use embassy_nrf::{interrupt, pac};
12use embassy_usb::driver::EndpointError; 12use embassy_usb::driver::EndpointError;
13use embassy_usb::{Builder, Config}; 13use embassy_usb::{Builder, Config};
14use embassy_usb_serial::{CdcAcmClass, State}; 14use embassy_usb_serial::{CdcAcmClass, State};
@@ -16,7 +16,8 @@ use futures::future::join;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18#[embassy_executor::main] 18#[embassy_executor::main]
19async fn main(_spawner: Spawner, p: Peripherals) { 19async fn main(_spawner: Spawner) {
20 let p = embassy_nrf::init(Default::default());
20 let clock: pac::CLOCK = unsafe { mem::transmute(()) }; 21 let clock: pac::CLOCK = unsafe { mem::transmute(()) };
21 22
22 info!("Enabling ext hfosc..."); 23 info!("Enabling ext hfosc...");
diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs
index 956315322..4c1a93087 100644
--- a/examples/nrf/src/bin/usb_serial_multitask.rs
+++ b/examples/nrf/src/bin/usb_serial_multitask.rs
@@ -6,9 +6,9 @@
6use core::mem; 6use core::mem;
7 7
8use defmt::{info, panic, unwrap}; 8use defmt::{info, panic, unwrap};
9use embassy_executor::executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_nrf::usb::{Driver, PowerUsb}; 10use embassy_nrf::usb::{Driver, PowerUsb};
11use embassy_nrf::{interrupt, pac, peripherals, Peripherals}; 11use embassy_nrf::{interrupt, pac, peripherals};
12use embassy_usb::driver::EndpointError; 12use embassy_usb::driver::EndpointError;
13use embassy_usb::{Builder, Config, UsbDevice}; 13use embassy_usb::{Builder, Config, UsbDevice};
14use embassy_usb_serial::{CdcAcmClass, State}; 14use embassy_usb_serial::{CdcAcmClass, State};
@@ -33,7 +33,8 @@ async fn echo_task(mut class: CdcAcmClass<'static, MyDriver>) {
33} 33}
34 34
35#[embassy_executor::main] 35#[embassy_executor::main]
36async fn main(spawner: Spawner, p: Peripherals) { 36async fn main(spawner: Spawner) {
37 let p = embassy_nrf::init(Default::default());
37 let clock: pac::CLOCK = unsafe { mem::transmute(()) }; 38 let clock: pac::CLOCK = unsafe { mem::transmute(()) };
38 39
39 info!("Enabling ext hfosc..."); 40 info!("Enabling ext hfosc...");
diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf/src/bin/wdt.rs
index 560cb3567..b0b9c3b81 100644
--- a/examples/nrf/src/bin/wdt.rs
+++ b/examples/nrf/src/bin/wdt.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::gpio::{Input, Pull}; 7use embassy_nrf::gpio::{Input, Pull};
8use embassy_nrf::wdt::{Config, Watchdog}; 8use embassy_nrf::wdt::{Config, Watchdog};
9use embassy_nrf::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_nrf::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut config = Config::default(); 16 let mut config = Config::default();
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml
index 94c3d8013..c2dcf429a 100644
--- a/examples/rp/Cargo.toml
+++ b/examples/rp/Cargo.toml
@@ -6,14 +6,14 @@ version = "0.1.0"
6 6
7[dependencies] 7[dependencies]
8embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 8embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime"] } 9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
10embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac"] } 11embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac"] }
11atomic-polyfill = "0.1.5"
12 12
13defmt = "0.3" 13defmt = "0.3"
14defmt-rtt = "0.3" 14defmt-rtt = "0.3"
15 15
16cortex-m = "0.7.3" 16cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
17cortex-m-rt = "0.7.0" 17cortex-m-rt = "0.7.0"
18panic-probe = { version = "0.3", features = ["print-defmt"] } 18panic-probe = { version = "0.3", features = ["print-defmt"] }
19futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } 19futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] }
diff --git a/examples/rp/src/bin/blinky.rs b/examples/rp/src/bin/blinky.rs
index e53fca1af..7aa36a19f 100644
--- a/examples/rp/src/bin/blinky.rs
+++ b/examples/rp/src/bin/blinky.rs
@@ -3,14 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_rp::gpio;
8use embassy_rp::{gpio, Peripherals}; 8use embassy_time::{Duration, Timer};
9use gpio::{Level, Output}; 9use gpio::{Level, Output};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12#[embassy_executor::main] 12#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_rp::init(Default::default());
14 let mut led = Output::new(p.PIN_25, Level::Low); 15 let mut led = Output::new(p.PIN_25, Level::Low);
15 16
16 loop { 17 loop {
diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs
index 02cbc9416..c5422c616 100644
--- a/examples/rp/src/bin/button.rs
+++ b/examples/rp/src/bin/button.rs
@@ -2,13 +2,13 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use embassy_executor::executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_rp::gpio::{Input, Level, Output, Pull}; 6use embassy_rp::gpio::{Input, Level, Output, Pull};
7use embassy_rp::Peripherals;
8use {defmt_rtt as _, panic_probe as _}; 7use {defmt_rtt as _, panic_probe as _};
9 8
10#[embassy_executor::main] 9#[embassy_executor::main]
11async fn main(_spawner: Spawner, p: Peripherals) { 10async fn main(_spawner: Spawner) {
11 let p = embassy_rp::init(Default::default());
12 let button = Input::new(p.PIN_28, Pull::Up); 12 let button = Input::new(p.PIN_28, Pull::Up);
13 let mut led = Output::new(p.PIN_25, Level::Low); 13 let mut led = Output::new(p.PIN_25, Level::Low);
14 14
diff --git a/examples/rp/src/bin/gpio_async.rs b/examples/rp/src/bin/gpio_async.rs
index ba905b015..52d13a9d5 100644
--- a/examples/rp/src/bin/gpio_async.rs
+++ b/examples/rp/src/bin/gpio_async.rs
@@ -3,9 +3,9 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_rp::gpio;
8use embassy_rp::{gpio, Peripherals}; 8use embassy_time::{Duration, Timer};
9use gpio::{Input, Level, Output, Pull}; 9use gpio::{Input, Level, Output, Pull};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
@@ -20,7 +20,8 @@ use {defmt_rtt as _, panic_probe as _};
20/// continue and turn off the LED, and then wait for 2 seconds before completing 20/// continue and turn off the LED, and then wait for 2 seconds before completing
21/// the loop and starting over again. 21/// the loop and starting over again.
22#[embassy_executor::main] 22#[embassy_executor::main]
23async fn main(_spawner: Spawner, p: Peripherals) { 23async fn main(_spawner: Spawner) {
24 let p = embassy_rp::init(Default::default());
24 let mut led = Output::new(p.PIN_25, Level::Low); 25 let mut led = Output::new(p.PIN_25, Level::Low);
25 let mut async_input = Input::new(p.PIN_16, Pull::None); 26 let mut async_input = Input::new(p.PIN_16, Pull::None);
26 27
diff --git a/examples/rp/src/bin/spi.rs b/examples/rp/src/bin/spi.rs
index a3160c106..88003ee17 100644
--- a/examples/rp/src/bin/spi.rs
+++ b/examples/rp/src/bin/spi.rs
@@ -3,14 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_rp::spi::Spi; 7use embassy_rp::spi::Spi;
8use embassy_rp::{gpio, spi, Peripherals}; 8use embassy_rp::{gpio, spi};
9use gpio::{Level, Output}; 9use gpio::{Level, Output};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12#[embassy_executor::main] 12#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_rp::init(Default::default());
14 info!("Hello World!"); 15 info!("Hello World!");
15 16
16 // Example for resistive touch sensor in Waveshare Pico-ResTouch 17 // Example for resistive touch sensor in Waveshare Pico-ResTouch
diff --git a/examples/rp/src/bin/spi_display.rs b/examples/rp/src/bin/spi_display.rs
index 2760b23fa..f0e54d87f 100644
--- a/examples/rp/src/bin/spi_display.rs
+++ b/examples/rp/src/bin/spi_display.rs
@@ -5,11 +5,11 @@
5use core::cell::RefCell; 5use core::cell::RefCell;
6 6
7use defmt::*; 7use defmt::*;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_executor::time::Delay;
10use embassy_rp::gpio::{Level, Output}; 9use embassy_rp::gpio::{Level, Output};
10use embassy_rp::spi;
11use embassy_rp::spi::Spi; 11use embassy_rp::spi::Spi;
12use embassy_rp::{spi, Peripherals}; 12use embassy_time::Delay;
13use embedded_graphics::image::{Image, ImageRawLE}; 13use embedded_graphics::image::{Image, ImageRawLE};
14use embedded_graphics::mono_font::ascii::FONT_10X20; 14use embedded_graphics::mono_font::ascii::FONT_10X20;
15use embedded_graphics::mono_font::MonoTextStyle; 15use embedded_graphics::mono_font::MonoTextStyle;
@@ -28,7 +28,8 @@ use crate::touch::Touch;
28const TOUCH_FREQ: u32 = 200_000; 28const TOUCH_FREQ: u32 = 200_000;
29 29
30#[embassy_executor::main] 30#[embassy_executor::main]
31async fn main(_spawner: Spawner, p: Peripherals) { 31async fn main(_spawner: Spawner) {
32 let p = embassy_rp::init(Default::default());
32 info!("Hello World!"); 33 info!("Hello World!");
33 34
34 let bl = p.PIN_13; 35 let bl = p.PIN_13;
diff --git a/examples/rp/src/bin/uart.rs b/examples/rp/src/bin/uart.rs
index 0d2954894..c63b31cae 100644
--- a/examples/rp/src/bin/uart.rs
+++ b/examples/rp/src/bin/uart.rs
@@ -2,18 +2,19 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use embassy_executor::executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_rp::{uart, Peripherals}; 6use embassy_rp::uart;
7use {defmt_rtt as _, panic_probe as _}; 7use {defmt_rtt as _, panic_probe as _};
8 8
9#[embassy_executor::main] 9#[embassy_executor::main]
10async fn main(_spawner: Spawner, p: Peripherals) { 10async fn main(_spawner: Spawner) {
11 let p = embassy_rp::init(Default::default());
11 let config = uart::Config::default(); 12 let config = uart::Config::default();
12 let mut uart = uart::Uart::new(p.UART0, p.PIN_0, p.PIN_1, p.PIN_2, p.PIN_3, config); 13 let mut uart = uart::Uart::new_with_rtscts(p.UART0, p.PIN_0, p.PIN_1, p.PIN_2, p.PIN_3, config);
13 uart.send("Hello World!\r\n".as_bytes()); 14 uart.blocking_write("Hello World!\r\n".as_bytes()).unwrap();
14 15
15 loop { 16 loop {
16 uart.send("hello there!\r\n".as_bytes()); 17 uart.blocking_write("hello there!\r\n".as_bytes()).unwrap();
17 cortex_m::asm::delay(1_000_000); 18 cortex_m::asm::delay(1_000_000);
18 } 19 }
19} 20}
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml
index 54499796b..b7009017c 100644
--- a/examples/std/Cargo.toml
+++ b/examples/std/Cargo.toml
@@ -5,9 +5,11 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "time", "nightly"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "nightly", "integrated-timers"] }
9embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "log", "medium-ethernet", "tcp", "dhcpv4", "pool-16"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "std", "nightly"] }
10embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "log", "medium-ethernet", "tcp", "udp", "dhcpv4", "pool-16"] }
10embedded-io = { version = "0.3.0", features = ["async", "std", "futures"] } 11embedded-io = { version = "0.3.0", features = ["async", "std", "futures"] }
12critical-section = { version = "1.1", features = ["std"] }
11 13
12async-io = "1.6.0" 14async-io = "1.6.0"
13env_logger = "0.9.0" 15env_logger = "0.9.0"
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs
index 202585289..528609260 100644
--- a/examples/std/src/bin/net.rs
+++ b/examples/std/src/bin/net.rs
@@ -1,7 +1,7 @@
1#![feature(type_alias_impl_trait)] 1#![feature(type_alias_impl_trait)]
2 2
3use clap::Parser; 3use clap::Parser;
4use embassy_executor::executor::{Executor, Spawner}; 4use embassy_executor::{Executor, Spawner};
5use embassy_net::tcp::TcpSocket; 5use embassy_net::tcp::TcpSocket;
6use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources}; 6use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources};
7use embassy_util::Forever; 7use embassy_util::Forever;
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs
new file mode 100644
index 000000000..07e11c385
--- /dev/null
+++ b/examples/std/src/bin/net_udp.rs
@@ -0,0 +1,109 @@
1#![feature(type_alias_impl_trait)]
2
3use clap::Parser;
4use embassy_executor::{Executor, Spawner};
5use embassy_net::udp::UdpSocket;
6use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources};
7use embassy_util::Forever;
8use heapless::Vec;
9use log::*;
10use rand_core::{OsRng, RngCore};
11
12#[path = "../tuntap.rs"]
13mod tuntap;
14
15use crate::tuntap::TunTapDevice;
16
17macro_rules! forever {
18 ($val:expr) => {{
19 type T = impl Sized;
20 static FOREVER: Forever<T> = Forever::new();
21 FOREVER.put_with(move || $val)
22 }};
23}
24
25#[derive(Parser)]
26#[clap(version = "1.0")]
27struct Opts {
28 /// TAP device name
29 #[clap(long, default_value = "tap0")]
30 tap: String,
31 /// use a static IP instead of DHCP
32 #[clap(long)]
33 static_ip: bool,
34}
35
36#[embassy_executor::task]
37async fn net_task(stack: &'static Stack<TunTapDevice>) -> ! {
38 stack.run().await
39}
40
41#[embassy_executor::task]
42async fn main_task(spawner: Spawner) {
43 let opts: Opts = Opts::parse();
44
45 // Init network device
46 let device = TunTapDevice::new(&opts.tap).unwrap();
47
48 // Choose between dhcp or static ip
49 let config = if opts.static_ip {
50 ConfigStrategy::Static(embassy_net::Config {
51 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
52 dns_servers: Vec::new(),
53 gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
54 })
55 } else {
56 ConfigStrategy::Dhcp
57 };
58
59 // Generate random seed
60 let mut seed = [0; 8];
61 OsRng.fill_bytes(&mut seed);
62 let seed = u64::from_le_bytes(seed);
63
64 // Init network stack
65 let stack = &*forever!(Stack::new(
66 device,
67 config,
68 forever!(StackResources::<1, 2, 8>::new()),
69 seed
70 ));
71
72 // Launch network task
73 spawner.spawn(net_task(stack)).unwrap();
74
75 // Then we can use it!
76 let mut rx_meta = [PacketMetadata::EMPTY; 16];
77 let mut rx_buffer = [0; 4096];
78 let mut tx_meta = [PacketMetadata::EMPTY; 16];
79 let mut tx_buffer = [0; 4096];
80 let mut buf = [0; 4096];
81
82 let mut socket = UdpSocket::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer);
83 socket.bind(9400).unwrap();
84
85 loop {
86 let (n, ep) = socket.recv_from(&mut buf).await.unwrap();
87 if let Ok(s) = core::str::from_utf8(&buf[..n]) {
88 info!("ECHO (to {}): {}", ep, s);
89 } else {
90 info!("ECHO (to {}): bytearray len {}", ep, n);
91 }
92 socket.send_to(&buf[..n], ep).await.unwrap();
93 }
94}
95
96static EXECUTOR: Forever<Executor> = Forever::new();
97
98fn main() {
99 env_logger::builder()
100 .filter_level(log::LevelFilter::Debug)
101 .filter_module("async_io", log::LevelFilter::Info)
102 .format_timestamp_nanos()
103 .init();
104
105 let executor = EXECUTOR.put(Executor::new());
106 executor.run(|spawner| {
107 spawner.spawn(main_task(spawner)).unwrap();
108 });
109}
diff --git a/examples/std/src/bin/serial.rs b/examples/std/src/bin/serial.rs
index b803d1ef7..35cba4cee 100644
--- a/examples/std/src/bin/serial.rs
+++ b/examples/std/src/bin/serial.rs
@@ -4,7 +4,7 @@
4mod serial_port; 4mod serial_port;
5 5
6use async_io::Async; 6use async_io::Async;
7use embassy_executor::executor::Executor; 7use embassy_executor::Executor;
8use embassy_util::Forever; 8use embassy_util::Forever;
9use embedded_io::asynch::Read; 9use embedded_io::asynch::Read;
10use log::*; 10use log::*;
diff --git a/examples/std/src/bin/tick.rs b/examples/std/src/bin/tick.rs
index 9ca900df8..b9de9d873 100644
--- a/examples/std/src/bin/tick.rs
+++ b/examples/std/src/bin/tick.rs
@@ -1,7 +1,7 @@
1#![feature(type_alias_impl_trait)] 1#![feature(type_alias_impl_trait)]
2 2
3use embassy_executor::executor::Spawner; 3use embassy_executor::Spawner;
4use embassy_executor::time::{Duration, Timer}; 4use embassy_time::{Duration, Timer};
5use log::*; 5use log::*;
6 6
7#[embassy_executor::task] 7#[embassy_executor::task]
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml
index 3ba297636..8476200d4 100644
--- a/examples/stm32f0/Cargo.toml
+++ b/examples/stm32f0/Cargo.toml
@@ -6,12 +6,13 @@ edition = "2021"
6# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 6# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 7
8[dependencies] 8[dependencies]
9cortex-m = "0.7.3" 9cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
10cortex-m-rt = "0.7.0" 10cortex-m-rt = "0.7.0"
11defmt = "0.3" 11defmt = "0.3"
12defmt-rtt = "0.3" 12defmt-rtt = "0.3"
13panic-probe = "0.3" 13panic-probe = "0.3"
14embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 14embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
15embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 15embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
16embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
16embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f030f4", "time-driver-any"] } 17embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f030f4", "time-driver-any"] }
17 18
diff --git a/examples/stm32f0/src/bin/hello.rs b/examples/stm32f0/src/bin/hello.rs
index c9081ea12..db78233ea 100644
--- a/examples/stm32f0/src/bin/hello.rs
+++ b/examples/stm32f0/src/bin/hello.rs
@@ -3,13 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
8use embassy_stm32::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::main] 10#[embassy_executor::main]
12async fn main(_spawner: Spawner, _p: Peripherals) -> ! { 11async fn main(_spawner: Spawner) -> ! {
12 let _p = embassy_stm32::init(Default::default());
13 loop { 13 loop {
14 Timer::after(Duration::from_secs(1)).await; 14 Timer::after(Duration::from_secs(1)).await;
15 info!("Hello"); 15 info!("Hello");
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml
index 9ce553b6d..fbc96400c 100644
--- a/examples/stm32f1/Cargo.toml
+++ b/examples/stm32f1/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] }
10embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 11embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
11embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } 12embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] }
@@ -13,7 +14,7 @@ embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", fea
13defmt = "0.3" 14defmt = "0.3"
14defmt-rtt = "0.3" 15defmt-rtt = "0.3"
15 16
16cortex-m = "0.7.3" 17cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
17cortex-m-rt = "0.7.0" 18cortex-m-rt = "0.7.0"
18embedded-hal = "0.2.6" 19embedded-hal = "0.2.6"
19panic-probe = { version = "0.3", features = ["print-defmt"] } 20panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs
index e54593fe5..2d6b4a0e9 100644
--- a/examples/stm32f1/src/bin/adc.rs
+++ b/examples/stm32f1/src/bin/adc.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Delay, Duration, Timer};
8use embassy_stm32::adc::Adc; 7use embassy_stm32::adc::Adc;
9use embassy_stm32::Peripherals; 8use embassy_time::{Delay, Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut adc = Adc::new(p.ADC1, &mut Delay); 16 let mut adc = Adc::new(p.ADC1, &mut Delay);
diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs
index 5171043e8..b9b0ac238 100644
--- a/examples/stm32f1/src/bin/blinky.rs
+++ b/examples/stm32f1/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PC13, Level::High, Speed::Low); 16 let mut led = Output::new(p.PC13, Level::High, Speed::Low);
diff --git a/examples/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs
index 549d1bfba..180b6aabd 100644
--- a/examples/stm32f1/src/bin/hello.rs
+++ b/examples/stm32f1/src/bin/hello.rs
@@ -3,20 +3,18 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::time::Hertz; 7use embassy_stm32::time::Hertz;
9use embassy_stm32::{Config, Peripherals}; 8use embassy_stm32::Config;
9use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) -> ! {
13 let mut config = Config::default(); 14 let mut config = Config::default();
14 config.rcc.sys_ck = Some(Hertz(36_000_000)); 15 config.rcc.sys_ck = Some(Hertz(36_000_000));
15 config 16 let _p = embassy_stm32::init(config);
16}
17 17
18#[embassy_executor::main(config = "config()")]
19async fn main(_spawner: Spawner, _p: Peripherals) -> ! {
20 loop { 18 loop {
21 info!("Hello World!"); 19 info!("Hello World!");
22 Timer::after(Duration::from_secs(1)).await; 20 Timer::after(Duration::from_secs(1)).await;
diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs
index cf7facb79..a9c46068f 100644
--- a/examples/stm32f1/src/bin/usb_serial.rs
+++ b/examples/stm32f1/src/bin/usb_serial.rs
@@ -3,28 +3,26 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{panic, *}; 5use defmt::{panic, *};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
10use embassy_stm32::usb::{Driver, Instance}; 9use embassy_stm32::usb::{Driver, Instance};
11use embassy_stm32::{interrupt, Config, Peripherals}; 10use embassy_stm32::{interrupt, Config};
11use embassy_time::{Duration, Timer};
12use embassy_usb::driver::EndpointError; 12use embassy_usb::driver::EndpointError;
13use embassy_usb::Builder; 13use embassy_usb::Builder;
14use embassy_usb_serial::{CdcAcmClass, State}; 14use embassy_usb_serial::{CdcAcmClass, State};
15use futures::future::join; 15use futures::future::join;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18fn config() -> Config { 18#[embassy_executor::main]
19async fn main(_spawner: Spawner) {
19 let mut config = Config::default(); 20 let mut config = Config::default();
20 config.rcc.hse = Some(Hertz(8_000_000)); 21 config.rcc.hse = Some(Hertz(8_000_000));
21 config.rcc.sys_ck = Some(Hertz(48_000_000)); 22 config.rcc.sys_ck = Some(Hertz(48_000_000));
22 config.rcc.pclk1 = Some(Hertz(24_000_000)); 23 config.rcc.pclk1 = Some(Hertz(24_000_000));
23 config 24 let mut p = embassy_stm32::init(config);
24}
25 25
26#[embassy_executor::main(config = "config()")]
27async fn main(_spawner: Spawner, mut p: Peripherals) {
28 info!("Hello World!"); 26 info!("Hello World!");
29 27
30 { 28 {
diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml
index a3fb736da..27894df50 100644
--- a/examples/stm32f2/Cargo.toml
+++ b/examples/stm32f2/Cargo.toml
@@ -5,13 +5,14 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
10 11
11defmt = "0.3" 12defmt = "0.3"
12defmt-rtt = "0.3" 13defmt-rtt = "0.3"
13 14
14cortex-m = "0.7.3" 15cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
15cortex-m-rt = "0.7.0" 16cortex-m-rt = "0.7.0"
16embedded-hal = "0.2.6" 17embedded-hal = "0.2.6"
17panic-probe = { version = "0.3", features = ["print-defmt"] } 18panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/stm32f2/src/bin/blinky.rs b/examples/stm32f2/src/bin/blinky.rs
index 48ae2e711..d8c89a519 100644
--- a/examples/stm32f2/src/bin/blinky.rs
+++ b/examples/stm32f2/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
diff --git a/examples/stm32f2/src/bin/pll.rs b/examples/stm32f2/src/bin/pll.rs
index 01e63b15e..17f09538c 100644
--- a/examples/stm32f2/src/bin/pll.rs
+++ b/examples/stm32f2/src/bin/pll.rs
@@ -5,17 +5,19 @@
5use core::convert::TryFrom; 5use core::convert::TryFrom;
6 6
7use defmt::*; 7use defmt::*;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_executor::time::{Duration, Timer};
10use embassy_stm32::rcc::{ 9use embassy_stm32::rcc::{
11 APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLL48Div, PLLConfig, PLLMainDiv, PLLMul, PLLPreDiv, PLLSrc, 10 APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLL48Div, PLLConfig, PLLMainDiv, PLLMul, PLLPreDiv, PLLSrc,
12}; 11};
13use embassy_stm32::time::Hertz; 12use embassy_stm32::time::Hertz;
14use embassy_stm32::{Config, Peripherals}; 13use embassy_stm32::Config;
14use embassy_time::{Duration, Timer};
15use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, panic_probe as _};
16 16
17// Example config for maximum performance on a NUCLEO-F207ZG board 17#[embassy_executor::main]
18fn config() -> Config { 18async fn main(_spawner: Spawner) {
19 // Example config for maximum performance on a NUCLEO-F207ZG board
20
19 let mut config = Config::default(); 21 let mut config = Config::default();
20 // By default, HSE on the board comes from a 8 MHz clock signal (not a crystal) 22 // By default, HSE on the board comes from a 8 MHz clock signal (not a crystal)
21 config.rcc.hse = Some(HSEConfig { 23 config.rcc.hse = Some(HSEConfig {
@@ -40,11 +42,9 @@ fn config() -> Config {
40 config.rcc.apb1_pre = APBPrescaler::Div4; 42 config.rcc.apb1_pre = APBPrescaler::Div4;
41 // 120 MHz / 2 = 60 MHz APB2 frequency 43 // 120 MHz / 2 = 60 MHz APB2 frequency
42 config.rcc.apb2_pre = APBPrescaler::Div2; 44 config.rcc.apb2_pre = APBPrescaler::Div2;
43 config
44}
45 45
46#[embassy_executor::main(config = "config()")] 46 let _p = embassy_stm32::init(config);
47async fn main(_spawner: Spawner, _p: Peripherals) { 47
48 loop { 48 loop {
49 Timer::after(Duration::from_millis(1000)).await; 49 Timer::after(Duration::from_millis(1000)).await;
50 info!("1s elapsed"); 50 info!("1s elapsed");
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml
index 410e9b3e0..b5ea28bb6 100644
--- a/examples/stm32f3/Cargo.toml
+++ b/examples/stm32f3/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
10embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 11embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
11embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } 12embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] }
@@ -14,7 +15,7 @@ embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", features
14defmt = "0.3" 15defmt = "0.3"
15defmt-rtt = "0.3" 16defmt-rtt = "0.3"
16 17
17cortex-m = "0.7.3" 18cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
18cortex-m-rt = "0.7.0" 19cortex-m-rt = "0.7.0"
19embedded-hal = "0.2.6" 20embedded-hal = "0.2.6"
20panic-probe = { version = "0.3", features = ["print-defmt"] } 21panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs
index 7146eaa54..185785ceb 100644
--- a/examples/stm32f3/src/bin/blinky.rs
+++ b/examples/stm32f3/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PA5, Level::High, Speed::Low); 16 let mut led = Output::new(p.PA5, Level::High, Speed::Low);
diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs
index ef5110316..61fc6dcab 100644
--- a/examples/stm32f3/src/bin/button_events.rs
+++ b/examples/stm32f3/src/bin/button_events.rs
@@ -11,12 +11,11 @@
11#![feature(type_alias_impl_trait)] 11#![feature(type_alias_impl_trait)]
12 12
13use defmt::*; 13use defmt::*;
14use embassy_executor::executor::Spawner; 14use embassy_executor::Spawner;
15use embassy_executor::time::{with_timeout, Duration, Timer};
16use embassy_stm32::exti::ExtiInput; 15use embassy_stm32::exti::ExtiInput;
17use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; 16use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed};
18use embassy_stm32::peripherals::PA0; 17use embassy_stm32::peripherals::PA0;
19use embassy_stm32::Peripherals; 18use embassy_time::{with_timeout, Duration, Timer};
20use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 19use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
21use embassy_util::channel::mpmc::Channel; 20use embassy_util::channel::mpmc::Channel;
22use {defmt_rtt as _, panic_probe as _}; 21use {defmt_rtt as _, panic_probe as _};
@@ -100,7 +99,8 @@ enum ButtonEvent {
100static CHANNEL: Channel<ThreadModeRawMutex, ButtonEvent, 4> = Channel::new(); 99static CHANNEL: Channel<ThreadModeRawMutex, ButtonEvent, 4> = Channel::new();
101 100
102#[embassy_executor::main] 101#[embassy_executor::main]
103async fn main(spawner: Spawner, p: Peripherals) { 102async fn main(spawner: Spawner) {
103 let p = embassy_stm32::init(Default::default());
104 let button = Input::new(p.PA0, Pull::Down); 104 let button = Input::new(p.PA0, Pull::Down);
105 let button = ExtiInput::new(button, p.EXTI0); 105 let button = ExtiInput::new(button, p.EXTI0);
106 info!("Press the USER button..."); 106 info!("Press the USER button...");
diff --git a/examples/stm32f3/src/bin/button_exti.rs b/examples/stm32f3/src/bin/button_exti.rs
index dee06e5de..1266778c1 100644
--- a/examples/stm32f3/src/bin/button_exti.rs
+++ b/examples/stm32f3/src/bin/button_exti.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let button = Input::new(p.PA0, Pull::Down); 16 let button = Input::new(p.PA0, Pull::Down);
diff --git a/examples/stm32f3/src/bin/flash.rs b/examples/stm32f3/src/bin/flash.rs
index be2f6f671..2cf24dbd3 100644
--- a/examples/stm32f3/src/bin/flash.rs
+++ b/examples/stm32f3/src/bin/flash.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
8use embassy_stm32::Peripherals;
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 8use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello Flash!"); 14 info!("Hello Flash!");
15 15
16 const ADDR: u32 = 0x26000; 16 const ADDR: u32 = 0x26000;
diff --git a/examples/stm32f3/src/bin/hello.rs b/examples/stm32f3/src/bin/hello.rs
index bd9953a0e..65773210d 100644
--- a/examples/stm32f3/src/bin/hello.rs
+++ b/examples/stm32f3/src/bin/hello.rs
@@ -3,21 +3,19 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::time::Hertz; 7use embassy_stm32::time::Hertz;
9use embassy_stm32::{Config, Peripherals}; 8use embassy_stm32::Config;
9use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) -> ! {
13 let mut config = Config::default(); 14 let mut config = Config::default();
14 config.rcc.hse = Some(Hertz(8_000_000)); 15 config.rcc.hse = Some(Hertz(8_000_000));
15 config.rcc.sysclk = Some(Hertz(16_000_000)); 16 config.rcc.sysclk = Some(Hertz(16_000_000));
16 config 17 let _p = embassy_stm32::init(config);
17}
18 18
19#[embassy_executor::main(config = "config()")]
20async fn main(_spawner: Spawner, _p: Peripherals) -> ! {
21 loop { 19 loop {
22 info!("Hello World!"); 20 info!("Hello World!");
23 Timer::after(Duration::from_secs(1)).await; 21 Timer::after(Duration::from_secs(1)).await;
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs
index fba5b286e..e96c31249 100644
--- a/examples/stm32f3/src/bin/multiprio.rs
+++ b/examples/stm32f3/src/bin/multiprio.rs
@@ -59,10 +59,10 @@
59 59
60use cortex_m_rt::entry; 60use cortex_m_rt::entry;
61use defmt::*; 61use defmt::*;
62use embassy_executor::time::{Duration, Instant, Timer};
63use embassy_stm32::executor::{Executor, InterruptExecutor}; 62use embassy_stm32::executor::{Executor, InterruptExecutor};
64use embassy_stm32::interrupt; 63use embassy_stm32::interrupt;
65use embassy_stm32::interrupt::InterruptExt; 64use embassy_stm32::interrupt::InterruptExt;
65use embassy_time::{Duration, Instant, Timer};
66use embassy_util::Forever; 66use embassy_util::Forever;
67use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
68 68
diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs
index f554c509a..95b2b6865 100644
--- a/examples/stm32f3/src/bin/spi_dma.rs
+++ b/examples/stm32f3/src/bin/spi_dma.rs
@@ -6,15 +6,15 @@ use core::fmt::Write;
6use core::str::from_utf8; 6use core::str::from_utf8;
7 7
8use defmt::*; 8use defmt::*;
9use embassy_executor::executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::spi::{Config, Spi}; 10use embassy_stm32::spi::{Config, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embassy_stm32::Peripherals;
13use heapless::String; 12use heapless::String;
14use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
15 14
16#[embassy_executor::main] 15#[embassy_executor::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 16async fn main(_spawner: Spawner) {
17 let p = embassy_stm32::init(Default::default());
18 info!("Hello World!"); 18 info!("Hello World!");
19 19
20 let mut spi = Spi::new( 20 let mut spi = Spi::new(
diff --git a/examples/stm32f3/src/bin/usart_dma.rs b/examples/stm32f3/src/bin/usart_dma.rs
index 62d165029..3bc5a287f 100644
--- a/examples/stm32f3/src/bin/usart_dma.rs
+++ b/examples/stm32f3/src/bin/usart_dma.rs
@@ -5,15 +5,15 @@
5use core::fmt::Write; 5use core::fmt::Write;
6 6
7use defmt::*; 7use defmt::*;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use embassy_stm32::Peripherals;
12use heapless::String; 11use heapless::String;
13use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
14 13
15#[embassy_executor::main] 14#[embassy_executor::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner) {
16 let p = embassy_stm32::init(Default::default());
17 info!("Hello World!"); 17 info!("Hello World!");
18 18
19 let config = Config::default(); 19 let config = Config::default();
diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs
index 87b1138f5..d3702fc35 100644
--- a/examples/stm32f3/src/bin/usb_serial.rs
+++ b/examples/stm32f3/src/bin/usb_serial.rs
@@ -3,32 +3,28 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{panic, *}; 5use defmt::{panic, *};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::time::mhz; 8use embassy_stm32::time::mhz;
10use embassy_stm32::usb::{Driver, Instance}; 9use embassy_stm32::usb::{Driver, Instance};
11use embassy_stm32::{interrupt, Config, Peripherals}; 10use embassy_stm32::{interrupt, Config};
11use embassy_time::{Duration, Timer};
12use embassy_usb::driver::EndpointError; 12use embassy_usb::driver::EndpointError;
13use embassy_usb::Builder; 13use embassy_usb::Builder;
14use embassy_usb_serial::{CdcAcmClass, State}; 14use embassy_usb_serial::{CdcAcmClass, State};
15use futures::future::join; 15use futures::future::join;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18fn config() -> Config { 18#[embassy_executor::main]
19async fn main(_spawner: Spawner) {
19 let mut config = Config::default(); 20 let mut config = Config::default();
20
21 config.rcc.hse = Some(mhz(8)); 21 config.rcc.hse = Some(mhz(8));
22 config.rcc.sysclk = Some(mhz(48)); 22 config.rcc.sysclk = Some(mhz(48));
23 config.rcc.pclk1 = Some(mhz(24)); 23 config.rcc.pclk1 = Some(mhz(24));
24 config.rcc.pclk2 = Some(mhz(24)); 24 config.rcc.pclk2 = Some(mhz(24));
25 config.rcc.pll48 = true; 25 config.rcc.pll48 = true;
26 let p = embassy_stm32::init(config);
26 27
27 config
28}
29
30#[embassy_executor::main(config = "config()")]
31async fn main(_spawner: Spawner, p: Peripherals) {
32 info!("Hello World!"); 28 info!("Hello World!");
33 29
34 // Needed for nucleo-stm32f303ze 30 // Needed for nucleo-stm32f303ze
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml
index 3c58320dd..04a217aff 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -6,13 +6,14 @@ version = "0.1.0"
6 6
7[dependencies] 7[dependencies]
8embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 8embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "time-tick-32768hz"] } 9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
11 12
12defmt = "0.3" 13defmt = "0.3"
13defmt-rtt = "0.3" 14defmt-rtt = "0.3"
14 15
15cortex-m = "0.7.3" 16cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
16cortex-m-rt = "0.7.0" 17cortex-m-rt = "0.7.0"
17embedded-hal = "0.2.6" 18embedded-hal = "0.2.6"
18embedded-io = "0.3.0" 19embedded-io = "0.3.0"
diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs
index 27ed4fcc5..871185074 100644
--- a/examples/stm32f4/src/bin/adc.rs
+++ b/examples/stm32f4/src/bin/adc.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Delay, Duration, Timer};
8use embassy_stm32::adc::Adc; 7use embassy_stm32::adc::Adc;
9use embassy_stm32::Peripherals; 8use embassy_time::{Delay, Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut adc = Adc::new(p.ADC1, &mut Delay); 16 let mut adc = Adc::new(p.ADC1, &mut Delay);
diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs
index f71fe0989..b27bee4ce 100644
--- a/examples/stm32f4/src/bin/blinky.rs
+++ b/examples/stm32f4/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PB7, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB7, Level::High, Speed::Low);
diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs
index 60dfb362b..dfe587d41 100644
--- a/examples/stm32f4/src/bin/button_exti.rs
+++ b/examples/stm32f4/src/bin/button_exti.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let button = Input::new(p.PC13, Pull::Down); 16 let button = Input::new(p.PC13, Pull::Down);
diff --git a/examples/stm32f4/src/bin/dac.rs b/examples/stm32f4/src/bin/dac.rs
index 392f5bf4d..d97ae7082 100644
--- a/examples/stm32f4/src/bin/dac.rs
+++ b/examples/stm32f4/src/bin/dac.rs
@@ -3,13 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::dac::{Channel, Dac, Value}; 7use embassy_stm32::dac::{Channel, Dac, Value};
8use embassy_stm32::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::main] 10#[embassy_executor::main]
12async fn main(_spawner: Spawner, p: Peripherals) -> ! { 11async fn main(_spawner: Spawner) -> ! {
12 let p = embassy_stm32::init(Default::default());
13 info!("Hello World, dude!"); 13 info!("Hello World, dude!");
14 14
15 let mut dac = Dac::new_1ch(p.DAC, p.PA4); 15 let mut dac = Dac::new_1ch(p.DAC, p.PA4);
diff --git a/examples/stm32f4/src/bin/flash.rs b/examples/stm32f4/src/bin/flash.rs
index 4f780656e..393d61e86 100644
--- a/examples/stm32f4/src/bin/flash.rs
+++ b/examples/stm32f4/src/bin/flash.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
8use embassy_stm32::Peripherals;
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 8use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello Flash!"); 14 info!("Hello Flash!");
15 15
16 let mut f = Flash::unlock(p.FLASH); 16 let mut f = Flash::unlock(p.FLASH);
diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs
index f957656ef..c409703f5 100644
--- a/examples/stm32f4/src/bin/hello.rs
+++ b/examples/stm32f4/src/bin/hello.rs
@@ -3,20 +3,18 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::time::Hertz; 7use embassy_stm32::time::Hertz;
9use embassy_stm32::{Config, Peripherals}; 8use embassy_stm32::Config;
9use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) -> ! {
13 let mut config = Config::default(); 14 let mut config = Config::default();
14 config.rcc.sys_ck = Some(Hertz(84_000_000)); 15 config.rcc.sys_ck = Some(Hertz(84_000_000));
15 config 16 let _p = embassy_stm32::init(config);
16}
17 17
18#[embassy_executor::main(config = "config()")]
19async fn main(_spawner: Spawner, _p: Peripherals) -> ! {
20 loop { 18 loop {
21 info!("Hello World!"); 19 info!("Hello World!");
22 Timer::after(Duration::from_secs(1)).await; 20 Timer::after(Duration::from_secs(1)).await;
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs
index fba5b286e..e96c31249 100644
--- a/examples/stm32f4/src/bin/multiprio.rs
+++ b/examples/stm32f4/src/bin/multiprio.rs
@@ -59,10 +59,10 @@
59 59
60use cortex_m_rt::entry; 60use cortex_m_rt::entry;
61use defmt::*; 61use defmt::*;
62use embassy_executor::time::{Duration, Instant, Timer};
63use embassy_stm32::executor::{Executor, InterruptExecutor}; 62use embassy_stm32::executor::{Executor, InterruptExecutor};
64use embassy_stm32::interrupt; 63use embassy_stm32::interrupt;
65use embassy_stm32::interrupt::InterruptExt; 64use embassy_stm32::interrupt::InterruptExt;
65use embassy_time::{Duration, Instant, Timer};
66use embassy_util::Forever; 66use embassy_util::Forever;
67use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
68 68
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs
index 0b352c2b7..7c5902052 100644
--- a/examples/stm32f4/src/bin/pwm.rs
+++ b/examples/stm32f4/src/bin/pwm.rs
@@ -3,16 +3,16 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; 7use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm};
9use embassy_stm32::pwm::Channel; 8use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::khz; 9use embassy_stm32::time::khz;
11use embassy_stm32::Peripherals; 10use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
13 12
14#[embassy_executor::main] 13#[embassy_executor::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default());
16 info!("Hello World!"); 16 info!("Hello World!");
17 17
18 let ch1 = PwmPin::new_ch1(p.PE9); 18 let ch1 = PwmPin::new_ch1(p.PE9);
diff --git a/examples/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs
index 6eef19963..0edd8a61a 100644
--- a/examples/stm32f4/src/bin/sdmmc.rs
+++ b/examples/stm32f4/src/bin/sdmmc.rs
@@ -3,20 +3,17 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::sdmmc::Sdmmc; 7use embassy_stm32::sdmmc::Sdmmc;
8use embassy_stm32::time::mhz; 8use embassy_stm32::time::mhz;
9use embassy_stm32::{interrupt, Config, Peripherals}; 9use embassy_stm32::{interrupt, Config};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) -> ! {
13 let mut config = Config::default(); 14 let mut config = Config::default();
14 config.rcc.sys_ck = Some(mhz(48)); 15 config.rcc.sys_ck = Some(mhz(48));
15 config 16 let p = embassy_stm32::init(config);
16}
17
18#[embassy_executor::main(config = "config()")]
19async fn main(_spawner: Spawner, p: Peripherals) -> ! {
20 info!("Hello World!"); 17 info!("Hello World!");
21 18
22 let irq = interrupt::take!(SDIO); 19 let irq = interrupt::take!(SDIO);
diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs
index 023ca0971..3d2a1a1ae 100644
--- a/examples/stm32f4/src/bin/spi_dma.rs
+++ b/examples/stm32f4/src/bin/spi_dma.rs
@@ -6,15 +6,15 @@ use core::fmt::Write;
6use core::str::from_utf8; 6use core::str::from_utf8;
7 7
8use defmt::*; 8use defmt::*;
9use embassy_executor::executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::spi::{Config, Spi}; 10use embassy_stm32::spi::{Config, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embassy_stm32::Peripherals;
13use heapless::String; 12use heapless::String;
14use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
15 14
16#[embassy_executor::main] 15#[embassy_executor::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 16async fn main(_spawner: Spawner) {
17 let p = embassy_stm32::init(Default::default());
18 info!("Hello World!"); 18 info!("Hello World!");
19 19
20 let mut spi = Spi::new( 20 let mut spi = Spi::new(
diff --git a/examples/stm32f4/src/bin/usart_buffered.rs b/examples/stm32f4/src/bin/usart_buffered.rs
index 2555998ce..7bcecbd26 100644
--- a/examples/stm32f4/src/bin/usart_buffered.rs
+++ b/examples/stm32f4/src/bin/usart_buffered.rs
@@ -3,15 +3,16 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
8use embassy_stm32::interrupt;
8use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; 9use embassy_stm32::usart::{BufferedUart, Config, State, Uart};
9use embassy_stm32::{interrupt, Peripherals};
10use embedded_io::asynch::BufRead; 10use embedded_io::asynch::BufRead;
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13#[embassy_executor::main] 13#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default());
15 info!("Hello World!"); 16 info!("Hello World!");
16 17
17 let config = Config::default(); 18 let config = Config::default();
diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs
index 7859ba2ae..bb41b8b4f 100644
--- a/examples/stm32f4/src/bin/usart_dma.rs
+++ b/examples/stm32f4/src/bin/usart_dma.rs
@@ -5,15 +5,15 @@
5use core::fmt::Write; 5use core::fmt::Write;
6 6
7use defmt::*; 7use defmt::*;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use embassy_stm32::Peripherals;
12use heapless::String; 11use heapless::String;
13use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
14 13
15#[embassy_executor::main] 14#[embassy_executor::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner) {
16 let p = embassy_stm32::init(Default::default());
17 info!("Hello World!"); 17 info!("Hello World!");
18 18
19 let config = Config::default(); 19 let config = Config::default();
diff --git a/examples/stm32f4/src/bin/wdt.rs b/examples/stm32f4/src/bin/wdt.rs
index 48394f4f1..b2c587fa1 100644
--- a/examples/stm32f4/src/bin/wdt.rs
+++ b/examples/stm32f4/src/bin/wdt.rs
@@ -3,15 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::wdg::IndependentWatchdog; 8use embassy_stm32::wdg::IndependentWatchdog;
10use embassy_stm32::Peripherals; 9use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 info!("Hello World!"); 15 info!("Hello World!");
16 16
17 let mut led = Output::new(p.PB7, Level::High, Speed::Low); 17 let mut led = Output::new(p.PB7, Level::High, Speed::Low);
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml
index 081bed84f..29d6da4d8 100644
--- a/examples/stm32f7/Cargo.toml
+++ b/examples/stm32f7/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] }
10embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] } 11embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] }
11embedded-io = { version = "0.3.0", features = ["async"] } 12embedded-io = { version = "0.3.0", features = ["async"] }
@@ -13,7 +14,7 @@ embedded-io = { version = "0.3.0", features = ["async"] }
13defmt = "0.3" 14defmt = "0.3"
14defmt-rtt = "0.3" 15defmt-rtt = "0.3"
15 16
16cortex-m = "0.7.3" 17cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
17cortex-m-rt = "0.7.0" 18cortex-m-rt = "0.7.0"
18embedded-hal = "0.2.6" 19embedded-hal = "0.2.6"
19panic-probe = { version = "0.3", features = ["print-defmt"] } 20panic-probe = { version = "0.3", features = ["print-defmt"] }
@@ -21,5 +22,5 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
21heapless = { version = "0.7.5", default-features = false } 22heapless = { version = "0.7.5", default-features = false }
22nb = "1.0.0" 23nb = "1.0.0"
23rand_core = "0.6.3" 24rand_core = "0.6.3"
24critical-section = "0.2.3" 25critical-section = "1.1"
25embedded-storage = "0.3.0" 26embedded-storage = "0.3.0"
diff --git a/examples/stm32f7/src/bin/adc.rs b/examples/stm32f7/src/bin/adc.rs
index 2a813c050..80fad8c41 100644
--- a/examples/stm32f7/src/bin/adc.rs
+++ b/examples/stm32f7/src/bin/adc.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Delay, Duration, Timer};
8use embassy_stm32::adc::Adc; 7use embassy_stm32::adc::Adc;
9use embassy_stm32::Peripherals; 8use embassy_time::{Delay, Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut adc = Adc::new(p.ADC1, &mut Delay); 16 let mut adc = Adc::new(p.ADC1, &mut Delay);
diff --git a/examples/stm32f7/src/bin/blinky.rs b/examples/stm32f7/src/bin/blinky.rs
index f71fe0989..b27bee4ce 100644
--- a/examples/stm32f7/src/bin/blinky.rs
+++ b/examples/stm32f7/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PB7, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB7, Level::High, Speed::Low);
diff --git a/examples/stm32f7/src/bin/button_exti.rs b/examples/stm32f7/src/bin/button_exti.rs
index 60dfb362b..dfe587d41 100644
--- a/examples/stm32f7/src/bin/button_exti.rs
+++ b/examples/stm32f7/src/bin/button_exti.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let button = Input::new(p.PC13, Pull::Down); 16 let button = Input::new(p.PC13, Pull::Down);
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs
index 33504af76..bdffabcb3 100644
--- a/examples/stm32f7/src/bin/eth.rs
+++ b/examples/stm32f7/src/bin/eth.rs
@@ -3,8 +3,7 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_net::tcp::TcpSocket; 7use embassy_net::tcp::TcpSocket;
9use embassy_net::{Ipv4Address, Stack, StackResources}; 8use embassy_net::{Ipv4Address, Stack, StackResources};
10use embassy_stm32::eth::generic_smi::GenericSMI; 9use embassy_stm32::eth::generic_smi::GenericSMI;
@@ -12,7 +11,8 @@ use embassy_stm32::eth::{Ethernet, State};
12use embassy_stm32::peripherals::ETH; 11use embassy_stm32::peripherals::ETH;
13use embassy_stm32::rng::Rng; 12use embassy_stm32::rng::Rng;
14use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
15use embassy_stm32::{interrupt, Config, Peripherals}; 14use embassy_stm32::{interrupt, Config};
15use embassy_time::{Duration, Timer};
16use embassy_util::Forever; 16use embassy_util::Forever;
17use embedded_io::asynch::Write; 17use embedded_io::asynch::Write;
18use rand_core::RngCore; 18use rand_core::RngCore;
@@ -33,14 +33,12 @@ async fn net_task(stack: &'static Stack<Device>) -> ! {
33 stack.run().await 33 stack.run().await
34} 34}
35 35
36fn config() -> Config { 36#[embassy_executor::main]
37async fn main(spawner: Spawner) -> ! {
37 let mut config = Config::default(); 38 let mut config = Config::default();
38 config.rcc.sys_ck = Some(mhz(200)); 39 config.rcc.sys_ck = Some(mhz(200));
39 config 40 let p = embassy_stm32::init(config);
40}
41 41
42#[embassy_executor::main(config = "config()")]
43async fn main(spawner: Spawner, p: Peripherals) -> ! {
44 info!("Hello World!"); 42 info!("Hello World!");
45 43
46 // Generate random seed. 44 // Generate random seed.
diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs
index 15864cabb..c10781d0c 100644
--- a/examples/stm32f7/src/bin/flash.rs
+++ b/examples/stm32f7/src/bin/flash.rs
@@ -3,15 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 info!("Hello Flash!"); 15 info!("Hello Flash!");
16 16
17 const ADDR: u32 = 0x8_0000; 17 const ADDR: u32 = 0x8_0000;
diff --git a/examples/stm32f7/src/bin/hello.rs b/examples/stm32f7/src/bin/hello.rs
index f957656ef..c409703f5 100644
--- a/examples/stm32f7/src/bin/hello.rs
+++ b/examples/stm32f7/src/bin/hello.rs
@@ -3,20 +3,18 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::info; 5use defmt::info;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::time::Hertz; 7use embassy_stm32::time::Hertz;
9use embassy_stm32::{Config, Peripherals}; 8use embassy_stm32::Config;
9use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) -> ! {
13 let mut config = Config::default(); 14 let mut config = Config::default();
14 config.rcc.sys_ck = Some(Hertz(84_000_000)); 15 config.rcc.sys_ck = Some(Hertz(84_000_000));
15 config 16 let _p = embassy_stm32::init(config);
16}
17 17
18#[embassy_executor::main(config = "config()")]
19async fn main(_spawner: Spawner, _p: Peripherals) -> ! {
20 loop { 18 loop {
21 info!("Hello World!"); 19 info!("Hello World!");
22 Timer::after(Duration::from_secs(1)).await; 20 Timer::after(Duration::from_secs(1)).await;
diff --git a/examples/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs
index 1f321df17..3bf427eca 100644
--- a/examples/stm32f7/src/bin/sdmmc.rs
+++ b/examples/stm32f7/src/bin/sdmmc.rs
@@ -3,20 +3,18 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::sdmmc::Sdmmc; 7use embassy_stm32::sdmmc::Sdmmc;
8use embassy_stm32::time::mhz; 8use embassy_stm32::time::mhz;
9use embassy_stm32::{interrupt, Config, Peripherals}; 9use embassy_stm32::{interrupt, Config};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) -> ! {
13 let mut config = Config::default(); 14 let mut config = Config::default();
14 config.rcc.sys_ck = Some(mhz(200)); 15 config.rcc.sys_ck = Some(mhz(200));
15 config 16 let p = embassy_stm32::init(config);
16}
17 17
18#[embassy_executor::main(config = "config()")]
19async fn main(_spawner: Spawner, p: Peripherals) -> ! {
20 info!("Hello World!"); 18 info!("Hello World!");
21 19
22 let irq = interrupt::take!(SDMMC1); 20 let irq = interrupt::take!(SDMMC1);
diff --git a/examples/stm32f7/src/bin/usart_dma.rs b/examples/stm32f7/src/bin/usart_dma.rs
index 9884d1634..07270479c 100644
--- a/examples/stm32f7/src/bin/usart_dma.rs
+++ b/examples/stm32f7/src/bin/usart_dma.rs
@@ -5,15 +5,15 @@
5use core::fmt::Write; 5use core::fmt::Write;
6 6
7use defmt::*; 7use defmt::*;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use embassy_stm32::Peripherals;
12use heapless::String; 11use heapless::String;
13use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
14 13
15#[embassy_executor::main] 14#[embassy_executor::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner) {
16 let p = embassy_stm32::init(Default::default());
17 let config = Config::default(); 17 let config = Config::default();
18 let mut usart = Uart::new(p.UART7, p.PA8, p.PA15, p.DMA1_CH1, NoDma, config); 18 let mut usart = Uart::new(p.UART7, p.PA8, p.PA15, p.DMA1_CH1, NoDma, config);
19 19
diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml
index 3dedeac63..5c80d43eb 100644
--- a/examples/stm32g0/Cargo.toml
+++ b/examples/stm32g0/Cargo.toml
@@ -5,13 +5,14 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] }
10 11
11defmt = "0.3" 12defmt = "0.3"
12defmt-rtt = "0.3" 13defmt-rtt = "0.3"
13 14
14cortex-m = "0.7.3" 15cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
15cortex-m-rt = "0.7.0" 16cortex-m-rt = "0.7.0"
16embedded-hal = "0.2.6" 17embedded-hal = "0.2.6"
17panic-probe = { version = "0.3", features = ["print-defmt"] } 18panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/stm32g0/src/bin/blinky.rs b/examples/stm32g0/src/bin/blinky.rs
index f71fe0989..b27bee4ce 100644
--- a/examples/stm32g0/src/bin/blinky.rs
+++ b/examples/stm32g0/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PB7, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB7, Level::High, Speed::Low);
diff --git a/examples/stm32g0/src/bin/button_exti.rs b/examples/stm32g0/src/bin/button_exti.rs
index 0832386ed..ef32d4c4a 100644
--- a/examples/stm32g0/src/bin/button_exti.rs
+++ b/examples/stm32g0/src/bin/button_exti.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let button = Input::new(p.PC13, Pull::Up); 16 let button = Input::new(p.PC13, Pull::Up);
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml
index 60c62ad1e..74c645cf5 100644
--- a/examples/stm32g4/Cargo.toml
+++ b/examples/stm32g4/Cargo.toml
@@ -5,14 +5,15 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] }
10embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } 11embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
11 12
12defmt = "0.3" 13defmt = "0.3"
13defmt-rtt = "0.3" 14defmt-rtt = "0.3"
14 15
15cortex-m = "0.7.3" 16cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
16cortex-m-rt = "0.7.0" 17cortex-m-rt = "0.7.0"
17embedded-hal = "0.2.6" 18embedded-hal = "0.2.6"
18panic-probe = { version = "0.3", features = ["print-defmt"] } 19panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs
index ea3c563b4..8a65b0692 100644
--- a/examples/stm32g4/src/bin/blinky.rs
+++ b/examples/stm32g4/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PA5, Level::High, Speed::Low); 16 let mut led = Output::new(p.PA5, Level::High, Speed::Low);
diff --git a/examples/stm32g4/src/bin/button_exti.rs b/examples/stm32g4/src/bin/button_exti.rs
index 60dfb362b..dfe587d41 100644
--- a/examples/stm32g4/src/bin/button_exti.rs
+++ b/examples/stm32g4/src/bin/button_exti.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let button = Input::new(p.PC13, Pull::Down); 16 let button = Input::new(p.PC13, Pull::Down);
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs
index 7c16d0a3a..017e89e41 100644
--- a/examples/stm32g4/src/bin/pwm.rs
+++ b/examples/stm32g4/src/bin/pwm.rs
@@ -3,16 +3,16 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; 7use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm};
9use embassy_stm32::pwm::Channel; 8use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::khz; 9use embassy_stm32::time::khz;
11use embassy_stm32::Peripherals; 10use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
13 12
14#[embassy_executor::main] 13#[embassy_executor::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default());
16 info!("Hello World!"); 16 info!("Hello World!");
17 17
18 let ch1 = PwmPin::new_ch1(p.PA5); 18 let ch1 = PwmPin::new_ch1(p.PA5);
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml
index 8b1999b30..a416796ea 100644
--- a/examples/stm32h7/Cargo.toml
+++ b/examples/stm32h7/Cargo.toml
@@ -5,24 +5,26 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
10embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] } 11embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16", "unstable-traits"] }
11embedded-io = { version = "0.3.0", features = ["async"] } 12embedded-io = { version = "0.3.0", features = ["async"] }
12 13
13defmt = "0.3" 14defmt = "0.3"
14defmt-rtt = "0.3" 15defmt-rtt = "0.3"
15 16
16cortex-m = "0.7.3" 17cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
17cortex-m-rt = "0.7.0" 18cortex-m-rt = "0.7.0"
18embedded-hal = "0.2.6" 19embedded-hal = "0.2.6"
19embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } 20embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" }
20embedded-hal-async = { version = "0.1.0-alpha.1" } 21embedded-hal-async = { version = "0.1.0-alpha.1" }
22embedded-nal-async = "0.2.0"
21panic-probe = { version = "0.3", features = ["print-defmt"] } 23panic-probe = { version = "0.3", features = ["print-defmt"] }
22futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 24futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
23heapless = { version = "0.7.5", default-features = false } 25heapless = { version = "0.7.5", default-features = false }
24rand_core = "0.6.3" 26rand_core = "0.6.3"
25critical-section = "0.2.5" 27critical-section = "1.1"
26micromath = "2.0.0" 28micromath = "2.0.0"
27stm32-fmc = "0.2.4" 29stm32-fmc = "0.2.4"
28embedded-storage = "0.3.0" 30embedded-storage = "0.3.0"
diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs
index f50976a30..0e1e28c72 100644
--- a/examples/stm32h7/src/bin/adc.rs
+++ b/examples/stm32h7/src/bin/adc.rs
@@ -3,25 +3,23 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Delay, Duration, Timer};
8use embassy_stm32::adc::{Adc, SampleTime}; 7use embassy_stm32::adc::{Adc, SampleTime};
9use embassy_stm32::rcc::AdcClockSource; 8use embassy_stm32::rcc::AdcClockSource;
10use embassy_stm32::time::mhz; 9use embassy_stm32::time::mhz;
11use embassy_stm32::{Config, Peripherals}; 10use embassy_stm32::Config;
11use embassy_time::{Delay, Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14pub fn config() -> Config { 14#[embassy_executor::main]
15async fn main(_spawner: Spawner) {
15 let mut config = Config::default(); 16 let mut config = Config::default();
16 config.rcc.sys_ck = Some(mhz(400)); 17 config.rcc.sys_ck = Some(mhz(400));
17 config.rcc.hclk = Some(mhz(200)); 18 config.rcc.hclk = Some(mhz(200));
18 config.rcc.per_ck = Some(mhz(64)); 19 config.rcc.per_ck = Some(mhz(64));
19 config.rcc.adc_clock_source = AdcClockSource::PerCk; 20 config.rcc.adc_clock_source = AdcClockSource::PerCk;
20 config 21 let mut p = embassy_stm32::init(config);
21}
22 22
23#[embassy_executor::main(config = "config()")]
24async fn main(_spawner: Spawner, mut p: Peripherals) {
25 info!("Hello World!"); 23 info!("Hello World!");
26 24
27 let mut adc = Adc::new(p.ADC3, &mut Delay); 25 let mut adc = Adc::new(p.ADC3, &mut Delay);
diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs
index 98ce15cc6..12f08c0fd 100644
--- a/examples/stm32h7/src/bin/blinky.rs
+++ b/examples/stm32h7/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
diff --git a/examples/stm32h7/src/bin/button_exti.rs b/examples/stm32h7/src/bin/button_exti.rs
index 60dfb362b..dfe587d41 100644
--- a/examples/stm32h7/src/bin/button_exti.rs
+++ b/examples/stm32h7/src/bin/button_exti.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let button = Input::new(p.PC13, Pull::Down); 16 let button = Input::new(p.PC13, Pull::Down);
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs
index 69187182f..9c443b83a 100644
--- a/examples/stm32h7/src/bin/camera.rs
+++ b/examples/stm32h7/src/bin/camera.rs
@@ -2,18 +2,24 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use embassy_executor::executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_executor::time::{Duration, Timer};
7use embassy_stm32::dcmi::{self, *}; 6use embassy_stm32::dcmi::{self, *};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::i2c::I2c; 8use embassy_stm32::i2c::I2c;
10use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; 9use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
11use embassy_stm32::time::{khz, mhz}; 10use embassy_stm32::time::{khz, mhz};
12use embassy_stm32::{interrupt, Config, Peripherals}; 11use embassy_stm32::{interrupt, Config};
12use embassy_time::{Duration, Timer};
13use ov7725::*;
13use {defmt_rtt as _, panic_probe as _}; 14use {defmt_rtt as _, panic_probe as _};
14 15
15#[allow(unused)] 16const WIDTH: usize = 100;
16pub fn config() -> Config { 17const HEIGHT: usize = 100;
18
19static mut FRAME: [u32; WIDTH * HEIGHT / 2] = [0u32; WIDTH * HEIGHT / 2];
20
21#[embassy_executor::main]
22async fn main(_spawner: Spawner) {
17 let mut config = Config::default(); 23 let mut config = Config::default();
18 config.rcc.sys_ck = Some(mhz(400)); 24 config.rcc.sys_ck = Some(mhz(400));
19 config.rcc.hclk = Some(mhz(400)); 25 config.rcc.hclk = Some(mhz(400));
@@ -22,24 +28,23 @@ pub fn config() -> Config {
22 config.rcc.pclk2 = Some(mhz(100)); 28 config.rcc.pclk2 = Some(mhz(100));
23 config.rcc.pclk3 = Some(mhz(100)); 29 config.rcc.pclk3 = Some(mhz(100));
24 config.rcc.pclk4 = Some(mhz(100)); 30 config.rcc.pclk4 = Some(mhz(100));
25 config 31 let p = embassy_stm32::init(config);
26}
27 32
28use ov7725::*;
29
30const WIDTH: usize = 100;
31const HEIGHT: usize = 100;
32
33static mut FRAME: [u32; WIDTH * HEIGHT / 2] = [0u32; WIDTH * HEIGHT / 2];
34
35#[embassy_executor::main(config = "config()")]
36async fn main(_spawner: Spawner, p: Peripherals) {
37 defmt::info!("Hello World!"); 33 defmt::info!("Hello World!");
38 let mco = Mco::new(p.MCO1, p.PA8, Mco1Source::Hsi, McoClock::Divided(3)); 34 let mco = Mco::new(p.MCO1, p.PA8, Mco1Source::Hsi, McoClock::Divided(3));
39 35
40 let mut led = Output::new(p.PE3, Level::High, Speed::Low); 36 let mut led = Output::new(p.PE3, Level::High, Speed::Low);
41 let i2c_irq = interrupt::take!(I2C1_EV); 37 let i2c_irq = interrupt::take!(I2C1_EV);
42 let cam_i2c = I2c::new(p.I2C1, p.PB8, p.PB9, i2c_irq, p.DMA1_CH1, p.DMA1_CH2, khz(100)); 38 let cam_i2c = I2c::new(
39 p.I2C1,
40 p.PB8,
41 p.PB9,
42 i2c_irq,
43 p.DMA1_CH1,
44 p.DMA1_CH2,
45 khz(100),
46 Default::default(),
47 );
43 48
44 let mut camera = Ov7725::new(cam_i2c, mco); 49 let mut camera = Ov7725::new(cam_i2c, mco);
45 50
@@ -78,8 +83,8 @@ mod ov7725 {
78 use core::marker::PhantomData; 83 use core::marker::PhantomData;
79 84
80 use defmt::Format; 85 use defmt::Format;
81 use embassy_executor::time::{Duration, Timer};
82 use embassy_stm32::rcc::{Mco, McoInstance}; 86 use embassy_stm32::rcc::{Mco, McoInstance};
87 use embassy_time::{Duration, Timer};
83 use embedded_hal_async::i2c::I2c; 88 use embedded_hal_async::i2c::I2c;
84 89
85 #[repr(u8)] 90 #[repr(u8)]
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs
index dece74bba..f12716370 100644
--- a/examples/stm32h7/src/bin/dac.rs
+++ b/examples/stm32h7/src/bin/dac.rs
@@ -9,19 +9,15 @@ use embassy_stm32::time::mhz;
9use embassy_stm32::Config; 9use embassy_stm32::Config;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12pub fn config() -> Config {
13 let mut config = Config::default();
14 config.rcc.sys_ck = Some(mhz(400));
15 config.rcc.hclk = Some(mhz(200));
16 config.rcc.pll1.q_ck = Some(mhz(100));
17 config
18}
19
20#[entry] 12#[entry]
21fn main() -> ! { 13fn main() -> ! {
22 info!("Hello World, dude!"); 14 info!("Hello World, dude!");
23 15
24 let p = embassy_stm32::init(config()); 16 let mut config = Config::default();
17 config.rcc.sys_ck = Some(mhz(400));
18 config.rcc.hclk = Some(mhz(200));
19 config.rcc.pll1.q_ck = Some(mhz(100));
20 let p = embassy_stm32::init(config);
25 21
26 let mut dac = Dac::new_1ch(p.DAC1, p.PA4); 22 let mut dac = Dac::new_1ch(p.DAC1, p.PA4);
27 23
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs
index 4282fcedd..83210bcb5 100644
--- a/examples/stm32h7/src/bin/eth.rs
+++ b/examples/stm32h7/src/bin/eth.rs
@@ -3,8 +3,7 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_net::tcp::TcpSocket; 7use embassy_net::tcp::TcpSocket;
9use embassy_net::{Ipv4Address, Stack, StackResources}; 8use embassy_net::{Ipv4Address, Stack, StackResources};
10use embassy_stm32::eth::generic_smi::GenericSMI; 9use embassy_stm32::eth::generic_smi::GenericSMI;
@@ -12,7 +11,8 @@ use embassy_stm32::eth::{Ethernet, State};
12use embassy_stm32::peripherals::ETH; 11use embassy_stm32::peripherals::ETH;
13use embassy_stm32::rng::Rng; 12use embassy_stm32::rng::Rng;
14use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
15use embassy_stm32::{interrupt, Config, Peripherals}; 14use embassy_stm32::{interrupt, Config};
15use embassy_time::{Duration, Timer};
16use embassy_util::Forever; 16use embassy_util::Forever;
17use embedded_io::asynch::Write; 17use embedded_io::asynch::Write;
18use rand_core::RngCore; 18use rand_core::RngCore;
@@ -33,16 +33,13 @@ async fn net_task(stack: &'static Stack<Device>) -> ! {
33 stack.run().await 33 stack.run().await
34} 34}
35 35
36pub fn config() -> Config { 36#[embassy_executor::main]
37async fn main(spawner: Spawner) -> ! {
37 let mut config = Config::default(); 38 let mut config = Config::default();
38 config.rcc.sys_ck = Some(mhz(400)); 39 config.rcc.sys_ck = Some(mhz(400));
39 config.rcc.hclk = Some(mhz(200)); 40 config.rcc.hclk = Some(mhz(200));
40 config.rcc.pll1.q_ck = Some(mhz(100)); 41 config.rcc.pll1.q_ck = Some(mhz(100));
41 config 42 let p = embassy_stm32::init(config);
42}
43
44#[embassy_executor::main(config = "config()")]
45async fn main(spawner: Spawner, p: Peripherals) -> ! {
46 info!("Hello World!"); 43 info!("Hello World!");
47 44
48 // Generate random seed. 45 // Generate random seed.
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs
new file mode 100644
index 000000000..99946f504
--- /dev/null
+++ b/examples/stm32h7/src/bin/eth_client.rs
@@ -0,0 +1,122 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_net::tcp::client::{TcpClient, TcpClientState};
8use embassy_net::{Stack, StackResources};
9use embassy_stm32::eth::generic_smi::GenericSMI;
10use embassy_stm32::eth::{Ethernet, State};
11use embassy_stm32::peripherals::ETH;
12use embassy_stm32::rng::Rng;
13use embassy_stm32::time::mhz;
14use embassy_stm32::{interrupt, Config};
15use embassy_time::{Duration, Timer};
16use embassy_util::Forever;
17use embedded_io::asynch::Write;
18use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect};
19use rand_core::RngCore;
20use {defmt_rtt as _, panic_probe as _};
21
22macro_rules! forever {
23 ($val:expr) => {{
24 type T = impl Sized;
25 static FOREVER: Forever<T> = Forever::new();
26 FOREVER.put_with(move || $val)
27 }};
28}
29
30type Device = Ethernet<'static, ETH, GenericSMI, 4, 4>;
31
32#[embassy_executor::task]
33async fn net_task(stack: &'static Stack<Device>) -> ! {
34 stack.run().await
35}
36
37#[embassy_executor::main]
38async fn main(spawner: Spawner) -> ! {
39 let mut config = Config::default();
40 config.rcc.sys_ck = Some(mhz(400));
41 config.rcc.hclk = Some(mhz(200));
42 config.rcc.pll1.q_ck = Some(mhz(100));
43 let p = embassy_stm32::init(config);
44 info!("Hello World!");
45
46 // Generate random seed.
47 let mut rng = Rng::new(p.RNG);
48 let mut seed = [0; 8];
49 rng.fill_bytes(&mut seed);
50 let seed = u64::from_le_bytes(seed);
51
52 let eth_int = interrupt::take!(ETH);
53 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
54
55 let device = unsafe {
56 Ethernet::new(
57 forever!(State::new()),
58 p.ETH,
59 eth_int,
60 p.PA1,
61 p.PA2,
62 p.PC1,
63 p.PA7,
64 p.PC4,
65 p.PC5,
66 p.PG13,
67 p.PB13,
68 p.PG11,
69 GenericSMI,
70 mac_addr,
71 0,
72 )
73 };
74
75 let config = embassy_net::ConfigStrategy::Dhcp;
76 //let config = embassy_net::ConfigStrategy::Static(embassy_net::Config {
77 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
78 // dns_servers: Vec::new(),
79 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
80 //});
81
82 // Init network stack
83 let stack = &*forever!(Stack::new(
84 device,
85 config,
86 forever!(StackResources::<1, 2, 8>::new()),
87 seed
88 ));
89
90 // Launch network task
91 unwrap!(spawner.spawn(net_task(&stack)));
92
93 info!("Network task initialized");
94
95 // To ensure DHCP configuration before trying connect
96 Timer::after(Duration::from_secs(20)).await;
97
98 static STATE: TcpClientState<1, 1024, 1024> = TcpClientState::new();
99 let client = TcpClient::new(&stack, &STATE);
100
101 loop {
102 let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(10, 42, 0, 1), 8000));
103
104 info!("connecting...");
105 let r = client.connect(addr).await;
106 if let Err(e) = r {
107 info!("connect error: {:?}", e);
108 Timer::after(Duration::from_secs(1)).await;
109 continue;
110 }
111 let mut connection = r.unwrap();
112 info!("connected!");
113 loop {
114 let r = connection.write_all(b"Hello\n").await;
115 if let Err(e) = r {
116 info!("write error: {:?}", e);
117 return;
118 }
119 Timer::after(Duration::from_secs(1)).await;
120 }
121 }
122}
diff --git a/examples/stm32h7/src/bin/flash.rs b/examples/stm32h7/src/bin/flash.rs
index 0c477deba..6682c64d5 100644
--- a/examples/stm32h7/src/bin/flash.rs
+++ b/examples/stm32h7/src/bin/flash.rs
@@ -3,15 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 info!("Hello Flash!"); 15 info!("Hello Flash!");
16 16
17 const ADDR: u32 = 0x08_0000; 17 const ADDR: u32 = 0x08_0000;
diff --git a/examples/stm32h7/src/bin/fmc.rs b/examples/stm32h7/src/bin/fmc.rs
index 5140a6e22..85c690fe6 100644
--- a/examples/stm32h7/src/bin/fmc.rs
+++ b/examples/stm32h7/src/bin/fmc.rs
@@ -3,23 +3,21 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Delay, Duration, Timer};
8use embassy_stm32::fmc::Fmc; 7use embassy_stm32::fmc::Fmc;
9use embassy_stm32::time::mhz; 8use embassy_stm32::time::mhz;
10use embassy_stm32::{Config, Peripherals}; 9use embassy_stm32::Config;
10use embassy_time::{Delay, Duration, Timer};
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13pub fn config() -> Config { 13#[embassy_executor::main]
14async fn main(_spawner: Spawner) {
14 let mut config = Config::default(); 15 let mut config = Config::default();
15 config.rcc.sys_ck = Some(mhz(400)); 16 config.rcc.sys_ck = Some(mhz(400));
16 config.rcc.hclk = Some(mhz(200)); 17 config.rcc.hclk = Some(mhz(200));
17 config.rcc.pll1.q_ck = Some(mhz(100)); 18 config.rcc.pll1.q_ck = Some(mhz(100));
18 config 19 let p = embassy_stm32::init(config);
19}
20 20
21#[embassy_executor::main(config = "config()")]
22async fn main(_spawner: Spawner, p: Peripherals) {
23 info!("Hello World!"); 21 info!("Hello World!");
24 22
25 let mut core_peri = cortex_m::Peripherals::take().unwrap(); 23 let mut core_peri = cortex_m::Peripherals::take().unwrap();
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs
index f2477c7a7..1972f8ff2 100644
--- a/examples/stm32h7/src/bin/low_level_timer_api.rs
+++ b/examples/stm32h7/src/bin/low_level_timer_api.rs
@@ -3,16 +3,17 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::low_level::AFType; 7use embassy_stm32::gpio::low_level::AFType;
9use embassy_stm32::gpio::Speed; 8use embassy_stm32::gpio::Speed;
10use embassy_stm32::pwm::*; 9use embassy_stm32::pwm::*;
11use embassy_stm32::time::{khz, mhz, Hertz}; 10use embassy_stm32::time::{khz, mhz, Hertz};
12use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef, Peripherals}; 11use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef};
12use embassy_time::{Duration, Timer};
13use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
14 14
15pub fn config() -> Config { 15#[embassy_executor::main]
16async fn main(_spawner: Spawner) {
16 let mut config = Config::default(); 17 let mut config = Config::default();
17 config.rcc.sys_ck = Some(mhz(400)); 18 config.rcc.sys_ck = Some(mhz(400));
18 config.rcc.hclk = Some(mhz(400)); 19 config.rcc.hclk = Some(mhz(400));
@@ -21,11 +22,8 @@ pub fn config() -> Config {
21 config.rcc.pclk2 = Some(mhz(100)); 22 config.rcc.pclk2 = Some(mhz(100));
22 config.rcc.pclk3 = Some(mhz(100)); 23 config.rcc.pclk3 = Some(mhz(100));
23 config.rcc.pclk4 = Some(mhz(100)); 24 config.rcc.pclk4 = Some(mhz(100));
24 config 25 let p = embassy_stm32::init(config);
25}
26 26
27#[embassy_executor::main(config = "config()")]
28async fn main(_spawner: Spawner, p: Peripherals) {
29 info!("Hello World!"); 27 info!("Hello World!");
30 28
31 let mut pwm = SimplePwm32::new(p.TIM5, p.PA0, p.PA1, p.PA2, p.PA3, khz(10)); 29 let mut pwm = SimplePwm32::new(p.TIM5, p.PA0, p.PA1, p.PA2, p.PA3, khz(10));
diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs
index 83ba3742b..036455d5e 100644
--- a/examples/stm32h7/src/bin/mco.rs
+++ b/examples/stm32h7/src/bin/mco.rs
@@ -3,15 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; 8use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
10use embassy_stm32::Peripherals; 9use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 info!("Hello World!"); 15 info!("Hello World!");
16 16
17 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 17 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs
index 36ed2e4a4..c5c0dd290 100644
--- a/examples/stm32h7/src/bin/pwm.rs
+++ b/examples/stm32h7/src/bin/pwm.rs
@@ -3,15 +3,16 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; 7use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm};
9use embassy_stm32::pwm::Channel; 8use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::{khz, mhz}; 9use embassy_stm32::time::{khz, mhz};
11use embassy_stm32::{Config, Peripherals}; 10use embassy_stm32::Config;
11use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14pub fn config() -> Config { 14#[embassy_executor::main]
15async fn main(_spawner: Spawner) {
15 let mut config = Config::default(); 16 let mut config = Config::default();
16 config.rcc.sys_ck = Some(mhz(400)); 17 config.rcc.sys_ck = Some(mhz(400));
17 config.rcc.hclk = Some(mhz(400)); 18 config.rcc.hclk = Some(mhz(400));
@@ -20,11 +21,7 @@ pub fn config() -> Config {
20 config.rcc.pclk2 = Some(mhz(100)); 21 config.rcc.pclk2 = Some(mhz(100));
21 config.rcc.pclk3 = Some(mhz(100)); 22 config.rcc.pclk3 = Some(mhz(100));
22 config.rcc.pclk4 = Some(mhz(100)); 23 config.rcc.pclk4 = Some(mhz(100));
23 config 24 let p = embassy_stm32::init(config);
24}
25
26#[embassy_executor::main(config = "config()")]
27async fn main(_spawner: Spawner, p: Peripherals) {
28 info!("Hello World!"); 25 info!("Hello World!");
29 26
30 let ch1 = PwmPin::new_ch1(p.PA6); 27 let ch1 = PwmPin::new_ch1(p.PA6);
diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs
index 81fb3d162..af9be0b62 100644
--- a/examples/stm32h7/src/bin/rng.rs
+++ b/examples/stm32h7/src/bin/rng.rs
@@ -3,13 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rng::Rng; 7use embassy_stm32::rng::Rng;
8use embassy_stm32::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::main] 10#[embassy_executor::main]
12async fn main(_spawner: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner) {
12 let p = embassy_stm32::init(Default::default());
13 info!("Hello World!"); 13 info!("Hello World!");
14 14
15 let mut rng = Rng::new(p.RNG); 15 let mut rng = Rng::new(p.RNG);
diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs
index 19ae5ade1..26d1db01e 100644
--- a/examples/stm32h7/src/bin/sdmmc.rs
+++ b/examples/stm32h7/src/bin/sdmmc.rs
@@ -3,20 +3,17 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::sdmmc::Sdmmc; 7use embassy_stm32::sdmmc::Sdmmc;
8use embassy_stm32::time::mhz; 8use embassy_stm32::time::mhz;
9use embassy_stm32::{interrupt, Config, Peripherals}; 9use embassy_stm32::{interrupt, Config};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) -> ! {
13 let mut config = Config::default(); 14 let mut config = Config::default();
14 config.rcc.sys_ck = Some(mhz(200)); 15 config.rcc.sys_ck = Some(mhz(200));
15 config 16 let p = embassy_stm32::init(config);
16}
17
18#[embassy_executor::main(config = "config()")]
19async fn main(_spawner: Spawner, p: Peripherals) -> ! {
20 info!("Hello World!"); 17 info!("Hello World!");
21 18
22 let irq = interrupt::take!(SDMMC1); 19 let irq = interrupt::take!(SDMMC1);
diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs
index 2fc75c7af..be2ac268e 100644
--- a/examples/stm32h7/src/bin/signal.rs
+++ b/examples/stm32h7/src/bin/signal.rs
@@ -3,9 +3,8 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
8use embassy_stm32::Peripherals;
9use embassy_util::channel::signal::Signal; 8use embassy_util::channel::signal::Signal;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
@@ -25,7 +24,8 @@ async fn my_sending_task() {
25} 24}
26 25
27#[embassy_executor::main] 26#[embassy_executor::main]
28async fn main(spawner: Spawner, _p: Peripherals) { 27async fn main(spawner: Spawner) {
28 let _p = embassy_stm32::init(Default::default());
29 unwrap!(spawner.spawn(my_sending_task())); 29 unwrap!(spawner.spawn(my_sending_task()));
30 30
31 loop { 31 loop {
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs
index dc8cb7f47..c28f937a8 100644
--- a/examples/stm32h7/src/bin/spi.rs
+++ b/examples/stm32h7/src/bin/spi.rs
@@ -7,7 +7,7 @@ use core::str::from_utf8;
7 7
8use cortex_m_rt::entry; 8use cortex_m_rt::entry;
9use defmt::*; 9use defmt::*;
10use embassy_executor::executor::Executor; 10use embassy_executor::Executor;
11use embassy_stm32::dma::NoDma; 11use embassy_stm32::dma::NoDma;
12use embassy_stm32::peripherals::SPI3; 12use embassy_stm32::peripherals::SPI3;
13use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
@@ -16,14 +16,6 @@ use embassy_util::Forever;
16use heapless::String; 16use heapless::String;
17use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
18 18
19pub fn config() -> Config {
20 let mut config = Config::default();
21 config.rcc.sys_ck = Some(mhz(400));
22 config.rcc.hclk = Some(mhz(200));
23 config.rcc.pll1.q_ck = Some(mhz(100));
24 config
25}
26
27#[embassy_executor::task] 19#[embassy_executor::task]
28async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) { 20async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) {
29 for n in 0u32.. { 21 for n in 0u32.. {
@@ -45,7 +37,11 @@ static EXECUTOR: Forever<Executor> = Forever::new();
45fn main() -> ! { 37fn main() -> ! {
46 info!("Hello World!"); 38 info!("Hello World!");
47 39
48 let p = embassy_stm32::init(config()); 40 let mut config = Config::default();
41 config.rcc.sys_ck = Some(mhz(400));
42 config.rcc.hclk = Some(mhz(200));
43 config.rcc.pll1.q_ck = Some(mhz(100));
44 let p = embassy_stm32::init(config);
49 45
50 let spi = spi::Spi::new( 46 let spi = spi::Spi::new(
51 p.SPI3, 47 p.SPI3,
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs
index 2631ed30c..6c78c194f 100644
--- a/examples/stm32h7/src/bin/spi_dma.rs
+++ b/examples/stm32h7/src/bin/spi_dma.rs
@@ -7,7 +7,7 @@ use core::str::from_utf8;
7 7
8use cortex_m_rt::entry; 8use cortex_m_rt::entry;
9use defmt::*; 9use defmt::*;
10use embassy_executor::executor::Executor; 10use embassy_executor::Executor;
11use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; 11use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3};
12use embassy_stm32::time::mhz; 12use embassy_stm32::time::mhz;
13use embassy_stm32::{spi, Config}; 13use embassy_stm32::{spi, Config};
@@ -15,14 +15,6 @@ use embassy_util::Forever;
15use heapless::String; 15use heapless::String;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18pub fn config() -> Config {
19 let mut config = Config::default();
20 config.rcc.sys_ck = Some(mhz(400));
21 config.rcc.hclk = Some(mhz(200));
22 config.rcc.pll1.q_ck = Some(mhz(100));
23 config
24}
25
26#[embassy_executor::task] 18#[embassy_executor::task]
27async fn main_task(mut spi: spi::Spi<'static, SPI3, DMA1_CH3, DMA1_CH4>) { 19async fn main_task(mut spi: spi::Spi<'static, SPI3, DMA1_CH3, DMA1_CH4>) {
28 for n in 0u32.. { 20 for n in 0u32.. {
@@ -41,7 +33,11 @@ static EXECUTOR: Forever<Executor> = Forever::new();
41fn main() -> ! { 33fn main() -> ! {
42 info!("Hello World!"); 34 info!("Hello World!");
43 35
44 let p = embassy_stm32::init(config()); 36 let mut config = Config::default();
37 config.rcc.sys_ck = Some(mhz(400));
38 config.rcc.hclk = Some(mhz(200));
39 config.rcc.pll1.q_ck = Some(mhz(100));
40 let p = embassy_stm32::init(config);
45 41
46 let spi = spi::Spi::new( 42 let spi = spi::Spi::new(
47 p.SPI3, 43 p.SPI3,
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs
index e491fb39d..1384d54c6 100644
--- a/examples/stm32h7/src/bin/usart.rs
+++ b/examples/stm32h7/src/bin/usart.rs
@@ -4,7 +4,7 @@
4 4
5use cortex_m_rt::entry; 5use cortex_m_rt::entry;
6use defmt::*; 6use defmt::*;
7use embassy_executor::executor::Executor; 7use embassy_executor::Executor;
8use embassy_stm32::dma::NoDma; 8use embassy_stm32::dma::NoDma;
9use embassy_stm32::usart::{Config, Uart}; 9use embassy_stm32::usart::{Config, Uart};
10use embassy_util::Forever; 10use embassy_util::Forever;
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs
index aacda45bc..f8d58bb84 100644
--- a/examples/stm32h7/src/bin/usart_dma.rs
+++ b/examples/stm32h7/src/bin/usart_dma.rs
@@ -6,7 +6,7 @@ use core::fmt::Write;
6 6
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use defmt::*; 8use defmt::*;
9use embassy_executor::executor::Executor; 9use embassy_executor::Executor;
10use embassy_stm32::dma::NoDma; 10use embassy_stm32::dma::NoDma;
11use embassy_stm32::usart::{Config, Uart}; 11use embassy_stm32::usart::{Config, Uart};
12use embassy_util::Forever; 12use embassy_util::Forever;
diff --git a/examples/stm32h7/src/bin/usart_split.rs b/examples/stm32h7/src/bin/usart_split.rs
index 12bb0ce9c..64080ec45 100644
--- a/examples/stm32h7/src/bin/usart_split.rs
+++ b/examples/stm32h7/src/bin/usart_split.rs
@@ -3,11 +3,10 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
8use embassy_stm32::peripherals::{DMA1_CH1, UART7}; 8use embassy_stm32::peripherals::{DMA1_CH1, UART7};
9use embassy_stm32::usart::{Config, Uart, UartRx}; 9use embassy_stm32::usart::{Config, Uart, UartRx};
10use embassy_stm32::Peripherals;
11use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 10use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
12use embassy_util::channel::mpmc::Channel; 11use embassy_util::channel::mpmc::Channel;
13use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
@@ -27,7 +26,8 @@ async fn writer(mut usart: Uart<'static, UART7, NoDma, NoDma>) {
27static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); 26static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new();
28 27
29#[embassy_executor::main] 28#[embassy_executor::main]
30async fn main(spawner: Spawner, p: Peripherals) -> ! { 29async fn main(spawner: Spawner) -> ! {
30 let p = embassy_stm32::init(Default::default());
31 info!("Hello World!"); 31 info!("Hello World!");
32 32
33 let config = Config::default(); 33 let config = Config::default();
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index 7edda042d..fdb716d15 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -9,7 +9,8 @@ nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan",
9 9
10[dependencies] 10[dependencies]
11embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 11embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
12embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 12embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
13embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
13embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } 14embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
14embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true} 15embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true}
15 16
@@ -22,7 +23,7 @@ defmt-rtt = "0.3"
22embedded-storage = "0.3.0" 23embedded-storage = "0.3.0"
23embedded-io = "0.3.0" 24embedded-io = "0.3.0"
24 25
25cortex-m = "0.7.3" 26cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
26cortex-m-rt = "0.7.0" 27cortex-m-rt = "0.7.0"
27panic-probe = { version = "0.3", features = ["print-defmt"] } 28panic-probe = { version = "0.3", features = ["print-defmt"] }
28futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 29futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs
index 8cf21effb..07fad07c6 100644
--- a/examples/stm32l0/src/bin/blinky.rs
+++ b/examples/stm32l0/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PB5, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB5, Level::High, Speed::Low);
diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs
index a5e05c3a3..9d194471e 100644
--- a/examples/stm32l0/src/bin/button.rs
+++ b/examples/stm32l0/src/bin/button.rs
@@ -3,13 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
8use embassy_stm32::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::main] 10#[embassy_executor::main]
12async fn main(_spawner: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner) {
12 let p = embassy_stm32::init(Default::default());
13 info!("Hello World!"); 13 info!("Hello World!");
14 14
15 let button = Input::new(p.PB2, Pull::Up); 15 let button = Input::new(p.PB2, Pull::Up);
diff --git a/examples/stm32l0/src/bin/button_exti.rs b/examples/stm32l0/src/bin/button_exti.rs
index 22a096af8..af82b9955 100644
--- a/examples/stm32l0/src/bin/button_exti.rs
+++ b/examples/stm32l0/src/bin/button_exti.rs
@@ -3,20 +3,18 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals; 9use embassy_stm32::Config;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> embassy_stm32::Config { 12#[embassy_executor::main]
13 let mut config = embassy_stm32::Config::default(); 13async fn main(_spawner: Spawner) {
14 let mut config = Config::default();
14 config.rcc.enable_hsi48 = true; 15 config.rcc.enable_hsi48 = true;
15 config 16 let p = embassy_stm32::init(config);
16}
17 17
18#[embassy_executor::main(config = "config()")]
19async fn main(_spawner: Spawner, p: Peripherals) {
20 let button = Input::new(p.PB2, Pull::Up); 18 let button = Input::new(p.PB2, Pull::Up);
21 let mut button = ExtiInput::new(button, p.EXTI2); 19 let mut button = ExtiInput::new(button, p.EXTI2);
22 20
diff --git a/examples/stm32l0/src/bin/flash.rs b/examples/stm32l0/src/bin/flash.rs
index 7ad5ae3aa..867cb4d3e 100644
--- a/examples/stm32l0/src/bin/flash.rs
+++ b/examples/stm32l0/src/bin/flash.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
8use embassy_stm32::Peripherals;
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 8use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello Flash!"); 14 info!("Hello Flash!");
15 15
16 const ADDR: u32 = 0x26000; 16 const ADDR: u32 = 0x26000;
diff --git a/examples/stm32l0/src/bin/lorawan.rs b/examples/stm32l0/src/bin/lorawan.rs
index 29e54c1be..303558b96 100644
--- a/examples/stm32l0/src/bin/lorawan.rs
+++ b/examples/stm32l0/src/bin/lorawan.rs
@@ -6,26 +6,25 @@
6#![feature(generic_associated_types)] 6#![feature(generic_associated_types)]
7#![feature(type_alias_impl_trait)] 7#![feature(type_alias_impl_trait)]
8 8
9use embassy_executor::Spawner;
9use embassy_lora::sx127x::*; 10use embassy_lora::sx127x::*;
10use embassy_lora::LoraTimer; 11use embassy_lora::LoraTimer;
11use embassy_stm32::exti::ExtiInput; 12use embassy_stm32::exti::ExtiInput;
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 13use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::rng::Rng; 14use embassy_stm32::rng::Rng;
15use embassy_stm32::spi;
14use embassy_stm32::time::khz; 16use embassy_stm32::time::khz;
15use embassy_stm32::{spi, Peripherals};
16use lorawan::default_crypto::DefaultFactory as Crypto; 17use lorawan::default_crypto::DefaultFactory as Crypto;
17use lorawan_device::async_device::{region, Device, JoinMode}; 18use lorawan_device::async_device::{region, Device, JoinMode};
18use {defmt_rtt as _, panic_probe as _}; 19use {defmt_rtt as _, panic_probe as _};
19 20
20fn config() -> embassy_stm32::Config { 21#[embassy_executor::main]
22async fn main(_spawner: Spawner) {
21 let mut config = embassy_stm32::Config::default(); 23 let mut config = embassy_stm32::Config::default();
22 config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16; 24 config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16;
23 config.rcc.enable_hsi48 = true; 25 config.rcc.enable_hsi48 = true;
24 config 26 let p = embassy_stm32::init(config);
25}
26 27
27#[embassy_executor::main(config = "config()")]
28async fn main(_spawner: embassy_executor::executor::Spawner, p: Peripherals) {
29 // SPI for sx127x 28 // SPI for sx127x
30 let spi = spi::Spi::new( 29 let spi = spi::Spi::new(
31 p.SPI1, 30 p.SPI1,
diff --git a/examples/stm32l0/src/bin/raw_spawn.rs b/examples/stm32l0/src/bin/raw_spawn.rs
index cd711a430..bd87e62a4 100644
--- a/examples/stm32l0/src/bin/raw_spawn.rs
+++ b/examples/stm32l0/src/bin/raw_spawn.rs
@@ -5,9 +5,9 @@ use core::mem;
5 5
6use cortex_m_rt::entry; 6use cortex_m_rt::entry;
7use defmt::*; 7use defmt::*;
8use embassy_executor::executor::raw::TaskStorage; 8use embassy_executor::raw::TaskStorage;
9use embassy_executor::executor::Executor; 9use embassy_executor::Executor;
10use embassy_executor::time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
11use embassy_util::Forever; 11use embassy_util::Forever;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs
index 74694295c..9b5b3e27d 100644
--- a/examples/stm32l0/src/bin/spi.rs
+++ b/examples/stm32l0/src/bin/spi.rs
@@ -3,16 +3,16 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
8use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::spi::{Config, Spi}; 9use embassy_stm32::spi::{Config, Spi};
10use embassy_stm32::time::Hertz; 10use embassy_stm32::time::Hertz;
11use embassy_stm32::Peripherals;
12use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
13 12
14#[embassy_executor::main] 13#[embassy_executor::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default());
16 info!("Hello World, folks!"); 16 info!("Hello World, folks!");
17 17
18 let mut spi = Spi::new( 18 let mut spi = Spi::new(
diff --git a/examples/stm32l0/src/bin/usart_dma.rs b/examples/stm32l0/src/bin/usart_dma.rs
index 1c5ce94d7..66657d0f0 100644
--- a/examples/stm32l0/src/bin/usart_dma.rs
+++ b/examples/stm32l0/src/bin/usart_dma.rs
@@ -3,13 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::usart::{Config, Uart}; 7use embassy_stm32::usart::{Config, Uart};
8use embassy_stm32::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::main] 10#[embassy_executor::main]
12async fn main(_spawner: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner) {
12 let p = embassy_stm32::init(Default::default());
13 let mut usart = Uart::new(p.USART1, p.PB7, p.PB6, p.DMA1_CH2, p.DMA1_CH3, Config::default()); 13 let mut usart = Uart::new(p.USART1, p.PB7, p.PB6, p.DMA1_CH2, p.DMA1_CH3, Config::default());
14 14
15 usart.write(b"Hello Embassy World!\r\n").await.unwrap(); 15 usart.write(b"Hello Embassy World!\r\n").await.unwrap();
diff --git a/examples/stm32l0/src/bin/usart_irq.rs b/examples/stm32l0/src/bin/usart_irq.rs
index b77d97f85..0e2237388 100644
--- a/examples/stm32l0/src/bin/usart_irq.rs
+++ b/examples/stm32l0/src/bin/usart_irq.rs
@@ -3,15 +3,16 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
8use embassy_stm32::interrupt;
8use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; 9use embassy_stm32::usart::{BufferedUart, Config, State, Uart};
9use embassy_stm32::{interrupt, Peripherals};
10use embedded_io::asynch::{Read, Write}; 10use embedded_io::asynch::{Read, Write};
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13#[embassy_executor::main] 13#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default());
15 info!("Hi!"); 16 info!("Hi!");
16 17
17 static mut TX_BUFFER: [u8; 8] = [0; 8]; 18 static mut TX_BUFFER: [u8; 8] = [0; 8];
diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml
index d69de9c53..43f844b67 100644
--- a/examples/stm32l1/Cargo.toml
+++ b/examples/stm32l1/Cargo.toml
@@ -5,13 +5,14 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] }
10 11
11defmt = "0.3" 12defmt = "0.3"
12defmt-rtt = "0.3" 13defmt-rtt = "0.3"
13 14
14cortex-m = "0.7.3" 15cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
15cortex-m-rt = "0.7.0" 16cortex-m-rt = "0.7.0"
16embedded-hal = "0.2.6" 17embedded-hal = "0.2.6"
17panic-probe = { version = "0.3", features = ["print-defmt"] } 18panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/stm32l1/src/bin/blinky.rs b/examples/stm32l1/src/bin/blinky.rs
index 58306be94..8a345d235 100644
--- a/examples/stm32l1/src/bin/blinky.rs
+++ b/examples/stm32l1/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PA12, Level::High, Speed::Low); 16 let mut led = Output::new(p.PA12, Level::High, Speed::Low);
diff --git a/examples/stm32l1/src/bin/flash.rs b/examples/stm32l1/src/bin/flash.rs
index 78938fe3e..a76b9879f 100644
--- a/examples/stm32l1/src/bin/flash.rs
+++ b/examples/stm32l1/src/bin/flash.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
8use embassy_stm32::Peripherals;
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 8use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello Flash!"); 14 info!("Hello Flash!");
15 15
16 const ADDR: u32 = 0x26000; 16 const ADDR: u32 = 0x26000;
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs
index 05e869e71..0a532e8e3 100644
--- a/examples/stm32l1/src/bin/spi.rs
+++ b/examples/stm32l1/src/bin/spi.rs
@@ -3,16 +3,16 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
8use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::spi::{Config, Spi}; 9use embassy_stm32::spi::{Config, Spi};
10use embassy_stm32::time::Hertz; 10use embassy_stm32::time::Hertz;
11use embassy_stm32::Peripherals;
12use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
13 12
14#[embassy_executor::main] 13#[embassy_executor::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default());
16 info!("Hello World, folks!"); 16 info!("Hello World, folks!");
17 17
18 let mut spi = Spi::new( 18 let mut spi = Spi::new(
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml
index 8ac974c92..eaffa253e 100644
--- a/examples/stm32l4/Cargo.toml
+++ b/examples/stm32l4/Cargo.toml
@@ -7,14 +7,15 @@ version = "0.1.0"
7 7
8[dependencies] 8[dependencies]
9embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 9embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
10embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 10embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
11embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
11embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" }
12embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits"] } 13embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits"] }
13 14
14defmt = "0.3" 15defmt = "0.3"
15defmt-rtt = "0.3" 16defmt-rtt = "0.3"
16 17
17cortex-m = "0.7.3" 18cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
18cortex-m-rt = "0.7.0" 19cortex-m-rt = "0.7.0"
19embedded-hal = "0.2.6" 20embedded-hal = "0.2.6"
20embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } 21embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" }
diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs
index 93a20d5ea..281346e5f 100644
--- a/examples/stm32l4/src/bin/adc.rs
+++ b/examples/stm32l4/src/bin/adc.rs
@@ -3,9 +3,9 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::time::Delay;
7use embassy_stm32::adc::{Adc, Resolution}; 6use embassy_stm32::adc::{Adc, Resolution};
8use embassy_stm32::pac; 7use embassy_stm32::pac;
8use embassy_time::Delay;
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
11#[cortex_m_rt::entry] 11#[cortex_m_rt::entry]
diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs
index 3d689b5ee..033292fff 100644
--- a/examples/stm32l4/src/bin/blinky.rs
+++ b/examples/stm32l4/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs
index 0832386ed..ef32d4c4a 100644
--- a/examples/stm32l4/src/bin/button_exti.rs
+++ b/examples/stm32l4/src/bin/button_exti.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let button = Input::new(p.PC13, Pull::Up); 16 let button = Input::new(p.PC13, Pull::Up);
diff --git a/examples/stm32l4/src/bin/i2c.rs b/examples/stm32l4/src/bin/i2c.rs
index 058529ecf..d54c080c7 100644
--- a/examples/stm32l4/src/bin/i2c.rs
+++ b/examples/stm32l4/src/bin/i2c.rs
@@ -3,20 +3,30 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
8use embassy_stm32::i2c::I2c; 8use embassy_stm32::i2c::I2c;
9use embassy_stm32::interrupt;
9use embassy_stm32::time::Hertz; 10use embassy_stm32::time::Hertz;
10use embassy_stm32::{interrupt, Peripherals};
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13const ADDRESS: u8 = 0x5F; 13const ADDRESS: u8 = 0x5F;
14const WHOAMI: u8 = 0x0F; 14const WHOAMI: u8 = 0x0F;
15 15
16#[embassy_executor::main] 16#[embassy_executor::main]
17async fn main(_spawner: Spawner, p: Peripherals) -> ! { 17async fn main(_spawner: Spawner) -> ! {
18 let p = embassy_stm32::init(Default::default());
18 let irq = interrupt::take!(I2C2_EV); 19 let irq = interrupt::take!(I2C2_EV);
19 let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, NoDma, NoDma, Hertz(100_000)); 20 let mut i2c = I2c::new(
21 p.I2C2,
22 p.PB10,
23 p.PB11,
24 irq,
25 NoDma,
26 NoDma,
27 Hertz(100_000),
28 Default::default(),
29 );
20 30
21 let mut data = [0u8; 1]; 31 let mut data = [0u8; 1];
22 unwrap!(i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data)); 32 unwrap!(i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data));
diff --git a/examples/stm32l4/src/bin/i2c_blocking_async.rs b/examples/stm32l4/src/bin/i2c_blocking_async.rs
index 2dae9c2d5..35a86660d 100644
--- a/examples/stm32l4/src/bin/i2c_blocking_async.rs
+++ b/examples/stm32l4/src/bin/i2c_blocking_async.rs
@@ -4,11 +4,11 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_embedded_hal::adapter::BlockingAsync; 6use embassy_embedded_hal::adapter::BlockingAsync;
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_stm32::dma::NoDma; 8use embassy_stm32::dma::NoDma;
9use embassy_stm32::i2c::I2c; 9use embassy_stm32::i2c::I2c;
10use embassy_stm32::interrupt;
10use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
11use embassy_stm32::{interrupt, Peripherals};
12use embedded_hal_async::i2c::I2c as I2cTrait; 12use embedded_hal_async::i2c::I2c as I2cTrait;
13use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
14 14
@@ -16,9 +16,19 @@ const ADDRESS: u8 = 0x5F;
16const WHOAMI: u8 = 0x0F; 16const WHOAMI: u8 = 0x0F;
17 17
18#[embassy_executor::main] 18#[embassy_executor::main]
19async fn main(_spawner: Spawner, p: Peripherals) -> ! { 19async fn main(_spawner: Spawner) -> ! {
20 let p = embassy_stm32::init(Default::default());
20 let irq = interrupt::take!(I2C2_EV); 21 let irq = interrupt::take!(I2C2_EV);
21 let i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, NoDma, NoDma, Hertz(100_000)); 22 let i2c = I2c::new(
23 p.I2C2,
24 p.PB10,
25 p.PB11,
26 irq,
27 NoDma,
28 NoDma,
29 Hertz(100_000),
30 Default::default(),
31 );
22 let mut i2c = BlockingAsync::new(i2c); 32 let mut i2c = BlockingAsync::new(i2c);
23 33
24 let mut data = [0u8; 1]; 34 let mut data = [0u8; 1];
diff --git a/examples/stm32l4/src/bin/i2c_dma.rs b/examples/stm32l4/src/bin/i2c_dma.rs
index 9e71d404b..3ce9398a4 100644
--- a/examples/stm32l4/src/bin/i2c_dma.rs
+++ b/examples/stm32l4/src/bin/i2c_dma.rs
@@ -3,19 +3,29 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::i2c::I2c; 7use embassy_stm32::i2c::I2c;
8use embassy_stm32::interrupt;
8use embassy_stm32::time::Hertz; 9use embassy_stm32::time::Hertz;
9use embassy_stm32::{interrupt, Peripherals};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12const ADDRESS: u8 = 0x5F; 12const ADDRESS: u8 = 0x5F;
13const WHOAMI: u8 = 0x0F; 13const WHOAMI: u8 = 0x0F;
14 14
15#[embassy_executor::main] 15#[embassy_executor::main]
16async fn main(_spawner: Spawner, p: Peripherals) -> ! { 16async fn main(_spawner: Spawner) -> ! {
17 let p = embassy_stm32::init(Default::default());
17 let irq = interrupt::take!(I2C2_EV); 18 let irq = interrupt::take!(I2C2_EV);
18 let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, p.DMA1_CH4, p.DMA1_CH5, Hertz(100_000)); 19 let mut i2c = I2c::new(
20 p.I2C2,
21 p.PB10,
22 p.PB11,
23 irq,
24 p.DMA1_CH4,
25 p.DMA1_CH5,
26 Hertz(100_000),
27 Default::default(),
28 );
19 29
20 let mut data = [0u8; 1]; 30 let mut data = [0u8; 1];
21 unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data).await); 31 unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data).await);
diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs
index ed47fc6c9..c9302bb99 100644
--- a/examples/stm32l4/src/bin/rng.rs
+++ b/examples/stm32l4/src/bin/rng.rs
@@ -3,13 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; 7use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv};
8use embassy_stm32::rng::Rng; 8use embassy_stm32::rng::Rng;
9use embassy_stm32::{Config, Peripherals}; 9use embassy_stm32::Config;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
13 let mut config = Config::default(); 14 let mut config = Config::default();
14 // 72Mhz clock (16 / 1 * 18 / 4) 15 // 72Mhz clock (16 / 1 * 18 / 4)
15 config.rcc.mux = ClockSrc::PLL( 16 config.rcc.mux = ClockSrc::PLL(
@@ -19,11 +20,8 @@ fn config() -> Config {
19 PLLMul::Mul18, 20 PLLMul::Mul18,
20 Some(PLLClkDiv::Div6), // 48Mhz (16 / 1 * 18 / 6) 21 Some(PLLClkDiv::Div6), // 48Mhz (16 / 1 * 18 / 6)
21 ); 22 );
22 config 23 let p = embassy_stm32::init(config);
23}
24 24
25#[embassy_executor::main(config = "config()")]
26async fn main(_spawner: Spawner, p: Peripherals) {
27 info!("Hello World!"); 25 info!("Hello World!");
28 26
29 let mut rng = Rng::new(p.RNG); 27 let mut rng = Rng::new(p.RNG);
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs
index e06b29b81..62ef0130e 100644
--- a/examples/stm32l4/src/bin/spi_blocking_async.rs
+++ b/examples/stm32l4/src/bin/spi_blocking_async.rs
@@ -4,17 +4,17 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_embedded_hal::adapter::BlockingAsync; 6use embassy_embedded_hal::adapter::BlockingAsync;
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_stm32::dma::NoDma; 8use embassy_stm32::dma::NoDma;
9use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 9use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
10use embassy_stm32::spi::{Config, Spi}; 10use embassy_stm32::spi::{Config, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embassy_stm32::Peripherals;
13use embedded_hal_async::spi::SpiBus; 12use embedded_hal_async::spi::SpiBus;
14use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
15 14
16#[embassy_executor::main] 15#[embassy_executor::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 16async fn main(_spawner: Spawner) {
17 let p = embassy_stm32::init(Default::default());
18 info!("Hello World!"); 18 info!("Hello World!");
19 19
20 let spi = Spi::new( 20 let spi = Spi::new(
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs
index e44754bec..89471db5a 100644
--- a/examples/stm32l4/src/bin/spi_dma.rs
+++ b/examples/stm32l4/src/bin/spi_dma.rs
@@ -3,15 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
8use embassy_stm32::spi::{Config, Spi}; 8use embassy_stm32::spi::{Config, Spi};
9use embassy_stm32::time::Hertz; 9use embassy_stm32::time::Hertz;
10use embassy_stm32::Peripherals;
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 info!("Hello World!"); 15 info!("Hello World!");
16 16
17 let mut spi = Spi::new( 17 let mut spi = Spi::new(
diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs
index fdd5a85e6..728906897 100644
--- a/examples/stm32l4/src/bin/usart_dma.rs
+++ b/examples/stm32l4/src/bin/usart_dma.rs
@@ -5,15 +5,15 @@
5use core::fmt::Write; 5use core::fmt::Write;
6 6
7use defmt::*; 7use defmt::*;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use embassy_stm32::Peripherals;
12use heapless::String; 11use heapless::String;
13use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
14 13
15#[embassy_executor::main] 14#[embassy_executor::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner) {
16 let p = embassy_stm32::init(Default::default());
17 info!("Hello World!"); 17 info!("Hello World!");
18 18
19 let config = Config::default(); 19 let config = Config::default();
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml
index 6466994ed..4d96d31fc 100644
--- a/examples/stm32l5/Cargo.toml
+++ b/examples/stm32l5/Cargo.toml
@@ -7,7 +7,8 @@ version = "0.1.0"
7 7
8[dependencies] 8[dependencies]
9embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 9embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
10embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 10embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
11embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } 12embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
13embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } 14embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] }
@@ -20,7 +21,7 @@ defmt = "0.3"
20defmt-rtt = "0.3" 21defmt-rtt = "0.3"
21panic-probe = { version = "0.3", features = ["print-defmt"] } 22panic-probe = { version = "0.3", features = ["print-defmt"] }
22 23
23cortex-m = "0.7.3" 24cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
24cortex-m-rt = "0.7.0" 25cortex-m-rt = "0.7.0"
25embedded-hal = "0.2.6" 26embedded-hal = "0.2.6"
26futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 27futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
diff --git a/examples/stm32l5/src/bin/button_exti.rs b/examples/stm32l5/src/bin/button_exti.rs
index 99462e597..e80ad2b3a 100644
--- a/examples/stm32l5/src/bin/button_exti.rs
+++ b/examples/stm32l5/src/bin/button_exti.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let button = Input::new(p.PC13, Pull::Down); 16 let button = Input::new(p.PC13, Pull::Down);
diff --git a/examples/stm32l5/src/bin/rng.rs b/examples/stm32l5/src/bin/rng.rs
index 45094374b..d359847e8 100644
--- a/examples/stm32l5/src/bin/rng.rs
+++ b/examples/stm32l5/src/bin/rng.rs
@@ -3,13 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; 7use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv};
8use embassy_stm32::rng::Rng; 8use embassy_stm32::rng::Rng;
9use embassy_stm32::{Config, Peripherals}; 9use embassy_stm32::Config;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
13 let mut config = Config::default(); 14 let mut config = Config::default();
14 config.rcc.mux = ClockSrc::PLL( 15 config.rcc.mux = ClockSrc::PLL(
15 PLLSource::HSI16, 16 PLLSource::HSI16,
@@ -18,11 +19,8 @@ fn config() -> Config {
18 PLLMul::Mul8, 19 PLLMul::Mul8,
19 Some(PLLClkDiv::Div2), 20 Some(PLLClkDiv::Div2),
20 ); 21 );
21 config 22 let p = embassy_stm32::init(config);
22}
23 23
24#[embassy_executor::main(config = "config()")]
25async fn main(_spawner: Spawner, p: Peripherals) {
26 info!("Hello World!"); 24 info!("Hello World!");
27 25
28 let mut rng = Rng::new(p.RNG); 26 let mut rng = Rng::new(p.RNG);
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs
index 9e1df15dd..7c53d03cc 100644
--- a/examples/stm32l5/src/bin/usb_ethernet.rs
+++ b/examples/stm32l5/src/bin/usb_ethernet.rs
@@ -7,14 +7,14 @@ use core::sync::atomic::{AtomicBool, Ordering};
7use core::task::Waker; 7use core::task::Waker;
8 8
9use defmt::*; 9use defmt::*;
10use embassy_executor::executor::Spawner; 10use embassy_executor::Spawner;
11use embassy_net::tcp::TcpSocket; 11use embassy_net::tcp::TcpSocket;
12use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; 12use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources};
13use embassy_stm32::rcc::*; 13use embassy_stm32::rcc::*;
14use embassy_stm32::rng::Rng; 14use embassy_stm32::rng::Rng;
15use embassy_stm32::time::Hertz; 15use embassy_stm32::time::Hertz;
16use embassy_stm32::usb::Driver; 16use embassy_stm32::usb::Driver;
17use embassy_stm32::{interrupt, Config, Peripherals}; 17use embassy_stm32::{interrupt, Config};
18use embassy_usb::{Builder, UsbDevice}; 18use embassy_usb::{Builder, UsbDevice};
19use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; 19use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
20use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 20use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
@@ -83,18 +83,13 @@ async fn net_task(stack: &'static Stack<Device>) -> ! {
83 stack.run().await 83 stack.run().await
84} 84}
85 85
86fn config() -> Config { 86#[embassy_executor::main]
87async fn main(spawner: Spawner) {
87 let mut config = Config::default(); 88 let mut config = Config::default();
88 config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000));
89
90 config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); 89 config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None);
91 config.rcc.hsi48 = true; 90 config.rcc.hsi48 = true;
91 let p = embassy_stm32::init(config);
92 92
93 config
94}
95
96#[embassy_executor::main(config = "config()")]
97async fn main(spawner: Spawner, p: Peripherals) {
98 // Create the driver, from the HAL. 93 // Create the driver, from the HAL.
99 let irq = interrupt::take!(USB_FS); 94 let irq = interrupt::take!(USB_FS);
100 let driver = Driver::new(p.USB, irq, p.PA12, p.PA11); 95 let driver = Driver::new(p.USB, irq, p.PA12, p.PA11);
diff --git a/examples/stm32l5/src/bin/usb_hid_mouse.rs b/examples/stm32l5/src/bin/usb_hid_mouse.rs
index 6aac00881..f7e3d93e3 100644
--- a/examples/stm32l5/src/bin/usb_hid_mouse.rs
+++ b/examples/stm32l5/src/bin/usb_hid_mouse.rs
@@ -4,12 +4,12 @@
4#![feature(type_alias_impl_trait)] 4#![feature(type_alias_impl_trait)]
5 5
6use defmt::*; 6use defmt::*;
7use embassy_executor::executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_executor::time::{Duration, Timer};
9use embassy_stm32::rcc::*; 8use embassy_stm32::rcc::*;
10use embassy_stm32::time::Hertz; 9use embassy_stm32::time::Hertz;
11use embassy_stm32::usb::Driver; 10use embassy_stm32::usb::Driver;
12use embassy_stm32::{interrupt, Config, Peripherals}; 11use embassy_stm32::{interrupt, Config, Peripherals};
12use embassy_time::{Duration, Timer};
13use embassy_usb::control::OutResponse; 13use embassy_usb::control::OutResponse;
14use embassy_usb::Builder; 14use embassy_usb::Builder;
15use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; 15use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State};
@@ -17,18 +17,13 @@ use futures::future::join;
17use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; 17use usbd_hid::descriptor::{MouseReport, SerializedDescriptor};
18use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
19 19
20fn config() -> Config { 20#[embassy_executor::main]
21async fn main(_spawner: Spawner) {
21 let mut config = Config::default(); 22 let mut config = Config::default();
22 config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000));
23
24 config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); 23 config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None);
25 config.rcc.hsi48 = true; 24 config.rcc.hsi48 = true;
25 let p = embassy_stm32::init(config);
26 26
27 config
28}
29
30#[embassy_executor::main(config = "config()")]
31async fn main(_spawner: Spawner, p: Peripherals) {
32 // Create the driver, from the HAL. 27 // Create the driver, from the HAL.
33 let irq = interrupt::take!(USB_FS); 28 let irq = interrupt::take!(USB_FS);
34 let driver = Driver::new(p.USB, irq, p.PA12, p.PA11); 29 let driver = Driver::new(p.USB, irq, p.PA12, p.PA11);
diff --git a/examples/stm32l5/src/bin/usb_serial.rs b/examples/stm32l5/src/bin/usb_serial.rs
index 508bce8a8..323db6557 100644
--- a/examples/stm32l5/src/bin/usb_serial.rs
+++ b/examples/stm32l5/src/bin/usb_serial.rs
@@ -3,29 +3,24 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{panic, *}; 5use defmt::{panic, *};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rcc::*; 7use embassy_stm32::rcc::*;
8use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
9use embassy_stm32::usb::{Driver, Instance}; 9use embassy_stm32::usb::{Driver, Instance};
10use embassy_stm32::{interrupt, Config, Peripherals}; 10use embassy_stm32::{interrupt, Config};
11use embassy_usb::driver::EndpointError; 11use embassy_usb::driver::EndpointError;
12use embassy_usb::Builder; 12use embassy_usb::Builder;
13use embassy_usb_serial::{CdcAcmClass, State}; 13use embassy_usb_serial::{CdcAcmClass, State};
14use futures::future::join; 14use futures::future::join;
15use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, panic_probe as _};
16 16
17fn config() -> Config { 17#[embassy_executor::main]
18async fn main(_spawner: Spawner) {
18 let mut config = Config::default(); 19 let mut config = Config::default();
19 config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000));
20
21 config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); 20 config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None);
22 config.rcc.hsi48 = true; 21 config.rcc.hsi48 = true;
22 let p = embassy_stm32::init(config);
23 23
24 config
25}
26
27#[embassy_executor::main(config = "config()")]
28async fn main(_spawner: Spawner, p: Peripherals) {
29 info!("Hello World!"); 24 info!("Hello World!");
30 25
31 // Create the driver, from the HAL. 26 // Create the driver, from the HAL.
diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml
index 4ce95be4c..48833664a 100644
--- a/examples/stm32u5/Cargo.toml
+++ b/examples/stm32u5/Cargo.toml
@@ -5,13 +5,14 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] }
10 11
11defmt = "0.3" 12defmt = "0.3"
12defmt-rtt = "0.3" 13defmt-rtt = "0.3"
13 14
14cortex-m = "0.7.3" 15cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
15cortex-m-rt = "0.7.0" 16cortex-m-rt = "0.7.0"
16embedded-hal = "0.2.6" 17embedded-hal = "0.2.6"
17panic-probe = { version = "0.3", features = ["print-defmt"] } 18panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/stm32u5/src/bin/blinky.rs b/examples/stm32u5/src/bin/blinky.rs
index 4f3eabc5e..976fb0b9a 100644
--- a/examples/stm32u5/src/bin/blinky.rs
+++ b/examples/stm32u5/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) -> ! { 12async fn main(_spawner: Spawner) -> ! {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PH7, Level::Low, Speed::Medium); 16 let mut led = Output::new(p.PH7, Level::Low, Speed::Medium);
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml
index dc9107dd0..b46300764 100644
--- a/examples/stm32wb/Cargo.toml
+++ b/examples/stm32wb/Cargo.toml
@@ -5,13 +5,14 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55cc", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55cc", "time-driver-any", "exti"] }
10 11
11defmt = "0.3" 12defmt = "0.3"
12defmt-rtt = "0.3" 13defmt-rtt = "0.3"
13 14
14cortex-m = "0.7.3" 15cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
15cortex-m-rt = "0.7.0" 16cortex-m-rt = "0.7.0"
16embedded-hal = "0.2.6" 17embedded-hal = "0.2.6"
17panic-probe = { version = "0.3", features = ["print-defmt"] } 18panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/stm32wb/src/bin/blinky.rs b/examples/stm32wb/src/bin/blinky.rs
index 3d8e8391d..f9bf90d2e 100644
--- a/examples/stm32wb/src/bin/blinky.rs
+++ b/examples/stm32wb/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PB0, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB0, Level::High, Speed::Low);
diff --git a/examples/stm32wb/src/bin/button_exti.rs b/examples/stm32wb/src/bin/button_exti.rs
index 41afaf4d6..3648db6ff 100644
--- a/examples/stm32wb/src/bin/button_exti.rs
+++ b/examples/stm32wb/src/bin/button_exti.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let button = Input::new(p.PC4, Pull::Up); 16 let button = Input::new(p.PC4, Pull::Up);
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml
index 00d63f02d..ae33478af 100644
--- a/examples/stm32wl/Cargo.toml
+++ b/examples/stm32wl/Cargo.toml
@@ -5,7 +5,8 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] }
10embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } 11embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] }
11 12
@@ -15,7 +16,7 @@ lorawan = { version = "0.7.1", default-features = false, features = ["default-cr
15defmt = "0.3" 16defmt = "0.3"
16defmt-rtt = "0.3" 17defmt-rtt = "0.3"
17 18
18cortex-m = "0.7.3" 19cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
19cortex-m-rt = "0.7.0" 20cortex-m-rt = "0.7.0"
20embedded-hal = "0.2.6" 21embedded-hal = "0.2.6"
21embedded-storage = "0.3.0" 22embedded-storage = "0.3.0"
diff --git a/examples/stm32wl/src/bin/blinky.rs b/examples/stm32wl/src/bin/blinky.rs
index e764b4cc3..6af5099ce 100644
--- a/examples/stm32wl/src/bin/blinky.rs
+++ b/examples/stm32wl/src/bin/blinky.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 8use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let mut led = Output::new(p.PB15, Level::High, Speed::Low); 16 let mut led = Output::new(p.PB15, Level::High, Speed::Low);
diff --git a/examples/stm32wl/src/bin/button_exti.rs b/examples/stm32wl/src/bin/button_exti.rs
index 9f143597d..1f02db5cf 100644
--- a/examples/stm32wl/src/bin/button_exti.rs
+++ b/examples/stm32wl/src/bin/button_exti.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 14 info!("Hello World!");
15 15
16 let button = Input::new(p.PA0, Pull::Up); 16 let button = Input::new(p.PA0, Pull::Up);
diff --git a/examples/stm32wl/src/bin/flash.rs b/examples/stm32wl/src/bin/flash.rs
index 46183b8a2..eb7489760 100644
--- a/examples/stm32wl/src/bin/flash.rs
+++ b/examples/stm32wl/src/bin/flash.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
8use embassy_stm32::Peripherals;
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 8use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy_executor::main] 11#[embassy_executor::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default());
14 info!("Hello Flash!"); 14 info!("Hello Flash!");
15 15
16 const ADDR: u32 = 0x36000; 16 const ADDR: u32 = 0x36000;
diff --git a/examples/stm32wl/src/bin/lorawan.rs b/examples/stm32wl/src/bin/lorawan.rs
index 2db022ea2..7e8a8946d 100644
--- a/examples/stm32wl/src/bin/lorawan.rs
+++ b/examples/stm32wl/src/bin/lorawan.rs
@@ -5,26 +5,25 @@
5#![feature(generic_associated_types)] 5#![feature(generic_associated_types)]
6#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
7 7
8use embassy_executor::Spawner;
8use embassy_lora::stm32wl::*; 9use embassy_lora::stm32wl::*;
9use embassy_lora::LoraTimer; 10use embassy_lora::LoraTimer;
10use embassy_stm32::dma::NoDma; 11use embassy_stm32::dma::NoDma;
11use embassy_stm32::gpio::{Level, Output, Pin, Speed}; 12use embassy_stm32::gpio::{Level, Output, Pin, Speed};
12use embassy_stm32::rng::Rng; 13use embassy_stm32::rng::Rng;
13use embassy_stm32::subghz::*; 14use embassy_stm32::subghz::*;
14use embassy_stm32::{interrupt, pac, Peripherals}; 15use embassy_stm32::{interrupt, pac};
15use lorawan::default_crypto::DefaultFactory as Crypto; 16use lorawan::default_crypto::DefaultFactory as Crypto;
16use lorawan_device::async_device::{region, Device, JoinMode}; 17use lorawan_device::async_device::{region, Device, JoinMode};
17use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
18 19
19fn config() -> embassy_stm32::Config { 20#[embassy_executor::main]
21async fn main(_spawner: Spawner) {
20 let mut config = embassy_stm32::Config::default(); 22 let mut config = embassy_stm32::Config::default();
21 config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16; 23 config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16;
22 config.rcc.enable_lsi = true; 24 config.rcc.enable_lsi = true;
23 config 25 let p = embassy_stm32::init(config);
24}
25 26
26#[embassy_executor::main(config = "config()")]
27async fn main(_spawner: embassy_executor::executor::Spawner, p: Peripherals) {
28 unsafe { pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)) } 27 unsafe { pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)) }
29 28
30 let ctrl1 = Output::new(p.PC3.degrade(), Level::High, Speed::High); 29 let ctrl1 = Output::new(p.PC3.degrade(), Level::High, Speed::High);
diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs
index 775dfbbfc..d16e3f5e4 100644
--- a/examples/stm32wl/src/bin/subghz.rs
+++ b/examples/stm32wl/src/bin/subghz.rs
@@ -6,12 +6,13 @@
6#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
7 7
8use defmt::*; 8use defmt::*;
9use embassy_executor::Spawner;
9use embassy_stm32::dma::NoDma; 10use embassy_stm32::dma::NoDma;
10use embassy_stm32::exti::ExtiInput; 11use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::interrupt;
12use embassy_stm32::interrupt::{Interrupt, InterruptExt}; 14use embassy_stm32::interrupt::{Interrupt, InterruptExt};
13use embassy_stm32::subghz::*; 15use embassy_stm32::subghz::*;
14use embassy_stm32::{interrupt, Peripherals};
15use embassy_util::channel::signal::Signal; 16use embassy_util::channel::signal::Signal;
16use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
17 18
@@ -51,14 +52,12 @@ const TCXO_MODE: TcxoMode = TcxoMode::new()
51 52
52const TX_PARAMS: TxParams = TxParams::new().set_power(0x0D).set_ramp_time(RampTime::Micros40); 53const TX_PARAMS: TxParams = TxParams::new().set_power(0x0D).set_ramp_time(RampTime::Micros40);
53 54
54fn config() -> embassy_stm32::Config { 55#[embassy_executor::main]
56async fn main(_spawner: Spawner) {
55 let mut config = embassy_stm32::Config::default(); 57 let mut config = embassy_stm32::Config::default();
56 config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSE32; 58 config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSE32;
57 config 59 let p = embassy_stm32::init(config);
58}
59 60
60#[embassy_executor::main(config = "config()")]
61async fn main(_spawner: embassy_executor::executor::Spawner, p: Peripherals) {
62 let mut led1 = Output::new(p.PB15, Level::High, Speed::Low); 61 let mut led1 = Output::new(p.PB15, Level::High, Speed::Low);
63 let mut led2 = Output::new(p.PB9, Level::Low, Speed::Low); 62 let mut led2 = Output::new(p.PB9, Level::Low, Speed::Low);
64 let mut led3 = Output::new(p.PB11, Level::Low, Speed::Low); 63 let mut led3 = Output::new(p.PB11, Level::Low, Speed::Low);
diff --git a/examples/wasm/Cargo.toml b/examples/wasm/Cargo.toml
index 4e26f023c..c7f980366 100644
--- a/examples/wasm/Cargo.toml
+++ b/examples/wasm/Cargo.toml
@@ -8,10 +8,11 @@ crate-type = ["cdylib"]
8 8
9[dependencies] 9[dependencies]
10embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] } 10embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] }
11embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "wasm", "nightly"] } 11embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "wasm", "nightly", "integrated-timers"] }
12embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "wasm", "nightly"] }
12 13
13wasm-logger = "0.2.0" 14wasm-logger = "0.2.0"
14wasm-bindgen = "0.2" 15wasm-bindgen = "0.2"
15web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] } 16web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] }
16log = "0.4.11" 17log = "0.4.11"
17critical-section = "0.2.5" 18critical-section = "1.1"
diff --git a/examples/wasm/src/lib.rs b/examples/wasm/src/lib.rs
index 2e961e65a..d44c020b6 100644
--- a/examples/wasm/src/lib.rs
+++ b/examples/wasm/src/lib.rs
@@ -1,8 +1,8 @@
1#![feature(type_alias_impl_trait)] 1#![feature(type_alias_impl_trait)]
2#![allow(incomplete_features)] 2#![allow(incomplete_features)]
3 3
4use embassy_executor::executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_executor::time::{Duration, Timer}; 5use embassy_time::{Duration, Timer};
6 6
7#[embassy_executor::task] 7#[embassy_executor::task]
8async fn ticker() { 8async fn ticker() {
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
index c6d0f485f..f5e342edc 100644
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -1,7 +1,7 @@
1# Before upgrading check that everything is available on all tier1 targets here: 1# Before upgrading check that everything is available on all tier1 targets here:
2# https://rust-lang.github.io/rustup-components-history 2# https://rust-lang.github.io/rustup-components-history
3[toolchain] 3[toolchain]
4channel = "nightly-2022-07-13" 4channel = "nightly-2022-08-16"
5components = [ "rust-src", "rustfmt" ] 5components = [ "rust-src", "rustfmt" ]
6targets = [ 6targets = [
7 "thumbv7em-none-eabi", 7 "thumbv7em-none-eabi",
diff --git a/stm32-metapac/Cargo.toml b/stm32-metapac/Cargo.toml
index 31d707785..9d5aba0c0 100644
--- a/stm32-metapac/Cargo.toml
+++ b/stm32-metapac/Cargo.toml
@@ -40,7 +40,7 @@ flavors = [
40] 40]
41 41
42[dependencies] 42[dependencies]
43cortex-m = "0.7.3" 43cortex-m = "0.7.6"
44cortex-m-rt = { version = ">=0.6.15,<0.8", optional = true } 44cortex-m-rt = { version = ">=0.6.15,<0.8", optional = true }
45 45
46# BEGIN BUILD DEPENDENCIES 46# BEGIN BUILD DEPENDENCIES
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml
index d19243b9d..8740cc488 100644
--- a/tests/rp/Cargo.toml
+++ b/tests/rp/Cargo.toml
@@ -5,13 +5,14 @@ version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] }
9embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits"] } 10embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits"] }
10 11
11defmt = "0.3.0" 12defmt = "0.3.0"
12defmt-rtt = "0.3.0" 13defmt-rtt = "0.3.0"
13 14
14cortex-m = "0.7.3" 15cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
15cortex-m-rt = "0.7.0" 16cortex-m-rt = "0.7.0"
16embedded-hal = "0.2.6" 17embedded-hal = "0.2.6"
17embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } 18embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" }
diff --git a/tests/rp/src/bin/gpio.rs b/tests/rp/src/bin/gpio.rs
index 6f6baf77a..af22fe27d 100644
--- a/tests/rp/src/bin/gpio.rs
+++ b/tests/rp/src/bin/gpio.rs
@@ -3,13 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{assert, *}; 5use defmt::{assert, *};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_rp::gpio::{Flex, Input, Level, Output, OutputOpenDrain, Pull}; 7use embassy_rp::gpio::{Flex, Input, Level, Output, OutputOpenDrain, Pull};
8use embassy_rp::Peripherals;
9use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[embassy_executor::main] 10#[embassy_executor::main]
12async fn main(_spawner: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner) {
12 let p = embassy_rp::init(Default::default());
13 info!("Hello World!"); 13 info!("Hello World!");
14 14
15 let (mut a, mut b) = (p.PIN_0, p.PIN_1); 15 let (mut a, mut b) = (p.PIN_0, p.PIN_1);
diff --git a/tests/rp/src/bin/gpio_async.rs b/tests/rp/src/bin/gpio_async.rs
index 1098682af..1eeaac1f6 100644
--- a/tests/rp/src/bin/gpio_async.rs
+++ b/tests/rp/src/bin/gpio_async.rs
@@ -3,15 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{assert, *}; 5use defmt::{assert, *};
6use embassy_executor::executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::time::{Duration, Instant, Timer};
8use embassy_rp::gpio::{Input, Level, Output, Pull}; 7use embassy_rp::gpio::{Input, Level, Output, Pull};
9use embassy_rp::Peripherals; 8use embassy_time::{Duration, Instant, Timer};
10use futures::future::join; 9use futures::future::join;
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy_executor::main] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_rp::init(Default::default());
15 info!("embassy-rp gpio_async test"); 15 info!("embassy-rp gpio_async test");
16 16
17 // On the CI device the following pins are connected with each other. 17 // On the CI device the following pins are connected with each other.
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml
index c1cca99d1..1d12995a2 100644
--- a/tests/stm32/Cargo.toml
+++ b/tests/stm32/Cargo.toml
@@ -14,13 +14,14 @@ stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board
14 14
15[dependencies] 15[dependencies]
16embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 16embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
17embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "time-tick-32768hz"] } 17embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
18embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "tick-32768hz"] }
18embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "memory-x", "time-driver-tim2"] } 19embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "memory-x", "time-driver-tim2"] }
19 20
20defmt = "0.3.0" 21defmt = "0.3.0"
21defmt-rtt = "0.3.0" 22defmt-rtt = "0.3.0"
22 23
23cortex-m = "0.7.3" 24cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
24cortex-m-rt = "0.7.0" 25cortex-m-rt = "0.7.0"
25embedded-hal = "0.2.6" 26embedded-hal = "0.2.6"
26embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } 27embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" }
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs
index 8eab731bf..18fd85d44 100644
--- a/tests/stm32/src/bin/gpio.rs
+++ b/tests/stm32/src/bin/gpio.rs
@@ -5,13 +5,13 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use defmt::assert; 7use defmt::assert;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::gpio::{Flex, Input, Level, Output, OutputOpenDrain, Pull, Speed}; 9use embassy_stm32::gpio::{Flex, Input, Level, Output, OutputOpenDrain, Pull, Speed};
10use embassy_stm32::Peripherals;
11use example_common::*; 10use example_common::*;
12 11
13#[embassy_executor::main(config = "config()")] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(config());
15 info!("Hello World!"); 15 info!("Hello World!");
16 16
17 // Arduino pins D0 and D1 17 // Arduino pins D0 and D1
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs
index 6d38b0bbf..1c5dc87c0 100644
--- a/tests/stm32/src/bin/spi.rs
+++ b/tests/stm32/src/bin/spi.rs
@@ -5,15 +5,15 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use defmt::assert_eq; 7use defmt::assert_eq;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::spi::{self, Spi}; 10use embassy_stm32::spi::{self, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embassy_stm32::Peripherals;
13use example_common::*; 12use example_common::*;
14 13
15#[embassy_executor::main(config = "config()")] 14#[embassy_executor::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner) {
16 let p = embassy_stm32::init(config());
17 info!("Hello World!"); 17 info!("Hello World!");
18 18
19 #[cfg(feature = "stm32f103c8")] 19 #[cfg(feature = "stm32f103c8")]
diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs
index 8147c5f08..cb2152e0b 100644
--- a/tests/stm32/src/bin/spi_dma.rs
+++ b/tests/stm32/src/bin/spi_dma.rs
@@ -5,14 +5,14 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use defmt::assert_eq; 7use defmt::assert_eq;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::spi::{self, Spi}; 9use embassy_stm32::spi::{self, Spi};
10use embassy_stm32::time::Hertz; 10use embassy_stm32::time::Hertz;
11use embassy_stm32::Peripherals;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy_executor::main(config = "config()")] 13#[embassy_executor::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(config());
16 info!("Hello World!"); 16 info!("Hello World!");
17 17
18 #[cfg(feature = "stm32f103c8")] 18 #[cfg(feature = "stm32f103c8")]
diff --git a/tests/stm32/src/bin/timer.rs b/tests/stm32/src/bin/timer.rs
index 76b07ca15..e00e43bf1 100644
--- a/tests/stm32/src/bin/timer.rs
+++ b/tests/stm32/src/bin/timer.rs
@@ -5,13 +5,13 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use defmt::assert; 7use defmt::assert;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_executor::time::{Duration, Instant, Timer}; 9use embassy_time::{Duration, Instant, Timer};
10use embassy_stm32::Peripherals;
11use example_common::*; 10use example_common::*;
12 11
13#[embassy_executor::main(config = "config()")] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, _p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let _p = embassy_stm32::init(config());
15 info!("Hello World!"); 15 info!("Hello World!");
16 16
17 let start = Instant::now(); 17 let start = Instant::now();
diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs
index 7b60e4b28..fb4b3fcca 100644
--- a/tests/stm32/src/bin/usart.rs
+++ b/tests/stm32/src/bin/usart.rs
@@ -5,14 +5,14 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use defmt::assert_eq; 7use defmt::assert_eq;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use embassy_stm32::Peripherals;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy_executor::main(config = "config()")] 13#[embassy_executor::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(config());
16 info!("Hello World!"); 16 info!("Hello World!");
17 17
18 #[cfg(feature = "stm32wb55rg")] 18 #[cfg(feature = "stm32wb55rg")]
diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs
index 323c41cae..09382a022 100644
--- a/tests/stm32/src/bin/usart_dma.rs
+++ b/tests/stm32/src/bin/usart_dma.rs
@@ -5,13 +5,13 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use defmt::assert_eq; 7use defmt::assert_eq;
8use embassy_executor::executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::usart::{Config, Uart}; 9use embassy_stm32::usart::{Config, Uart};
10use embassy_stm32::Peripherals;
11use example_common::*; 10use example_common::*;
12 11
13#[embassy_executor::main(config = "config()")] 12#[embassy_executor::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(config());
15 info!("Hello World!"); 15 info!("Hello World!");
16 16
17 #[cfg(feature = "stm32wb55rg")] 17 #[cfg(feature = "stm32wb55rg")]