aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-06-12 22:15:44 +0200
committerDario Nieuwenhuis <[email protected]>2022-06-12 22:22:31 +0200
commita8703b75988e1e700af701116464025679d2feb8 (patch)
treef4ec5de70ec05e793a774049e010935ac45853ed
parent6199bdea710cde33e5d5381b6d6abfc8af46df19 (diff)
Run rustfmt.
-rw-r--r--docs/modules/ROOT/examples/basic/src/main.rs13
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs12
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs4
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs13
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs30
-rw-r--r--embassy-boot/boot/src/lib.rs56
-rw-r--r--embassy-boot/nrf/src/lib.rs16
-rw-r--r--embassy-boot/nrf/src/main.rs2
-rw-r--r--embassy-boot/stm32/src/lib.rs4
-rw-r--r--embassy-boot/stm32/src/main.rs2
-rw-r--r--embassy-cortex-m/src/executor.rs4
-rw-r--r--embassy-cortex-m/src/interrupt.rs5
-rw-r--r--embassy-cortex-m/src/peripheral.rs11
-rw-r--r--embassy-embedded-hal/src/adapter.rs19
-rw-r--r--embassy-embedded-hal/src/shared_bus/i2c.rs12
-rw-r--r--embassy-embedded-hal/src/shared_bus/spi.rs5
-rw-r--r--embassy-hal-common/src/drop.rs4
-rw-r--r--embassy-hal-common/src/ratio.rs1
-rw-r--r--embassy-lora/src/stm32wl/mod.rs67
-rw-r--r--embassy-lora/src/sx127x/mod.rs7
-rw-r--r--embassy-lora/src/sx127x/sx127x_lora/mod.rs174
-rw-r--r--embassy-macros/src/lib.rs12
-rw-r--r--embassy-macros/src/macros/cortex_m_interrupt.rs6
-rw-r--r--embassy-macros/src/macros/main.rs13
-rw-r--r--embassy-macros/src/macros/task.rs5
-rw-r--r--embassy-macros/src/util/ctxt.rs5
-rw-r--r--embassy-net/src/device.rs4
-rw-r--r--embassy-net/src/lib.rs4
-rw-r--r--embassy-net/src/packet_pool.rs7
-rw-r--r--embassy-net/src/stack.rs39
-rw-r--r--embassy-net/src/tcp.rs22
-rw-r--r--embassy-nrf/src/buffered_uarte.rs22
-rw-r--r--embassy-nrf/src/chips/nrf52805.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52810.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52811.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52820.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52832.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52833.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52840.rs3
-rw-r--r--embassy-nrf/src/chips/nrf5340_app.rs3
-rw-r--r--embassy-nrf/src/chips/nrf5340_net.rs3
-rw-r--r--embassy-nrf/src/chips/nrf9160.rs3
-rw-r--r--embassy-nrf/src/gpio.rs12
-rw-r--r--embassy-nrf/src/gpiote.rs10
-rw-r--r--embassy-nrf/src/lib.rs9
-rw-r--r--embassy-nrf/src/nvmc.rs11
-rw-r--r--embassy-nrf/src/ppi/dppi.rs19
-rw-r--r--embassy-nrf/src/ppi/mod.rs5
-rw-r--r--embassy-nrf/src/ppi/ppi.rs18
-rw-r--r--embassy-nrf/src/pwm.rs80
-rw-r--r--embassy-nrf/src/qdec.rs28
-rw-r--r--embassy-nrf/src/qspi.rs60
-rw-r--r--embassy-nrf/src/rng.rs14
-rw-r--r--embassy-nrf/src/saadc.rs66
-rw-r--r--embassy-nrf/src/spim.rs27
-rw-r--r--embassy-nrf/src/temp.rs19
-rw-r--r--embassy-nrf/src/time_driver.rs22
-rw-r--r--embassy-nrf/src/timer.rs16
-rw-r--r--embassy-nrf/src/twim.rs88
-rw-r--r--embassy-nrf/src/uarte.rs31
-rw-r--r--embassy-nrf/src/usb.rs59
-rw-r--r--embassy-rp/src/clocks.rs18
-rw-r--r--embassy-rp/src/gpio.rs18
-rw-r--r--embassy-rp/src/interrupt.rs2
-rw-r--r--embassy-rp/src/lib.rs7
-rw-r--r--embassy-rp/src/reset.rs8
-rw-r--r--embassy-rp/src/spi.rs30
-rw-r--r--embassy-rp/src/timer.rs21
-rw-r--r--embassy-rp/src/uart.rs9
-rw-r--r--embassy-stm32/build.rs45
-rw-r--r--embassy-stm32/src/adc/f1.rs8
-rw-r--r--embassy-stm32/src/adc/v2.rs20
-rw-r--r--embassy-stm32/src/adc/v3.rs22
-rw-r--r--embassy-stm32/src/adc/v4.rs17
-rw-r--r--embassy-stm32/src/can/bxcan.rs7
-rw-r--r--embassy-stm32/src/crc/v1.rs3
-rw-r--r--embassy-stm32/src/crc/v2v3.rs3
-rw-r--r--embassy-stm32/src/dac/mod.rs3
-rw-r--r--embassy-stm32/src/dac/v2.rs23
-rw-r--r--embassy-stm32/src/dcmi.rs16
-rw-r--r--embassy-stm32/src/dma/bdma.rs25
-rw-r--r--embassy-stm32/src/dma/dma.rs16
-rw-r--r--embassy-stm32/src/dma/dmamux.rs11
-rw-r--r--embassy-stm32/src/dma/gpdma.rs8
-rw-r--r--embassy-stm32/src/dma/mod.rs22
-rw-r--r--embassy-stm32/src/eth/generic_smi.rs5
-rw-r--r--embassy-stm32/src/eth/v1/mod.rs25
-rw-r--r--embassy-stm32/src/eth/v1/rx_desc.rs12
-rw-r--r--embassy-stm32/src/eth/v1/tx_desc.rs9
-rw-r--r--embassy-stm32/src/eth/v2/descriptors.rs12
-rw-r--r--embassy-stm32/src/eth/v2/mod.rs21
-rw-r--r--embassy-stm32/src/exti.rs19
-rw-r--r--embassy-stm32/src/flash/f3.rs5
-rw-r--r--embassy-stm32/src/flash/f7.rs5
-rw-r--r--embassy-stm32/src/flash/h7.rs8
-rw-r--r--embassy-stm32/src/flash/l.rs11
-rw-r--r--embassy-stm32/src/flash/mod.rs16
-rw-r--r--embassy-stm32/src/fmc/mod.rs3
-rw-r--r--embassy-stm32/src/gpio.rs50
-rw-r--r--embassy-stm32/src/i2c/mod.rs3
-rw-r--r--embassy-stm32/src/i2c/v1.rs14
-rw-r--r--embassy-stm32/src/i2c/v2.rs100
-rw-r--r--embassy-stm32/src/lib.rs14
-rw-r--r--embassy-stm32/src/pwm/mod.rs19
-rw-r--r--embassy-stm32/src/pwm/simple_pwm.rs9
-rw-r--r--embassy-stm32/src/rcc/f0.rs6
-rw-r--r--embassy-stm32/src/rcc/f2.rs4
-rw-r--r--embassy-stm32/src/rcc/f4.rs26
-rw-r--r--embassy-stm32/src/rcc/f7.rs22
-rw-r--r--embassy-stm32/src/rcc/g0.rs3
-rw-r--r--embassy-stm32/src/rcc/g4.rs3
-rw-r--r--embassy-stm32/src/rcc/h7.rs60
-rw-r--r--embassy-stm32/src/rcc/l0.rs3
-rw-r--r--embassy-stm32/src/rcc/l1.rs3
-rw-r--r--embassy-stm32/src/rcc/l4.rs3
-rw-r--r--embassy-stm32/src/rcc/l5.rs6
-rw-r--r--embassy-stm32/src/rcc/mod.rs9
-rw-r--r--embassy-stm32/src/rcc/u5.rs3
-rw-r--r--embassy-stm32/src/rcc/wb.rs3
-rw-r--r--embassy-stm32/src/rng.rs5
-rw-r--r--embassy-stm32/src/sdmmc/mod.rs91
-rw-r--r--embassy-stm32/src/spi/mod.rs64
-rw-r--r--embassy-stm32/src/subghz/mod.rs55
-rw-r--r--embassy-stm32/src/subghz/pa_config.rs35
-rw-r--r--embassy-stm32/src/subghz/packet_params.rs5
-rw-r--r--embassy-stm32/src/subghz/packet_status.rs4
-rw-r--r--embassy-stm32/src/subghz/rf_frequency.rs5
-rw-r--r--embassy-stm32/src/subghz/sleep_cfg.rs4
-rw-r--r--embassy-stm32/src/subghz/status.rs7
-rw-r--r--embassy-stm32/src/subghz/timeout.rs16
-rw-r--r--embassy-stm32/src/time_driver.rs28
-rw-r--r--embassy-stm32/src/timer/mod.rs13
-rw-r--r--embassy-stm32/src/usart/buffered.rs3
-rw-r--r--embassy-stm32/src/usart/mod.rs18
-rw-r--r--embassy-stm32/src/usb/mod.rs1
-rw-r--r--embassy-stm32/src/usb/usb.rs28
-rw-r--r--embassy-stm32/src/usb_otg.rs9
-rw-r--r--embassy-usb-hid/src/lib.rs32
-rw-r--r--embassy-usb-ncm/src/lib.rs10
-rw-r--r--embassy-usb-serial/src/lib.rs16
-rw-r--r--embassy-usb/src/builder.rs54
-rw-r--r--embassy-usb/src/descriptor.rs9
-rw-r--r--embassy-usb/src/driver.rs10
-rw-r--r--embassy-usb/src/lib.rs21
-rw-r--r--embassy/src/blocking_mutex/mod.rs3
-rw-r--r--embassy/src/blocking_mutex/raw.rs20
-rw-r--r--embassy/src/channel/mpmc.rs50
-rw-r--r--embassy/src/executor/arch/wasm.rs8
-rw-r--r--embassy/src/executor/raw/mod.rs9
-rw-r--r--embassy/src/executor/raw/run_queue.rs8
-rw-r--r--embassy/src/executor/raw/timer_queue.rs9
-rw-r--r--embassy/src/executor/spawner.rs1
-rw-r--r--embassy/src/lib.rs5
-rw-r--r--embassy/src/mutex.rs1
-rw-r--r--embassy/src/time/delay.rs3
-rw-r--r--embassy/src/time/driver_std.rs25
-rw-r--r--embassy/src/time/driver_wasm.rs19
-rw-r--r--embassy/src/time/duration.rs22
-rw-r--r--embassy/src/time/instant.rs12
-rw-r--r--embassy/src/time/timer.rs9
-rw-r--r--embassy/src/waitqueue/waker.rs3
-rw-r--r--examples/boot/nrf/src/bin/a.rs14
-rw-r--r--examples/boot/nrf/src/bin/b.rs7
-rw-r--r--examples/boot/stm32f3/src/bin/a.rs10
-rw-r--r--examples/boot/stm32f3/src/bin/b.rs5
-rw-r--r--examples/boot/stm32f7/src/bin/a.rs10
-rw-r--r--examples/boot/stm32f7/src/bin/b.rs5
-rw-r--r--examples/boot/stm32h7/src/bin/a.rs10
-rw-r--r--examples/boot/stm32h7/src/bin/b.rs5
-rw-r--r--examples/boot/stm32l0/src/bin/a.rs10
-rw-r--r--examples/boot/stm32l0/src/bin/b.rs5
-rw-r--r--examples/boot/stm32l1/src/bin/a.rs10
-rw-r--r--examples/boot/stm32l1/src/bin/b.rs5
-rw-r--r--examples/boot/stm32l4/src/bin/a.rs10
-rw-r--r--examples/boot/stm32l4/src/bin/b.rs5
-rw-r--r--examples/boot/stm32wl/src/bin/a.rs10
-rw-r--r--examples/boot/stm32wl/src/bin/b.rs5
-rw-r--r--examples/nrf/src/bin/awaitable_timer.rs7
-rw-r--r--examples/nrf/src/bin/blinky.rs4
-rw-r--r--examples/nrf/src/bin/buffered_uart.rs8
-rw-r--r--examples/nrf/src/bin/channel.rs4
-rw-r--r--examples/nrf/src/bin/channel_sender_receiver.rs4
-rw-r--r--examples/nrf/src/bin/executor_fairness_test.rs5
-rw-r--r--examples/nrf/src/bin/gpiote_channel.rs4
-rw-r--r--examples/nrf/src/bin/gpiote_port.rs4
-rw-r--r--examples/nrf/src/bin/multiprio.rs4
-rw-r--r--examples/nrf/src/bin/mutex.rs4
-rw-r--r--examples/nrf/src/bin/nvmc.rs4
-rw-r--r--examples/nrf/src/bin/ppi.rs12
-rw-r--r--examples/nrf/src/bin/pwm.rs130
-rw-r--r--examples/nrf/src/bin/pwm_double_sequence.rs7
-rw-r--r--examples/nrf/src/bin/pwm_sequence.rs8
-rw-r--r--examples/nrf/src/bin/pwm_sequence_ppi.rs9
-rw-r--r--examples/nrf/src/bin/pwm_sequence_ws2812b.rs7
-rw-r--r--examples/nrf/src/bin/pwm_servo.rs4
-rw-r--r--examples/nrf/src/bin/qdec.rs11
-rw-r--r--examples/nrf/src/bin/qspi.rs7
-rw-r--r--examples/nrf/src/bin/qspi_lowpower.rs8
-rw-r--r--examples/nrf/src/bin/raw_spawn.rs5
-rw-r--r--examples/nrf/src/bin/rng.rs17
-rw-r--r--examples/nrf/src/bin/saadc.rs4
-rw-r--r--examples/nrf/src/bin/saadc_continuous.rs4
-rw-r--r--examples/nrf/src/bin/self_spawn.rs4
-rw-r--r--examples/nrf/src/bin/self_spawn_current_executor.rs4
-rw-r--r--examples/nrf/src/bin/spim.rs7
-rw-r--r--examples/nrf/src/bin/temp.rs7
-rw-r--r--examples/nrf/src/bin/timer.rs4
-rw-r--r--examples/nrf/src/bin/twim.rs4
-rw-r--r--examples/nrf/src/bin/twim_lowpower.rs5
-rw-r--r--examples/nrf/src/bin/uart.rs4
-rw-r--r--examples/nrf/src/bin/uart_idle.rs8
-rw-r--r--examples/nrf/src/bin/uart_split.rs4
-rw-r--r--examples/nrf/src/bin/usb_ethernet.rs14
-rw-r--r--examples/nrf/src/bin/usb_hid_keyboard.rs21
-rw-r--r--examples/nrf/src/bin/usb_hid_mouse.rs9
-rw-r--r--examples/nrf/src/bin/usb_serial.rs13
-rw-r--r--examples/nrf/src/bin/usb_serial_multitask.rs9
-rw-r--r--examples/nrf/src/bin/wdt.rs4
-rw-r--r--examples/rp/src/bin/blinky.rs4
-rw-r--r--examples/rp/src/bin/button.rs4
-rw-r--r--examples/rp/src/bin/spi.rs7
-rw-r--r--examples/rp/src/bin/spi_display.rs12
-rw-r--r--examples/rp/src/bin/uart.rs4
-rw-r--r--examples/std/src/serial_port.rs10
-rw-r--r--examples/std/src/tuntap.rs16
-rw-r--r--examples/stm32f0/src/bin/hello.rs4
-rw-r--r--examples/stm32f1/src/bin/adc.rs4
-rw-r--r--examples/stm32f1/src/bin/blinky.rs4
-rw-r--r--examples/stm32f1/src/bin/hello.rs7
-rw-r--r--examples/stm32f1/src/bin/usb_serial.rs20
-rw-r--r--examples/stm32f2/src/bin/blinky.rs4
-rw-r--r--examples/stm32f2/src/bin/pll.rs16
-rw-r--r--examples/stm32f3/src/bin/blinky.rs4
-rw-r--r--examples/stm32f3/src/bin/button.rs3
-rw-r--r--examples/stm32f3/src/bin/button_events.rs25
-rw-r--r--examples/stm32f3/src/bin/button_exti.rs3
-rw-r--r--examples/stm32f3/src/bin/flash.rs4
-rw-r--r--examples/stm32f3/src/bin/hello.rs7
-rw-r--r--examples/stm32f3/src/bin/multiprio.rs6
-rw-r--r--examples/stm32f3/src/bin/spi_dma.rs8
-rw-r--r--examples/stm32f3/src/bin/usart_dma.rs4
-rw-r--r--examples/stm32f3/src/bin/usb_serial.rs20
-rw-r--r--examples/stm32f4/src/bin/adc.rs4
-rw-r--r--examples/stm32f4/src/bin/blinky.rs3
-rw-r--r--examples/stm32f4/src/bin/button.rs3
-rw-r--r--examples/stm32f4/src/bin/button_exti.rs3
-rw-r--r--examples/stm32f4/src/bin/can.rs4
-rw-r--r--examples/stm32f4/src/bin/hello.rs7
-rw-r--r--examples/stm32f4/src/bin/multiprio.rs6
-rw-r--r--examples/stm32f4/src/bin/sdmmc.rs4
-rw-r--r--examples/stm32f4/src/bin/spi.rs4
-rw-r--r--examples/stm32f4/src/bin/spi_dma.rs8
-rw-r--r--examples/stm32f4/src/bin/usart.rs3
-rw-r--r--examples/stm32f4/src/bin/usart_buffered.rs3
-rw-r--r--examples/stm32f4/src/bin/usart_dma.rs4
-rw-r--r--examples/stm32f7/build.rs3
-rw-r--r--examples/stm32f7/src/bin/adc.rs4
-rw-r--r--examples/stm32f7/src/bin/blinky.rs3
-rw-r--r--examples/stm32f7/src/bin/button.rs3
-rw-r--r--examples/stm32f7/src/bin/button_exti.rs3
-rw-r--r--examples/stm32f7/src/bin/eth.rs7
-rw-r--r--examples/stm32f7/src/bin/flash.rs12
-rw-r--r--examples/stm32f7/src/bin/hello.rs7
-rw-r--r--examples/stm32f7/src/bin/sdmmc.rs4
-rw-r--r--examples/stm32f7/src/bin/usart_dma.rs5
-rw-r--r--examples/stm32g0/src/bin/blinky.rs3
-rw-r--r--examples/stm32g0/src/bin/button.rs3
-rw-r--r--examples/stm32g0/src/bin/button_exti.rs3
-rw-r--r--examples/stm32g4/src/bin/blinky.rs3
-rw-r--r--examples/stm32g4/src/bin/button.rs3
-rw-r--r--examples/stm32g4/src/bin/button_exti.rs3
-rw-r--r--examples/stm32g4/src/bin/pwm.rs6
-rw-r--r--examples/stm32h7/src/bin/adc.rs6
-rw-r--r--examples/stm32h7/src/bin/blinky.rs3
-rw-r--r--examples/stm32h7/src/bin/button_exti.rs3
-rw-r--r--examples/stm32h7/src/bin/camera.rs40
-rw-r--r--examples/stm32h7/src/bin/dac.rs4
-rw-r--r--examples/stm32h7/src/bin/eth.rs7
-rw-r--r--examples/stm32h7/src/bin/flash.rs11
-rw-r--r--examples/stm32h7/src/bin/fmc.rs21
-rw-r--r--examples/stm32h7/src/bin/low_level_timer_api.rs26
-rw-r--r--examples/stm32h7/src/bin/mco.rs3
-rw-r--r--examples/stm32h7/src/bin/pwm.rs6
-rw-r--r--examples/stm32h7/src/bin/rng.rs3
-rw-r--r--examples/stm32h7/src/bin/sdmmc.rs4
-rw-r--r--examples/stm32h7/src/bin/signal.rs7
-rw-r--r--examples/stm32h7/src/bin/spi.rs8
-rw-r--r--examples/stm32h7/src/bin/spi_dma.rs8
-rw-r--r--examples/stm32h7/src/bin/usart.rs6
-rw-r--r--examples/stm32h7/src/bin/usart_dma.rs7
-rw-r--r--examples/stm32h7/src/bin/usart_split.rs11
-rw-r--r--examples/stm32l0/src/bin/blinky.rs4
-rw-r--r--examples/stm32l0/src/bin/button.rs3
-rw-r--r--examples/stm32l0/src/bin/button_exti.rs4
-rw-r--r--examples/stm32l0/src/bin/flash.rs4
-rw-r--r--examples/stm32l0/src/bin/lorawan.rs27
-rw-r--r--examples/stm32l0/src/bin/raw_spawn.rs8
-rw-r--r--examples/stm32l0/src/bin/spi.rs7
-rw-r--r--examples/stm32l0/src/bin/usart_dma.rs14
-rw-r--r--examples/stm32l0/src/bin/usart_irq.rs11
-rw-r--r--examples/stm32l1/src/bin/blinky.rs4
-rw-r--r--examples/stm32l1/src/bin/flash.rs4
-rw-r--r--examples/stm32l1/src/bin/spi.rs7
-rw-r--r--examples/stm32l4/src/bin/adc.rs4
-rw-r--r--examples/stm32l4/src/bin/blinky.rs3
-rw-r--r--examples/stm32l4/src/bin/button.rs3
-rw-r--r--examples/stm32l4/src/bin/button_exti.rs3
-rw-r--r--examples/stm32l4/src/bin/dac.rs4
-rw-r--r--examples/stm32l4/src/bin/i2c.rs7
-rw-r--r--examples/stm32l4/src/bin/i2c_blocking_async.rs7
-rw-r--r--examples/stm32l4/src/bin/i2c_dma.rs17
-rw-r--r--examples/stm32l4/src/bin/rng.rs3
-rw-r--r--examples/stm32l4/src/bin/spi.rs4
-rw-r--r--examples/stm32l4/src/bin/spi_blocking_async.rs4
-rw-r--r--examples/stm32l4/src/bin/spi_dma.rs4
-rw-r--r--examples/stm32l4/src/bin/usart.rs4
-rw-r--r--examples/stm32l4/src/bin/usart_dma.rs4
-rw-r--r--examples/stm32l5/src/bin/button_exti.rs3
-rw-r--r--examples/stm32l5/src/bin/rng.rs3
-rw-r--r--examples/stm32l5/src/bin/usb_ethernet.rs23
-rw-r--r--examples/stm32l5/src/bin/usb_hid_mouse.rs15
-rw-r--r--examples/stm32l5/src/bin/usb_serial.rs21
-rw-r--r--examples/stm32u5/src/bin/blinky.rs4
-rw-r--r--examples/stm32u5/src/bin/boot.rs5
-rw-r--r--examples/stm32wb/src/bin/blinky.rs3
-rw-r--r--examples/stm32wb/src/bin/button_exti.rs3
-rw-r--r--examples/stm32wl/src/bin/blinky.rs3
-rw-r--r--examples/stm32wl/src/bin/button.rs6
-rw-r--r--examples/stm32wl/src/bin/button_exti.rs3
-rw-r--r--examples/stm32wl/src/bin/flash.rs4
-rw-r--r--examples/stm32wl/src/bin/lorawan.rs23
-rw-r--r--examples/stm32wl/src/bin/subghz.rs20
-rw-r--r--examples/wasm/src/lib.rs14
-rw-r--r--stm32-gen-features/src/main.rs3
-rw-r--r--stm32-metapac-gen/src/lib.rs82
-rw-r--r--stm32-metapac-gen/src/main.rs1
-rw-r--r--stm32-metapac/build.rs1
-rw-r--r--stm32-metapac/build_pregenerated.rs5
-rw-r--r--tests/stm32/src/example_common.rs10
-rw-r--r--xtask/src/main.rs10
340 files changed, 1318 insertions, 3012 deletions
diff --git a/docs/modules/ROOT/examples/basic/src/main.rs b/docs/modules/ROOT/examples/basic/src/main.rs
index 8394f73b7..461741fd7 100644
--- a/docs/modules/ROOT/examples/basic/src/main.rs
+++ b/docs/modules/ROOT/examples/basic/src/main.rs
@@ -2,18 +2,13 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9
10use embassy::executor::Spawner; 6use embassy::executor::Spawner;
11use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
12use embassy_nrf::{ 8use embassy_nrf::gpio::{Level, Output, OutputDrive};
13 gpio::{Level, Output, OutputDrive}, 9use embassy_nrf::peripherals::P0_13;
14 peripherals::P0_13, 10use embassy_nrf::Peripherals;
15 Peripherals, 11use {defmt_rtt as _, panic_probe as _}; // global logger
16};
17 12
18#[embassy::task] 13#[embassy::task]
19async fn blinker(mut led: Output<'static, P0_13>, interval: Duration) { 14async fn blinker(mut led: Output<'static, P0_13>, interval: Duration) {
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 35726be64..56bc698da 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,15 +2,11 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _;
6use panic_probe as _;
7
8use embassy::executor::Spawner; 5use embassy::executor::Spawner;
9use embassy_stm32::{ 6use embassy_stm32::exti::ExtiInput;
10 exti::ExtiInput, 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
11 gpio::{Input, Level, Output, Pull, Speed}, 8use embassy_stm32::Peripherals;
12 Peripherals, 9use {defmt_rtt as _, panic_probe as _};
13};
14 10
15#[embassy::main] 11#[embassy::main]
16async fn main(_s: Spawner, p: Peripherals) { 12async fn main(_s: Spawner, p: Peripherals) {
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs
index 2064ea616..d0c9f4907 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs
+++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs
@@ -2,10 +2,8 @@
2#![no_main] 2#![no_main]
3 3
4use cortex_m_rt::entry; 4use cortex_m_rt::entry;
5use defmt_rtt as _;
6use panic_probe as _;
7
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 5use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
6use {defmt_rtt as _, panic_probe as _};
9 7
10#[entry] 8#[entry]
11fn main() -> ! { 9fn main() -> ! {
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs
index 6a75384c4..743d0c342 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs
+++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs
@@ -1,18 +1,15 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3 3
4use defmt_rtt as _;
5use panic_probe as _;
6
7use core::cell::RefCell; 4use core::cell::RefCell;
5
8use cortex_m::interrupt::Mutex; 6use cortex_m::interrupt::Mutex;
9use cortex_m::peripheral::NVIC; 7use cortex_m::peripheral::NVIC;
10use cortex_m_rt::entry; 8use cortex_m_rt::entry;
11use embassy_stm32::{ 9use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed};
12 gpio::{Input, Level, Output, Pin, Pull, Speed}, 10use embassy_stm32::peripherals::{PB14, PC13};
13 interrupt, pac, 11use embassy_stm32::{interrupt, pac};
14 peripherals::{PB14, PC13}, 12use {defmt_rtt as _, panic_probe as _};
15};
16 13
17static BUTTON: Mutex<RefCell<Option<Input<'static, PC13>>>> = Mutex::new(RefCell::new(None)); 14static BUTTON: Mutex<RefCell<Option<Input<'static, PC13>>>> = Mutex::new(RefCell::new(None));
18static LED: Mutex<RefCell<Option<Output<'static, PB14>>>> = Mutex::new(RefCell::new(None)); 15static LED: Mutex<RefCell<Option<Output<'static, PB14>>>> = Mutex::new(RefCell::new(None));
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs
index 239eac188..990d46cb6 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs
+++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs
@@ -1,12 +1,8 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3 3
4use defmt_rtt as _;
5use panic_probe as _;
6
7use stm32_metapac as pac;
8
9use pac::gpio::vals; 4use pac::gpio::vals;
5use {defmt_rtt as _, panic_probe as _, stm32_metapac as pac};
10 6
11#[cortex_m_rt::entry] 7#[cortex_m_rt::entry]
12fn main() -> ! { 8fn main() -> ! {
@@ -30,30 +26,18 @@ fn main() -> ! {
30 let gpioc = pac::GPIOC; 26 let gpioc = pac::GPIOC;
31 const BUTTON_PIN: usize = 13; 27 const BUTTON_PIN: usize = 13;
32 unsafe { 28 unsafe {
33 gpioc 29 gpioc.pupdr().modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP));
34 .pupdr() 30 gpioc.otyper().modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL));
35 .modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP)); 31 gpioc.moder().modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT));
36 gpioc
37 .otyper()
38 .modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL));
39 gpioc
40 .moder()
41 .modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT));
42 } 32 }
43 33
44 // Setup LED 34 // Setup LED
45 let gpiob = pac::GPIOB; 35 let gpiob = pac::GPIOB;
46 const LED_PIN: usize = 14; 36 const LED_PIN: usize = 14;
47 unsafe { 37 unsafe {
48 gpiob 38 gpiob.pupdr().modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING));
49 .pupdr() 39 gpiob.otyper().modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL));
50 .modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING)); 40 gpiob.moder().modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT));
51 gpiob
52 .otyper()
53 .modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL));
54 gpiob
55 .moder()
56 .modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT));
57 } 41 }
58 42
59 // Main loop 43 // Main loop
diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs
index 87bb973a7..b18c88a6b 100644
--- a/embassy-boot/boot/src/lib.rs
+++ b/embassy-boot/boot/src/lib.rs
@@ -202,8 +202,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> {
202 // Ensure we have enough progress pages to store copy progress 202 // Ensure we have enough progress pages to store copy progress
203 assert!( 203 assert!(
204 self.active.len() / PAGE_SIZE 204 self.active.len() / PAGE_SIZE
205 <= (self.state.len() 205 <= (self.state.len() - <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE)
206 - <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE)
207 / <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE 206 / <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE
208 ); 207 );
209 208
@@ -226,15 +225,12 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> {
226 // Overwrite magic and reset progress 225 // Overwrite magic and reset progress
227 let fstate = p.state().flash(); 226 let fstate = p.state().flash();
228 let aligned = Aligned( 227 let aligned = Aligned(
229 [!P::STATE::ERASE_VALUE; 228 [!P::STATE::ERASE_VALUE; <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE],
230 <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE],
231 ); 229 );
232 fstate.write(self.state.from as u32, &aligned.0)?; 230 fstate.write(self.state.from as u32, &aligned.0)?;
233 fstate.erase(self.state.from as u32, self.state.to as u32)?; 231 fstate.erase(self.state.from as u32, self.state.to as u32)?;
234 let aligned = Aligned( 232 let aligned =
235 [BOOT_MAGIC; 233 Aligned([BOOT_MAGIC; <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE]);
236 <<P as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE],
237 );
238 fstate.write(self.state.from as u32, &aligned.0)?; 234 fstate.write(self.state.from as u32, &aligned.0)?;
239 } 235 }
240 } 236 }
@@ -262,10 +258,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> {
262 let flash = p.flash(); 258 let flash = p.flash();
263 let mut aligned = Aligned([!P::ERASE_VALUE; P::FLASH::WRITE_SIZE]); 259 let mut aligned = Aligned([!P::ERASE_VALUE; P::FLASH::WRITE_SIZE]);
264 for i in 0..max_index { 260 for i in 0..max_index {
265 flash.read( 261 flash.read((self.state.from + write_size + i * write_size) as u32, &mut aligned.0)?;
266 (self.state.from + write_size + i * write_size) as u32,
267 &mut aligned.0,
268 )?;
269 if aligned.0 == [P::ERASE_VALUE; P::FLASH::WRITE_SIZE] { 262 if aligned.0 == [P::ERASE_VALUE; P::FLASH::WRITE_SIZE] {
270 return Ok(i); 263 return Ok(i);
271 } 264 }
@@ -311,9 +304,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> {
311 offset += chunk.len(); 304 offset += chunk.len();
312 } 305 }
313 306
314 p.active() 307 p.active().flash().erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?;
315 .flash()
316 .erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?;
317 308
318 let mut offset = to_page; 309 let mut offset = to_page;
319 for chunk in buf.chunks(P::ACTIVE::BLOCK_SIZE) { 310 for chunk in buf.chunks(P::ACTIVE::BLOCK_SIZE) {
@@ -343,9 +334,7 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> {
343 offset += chunk.len(); 334 offset += chunk.len();
344 } 335 }
345 336
346 p.dfu() 337 p.dfu().flash().erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?;
347 .flash()
348 .erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?;
349 338
350 let mut offset = to_page; 339 let mut offset = to_page;
351 for chunk in buf.chunks(P::DFU::BLOCK_SIZE) { 340 for chunk in buf.chunks(P::DFU::BLOCK_SIZE) {
@@ -609,9 +598,7 @@ impl FirmwareUpdater {
609 aligned[i] = 0; 598 aligned[i] = 0;
610 } 599 }
611 flash.write(self.state.from as u32, aligned).await?; 600 flash.write(self.state.from as u32, aligned).await?;
612 flash 601 flash.erase(self.state.from as u32, self.state.to as u32).await?;
613 .erase(self.state.from as u32, self.state.to as u32)
614 .await?;
615 602
616 for i in 0..aligned.len() { 603 for i in 0..aligned.len() {
617 aligned[i] = magic; 604 aligned[i] = magic;
@@ -677,13 +664,15 @@ impl FirmwareUpdater {
677 664
678#[cfg(test)] 665#[cfg(test)]
679mod tests { 666mod tests {
680 use super::*;
681 use core::convert::Infallible; 667 use core::convert::Infallible;
682 use core::future::Future; 668 use core::future::Future;
669
683 use embedded_storage::nor_flash::ErrorType; 670 use embedded_storage::nor_flash::ErrorType;
684 use embedded_storage_async::nor_flash::AsyncReadNorFlash; 671 use embedded_storage_async::nor_flash::AsyncReadNorFlash;
685 use futures::executor::block_on; 672 use futures::executor::block_on;
686 673
674 use super::*;
675
687 /* 676 /*
688 #[test] 677 #[test]
689 fn test_bad_magic() { 678 fn test_bad_magic() {
@@ -810,11 +799,7 @@ mod tests {
810 assert_eq!( 799 assert_eq!(
811 State::Swap, 800 State::Swap,
812 bootloader 801 bootloader
813 .prepare_boot(&mut MultiFlashProvider::new( 802 .prepare_boot(&mut MultiFlashProvider::new(&mut active, &mut state, &mut dfu,))
814 &mut active,
815 &mut state,
816 &mut dfu,
817 ))
818 .unwrap() 803 .unwrap()
819 ); 804 );
820 805
@@ -858,11 +843,7 @@ mod tests {
858 assert_eq!( 843 assert_eq!(
859 State::Swap, 844 State::Swap,
860 bootloader 845 bootloader
861 .prepare_boot(&mut MultiFlashProvider::new( 846 .prepare_boot(&mut MultiFlashProvider::new(&mut active, &mut state, &mut dfu,))
862 &mut active,
863 &mut state,
864 &mut dfu,
865 ))
866 .unwrap() 847 .unwrap()
867 ); 848 );
868 849
@@ -876,9 +857,7 @@ mod tests {
876 } 857 }
877 } 858 }
878 859
879 struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>( 860 struct MemFlash<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize>([u8; SIZE]);
880 [u8; SIZE],
881 );
882 861
883 impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash 862 impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> NorFlash
884 for MemFlash<SIZE, ERASE_SIZE, WRITE_SIZE> 863 for MemFlash<SIZE, ERASE_SIZE, WRITE_SIZE>
@@ -889,12 +868,7 @@ mod tests {
889 let from = from as usize; 868 let from = from as usize;
890 let to = to as usize; 869 let to = to as usize;
891 assert!(from % ERASE_SIZE == 0); 870 assert!(from % ERASE_SIZE == 0);
892 assert!( 871 assert!(to % ERASE_SIZE == 0, "To: {}, erase size: {}", to, ERASE_SIZE);
893 to % ERASE_SIZE == 0,
894 "To: {}, erase size: {}",
895 to,
896 ERASE_SIZE
897 );
898 for i in from..to { 872 for i in from..to {
899 self.0[i] = 0xFF; 873 self.0[i] = 0xFF;
900 } 874 }
diff --git a/embassy-boot/nrf/src/lib.rs b/embassy-boot/nrf/src/lib.rs
index 9f891887c..2d6b837cb 100644
--- a/embassy-boot/nrf/src/lib.rs
+++ b/embassy-boot/nrf/src/lib.rs
@@ -6,14 +6,10 @@
6 6
7mod fmt; 7mod fmt;
8 8
9pub use embassy_boot::{ 9pub use embassy_boot::{FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider};
10 FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, 10use embassy_nrf::nvmc::{Nvmc, PAGE_SIZE};
11}; 11use embassy_nrf::peripherals::WDT;
12use embassy_nrf::{ 12use embassy_nrf::wdt;
13 nvmc::{Nvmc, PAGE_SIZE},
14 peripherals::WDT,
15 wdt,
16};
17use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; 13use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash};
18 14
19pub struct BootLoader { 15pub struct BootLoader {
@@ -95,9 +91,7 @@ impl BootLoader {
95 let mut cmd = mbr::sd_mbr_command_t { 91 let mut cmd = mbr::sd_mbr_command_t {
96 command: mbr::NRF_MBR_COMMANDS_SD_MBR_COMMAND_IRQ_FORWARD_ADDRESS_SET, 92 command: mbr::NRF_MBR_COMMANDS_SD_MBR_COMMAND_IRQ_FORWARD_ADDRESS_SET,
97 params: mbr::sd_mbr_command_t__bindgen_ty_1 { 93 params: mbr::sd_mbr_command_t__bindgen_ty_1 {
98 irq_forward_address_set: mbr::sd_mbr_command_irq_forward_address_set_t { 94 irq_forward_address_set: mbr::sd_mbr_command_irq_forward_address_set_t { address: addr },
99 address: addr,
100 },
101 }, 95 },
102 }; 96 };
103 let ret = mbr::sd_mbr_command(&mut cmd); 97 let ret = mbr::sd_mbr_command(&mut cmd);
diff --git a/embassy-boot/nrf/src/main.rs b/embassy-boot/nrf/src/main.rs
index 0ccd3774d..bc7e0755f 100644
--- a/embassy-boot/nrf/src/main.rs
+++ b/embassy-boot/nrf/src/main.rs
@@ -2,10 +2,8 @@
2#![no_main] 2#![no_main]
3 3
4use cortex_m_rt::{entry, exception}; 4use cortex_m_rt::{entry, exception};
5
6#[cfg(feature = "defmt")] 5#[cfg(feature = "defmt")]
7use defmt_rtt as _; 6use defmt_rtt as _;
8
9use embassy_boot_nrf::*; 7use embassy_boot_nrf::*;
10use embassy_nrf::nvmc::Nvmc; 8use embassy_nrf::nvmc::Nvmc;
11 9
diff --git a/embassy-boot/stm32/src/lib.rs b/embassy-boot/stm32/src/lib.rs
index 8c6e65507..5a4f2d058 100644
--- a/embassy-boot/stm32/src/lib.rs
+++ b/embassy-boot/stm32/src/lib.rs
@@ -6,9 +6,7 @@
6 6
7mod fmt; 7mod fmt;
8 8
9pub use embassy_boot::{ 9pub use embassy_boot::{FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, State};
10 FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, State,
11};
12use embedded_storage::nor_flash::NorFlash; 10use embedded_storage::nor_flash::NorFlash;
13 11
14pub struct BootLoader<const PAGE_SIZE: usize> { 12pub struct BootLoader<const PAGE_SIZE: usize> {
diff --git a/embassy-boot/stm32/src/main.rs b/embassy-boot/stm32/src/main.rs
index d79b14c67..45c511ced 100644
--- a/embassy-boot/stm32/src/main.rs
+++ b/embassy-boot/stm32/src/main.rs
@@ -2,10 +2,8 @@
2#![no_main] 2#![no_main]
3 3
4use cortex_m_rt::{entry, exception}; 4use cortex_m_rt::{entry, exception};
5
6#[cfg(feature = "defmt")] 5#[cfg(feature = "defmt")]
7use defmt_rtt as _; 6use defmt_rtt as _;
8
9use embassy_boot_stm32::*; 7use embassy_boot_stm32::*;
10use embassy_stm32::flash::{Flash, ERASE_SIZE}; 8use embassy_stm32::flash::{Flash, ERASE_SIZE};
11 9
diff --git a/embassy-cortex-m/src/executor.rs b/embassy-cortex-m/src/executor.rs
index 63a1519cf..34f3ec236 100644
--- a/embassy-cortex-m/src/executor.rs
+++ b/embassy-cortex-m/src/executor.rs
@@ -1,9 +1,9 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use crate::interrupt::{Interrupt, InterruptExt}; 3pub use embassy::executor::Executor;
4use embassy::executor::{raw, SendSpawner}; 4use embassy::executor::{raw, SendSpawner};
5 5
6pub use embassy::executor::Executor; 6use crate::interrupt::{Interrupt, InterruptExt};
7 7
8fn pend_by_number(n: u16) { 8fn pend_by_number(n: u16) {
9 #[derive(Clone, Copy)] 9 #[derive(Clone, Copy)]
diff --git a/embassy-cortex-m/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs
index df2aad0ec..72686b402 100644
--- a/embassy-cortex-m/src/interrupt.rs
+++ b/embassy-cortex-m/src/interrupt.rs
@@ -1,9 +1,8 @@
1use core::{mem, ptr};
2
1use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; 3use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering};
2use core::mem;
3use core::ptr;
4use cortex_m::peripheral::NVIC; 4use cortex_m::peripheral::NVIC;
5use embassy_hal_common::Unborrow; 5use embassy_hal_common::Unborrow;
6
7pub use embassy_macros::cortex_m_interrupt_take as take; 6pub use embassy_macros::cortex_m_interrupt_take as take;
8 7
9/// Implementation detail, do not use outside embassy crates. 8/// Implementation detail, do not use outside embassy crates.
diff --git a/embassy-cortex-m/src/peripheral.rs b/embassy-cortex-m/src/peripheral.rs
index 40277691c..5ff690831 100644
--- a/embassy-cortex-m/src/peripheral.rs
+++ b/embassy-cortex-m/src/peripheral.rs
@@ -1,5 +1,6 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2use core::mem::MaybeUninit; 2use core::mem::MaybeUninit;
3
3use cortex_m::peripheral::scb::VectActive; 4use cortex_m::peripheral::scb::VectActive;
4use cortex_m::peripheral::{NVIC, SCB}; 5use cortex_m::peripheral::{NVIC, SCB};
5 6
@@ -53,13 +54,11 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> {
53 /// Create a new `PeripheralMutex` wrapping `irq`, with `init` initializing the initial state. 54 /// Create a new `PeripheralMutex` wrapping `irq`, with `init` initializing the initial state.
54 /// 55 ///
55 /// Registers `on_interrupt` as the `irq`'s handler, and enables it. 56 /// Registers `on_interrupt` as the `irq`'s handler, and enables it.
56 pub fn new( 57 pub fn new(irq: S::Interrupt, storage: &'a mut StateStorage<S>, init: impl FnOnce() -> S) -> Self {
57 irq: S::Interrupt,
58 storage: &'a mut StateStorage<S>,
59 init: impl FnOnce() -> S,
60 ) -> Self {
61 if can_be_preempted(&irq) { 58 if can_be_preempted(&irq) {
62 panic!("`PeripheralMutex` cannot be created in an interrupt with higher priority than the interrupt it wraps"); 59 panic!(
60 "`PeripheralMutex` cannot be created in an interrupt with higher priority than the interrupt it wraps"
61 );
63 } 62 }
64 63
65 let state_ptr = storage.0.as_mut_ptr(); 64 let state_ptr = storage.0.as_mut_ptr();
diff --git a/embassy-embedded-hal/src/adapter.rs b/embassy-embedded-hal/src/adapter.rs
index 033efb7ef..7d25d89fc 100644
--- a/embassy-embedded-hal/src/adapter.rs
+++ b/embassy-embedded-hal/src/adapter.rs
@@ -1,6 +1,6 @@
1use core::future::Future; 1use core::future::Future;
2use embedded_hal_02::blocking; 2
3use embedded_hal_02::serial; 3use embedded_hal_02::{blocking, serial};
4 4
5/// BlockingAsync is a wrapper that implements async traits using blocking peripherals. This allows 5/// BlockingAsync is a wrapper that implements async traits using blocking peripherals. This allows
6/// driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations. 6/// driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations.
@@ -25,9 +25,7 @@ impl<T> BlockingAsync<T> {
25impl<T, E> embedded_hal_1::i2c::ErrorType for BlockingAsync<T> 25impl<T, E> embedded_hal_1::i2c::ErrorType for BlockingAsync<T>
26where 26where
27 E: embedded_hal_1::i2c::Error + 'static, 27 E: embedded_hal_1::i2c::Error + 'static,
28 T: blocking::i2c::WriteRead<Error = E> 28 T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>,
29 + blocking::i2c::Read<Error = E>
30 + blocking::i2c::Write<Error = E>,
31{ 29{
32 type Error = E; 30 type Error = E;
33} 31}
@@ -35,9 +33,7 @@ where
35impl<T, E> embedded_hal_async::i2c::I2c for BlockingAsync<T> 33impl<T, E> embedded_hal_async::i2c::I2c for BlockingAsync<T>
36where 34where
37 E: embedded_hal_1::i2c::Error + 'static, 35 E: embedded_hal_1::i2c::Error + 'static,
38 T: blocking::i2c::WriteRead<Error = E> 36 T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>,
39 + blocking::i2c::Read<Error = E>
40 + blocking::i2c::Write<Error = E>,
41{ 37{
42 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; 38 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
43 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; 39 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
@@ -51,12 +47,7 @@ where
51 async move { self.wrapped.write(address, bytes) } 47 async move { self.wrapped.write(address, bytes) }
52 } 48 }
53 49
54 fn write_read<'a>( 50 fn write_read<'a>(&'a mut self, address: u8, bytes: &'a [u8], buffer: &'a mut [u8]) -> Self::WriteReadFuture<'a> {
55 &'a mut self,
56 address: u8,
57 bytes: &'a [u8],
58 buffer: &'a mut [u8],
59 ) -> Self::WriteReadFuture<'a> {
60 async move { self.wrapped.write_read(address, bytes, buffer) } 51 async move { self.wrapped.write_read(address, bytes, buffer) }
61 } 52 }
62 53
diff --git a/embassy-embedded-hal/src/shared_bus/i2c.rs b/embassy-embedded-hal/src/shared_bus/i2c.rs
index 5a180e897..e8131288a 100644
--- a/embassy-embedded-hal/src/shared_bus/i2c.rs
+++ b/embassy-embedded-hal/src/shared_bus/i2c.rs
@@ -22,7 +22,9 @@
22//! let i2c_dev2 = I2cBusDevice::new(i2c_bus); 22//! let i2c_dev2 = I2cBusDevice::new(i2c_bus);
23//! let mpu = Mpu6050::new(i2c_dev2); 23//! let mpu = Mpu6050::new(i2c_dev2);
24//! ``` 24//! ```
25use core::{fmt::Debug, future::Future}; 25use core::fmt::Debug;
26use core::future::Future;
27
26use embassy::blocking_mutex::raw::RawMutex; 28use embassy::blocking_mutex::raw::RawMutex;
27use embassy::mutex::Mutex; 29use embassy::mutex::Mutex;
28use embedded_hal_async::i2c; 30use embedded_hal_async::i2c;
@@ -70,9 +72,7 @@ where
70 fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { 72 fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
71 async move { 73 async move {
72 let mut bus = self.bus.lock().await; 74 let mut bus = self.bus.lock().await;
73 bus.read(address, buffer) 75 bus.read(address, buffer).await.map_err(I2cBusDeviceError::I2c)?;
74 .await
75 .map_err(I2cBusDeviceError::I2c)?;
76 Ok(()) 76 Ok(())
77 } 77 }
78 } 78 }
@@ -82,9 +82,7 @@ where
82 fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { 82 fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> {
83 async move { 83 async move {
84 let mut bus = self.bus.lock().await; 84 let mut bus = self.bus.lock().await;
85 bus.write(address, bytes) 85 bus.write(address, bytes).await.map_err(I2cBusDeviceError::I2c)?;
86 .await
87 .map_err(I2cBusDeviceError::I2c)?;
88 Ok(()) 86 Ok(())
89 } 87 }
90 } 88 }
diff --git a/embassy-embedded-hal/src/shared_bus/spi.rs b/embassy-embedded-hal/src/shared_bus/spi.rs
index 3ec064ba7..fd4b6d565 100644
--- a/embassy-embedded-hal/src/shared_bus/spi.rs
+++ b/embassy-embedded-hal/src/shared_bus/spi.rs
@@ -25,10 +25,11 @@
25//! let spi_dev2 = SpiBusDevice::new(spi_bus, cs_pin2); 25//! let spi_dev2 = SpiBusDevice::new(spi_bus, cs_pin2);
26//! let display2 = ST7735::new(spi_dev2, dc2, rst2, Default::default(), 160, 128); 26//! let display2 = ST7735::new(spi_dev2, dc2, rst2, Default::default(), 160, 128);
27//! ``` 27//! ```
28use core::{fmt::Debug, future::Future}; 28use core::fmt::Debug;
29use core::future::Future;
30
29use embassy::blocking_mutex::raw::RawMutex; 31use embassy::blocking_mutex::raw::RawMutex;
30use embassy::mutex::Mutex; 32use embassy::mutex::Mutex;
31
32use embedded_hal_1::digital::blocking::OutputPin; 33use embedded_hal_1::digital::blocking::OutputPin;
33use embedded_hal_1::spi::ErrorType; 34use embedded_hal_1::spi::ErrorType;
34use embedded_hal_async::spi; 35use embedded_hal_async::spi;
diff --git a/embassy-hal-common/src/drop.rs b/embassy-hal-common/src/drop.rs
index 3a90dd509..6ef716f99 100644
--- a/embassy-hal-common/src/drop.rs
+++ b/embassy-hal-common/src/drop.rs
@@ -7,9 +7,7 @@ pub struct OnDrop<F: FnOnce()> {
7 7
8impl<F: FnOnce()> OnDrop<F> { 8impl<F: FnOnce()> OnDrop<F> {
9 pub fn new(f: F) -> Self { 9 pub fn new(f: F) -> Self {
10 Self { 10 Self { f: MaybeUninit::new(f) }
11 f: MaybeUninit::new(f),
12 }
13 } 11 }
14 12
15 pub fn defuse(self) { 13 pub fn defuse(self) {
diff --git a/embassy-hal-common/src/ratio.rs b/embassy-hal-common/src/ratio.rs
index ce7e4b1b9..9a8808a33 100644
--- a/embassy-hal-common/src/ratio.rs
+++ b/embassy-hal-common/src/ratio.rs
@@ -1,4 +1,5 @@
1use core::ops::{Add, Div, Mul}; 1use core::ops::{Add, Div, Mul};
2
2use num_traits::{CheckedAdd, CheckedDiv, CheckedMul}; 3use num_traits::{CheckedAdd, CheckedDiv, CheckedMul};
3 4
4/// Represents the ratio between two numbers. 5/// Represents the ratio between two numbers.
diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs
index b5ce278dc..5f3dc17a7 100644
--- a/embassy-lora/src/stm32wl/mod.rs
+++ b/embassy-lora/src/stm32wl/mod.rs
@@ -1,25 +1,20 @@
1//! A radio driver integration for the radio found on STM32WL family devices. 1//! A radio driver integration for the radio found on STM32WL family devices.
2use core::future::Future; 2use core::future::Future;
3use core::mem::MaybeUninit; 3use core::mem::MaybeUninit;
4
4use embassy::channel::signal::Signal; 5use embassy::channel::signal::Signal;
5use embassy_hal_common::unborrow; 6use embassy_hal_common::unborrow;
6use embassy_stm32::interrupt::InterruptExt; 7use embassy_stm32::dma::NoDma;
7use embassy_stm32::Unborrow; 8use embassy_stm32::gpio::{AnyPin, Output};
8use embassy_stm32::{ 9use embassy_stm32::interrupt::{InterruptExt, SUBGHZ_RADIO};
9 dma::NoDma, 10use embassy_stm32::subghz::{
10 gpio::{AnyPin, Output}, 11 CalibrateImage, CfgIrq, CodingRate, HeaderType, Irq, LoRaBandwidth, LoRaModParams, LoRaPacketParams, LoRaSyncWord,
11 interrupt::SUBGHZ_RADIO, 12 Ocp, PaConfig, PaSel, PacketType, RampTime, RegMode, RfFreq, SpreadingFactor as SF, StandbyClk, Status, SubGhz,
12 subghz::{ 13 TcxoMode, TcxoTrim, Timeout, TxParams,
13 CalibrateImage, CfgIrq, CodingRate, HeaderType, Irq, LoRaBandwidth, LoRaModParams,
14 LoRaPacketParams, LoRaSyncWord, Ocp, PaConfig, PaSel, PacketType, RampTime, RegMode,
15 RfFreq, SpreadingFactor as SF, StandbyClk, Status, SubGhz, TcxoMode, TcxoTrim, Timeout,
16 TxParams,
17 },
18};
19use lorawan_device::async_device::{
20 radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig},
21 Timings,
22}; 14};
15use embassy_stm32::Unborrow;
16use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig};
17use lorawan_device::async_device::Timings;
23 18
24#[derive(Debug, Copy, Clone)] 19#[derive(Debug, Copy, Clone)]
25#[cfg_attr(feature = "defmt", derive(defmt::Format))] 20#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -98,9 +93,7 @@ impl<'a> StateInner<'a> {
98 self.radio.set_standby(StandbyClk::Rc)?; 93 self.radio.set_standby(StandbyClk::Rc)?;
99 let tcxo_mode = TcxoMode::new() 94 let tcxo_mode = TcxoMode::new()
100 .set_txco_trim(TcxoTrim::Volts1pt7) 95 .set_txco_trim(TcxoTrim::Volts1pt7)
101 .set_timeout(Timeout::from_duration_sat( 96 .set_timeout(Timeout::from_duration_sat(core::time::Duration::from_millis(40)));
102 core::time::Duration::from_millis(40),
103 ));
104 97
105 self.radio.set_tcxo_mode(&tcxo_mode)?; 98 self.radio.set_tcxo_mode(&tcxo_mode)?;
106 self.radio.set_regulator_mode(RegMode::Ldo)?; 99 self.radio.set_regulator_mode(RegMode::Ldo)?;
@@ -109,21 +102,14 @@ impl<'a> StateInner<'a> {
109 102
110 self.radio.set_buffer_base_address(0, 0)?; 103 self.radio.set_buffer_base_address(0, 0)?;
111 104
112 self.radio.set_pa_config( 105 self.radio
113 &PaConfig::new() 106 .set_pa_config(&PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp))?;
114 .set_pa_duty_cycle(0x1)
115 .set_hp_max(0x0)
116 .set_pa(PaSel::Lp),
117 )?;
118 107
119 self.radio.set_pa_ocp(Ocp::Max140m)?; 108 self.radio.set_pa_ocp(Ocp::Max140m)?;
120 109
121 // let tx_params = TxParams::LP_14.set_ramp_time(RampTime::Micros40); 110 // let tx_params = TxParams::LP_14.set_ramp_time(RampTime::Micros40);
122 self.radio.set_tx_params( 111 self.radio
123 &TxParams::new() 112 .set_tx_params(&TxParams::new().set_ramp_time(RampTime::Micros40).set_power(0x0A))?;
124 .set_ramp_time(RampTime::Micros40)
125 .set_power(0x0A),
126 )?;
127 113
128 self.radio.set_packet_type(PacketType::LoRa)?; 114 self.radio.set_packet_type(PacketType::LoRa)?;
129 self.radio.set_lora_sync_word(LoRaSyncWord::Public)?; 115 self.radio.set_lora_sync_word(LoRaSyncWord::Public)?;
@@ -193,19 +179,14 @@ impl<'a> StateInner<'a> {
193 179
194 /// Perform a radio receive operation with the radio config and receive buffer. The receive buffer must 180 /// Perform a radio receive operation with the radio config and receive buffer. The receive buffer must
195 /// be able to hold a single LoRaWAN packet. 181 /// be able to hold a single LoRaWAN packet.
196 async fn do_rx( 182 async fn do_rx(&mut self, config: RfConfig, buf: &mut [u8]) -> Result<(usize, RxQuality), RadioError> {
197 &mut self,
198 config: RfConfig,
199 buf: &mut [u8],
200 ) -> Result<(usize, RxQuality), RadioError> {
201 assert!(buf.len() >= 255); 183 assert!(buf.len() >= 255);
202 trace!("RX START"); 184 trace!("RX START");
203 // trace!("Starting RX: {}", config); 185 // trace!("Starting RX: {}", config);
204 self.switch.set_rx(); 186 self.switch.set_rx();
205 self.configure()?; 187 self.configure()?;
206 188
207 self.radio 189 self.radio.set_rf_frequency(&RfFreq::from_frequency(config.frequency))?;
208 .set_rf_frequency(&RfFreq::from_frequency(config.frequency))?;
209 190
210 let mod_params = LoRaModParams::new() 191 let mod_params = LoRaModParams::new()
211 .set_sf(convert_spreading_factor(config.spreading_factor)) 192 .set_sf(convert_spreading_factor(config.spreading_factor))
@@ -315,16 +296,8 @@ pub struct RadioSwitch<'a> {
315} 296}
316 297
317impl<'a> RadioSwitch<'a> { 298impl<'a> RadioSwitch<'a> {
318 pub fn new( 299 pub fn new(ctrl1: Output<'a, AnyPin>, ctrl2: Output<'a, AnyPin>, ctrl3: Output<'a, AnyPin>) -> Self {
319 ctrl1: Output<'a, AnyPin>, 300 Self { ctrl1, ctrl2, ctrl3 }
320 ctrl2: Output<'a, AnyPin>,
321 ctrl3: Output<'a, AnyPin>,
322 ) -> Self {
323 Self {
324 ctrl1,
325 ctrl2,
326 ctrl3,
327 }
328 } 301 }
329 302
330 pub(crate) fn set_rx(&mut self) { 303 pub(crate) fn set_rx(&mut self) {
diff --git a/embassy-lora/src/sx127x/mod.rs b/embassy-lora/src/sx127x/mod.rs
index c70f33582..f47a9eb55 100644
--- a/embassy-lora/src/sx127x/mod.rs
+++ b/embassy-lora/src/sx127x/mod.rs
@@ -1,11 +1,10 @@
1use core::future::Future; 1use core::future::Future;
2
2use embedded_hal::digital::v2::OutputPin; 3use embedded_hal::digital::v2::OutputPin;
3use embedded_hal_async::digital::Wait; 4use embedded_hal_async::digital::Wait;
4use embedded_hal_async::spi::*; 5use embedded_hal_async::spi::*;
5use lorawan_device::async_device::{ 6use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig};
6 radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}, 7use lorawan_device::async_device::Timings;
7 Timings,
8};
9 8
10mod sx127x_lora; 9mod sx127x_lora;
11use sx127x_lora::{Error as RadioError, LoRa, RadioMode, IRQ}; 10use sx127x_lora::{Error as RadioError, LoRa, RadioMode, IRQ};
diff --git a/embassy-lora/src/sx127x/sx127x_lora/mod.rs b/embassy-lora/src/sx127x/sx127x_lora/mod.rs
index 62eaf0a95..8b937ec2f 100644
--- a/embassy-lora/src/sx127x/sx127x_lora/mod.rs
+++ b/embassy-lora/src/sx127x/sx127x_lora/mod.rs
@@ -11,9 +11,8 @@ use embedded_hal::digital::v2::OutputPin;
11use embedded_hal_async::spi::SpiBus; 11use embedded_hal_async::spi::SpiBus;
12 12
13mod register; 13mod register;
14use self::register::PaConfig;
15use self::register::Register;
16pub use self::register::IRQ; 14pub use self::register::IRQ;
15use self::register::{PaConfig, Register};
17 16
18/// Provides high-level access to Semtech SX1276/77/78/79 based boards connected to a Raspberry Pi 17/// Provides high-level access to Semtech SX1276/77/78/79 based boards connected to a Raspberry Pi
19pub struct LoRa<SPI, CS, RESET> { 18pub struct LoRa<SPI, CS, RESET> {
@@ -72,15 +71,11 @@ where
72 let version = self.read_register(Register::RegVersion.addr()).await?; 71 let version = self.read_register(Register::RegVersion.addr()).await?;
73 if version == VERSION_CHECK { 72 if version == VERSION_CHECK {
74 self.set_mode(RadioMode::Sleep).await?; 73 self.set_mode(RadioMode::Sleep).await?;
75 self.write_register(Register::RegFifoTxBaseAddr.addr(), 0) 74 self.write_register(Register::RegFifoTxBaseAddr.addr(), 0).await?;
76 .await?; 75 self.write_register(Register::RegFifoRxBaseAddr.addr(), 0).await?;
77 self.write_register(Register::RegFifoRxBaseAddr.addr(), 0)
78 .await?;
79 let lna = self.read_register(Register::RegLna.addr()).await?; 76 let lna = self.read_register(Register::RegLna.addr()).await?;
80 self.write_register(Register::RegLna.addr(), lna | 0x03) 77 self.write_register(Register::RegLna.addr(), lna | 0x03).await?;
81 .await?; 78 self.write_register(Register::RegModemConfig3.addr(), 0x04).await?;
82 self.write_register(Register::RegModemConfig3.addr(), 0x04)
83 .await?;
84 self.set_tcxo(true).await?; 79 self.set_tcxo(true).await?;
85 self.set_mode(RadioMode::Stdby).await?; 80 self.set_mode(RadioMode::Stdby).await?;
86 self.cs.set_high().map_err(CS)?; 81 self.cs.set_high().map_err(CS)?;
@@ -106,10 +101,7 @@ where
106 .await 101 .await
107 } 102 }
108 103
109 pub async fn transmit_start( 104 pub async fn transmit_start(&mut self, buffer: &[u8]) -> Result<(), Error<E, CS::Error, RESET::Error>> {
110 &mut self,
111 buffer: &[u8],
112 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
113 assert!(buffer.len() < 255); 105 assert!(buffer.len() < 255);
114 if self.transmitting().await? { 106 if self.transmitting().await? {
115 //trace!("ALREADY TRANSMNITTING"); 107 //trace!("ALREADY TRANSMNITTING");
@@ -123,10 +115,8 @@ where
123 } 115 }
124 116
125 self.write_register(Register::RegIrqFlags.addr(), 0).await?; 117 self.write_register(Register::RegIrqFlags.addr(), 0).await?;
126 self.write_register(Register::RegFifoAddrPtr.addr(), 0) 118 self.write_register(Register::RegFifoAddrPtr.addr(), 0).await?;
127 .await?; 119 self.write_register(Register::RegPayloadLength.addr(), 0).await?;
128 self.write_register(Register::RegPayloadLength.addr(), 0)
129 .await?;
130 for byte in buffer.iter() { 120 for byte in buffer.iter() {
131 self.write_register(Register::RegFifo.addr(), *byte).await?; 121 self.write_register(Register::RegFifo.addr(), *byte).await?;
132 } 122 }
@@ -138,10 +128,7 @@ where
138 } 128 }
139 129
140 pub async fn packet_ready(&mut self) -> Result<bool, Error<E, CS::Error, RESET::Error>> { 130 pub async fn packet_ready(&mut self) -> Result<bool, Error<E, CS::Error, RESET::Error>> {
141 Ok(self 131 Ok(self.read_register(Register::RegIrqFlags.addr()).await?.get_bit(6))
142 .read_register(Register::RegIrqFlags.addr())
143 .await?
144 .get_bit(6))
145 } 132 }
146 133
147 pub async fn irq_flags_mask(&mut self) -> Result<u8, Error<E, CS::Error, RESET::Error>> { 134 pub async fn irq_flags_mask(&mut self) -> Result<u8, Error<E, CS::Error, RESET::Error>> {
@@ -159,37 +146,26 @@ where
159 146
160 /// Returns the contents of the fifo as a fixed 255 u8 array. This should only be called is there is a 147 /// Returns the contents of the fifo as a fixed 255 u8 array. This should only be called is there is a
161 /// new packet ready to be read. 148 /// new packet ready to be read.
162 pub async fn read_packet( 149 pub async fn read_packet(&mut self, buffer: &mut [u8]) -> Result<(), Error<E, CS::Error, RESET::Error>> {
163 &mut self,
164 buffer: &mut [u8],
165 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
166 self.clear_irq().await?; 150 self.clear_irq().await?;
167 let size = self.read_register(Register::RegRxNbBytes.addr()).await?; 151 let size = self.read_register(Register::RegRxNbBytes.addr()).await?;
168 assert!(size as usize <= buffer.len()); 152 assert!(size as usize <= buffer.len());
169 let fifo_addr = self 153 let fifo_addr = self.read_register(Register::RegFifoRxCurrentAddr.addr()).await?;
170 .read_register(Register::RegFifoRxCurrentAddr.addr()) 154 self.write_register(Register::RegFifoAddrPtr.addr(), fifo_addr).await?;
171 .await?;
172 self.write_register(Register::RegFifoAddrPtr.addr(), fifo_addr)
173 .await?;
174 for i in 0..size { 155 for i in 0..size {
175 let byte = self.read_register(Register::RegFifo.addr()).await?; 156 let byte = self.read_register(Register::RegFifo.addr()).await?;
176 buffer[i as usize] = byte; 157 buffer[i as usize] = byte;
177 } 158 }
178 self.write_register(Register::RegFifoAddrPtr.addr(), 0) 159 self.write_register(Register::RegFifoAddrPtr.addr(), 0).await?;
179 .await?;
180 Ok(()) 160 Ok(())
181 } 161 }
182 162
183 /// Returns true if the radio is currently transmitting a packet. 163 /// Returns true if the radio is currently transmitting a packet.
184 pub async fn transmitting(&mut self) -> Result<bool, Error<E, CS::Error, RESET::Error>> { 164 pub async fn transmitting(&mut self) -> Result<bool, Error<E, CS::Error, RESET::Error>> {
185 if (self.read_register(Register::RegOpMode.addr()).await?) & RadioMode::Tx.addr() 165 if (self.read_register(Register::RegOpMode.addr()).await?) & RadioMode::Tx.addr() == RadioMode::Tx.addr() {
186 == RadioMode::Tx.addr()
187 {
188 Ok(true) 166 Ok(true)
189 } else { 167 } else {
190 if (self.read_register(Register::RegIrqFlags.addr()).await? & IRQ::IrqTxDoneMask.addr()) 168 if (self.read_register(Register::RegIrqFlags.addr()).await? & IRQ::IrqTxDoneMask.addr()) == 1 {
191 == 1
192 {
193 self.write_register(Register::RegIrqFlags.addr(), IRQ::IrqTxDoneMask.addr()) 169 self.write_register(Register::RegIrqFlags.addr(), IRQ::IrqTxDoneMask.addr())
194 .await?; 170 .await?;
195 } 171 }
@@ -200,8 +176,7 @@ where
200 /// Clears the radio's IRQ registers. 176 /// Clears the radio's IRQ registers.
201 pub async fn clear_irq(&mut self) -> Result<u8, Error<E, CS::Error, RESET::Error>> { 177 pub async fn clear_irq(&mut self) -> Result<u8, Error<E, CS::Error, RESET::Error>> {
202 let irq_flags = self.read_register(Register::RegIrqFlags.addr()).await?; 178 let irq_flags = self.read_register(Register::RegIrqFlags.addr()).await?;
203 self.write_register(Register::RegIrqFlags.addr(), 0xFF) 179 self.write_register(Register::RegIrqFlags.addr(), 0xFF).await?;
204 .await?;
205 Ok(irq_flags) 180 Ok(irq_flags)
206 } 181 }
207 182
@@ -243,11 +218,8 @@ where
243 self.set_ocp(100).await?; 218 self.set_ocp(100).await?;
244 } 219 }
245 level -= 2; 220 level -= 2;
246 self.write_register( 221 self.write_register(Register::RegPaConfig.addr(), PaConfig::PaBoost.addr() | level as u8)
247 Register::RegPaConfig.addr(), 222 .await
248 PaConfig::PaBoost.addr() | level as u8,
249 )
250 .await
251 } 223 }
252 } 224 }
253 225
@@ -269,10 +241,7 @@ where
269 } 241 }
270 242
271 /// Sets the state of the radio. Default mode after initiation is `Standby`. 243 /// Sets the state of the radio. Default mode after initiation is `Standby`.
272 pub async fn set_mode( 244 pub async fn set_mode(&mut self, mode: RadioMode) -> Result<(), Error<E, CS::Error, RESET::Error>> {
273 &mut self,
274 mode: RadioMode,
275 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
276 if self.explicit_header { 245 if self.explicit_header {
277 self.set_explicit_header_mode().await?; 246 self.set_explicit_header_mode().await?;
278 } else { 247 } else {
@@ -289,25 +258,18 @@ where
289 } 258 }
290 259
291 pub async fn reset_payload_length(&mut self) -> Result<(), Error<E, CS::Error, RESET::Error>> { 260 pub async fn reset_payload_length(&mut self) -> Result<(), Error<E, CS::Error, RESET::Error>> {
292 self.write_register(Register::RegPayloadLength.addr(), 0xFF) 261 self.write_register(Register::RegPayloadLength.addr(), 0xFF).await
293 .await
294 } 262 }
295 263
296 /// Sets the frequency of the radio. Values are in megahertz. 264 /// Sets the frequency of the radio. Values are in megahertz.
297 /// I.E. 915 MHz must be used for North America. Check regulation for your area. 265 /// I.E. 915 MHz must be used for North America. Check regulation for your area.
298 pub async fn set_frequency( 266 pub async fn set_frequency(&mut self, freq: u32) -> Result<(), Error<E, CS::Error, RESET::Error>> {
299 &mut self,
300 freq: u32,
301 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
302 const FREQ_STEP: f64 = 61.03515625; 267 const FREQ_STEP: f64 = 61.03515625;
303 // calculate register values 268 // calculate register values
304 let frf = (freq as f64 / FREQ_STEP) as u32; 269 let frf = (freq as f64 / FREQ_STEP) as u32;
305 // write registers 270 // write registers
306 self.write_register( 271 self.write_register(Register::RegFrfMsb.addr(), ((frf & 0x00FF_0000) >> 16) as u8)
307 Register::RegFrfMsb.addr(), 272 .await?;
308 ((frf & 0x00FF_0000) >> 16) as u8,
309 )
310 .await?;
311 self.write_register(Register::RegFrfMid.addr(), ((frf & 0x0000_FF00) >> 8) as u8) 273 self.write_register(Register::RegFrfMid.addr(), ((frf & 0x0000_FF00) >> 8) as u8)
312 .await?; 274 .await?;
313 self.write_register(Register::RegFrfLsb.addr(), (frf & 0x0000_00FF) as u8) 275 self.write_register(Register::RegFrfLsb.addr(), (frf & 0x0000_00FF) as u8)
@@ -335,10 +297,7 @@ where
335 /// Sets the spreading factor of the radio. Supported values are between 6 and 12. 297 /// Sets the spreading factor of the radio. Supported values are between 6 and 12.
336 /// If a spreading factor of 6 is set, implicit header mode must be used to transmit 298 /// If a spreading factor of 6 is set, implicit header mode must be used to transmit
337 /// and receive packets. Default value is `7`. 299 /// and receive packets. Default value is `7`.
338 pub async fn set_spreading_factor( 300 pub async fn set_spreading_factor(&mut self, mut sf: u8) -> Result<(), Error<E, CS::Error, RESET::Error>> {
339 &mut self,
340 mut sf: u8,
341 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
342 if sf < 6 { 301 if sf < 6 {
343 sf = 6; 302 sf = 6;
344 } else if sf > 12 { 303 } else if sf > 12 {
@@ -346,13 +305,11 @@ where
346 } 305 }
347 306
348 if sf == 6 { 307 if sf == 6 {
349 self.write_register(Register::RegDetectionOptimize.addr(), 0xc5) 308 self.write_register(Register::RegDetectionOptimize.addr(), 0xc5).await?;
350 .await?;
351 self.write_register(Register::RegDetectionThreshold.addr(), 0x0c) 309 self.write_register(Register::RegDetectionThreshold.addr(), 0x0c)
352 .await?; 310 .await?;
353 } else { 311 } else {
354 self.write_register(Register::RegDetectionOptimize.addr(), 0xc3) 312 self.write_register(Register::RegDetectionOptimize.addr(), 0xc3).await?;
355 .await?;
356 self.write_register(Register::RegDetectionThreshold.addr(), 0x0a) 313 self.write_register(Register::RegDetectionThreshold.addr(), 0x0a)
357 .await?; 314 .await?;
358 } 315 }
@@ -364,16 +321,12 @@ where
364 .await?; 321 .await?;
365 self.set_ldo_flag().await?; 322 self.set_ldo_flag().await?;
366 323
367 self.write_register(Register::RegSymbTimeoutLsb.addr(), 0x05) 324 self.write_register(Register::RegSymbTimeoutLsb.addr(), 0x05).await?;
368 .await?;
369 325
370 Ok(()) 326 Ok(())
371 } 327 }
372 328
373 pub async fn set_tcxo( 329 pub async fn set_tcxo(&mut self, external: bool) -> Result<(), Error<E, CS::Error, RESET::Error>> {
374 &mut self,
375 external: bool,
376 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
377 if external { 330 if external {
378 self.write_register(Register::RegTcxo.addr(), 0x10).await 331 self.write_register(Register::RegTcxo.addr(), 0x10).await
379 } else { 332 } else {
@@ -384,10 +337,7 @@ where
384 /// Sets the signal bandwidth of the radio. Supported values are: `7800 Hz`, `10400 Hz`, 337 /// Sets the signal bandwidth of the radio. Supported values are: `7800 Hz`, `10400 Hz`,
385 /// `15600 Hz`, `20800 Hz`, `31250 Hz`,`41700 Hz` ,`62500 Hz`,`125000 Hz` and `250000 Hz` 338 /// `15600 Hz`, `20800 Hz`, `31250 Hz`,`41700 Hz` ,`62500 Hz`,`125000 Hz` and `250000 Hz`
386 /// Default value is `125000 Hz` 339 /// Default value is `125000 Hz`
387 pub async fn set_signal_bandwidth( 340 pub async fn set_signal_bandwidth(&mut self, sbw: i64) -> Result<(), Error<E, CS::Error, RESET::Error>> {
388 &mut self,
389 sbw: i64,
390 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
391 let bw: i64 = match sbw { 341 let bw: i64 = match sbw {
392 7_800 => 0, 342 7_800 => 0,
393 10_400 => 1, 343 10_400 => 1,
@@ -413,10 +363,7 @@ where
413 /// Sets the coding rate of the radio with the numerator fixed at 4. Supported values 363 /// Sets the coding rate of the radio with the numerator fixed at 4. Supported values
414 /// are between `5` and `8`, these correspond to coding rates of `4/5` and `4/8`. 364 /// are between `5` and `8`, these correspond to coding rates of `4/5` and `4/8`.
415 /// Default value is `5`. 365 /// Default value is `5`.
416 pub async fn set_coding_rate_4( 366 pub async fn set_coding_rate_4(&mut self, mut denominator: u8) -> Result<(), Error<E, CS::Error, RESET::Error>> {
417 &mut self,
418 mut denominator: u8,
419 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
420 if denominator < 5 { 367 if denominator < 5 {
421 denominator = 5; 368 denominator = 5;
422 } else if denominator > 8 { 369 } else if denominator > 8 {
@@ -424,23 +371,16 @@ where
424 } 371 }
425 let cr = denominator - 4; 372 let cr = denominator - 4;
426 let modem_config_1 = self.read_register(Register::RegModemConfig1.addr()).await?; 373 let modem_config_1 = self.read_register(Register::RegModemConfig1.addr()).await?;
427 self.write_register( 374 self.write_register(Register::RegModemConfig1.addr(), (modem_config_1 & 0xf1) | (cr << 1))
428 Register::RegModemConfig1.addr(), 375 .await
429 (modem_config_1 & 0xf1) | (cr << 1),
430 )
431 .await
432 } 376 }
433 377
434 /// Sets the preamble length of the radio. Values are between 6 and 65535. 378 /// Sets the preamble length of the radio. Values are between 6 and 65535.
435 /// Default value is `8`. 379 /// Default value is `8`.
436 pub async fn set_preamble_length( 380 pub async fn set_preamble_length(&mut self, length: i64) -> Result<(), Error<E, CS::Error, RESET::Error>> {
437 &mut self,
438 length: i64,
439 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
440 self.write_register(Register::RegPreambleMsb.addr(), (length >> 8) as u8) 381 self.write_register(Register::RegPreambleMsb.addr(), (length >> 8) as u8)
441 .await?; 382 .await?;
442 self.write_register(Register::RegPreambleLsb.addr(), length as u8) 383 self.write_register(Register::RegPreambleLsb.addr(), length as u8).await
443 .await
444 } 384 }
445 385
446 /// Enables are disables the radio's CRC check. Default value is `false`. 386 /// Enables are disables the radio's CRC check. Default value is `false`.
@@ -456,20 +396,13 @@ where
456 } 396 }
457 397
458 /// Inverts the radio's IQ signals. Default value is `false`. 398 /// Inverts the radio's IQ signals. Default value is `false`.
459 pub async fn set_invert_iq( 399 pub async fn set_invert_iq(&mut self, value: bool) -> Result<(), Error<E, CS::Error, RESET::Error>> {
460 &mut self,
461 value: bool,
462 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
463 if value { 400 if value {
464 self.write_register(Register::RegInvertiq.addr(), 0x66) 401 self.write_register(Register::RegInvertiq.addr(), 0x66).await?;
465 .await?; 402 self.write_register(Register::RegInvertiq2.addr(), 0x19).await
466 self.write_register(Register::RegInvertiq2.addr(), 0x19)
467 .await
468 } else { 403 } else {
469 self.write_register(Register::RegInvertiq.addr(), 0x27) 404 self.write_register(Register::RegInvertiq.addr(), 0x27).await?;
470 .await?; 405 self.write_register(Register::RegInvertiq2.addr(), 0x1d).await
471 self.write_register(Register::RegInvertiq2.addr(), 0x1d)
472 .await
473 } 406 }
474 } 407 }
475 408
@@ -504,15 +437,11 @@ where
504 437
505 /// Returns the signal to noise radio of the the last received packet. 438 /// Returns the signal to noise radio of the the last received packet.
506 pub async fn get_packet_snr(&mut self) -> Result<f64, Error<E, CS::Error, RESET::Error>> { 439 pub async fn get_packet_snr(&mut self) -> Result<f64, Error<E, CS::Error, RESET::Error>> {
507 Ok(f64::from( 440 Ok(f64::from(self.read_register(Register::RegPktSnrValue.addr()).await?))
508 self.read_register(Register::RegPktSnrValue.addr()).await?,
509 ))
510 } 441 }
511 442
512 /// Returns the frequency error of the last received packet in Hz. 443 /// Returns the frequency error of the last received packet in Hz.
513 pub async fn get_packet_frequency_error( 444 pub async fn get_packet_frequency_error(&mut self) -> Result<i64, Error<E, CS::Error, RESET::Error>> {
514 &mut self,
515 ) -> Result<i64, Error<E, CS::Error, RESET::Error>> {
516 let mut freq_error: i32; 445 let mut freq_error: i32;
517 freq_error = i32::from(self.read_register(Register::RegFreqErrorMsb.addr()).await? & 0x7); 446 freq_error = i32::from(self.read_register(Register::RegFreqErrorMsb.addr()).await? & 0x7);
518 freq_error <<= 8i64; 447 freq_error <<= 8i64;
@@ -537,29 +466,20 @@ where
537 let mut config_3 = self.read_register(Register::RegModemConfig3.addr()).await?; 466 let mut config_3 = self.read_register(Register::RegModemConfig3.addr()).await?;
538 config_3.set_bit(3, ldo_on); 467 config_3.set_bit(3, ldo_on);
539 //config_3.set_bit(2, true); 468 //config_3.set_bit(2, true);
540 self.write_register(Register::RegModemConfig3.addr(), config_3) 469 self.write_register(Register::RegModemConfig3.addr(), config_3).await
541 .await
542 } 470 }
543 471
544 async fn read_register(&mut self, reg: u8) -> Result<u8, Error<E, CS::Error, RESET::Error>> { 472 async fn read_register(&mut self, reg: u8) -> Result<u8, Error<E, CS::Error, RESET::Error>> {
545 let mut buffer = [reg & 0x7f, 0]; 473 let mut buffer = [reg & 0x7f, 0];
546 self.cs.set_low().map_err(CS)?; 474 self.cs.set_low().map_err(CS)?;
547 475
548 let _ = self 476 let _ = self.spi.transfer(&mut buffer, &[reg & 0x7f, 0]).await.map_err(SPI)?;
549 .spi
550 .transfer(&mut buffer, &[reg & 0x7f, 0])
551 .await
552 .map_err(SPI)?;
553 477
554 self.cs.set_high().map_err(CS)?; 478 self.cs.set_high().map_err(CS)?;
555 Ok(buffer[1]) 479 Ok(buffer[1])
556 } 480 }
557 481
558 async fn write_register( 482 async fn write_register(&mut self, reg: u8, byte: u8) -> Result<(), Error<E, CS::Error, RESET::Error>> {
559 &mut self,
560 reg: u8,
561 byte: u8,
562 ) -> Result<(), Error<E, CS::Error, RESET::Error>> {
563 self.cs.set_low().map_err(CS)?; 483 self.cs.set_low().map_err(CS)?;
564 let buffer = [reg | 0x80, byte]; 484 let buffer = [reg | 0x80, byte];
565 self.spi.write(&buffer).await.map_err(SPI)?; 485 self.spi.write(&buffer).await.map_err(SPI)?;
@@ -576,8 +496,7 @@ where
576 .set_bit(3, false) //Low freq registers 496 .set_bit(3, false) //Low freq registers
577 .set_bits(0..2, 0b011); // Mode 497 .set_bits(0..2, 0b011); // Mode
578 498
579 self.write_register(Register::RegOpMode as u8, op_mode) 499 self.write_register(Register::RegOpMode as u8, op_mode).await
580 .await
581 } 500 }
582 501
583 pub async fn set_fsk_pa_ramp( 502 pub async fn set_fsk_pa_ramp(
@@ -590,8 +509,7 @@ where
590 .set_bits(5..6, modulation_shaping as u8) 509 .set_bits(5..6, modulation_shaping as u8)
591 .set_bits(0..3, ramp as u8); 510 .set_bits(0..3, ramp as u8);
592 511
593 self.write_register(Register::RegPaRamp as u8, pa_ramp) 512 self.write_register(Register::RegPaRamp as u8, pa_ramp).await
594 .await
595 } 513 }
596 514
597 pub async fn set_lora_pa_ramp(&mut self) -> Result<(), Error<E, CS::Error, RESET::Error>> { 515 pub async fn set_lora_pa_ramp(&mut self) -> Result<(), Error<E, CS::Error, RESET::Error>> {
diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs
index 50f442438..ec8498f9f 100644
--- a/embassy-macros/src/lib.rs
+++ b/embassy-macros/src/lib.rs
@@ -25,17 +25,13 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
25pub fn cortex_m_interrupt(args: TokenStream, item: TokenStream) -> TokenStream { 25pub fn cortex_m_interrupt(args: TokenStream, item: TokenStream) -> TokenStream {
26 let args = syn::parse_macro_input!(args as syn::AttributeArgs); 26 let args = syn::parse_macro_input!(args as syn::AttributeArgs);
27 let f = syn::parse_macro_input!(item as syn::ItemFn); 27 let f = syn::parse_macro_input!(item as syn::ItemFn);
28 cortex_m_interrupt::run(args, f) 28 cortex_m_interrupt::run(args, f).unwrap_or_else(|x| x).into()
29 .unwrap_or_else(|x| x)
30 .into()
31} 29}
32 30
33#[proc_macro] 31#[proc_macro]
34pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream { 32pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream {
35 let name = syn::parse_macro_input!(item as syn::Ident); 33 let name = syn::parse_macro_input!(item as syn::Ident);
36 cortex_m_interrupt_declare::run(name) 34 cortex_m_interrupt_declare::run(name).unwrap_or_else(|x| x).into()
37 .unwrap_or_else(|x| x)
38 .into()
39} 35}
40 36
41/// # interrupt_take procedural macro 37/// # interrupt_take procedural macro
@@ -46,7 +42,5 @@ pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream {
46#[proc_macro] 42#[proc_macro]
47pub fn cortex_m_interrupt_take(item: TokenStream) -> TokenStream { 43pub fn cortex_m_interrupt_take(item: TokenStream) -> TokenStream {
48 let name = syn::parse_macro_input!(item as syn::Ident); 44 let name = syn::parse_macro_input!(item as syn::Ident);
49 cortex_m_interrupt_take::run(name) 45 cortex_m_interrupt_take::run(name).unwrap_or_else(|x| x).into()
50 .unwrap_or_else(|x| x)
51 .into()
52} 46}
diff --git a/embassy-macros/src/macros/cortex_m_interrupt.rs b/embassy-macros/src/macros/cortex_m_interrupt.rs
index 32cc0e010..13af8ca07 100644
--- a/embassy-macros/src/macros/cortex_m_interrupt.rs
+++ b/embassy-macros/src/macros/cortex_m_interrupt.rs
@@ -1,9 +1,9 @@
1use std::iter;
2
1use darling::FromMeta; 3use darling::FromMeta;
2use proc_macro2::TokenStream; 4use proc_macro2::TokenStream;
3use quote::quote; 5use quote::quote;
4use std::iter; 6use syn::{ReturnType, Type, Visibility};
5use syn::ReturnType;
6use syn::{Type, Visibility};
7 7
8use crate::util::ctxt::Ctxt; 8use crate::util::ctxt::Ctxt;
9 9
diff --git a/embassy-macros/src/macros/main.rs b/embassy-macros/src/macros/main.rs
index b7ce9dda4..5638276b2 100644
--- a/embassy-macros/src/macros/main.rs
+++ b/embassy-macros/src/macros/main.rs
@@ -81,14 +81,11 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
81 81
82 #[cfg(all(not(feature = "std"), not(feature = "wasm")))] 82 #[cfg(all(not(feature = "std"), not(feature = "wasm")))]
83 let main = { 83 let main = {
84 let config = args 84 let config = args.config.map(|s| s.parse::<syn::Expr>().unwrap()).unwrap_or_else(|| {
85 .config 85 syn::Expr::Verbatim(quote! {
86 .map(|s| s.parse::<syn::Expr>().unwrap()) 86 Default::default()
87 .unwrap_or_else(|| { 87 })
88 syn::Expr::Verbatim(quote! { 88 });
89 Default::default()
90 })
91 });
92 89
93 let (hal_setup, peris_arg) = match HAL { 90 let (hal_setup, peris_arg) = match HAL {
94 Some(hal) => { 91 Some(hal) => {
diff --git a/embassy-macros/src/macros/task.rs b/embassy-macros/src/macros/task.rs
index e48de3d63..53c9af546 100644
--- a/embassy-macros/src/macros/task.rs
+++ b/embassy-macros/src/macros/task.rs
@@ -47,10 +47,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
47 id.mutability = None; 47 id.mutability = None;
48 } 48 }
49 _ => { 49 _ => {
50 ctxt.error_spanned_by( 50 ctxt.error_spanned_by(arg, "pattern matching in task arguments is not yet supported");
51 arg,
52 "pattern matching in task arguments is not yet supported",
53 );
54 } 51 }
55 }, 52 },
56 } 53 }
diff --git a/embassy-macros/src/util/ctxt.rs b/embassy-macros/src/util/ctxt.rs
index d668ae780..74c872c3c 100644
--- a/embassy-macros/src/util/ctxt.rs
+++ b/embassy-macros/src/util/ctxt.rs
@@ -1,11 +1,12 @@
1// nifty utility borrowed from serde :) 1// nifty utility borrowed from serde :)
2// https://github.com/serde-rs/serde/blob/master/serde_derive/src/internals/ctxt.rs 2// https://github.com/serde-rs/serde/blob/master/serde_derive/src/internals/ctxt.rs
3 3
4use proc_macro2::TokenStream;
5use quote::{quote, ToTokens};
6use std::cell::RefCell; 4use std::cell::RefCell;
7use std::fmt::Display; 5use std::fmt::Display;
8use std::thread; 6use std::thread;
7
8use proc_macro2::TokenStream;
9use quote::{quote, ToTokens};
9use syn; 10use syn;
10 11
11/// A type to collect errors together and format them. 12/// A type to collect errors together and format them.
diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs
index 99c6a2212..c183bd58a 100644
--- a/embassy-net/src/device.rs
+++ b/embassy-net/src/device.rs
@@ -1,6 +1,6 @@
1use core::task::Waker; 1use core::task::Waker;
2use smoltcp::phy::Device as SmolDevice; 2
3use smoltcp::phy::DeviceCapabilities; 3use smoltcp::phy::{Device as SmolDevice, DeviceCapabilities};
4use smoltcp::time::Instant as SmolInstant; 4use smoltcp::time::Instant as SmolInstant;
5 5
6use crate::packet_pool::PacketBoxExt; 6use crate::packet_pool::PacketBoxExt;
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index 243dfda88..1c5ba103a 100644
--- a/embassy-net/src/lib.rs
+++ b/embassy-net/src/lib.rs
@@ -18,11 +18,9 @@ pub mod tcp;
18 18
19// smoltcp reexports 19// smoltcp reexports
20pub use smoltcp::phy::{DeviceCapabilities, Medium}; 20pub use smoltcp::phy::{DeviceCapabilities, Medium};
21pub use smoltcp::time::Duration as SmolDuration; 21pub use smoltcp::time::{Duration as SmolDuration, Instant as SmolInstant};
22pub use smoltcp::time::Instant as SmolInstant;
23#[cfg(feature = "medium-ethernet")] 22#[cfg(feature = "medium-ethernet")]
24pub use smoltcp::wire::{EthernetAddress, HardwareAddress}; 23pub use smoltcp::wire::{EthernetAddress, HardwareAddress};
25pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; 24pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr};
26
27#[cfg(feature = "proto-ipv6")] 25#[cfg(feature = "proto-ipv6")]
28pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr}; 26pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr};
diff --git a/embassy-net/src/packet_pool.rs b/embassy-net/src/packet_pool.rs
index 99311ae74..cb8a1316c 100644
--- a/embassy-net/src/packet_pool.rs
+++ b/embassy-net/src/packet_pool.rs
@@ -1,6 +1,6 @@
1use as_slice::{AsMutSlice, AsSlice};
2use core::ops::{Deref, DerefMut, Range}; 1use core::ops::{Deref, DerefMut, Range};
3 2
3use as_slice::{AsMutSlice, AsSlice};
4use atomic_pool::{pool, Box}; 4use atomic_pool::{pool, Box};
5 5
6pub const MTU: usize = 1516; 6pub const MTU: usize = 1516;
@@ -41,10 +41,7 @@ pub trait PacketBoxExt {
41 41
42impl PacketBoxExt for PacketBox { 42impl PacketBoxExt for PacketBox {
43 fn slice(self, range: Range<usize>) -> PacketBuf { 43 fn slice(self, range: Range<usize>) -> PacketBuf {
44 PacketBuf { 44 PacketBuf { packet: self, range }
45 packet: self,
46 range,
47 }
48 } 45 }
49} 46}
50 47
diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs
index e28370df8..f3b1ff9d4 100644
--- a/embassy-net/src/stack.rs
+++ b/embassy-net/src/stack.rs
@@ -1,7 +1,7 @@
1use core::cell::UnsafeCell; 1use core::cell::UnsafeCell;
2use core::future::Future; 2use core::future::Future;
3use core::task::Context; 3use core::task::{Context, Poll};
4use core::task::Poll; 4
5use embassy::time::{Instant, Timer}; 5use embassy::time::{Instant, Timer};
6use embassy::waitqueue::WakerRegistration; 6use embassy::waitqueue::WakerRegistration;
7use futures::future::poll_fn; 7use futures::future::poll_fn;
@@ -9,19 +9,17 @@ use futures::pin_mut;
9use heapless::Vec; 9use heapless::Vec;
10#[cfg(feature = "dhcpv4")] 10#[cfg(feature = "dhcpv4")]
11use smoltcp::iface::SocketHandle; 11use smoltcp::iface::SocketHandle;
12use smoltcp::iface::{Interface, InterfaceBuilder}; 12use smoltcp::iface::{Interface, InterfaceBuilder, SocketSet, SocketStorage};
13use smoltcp::iface::{SocketSet, SocketStorage};
14#[cfg(feature = "dhcpv4")]
15use smoltcp::socket::dhcpv4;
16use smoltcp::time::Instant as SmolInstant;
17use smoltcp::wire::{IpCidr, Ipv4Address, Ipv4Cidr};
18
19#[cfg(feature = "medium-ethernet")] 13#[cfg(feature = "medium-ethernet")]
20use smoltcp::iface::{Neighbor, NeighborCache, Route, Routes}; 14use smoltcp::iface::{Neighbor, NeighborCache, Route, Routes};
21#[cfg(feature = "medium-ethernet")] 15#[cfg(feature = "medium-ethernet")]
22use smoltcp::phy::{Device as _, Medium}; 16use smoltcp::phy::{Device as _, Medium};
17#[cfg(feature = "dhcpv4")]
18use smoltcp::socket::dhcpv4;
19use smoltcp::time::Instant as SmolInstant;
23#[cfg(feature = "medium-ethernet")] 20#[cfg(feature = "medium-ethernet")]
24use smoltcp::wire::{EthernetAddress, HardwareAddress, IpAddress}; 21use smoltcp::wire::{EthernetAddress, HardwareAddress, IpAddress};
22use smoltcp::wire::{IpCidr, Ipv4Address, Ipv4Cidr};
25 23
26use crate::device::{Device, DeviceAdapter, LinkState}; 24use crate::device::{Device, DeviceAdapter, LinkState};
27 25
@@ -38,9 +36,7 @@ pub struct StackResources<const ADDR: usize, const SOCK: usize, const NEIGHBOR:
38 neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR], 36 neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR],
39} 37}
40 38
41impl<const ADDR: usize, const SOCK: usize, const NEIGHBOR: usize> 39impl<const ADDR: usize, const SOCK: usize, const NEIGHBOR: usize> StackResources<ADDR, SOCK, NEIGHBOR> {
42 StackResources<ADDR, SOCK, NEIGHBOR>
43{
44 pub fn new() -> Self { 40 pub fn new() -> Self {
45 Self { 41 Self {
46 addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32); ADDR], 42 addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32); ADDR],
@@ -122,8 +118,7 @@ impl<D: Device + 'static> Stack<D> {
122 118
123 let sockets = SocketSet::new(&mut resources.sockets[..]); 119 let sockets = SocketSet::new(&mut resources.sockets[..]);
124 120
125 let next_local_port = 121 let next_local_port = (random_seed % (LOCAL_PORT_MAX - LOCAL_PORT_MIN) as u64) as u16 + LOCAL_PORT_MIN;
126 (random_seed % (LOCAL_PORT_MAX - LOCAL_PORT_MIN) as u64) as u16 + LOCAL_PORT_MIN;
127 122
128 let mut inner = Inner { 123 let mut inner = Inner {
129 device, 124 device,
@@ -194,11 +189,7 @@ impl SocketStack {
194 #[allow(clippy::absurd_extreme_comparisons)] 189 #[allow(clippy::absurd_extreme_comparisons)]
195 pub fn get_local_port(&mut self) -> u16 { 190 pub fn get_local_port(&mut self) -> u16 {
196 let res = self.next_local_port; 191 let res = self.next_local_port;
197 self.next_local_port = if res >= LOCAL_PORT_MAX { 192 self.next_local_port = if res >= LOCAL_PORT_MAX { LOCAL_PORT_MIN } else { res + 1 };
198 LOCAL_PORT_MIN
199 } else {
200 res + 1
201 };
202 res 193 res
203 } 194 }
204} 195}
@@ -217,10 +208,7 @@ impl<D: Device + 'static> Inner<D> {
217 if medium == Medium::Ethernet { 208 if medium == Medium::Ethernet {
218 if let Some(gateway) = config.gateway { 209 if let Some(gateway) = config.gateway {
219 debug!(" Default gateway: {}", gateway); 210 debug!(" Default gateway: {}", gateway);
220 s.iface 211 s.iface.routes_mut().add_default_ipv4_route(gateway).unwrap();
221 .routes_mut()
222 .add_default_ipv4_route(gateway)
223 .unwrap();
224 } else { 212 } else {
225 debug!(" Default gateway: None"); 213 debug!(" Default gateway: None");
226 s.iface.routes_mut().remove_default_ipv4_route(); 214 s.iface.routes_mut().remove_default_ipv4_route();
@@ -259,10 +247,7 @@ impl<D: Device + 'static> Inner<D> {
259 s.waker.register(cx.waker()); 247 s.waker.register(cx.waker());
260 248
261 let timestamp = instant_to_smoltcp(Instant::now()); 249 let timestamp = instant_to_smoltcp(Instant::now());
262 if s.iface 250 if s.iface.poll(timestamp, &mut self.device, &mut s.sockets).is_err() {
263 .poll(timestamp, &mut self.device, &mut s.sockets)
264 .is_err()
265 {
266 // If poll() returns error, it may not be done yet, so poll again later. 251 // If poll() returns error, it may not be done yet, so poll again later.
267 cx.waker().wake_by_ref(); 252 cx.waker().wake_by_ref();
268 return; 253 return;
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs
index 35ecf1b0c..c18391ace 100644
--- a/embassy-net/src/tcp.rs
+++ b/embassy-net/src/tcp.rs
@@ -2,18 +2,17 @@ use core::cell::UnsafeCell;
2use core::future::Future; 2use core::future::Future;
3use core::mem; 3use core::mem;
4use core::task::Poll; 4use core::task::Poll;
5
5use futures::future::poll_fn; 6use futures::future::poll_fn;
6use smoltcp::iface::{Interface, SocketHandle}; 7use smoltcp::iface::{Interface, SocketHandle};
7use smoltcp::socket::tcp; 8use smoltcp::socket::tcp;
8use smoltcp::time::Duration; 9use smoltcp::time::Duration;
9use smoltcp::wire::IpEndpoint; 10use smoltcp::wire::{IpEndpoint, IpListenEndpoint};
10use smoltcp::wire::IpListenEndpoint;
11 11
12use super::stack::Stack;
12use crate::stack::SocketStack; 13use crate::stack::SocketStack;
13use crate::Device; 14use crate::Device;
14 15
15use super::stack::Stack;
16
17#[derive(PartialEq, Eq, Clone, Copy, Debug)] 16#[derive(PartialEq, Eq, Clone, Copy, Debug)]
18#[cfg_attr(feature = "defmt", derive(defmt::Format))] 17#[cfg_attr(feature = "defmt", derive(defmt::Format))]
19pub enum Error { 18pub enum Error {
@@ -57,11 +56,7 @@ pub struct TcpWriter<'a> {
57} 56}
58 57
59impl<'a> TcpSocket<'a> { 58impl<'a> TcpSocket<'a> {
60 pub fn new<D: Device>( 59 pub fn new<D: Device>(stack: &'a Stack<D>, rx_buffer: &'a mut [u8], tx_buffer: &'a mut [u8]) -> Self {
61 stack: &'a Stack<D>,
62 rx_buffer: &'a mut [u8],
63 tx_buffer: &'a mut [u8],
64 ) -> Self {
65 // safety: not accessed reentrantly. 60 // safety: not accessed reentrantly.
66 let s = unsafe { &mut *stack.socket.get() }; 61 let s = unsafe { &mut *stack.socket.get() };
67 let rx_buffer: &'static mut [u8] = unsafe { mem::transmute(rx_buffer) }; 62 let rx_buffer: &'static mut [u8] = unsafe { mem::transmute(rx_buffer) };
@@ -91,10 +86,7 @@ impl<'a> TcpSocket<'a> {
91 let local_port = unsafe { &mut *self.io.stack.get() }.get_local_port(); 86 let local_port = unsafe { &mut *self.io.stack.get() }.get_local_port();
92 87
93 // safety: not accessed reentrantly. 88 // safety: not accessed reentrantly.
94 match unsafe { 89 match unsafe { self.io.with_mut(|s, i| s.connect(i, remote_endpoint, local_port)) } {
95 self.io
96 .with_mut(|s, i| s.connect(i, remote_endpoint, local_port))
97 } {
98 Ok(()) => {} 90 Ok(()) => {}
99 Err(tcp::ConnectError::InvalidState) => return Err(ConnectError::InvalidState), 91 Err(tcp::ConnectError::InvalidState) => return Err(ConnectError::InvalidState),
100 Err(tcp::ConnectError::Unaddressable) => return Err(ConnectError::NoRoute), 92 Err(tcp::ConnectError::Unaddressable) => return Err(ConnectError::NoRoute),
@@ -102,9 +94,7 @@ impl<'a> TcpSocket<'a> {
102 94
103 futures::future::poll_fn(|cx| unsafe { 95 futures::future::poll_fn(|cx| unsafe {
104 self.io.with_mut(|s, _| match s.state() { 96 self.io.with_mut(|s, _| match s.state() {
105 tcp::State::Closed | tcp::State::TimeWait => { 97 tcp::State::Closed | tcp::State::TimeWait => Poll::Ready(Err(ConnectError::ConnectionReset)),
106 Poll::Ready(Err(ConnectError::ConnectionReset))
107 }
108 tcp::State::Listen => unreachable!(), 98 tcp::State::Listen => unreachable!(),
109 tcp::State::SynSent | tcp::State::SynReceived => { 99 tcp::State::SynSent | tcp::State::SynReceived => {
110 s.register_send_waker(cx.waker()); 100 s.register_send_waker(cx.waker());
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index ef3ccdc93..34f20efe7 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -13,28 +13,26 @@
13//! 13//!
14//! Please also see [crate::uarte] to understand when [BufferedUarte] should be used. 14//! Please also see [crate::uarte] to understand when [BufferedUarte] should be used.
15 15
16use crate::interrupt::InterruptExt;
17use crate::Unborrow;
18use core::cmp::min; 16use core::cmp::min;
19use core::future::Future; 17use core::future::Future;
20use core::marker::PhantomData; 18use core::marker::PhantomData;
21use core::sync::atomic::{compiler_fence, Ordering}; 19use core::sync::atomic::{compiler_fence, Ordering};
22use core::task::Poll; 20use core::task::Poll;
21
23use embassy::waitqueue::WakerRegistration; 22use embassy::waitqueue::WakerRegistration;
24use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; 23use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
25use embassy_hal_common::ring_buffer::RingBuffer; 24use embassy_hal_common::ring_buffer::RingBuffer;
26use embassy_hal_common::{low_power_wait_until, unborrow}; 25use embassy_hal_common::{low_power_wait_until, unborrow};
27use futures::future::poll_fn; 26use futures::future::poll_fn;
27// Re-export SVD variants to allow user to directly set values
28pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
28 29
29use crate::gpio::Pin as GpioPin; 30use crate::gpio::Pin as GpioPin;
30use crate::pac; 31use crate::interrupt::InterruptExt;
31use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; 32use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
32use crate::timer::Instance as TimerInstance; 33use crate::timer::{Frequency, Instance as TimerInstance, Timer};
33use crate::timer::{Frequency, Timer};
34use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance}; 34use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance};
35 35use crate::{pac, Unborrow};
36// Re-export SVD variants to allow user to directly set values
37pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
38 36
39#[derive(Copy, Clone, Debug, PartialEq)] 37#[derive(Copy, Clone, Debug, PartialEq)]
40enum RxState { 38enum RxState {
@@ -234,9 +232,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Read for Buffe
234 } 232 }
235} 233}
236 234
237impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead 235impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead for BufferedUarte<'d, U, T> {
238 for BufferedUarte<'d, U, T>
239{
240 type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> 236 type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>>
241 where 237 where
242 Self: 'a; 238 Self: 'a;
@@ -276,9 +272,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead
276 } 272 }
277} 273}
278 274
279impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write 275impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write for BufferedUarte<'d, U, T> {
280 for BufferedUarte<'d, U, T>
281{
282 type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> 276 type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
283 where 277 where
284 Self: 'a; 278 Self: 'a;
diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs
index 31659859b..8fca4da1a 100644
--- a/embassy-nrf/src/chips/nrf52805.rs
+++ b/embassy-nrf/src/chips/nrf52805.rs
@@ -197,9 +197,10 @@ 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 crate::pac::Interrupt as InterruptEnum;
201 use embassy_macros::cortex_m_interrupt_declare as declare; 200 use embassy_macros::cortex_m_interrupt_declare as declare;
202 201
202 use crate::pac::Interrupt as InterruptEnum;
203
203 declare!(POWER_CLOCK); 204 declare!(POWER_CLOCK);
204 declare!(RADIO); 205 declare!(RADIO);
205 declare!(UARTE0_UART0); 206 declare!(UARTE0_UART0);
diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs
index 195be51c8..538a617d2 100644
--- a/embassy-nrf/src/chips/nrf52810.rs
+++ b/embassy-nrf/src/chips/nrf52810.rs
@@ -218,9 +218,10 @@ 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 crate::pac::Interrupt as InterruptEnum;
222 use embassy_macros::cortex_m_interrupt_declare as declare; 221 use embassy_macros::cortex_m_interrupt_declare as declare;
223 222
223 use crate::pac::Interrupt as InterruptEnum;
224
224 declare!(POWER_CLOCK); 225 declare!(POWER_CLOCK);
225 declare!(RADIO); 226 declare!(RADIO);
226 declare!(UARTE0_UART0); 227 declare!(UARTE0_UART0);
diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs
index 18f054059..808adf517 100644
--- a/embassy-nrf/src/chips/nrf52811.rs
+++ b/embassy-nrf/src/chips/nrf52811.rs
@@ -219,9 +219,10 @@ 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 crate::pac::Interrupt as InterruptEnum;
223 use embassy_macros::cortex_m_interrupt_declare as declare; 222 use embassy_macros::cortex_m_interrupt_declare as declare;
224 223
224 use crate::pac::Interrupt as InterruptEnum;
225
225 declare!(POWER_CLOCK); 226 declare!(POWER_CLOCK);
226 declare!(RADIO); 227 declare!(RADIO);
227 declare!(UARTE0_UART0); 228 declare!(UARTE0_UART0);
diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs
index b4ad4c729..6be5bd361 100644
--- a/embassy-nrf/src/chips/nrf52820.rs
+++ b/embassy-nrf/src/chips/nrf52820.rs
@@ -211,9 +211,10 @@ 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 crate::pac::Interrupt as InterruptEnum;
215 use embassy_macros::cortex_m_interrupt_declare as declare; 214 use embassy_macros::cortex_m_interrupt_declare as declare;
216 215
216 use crate::pac::Interrupt as InterruptEnum;
217
217 declare!(POWER_CLOCK); 218 declare!(POWER_CLOCK);
218 declare!(RADIO); 219 declare!(RADIO);
219 declare!(UARTE0_UART0); 220 declare!(UARTE0_UART0);
diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs
index d578519ff..cdc644d6e 100644
--- a/embassy-nrf/src/chips/nrf52832.rs
+++ b/embassy-nrf/src/chips/nrf52832.rs
@@ -235,9 +235,10 @@ 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 crate::pac::Interrupt as InterruptEnum;
239 use embassy_macros::cortex_m_interrupt_declare as declare; 238 use embassy_macros::cortex_m_interrupt_declare as declare;
240 239
240 use crate::pac::Interrupt as InterruptEnum;
241
241 declare!(POWER_CLOCK); 242 declare!(POWER_CLOCK);
242 declare!(RADIO); 243 declare!(RADIO);
243 declare!(UARTE0_UART0); 244 declare!(UARTE0_UART0);
diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs
index 92f415a51..4c3c5574d 100644
--- a/embassy-nrf/src/chips/nrf52833.rs
+++ b/embassy-nrf/src/chips/nrf52833.rs
@@ -278,9 +278,10 @@ 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 crate::pac::Interrupt as InterruptEnum;
282 use embassy_macros::cortex_m_interrupt_declare as declare; 281 use embassy_macros::cortex_m_interrupt_declare as declare;
283 282
283 use crate::pac::Interrupt as InterruptEnum;
284
284 declare!(POWER_CLOCK); 285 declare!(POWER_CLOCK);
285 declare!(RADIO); 286 declare!(RADIO);
286 declare!(UARTE0_UART0); 287 declare!(UARTE0_UART0);
diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs
index e7a94b18f..bdaeadb9b 100644
--- a/embassy-nrf/src/chips/nrf52840.rs
+++ b/embassy-nrf/src/chips/nrf52840.rs
@@ -283,9 +283,10 @@ 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 crate::pac::Interrupt as InterruptEnum;
287 use embassy_macros::cortex_m_interrupt_declare as declare; 286 use embassy_macros::cortex_m_interrupt_declare as declare;
288 287
288 use crate::pac::Interrupt as InterruptEnum;
289
289 declare!(POWER_CLOCK); 290 declare!(POWER_CLOCK);
290 declare!(RADIO); 291 declare!(RADIO);
291 declare!(UARTE0_UART0); 292 declare!(UARTE0_UART0);
diff --git a/embassy-nrf/src/chips/nrf5340_app.rs b/embassy-nrf/src/chips/nrf5340_app.rs
index 13ed23cd7..26dc56bdb 100644
--- a/embassy-nrf/src/chips/nrf5340_app.rs
+++ b/embassy-nrf/src/chips/nrf5340_app.rs
@@ -468,9 +468,10 @@ 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 crate::pac::Interrupt as InterruptEnum;
472 use embassy_macros::cortex_m_interrupt_declare as declare; 471 use embassy_macros::cortex_m_interrupt_declare as declare;
473 472
473 use crate::pac::Interrupt as InterruptEnum;
474
474 declare!(FPU); 475 declare!(FPU);
475 declare!(CACHE); 476 declare!(CACHE);
476 declare!(SPU); 477 declare!(SPU);
diff --git a/embassy-nrf/src/chips/nrf5340_net.rs b/embassy-nrf/src/chips/nrf5340_net.rs
index a7e70cdc3..e28cfe013 100644
--- a/embassy-nrf/src/chips/nrf5340_net.rs
+++ b/embassy-nrf/src/chips/nrf5340_net.rs
@@ -328,9 +328,10 @@ 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 crate::pac::Interrupt as InterruptEnum;
332 use embassy_macros::cortex_m_interrupt_declare as declare; 331 use embassy_macros::cortex_m_interrupt_declare as declare;
333 332
333 use crate::pac::Interrupt as InterruptEnum;
334
334 declare!(CLOCK_POWER); 335 declare!(CLOCK_POWER);
335 declare!(RADIO); 336 declare!(RADIO);
336 declare!(RNG); 337 declare!(RNG);
diff --git a/embassy-nrf/src/chips/nrf9160.rs b/embassy-nrf/src/chips/nrf9160.rs
index 57ff39b7b..1a0bd10fe 100644
--- a/embassy-nrf/src/chips/nrf9160.rs
+++ b/embassy-nrf/src/chips/nrf9160.rs
@@ -346,9 +346,10 @@ 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 crate::pac::Interrupt as InterruptEnum;
350 use embassy_macros::cortex_m_interrupt_declare as declare; 349 use embassy_macros::cortex_m_interrupt_declare as declare;
351 350
351 use crate::pac::Interrupt as InterruptEnum;
352
352 declare!(SPU); 353 declare!(SPU);
353 declare!(CLOCK_POWER); 354 declare!(CLOCK_POWER);
354 declare!(UARTE0_SPIM0_SPIS0_TWIM0_TWIS0); 355 declare!(UARTE0_SPIM0_SPIS0_TWIM0_TWIS0);
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index a6c846213..e68b8874a 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -4,15 +4,13 @@ use core::convert::Infallible;
4use core::hint::unreachable_unchecked; 4use core::hint::unreachable_unchecked;
5use core::marker::PhantomData; 5use core::marker::PhantomData;
6 6
7use crate::Unborrow;
8use cfg_if::cfg_if; 7use cfg_if::cfg_if;
9use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; 8use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
10 9
11use crate::pac; 10use self::sealed::Pin as _;
12use crate::pac::p0 as gpio; 11use crate::pac::p0 as gpio;
13use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A}; 12use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A};
14 13use crate::{pac, Unborrow};
15use self::sealed::Pin as _;
16 14
17/// A GPIO port with up to 32 pins. 15/// A GPIO port with up to 32 pins.
18#[derive(Debug, Eq, PartialEq)] 16#[derive(Debug, Eq, PartialEq)]
@@ -93,11 +91,7 @@ pub struct Output<'d, T: Pin> {
93} 91}
94 92
95impl<'d, T: Pin> Output<'d, T> { 93impl<'d, T: Pin> Output<'d, T> {
96 pub fn new( 94 pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self {
97 pin: impl Unborrow<Target = T> + 'd,
98 initial_output: Level,
99 drive: OutputDrive,
100 ) -> Self {
101 let mut pin = Flex::new(pin); 95 let mut pin = Flex::new(pin);
102 match initial_output { 96 match initial_output {
103 Level::High => pin.set_high(), 97 Level::High => pin.set_high(),
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index 051546236..d4e1cb35c 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -1,17 +1,17 @@
1use crate::interrupt::{Interrupt, InterruptExt};
2use core::convert::Infallible; 1use core::convert::Infallible;
3use core::future::Future; 2use core::future::Future;
4use core::marker::PhantomData; 3use core::marker::PhantomData;
5use core::task::{Context, Poll}; 4use core::task::{Context, Poll};
5
6use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
7use embassy_hal_common::unsafe_impl_unborrow; 7use embassy_hal_common::unsafe_impl_unborrow;
8use futures::future::poll_fn; 8use futures::future::poll_fn;
9 9
10use crate::gpio::sealed::Pin as _; 10use crate::gpio::sealed::Pin as _;
11use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin}; 11use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin};
12use crate::pac; 12use crate::interrupt::{Interrupt, InterruptExt};
13use crate::ppi::{Event, Task}; 13use crate::ppi::{Event, Task};
14use crate::{interrupt, peripherals}; 14use crate::{interrupt, pac, peripherals};
15 15
16pub const CHANNEL_COUNT: usize = 8; 16pub const CHANNEL_COUNT: usize = 8;
17 17
@@ -468,9 +468,7 @@ mod eh1 {
468 type Error = Infallible; 468 type Error = Infallible;
469 } 469 }
470 470
471 impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::blocking::InputPin 471 impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::blocking::InputPin for InputChannel<'d, C, T> {
472 for InputChannel<'d, C, T>
473 {
474 fn is_high(&self) -> Result<bool, Self::Error> { 472 fn is_high(&self) -> Result<bool, Self::Error> {
475 Ok(self.pin.is_high()) 473 Ok(self.pin.is_high())
476 } 474 }
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index 6eaadfc63..1f1ffc99d 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -35,10 +35,7 @@
35//! mutable slices always reside in RAM. 35//! mutable slices always reside in RAM.
36 36
37#![no_std] 37#![no_std]
38#![cfg_attr( 38#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))]
39 feature = "nightly",
40 feature(generic_associated_types, type_alias_impl_trait)
41)]
42 39
43#[cfg(not(any( 40#[cfg(not(any(
44 feature = "nrf51", 41 feature = "nrf51",
@@ -115,9 +112,10 @@ mod chip;
115pub use chip::EASY_DMA_SIZE; 112pub use chip::EASY_DMA_SIZE;
116 113
117pub mod interrupt { 114pub mod interrupt {
118 pub use crate::chip::irqs::*;
119 pub use cortex_m::interrupt::{CriticalSection, Mutex}; 115 pub use cortex_m::interrupt::{CriticalSection, Mutex};
120 pub use embassy_cortex_m::interrupt::*; 116 pub use embassy_cortex_m::interrupt::*;
117
118 pub use crate::chip::irqs::*;
121} 119}
122 120
123// Reexports 121// Reexports
@@ -126,7 +124,6 @@ pub mod interrupt {
126pub use chip::pac; 124pub use chip::pac;
127#[cfg(not(feature = "unstable-pac"))] 125#[cfg(not(feature = "unstable-pac"))]
128pub(crate) use chip::pac; 126pub(crate) use chip::pac;
129
130pub use chip::{peripherals, Peripherals}; 127pub use chip::{peripherals, Peripherals};
131pub use embassy_cortex_m::executor; 128pub use embassy_cortex_m::executor;
132pub use embassy_hal_common::{unborrow, Unborrow}; 129pub use embassy_hal_common::{unborrow, Unborrow};
diff --git a/embassy-nrf/src/nvmc.rs b/embassy-nrf/src/nvmc.rs
index 108a71d5e..e350f8c99 100644
--- a/embassy-nrf/src/nvmc.rs
+++ b/embassy-nrf/src/nvmc.rs
@@ -1,17 +1,16 @@
1//! Nvmcerature sensor interface. 1//! Nvmcerature sensor interface.
2 2
3use crate::pac;
4use crate::peripherals::NVMC;
5
6use crate::Unborrow;
7use core::marker::PhantomData; 3use core::marker::PhantomData;
8use core::ptr; 4use core::{ptr, slice};
9use core::slice; 5
10use embassy_hal_common::unborrow; 6use embassy_hal_common::unborrow;
11use embedded_storage::nor_flash::{ 7use embedded_storage::nor_flash::{
12 ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, 8 ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash,
13}; 9};
14 10
11use crate::peripherals::NVMC;
12use crate::{pac, Unborrow};
13
15pub const PAGE_SIZE: usize = 4096; 14pub const PAGE_SIZE: usize = 4096;
16pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; 15pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE;
17 16
diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs
index 8609ef8d4..d0bffb1e0 100644
--- a/embassy-nrf/src/ppi/dppi.rs
+++ b/embassy-nrf/src/ppi/dppi.rs
@@ -1,11 +1,9 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use crate::Unborrow;
4use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
5 4
6use crate::pac;
7
8use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; 5use super::{Channel, ConfigurableChannel, Event, Ppi, Task};
6use crate::{pac, Unborrow};
9 7
10const DPPI_ENABLE_BIT: u32 = 0x8000_0000; 8const DPPI_ENABLE_BIT: u32 = 0x8000_0000;
11const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; 9const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF;
@@ -21,12 +19,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> {
21} 19}
22 20
23impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { 21impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> {
24 pub fn new_one_to_two( 22 pub fn new_one_to_two(ch: impl Unborrow<Target = C> + 'd, event: Event, task1: Task, task2: Task) -> Self {
25 ch: impl Unborrow<Target = C> + 'd,
26 event: Event,
27 task1: Task,
28 task2: Task,
29 ) -> Self {
30 Ppi::new_many_to_many(ch, [event], [task1, task2]) 23 Ppi::new_many_to_many(ch, [event], [task1, task2])
31 } 24 }
32} 25}
@@ -64,9 +57,7 @@ impl<'d, C: ConfigurableChannel, const EVENT_COUNT: usize, const TASK_COUNT: usi
64 } 57 }
65} 58}
66 59
67impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> 60impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Ppi<'d, C, EVENT_COUNT, TASK_COUNT> {
68 Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
69{
70 /// Enables the channel. 61 /// Enables the channel.
71 pub fn enable(&mut self) { 62 pub fn enable(&mut self) {
72 let n = self.ch.number(); 63 let n = self.ch.number();
@@ -80,9 +71,7 @@ impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize>
80 } 71 }
81} 72}
82 73
83impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop 74impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> {
84 for Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
85{
86 fn drop(&mut self) { 75 fn drop(&mut self) {
87 self.disable(); 76 self.disable();
88 77
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs
index faabbf7ca..660db6410 100644
--- a/embassy-nrf/src/ppi/mod.rs
+++ b/embassy-nrf/src/ppi/mod.rs
@@ -15,12 +15,13 @@
15//! many tasks and events, but any single task or event can only be coupled with one channel. 15//! many tasks and events, but any single task or event can only be coupled with one channel.
16//! 16//!
17 17
18use crate::peripherals;
19use crate::Unborrow;
20use core::marker::PhantomData; 18use core::marker::PhantomData;
21use core::ptr::NonNull; 19use core::ptr::NonNull;
20
22use embassy_hal_common::unsafe_impl_unborrow; 21use embassy_hal_common::unsafe_impl_unborrow;
23 22
23use crate::{peripherals, Unborrow};
24
24#[cfg(feature = "_dppi")] 25#[cfg(feature = "_dppi")]
25mod dppi; 26mod dppi;
26#[cfg(feature = "_ppi")] 27#[cfg(feature = "_ppi")]
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs
index d832d69e7..e5c86d444 100644
--- a/embassy-nrf/src/ppi/ppi.rs
+++ b/embassy-nrf/src/ppi/ppi.rs
@@ -1,10 +1,9 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use crate::Unborrow;
4use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
5 4
6use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; 5use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task};
7use crate::pac; 6use crate::{pac, Unborrow};
8 7
9impl Task { 8impl Task {
10 fn reg_val(&self) -> u32 { 9 fn reg_val(&self) -> u32 {
@@ -55,12 +54,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> {
55 54
56#[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task 55#[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task
57impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { 56impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> {
58 pub fn new_one_to_two( 57 pub fn new_one_to_two(ch: impl Unborrow<Target = C> + 'd, event: Event, task1: Task, task2: Task) -> Self {
59 ch: impl Unborrow<Target = C> + 'd,
60 event: Event,
61 task1: Task,
62 task2: Task,
63 ) -> Self {
64 unborrow!(ch); 58 unborrow!(ch);
65 59
66 let r = regs(); 60 let r = regs();
@@ -76,9 +70,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> {
76 } 70 }
77} 71}
78 72
79impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> 73impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Ppi<'d, C, EVENT_COUNT, TASK_COUNT> {
80 Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
81{
82 /// Enables the channel. 74 /// Enables the channel.
83 pub fn enable(&mut self) { 75 pub fn enable(&mut self) {
84 let n = self.ch.number(); 76 let n = self.ch.number();
@@ -92,9 +84,7 @@ impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize>
92 } 84 }
93} 85}
94 86
95impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop 87impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> {
96 for Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
97{
98 fn drop(&mut self) { 88 fn drop(&mut self) {
99 self.disable(); 89 self.disable();
100 90
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index 3ed60ca05..9a78ff1f1 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -1,16 +1,16 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::Unborrow;
4use core::marker::PhantomData; 3use core::marker::PhantomData;
5use core::sync::atomic::{compiler_fence, Ordering}; 4use core::sync::atomic::{compiler_fence, Ordering};
5
6use embassy_hal_common::unborrow; 6use embassy_hal_common::unborrow;
7 7
8use crate::gpio::sealed::Pin as _; 8use crate::gpio::sealed::Pin as _;
9use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; 9use crate::gpio::{AnyPin, Pin as GpioPin, PselBits};
10use crate::interrupt::Interrupt; 10use crate::interrupt::Interrupt;
11use crate::pac;
12use crate::ppi::{Event, Task}; 11use crate::ppi::{Event, Task};
13use crate::util::slice_in_ram_or; 12use crate::util::slice_in_ram_or;
13use crate::{pac, Unborrow};
14 14
15/// SimplePwm is the traditional pwm interface you're probably used to, allowing 15/// SimplePwm is the traditional pwm interface you're probably used to, allowing
16/// to simply set a duty cycle across up to four channels. 16/// to simply set a duty cycle across up to four channels.
@@ -68,14 +68,7 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
68 config: Config, 68 config: Config,
69 ) -> Result<Self, Error> { 69 ) -> Result<Self, Error> {
70 unborrow!(ch0, ch1); 70 unborrow!(ch0, ch1);
71 Self::new_inner( 71 Self::new_inner(pwm, Some(ch0.degrade()), Some(ch1.degrade()), None, None, config)
72 pwm,
73 Some(ch0.degrade()),
74 Some(ch1.degrade()),
75 None,
76 None,
77 config,
78 )
79 } 72 }
80 73
81 /// Create a new 3-channel PWM 74 /// Create a new 3-channel PWM
@@ -171,10 +164,8 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
171 CounterMode::UpAndDown => w.updown().up_and_down(), 164 CounterMode::UpAndDown => w.updown().up_and_down(),
172 CounterMode::Up => w.updown().up(), 165 CounterMode::Up => w.updown().up(),
173 }); 166 });
174 r.prescaler 167 r.prescaler.write(|w| w.prescaler().bits(config.prescaler as u8));
175 .write(|w| w.prescaler().bits(config.prescaler as u8)); 168 r.countertop.write(|w| unsafe { w.countertop().bits(config.max_duty) });
176 r.countertop
177 .write(|w| unsafe { w.countertop().bits(config.max_duty) });
178 169
179 Ok(Self { 170 Ok(Self {
180 phantom: PhantomData, 171 phantom: PhantomData,
@@ -391,9 +382,7 @@ impl<'d, 's, T: Instance> SingleSequencer<'d, 's, T> {
391 pub fn start(&self, times: SingleSequenceMode) -> Result<(), Error> { 382 pub fn start(&self, times: SingleSequenceMode) -> Result<(), Error> {
392 let (start_seq, times) = match times { 383 let (start_seq, times) = match times {
393 SingleSequenceMode::Times(n) if n == 1 => (StartSequence::One, SequenceMode::Loop(1)), 384 SingleSequenceMode::Times(n) if n == 1 => (StartSequence::One, SequenceMode::Loop(1)),
394 SingleSequenceMode::Times(n) if n & 1 == 1 => { 385 SingleSequenceMode::Times(n) if n & 1 == 1 => (StartSequence::One, SequenceMode::Loop((n / 2) + 1)),
395 (StartSequence::One, SequenceMode::Loop((n / 2) + 1))
396 }
397 SingleSequenceMode::Times(n) => (StartSequence::Zero, SequenceMode::Loop(n / 2)), 386 SingleSequenceMode::Times(n) => (StartSequence::Zero, SequenceMode::Loop(n / 2)),
398 SingleSequenceMode::Infinite => (StartSequence::Zero, SequenceMode::Infinite), 387 SingleSequenceMode::Infinite => (StartSequence::Zero, SequenceMode::Infinite),
399 }; 388 };
@@ -424,11 +413,7 @@ pub struct Sequencer<'d, 's, T: Instance> {
424impl<'d, 's, T: Instance> Sequencer<'d, 's, T> { 413impl<'d, 's, T: Instance> Sequencer<'d, 's, T> {
425 /// Create a new double sequence. In the absence of sequence 1, sequence 0 414 /// Create a new double sequence. In the absence of sequence 1, sequence 0
426 /// will be used twice in the one loop. 415 /// will be used twice in the one loop.
427 pub fn new( 416 pub fn new(pwm: &'s mut SequencePwm<'d, T>, sequence0: Sequence<'s>, sequence1: Option<Sequence<'s>>) -> Self {
428 pwm: &'s mut SequencePwm<'d, T>,
429 sequence0: Sequence<'s>,
430 sequence1: Option<Sequence<'s>>,
431 ) -> Self {
432 Sequencer { 417 Sequencer {
433 _pwm: pwm, 418 _pwm: pwm,
434 sequence0, 419 sequence0,
@@ -457,42 +442,26 @@ impl<'d, 's, T: Instance> Sequencer<'d, 's, T> {
457 442
458 let r = T::regs(); 443 let r = T::regs();
459 444
460 r.seq0 445 r.seq0.refresh.write(|w| unsafe { w.bits(sequence0.config.refresh) });
461 .refresh 446 r.seq0.enddelay.write(|w| unsafe { w.bits(sequence0.config.end_delay) });
462 .write(|w| unsafe { w.bits(sequence0.config.refresh) }); 447 r.seq0.ptr.write(|w| unsafe { w.bits(sequence0.words.as_ptr() as u32) });
463 r.seq0 448 r.seq0.cnt.write(|w| unsafe { w.bits(sequence0.words.len() as u32) });
464 .enddelay
465 .write(|w| unsafe { w.bits(sequence0.config.end_delay) });
466 r.seq0
467 .ptr
468 .write(|w| unsafe { w.bits(sequence0.words.as_ptr() as u32) });
469 r.seq0
470 .cnt
471 .write(|w| unsafe { w.bits(sequence0.words.len() as u32) });
472 449
473 r.seq1 450 r.seq1.refresh.write(|w| unsafe { w.bits(alt_sequence.config.refresh) });
474 .refresh
475 .write(|w| unsafe { w.bits(alt_sequence.config.refresh) });
476 r.seq1 451 r.seq1
477 .enddelay 452 .enddelay
478 .write(|w| unsafe { w.bits(alt_sequence.config.end_delay) }); 453 .write(|w| unsafe { w.bits(alt_sequence.config.end_delay) });
479 r.seq1 454 r.seq1
480 .ptr 455 .ptr
481 .write(|w| unsafe { w.bits(alt_sequence.words.as_ptr() as u32) }); 456 .write(|w| unsafe { w.bits(alt_sequence.words.as_ptr() as u32) });
482 r.seq1 457 r.seq1.cnt.write(|w| unsafe { w.bits(alt_sequence.words.len() as u32) });
483 .cnt
484 .write(|w| unsafe { w.bits(alt_sequence.words.len() as u32) });
485 458
486 r.enable.write(|w| w.enable().enabled()); 459 r.enable.write(|w| w.enable().enabled());
487 460
488 // defensive before seqstart 461 // defensive before seqstart
489 compiler_fence(Ordering::SeqCst); 462 compiler_fence(Ordering::SeqCst);
490 463
491 let seqstart_index = if start_seq == StartSequence::One { 464 let seqstart_index = if start_seq == StartSequence::One { 1 } else { 0 };
492 1
493 } else {
494 0
495 };
496 465
497 match times { 466 match times {
498 // just the one time, no loop count 467 // just the one time, no loop count
@@ -604,10 +573,7 @@ pub enum CounterMode {
604impl<'d, T: Instance> SimplePwm<'d, T> { 573impl<'d, T: Instance> SimplePwm<'d, T> {
605 /// Create a new 1-channel PWM 574 /// Create a new 1-channel PWM
606 #[allow(unused_unsafe)] 575 #[allow(unused_unsafe)]
607 pub fn new_1ch( 576 pub fn new_1ch(pwm: impl Unborrow<Target = T> + 'd, ch0: impl Unborrow<Target = impl GpioPin> + 'd) -> Self {
608 pwm: impl Unborrow<Target = T> + 'd,
609 ch0: impl Unborrow<Target = impl GpioPin> + 'd,
610 ) -> Self {
611 unborrow!(ch0); 577 unborrow!(ch0);
612 Self::new_inner(pwm, Some(ch0.degrade()), None, None, None) 578 Self::new_inner(pwm, Some(ch0.degrade()), None, None, None)
613 } 579 }
@@ -632,13 +598,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
632 ch2: impl Unborrow<Target = impl GpioPin> + 'd, 598 ch2: impl Unborrow<Target = impl GpioPin> + 'd,
633 ) -> Self { 599 ) -> Self {
634 unborrow!(ch0, ch1, ch2); 600 unborrow!(ch0, ch1, ch2);
635 Self::new_inner( 601 Self::new_inner(pwm, Some(ch0.degrade()), Some(ch1.degrade()), Some(ch2.degrade()), None)
636 pwm,
637 Some(ch0.degrade()),
638 Some(ch1.degrade()),
639 Some(ch2.degrade()),
640 None,
641 )
642 } 602 }
643 603
644 /// Create a new 4-channel PWM 604 /// Create a new 4-channel PWM
@@ -709,9 +669,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
709 // Enable 669 // Enable
710 r.enable.write(|w| w.enable().enabled()); 670 r.enable.write(|w| w.enable().enabled());
711 671
712 r.seq0 672 r.seq0.ptr.write(|w| unsafe { w.bits((&pwm.duty).as_ptr() as u32) });
713 .ptr
714 .write(|w| unsafe { w.bits((&pwm.duty).as_ptr() as u32) });
715 673
716 r.seq0.cnt.write(|w| unsafe { w.bits(4) }); 674 r.seq0.cnt.write(|w| unsafe { w.bits(4) });
717 r.seq0.refresh.write(|w| unsafe { w.bits(0) }); 675 r.seq0.refresh.write(|w| unsafe { w.bits(0) });
@@ -750,9 +708,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
750 self.duty[channel] = duty & 0x7FFF; 708 self.duty[channel] = duty & 0x7FFF;
751 709
752 // reload ptr in case self was moved 710 // reload ptr in case self was moved
753 r.seq0 711 r.seq0.ptr.write(|w| unsafe { w.bits((&self.duty).as_ptr() as u32) });
754 .ptr
755 .write(|w| unsafe { w.bits((&self.duty).as_ptr() as u32) });
756 712
757 // defensive before seqstart 713 // defensive before seqstart
758 compiler_fence(Ordering::SeqCst); 714 compiler_fence(Ordering::SeqCst);
diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs
index b230043b4..e254328a6 100644
--- a/embassy-nrf/src/qdec.rs
+++ b/embassy-nrf/src/qdec.rs
@@ -1,19 +1,18 @@
1//! Quadrature decoder interface 1//! Quadrature decoder interface
2 2
3use crate::gpio::sealed::Pin as _;
4use crate::gpio::{AnyPin, Pin as GpioPin};
5use crate::interrupt;
6use crate::pac;
7use crate::peripherals::QDEC;
8
9use crate::interrupt::InterruptExt;
10use crate::Unborrow;
11use core::marker::PhantomData; 3use core::marker::PhantomData;
12use core::task::Poll; 4use core::task::Poll;
5
13use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
14use embassy_hal_common::unborrow; 7use embassy_hal_common::unborrow;
15use futures::future::poll_fn; 8use futures::future::poll_fn;
16 9
10use crate::gpio::sealed::Pin as _;
11use crate::gpio::{AnyPin, Pin as GpioPin};
12use crate::interrupt::InterruptExt;
13use crate::peripherals::QDEC;
14use crate::{interrupt, pac, Unborrow};
15
17/// Quadrature decoder 16/// Quadrature decoder
18pub struct Qdec<'d> { 17pub struct Qdec<'d> {
19 phantom: PhantomData<&'d QDEC>, 18 phantom: PhantomData<&'d QDEC>,
@@ -63,14 +62,7 @@ impl<'d> Qdec<'d> {
63 config: Config, 62 config: Config,
64 ) -> Self { 63 ) -> Self {
65 unborrow!(a, b, led); 64 unborrow!(a, b, led);
66 Self::new_inner( 65 Self::new_inner(qdec, irq, a.degrade(), b.degrade(), Some(led.degrade()), config)
67 qdec,
68 irq,
69 a.degrade(),
70 b.degrade(),
71 Some(led.degrade()),
72 config,
73 )
74 } 66 }
75 67
76 fn new_inner( 68 fn new_inner(
@@ -139,9 +131,7 @@ impl<'d> Qdec<'d> {
139 }); 131 });
140 irq.enable(); 132 irq.enable();
141 133
142 Self { 134 Self { phantom: PhantomData }
143 phantom: PhantomData,
144 }
145 } 135 }
146 136
147 /// Perform an asynchronous read of the decoder. 137 /// Perform an asynchronous read of the decoder.
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs
index adb0d8386..92fa79b8a 100644
--- a/embassy-nrf/src/qspi.rs
+++ b/embassy-nrf/src/qspi.rs
@@ -1,22 +1,20 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::interrupt::{Interrupt, InterruptExt};
4use crate::Unborrow;
5use core::marker::PhantomData; 3use core::marker::PhantomData;
6use core::ptr; 4use core::ptr;
7use core::task::Poll; 5use core::task::Poll;
6
8use embassy_hal_common::drop::DropBomb; 7use embassy_hal_common::drop::DropBomb;
9use embassy_hal_common::unborrow; 8use embassy_hal_common::unborrow;
10use futures::future::poll_fn; 9use futures::future::poll_fn;
11 10
12use crate::gpio::sealed::Pin as _; 11use crate::gpio::sealed::Pin as _;
13use crate::gpio::{self, Pin as GpioPin}; 12use crate::gpio::{self, Pin as GpioPin};
14use crate::pac; 13use crate::interrupt::{Interrupt, InterruptExt};
15 14pub use crate::pac::qspi::ifconfig0::{
16pub use crate::pac::qspi::ifconfig0::ADDRMODE_A as AddressMode; 15 ADDRMODE_A as AddressMode, PPSIZE_A as WritePageSize, READOC_A as ReadOpcode, WRITEOC_A as WriteOpcode,
17pub use crate::pac::qspi::ifconfig0::PPSIZE_A as WritePageSize; 16};
18pub use crate::pac::qspi::ifconfig0::READOC_A as ReadOpcode; 17use crate::{pac, Unborrow};
19pub use crate::pac::qspi::ifconfig0::WRITEOC_A as WriteOpcode;
20 18
21// TODO 19// TODO
22// - config: 20// - config:
@@ -168,12 +166,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> {
168 } 166 }
169 } 167 }
170 168
171 pub async fn custom_instruction( 169 pub async fn custom_instruction(&mut self, opcode: u8, req: &[u8], resp: &mut [u8]) -> Result<(), Error> {
172 &mut self,
173 opcode: u8,
174 req: &[u8],
175 resp: &mut [u8],
176 ) -> Result<(), Error> {
177 let bomb = DropBomb::new(); 170 let bomb = DropBomb::new();
178 171
179 let len = core::cmp::max(req.len(), resp.len()) as u8; 172 let len = core::cmp::max(req.len(), resp.len()) as u8;
@@ -188,12 +181,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> {
188 Ok(()) 181 Ok(())
189 } 182 }
190 183
191 pub fn blocking_custom_instruction( 184 pub fn blocking_custom_instruction(&mut self, opcode: u8, req: &[u8], resp: &mut [u8]) -> Result<(), Error> {
192 &mut self,
193 opcode: u8,
194 req: &[u8],
195 resp: &mut [u8],
196 ) -> Result<(), Error> {
197 let len = core::cmp::max(req.len(), resp.len()) as u8; 185 let len = core::cmp::max(req.len(), resp.len()) as u8;
198 self.custom_instruction_start(opcode, req, len)?; 186 self.custom_instruction_start(opcode, req, len)?;
199 187
@@ -292,15 +280,9 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> {
292 280
293 let r = T::regs(); 281 let r = T::regs();
294 282
295 r.read 283 r.read.src.write(|w| unsafe { w.src().bits(address as u32) });
296 .src 284 r.read.dst.write(|w| unsafe { w.dst().bits(data.as_ptr() as u32) });
297 .write(|w| unsafe { w.src().bits(address as u32) }); 285 r.read.cnt.write(|w| unsafe { w.cnt().bits(data.len() as u32) });
298 r.read
299 .dst
300 .write(|w| unsafe { w.dst().bits(data.as_ptr() as u32) });
301 r.read
302 .cnt
303 .write(|w| unsafe { w.cnt().bits(data.len() as u32) });
304 286
305 r.events_ready.reset(); 287 r.events_ready.reset();
306 r.intenset.write(|w| w.ready().set()); 288 r.intenset.write(|w| w.ready().set());
@@ -322,15 +304,9 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> {
322 } 304 }
323 305
324 let r = T::regs(); 306 let r = T::regs();
325 r.write 307 r.write.src.write(|w| unsafe { w.src().bits(data.as_ptr() as u32) });
326 .src 308 r.write.dst.write(|w| unsafe { w.dst().bits(address as u32) });
327 .write(|w| unsafe { w.src().bits(data.as_ptr() as u32) }); 309 r.write.cnt.write(|w| unsafe { w.cnt().bits(data.len() as u32) });
328 r.write
329 .dst
330 .write(|w| unsafe { w.dst().bits(address as u32) });
331 r.write
332 .cnt
333 .write(|w| unsafe { w.cnt().bits(data.len() as u32) });
334 310
335 r.events_ready.reset(); 311 r.events_ready.reset();
336 r.intenset.write(|w| w.ready().set()); 312 r.intenset.write(|w| w.ready().set());
@@ -346,9 +322,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> {
346 } 322 }
347 323
348 let r = T::regs(); 324 let r = T::regs();
349 r.erase 325 r.erase.ptr.write(|w| unsafe { w.ptr().bits(address as u32) });
350 .ptr
351 .write(|w| unsafe { w.ptr().bits(address as u32) });
352 r.erase.len.write(|w| w.len()._4kb()); 326 r.erase.len.write(|w| w.len()._4kb());
353 327
354 r.events_ready.reset(); 328 r.events_ready.reset();
@@ -458,9 +432,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Drop for Qspi<'d, T, FLASH_SIZE>
458 } 432 }
459} 433}
460 434
461use embedded_storage::nor_flash::{ 435use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash};
462 ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash,
463};
464 436
465impl<'d, T: Instance, const FLASH_SIZE: usize> ErrorType for Qspi<'d, T, FLASH_SIZE> { 437impl<'d, T: Instance, const FLASH_SIZE: usize> ErrorType for Qspi<'d, T, FLASH_SIZE> {
466 type Error = Error; 438 type Error = Error;
diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs
index 43cf805fd..e68ed912e 100644
--- a/embassy-nrf/src/rng.rs
+++ b/embassy-nrf/src/rng.rs
@@ -1,19 +1,16 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2use core::ptr; 2use core::ptr;
3use core::sync::atomic::AtomicPtr; 3use core::sync::atomic::{AtomicPtr, Ordering};
4use core::sync::atomic::Ordering;
5use core::task::Poll; 4use core::task::Poll;
6 5
7use crate::interrupt::InterruptExt;
8use crate::Unborrow;
9use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
10use embassy_hal_common::drop::OnDrop; 7use embassy_hal_common::drop::OnDrop;
11use embassy_hal_common::unborrow; 8use embassy_hal_common::unborrow;
12use futures::future::poll_fn; 9use futures::future::poll_fn;
13 10
14use crate::interrupt; 11use crate::interrupt::InterruptExt;
15use crate::pac;
16use crate::peripherals::RNG; 12use crate::peripherals::RNG;
13use crate::{interrupt, pac, Unborrow};
17 14
18impl RNG { 15impl RNG {
19 fn regs() -> &'static pac::rng::RegisterBlock { 16 fn regs() -> &'static pac::rng::RegisterBlock {
@@ -48,10 +45,7 @@ impl<'d> Rng<'d> {
48 /// e.g. using `mem::forget`. 45 /// e.g. using `mem::forget`.
49 /// 46 ///
50 /// The synchronous API is safe. 47 /// The synchronous API is safe.
51 pub fn new( 48 pub fn new(_rng: impl Unborrow<Target = RNG> + 'd, irq: impl Unborrow<Target = interrupt::RNG> + 'd) -> Self {
52 _rng: impl Unborrow<Target = RNG> + 'd,
53 irq: impl Unborrow<Target = interrupt::RNG> + 'd,
54 ) -> Self {
55 unborrow!(irq); 49 unborrow!(irq);
56 50
57 let this = Self { 51 let this = Self {
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index 915115a12..7d39e33f8 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -1,29 +1,23 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::interrupt::InterruptExt;
4use crate::Unborrow;
5use core::marker::PhantomData; 3use core::marker::PhantomData;
6use core::sync::atomic::{compiler_fence, Ordering}; 4use core::sync::atomic::{compiler_fence, Ordering};
7use core::task::Poll; 5use core::task::Poll;
6
8use embassy::waitqueue::AtomicWaker; 7use embassy::waitqueue::AtomicWaker;
9use embassy_hal_common::unborrow; 8use embassy_hal_common::unborrow;
10use futures::future::poll_fn; 9use futures::future::poll_fn;
11
12use crate::interrupt;
13use crate::ppi::{ConfigurableChannel, Event, Ppi, Task};
14use crate::timer::{Frequency, Instance as TimerInstance, Timer};
15use crate::{pac, peripherals};
16
17use pac::{saadc, SAADC}; 10use pac::{saadc, SAADC};
18 11use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A};
19// We treat the positive and negative channels with the same enum values to keep our type tidy and given they are the same 12// We treat the positive and negative channels with the same enum values to keep our type tidy and given they are the same
20pub(crate) use saadc::ch::pselp::PSELP_A as InputChannel; 13pub(crate) use saadc::ch::pselp::PSELP_A as InputChannel;
14use saadc::oversample::OVERSAMPLE_A;
15use saadc::resolution::VAL_A;
21 16
22use saadc::{ 17use crate::interrupt::InterruptExt;
23 ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}, 18use crate::ppi::{ConfigurableChannel, Event, Ppi, Task};
24 oversample::OVERSAMPLE_A, 19use crate::timer::{Frequency, Instance as TimerInstance, Timer};
25 resolution::VAL_A, 20use crate::{interrupt, pac, peripherals, Unborrow};
26};
27 21
28#[derive(Debug, Clone, Copy, PartialEq, Eq)] 22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29#[cfg_attr(feature = "defmt", derive(defmt::Format))] 23#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -178,23 +172,17 @@ impl<'d, const N: usize> Saadc<'d, N> {
178 172
179 let r = unsafe { &*SAADC::ptr() }; 173 let r = unsafe { &*SAADC::ptr() };
180 174
181 let Config { 175 let Config { resolution, oversample } = config;
182 resolution,
183 oversample,
184 } = config;
185 176
186 // Configure channels 177 // Configure channels
187 r.enable.write(|w| w.enable().enabled()); 178 r.enable.write(|w| w.enable().enabled());
188 r.resolution.write(|w| w.val().variant(resolution.into())); 179 r.resolution.write(|w| w.val().variant(resolution.into()));
189 r.oversample 180 r.oversample.write(|w| w.oversample().variant(oversample.into()));
190 .write(|w| w.oversample().variant(oversample.into()));
191 181
192 for (i, cc) in channel_configs.iter().enumerate() { 182 for (i, cc) in channel_configs.iter().enumerate() {
193 r.ch[i].pselp.write(|w| w.pselp().variant(cc.p_channel)); 183 r.ch[i].pselp.write(|w| w.pselp().variant(cc.p_channel));
194 if let Some(n_channel) = cc.n_channel { 184 if let Some(n_channel) = cc.n_channel {
195 r.ch[i] 185 r.ch[i].pseln.write(|w| unsafe { w.pseln().bits(n_channel as u8) });
196 .pseln
197 .write(|w| unsafe { w.pseln().bits(n_channel as u8) });
198 } 186 }
199 r.ch[i].config.write(|w| { 187 r.ch[i].config.write(|w| {
200 w.refsel().variant(cc.reference.into()); 188 w.refsel().variant(cc.reference.into());
@@ -223,9 +211,7 @@ impl<'d, const N: usize> Saadc<'d, N> {
223 irq.unpend(); 211 irq.unpend();
224 irq.enable(); 212 irq.enable();
225 213
226 Self { 214 Self { phantom: PhantomData }
227 phantom: PhantomData,
228 }
229 } 215 }
230 216
231 fn on_interrupt(_ctx: *mut ()) { 217 fn on_interrupt(_ctx: *mut ()) {
@@ -285,12 +271,8 @@ impl<'d, const N: usize> Saadc<'d, N> {
285 let r = Self::regs(); 271 let r = Self::regs();
286 272
287 // Set up the DMA 273 // Set up the DMA
288 r.result 274 r.result.ptr.write(|w| unsafe { w.ptr().bits(buf.as_mut_ptr() as u32) });
289 .ptr 275 r.result.maxcnt.write(|w| unsafe { w.maxcnt().bits(N as _) });
290 .write(|w| unsafe { w.ptr().bits(buf.as_mut_ptr() as u32) });
291 r.result
292 .maxcnt
293 .write(|w| unsafe { w.maxcnt().bits(N as _) });
294 276
295 // Reset and enable the end event 277 // Reset and enable the end event
296 r.events_end.reset(); 278 r.events_end.reset();
@@ -353,11 +335,8 @@ impl<'d, const N: usize> Saadc<'d, N> {
353 // We want the task start to effectively short with the last one ending so 335 // We want the task start to effectively short with the last one ending so
354 // we don't miss any samples. It'd be great for the SAADC to offer a SHORTS 336 // we don't miss any samples. It'd be great for the SAADC to offer a SHORTS
355 // register instead, but it doesn't, so we must use PPI. 337 // register instead, but it doesn't, so we must use PPI.
356 let mut start_ppi = Ppi::new_one_to_one( 338 let mut start_ppi =
357 ppi_ch1, 339 Ppi::new_one_to_one(ppi_ch1, Event::from_reg(&r.events_end), Task::from_reg(&r.tasks_start));
358 Event::from_reg(&r.events_end),
359 Task::from_reg(&r.tasks_start),
360 );
361 start_ppi.enable(); 340 start_ppi.enable();
362 341
363 let mut timer = Timer::new(timer); 342 let mut timer = Timer::new(timer);
@@ -365,11 +344,7 @@ impl<'d, const N: usize> Saadc<'d, N> {
365 timer.cc(0).write(sample_counter); 344 timer.cc(0).write(sample_counter);
366 timer.cc(0).short_compare_clear(); 345 timer.cc(0).short_compare_clear();
367 346
368 let mut sample_ppi = Ppi::new_one_to_one( 347 let mut sample_ppi = Ppi::new_one_to_one(ppi_ch2, timer.cc(0).event_compare(), Task::from_reg(&r.tasks_sample));
369 ppi_ch2,
370 timer.cc(0).event_compare(),
371 Task::from_reg(&r.tasks_sample),
372 );
373 348
374 timer.start(); 349 timer.start();
375 350
@@ -417,9 +392,7 @@ impl<'d, const N: usize> Saadc<'d, N> {
417 r.result 392 r.result
418 .ptr 393 .ptr
419 .write(|w| unsafe { w.ptr().bits(bufs[0].as_mut_ptr() as u32) }); 394 .write(|w| unsafe { w.ptr().bits(bufs[0].as_mut_ptr() as u32) });
420 r.result 395 r.result.maxcnt.write(|w| unsafe { w.maxcnt().bits((N0 * N) as _) });
421 .maxcnt
422 .write(|w| unsafe { w.maxcnt().bits((N0 * N) as _) });
423 396
424 // Reset and enable the events 397 // Reset and enable the events
425 r.events_end.reset(); 398 r.events_end.reset();
@@ -500,8 +473,7 @@ impl<'d> Saadc<'d, 1> {
500 ) where 473 ) where
501 S: FnMut(&[[i16; 1]]) -> SamplerState, 474 S: FnMut(&[[i16; 1]]) -> SamplerState,
502 { 475 {
503 self.run_sampler(bufs, Some(sample_rate_divisor), || {}, sampler) 476 self.run_sampler(bufs, Some(sample_rate_divisor), || {}, sampler).await;
504 .await;
505 } 477 }
506} 478}
507 479
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index 7b28373df..efccfeca3 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -1,23 +1,20 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::interrupt::InterruptExt;
4use crate::Unborrow;
5use core::marker::PhantomData; 3use core::marker::PhantomData;
6use core::sync::atomic::{compiler_fence, Ordering}; 4use core::sync::atomic::{compiler_fence, Ordering};
7use core::task::Poll; 5use core::task::Poll;
6
8use embassy_hal_common::unborrow; 7use embassy_hal_common::unborrow;
8pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
9use futures::future::poll_fn; 9use futures::future::poll_fn;
10pub use pac::spim0::frequency::FREQUENCY_A as Frequency;
10 11
11use crate::chip::FORCE_COPY_BUFFER_SIZE; 12use crate::chip::FORCE_COPY_BUFFER_SIZE;
12use crate::gpio::sealed::Pin as _; 13use crate::gpio::sealed::Pin as _;
13use crate::gpio::{self, AnyPin}; 14use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits};
14use crate::gpio::{Pin as GpioPin, PselBits}; 15use crate::interrupt::{Interrupt, InterruptExt};
15use crate::interrupt::Interrupt; 16use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut};
16use crate::util::{slice_ptr_parts, slice_ptr_parts_mut}; 17use crate::{pac, Unborrow};
17use crate::{pac, util::slice_in_ram_or};
18
19pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
20pub use pac::spim0::frequency::FREQUENCY_A as Frequency;
21 18
22#[derive(Debug, Clone, Copy, PartialEq, Eq)] 19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23#[cfg_attr(feature = "defmt", derive(defmt::Format))] 20#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -183,9 +180,7 @@ impl<'d, T: Instance> Spim<'d, T> {
183 irq.unpend(); 180 irq.unpend();
184 irq.enable(); 181 irq.enable();
185 182
186 Self { 183 Self { phantom: PhantomData }
187 phantom: PhantomData,
188 }
189 } 184 }
190 185
191 fn on_interrupt(_: *mut ()) { 186 fn on_interrupt(_: *mut ()) {
@@ -295,11 +290,7 @@ impl<'d, T: Instance> Spim<'d, T> {
295 } 290 }
296 291
297 /// Same as [`blocking_transfer`](Spim::blocking_transfer) but will fail instead of copying data into RAM. Consult the module level documentation to learn more. 292 /// Same as [`blocking_transfer`](Spim::blocking_transfer) but will fail instead of copying data into RAM. Consult the module level documentation to learn more.
298 pub fn blocking_transfer_from_ram( 293 pub fn blocking_transfer_from_ram(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Error> {
299 &mut self,
300 read: &mut [u8],
301 write: &[u8],
302 ) -> Result<(), Error> {
303 self.blocking_inner(read, write) 294 self.blocking_inner(read, write)
304 } 295 }
305 296
diff --git a/embassy-nrf/src/temp.rs b/embassy-nrf/src/temp.rs
index e5e5f29ab..43ba3e042 100644
--- a/embassy-nrf/src/temp.rs
+++ b/embassy-nrf/src/temp.rs
@@ -1,18 +1,18 @@
1//! Temperature sensor interface. 1//! Temperature sensor interface.
2 2
3use crate::interrupt;
4use crate::pac;
5use crate::peripherals::TEMP;
6
7use crate::interrupt::InterruptExt;
8use crate::Unborrow;
9use core::marker::PhantomData; 3use core::marker::PhantomData;
10use core::task::Poll; 4use core::task::Poll;
5
11use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
12use embassy_hal_common::{drop::OnDrop, unborrow}; 7use embassy_hal_common::drop::OnDrop;
8use embassy_hal_common::unborrow;
13use fixed::types::I30F2; 9use fixed::types::I30F2;
14use futures::future::poll_fn; 10use futures::future::poll_fn;
15 11
12use crate::interrupt::InterruptExt;
13use crate::peripherals::TEMP;
14use crate::{interrupt, pac, Unborrow};
15
16/// Integrated temperature sensor. 16/// Integrated temperature sensor.
17pub struct Temp<'d> { 17pub struct Temp<'d> {
18 _temp: PhantomData<&'d TEMP>, 18 _temp: PhantomData<&'d TEMP>,
@@ -22,10 +22,7 @@ pub struct Temp<'d> {
22static WAKER: AtomicWaker = AtomicWaker::new(); 22static WAKER: AtomicWaker = AtomicWaker::new();
23 23
24impl<'d> Temp<'d> { 24impl<'d> Temp<'d> {
25 pub fn new( 25 pub fn new(_t: impl Unborrow<Target = TEMP> + 'd, irq: impl Unborrow<Target = interrupt::TEMP> + 'd) -> Self {
26 _t: impl Unborrow<Target = TEMP> + 'd,
27 irq: impl Unborrow<Target = interrupt::TEMP> + 'd,
28 ) -> Self {
29 unborrow!(_t, irq); 26 unborrow!(_t, irq);
30 27
31 // Enable interrupt that signals temperature values 28 // Enable interrupt that signals temperature values
diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs
index 8f1758146..f7b3345b2 100644
--- a/embassy-nrf/src/time_driver.rs
+++ b/embassy-nrf/src/time_driver.rs
@@ -1,14 +1,14 @@
1use crate::interrupt::{Interrupt, InterruptExt};
2use core::cell::Cell; 1use core::cell::Cell;
3use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; 2use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering};
4use core::{mem, ptr}; 3use core::{mem, ptr};
4
5use critical_section::CriticalSection; 5use critical_section::CriticalSection;
6use embassy::blocking_mutex::raw::CriticalSectionRawMutex; 6use embassy::blocking_mutex::raw::CriticalSectionRawMutex;
7use embassy::blocking_mutex::CriticalSectionMutex as Mutex; 7use embassy::blocking_mutex::CriticalSectionMutex as Mutex;
8use embassy::time::driver::{AlarmHandle, Driver}; 8use embassy::time::driver::{AlarmHandle, Driver};
9 9
10use crate::interrupt; 10use crate::interrupt::{Interrupt, InterruptExt};
11use crate::pac; 11use crate::{interrupt, pac};
12 12
13fn rtc() -> &'static pac::rtc0::RegisterBlock { 13fn rtc() -> &'static pac::rtc0::RegisterBlock {
14 unsafe { &*pac::RTC1::ptr() } 14 unsafe { &*pac::RTC1::ptr() }
@@ -220,15 +220,13 @@ impl Driver for RtcDriver {
220 } 220 }
221 221
222 unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { 222 unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
223 let id = self 223 let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| {
224 .alarm_count 224 if x < ALARM_COUNT as u8 {
225 .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { 225 Some(x + 1)
226 if x < ALARM_COUNT as u8 { 226 } else {
227 Some(x + 1) 227 None
228 } else { 228 }
229 None 229 });
230 }
231 });
232 230
233 match id { 231 match id {
234 Ok(id) => Some(AlarmHandle::new(id)), 232 Ok(id) => Some(AlarmHandle::new(id)),
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs
index 588654f96..c8c36dfae 100644
--- a/embassy-nrf/src/timer.rs
+++ b/embassy-nrf/src/timer.rs
@@ -3,16 +3,14 @@
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::task::Poll; 4use core::task::Poll;
5 5
6use crate::interrupt::Interrupt;
7use crate::interrupt::InterruptExt;
8use crate::Unborrow;
9use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
10use embassy_hal_common::drop::OnDrop; 7use embassy_hal_common::drop::OnDrop;
11use embassy_hal_common::unborrow; 8use embassy_hal_common::unborrow;
12use futures::future::poll_fn; 9use futures::future::poll_fn;
13 10
14use crate::pac; 11use crate::interrupt::{Interrupt, InterruptExt};
15use crate::ppi::{Event, Task}; 12use crate::ppi::{Event, Task};
13use crate::{pac, Unborrow};
16 14
17pub(crate) mod sealed { 15pub(crate) mod sealed {
18 16
@@ -131,9 +129,7 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> {
131 fn new_irqless(_timer: impl Unborrow<Target = T> + 'd) -> Self { 129 fn new_irqless(_timer: impl Unborrow<Target = T> + 'd) -> Self {
132 let regs = T::regs(); 130 let regs = T::regs();
133 131
134 let mut this = Self { 132 let mut this = Self { phantom: PhantomData };
135 phantom: PhantomData,
136 };
137 133
138 // Stop the timer before doing anything else, 134 // Stop the timer before doing anything else,
139 // since changing BITMODE while running can cause 'unpredictable behaviour' according to the specification. 135 // since changing BITMODE while running can cause 'unpredictable behaviour' according to the specification.
@@ -233,11 +229,7 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> {
233 /// Panics if `n` >= the number of CC registers this timer has (4 for a normal timer, 6 for an extended timer). 229 /// Panics if `n` >= the number of CC registers this timer has (4 for a normal timer, 6 for an extended timer).
234 pub fn cc(&mut self, n: usize) -> Cc<T, I> { 230 pub fn cc(&mut self, n: usize) -> Cc<T, I> {
235 if n >= T::CCS { 231 if n >= T::CCS {
236 panic!( 232 panic!("Cannot get CC register {} of timer with {} CC registers.", n, T::CCS);
237 "Cannot get CC register {} of timer with {} CC registers.",
238 n,
239 T::CCS
240 );
241 } 233 }
242 Cc { 234 Cc {
243 n, 235 n,
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index 2337ae219..c3921104e 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -6,12 +6,12 @@
6//! 6//!
7//! - nRF52832: Section 33 7//! - nRF52832: Section 33
8//! - nRF52840: Section 6.31 8//! - nRF52840: Section 6.31
9use crate::interrupt::{Interrupt, InterruptExt};
10use crate::Unborrow;
11use core::future::Future; 9use core::future::Future;
12use core::marker::PhantomData; 10use core::marker::PhantomData;
13use core::sync::atomic::{compiler_fence, Ordering::SeqCst}; 11use core::sync::atomic::compiler_fence;
12use core::sync::atomic::Ordering::SeqCst;
14use core::task::Poll; 13use core::task::Poll;
14
15#[cfg(feature = "time")] 15#[cfg(feature = "time")]
16use embassy::time::{Duration, Instant}; 16use embassy::time::{Duration, Instant};
17use embassy::waitqueue::AtomicWaker; 17use embassy::waitqueue::AtomicWaker;
@@ -19,10 +19,10 @@ use embassy_hal_common::unborrow;
19use futures::future::poll_fn; 19use futures::future::poll_fn;
20 20
21use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; 21use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
22use crate::gpio;
23use crate::gpio::Pin as GpioPin; 22use crate::gpio::Pin as GpioPin;
24use crate::pac; 23use crate::interrupt::{Interrupt, InterruptExt};
25use crate::util::{slice_in_ram, slice_in_ram_or}; 24use crate::util::{slice_in_ram, slice_in_ram_or};
25use crate::{gpio, pac, Unborrow};
26 26
27pub enum Frequency { 27pub enum Frequency {
28 #[doc = "26738688: 100 kbps"] 28 #[doc = "26738688: 100 kbps"]
@@ -134,9 +134,7 @@ impl<'d, T: Instance> Twim<'d, T> {
134 irq.unpend(); 134 irq.unpend();
135 irq.enable(); 135 irq.enable();
136 136
137 Self { 137 Self { phantom: PhantomData }
138 phantom: PhantomData,
139 }
140 } 138 }
141 139
142 fn on_interrupt(_: *mut ()) { 140 fn on_interrupt(_: *mut ()) {
@@ -319,12 +317,7 @@ impl<'d, T: Instance> Twim<'d, T> {
319 }) 317 })
320 } 318 }
321 319
322 fn setup_write_from_ram( 320 fn setup_write_from_ram(&mut self, address: u8, buffer: &[u8], inten: bool) -> Result<(), Error> {
323 &mut self,
324 address: u8,
325 buffer: &[u8],
326 inten: bool,
327 ) -> Result<(), Error> {
328 let r = T::regs(); 321 let r = T::regs();
329 322
330 compiler_fence(SeqCst); 323 compiler_fence(SeqCst);
@@ -506,12 +499,7 @@ impl<'d, T: Instance> Twim<'d, T> {
506 /// 499 ///
507 /// The buffers must have a length of at most 255 bytes on the nRF52832 500 /// The buffers must have a length of at most 255 bytes on the nRF52832
508 /// and at most 65535 bytes on the nRF52840. 501 /// and at most 65535 bytes on the nRF52840.
509 pub fn blocking_write_read( 502 pub fn blocking_write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Error> {
510 &mut self,
511 address: u8,
512 wr_buffer: &[u8],
513 rd_buffer: &mut [u8],
514 ) -> Result<(), Error> {
515 self.setup_write_read(address, wr_buffer, rd_buffer, false)?; 503 self.setup_write_read(address, wr_buffer, rd_buffer, false)?;
516 self.blocking_wait(); 504 self.blocking_wait();
517 compiler_fence(SeqCst); 505 compiler_fence(SeqCst);
@@ -543,12 +531,7 @@ impl<'d, T: Instance> Twim<'d, T> {
543 /// 531 ///
544 /// See [`blocking_write`]. 532 /// See [`blocking_write`].
545 #[cfg(feature = "time")] 533 #[cfg(feature = "time")]
546 pub fn blocking_write_timeout( 534 pub fn blocking_write_timeout(&mut self, address: u8, buffer: &[u8], timeout: Duration) -> Result<(), Error> {
547 &mut self,
548 address: u8,
549 buffer: &[u8],
550 timeout: Duration,
551 ) -> Result<(), Error> {
552 self.setup_write(address, buffer, false)?; 535 self.setup_write(address, buffer, false)?;
553 self.blocking_wait_timeout(timeout)?; 536 self.blocking_wait_timeout(timeout)?;
554 compiler_fence(SeqCst); 537 compiler_fence(SeqCst);
@@ -578,12 +561,7 @@ impl<'d, T: Instance> Twim<'d, T> {
578 /// The buffer must have a length of at most 255 bytes on the nRF52832 561 /// The buffer must have a length of at most 255 bytes on the nRF52832
579 /// and at most 65535 bytes on the nRF52840. 562 /// and at most 65535 bytes on the nRF52840.
580 #[cfg(feature = "time")] 563 #[cfg(feature = "time")]
581 pub fn blocking_read_timeout( 564 pub fn blocking_read_timeout(&mut self, address: u8, buffer: &mut [u8], timeout: Duration) -> Result<(), Error> {
582 &mut self,
583 address: u8,
584 buffer: &mut [u8],
585 timeout: Duration,
586 ) -> Result<(), Error> {
587 self.setup_read(address, buffer, false)?; 565 self.setup_read(address, buffer, false)?;
588 self.blocking_wait_timeout(timeout)?; 566 self.blocking_wait_timeout(timeout)?;
589 compiler_fence(SeqCst); 567 compiler_fence(SeqCst);
@@ -662,12 +640,7 @@ impl<'d, T: Instance> Twim<'d, T> {
662 Ok(()) 640 Ok(())
663 } 641 }
664 642
665 pub async fn write_read( 643 pub async fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Error> {
666 &mut self,
667 address: u8,
668 wr_buffer: &[u8],
669 rd_buffer: &mut [u8],
670 ) -> Result<(), Error> {
671 self.setup_write_read(address, wr_buffer, rd_buffer, true)?; 644 self.setup_write_read(address, wr_buffer, rd_buffer, true)?;
672 self.async_wait().await; 645 self.async_wait().await;
673 compiler_fence(SeqCst); 646 compiler_fence(SeqCst);
@@ -786,12 +759,7 @@ mod eh02 {
786 impl<'a, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for Twim<'a, T> { 759 impl<'a, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for Twim<'a, T> {
787 type Error = Error; 760 type Error = Error;
788 761
789 fn write_read<'w>( 762 fn write_read<'w>(&mut self, addr: u8, bytes: &'w [u8], buffer: &'w mut [u8]) -> Result<(), Error> {
790 &mut self,
791 addr: u8,
792 bytes: &'w [u8],
793 buffer: &'w mut [u8],
794 ) -> Result<(), Error> {
795 self.blocking_write_read(addr, bytes, buffer) 763 self.blocking_write_read(addr, bytes, buffer)
796 } 764 }
797 } 765 }
@@ -809,12 +777,12 @@ mod eh1 {
809 Self::Transmit => embedded_hal_1::i2c::ErrorKind::Other, 777 Self::Transmit => embedded_hal_1::i2c::ErrorKind::Other,
810 Self::Receive => embedded_hal_1::i2c::ErrorKind::Other, 778 Self::Receive => embedded_hal_1::i2c::ErrorKind::Other,
811 Self::DMABufferNotInDataMemory => embedded_hal_1::i2c::ErrorKind::Other, 779 Self::DMABufferNotInDataMemory => embedded_hal_1::i2c::ErrorKind::Other,
812 Self::AddressNack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge( 780 Self::AddressNack => {
813 embedded_hal_1::i2c::NoAcknowledgeSource::Address, 781 embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address)
814 ), 782 }
815 Self::DataNack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge( 783 Self::DataNack => {
816 embedded_hal_1::i2c::NoAcknowledgeSource::Data, 784 embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Data)
817 ), 785 }
818 Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, 786 Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun,
819 Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, 787 Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other,
820 } 788 }
@@ -841,24 +809,14 @@ mod eh1 {
841 todo!(); 809 todo!();
842 } 810 }
843 811
844 fn write_iter_read<B>( 812 fn write_iter_read<B>(&mut self, _address: u8, _bytes: B, _buffer: &mut [u8]) -> Result<(), Self::Error>
845 &mut self,
846 _address: u8,
847 _bytes: B,
848 _buffer: &mut [u8],
849 ) -> Result<(), Self::Error>
850 where 813 where
851 B: IntoIterator<Item = u8>, 814 B: IntoIterator<Item = u8>,
852 { 815 {
853 todo!(); 816 todo!();
854 } 817 }
855 818
856 fn write_read( 819 fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> {
857 &mut self,
858 address: u8,
859 wr_buffer: &[u8],
860 rd_buffer: &mut [u8],
861 ) -> Result<(), Self::Error> {
862 self.blocking_write_read(address, wr_buffer, rd_buffer) 820 self.blocking_write_read(address, wr_buffer, rd_buffer)
863 } 821 }
864 822
@@ -870,11 +828,7 @@ mod eh1 {
870 todo!(); 828 todo!();
871 } 829 }
872 830
873 fn transaction_iter<'a, O>( 831 fn transaction_iter<'a, O>(&mut self, _address: u8, _operations: O) -> Result<(), Self::Error>
874 &mut self,
875 _address: u8,
876 _operations: O,
877 ) -> Result<(), Self::Error>
878 where 832 where
879 O: IntoIterator<Item = embedded_hal_1::i2c::blocking::Operation<'a>>, 833 O: IntoIterator<Item = embedded_hal_1::i2c::blocking::Operation<'a>>,
880 { 834 {
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index 70dbfb080..50b341447 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -13,27 +13,24 @@
13//! memory may be used given that buffers are passed in directly to its read and write 13//! memory may be used given that buffers are passed in directly to its read and write
14//! methods. 14//! methods.
15 15
16use crate::interrupt::InterruptExt;
17use crate::Unborrow;
18use core::marker::PhantomData; 16use core::marker::PhantomData;
19use core::sync::atomic::{compiler_fence, Ordering}; 17use core::sync::atomic::{compiler_fence, Ordering};
20use core::task::Poll; 18use core::task::Poll;
19
21use embassy_hal_common::drop::OnDrop; 20use embassy_hal_common::drop::OnDrop;
22use embassy_hal_common::unborrow; 21use embassy_hal_common::unborrow;
23use futures::future::poll_fn; 22use futures::future::poll_fn;
23// Re-export SVD variants to allow user to directly set values.
24pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
24 25
25use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; 26use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
26use crate::gpio::sealed::Pin as _; 27use crate::gpio::sealed::Pin as _;
27use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; 28use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits};
28use crate::interrupt::Interrupt; 29use crate::interrupt::{Interrupt, InterruptExt};
29use crate::pac;
30use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; 30use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
31use crate::timer::Instance as TimerInstance; 31use crate::timer::{Frequency, Instance as TimerInstance, Timer};
32use crate::timer::{Frequency, Timer};
33use crate::util::slice_in_ram_or; 32use crate::util::slice_in_ram_or;
34 33use crate::{pac, Unborrow};
35// Re-export SVD variants to allow user to directly set values.
36pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
37 34
38#[non_exhaustive] 35#[non_exhaustive]
39pub struct Config { 36pub struct Config {
@@ -182,12 +179,8 @@ impl<'d, T: Instance> Uarte<'d, T> {
182 179
183 Self { 180 Self {
184 phantom: PhantomData, 181 phantom: PhantomData,
185 tx: UarteTx { 182 tx: UarteTx { phantom: PhantomData },
186 phantom: PhantomData, 183 rx: UarteRx { phantom: PhantomData },
187 },
188 rx: UarteRx {
189 phantom: PhantomData,
190 },
191 } 184 }
192 } 185 }
193 186
@@ -893,9 +886,7 @@ mod eh02 {
893 } 886 }
894 } 887 }
895 888
896 impl<'d, U: Instance, T: TimerInstance> embedded_hal_02::blocking::serial::Write<u8> 889 impl<'d, U: Instance, T: TimerInstance> embedded_hal_02::blocking::serial::Write<u8> for UarteWithIdle<'d, U, T> {
897 for UarteWithIdle<'d, U, T>
898 {
899 type Error = Error; 890 type Error = Error;
900 891
901 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { 892 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
@@ -956,9 +947,7 @@ mod eh1 {
956 type Error = Error; 947 type Error = Error;
957 } 948 }
958 949
959 impl<'d, U: Instance, T: TimerInstance> embedded_hal_1::serial::ErrorType 950 impl<'d, U: Instance, T: TimerInstance> embedded_hal_1::serial::ErrorType for UarteWithIdle<'d, U, T> {
960 for UarteWithIdle<'d, U, T>
961 {
962 type Error = Error; 951 type Error = Error;
963 } 952 }
964} 953}
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs
index d0223c4c9..6c872581d 100644
--- a/embassy-nrf/src/usb.rs
+++ b/embassy-nrf/src/usb.rs
@@ -1,25 +1,23 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::interrupt::InterruptExt;
4use crate::Unborrow;
5use core::marker::PhantomData; 3use core::marker::PhantomData;
6use core::mem::MaybeUninit; 4use core::mem::MaybeUninit;
7use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; 5use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
8use core::task::Poll; 6use core::task::Poll;
7
9use cortex_m::peripheral::NVIC; 8use cortex_m::peripheral::NVIC;
10use embassy::waitqueue::AtomicWaker; 9use embassy::waitqueue::AtomicWaker;
11use embassy_hal_common::unborrow; 10use embassy_hal_common::unborrow;
11pub use embassy_usb;
12use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; 12use embassy_usb::driver::{self, EndpointError, Event, Unsupported};
13use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; 13use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection};
14use futures::future::poll_fn; 14use futures::future::poll_fn;
15use futures::Future; 15use futures::Future;
16
17pub use embassy_usb;
18use pac::usbd::RegisterBlock; 16use pac::usbd::RegisterBlock;
19 17
20use crate::interrupt::Interrupt; 18use crate::interrupt::{Interrupt, InterruptExt};
21use crate::pac;
22use crate::util::slice_in_ram; 19use crate::util::slice_in_ram;
20use crate::{pac, Unborrow};
23 21
24const NEW_AW: AtomicWaker = AtomicWaker::new(); 22const NEW_AW: AtomicWaker = AtomicWaker::new();
25static BUS_WAKER: AtomicWaker = NEW_AW; 23static BUS_WAKER: AtomicWaker = NEW_AW;
@@ -35,10 +33,7 @@ pub struct Driver<'d, T: Instance> {
35} 33}
36 34
37impl<'d, T: Instance> Driver<'d, T> { 35impl<'d, T: Instance> Driver<'d, T> {
38 pub fn new( 36 pub fn new(_usb: impl Unborrow<Target = T> + 'd, irq: impl Unborrow<Target = T::Interrupt> + 'd) -> Self {
39 _usb: impl Unborrow<Target = T> + 'd,
40 irq: impl Unborrow<Target = T::Interrupt> + 'd,
41 ) -> Self {
42 unborrow!(irq); 37 unborrow!(irq);
43 irq.set_handler(Self::on_interrupt); 38 irq.set_handler(Self::on_interrupt);
44 irq.unpend(); 39 irq.unpend();
@@ -143,9 +138,7 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> {
143 138
144 fn start(self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) { 139 fn start(self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) {
145 ( 140 (
146 Bus { 141 Bus { phantom: PhantomData },
147 phantom: PhantomData,
148 },
149 ControlPipe { 142 ControlPipe {
150 _phantom: PhantomData, 143 _phantom: PhantomData,
151 max_packet_size: control_max_packet_size, 144 max_packet_size: control_max_packet_size,
@@ -266,8 +259,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
266 let regs = T::regs(); 259 let regs = T::regs();
267 unsafe { 260 unsafe {
268 if ep_addr.index() == 0 { 261 if ep_addr.index() == 0 {
269 regs.tasks_ep0stall 262 regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(stalled));
270 .write(|w| w.tasks_ep0stall().bit(stalled));
271 } else { 263 } else {
272 regs.epstall.write(|w| { 264 regs.epstall.write(|w| {
273 w.ep().bits(ep_addr.index() as u8 & 0b111); 265 w.ep().bits(ep_addr.index() as u8 & 0b111);
@@ -370,8 +362,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
370 regs.eventcause.write(|w| w.usbwuallowed().set_bit()); 362 regs.eventcause.write(|w| w.usbwuallowed().set_bit());
371 363
372 regs.dpdmvalue.write(|w| w.state().resume()); 364 regs.dpdmvalue.write(|w| w.state().resume());
373 regs.tasks_dpdmdrive 365 regs.tasks_dpdmdrive.write(|w| w.tasks_dpdmdrive().set_bit());
374 .write(|w| w.tasks_dpdmdrive().set_bit());
375 366
376 Poll::Ready(()) 367 Poll::Ready(())
377 } else { 368 } else {
@@ -520,11 +511,7 @@ unsafe fn read_dma<T: Instance>(i: usize, buf: &mut [u8]) -> Result<usize, Endpo
520 dma_start(); 511 dma_start();
521 regs.events_endepout[i].reset(); 512 regs.events_endepout[i].reset();
522 regs.tasks_startepout[i].write(|w| w.tasks_startepout().set_bit()); 513 regs.tasks_startepout[i].write(|w| w.tasks_startepout().set_bit());
523 while regs.events_endepout[i] 514 while regs.events_endepout[i].read().events_endepout().bit_is_clear() {}
524 .read()
525 .events_endepout()
526 .bit_is_clear()
527 {}
528 regs.events_endepout[i].reset(); 515 regs.events_endepout[i].reset();
529 dma_end(); 516 dma_end();
530 517
@@ -579,9 +566,7 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
579 let i = self.info.addr.index(); 566 let i = self.info.addr.index();
580 assert!(i != 0); 567 assert!(i != 0);
581 568
582 self.wait_data_ready() 569 self.wait_data_ready().await.map_err(|_| EndpointError::Disabled)?;
583 .await
584 .map_err(|_| EndpointError::Disabled)?;
585 570
586 unsafe { read_dma::<T>(i, buf) } 571 unsafe { read_dma::<T>(i, buf) }
587 } 572 }
@@ -596,9 +581,7 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> {
596 let i = self.info.addr.index(); 581 let i = self.info.addr.index();
597 assert!(i != 0); 582 assert!(i != 0);
598 583
599 self.wait_data_ready() 584 self.wait_data_ready().await.map_err(|_| EndpointError::Disabled)?;
600 .await
601 .map_err(|_| EndpointError::Disabled)?;
602 585
603 unsafe { write_dma::<T>(i, buf) } 586 unsafe { write_dma::<T>(i, buf) }
604 587
@@ -659,20 +642,14 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
659 } 642 }
660 } 643 }
661 644
662 fn data_out<'a>( 645 fn data_out<'a>(&'a mut self, buf: &'a mut [u8], _first: bool, _last: bool) -> Self::DataOutFuture<'a> {
663 &'a mut self,
664 buf: &'a mut [u8],
665 _first: bool,
666 _last: bool,
667 ) -> Self::DataOutFuture<'a> {
668 async move { 646 async move {
669 let regs = T::regs(); 647 let regs = T::regs();
670 648
671 regs.events_ep0datadone.reset(); 649 regs.events_ep0datadone.reset();
672 650
673 // This starts a RX on EP0. events_ep0datadone notifies when done. 651 // This starts a RX on EP0. events_ep0datadone notifies when done.
674 regs.tasks_ep0rcvout 652 regs.tasks_ep0rcvout.write(|w| w.tasks_ep0rcvout().set_bit());
675 .write(|w| w.tasks_ep0rcvout().set_bit());
676 653
677 // Wait until ready 654 // Wait until ready
678 regs.intenset.write(|w| { 655 regs.intenset.write(|w| {
@@ -701,12 +678,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
701 } 678 }
702 } 679 }
703 680
704 fn data_in<'a>( 681 fn data_in<'a>(&'a mut self, buf: &'a [u8], _first: bool, last: bool) -> Self::DataInFuture<'a> {
705 &'a mut self,
706 buf: &'a [u8],
707 _first: bool,
708 last: bool,
709 ) -> Self::DataInFuture<'a> {
710 async move { 682 async move {
711 let regs = T::regs(); 683 let regs = T::regs();
712 regs.events_ep0datadone.reset(); 684 regs.events_ep0datadone.reset();
@@ -745,8 +717,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
745 fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a> { 717 fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a> {
746 async move { 718 async move {
747 let regs = T::regs(); 719 let regs = T::regs();
748 regs.tasks_ep0status 720 regs.tasks_ep0status.write(|w| w.tasks_ep0status().bit(true));
749 .write(|w| w.tasks_ep0status().bit(true));
750 } 721 }
751 } 722 }
752 723
diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs
index 3082cd0d7..3ad1e5d82 100644
--- a/embassy-rp/src/clocks.rs
+++ b/embassy-rp/src/clocks.rs
@@ -47,11 +47,9 @@ pub unsafe fn init() {
47 start_xosc(); 47 start_xosc();
48 48
49 // Before we touch PLLs, switch sys and ref cleanly away from their aux sources. 49 // Before we touch PLLs, switch sys and ref cleanly away from their aux sources.
50 c.clk_sys_ctrl() 50 c.clk_sys_ctrl().modify(|w| w.set_src(ClkSysCtrlSrc::CLK_REF));
51 .modify(|w| w.set_src(ClkSysCtrlSrc::CLK_REF));
52 while c.clk_sys_selected().read() != 1 {} 51 while c.clk_sys_selected().read() != 1 {}
53 c.clk_ref_ctrl() 52 c.clk_ref_ctrl().modify(|w| w.set_src(ClkRefCtrlSrc::ROSC_CLKSRC_PH));
54 .modify(|w| w.set_src(ClkRefCtrlSrc::ROSC_CLKSRC_PH));
55 while c.clk_ref_selected().read() != 1 {} 53 while c.clk_ref_selected().read() != 1 {}
56 54
57 // Configure PLLs 55 // Configure PLLs
@@ -135,9 +133,7 @@ unsafe fn start_xosc() {
135 .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ)); 133 .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ));
136 134
137 let startup_delay = (((XOSC_MHZ * 1_000_000) / 1000) + 128) / 256; 135 let startup_delay = (((XOSC_MHZ * 1_000_000) / 1000) + 128) / 256;
138 pac::XOSC 136 pac::XOSC.startup().write(|w| w.set_delay(startup_delay as u16));
139 .startup()
140 .write(|w| w.set_delay(startup_delay as u16));
141 pac::XOSC.ctrl().write(|w| { 137 pac::XOSC.ctrl().write(|w| {
142 w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ); 138 w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ);
143 w.set_enable(pac::xosc::vals::Enable::ENABLE); 139 w.set_enable(pac::xosc::vals::Enable::ENABLE);
@@ -145,13 +141,7 @@ unsafe fn start_xosc() {
145 while !pac::XOSC.status().read().stable() {} 141 while !pac::XOSC.status().read().stable() {}
146} 142}
147 143
148unsafe fn configure_pll( 144unsafe fn configure_pll(p: pac::pll::Pll, refdiv: u32, vco_freq: u32, post_div1: u8, post_div2: u8) {
149 p: pac::pll::Pll,
150 refdiv: u32,
151 vco_freq: u32,
152 post_div1: u8,
153 post_div2: u8,
154) {
155 let ref_freq = XOSC_MHZ * 1_000_000 / refdiv; 145 let ref_freq = XOSC_MHZ * 1_000_000 / refdiv;
156 146
157 let fbdiv = vco_freq / ref_freq; 147 let fbdiv = vco_freq / ref_freq;
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs
index a2e1b3d7b..ae771e849 100644
--- a/embassy-rp/src/gpio.rs
+++ b/embassy-rp/src/gpio.rs
@@ -1,13 +1,11 @@
1use core::convert::Infallible; 1use core::convert::Infallible;
2use core::marker::PhantomData; 2use core::marker::PhantomData;
3 3
4use crate::pac; 4use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
5
5use crate::pac::common::{Reg, RW}; 6use crate::pac::common::{Reg, RW};
6use crate::pac::SIO; 7use crate::pac::SIO;
7use crate::peripherals; 8use crate::{pac, peripherals, Unborrow};
8
9use crate::Unborrow;
10use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
11 9
12/// Represents a digital input or output level. 10/// Represents a digital input or output level.
13#[derive(Debug, Eq, PartialEq)] 11#[derive(Debug, Eq, PartialEq)]
@@ -195,10 +193,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
195 pub fn set_high(&mut self) { 193 pub fn set_high(&mut self) {
196 // For Open Drain High, disable the output pin. 194 // For Open Drain High, disable the output pin.
197 unsafe { 195 unsafe {
198 self.pin 196 self.pin.sio_oe().value_clr().write_value(1 << self.pin.pin());
199 .sio_oe()
200 .value_clr()
201 .write_value(1 << self.pin.pin());
202 } 197 }
203 } 198 }
204 199
@@ -207,10 +202,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
207 pub fn set_low(&mut self) { 202 pub fn set_low(&mut self) {
208 // For Open Drain Low, enable the output pin. 203 // For Open Drain Low, enable the output pin.
209 unsafe { 204 unsafe {
210 self.pin 205 self.pin.sio_oe().value_set().write_value(1 << self.pin.pin());
211 .sio_oe()
212 .value_set()
213 .write_value(1 << self.pin.pin());
214 } 206 }
215 } 207 }
216 208
diff --git a/embassy-rp/src/interrupt.rs b/embassy-rp/src/interrupt.rs
index 042882691..d652a8c71 100644
--- a/embassy-rp/src/interrupt.rs
+++ b/embassy-rp/src/interrupt.rs
@@ -5,9 +5,9 @@
5 5
6// Re-exports 6// Re-exports
7pub use embassy_cortex_m::interrupt::*; 7pub use embassy_cortex_m::interrupt::*;
8use embassy_macros::cortex_m_interrupt_declare as declare;
8 9
9use crate::pac::Interrupt as InterruptEnum; 10use crate::pac::Interrupt as InterruptEnum;
10use embassy_macros::cortex_m_interrupt_declare as declare;
11declare!(TIMER_IRQ_0); 11declare!(TIMER_IRQ_0);
12declare!(TIMER_IRQ_1); 12declare!(TIMER_IRQ_1);
13declare!(TIMER_IRQ_2); 13declare!(TIMER_IRQ_2);
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs
index 72fe864b5..90ef1b170 100644
--- a/embassy-rp/src/lib.rs
+++ b/embassy-rp/src/lib.rs
@@ -17,15 +17,14 @@ mod reset;
17 17
18// Reexports 18// Reexports
19 19
20pub use embassy_cortex_m::executor;
21pub use embassy_hal_common::{unborrow, Unborrow};
22pub use embassy_macros::cortex_m_interrupt as interrupt;
20#[cfg(feature = "unstable-pac")] 23#[cfg(feature = "unstable-pac")]
21pub use rp2040_pac2 as pac; 24pub use rp2040_pac2 as pac;
22#[cfg(not(feature = "unstable-pac"))] 25#[cfg(not(feature = "unstable-pac"))]
23pub(crate) use rp2040_pac2 as pac; 26pub(crate) use rp2040_pac2 as pac;
24 27
25pub use embassy_cortex_m::executor;
26pub use embassy_hal_common::{unborrow, Unborrow};
27pub use embassy_macros::cortex_m_interrupt as interrupt;
28
29embassy_hal_common::peripherals! { 28embassy_hal_common::peripherals! {
30 PIN_0, 29 PIN_0,
31 PIN_1, 30 PIN_1,
diff --git a/embassy-rp/src/reset.rs b/embassy-rp/src/reset.rs
index 914e6a698..edd47c223 100644
--- a/embassy-rp/src/reset.rs
+++ b/embassy-rp/src/reset.rs
@@ -1,7 +1,7 @@
1use crate::pac;
2
3pub use pac::resets::regs::Peripherals; 1pub use pac::resets::regs::Peripherals;
4 2
3use crate::pac;
4
5pub const ALL_PERIPHERALS: Peripherals = Peripherals(0x01ffffff); 5pub const ALL_PERIPHERALS: Peripherals = Peripherals(0x01ffffff);
6 6
7pub unsafe fn reset(peris: Peripherals) { 7pub unsafe fn reset(peris: Peripherals) {
@@ -10,8 +10,6 @@ pub unsafe fn reset(peris: Peripherals) {
10 10
11pub unsafe fn unreset_wait(peris: Peripherals) { 11pub unsafe fn unreset_wait(peris: Peripherals) {
12 // TODO use the "atomic clear" register version 12 // TODO use the "atomic clear" register version
13 pac::RESETS 13 pac::RESETS.reset().modify(|v| *v = Peripherals(v.0 & !peris.0));
14 .reset()
15 .modify(|v| *v = Peripherals(v.0 & !peris.0));
16 while ((!pac::RESETS.reset_done().read().0) & peris.0) != 0 {} 14 while ((!pac::RESETS.reset_done().read().0) & peris.0) != 0 {}
17} 15}
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs
index 726c20a83..e988e41d2 100644
--- a/embassy-rp/src/spi.rs
+++ b/embassy-rp/src/spi.rs
@@ -1,13 +1,11 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use crate::Unborrow;
4use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
4pub use embedded_hal_02::spi::{Phase, Polarity};
5 5
6use crate::gpio::sealed::Pin as _; 6use crate::gpio::sealed::Pin as _;
7use crate::gpio::{AnyPin, Pin as GpioPin}; 7use crate::gpio::{AnyPin, Pin as GpioPin};
8use crate::{pac, peripherals}; 8use crate::{pac, peripherals, Unborrow};
9
10pub use embedded_hal_02::spi::{Phase, Polarity};
11 9
12#[derive(Debug, Clone, Copy, PartialEq, Eq)] 10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13#[cfg_attr(feature = "defmt", derive(defmt::Format))] 11#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -56,11 +54,7 @@ fn calc_prescs(freq: u32) -> (u8, u8) {
56 } 54 }
57 55
58 let presc = div_roundup(ratio, 256); 56 let presc = div_roundup(ratio, 256);
59 let postdiv = if presc == 1 { 57 let postdiv = if presc == 1 { ratio } else { div_roundup(ratio, presc) };
60 ratio
61 } else {
62 div_roundup(ratio, presc)
63 };
64 58
65 ((presc * 2) as u8, (postdiv - 1) as u8) 59 ((presc * 2) as u8, (postdiv - 1) as u8)
66} 60}
@@ -91,14 +85,7 @@ impl<'d, T: Instance> Spi<'d, T> {
91 config: Config, 85 config: Config,
92 ) -> Self { 86 ) -> Self {
93 unborrow!(clk, mosi); 87 unborrow!(clk, mosi);
94 Self::new_inner( 88 Self::new_inner(inner, Some(clk.degrade()), Some(mosi.degrade()), None, None, config)
95 inner,
96 Some(clk.degrade()),
97 Some(mosi.degrade()),
98 None,
99 None,
100 config,
101 )
102 } 89 }
103 90
104 pub fn new_rxonly( 91 pub fn new_rxonly(
@@ -108,14 +95,7 @@ impl<'d, T: Instance> Spi<'d, T> {
108 config: Config, 95 config: Config,
109 ) -> Self { 96 ) -> Self {
110 unborrow!(clk, miso); 97 unborrow!(clk, miso);
111 Self::new_inner( 98 Self::new_inner(inner, Some(clk.degrade()), None, Some(miso.degrade()), None, config)
112 inner,
113 Some(clk.degrade()),
114 None,
115 Some(miso.degrade()),
116 None,
117 config,
118 )
119 } 99 }
120 100
121 fn new_inner( 101 fn new_inner(
diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs
index c43e044f3..6c4c258b1 100644
--- a/embassy-rp/src/timer.rs
+++ b/embassy-rp/src/timer.rs
@@ -1,11 +1,12 @@
1use crate::interrupt::{Interrupt, InterruptExt};
2use atomic_polyfill::{AtomicU8, Ordering};
3use core::cell::Cell; 1use core::cell::Cell;
2
3use atomic_polyfill::{AtomicU8, Ordering};
4use critical_section::CriticalSection; 4use critical_section::CriticalSection;
5use embassy::blocking_mutex::raw::CriticalSectionRawMutex; 5use embassy::blocking_mutex::raw::CriticalSectionRawMutex;
6use embassy::blocking_mutex::Mutex; 6use embassy::blocking_mutex::Mutex;
7use embassy::time::driver::{AlarmHandle, Driver}; 7use embassy::time::driver::{AlarmHandle, Driver};
8 8
9use crate::interrupt::{Interrupt, InterruptExt};
9use crate::{interrupt, pac}; 10use crate::{interrupt, pac};
10 11
11struct AlarmState { 12struct AlarmState {
@@ -45,15 +46,13 @@ impl Driver for TimerDriver {
45 } 46 }
46 47
47 unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { 48 unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
48 let id = self 49 let id = self.next_alarm.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| {
49 .next_alarm 50 if x < ALARM_COUNT as u8 {
50 .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { 51 Some(x + 1)
51 if x < ALARM_COUNT as u8 { 52 } else {
52 Some(x + 1) 53 None
53 } else { 54 }
54 None 55 });
55 }
56 });
57 56
58 match id { 57 match id {
59 Ok(id) => Some(AlarmHandle::new(id)), 58 Ok(id) => Some(AlarmHandle::new(id)),
diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs
index 1aa3c5a84..c95407b6f 100644
--- a/embassy-rp/src/uart.rs
+++ b/embassy-rp/src/uart.rs
@@ -1,10 +1,9 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use crate::Unborrow;
4use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
5use gpio::Pin; 4use gpio::Pin;
6 5
7use crate::{gpio, pac, peripherals}; 6use crate::{gpio, pac, peripherals, Unborrow};
8 7
9#[non_exhaustive] 8#[non_exhaustive]
10pub struct Config { 9pub struct Config {
@@ -57,10 +56,8 @@ impl<'d, T: Instance> Uart<'d, T> {
57 } 56 }
58 57
59 // Load PL011's baud divisor registers 58 // Load PL011's baud divisor registers
60 p.uartibrd() 59 p.uartibrd().write_value(pac::uart::regs::Uartibrd(baud_ibrd));
61 .write_value(pac::uart::regs::Uartibrd(baud_ibrd)); 60 p.uartfbrd().write_value(pac::uart::regs::Uartfbrd(baud_fbrd));
62 p.uartfbrd()
63 .write_value(pac::uart::regs::Uartfbrd(baud_fbrd));
64 61
65 p.uartlcr_h().write(|w| { 62 p.uartlcr_h().write(|w| {
66 w.set_wlen(config.data_bits - 5); 63 w.set_wlen(config.data_bits - 5);
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index 42c88a269..3b4aa5dfd 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -1,10 +1,10 @@
1use proc_macro2::TokenStream;
2use quote::{format_ident, quote};
3use std::collections::{HashMap, HashSet}; 1use std::collections::{HashMap, HashSet};
4use std::env;
5use std::fmt::Write as _; 2use std::fmt::Write as _;
6use std::fs;
7use std::path::PathBuf; 3use std::path::PathBuf;
4use std::{env, fs};
5
6use proc_macro2::TokenStream;
7use quote::{format_ident, quote};
8use stm32_metapac::metadata::METADATA; 8use stm32_metapac::metadata::METADATA;
9 9
10fn main() { 10fn main() {
@@ -116,10 +116,7 @@ fn main() {
116 continue; 116 continue;
117 } 117 }
118 for irq in p.interrupts { 118 for irq in p.interrupts {
119 dma_irqs 119 dma_irqs.entry(irq.interrupt).or_default().push((p.name, irq.signal));
120 .entry(irq.interrupt)
121 .or_default()
122 .push((p.name, irq.signal));
123 } 120 }
124 } 121 }
125 } 122 }
@@ -128,9 +125,7 @@ fn main() {
128 for (irq, channels) in dma_irqs { 125 for (irq, channels) in dma_irqs {
129 let irq = format_ident!("{}", irq); 126 let irq = format_ident!("{}", irq);
130 127
131 let channels = channels 128 let channels = channels.iter().map(|(dma, ch)| format_ident!("{}_{}", dma, ch));
132 .iter()
133 .map(|(dma, ch)| format_ident!("{}_{}", dma, ch));
134 129
135 g.extend(quote! { 130 g.extend(quote! {
136 #[crate::interrupt] 131 #[crate::interrupt]
@@ -147,9 +142,7 @@ fn main() {
147 142
148 for p in METADATA.peripherals { 143 for p in METADATA.peripherals {
149 // generating RccPeripheral impl for H7 ADC3 would result in bad frequency 144 // generating RccPeripheral impl for H7 ADC3 would result in bad frequency
150 if !singletons.contains(&p.name.to_string()) 145 if !singletons.contains(&p.name.to_string()) || (p.name == "ADC3" && METADATA.line.starts_with("STM32H7")) {
151 || (p.name == "ADC3" && METADATA.line.starts_with("STM32H7"))
152 {
153 continue; 146 continue;
154 } 147 }
155 148
@@ -568,12 +561,7 @@ fn main() {
568 let mut pins_table: Vec<Vec<String>> = Vec::new(); 561 let mut pins_table: Vec<Vec<String>> = Vec::new();
569 let mut dma_channels_table: Vec<Vec<String>> = Vec::new(); 562 let mut dma_channels_table: Vec<Vec<String>> = Vec::new();
570 563
571 let gpio_base = METADATA 564 let gpio_base = METADATA.peripherals.iter().find(|p| p.name == "GPIOA").unwrap().address as u32;
572 .peripherals
573 .iter()
574 .find(|p| p.name == "GPIOA")
575 .unwrap()
576 .address as u32;
577 let gpio_stride = 0x400; 565 let gpio_stride = 0x400;
578 566
579 for p in METADATA.peripherals { 567 for p in METADATA.peripherals {
@@ -618,11 +606,7 @@ fn main() {
618 606
619 for ch in METADATA.dma_channels { 607 for ch in METADATA.dma_channels {
620 let mut row = Vec::new(); 608 let mut row = Vec::new();
621 let dma_peri = METADATA 609 let dma_peri = METADATA.peripherals.iter().find(|p| p.name == ch.dma).unwrap();
622 .peripherals
623 .iter()
624 .find(|p| p.name == ch.dma)
625 .unwrap();
626 let bi = dma_peri.registers.as_ref().unwrap(); 610 let bi = dma_peri.registers.as_ref().unwrap();
627 611
628 let num; 612 let num;
@@ -649,10 +633,7 @@ fn main() {
649 row.push(num.to_string()); 633 row.push(num.to_string());
650 if let Some(dmamux) = &ch.dmamux { 634 if let Some(dmamux) = &ch.dmamux {
651 let dmamux_channel = ch.dmamux_channel.unwrap(); 635 let dmamux_channel = ch.dmamux_channel.unwrap();
652 row.push(format!( 636 row.push(format!("{{dmamux: {}, dmamux_channel: {}}}", dmamux, dmamux_channel));
653 "{{dmamux: {}, dmamux_channel: {}}}",
654 dmamux, dmamux_channel
655 ));
656 } else { 637 } else {
657 row.push("{}".to_string()); 638 row.push("{}".to_string());
658 } 639 }
@@ -709,11 +690,7 @@ fn main() {
709 }; 690 };
710 691
711 if let Some(core) = core_name { 692 if let Some(core) = core_name {
712 println!( 693 println!("cargo:rustc-cfg={}_{}", &chip_name[..chip_name.len() - 2], core);
713 "cargo:rustc-cfg={}_{}",
714 &chip_name[..chip_name.len() - 2],
715 core
716 );
717 } else { 694 } else {
718 println!("cargo:rustc-cfg={}", &chip_name[..chip_name.len() - 2]); 695 println!("cargo:rustc-cfg={}", &chip_name[..chip_name.len() - 2]);
719 } 696 }
diff --git a/embassy-stm32/src/adc/f1.rs b/embassy-stm32/src/adc/f1.rs
index ecb68b1a9..74cfac136 100644
--- a/embassy-stm32/src/adc/f1.rs
+++ b/embassy-stm32/src/adc/f1.rs
@@ -1,10 +1,12 @@
1use core::marker::PhantomData;
2
3use embassy_hal_common::unborrow;
4use embedded_hal_02::blocking::delay::DelayUs;
5
1use crate::adc::{AdcPin, Instance}; 6use crate::adc::{AdcPin, Instance};
2use crate::rcc::get_freqs; 7use crate::rcc::get_freqs;
3use crate::time::Hertz; 8use crate::time::Hertz;
4use crate::Unborrow; 9use crate::Unborrow;
5use core::marker::PhantomData;
6use embassy_hal_common::unborrow;
7use embedded_hal_02::blocking::delay::DelayUs;
8 10
9pub const VDDA_CALIB_MV: u32 = 3300; 11pub const VDDA_CALIB_MV: u32 = 3300;
10pub const ADC_MAX: u32 = (1 << 12) - 1; 12pub const ADC_MAX: u32 = (1 << 12) - 1;
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs
index cdb8dfe9e..936a35562 100644
--- a/embassy-stm32/src/adc/v2.rs
+++ b/embassy-stm32/src/adc/v2.rs
@@ -1,10 +1,12 @@
1use crate::adc::{AdcPin, Instance};
2use crate::time::Hertz;
3use crate::Unborrow;
4use core::marker::PhantomData; 1use core::marker::PhantomData;
2
5use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
6use embedded_hal_02::blocking::delay::DelayUs; 4use embedded_hal_02::blocking::delay::DelayUs;
7 5
6use crate::adc::{AdcPin, Instance};
7use crate::time::Hertz;
8use crate::Unborrow;
9
8pub const VDDA_CALIB_MV: u32 = 3000; 10pub const VDDA_CALIB_MV: u32 = 3000;
9 11
10#[cfg(not(any(rcc_f4, rcc_f7)))] 12#[cfg(not(any(rcc_f4, rcc_f7)))]
@@ -132,9 +134,7 @@ impl Prescaler {
132 2..=3 => Self::Div4, 134 2..=3 => Self::Div4,
133 4..=5 => Self::Div6, 135 4..=5 => Self::Div6,
134 6..=7 => Self::Div8, 136 6..=7 => Self::Div8,
135 _ => panic!( 137 _ => panic!("Selected PCLK2 frequency is too high for ADC with largest possible prescaler."),
136 "Selected PCLK2 frequency is too high for ADC with largest possible prescaler."
137 ),
138 } 138 }
139 } 139 }
140 140
@@ -165,9 +165,7 @@ where
165 165
166 let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) }; 166 let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) };
167 unsafe { 167 unsafe {
168 T::common_regs() 168 T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre()));
169 .ccr()
170 .modify(|w| w.set_adcpre(presc.adcpre()));
171 } 169 }
172 170
173 unsafe { 171 unsafe {
@@ -241,9 +239,7 @@ where
241 pin.set_as_analog(); 239 pin.set_as_analog();
242 240
243 // Configure ADC 241 // Configure ADC
244 T::regs() 242 T::regs().cr1().modify(|reg| reg.set_res(self.resolution.res()));
245 .cr1()
246 .modify(|reg| reg.set_res(self.resolution.res()));
247 243
248 // Select channel 244 // Select channel
249 T::regs().sqr3().write(|reg| reg.set_sq(0, pin.channel())); 245 T::regs().sqr3().write(|reg| reg.set_sq(0, pin.channel()));
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs
index 875510b7b..49d149b18 100644
--- a/embassy-stm32/src/adc/v3.rs
+++ b/embassy-stm32/src/adc/v3.rs
@@ -1,9 +1,11 @@
1use crate::adc::{AdcPin, Instance};
2use crate::Unborrow;
3use core::marker::PhantomData; 1use core::marker::PhantomData;
2
4use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
5use embedded_hal_02::blocking::delay::DelayUs; 4use embedded_hal_02::blocking::delay::DelayUs;
6 5
6use crate::adc::{AdcPin, Instance};
7use crate::Unborrow;
8
7pub const VDDA_CALIB_MV: u32 = 3000; 9pub const VDDA_CALIB_MV: u32 = 3000;
8 10
9/// Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent ADC clock 11/// Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent ADC clock
@@ -369,13 +371,9 @@ impl<'d, T: Instance> Adc<'d, T> {
369 371
370 // Configure ADC 372 // Configure ADC
371 #[cfg(not(stm32g0))] 373 #[cfg(not(stm32g0))]
372 T::regs() 374 T::regs().cfgr().modify(|reg| reg.set_res(self.resolution.res()));
373 .cfgr()
374 .modify(|reg| reg.set_res(self.resolution.res()));
375 #[cfg(stm32g0)] 375 #[cfg(stm32g0)]
376 T::regs() 376 T::regs().cfgr1().modify(|reg| reg.set_res(self.resolution.res()));
377 .cfgr1()
378 .modify(|reg| reg.set_res(self.resolution.res()));
379 377
380 // Configure channel 378 // Configure channel
381 Self::set_channel_sample_time(pin.channel(), self.sample_time); 379 Self::set_channel_sample_time(pin.channel(), self.sample_time);
@@ -384,9 +382,7 @@ impl<'d, T: Instance> Adc<'d, T> {
384 #[cfg(not(stm32g0))] 382 #[cfg(not(stm32g0))]
385 T::regs().sqr1().write(|reg| reg.set_sq(0, pin.channel())); 383 T::regs().sqr1().write(|reg| reg.set_sq(0, pin.channel()));
386 #[cfg(stm32g0)] 384 #[cfg(stm32g0)]
387 T::regs() 385 T::regs().chselr().write(|reg| reg.set_chsel(pin.channel() as u32));
388 .chselr()
389 .write(|reg| reg.set_chsel(pin.channel() as u32));
390 386
391 // Some models are affected by an erratum: 387 // Some models are affected by an erratum:
392 // If we perform conversions slower than 1 kHz, the first read ADC value can be 388 // If we perform conversions slower than 1 kHz, the first read ADC value can be
@@ -407,9 +403,7 @@ impl<'d, T: Instance> Adc<'d, T> {
407 403
408 #[cfg(stm32g0)] 404 #[cfg(stm32g0)]
409 unsafe fn set_channel_sample_time(_ch: u8, sample_time: SampleTime) { 405 unsafe fn set_channel_sample_time(_ch: u8, sample_time: SampleTime) {
410 T::regs() 406 T::regs().smpr().modify(|reg| reg.set_smp1(sample_time.sample_time()));
411 .smpr()
412 .modify(|reg| reg.set_smp1(sample_time.sample_time()));
413 } 407 }
414 408
415 #[cfg(not(stm32g0))] 409 #[cfg(not(stm32g0))]
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs
index 316e04e0c..cdb79f517 100644
--- a/embassy-stm32/src/adc/v4.rs
+++ b/embassy-stm32/src/adc/v4.rs
@@ -1,16 +1,13 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use crate::time::{Hertz, U32Ext}; 3use atomic_polyfill::{AtomicU8, Ordering};
4use crate::Unborrow;
5use atomic_polyfill::AtomicU8;
6use atomic_polyfill::Ordering;
7use embedded_hal_02::blocking::delay::DelayUs; 4use embedded_hal_02::blocking::delay::DelayUs;
8use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel}; 5use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel};
9use pac::adccommon::vals::Presc; 6use pac::adccommon::vals::Presc;
10 7
11use crate::pac;
12
13use super::{AdcPin, Instance}; 8use super::{AdcPin, Instance};
9use crate::time::{Hertz, U32Ext};
10use crate::{pac, Unborrow};
14 11
15pub enum Resolution { 12pub enum Resolution {
16 SixteenBit, 13 SixteenBit,
@@ -333,9 +330,7 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> {
333 let prescaler = Prescaler::from_ker_ck(T::frequency()); 330 let prescaler = Prescaler::from_ker_ck(T::frequency());
334 331
335 unsafe { 332 unsafe {
336 T::common_regs() 333 T::common_regs().ccr().modify(|w| w.set_presc(prescaler.presc()));
337 .ccr()
338 .modify(|w| w.set_presc(prescaler.presc()));
339 } 334 }
340 335
341 let frequency = Hertz(T::frequency().0 / prescaler.divisor()); 336 let frequency = Hertz(T::frequency().0 / prescaler.divisor());
@@ -509,9 +504,7 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> {
509 504
510 unsafe fn read_channel(&mut self, channel: u8) -> u16 { 505 unsafe fn read_channel(&mut self, channel: u8) -> u16 {
511 // Configure ADC 506 // Configure ADC
512 T::regs() 507 T::regs().cfgr().modify(|reg| reg.set_res(self.resolution.res()));
513 .cfgr()
514 .modify(|reg| reg.set_res(self.resolution.res()));
515 508
516 // Configure channel 509 // Configure channel
517 Self::set_channel_sample_time(channel, self.sample_time); 510 Self::set_channel_sample_time(channel, self.sample_time);
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs
index 0922d4d65..b54fd3ff3 100644
--- a/embassy-stm32/src/can/bxcan.rs
+++ b/embassy-stm32/src/can/bxcan.rs
@@ -1,13 +1,12 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2use core::ops::{Deref, DerefMut}; 2use core::ops::{Deref, DerefMut};
3 3
4use crate::Unborrow; 4pub use bxcan;
5use embassy_hal_common::unborrow; 5use embassy_hal_common::unborrow;
6 6
7use crate::gpio::sealed::AFType; 7use crate::gpio::sealed::AFType;
8use crate::{peripherals, rcc::RccPeripheral}; 8use crate::rcc::RccPeripheral;
9 9use crate::{peripherals, Unborrow};
10pub use bxcan;
11 10
12pub struct Can<'d, T: Instance + bxcan::Instance> { 11pub struct Can<'d, T: Instance + bxcan::Instance> {
13 phantom: PhantomData<&'d mut T>, 12 phantom: PhantomData<&'d mut T>,
diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs
index 1ab4530b9..87133714c 100644
--- a/embassy-stm32/src/crc/v1.rs
+++ b/embassy-stm32/src/crc/v1.rs
@@ -1,10 +1,11 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use embassy_hal_common::unborrow;
4
3use crate::pac::CRC as PAC_CRC; 5use crate::pac::CRC as PAC_CRC;
4use crate::peripherals::CRC; 6use crate::peripherals::CRC;
5use crate::rcc::sealed::RccPeripheral; 7use crate::rcc::sealed::RccPeripheral;
6use crate::Unborrow; 8use crate::Unborrow;
7use embassy_hal_common::unborrow;
8 9
9pub struct Crc<'d> { 10pub struct Crc<'d> {
10 _peripheral: CRC, 11 _peripheral: CRC,
diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs
index b6645c67f..63f24e4e1 100644
--- a/embassy-stm32/src/crc/v2v3.rs
+++ b/embassy-stm32/src/crc/v2v3.rs
@@ -1,11 +1,12 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use embassy_hal_common::unborrow;
4
3use crate::pac::crc::vals; 5use crate::pac::crc::vals;
4use crate::pac::CRC as PAC_CRC; 6use crate::pac::CRC as PAC_CRC;
5use crate::peripherals::CRC; 7use crate::peripherals::CRC;
6use crate::rcc::sealed::RccPeripheral; 8use crate::rcc::sealed::RccPeripheral;
7use crate::Unborrow; 9use crate::Unborrow;
8use embassy_hal_common::unborrow;
9 10
10pub struct Crc<'d> { 11pub struct Crc<'d> {
11 _peripheral: CRC, 12 _peripheral: CRC,
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs
index 1f6ba63df..f1cb452c7 100644
--- a/embassy-stm32/src/dac/mod.rs
+++ b/embassy-stm32/src/dac/mod.rs
@@ -3,9 +3,10 @@
3#[cfg_attr(dac_v1, path = "v1.rs")] 3#[cfg_attr(dac_v1, path = "v1.rs")]
4#[cfg_attr(dac_v2, path = "v2.rs")] 4#[cfg_attr(dac_v2, path = "v2.rs")]
5mod _version; 5mod _version;
6use crate::peripherals;
7pub use _version::*; 6pub use _version::*;
8 7
8use crate::peripherals;
9
9pub(crate) mod sealed { 10pub(crate) mod sealed {
10 pub trait Instance { 11 pub trait Instance {
11 fn regs() -> &'static crate::pac::dac::Dac; 12 fn regs() -> &'static crate::pac::dac::Dac;
diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs
index 0b421cc88..ba7856a5a 100644
--- a/embassy-stm32/src/dac/v2.rs
+++ b/embassy-stm32/src/dac/v2.rs
@@ -1,8 +1,10 @@
1use core::marker::PhantomData;
2
3use embassy_hal_common::unborrow;
4
1use crate::dac::{DacPin, Instance}; 5use crate::dac::{DacPin, Instance};
2use crate::pac::dac; 6use crate::pac::dac;
3use crate::Unborrow; 7use crate::Unborrow;
4use core::marker::PhantomData;
5use embassy_hal_common::unborrow;
6 8
7#[derive(Debug, Copy, Clone, Eq, PartialEq)] 9#[derive(Debug, Copy, Clone, Eq, PartialEq)]
8#[cfg_attr(feature = "defmt", derive(defmt::Format))] 10#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -93,23 +95,14 @@ pub struct Dac<'d, T: Instance> {
93 95
94macro_rules! enable { 96macro_rules! enable {
95 ($enable_reg:ident, $enable_field:ident, $reset_reg:ident, $reset_field:ident) => { 97 ($enable_reg:ident, $enable_field:ident, $reset_reg:ident, $reset_field:ident) => {
96 crate::pac::RCC 98 crate::pac::RCC.$enable_reg().modify(|w| w.$enable_field(true));
97 .$enable_reg() 99 crate::pac::RCC.$reset_reg().modify(|w| w.$reset_field(true));
98 .modify(|w| w.$enable_field(true)); 100 crate::pac::RCC.$reset_reg().modify(|w| w.$reset_field(false));
99 crate::pac::RCC
100 .$reset_reg()
101 .modify(|w| w.$reset_field(true));
102 crate::pac::RCC
103 .$reset_reg()
104 .modify(|w| w.$reset_field(false));
105 }; 101 };
106} 102}
107 103
108impl<'d, T: Instance> Dac<'d, T> { 104impl<'d, T: Instance> Dac<'d, T> {
109 pub fn new_1ch( 105 pub fn new_1ch(peri: impl Unborrow<Target = T> + 'd, _ch1: impl Unborrow<Target = impl DacPin<T, 1>> + 'd) -> Self {
110 peri: impl Unborrow<Target = T> + 'd,
111 _ch1: impl Unborrow<Target = impl DacPin<T, 1>> + 'd,
112 ) -> Self {
113 unborrow!(peri); 106 unborrow!(peri);
114 Self::new_inner(peri, 1) 107 Self::new_inner(peri, 1)
115 } 108 }
diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs
index 8a28ca4b2..f4ca93a71 100644
--- a/embassy-stm32/src/dcmi.rs
+++ b/embassy-stm32/src/dcmi.rs
@@ -1,13 +1,14 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2use core::task::Poll; 2use core::task::Poll;
3 3
4use crate::interrupt::{Interrupt, InterruptExt};
5use crate::Unborrow;
6use embassy::waitqueue::AtomicWaker; 4use embassy::waitqueue::AtomicWaker;
7use embassy_hal_common::unborrow; 5use embassy_hal_common::unborrow;
8use futures::future::poll_fn; 6use futures::future::poll_fn;
9 7
10use crate::gpio::{sealed::AFType, Speed}; 8use crate::gpio::sealed::AFType;
9use crate::gpio::Speed;
10use crate::interrupt::{Interrupt, InterruptExt};
11use crate::Unborrow;
11 12
12/// The level on the VSync pin when the data is not valid on the parallel interface. 13/// The level on the VSync pin when the data is not valid on the parallel interface.
13#[derive(Clone, Copy, PartialEq)] 14#[derive(Clone, Copy, PartialEq)]
@@ -466,14 +467,7 @@ where
466 let src = r.dr().ptr() as *mut u32; 467 let src = r.dr().ptr() as *mut u32;
467 468
468 unsafe { 469 unsafe {
469 channel.start_double_buffered_read( 470 channel.start_double_buffered_read(request, src, m0ar, m1ar, chunk_size, TransferOptions::default());
470 request,
471 src,
472 m0ar,
473 m1ar,
474 chunk_size,
475 TransferOptions::default(),
476 );
477 } 471 }
478 472
479 let mut last_chunk_set_for_transfer = false; 473 let mut last_chunk_set_for_transfer = false;
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs
index b17d22953..c87f3ac49 100644
--- a/embassy-stm32/src/dma/bdma.rs
+++ b/embassy-stm32/src/dma/bdma.rs
@@ -3,16 +3,15 @@
3use core::sync::atomic::{fence, Ordering}; 3use core::sync::atomic::{fence, Ordering};
4use core::task::Waker; 4use core::task::Waker;
5 5
6use crate::interrupt::{Interrupt, InterruptExt};
7use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
8 7
8use super::{TransferOptions, Word, WordSize};
9use crate::_generated::BDMA_CHANNEL_COUNT; 9use crate::_generated::BDMA_CHANNEL_COUNT;
10use crate::dma::Request; 10use crate::dma::Request;
11use crate::interrupt::{Interrupt, InterruptExt};
11use crate::pac; 12use crate::pac;
12use crate::pac::bdma::vals; 13use crate::pac::bdma::vals;
13 14
14use super::{TransferOptions, Word, WordSize};
15
16impl From<WordSize> for vals::Size { 15impl From<WordSize> for vals::Size {
17 fn from(raw: WordSize) -> Self { 16 fn from(raw: WordSize) -> Self {
18 match raw { 17 match raw {
@@ -185,14 +184,8 @@ mod low_level_api {
185 #[cfg(dmamux)] dmamux_regs: pac::dmamux::Dmamux, 184 #[cfg(dmamux)] dmamux_regs: pac::dmamux::Dmamux,
186 #[cfg(dmamux)] dmamux_ch_num: u8, 185 #[cfg(dmamux)] dmamux_ch_num: u8,
187 ) { 186 ) {
188 assert!( 187 assert!(options.mburst == crate::dma::Burst::Single, "Burst mode not supported");
189 options.mburst == crate::dma::Burst::Single, 188 assert!(options.pburst == crate::dma::Burst::Single, "Burst mode not supported");
190 "Burst mode not supported"
191 );
192 assert!(
193 options.pburst == crate::dma::Burst::Single,
194 "Burst mode not supported"
195 );
196 assert!( 189 assert!(
197 options.flow_ctrl == crate::dma::FlowControl::Dma, 190 options.flow_ctrl == crate::dma::FlowControl::Dma,
198 "Peripheral flow control not supported" 191 "Peripheral flow control not supported"
@@ -206,10 +199,7 @@ mod low_level_api {
206 super::super::dmamux::configure_dmamux(dmamux_regs, dmamux_ch_num, request); 199 super::super::dmamux::configure_dmamux(dmamux_regs, dmamux_ch_num, request);
207 200
208 #[cfg(bdma_v2)] 201 #[cfg(bdma_v2)]
209 critical_section::with(|_| { 202 critical_section::with(|_| dma.cselr().modify(|w| w.set_cs(channel_number as _, request)));
210 dma.cselr()
211 .modify(|w| w.set_cs(channel_number as _, request))
212 });
213 203
214 // "Preceding reads and writes cannot be moved past subsequent writes." 204 // "Preceding reads and writes cannot be moved past subsequent writes."
215 fence(Ordering::SeqCst); 205 fence(Ordering::SeqCst);
@@ -279,10 +269,7 @@ mod low_level_api {
279 let cr = dma.ch(channel_num).cr(); 269 let cr = dma.ch(channel_num).cr();
280 270
281 if isr.teif(channel_num) { 271 if isr.teif(channel_num) {
282 panic!( 272 panic!("DMA: error on BDMA@{:08x} channel {}", dma.0 as u32, channel_num);
283 "DMA: error on BDMA@{:08x} channel {}",
284 dma.0 as u32, channel_num
285 );
286 } 273 }
287 if isr.tcif(channel_num) && cr.read().tcie() { 274 if isr.tcif(channel_num) && cr.read().tcie() {
288 cr.write(|_| ()); // Disable channel interrupts with the default value. 275 cr.write(|_| ()); // Disable channel interrupts with the default value.
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs
index 04cde7b4b..e8e589de8 100644
--- a/embassy-stm32/src/dma/dma.rs
+++ b/embassy-stm32/src/dma/dma.rs
@@ -1,15 +1,13 @@
1use core::sync::atomic::{fence, Ordering}; 1use core::sync::atomic::{fence, Ordering};
2use core::task::Waker; 2use core::task::Waker;
3 3
4use crate::interrupt::{Interrupt, InterruptExt};
5use embassy::waitqueue::AtomicWaker; 4use embassy::waitqueue::AtomicWaker;
6 5
6use super::{Burst, FlowControl, Request, TransferOptions, Word, WordSize};
7use crate::_generated::DMA_CHANNEL_COUNT; 7use crate::_generated::DMA_CHANNEL_COUNT;
8use crate::interrupt; 8use crate::interrupt::{Interrupt, InterruptExt};
9use crate::pac;
10use crate::pac::dma::{regs, vals}; 9use crate::pac::dma::{regs, vals};
11 10use crate::{interrupt, pac};
12use super::{Burst, FlowControl, Request, TransferOptions, Word, WordSize};
13 11
14impl From<WordSize> for vals::Size { 12impl From<WordSize> for vals::Size {
15 fn from(raw: WordSize) -> Self { 13 fn from(raw: WordSize) -> Self {
@@ -407,10 +405,7 @@ mod low_level_api {
407 let isr = dma.isr(channel_num / 4).read(); 405 let isr = dma.isr(channel_num / 4).read();
408 406
409 if isr.teif(channel_num % 4) { 407 if isr.teif(channel_num % 4) {
410 panic!( 408 panic!("DMA: error on DMA@{:08x} channel {}", dma.0 as u32, channel_num);
411 "DMA: error on DMA@{:08x} channel {}",
412 dma.0 as u32, channel_num
413 );
414 } 409 }
415 410
416 if isr.tcif(channel_num % 4) && cr.read().tcie() { 411 if isr.tcif(channel_num % 4) && cr.read().tcie() {
@@ -418,8 +413,7 @@ mod low_level_api {
418 cr.write(|_| ()); // Disable channel with the default value. 413 cr.write(|_| ()); // Disable channel with the default value.
419 } else { 414 } else {
420 // for double buffered mode, clear TCIF flag but do not stop the transfer 415 // for double buffered mode, clear TCIF flag but do not stop the transfer
421 dma.ifcr(channel_num / 4) 416 dma.ifcr(channel_num / 4).write(|w| w.set_tcif(channel_num % 4, true));
422 .write(|w| w.set_tcif(channel_num % 4, true));
423 } 417 }
424 STATE.channels[state_index].waker.wake(); 418 STATE.channels[state_index].waker.wake();
425 } 419 }
diff --git a/embassy-stm32/src/dma/dmamux.rs b/embassy-stm32/src/dma/dmamux.rs
index c45bebe26..e9967e349 100644
--- a/embassy-stm32/src/dma/dmamux.rs
+++ b/embassy-stm32/src/dma/dmamux.rs
@@ -1,13 +1,8 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::pac; 3use crate::{pac, peripherals};
4use crate::peripherals; 4
5 5pub(crate) unsafe fn configure_dmamux(dmamux_regs: pac::dmamux::Dmamux, dmamux_ch_num: u8, request: u8) {
6pub(crate) unsafe fn configure_dmamux(
7 dmamux_regs: pac::dmamux::Dmamux,
8 dmamux_ch_num: u8,
9 request: u8,
10) {
11 let ch_mux_regs = dmamux_regs.ccr(dmamux_ch_num as _); 6 let ch_mux_regs = dmamux_regs.ccr(dmamux_ch_num as _);
12 ch_mux_regs.write(|reg| { 7 ch_mux_regs.write(|reg| {
13 reg.set_nbreq(0); 8 reg.set_nbreq(0);
diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs
index b054f95cc..8e901d725 100644
--- a/embassy-stm32/src/dma/gpdma.rs
+++ b/embassy-stm32/src/dma/gpdma.rs
@@ -1,15 +1,13 @@
1use core::sync::atomic::{fence, Ordering}; 1use core::sync::atomic::{fence, Ordering};
2use core::task::Waker; 2use core::task::Waker;
3 3
4use crate::interrupt::{Interrupt, InterruptExt};
5use embassy::waitqueue::AtomicWaker; 4use embassy::waitqueue::AtomicWaker;
6 5
6use super::{Request, TransferOptions, Word, WordSize};
7use crate::_generated::GPDMA_CHANNEL_COUNT; 7use crate::_generated::GPDMA_CHANNEL_COUNT;
8use crate::interrupt; 8use crate::interrupt::{Interrupt, InterruptExt};
9use crate::pac;
10use crate::pac::gpdma::{vals, Gpdma}; 9use crate::pac::gpdma::{vals, Gpdma};
11 10use crate::{interrupt, pac};
12use super::{Request, TransferOptions, Word, WordSize};
13 11
14impl From<WordSize> for vals::ChTr1Dw { 12impl From<WordSize> for vals::ChTr1Dw {
15 fn from(raw: WordSize) -> Self { 13 fn from(raw: WordSize) -> Self {
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs
index 3a9097784..87ac38ba8 100644
--- a/embassy-stm32/src/dma/mod.rs
+++ b/embassy-stm32/src/dma/mod.rs
@@ -7,18 +7,18 @@ mod dmamux;
7#[cfg(gpdma)] 7#[cfg(gpdma)]
8mod gpdma; 8mod gpdma;
9 9
10#[cfg(dmamux)]
11pub use dmamux::*;
12
13use crate::Unborrow;
14use core::future::Future; 10use core::future::Future;
15use core::marker::PhantomData; 11use core::marker::PhantomData;
16use core::mem; 12use core::mem;
17use core::pin::Pin; 13use core::pin::Pin;
18use core::task::Waker; 14use core::task::{Context, Poll, Waker};
19use core::task::{Context, Poll}; 15
16#[cfg(dmamux)]
17pub use dmamux::*;
20use embassy_hal_common::unborrow; 18use embassy_hal_common::unborrow;
21 19
20use crate::Unborrow;
21
22#[cfg(feature = "unstable-pac")] 22#[cfg(feature = "unstable-pac")]
23pub mod low_level { 23pub mod low_level {
24 pub use super::transfers::*; 24 pub use super::transfers::*;
@@ -249,15 +249,7 @@ mod transfers {
249 ) -> impl Future<Output = ()> + 'a { 249 ) -> impl Future<Output = ()> + 'a {
250 unborrow!(channel); 250 unborrow!(channel);
251 251
252 unsafe { 252 unsafe { channel.start_write_repeated::<W>(request, repeated, count, reg_addr, Default::default()) };
253 channel.start_write_repeated::<W>(
254 request,
255 repeated,
256 count,
257 reg_addr,
258 Default::default(),
259 )
260 };
261 253
262 Transfer::new(channel) 254 Transfer::new(channel)
263 } 255 }
diff --git a/embassy-stm32/src/eth/generic_smi.rs b/embassy-stm32/src/eth/generic_smi.rs
index 5a323bf5a..968256046 100644
--- a/embassy-stm32/src/eth/generic_smi.rs
+++ b/embassy-stm32/src/eth/generic_smi.rs
@@ -51,10 +51,7 @@ unsafe impl PHY for GenericSMI {
51 Self::smi_write_ext(sm, PHY_REG_WUCSR, 0); 51 Self::smi_write_ext(sm, PHY_REG_WUCSR, 0);
52 52
53 // Enable auto-negotiation 53 // Enable auto-negotiation
54 sm.smi_write( 54 sm.smi_write(PHY_REG_BCR, PHY_REG_BCR_AN | PHY_REG_BCR_ANRST | PHY_REG_BCR_100M);
55 PHY_REG_BCR,
56 PHY_REG_BCR_AN | PHY_REG_BCR_ANRST | PHY_REG_BCR_100M,
57 );
58 } 55 }
59 56
60 fn poll_link<S: StationManagement>(sm: &mut S) -> bool { 57 fn poll_link<S: StationManagement>(sm: &mut S) -> bool {
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs
index d2cfb17c0..7985acc5a 100644
--- a/embassy-stm32/src/eth/v1/mod.rs
+++ b/embassy-stm32/src/eth/v1/mod.rs
@@ -4,33 +4,30 @@ use core::marker::PhantomData;
4use core::sync::atomic::{fence, Ordering}; 4use core::sync::atomic::{fence, Ordering};
5use core::task::Waker; 5use core::task::Waker;
6 6
7use crate::Unborrow;
8use embassy::waitqueue::AtomicWaker; 7use embassy::waitqueue::AtomicWaker;
9use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; 8use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
10use embassy_hal_common::unborrow; 9use embassy_hal_common::unborrow;
11use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; 10use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU};
12 11
13use crate::gpio::sealed::Pin as __GpioPin; 12use crate::gpio::sealed::{AFType, Pin as __GpioPin};
14use crate::gpio::{sealed::AFType, AnyPin, Speed}; 13use crate::gpio::{AnyPin, Speed};
15#[cfg(eth_v1a)] 14#[cfg(eth_v1a)]
16use crate::pac::AFIO; 15use crate::pac::AFIO;
17#[cfg(any(eth_v1b, eth_v1c))] 16#[cfg(any(eth_v1b, eth_v1c))]
18use crate::pac::SYSCFG; 17use crate::pac::SYSCFG;
19use crate::pac::{ETH, RCC}; 18use crate::pac::{ETH, RCC};
19use crate::Unborrow;
20 20
21mod descriptors; 21mod descriptors;
22mod rx_desc; 22mod rx_desc;
23mod tx_desc; 23mod tx_desc;
24 24
25use super::*;
26use descriptors::DescriptorRing; 25use descriptors::DescriptorRing;
27use stm32_metapac::eth::vals::{ 26use stm32_metapac::eth::vals::{Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf};
28 Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf, 27
29}; 28use super::*;
30 29
31pub struct State<'d, T: Instance, const TX: usize, const RX: usize>( 30pub struct State<'d, T: Instance, const TX: usize, const RX: usize>(StateStorage<Inner<'d, T, TX, RX>>);
32 StateStorage<Inner<'d, T, TX, RX>>,
33);
34impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> { 31impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> {
35 pub fn new() -> Self { 32 pub fn new() -> Self {
36 Self(StateStorage::new()) 33 Self(StateStorage::new())
@@ -300,9 +297,7 @@ unsafe impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> StationMa
300 } 297 }
301} 298}
302 299
303impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device 300impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device for Ethernet<'d, T, P, TX, RX> {
304 for Ethernet<'d, T, P, TX, RX>
305{
306 fn is_transmit_ready(&mut self) -> bool { 301 fn is_transmit_ready(&mut self) -> bool {
307 self.state.with(|s| s.desc_ring.tx.available()) 302 self.state.with(|s| s.desc_ring.tx.available())
308 } 303 }
@@ -339,9 +334,7 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device
339 } 334 }
340} 335}
341 336
342impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop 337impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop for Ethernet<'d, T, P, TX, RX> {
343 for Ethernet<'d, T, P, TX, RX>
344{
345 fn drop(&mut self) { 338 fn drop(&mut self) {
346 // NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers 339 // NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers
347 unsafe { 340 unsafe {
diff --git a/embassy-stm32/src/eth/v1/rx_desc.rs b/embassy-stm32/src/eth/v1/rx_desc.rs
index 6164f2975..d482590a1 100644
--- a/embassy-stm32/src/eth/v1/rx_desc.rs
+++ b/embassy-stm32/src/eth/v1/rx_desc.rs
@@ -59,8 +59,7 @@ impl RDes {
59 // 59 //
60 // Contains first buffer of packet AND contains last buf of 60 // Contains first buffer of packet AND contains last buf of
61 // packet AND no errors 61 // packet AND no errors
62 (self.rdes0.get() & (RXDESC_0_ES | RXDESC_0_FS | RXDESC_0_LS)) 62 (self.rdes0.get() & (RXDESC_0_ES | RXDESC_0_FS | RXDESC_0_LS)) == (RXDESC_0_FS | RXDESC_0_LS)
63 == (RXDESC_0_FS | RXDESC_0_LS)
64 } 63 }
65 64
66 /// Return true if this RDes is not currently owned by the DMA 65 /// Return true if this RDes is not currently owned by the DMA
@@ -72,8 +71,7 @@ impl RDes {
72 /// Configures the reception buffer address and length and passed descriptor ownership to the DMA 71 /// Configures the reception buffer address and length and passed descriptor ownership to the DMA
73 #[inline(always)] 72 #[inline(always)]
74 pub fn set_ready(&mut self, buf_addr: u32, buf_len: usize) { 73 pub fn set_ready(&mut self, buf_addr: u32, buf_len: usize) {
75 self.rdes1 74 self.rdes1.set(self.rdes1.get() | (buf_len as u32) & RXDESC_1_RBS_MASK);
76 .set(self.rdes1.get() | (buf_len as u32) & RXDESC_1_RBS_MASK);
77 self.rdes2.set(buf_addr); 75 self.rdes2.set(buf_addr);
78 76
79 // "Preceding reads and writes cannot be moved past subsequent writes." 77 // "Preceding reads and writes cannot be moved past subsequent writes."
@@ -220,11 +218,7 @@ impl<const N: usize> RDesRing<N> {
220 // We already have fences in `set_owned`, which is called in `setup` 218 // We already have fences in `set_owned`, which is called in `setup`
221 219
222 // Start receive 220 // Start receive
223 unsafe { 221 unsafe { ETH.ethernet_dma().dmaomr().modify(|w| w.set_sr(DmaomrSr::STARTED)) };
224 ETH.ethernet_dma()
225 .dmaomr()
226 .modify(|w| w.set_sr(DmaomrSr::STARTED))
227 };
228 222
229 self.demand_poll(); 223 self.demand_poll();
230 } 224 }
diff --git a/embassy-stm32/src/eth/v1/tx_desc.rs b/embassy-stm32/src/eth/v1/tx_desc.rs
index f253ab19a..f2889b550 100644
--- a/embassy-stm32/src/eth/v1/tx_desc.rs
+++ b/embassy-stm32/src/eth/v1/tx_desc.rs
@@ -100,8 +100,7 @@ impl TDes {
100 // set up as a part fo the ring buffer - configures the tdes 100 // set up as a part fo the ring buffer - configures the tdes
101 pub fn setup(&mut self, next: Option<&Self>) { 101 pub fn setup(&mut self, next: Option<&Self>) {
102 // Defer this initialization to this function, so we can have `RingEntry` on bss. 102 // Defer this initialization to this function, so we can have `RingEntry` on bss.
103 self.tdes0 103 self.tdes0.set(TXDESC_0_TCH | TXDESC_0_IOC | TXDESC_0_FS | TXDESC_0_LS);
104 .set(TXDESC_0_TCH | TXDESC_0_IOC | TXDESC_0_FS | TXDESC_0_LS);
105 match next { 104 match next {
106 Some(next) => self.set_buffer2(next as *const TDes as *const u8), 105 Some(next) => self.set_buffer2(next as *const TDes as *const u8),
107 None => { 106 None => {
@@ -169,11 +168,7 @@ impl<const N: usize> TDesRing<N> {
169 // volatiles 168 // volatiles
170 169
171 // Start transmission 170 // Start transmission
172 unsafe { 171 unsafe { ETH.ethernet_dma().dmaomr().modify(|w| w.set_st(St::STARTED)) };
173 ETH.ethernet_dma()
174 .dmaomr()
175 .modify(|w| w.set_st(St::STARTED))
176 };
177 } 172 }
178 173
179 /// Return true if a TDes is available for use 174 /// Return true if a TDes is available for use
diff --git a/embassy-stm32/src/eth/v2/descriptors.rs b/embassy-stm32/src/eth/v2/descriptors.rs
index 23b11857c..c6c06a9ce 100644
--- a/embassy-stm32/src/eth/v2/descriptors.rs
+++ b/embassy-stm32/src/eth/v2/descriptors.rs
@@ -101,11 +101,9 @@ impl<const N: usize> TDesRing<N> {
101 unsafe { 101 unsafe {
102 let dma = ETH.ethernet_dma(); 102 let dma = ETH.ethernet_dma();
103 103
104 dma.dmactx_dlar() 104 dma.dmactx_dlar().write(|w| w.0 = &self.td as *const _ as u32);
105 .write(|w| w.0 = &self.td as *const _ as u32);
106 dma.dmactx_rlr().write(|w| w.set_tdrl((N as u16) - 1)); 105 dma.dmactx_rlr().write(|w| w.set_tdrl((N as u16) - 1));
107 dma.dmactx_dtpr() 106 dma.dmactx_dtpr().write(|w| w.0 = &self.td[0] as *const _ as u32);
108 .write(|w| w.0 = &self.td[0] as *const _ as u32);
109 } 107 }
110 } 108 }
111 109
@@ -127,8 +125,7 @@ impl<const N: usize> TDesRing<N> {
127 125
128 // Read format 126 // Read format
129 td.tdes0.set(address); 127 td.tdes0.set(address);
130 td.tdes2 128 td.tdes2.set(pkt_len as u32 & EMAC_TDES2_B1L | EMAC_TDES2_IOC);
131 .set(pkt_len as u32 & EMAC_TDES2_B1L | EMAC_TDES2_IOC);
132 129
133 // FD: Contains first buffer of packet 130 // FD: Contains first buffer of packet
134 // LD: Contains last buffer of packet 131 // LD: Contains last buffer of packet
@@ -225,8 +222,7 @@ impl RDes {
225 #[inline(always)] 222 #[inline(always)]
226 pub fn set_ready(&mut self, buf_addr: u32) { 223 pub fn set_ready(&mut self, buf_addr: u32) {
227 self.rdes0.set(buf_addr); 224 self.rdes0.set(buf_addr);
228 self.rdes3 225 self.rdes3.set(EMAC_RDES3_BUF1V | EMAC_RDES3_IOC | EMAC_DES3_OWN);
229 .set(EMAC_RDES3_BUF1V | EMAC_RDES3_IOC | EMAC_DES3_OWN);
230 } 226 }
231} 227}
232 228
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs
index e438a7b5e..2b1caf992 100644
--- a/embassy-stm32/src/eth/v2/mod.rs
+++ b/embassy-stm32/src/eth/v2/mod.rs
@@ -2,23 +2,22 @@ use core::marker::PhantomData;
2use core::sync::atomic::{fence, Ordering}; 2use core::sync::atomic::{fence, Ordering};
3use core::task::Waker; 3use core::task::Waker;
4 4
5use crate::Unborrow;
6use embassy::waitqueue::AtomicWaker; 5use embassy::waitqueue::AtomicWaker;
7use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; 6use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
8use embassy_hal_common::unborrow; 7use embassy_hal_common::unborrow;
9use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; 8use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU};
10 9
11use crate::gpio::sealed::Pin as _; 10use crate::gpio::sealed::{AFType, Pin as _};
12use crate::gpio::{sealed::AFType, AnyPin, Speed}; 11use crate::gpio::{AnyPin, Speed};
13use crate::pac::{ETH, RCC, SYSCFG}; 12use crate::pac::{ETH, RCC, SYSCFG};
13use crate::Unborrow;
14 14
15mod descriptors; 15mod descriptors;
16use super::*;
17use descriptors::DescriptorRing; 16use descriptors::DescriptorRing;
18 17
19pub struct State<'d, T: Instance, const TX: usize, const RX: usize>( 18use super::*;
20 StateStorage<Inner<'d, T, TX, RX>>, 19
21); 20pub struct State<'d, T: Instance, const TX: usize, const RX: usize>(StateStorage<Inner<'d, T, TX, RX>>);
22impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> { 21impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> {
23 pub fn new() -> Self { 22 pub fn new() -> Self {
24 Self(StateStorage::new()) 23 Self(StateStorage::new())
@@ -234,9 +233,7 @@ unsafe impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> StationMa
234 } 233 }
235} 234}
236 235
237impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device 236impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device for Ethernet<'d, T, P, TX, RX> {
238 for Ethernet<'d, T, P, TX, RX>
239{
240 fn is_transmit_ready(&mut self) -> bool { 237 fn is_transmit_ready(&mut self) -> bool {
241 self.state.with(|s| s.desc_ring.tx.available()) 238 self.state.with(|s| s.desc_ring.tx.available())
242 } 239 }
@@ -273,9 +270,7 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device
273 } 270 }
274} 271}
275 272
276impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop 273impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop for Ethernet<'d, T, P, TX, RX> {
277 for Ethernet<'d, T, P, TX, RX>
278{
279 fn drop(&mut self) { 274 fn drop(&mut self) {
280 // NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers 275 // NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers
281 unsafe { 276 unsafe {
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index efe54e59a..378665b77 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -1,17 +1,15 @@
1use crate::Unborrow;
2use core::future::Future; 1use core::future::Future;
3use core::marker::PhantomData; 2use core::marker::PhantomData;
4use core::pin::Pin; 3use core::pin::Pin;
5use core::task::{Context, Poll}; 4use core::task::{Context, Poll};
5
6use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
7use embassy_hal_common::unsafe_impl_unborrow; 7use embassy_hal_common::unsafe_impl_unborrow;
8 8
9use crate::gpio::{AnyPin, Input, Pin as GpioPin}; 9use crate::gpio::{AnyPin, Input, Pin as GpioPin};
10use crate::interrupt;
11use crate::pac;
12use crate::pac::exti::regs::Lines; 10use crate::pac::exti::regs::Lines;
13use crate::pac::EXTI; 11use crate::pac::EXTI;
14use crate::peripherals; 12use crate::{interrupt, pac, peripherals, Unborrow};
15 13
16const EXTI_COUNT: usize = 16; 14const EXTI_COUNT: usize = 16;
17const NEW_AW: AtomicWaker = AtomicWaker::new(); 15const NEW_AW: AtomicWaker = AtomicWaker::new();
@@ -130,9 +128,10 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> {
130} 128}
131 129
132mod eh02 { 130mod eh02 {
133 use super::*;
134 use core::convert::Infallible; 131 use core::convert::Infallible;
135 132
133 use super::*;
134
136 impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> { 135 impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> {
137 type Error = Infallible; 136 type Error = Infallible;
138 137
@@ -148,9 +147,10 @@ mod eh02 {
148 147
149#[cfg(feature = "unstable-traits")] 148#[cfg(feature = "unstable-traits")]
150mod eh1 { 149mod eh1 {
151 use super::*;
152 use core::convert::Infallible; 150 use core::convert::Infallible;
153 151
152 use super::*;
153
154 impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> { 154 impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> {
155 type Error = Infallible; 155 type Error = Infallible;
156 } 156 }
@@ -212,9 +212,7 @@ impl<'a> ExtiInputFuture<'a> {
212 fn new(pin: u8, port: u8, rising: bool, falling: bool) -> Self { 212 fn new(pin: u8, port: u8, rising: bool, falling: bool) -> Self {
213 critical_section::with(|_| unsafe { 213 critical_section::with(|_| unsafe {
214 let pin = pin as usize; 214 let pin = pin as usize;
215 exticr_regs() 215 exticr_regs().exticr(pin / 4).modify(|w| w.set_exti(pin % 4, port));
216 .exticr(pin / 4)
217 .modify(|w| w.set_exti(pin % 4, port));
218 EXTI.rtsr(0).modify(|w| w.set_line(pin, rising)); 216 EXTI.rtsr(0).modify(|w| w.set_line(pin, rising));
219 EXTI.ftsr(0).modify(|w| w.set_line(pin, falling)); 217 EXTI.ftsr(0).modify(|w| w.set_line(pin, falling));
220 218
@@ -366,8 +364,7 @@ macro_rules! enable_irq {
366 364
367/// safety: must be called only once 365/// safety: must be called only once
368pub(crate) unsafe fn init() { 366pub(crate) unsafe fn init() {
369 use crate::interrupt::Interrupt; 367 use crate::interrupt::{Interrupt, InterruptExt};
370 use crate::interrupt::InterruptExt;
371 368
372 foreach_exti_irq!(enable_irq); 369 foreach_exti_irq!(enable_irq);
373 370
diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs
index a5dc8dd0a..1cb08ee1a 100644
--- a/embassy-stm32/src/flash/f3.rs
+++ b/embassy-stm32/src/flash/f3.rs
@@ -20,10 +20,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error
20 let mut ret: Result<(), Error> = Ok(()); 20 let mut ret: Result<(), Error> = Ok(());
21 let mut offset = offset; 21 let mut offset = offset;
22 for chunk in buf.chunks(2) { 22 for chunk in buf.chunks(2) {
23 write_volatile( 23 write_volatile(offset as *mut u16, u16::from_le_bytes(chunk[0..2].try_into().unwrap()));
24 offset as *mut u16,
25 u16::from_le_bytes(chunk[0..2].try_into().unwrap()),
26 );
27 offset += chunk.len() as u32; 24 offset += chunk.len() as u32;
28 25
29 ret = blocking_wait_ready(); 26 ret = blocking_wait_ready();
diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs
index 16316fd93..6d47b78a0 100644
--- a/embassy-stm32/src/flash/f7.rs
+++ b/embassy-stm32/src/flash/f7.rs
@@ -26,10 +26,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error
26 let mut offset = offset; 26 let mut offset = offset;
27 for chunk in buf.chunks(super::WRITE_SIZE) { 27 for chunk in buf.chunks(super::WRITE_SIZE) {
28 for val in chunk.chunks(4) { 28 for val in chunk.chunks(4) {
29 write_volatile( 29 write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap()));
30 offset as *mut u32,
31 u32::from_le_bytes(val[0..4].try_into().unwrap()),
32 );
33 offset += val.len() as u32; 30 offset += val.len() as u32;
34 31
35 // prevents parallelism errors 32 // prevents parallelism errors
diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs
index afccffc4a..7ce0ac776 100644
--- a/embassy-stm32/src/flash/h7.rs
+++ b/embassy-stm32/src/flash/h7.rs
@@ -28,8 +28,7 @@ pub(crate) unsafe fn unlock() {
28} 28}
29 29
30pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error> { 30pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error> {
31 let bank = if !is_dual_bank() || (offset - super::FLASH_BASE as u32) < SECOND_BANK_OFFSET as u32 31 let bank = if !is_dual_bank() || (offset - super::FLASH_BASE as u32) < SECOND_BANK_OFFSET as u32 {
32 {
33 pac::FLASH.bank(0) 32 pac::FLASH.bank(0)
34 } else { 33 } else {
35 pac::FLASH.bank(1) 34 pac::FLASH.bank(1)
@@ -46,10 +45,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error
46 'outer: for chunk in buf.chunks(super::WRITE_SIZE) { 45 'outer: for chunk in buf.chunks(super::WRITE_SIZE) {
47 for val in chunk.chunks(4) { 46 for val in chunk.chunks(4) {
48 trace!("Writing at {:x}", offset); 47 trace!("Writing at {:x}", offset);
49 write_volatile( 48 write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap()));
50 offset as *mut u32,
51 u32::from_le_bytes(val[0..4].try_into().unwrap()),
52 );
53 offset += val.len() as u32; 49 offset += val.len() as u32;
54 50
55 ret = blocking_wait_ready(bank); 51 ret = blocking_wait_ready(bank);
diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs
index cad950e6f..5048a3314 100644
--- a/embassy-stm32/src/flash/l.rs
+++ b/embassy-stm32/src/flash/l.rs
@@ -42,10 +42,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error
42 let mut offset = offset; 42 let mut offset = offset;
43 for chunk in buf.chunks(super::WRITE_SIZE) { 43 for chunk in buf.chunks(super::WRITE_SIZE) {
44 for val in chunk.chunks(4) { 44 for val in chunk.chunks(4) {
45 write_volatile( 45 write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap()));
46 offset as *mut u32,
47 u32::from_le_bytes(val[0..4].try_into().unwrap()),
48 );
49 offset += val.len() as u32; 46 offset += val.len() as u32;
50 } 47 }
51 48
@@ -80,11 +77,7 @@ pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> {
80 let idx = (page - super::FLASH_BASE as u32) / super::ERASE_SIZE as u32; 77 let idx = (page - super::FLASH_BASE as u32) / super::ERASE_SIZE as u32;
81 78
82 #[cfg(flash_l4)] 79 #[cfg(flash_l4)]
83 let (idx, bank) = if idx > 255 { 80 let (idx, bank) = if idx > 255 { (idx - 256, true) } else { (idx, false) };
84 (idx - 256, true)
85 } else {
86 (idx, false)
87 };
88 81
89 pac::FLASH.cr().modify(|w| { 82 pac::FLASH.cr().modify(|w| {
90 w.set_per(true); 83 w.set_per(true);
diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs
index 330e51421..31ca243a6 100644
--- a/embassy-stm32/src/flash/mod.rs
+++ b/embassy-stm32/src/flash/mod.rs
@@ -1,17 +1,11 @@
1use crate::peripherals::FLASH;
2use crate::Unborrow;
3use core::marker::PhantomData; 1use core::marker::PhantomData;
4use embassy_hal_common::unborrow;
5 2
6use embedded_storage::nor_flash::{ 3use embassy_hal_common::unborrow;
7 ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, 4use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash};
8};
9 5
10pub use crate::pac::ERASE_SIZE; 6pub use crate::pac::{ERASE_SIZE, ERASE_VALUE, FLASH_BASE, FLASH_SIZE, WRITE_SIZE};
11pub use crate::pac::ERASE_VALUE; 7use crate::peripherals::FLASH;
12pub use crate::pac::FLASH_BASE; 8use crate::Unborrow;
13pub use crate::pac::FLASH_SIZE;
14pub use crate::pac::WRITE_SIZE;
15const FLASH_END: usize = FLASH_BASE + FLASH_SIZE; 9const FLASH_END: usize = FLASH_BASE + FLASH_SIZE;
16 10
17#[cfg_attr(any(flash_wl, flash_wb, flash_l0, flash_l1, flash_l4), path = "l.rs")] 11#[cfg_attr(any(flash_wl, flash_wb, flash_l0, flash_l1, flash_l4), path = "l.rs")]
diff --git a/embassy-stm32/src/fmc/mod.rs b/embassy-stm32/src/fmc/mod.rs
index c227cfa17..4f8e467d0 100644
--- a/embassy-stm32/src/fmc/mod.rs
+++ b/embassy-stm32/src/fmc/mod.rs
@@ -1,9 +1,10 @@
1use crate::Unborrow;
2use core::marker::PhantomData; 1use core::marker::PhantomData;
2
3use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
4 4
5use crate::gpio::sealed::AFType; 5use crate::gpio::sealed::AFType;
6use crate::gpio::{Pull, Speed}; 6use crate::gpio::{Pull, Speed};
7use crate::Unborrow;
7 8
8mod pins; 9mod pins;
9pub use pins::*; 10pub use pins::*;
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index 31f22e21b..6e445f8cd 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -1,12 +1,11 @@
1#![macro_use] 1#![macro_use]
2use crate::Unborrow;
3use core::convert::Infallible; 2use core::convert::Infallible;
4use core::marker::PhantomData; 3use core::marker::PhantomData;
4
5use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; 5use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
6 6
7use crate::pac;
8use crate::pac::gpio::{self, vals}; 7use crate::pac::gpio::{self, vals};
9use crate::peripherals; 8use crate::{pac, peripherals, Unborrow};
10 9
11/// Pull setting for an input. 10/// Pull setting for an input.
12#[derive(Debug, Eq, PartialEq)] 11#[derive(Debug, Eq, PartialEq)]
@@ -138,8 +137,7 @@ impl<'d, T: Pin> Drop for Input<'d, T> {
138 #[cfg(gpio_v1)] 137 #[cfg(gpio_v1)]
139 { 138 {
140 let crlh = if n < 8 { 0 } else { 1 }; 139 let crlh = if n < 8 { 0 } else { 1 };
141 r.cr(crlh) 140 r.cr(crlh).modify(|w| w.set_cnf_in(n % 8, vals::CnfIn::FLOATING));
142 .modify(|w| w.set_cnf_in(n % 8, vals::CnfIn::FLOATING));
143 } 141 }
144 #[cfg(gpio_v2)] 142 #[cfg(gpio_v2)]
145 r.pupdr().modify(|w| w.set_pupdr(n, vals::Pupdr::FLOATING)); 143 r.pupdr().modify(|w| w.set_pupdr(n, vals::Pupdr::FLOATING));
@@ -264,12 +262,7 @@ pub struct OutputOpenDrain<'d, T: Pin> {
264 262
265impl<'d, T: Pin> OutputOpenDrain<'d, T> { 263impl<'d, T: Pin> OutputOpenDrain<'d, T> {
266 #[inline] 264 #[inline]
267 pub fn new( 265 pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self {
268 pin: impl Unborrow<Target = T> + 'd,
269 initial_output: Level,
270 speed: Speed,
271 pull: Pull,
272 ) -> Self {
273 unborrow!(pin); 266 unborrow!(pin);
274 267
275 match initial_output { 268 match initial_output {
@@ -289,8 +282,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
289 Pull::None => {} 282 Pull::None => {}
290 } 283 }
291 r.cr(crlh).modify(|w| w.set_mode(n % 8, speed.into())); 284 r.cr(crlh).modify(|w| w.set_mode(n % 8, speed.into()));
292 r.cr(crlh) 285 r.cr(crlh).modify(|w| w.set_cnf_out(n % 8, vals::CnfOut::OPENDRAIN));
293 .modify(|w| w.set_cnf_out(n % 8, vals::CnfOut::OPENDRAIN));
294 } 286 }
295 #[cfg(gpio_v2)] 287 #[cfg(gpio_v2)]
296 { 288 {
@@ -480,18 +472,12 @@ pub(crate) mod sealed {
480 block.afr(pin / 8).modify(|w| w.set_afr(pin % 8, af_num)); 472 block.afr(pin / 8).modify(|w| w.set_afr(pin % 8, af_num));
481 match af_type { 473 match af_type {
482 AFType::Input => {} 474 AFType::Input => {}
483 AFType::OutputPushPull => { 475 AFType::OutputPushPull => block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)),
484 block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)) 476 AFType::OutputOpenDrain => block.otyper().modify(|w| w.set_ot(pin, vals::Ot::OPENDRAIN)),
485 }
486 AFType::OutputOpenDrain => block
487 .otyper()
488 .modify(|w| w.set_ot(pin, vals::Ot::OPENDRAIN)),
489 } 477 }
490 block.pupdr().modify(|w| w.set_pupdr(pin, pull.into())); 478 block.pupdr().modify(|w| w.set_pupdr(pin, pull.into()));
491 479
492 block 480 block.moder().modify(|w| w.set_moder(pin, vals::Moder::ALTERNATE));
493 .moder()
494 .modify(|w| w.set_moder(pin, vals::Moder::ALTERNATE));
495 } 481 }
496 482
497 #[inline] 483 #[inline]
@@ -507,9 +493,7 @@ pub(crate) mod sealed {
507 }); 493 });
508 } 494 }
509 #[cfg(gpio_v2)] 495 #[cfg(gpio_v2)]
510 block 496 block.moder().modify(|w| w.set_moder(pin, vals::Moder::ANALOG));
511 .moder()
512 .modify(|w| w.set_moder(pin, vals::Moder::ANALOG));
513 } 497 }
514 498
515 /// Set the pin as "disconnected", ie doing nothing and consuming the lowest 499 /// Set the pin as "disconnected", ie doing nothing and consuming the lowest
@@ -535,9 +519,7 @@ pub(crate) mod sealed {
535 } 519 }
536 520
537 #[cfg(gpio_v2)] 521 #[cfg(gpio_v2)]
538 self.block() 522 self.block().ospeedr().modify(|w| w.set_ospeedr(pin, speed.into()));
539 .ospeedr()
540 .modify(|w| w.set_ospeedr(pin, speed.into()));
541 } 523 }
542 } 524 }
543} 525}
@@ -623,10 +605,9 @@ pub(crate) unsafe fn init() {
623} 605}
624 606
625mod eh02 { 607mod eh02 {
608 use embedded_hal_02::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
609
626 use super::*; 610 use super::*;
627 use embedded_hal_02::digital::v2::{
628 InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin,
629 };
630 611
631 impl<'d, T: Pin> InputPin for Input<'d, T> { 612 impl<'d, T: Pin> InputPin for Input<'d, T> {
632 type Error = Infallible; 613 type Error = Infallible;
@@ -715,12 +696,11 @@ mod eh02 {
715 696
716#[cfg(feature = "unstable-traits")] 697#[cfg(feature = "unstable-traits")]
717mod eh1 { 698mod eh1 {
718 use super::*; 699 use embedded_hal_1::digital::blocking::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
719 use embedded_hal_1::digital::blocking::{
720 InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin,
721 };
722 use embedded_hal_1::digital::ErrorType; 700 use embedded_hal_1::digital::ErrorType;
723 701
702 use super::*;
703
724 impl<'d, T: Pin> ErrorType for Input<'d, T> { 704 impl<'d, T: Pin> ErrorType for Input<'d, T> {
725 type Error = Infallible; 705 type Error = Infallible;
726 } 706 }
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs
index 54f8d1935..9d314f411 100644
--- a/embassy-stm32/src/i2c/mod.rs
+++ b/embassy-stm32/src/i2c/mod.rs
@@ -5,9 +5,10 @@ use crate::interrupt::Interrupt;
5#[cfg_attr(i2c_v1, path = "v1.rs")] 5#[cfg_attr(i2c_v1, path = "v1.rs")]
6#[cfg_attr(i2c_v2, path = "v2.rs")] 6#[cfg_attr(i2c_v2, path = "v2.rs")]
7mod _version; 7mod _version;
8use crate::peripherals;
9pub use _version::*; 8pub use _version::*;
10 9
10use crate::peripherals;
11
11#[derive(Debug)] 12#[derive(Debug)]
12#[cfg_attr(feature = "defmt", derive(defmt::Format))] 13#[cfg_attr(feature = "defmt", derive(defmt::Format))]
13pub enum Error { 14pub enum Error {
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs
index 77acc3870..87a4f9699 100644
--- a/embassy-stm32/src/i2c/v1.rs
+++ b/embassy-stm32/src/i2c/v1.rs
@@ -1,11 +1,12 @@
1use crate::Unborrow;
2use core::marker::PhantomData; 1use core::marker::PhantomData;
2
3use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
4 4
5use crate::gpio::sealed::AFType; 5use crate::gpio::sealed::AFType;
6use crate::i2c::{Error, Instance, SclPin, SdaPin}; 6use crate::i2c::{Error, Instance, SclPin, SdaPin};
7use crate::pac::i2c; 7use crate::pac::i2c;
8use crate::time::Hertz; 8use crate::time::Hertz;
9use crate::Unborrow;
9 10
10pub struct State {} 11pub struct State {}
11 12
@@ -68,9 +69,7 @@ impl<'d, T: Instance> I2c<'d, T> {
68 }); 69 });
69 } 70 }
70 71
71 Self { 72 Self { phantom: PhantomData }
72 phantom: PhantomData,
73 }
74 } 73 }
75 74
76 unsafe fn check_and_clear_error_flags(&self) -> Result<i2c::regs::Sr1, Error> { 75 unsafe fn check_and_clear_error_flags(&self) -> Result<i2c::regs::Sr1, Error> {
@@ -249,12 +248,7 @@ impl<'d, T: Instance> I2c<'d, T> {
249 Ok(()) 248 Ok(())
250 } 249 }
251 250
252 pub fn blocking_write_read( 251 pub fn blocking_write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> {
253 &mut self,
254 addr: u8,
255 bytes: &[u8],
256 buffer: &mut [u8],
257 ) -> Result<(), Error> {
258 unsafe { self.write_bytes(addr, bytes)? }; 252 unsafe { self.write_bytes(addr, bytes)? };
259 self.blocking_read(addr, buffer)?; 253 self.blocking_read(addr, buffer)?;
260 254
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index 4d4840a0d..1a085e782 100644
--- a/embassy-stm32/src/i2c/v2.rs
+++ b/embassy-stm32/src/i2c/v2.rs
@@ -2,8 +2,6 @@ use core::cmp;
2use core::marker::PhantomData; 2use core::marker::PhantomData;
3use core::task::Poll; 3use core::task::Poll;
4 4
5use crate::interrupt::InterruptExt;
6use crate::Unborrow;
7use atomic_polyfill::{AtomicUsize, Ordering}; 5use atomic_polyfill::{AtomicUsize, Ordering};
8use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
9use embassy_hal_common::drop::OnDrop; 7use embassy_hal_common::drop::OnDrop;
@@ -13,8 +11,10 @@ use futures::future::poll_fn;
13use crate::dma::NoDma; 11use crate::dma::NoDma;
14use crate::gpio::sealed::AFType; 12use crate::gpio::sealed::AFType;
15use crate::i2c::{Error, Instance, SclPin, SdaPin}; 13use crate::i2c::{Error, Instance, SclPin, SdaPin};
14use crate::interrupt::InterruptExt;
16use crate::pac::i2c; 15use crate::pac::i2c;
17use crate::time::Hertz; 16use crate::time::Hertz;
17use crate::Unborrow;
18 18
19pub struct State { 19pub struct State {
20 waker: AtomicWaker, 20 waker: AtomicWaker,
@@ -277,12 +277,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
277 } 277 }
278 } 278 }
279 279
280 fn read_internal( 280 fn read_internal(&mut self, address: u8, buffer: &mut [u8], restart: bool) -> Result<(), Error> {
281 &mut self,
282 address: u8,
283 buffer: &mut [u8],
284 restart: bool,
285 ) -> Result<(), Error> {
286 let completed_chunks = buffer.len() / 255; 281 let completed_chunks = buffer.len() / 255;
287 let total_chunks = if completed_chunks * 255 == buffer.len() { 282 let total_chunks = if completed_chunks * 255 == buffer.len() {
288 completed_chunks 283 completed_chunks
@@ -335,12 +330,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
335 // ST SAD+W 330 // ST SAD+W
336 // NOTE(unsafe) We have &mut self 331 // NOTE(unsafe) We have &mut self
337 unsafe { 332 unsafe {
338 Self::master_write( 333 Self::master_write(address, bytes.len().min(255), Stop::Software, last_chunk_idx != 0);
339 address,
340 bytes.len().min(255),
341 Stop::Software,
342 last_chunk_idx != 0,
343 );
344 } 334 }
345 335
346 for (number, chunk) in bytes.chunks(255).enumerate() { 336 for (number, chunk) in bytes.chunks(255).enumerate() {
@@ -467,12 +457,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
467 Ok(()) 457 Ok(())
468 } 458 }
469 459
470 async fn read_dma_internal( 460 async fn read_dma_internal(&mut self, address: u8, buffer: &mut [u8], restart: bool) -> Result<(), Error>
471 &mut self,
472 address: u8,
473 buffer: &mut [u8],
474 restart: bool,
475 ) -> Result<(), Error>
476 where 461 where
477 RXDMA: crate::i2c::RxDma<T>, 462 RXDMA: crate::i2c::RxDma<T>,
478 { 463 {
@@ -513,13 +498,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
513 498
514 // NOTE(unsafe) self.rx_dma does not fiddle with the i2c registers 499 // NOTE(unsafe) self.rx_dma does not fiddle with the i2c registers
515 unsafe { 500 unsafe {
516 Self::master_read( 501 Self::master_read(address, total_len.min(255), Stop::Software, total_chunks != 1, restart);
517 address,
518 total_len.min(255),
519 Stop::Software,
520 total_chunks != 1,
521 restart,
522 );
523 } 502 }
524 503
525 poll_fn(|cx| { 504 poll_fn(|cx| {
@@ -597,12 +576,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
597 } 576 }
598 } 577 }
599 578
600 pub async fn write_read( 579 pub async fn write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error>
601 &mut self,
602 address: u8,
603 bytes: &[u8],
604 buffer: &mut [u8],
605 ) -> Result<(), Error>
606 where 580 where
607 TXDMA: super::TxDma<T>, 581 TXDMA: super::TxDma<T>,
608 RXDMA: super::RxDma<T>, 582 RXDMA: super::RxDma<T>,
@@ -634,12 +608,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
634 self.write_internal(address, bytes, true) 608 self.write_internal(address, bytes, true)
635 } 609 }
636 610
637 pub fn blocking_write_read( 611 pub fn blocking_write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> {
638 &mut self,
639 address: u8,
640 bytes: &[u8],
641 buffer: &mut [u8],
642 ) -> Result<(), Error> {
643 self.write_internal(address, bytes, false)?; 612 self.write_internal(address, bytes, false)?;
644 self.read_internal(address, buffer, true) 613 self.read_internal(address, buffer, true)
645 // Automatic Stop 614 // Automatic Stop
@@ -675,10 +644,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
675 if idx != 0 { 644 if idx != 0 {
676 // NOTE(unsafe) We have &mut self 645 // NOTE(unsafe) We have &mut self
677 unsafe { 646 unsafe {
678 Self::master_continue( 647 Self::master_continue(slice_len.min(255), (idx != last_slice_index) || (slice_len > 255));
679 slice_len.min(255),
680 (idx != last_slice_index) || (slice_len > 255),
681 );
682 } 648 }
683 } 649 }
684 650
@@ -686,10 +652,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
686 if number != 0 { 652 if number != 0 {
687 // NOTE(unsafe) We have &mut self 653 // NOTE(unsafe) We have &mut self
688 unsafe { 654 unsafe {
689 Self::master_continue( 655 Self::master_continue(chunk.len(), (number != last_chunk_idx) || (idx != last_slice_index));
690 chunk.len(),
691 (number != last_chunk_idx) || (idx != last_slice_index),
692 );
693 } 656 }
694 } 657 }
695 658
@@ -737,12 +700,7 @@ mod eh02 {
737 impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { 700 impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> {
738 type Error = Error; 701 type Error = Error;
739 702
740 fn write_read( 703 fn write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> {
741 &mut self,
742 address: u8,
743 bytes: &[u8],
744 buffer: &mut [u8],
745 ) -> Result<(), Self::Error> {
746 self.blocking_write_read(address, bytes, buffer) 704 self.blocking_write_read(address, bytes, buffer)
747 } 705 }
748 } 706 }
@@ -794,10 +752,7 @@ impl Timings {
794 752
795 // For the standard-mode configuration method, we must have a ratio of 4 753 // For the standard-mode configuration method, we must have a ratio of 4
796 // or higher 754 // or higher
797 assert!( 755 assert!(ratio >= 4, "The I2C PCLK must be at least 4 times the bus frequency!");
798 ratio >= 4,
799 "The I2C PCLK must be at least 4 times the bus frequency!"
800 );
801 756
802 let (presc_reg, scll, sclh, sdadel, scldel) = if freq > 100_000 { 757 let (presc_reg, scll, sclh, sdadel, scldel) = if freq > 100_000 {
803 // Fast-mode (Fm) or Fast-mode Plus (Fm+) 758 // Fast-mode (Fm) or Fast-mode Plus (Fm+)
@@ -831,13 +786,7 @@ impl Timings {
831 (sdadel, scldel) 786 (sdadel, scldel)
832 }; 787 };
833 788
834 ( 789 (presc_reg, scll as u8, sclh as u8, sdadel as u8, scldel as u8)
835 presc_reg,
836 scll as u8,
837 sclh as u8,
838 sdadel as u8,
839 scldel as u8,
840 )
841 } else { 790 } else {
842 // Standard-mode (Sm) 791 // Standard-mode (Sm)
843 // here we pick SCLL = SCLH 792 // here we pick SCLL = SCLH
@@ -855,21 +804,12 @@ impl Timings {
855 let scll = sclh; 804 let scll = sclh;
856 805
857 // Speed check 806 // Speed check
858 assert!( 807 assert!(sclh < 256, "The I2C PCLK is too fast for this bus frequency!");
859 sclh < 256,
860 "The I2C PCLK is too fast for this bus frequency!"
861 );
862 808
863 let sdadel = i2cclk / 2_000_000 / presc; 809 let sdadel = i2cclk / 2_000_000 / presc;
864 let scldel = i2cclk / 500_000 / presc - 1; 810 let scldel = i2cclk / 500_000 / presc - 1;
865 811
866 ( 812 (presc_reg, scll as u8, sclh as u8, sdadel as u8, scldel as u8)
867 presc_reg,
868 scll as u8,
869 sclh as u8,
870 sdadel as u8,
871 scldel as u8,
872 )
873 }; 813 };
874 814
875 // Sanity check 815 // Sanity check
@@ -900,9 +840,9 @@ mod eh1 {
900 match *self { 840 match *self {
901 Self::Bus => embedded_hal_1::i2c::ErrorKind::Bus, 841 Self::Bus => embedded_hal_1::i2c::ErrorKind::Bus,
902 Self::Arbitration => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss, 842 Self::Arbitration => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss,
903 Self::Nack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge( 843 Self::Nack => {
904 embedded_hal_1::i2c::NoAcknowledgeSource::Unknown, 844 embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Unknown)
905 ), 845 }
906 Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, 846 Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other,
907 Self::Crc => embedded_hal_1::i2c::ErrorKind::Other, 847 Self::Crc => embedded_hal_1::i2c::ErrorKind::Other,
908 Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, 848 Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun,
@@ -911,9 +851,7 @@ mod eh1 {
911 } 851 }
912 } 852 }
913 853
914 impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_1::i2c::ErrorType 854 impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_1::i2c::ErrorType for I2c<'d, T, TXDMA, RXDMA> {
915 for I2c<'d, T, TXDMA, RXDMA>
916 {
917 type Error = Error; 855 type Error = Error;
918 } 856 }
919} 857}
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index b795352c1..717ebb95e 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -1,8 +1,5 @@
1#![no_std] 1#![no_std]
2#![cfg_attr( 2#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))]
3 feature = "nightly",
4 feature(generic_associated_types, type_alias_impl_trait)
5)]
6 3
7// This must go FIRST so that all the other modules see its macros. 4// This must go FIRST so that all the other modules see its macros.
8pub mod fmt; 5pub mod fmt;
@@ -42,9 +39,7 @@ pub mod i2c;
42 39
43#[cfg(crc)] 40#[cfg(crc)]
44pub mod crc; 41pub mod crc;
45#[cfg(any( 42#[cfg(any(flash_l0, flash_l1, flash_wl, flash_wb, flash_l4, flash_f3, flash_f7, flash_h7))]
46 flash_l0, flash_l1, flash_wl, flash_wb, flash_l4, flash_f3, flash_f7, flash_h7
47))]
48pub mod flash; 43pub mod flash;
49pub mod pwm; 44pub mod pwm;
50#[cfg(rng)] 45#[cfg(rng)]
@@ -77,7 +72,6 @@ pub use _generated::{peripherals, Peripherals};
77pub use embassy_cortex_m::executor; 72pub use embassy_cortex_m::executor;
78pub use embassy_hal_common::{unborrow, Unborrow}; 73pub use embassy_hal_common::{unborrow, Unborrow};
79pub use embassy_macros::cortex_m_interrupt as interrupt; 74pub use embassy_macros::cortex_m_interrupt as interrupt;
80
81#[cfg(feature = "unstable-pac")] 75#[cfg(feature = "unstable-pac")]
82pub use stm32_metapac as pac; 76pub use stm32_metapac as pac;
83#[cfg(not(feature = "unstable-pac"))] 77#[cfg(not(feature = "unstable-pac"))]
@@ -114,8 +108,8 @@ pub fn init(config: Config) -> Peripherals {
114 cr.set_dbg_standby(true); 108 cr.set_dbg_standby(true);
115 } 109 }
116 #[cfg(any( 110 #[cfg(any(
117 dbgmcu_f1, dbgmcu_f2, dbgmcu_f3, dbgmcu_f4, dbgmcu_f7, dbgmcu_g4, dbgmcu_f7, 111 dbgmcu_f1, dbgmcu_f2, dbgmcu_f3, dbgmcu_f4, dbgmcu_f7, dbgmcu_g4, dbgmcu_f7, dbgmcu_l0, dbgmcu_l1,
118 dbgmcu_l0, dbgmcu_l1, dbgmcu_l4, dbgmcu_wb, dbgmcu_wl 112 dbgmcu_l4, dbgmcu_wb, dbgmcu_wl
119 ))] 113 ))]
120 { 114 {
121 cr.set_dbg_sleep(true); 115 cr.set_dbg_sleep(true);
diff --git a/embassy-stm32/src/pwm/mod.rs b/embassy-stm32/src/pwm/mod.rs
index c6edbc6c3..bd8358563 100644
--- a/embassy-stm32/src/pwm/mod.rs
+++ b/embassy-stm32/src/pwm/mod.rs
@@ -64,9 +64,7 @@ pub(crate) mod sealed {
64 unsafe fn get_max_compare_value(&self) -> u16; 64 unsafe fn get_max_compare_value(&self) -> u16;
65 } 65 }
66 66
67 pub trait CaptureCompare32bitInstance: 67 pub trait CaptureCompare32bitInstance: crate::timer::sealed::GeneralPurpose32bitInstance {
68 crate::timer::sealed::GeneralPurpose32bitInstance
69 {
70 unsafe fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode); 68 unsafe fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode);
71 69
72 unsafe fn enable_channel(&mut self, channel: Channel, enable: bool); 70 unsafe fn enable_channel(&mut self, channel: Channel, enable: bool);
@@ -82,10 +80,7 @@ pub trait CaptureCompare16bitInstance:
82{ 80{
83} 81}
84pub trait CaptureCompare32bitInstance: 82pub trait CaptureCompare32bitInstance:
85 sealed::CaptureCompare32bitInstance 83 sealed::CaptureCompare32bitInstance + CaptureCompare16bitInstance + crate::timer::GeneralPurpose32bitInstance + 'static
86 + CaptureCompare16bitInstance
87 + crate::timer::GeneralPurpose32bitInstance
88 + 'static
89{ 84{
90} 85}
91 86
@@ -93,11 +88,7 @@ pub trait CaptureCompare32bitInstance:
93macro_rules! impl_compare_capable_16bit { 88macro_rules! impl_compare_capable_16bit {
94 ($inst:ident) => { 89 ($inst:ident) => {
95 impl crate::pwm::sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { 90 impl crate::pwm::sealed::CaptureCompare16bitInstance for crate::peripherals::$inst {
96 unsafe fn set_output_compare_mode( 91 unsafe fn set_output_compare_mode(&mut self, channel: crate::pwm::Channel, mode: OutputCompareMode) {
97 &mut self,
98 channel: crate::pwm::Channel,
99 mode: OutputCompareMode,
100 ) {
101 use crate::timer::sealed::GeneralPurpose16bitInstance; 92 use crate::timer::sealed::GeneralPurpose16bitInstance;
102 let r = Self::regs_gp16(); 93 let r = Self::regs_gp16();
103 let raw_channel: usize = channel.raw(); 94 let raw_channel: usize = channel.raw();
@@ -114,9 +105,7 @@ macro_rules! impl_compare_capable_16bit {
114 105
115 unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { 106 unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) {
116 use crate::timer::sealed::GeneralPurpose16bitInstance; 107 use crate::timer::sealed::GeneralPurpose16bitInstance;
117 Self::regs_gp16() 108 Self::regs_gp16().ccr(channel.raw()).modify(|w| w.set_ccr(value));
118 .ccr(channel.raw())
119 .modify(|w| w.set_ccr(value));
120 } 109 }
121 110
122 unsafe fn get_max_compare_value(&self) -> u16 { 111 unsafe fn get_max_compare_value(&self) -> u16 {
diff --git a/embassy-stm32/src/pwm/simple_pwm.rs b/embassy-stm32/src/pwm/simple_pwm.rs
index 990f5bda7..a475f3f70 100644
--- a/embassy-stm32/src/pwm/simple_pwm.rs
+++ b/embassy-stm32/src/pwm/simple_pwm.rs
@@ -1,11 +1,12 @@
1use crate::Unborrow;
2use core::marker::PhantomData; 1use core::marker::PhantomData;
2
3use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
4 4
5use super::*; 5use super::*;
6#[allow(unused_imports)] 6#[allow(unused_imports)]
7use crate::gpio::sealed::{AFType, Pin}; 7use crate::gpio::sealed::{AFType, Pin};
8use crate::time::Hertz; 8use crate::time::Hertz;
9use crate::Unborrow;
9 10
10pub struct SimplePwm<'d, T> { 11pub struct SimplePwm<'d, T> {
11 phantom: PhantomData<&'d mut T>, 12 phantom: PhantomData<&'d mut T>,
@@ -74,11 +75,7 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
74 }) 75 })
75 } 76 }
76 77
77 fn new_inner<F: Into<Hertz>>( 78 fn new_inner<F: Into<Hertz>>(tim: impl Unborrow<Target = T> + 'd, freq: F, configure_pins: impl FnOnce()) -> Self {
78 tim: impl Unborrow<Target = T> + 'd,
79 freq: F,
80 configure_pins: impl FnOnce(),
81 ) -> Self {
82 unborrow!(tim); 79 unborrow!(tim);
83 80
84 T::enable(); 81 T::enable();
diff --git a/embassy-stm32/src/rcc/f0.rs b/embassy-stm32/src/rcc/f0.rs
index 427c958f0..10b075da4 100644
--- a/embassy-stm32/src/rcc/f0.rs
+++ b/embassy-stm32/src/rcc/f0.rs
@@ -1,9 +1,8 @@
1use super::{set_freqs, Clocks};
1use crate::pac::rcc::vals::{Hpre, Pllmul, Pllsrc, Ppre, Sw, Usbsw}; 2use crate::pac::rcc::vals::{Hpre, Pllmul, Pllsrc, Ppre, Sw, Usbsw};
2use crate::pac::{FLASH, RCC}; 3use crate::pac::{FLASH, RCC};
3use crate::time::Hertz; 4use crate::time::Hertz;
4 5
5use super::{set_freqs, Clocks};
6
7const HSI: u32 = 8_000_000; 6const HSI: u32 = 8_000_000;
8 7
9/// Configuration of the clocks 8/// Configuration of the clocks
@@ -112,8 +111,7 @@ pub(crate) unsafe fn init(config: Config) {
112 while !RCC.cr2().read().hsi48rdy() {} 111 while !RCC.cr2().read().hsi48rdy() {}
113 112
114 if pllmul_bits.is_some() { 113 if pllmul_bits.is_some() {
115 RCC.cfgr() 114 RCC.cfgr().modify(|w| w.set_pllsrc(Pllsrc::HSI48_DIV_PREDIV))
116 .modify(|w| w.set_pllsrc(Pllsrc::HSI48_DIV_PREDIV))
117 } 115 }
118 } 116 }
119 _ => { 117 _ => {
diff --git a/embassy-stm32/src/rcc/f2.rs b/embassy-stm32/src/rcc/f2.rs
index 7e5992bba..65fa78f82 100644
--- a/embassy-stm32/src/rcc/f2.rs
+++ b/embassy-stm32/src/rcc/f2.rs
@@ -436,9 +436,7 @@ pub(crate) unsafe fn init(config: Config) {
436 let pll_clocks = config.pll.clocks(pll_src_freq); 436 let pll_clocks = config.pll.clocks(pll_src_freq);
437 assert!(Hertz(950_000) <= pll_clocks.in_freq && pll_clocks.in_freq <= Hertz(2_100_000)); 437 assert!(Hertz(950_000) <= pll_clocks.in_freq && pll_clocks.in_freq <= Hertz(2_100_000));
438 assert!(Hertz(192_000_000) <= pll_clocks.vco_freq && pll_clocks.vco_freq <= Hertz(432_000_000)); 438 assert!(Hertz(192_000_000) <= pll_clocks.vco_freq && pll_clocks.vco_freq <= Hertz(432_000_000));
439 assert!( 439 assert!(Hertz(24_000_000) <= pll_clocks.main_freq && pll_clocks.main_freq <= Hertz(120_000_000));
440 Hertz(24_000_000) <= pll_clocks.main_freq && pll_clocks.main_freq <= Hertz(120_000_000)
441 );
442 // USB actually requires == 48 MHz, but other PLL48 peripherals are fine with <= 48MHz 440 // USB actually requires == 48 MHz, but other PLL48 peripherals are fine with <= 48MHz
443 assert!(pll_clocks.pll48_freq <= Hertz(48_000_000)); 441 assert!(pll_clocks.pll48_freq <= Hertz(48_000_000));
444 442
diff --git a/embassy-stm32/src/rcc/f4.rs b/embassy-stm32/src/rcc/f4.rs
index 22a2e9ad0..21f3ad15d 100644
--- a/embassy-stm32/src/rcc/f4.rs
+++ b/embassy-stm32/src/rcc/f4.rs
@@ -20,18 +20,12 @@ pub struct Config {
20 pub pll48: bool, 20 pub pll48: bool,
21} 21}
22 22
23unsafe fn setup_pll( 23unsafe fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option<u32>, pll48clk: bool) -> PllResults {
24 pllsrcclk: u32,
25 use_hse: bool,
26 pllsysclk: Option<u32>,
27 pll48clk: bool,
28) -> PllResults {
29 use crate::pac::rcc::vals::{Pllp, Pllsrc}; 24 use crate::pac::rcc::vals::{Pllp, Pllsrc};
30 25
31 let sysclk = pllsysclk.unwrap_or(pllsrcclk); 26 let sysclk = pllsysclk.unwrap_or(pllsrcclk);
32 if pllsysclk.is_none() && !pll48clk { 27 if pllsysclk.is_none() && !pll48clk {
33 RCC.pllcfgr() 28 RCC.pllcfgr().modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8)));
34 .modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8)));
35 29
36 return PllResults { 30 return PllResults {
37 use_pll: false, 31 use_pll: false,
@@ -47,11 +41,7 @@ unsafe fn setup_pll(
47 // Sysclk output divisor must be one of 2, 4, 6 or 8 41 // Sysclk output divisor must be one of 2, 4, 6 or 8
48 let sysclk_div = core::cmp::min(8, (432_000_000 / sysclk) & !1); 42 let sysclk_div = core::cmp::min(8, (432_000_000 / sysclk) & !1);
49 43
50 let target_freq = if pll48clk { 44 let target_freq = if pll48clk { 48_000_000 } else { sysclk * sysclk_div };
51 48_000_000
52 } else {
53 sysclk * sysclk_div
54 };
55 45
56 // Find the lowest pllm value that minimize the difference between 46 // Find the lowest pllm value that minimize the difference between
57 // target frequency and the real vco_out frequency. 47 // target frequency and the real vco_out frequency.
@@ -135,11 +125,7 @@ pub(crate) unsafe fn init(config: Config) {
135 assert!((max::PLL_48_CLK as i32 - freq as i32).abs() <= max::PLL_48_TOLERANCE as i32); 125 assert!((max::PLL_48_CLK as i32 - freq as i32).abs() <= max::PLL_48_TOLERANCE as i32);
136 } 126 }
137 127
138 let sysclk = if sysclk_on_pll { 128 let sysclk = if sysclk_on_pll { unwrap!(plls.pllsysclk) } else { sysclk };
139 unwrap!(plls.pllsysclk)
140 } else {
141 sysclk
142 };
143 129
144 // AHB prescaler 130 // AHB prescaler
145 let hclk = config.hclk.map(|h| h.0).unwrap_or(sysclk); 131 let hclk = config.hclk.map(|h| h.0).unwrap_or(sysclk);
@@ -269,9 +255,7 @@ mod max {
269 pub(crate) const SYSCLK_MAX: u32 = 168_000_000; 255 pub(crate) const SYSCLK_MAX: u32 = 168_000_000;
270 #[cfg(any(stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,))] 256 #[cfg(any(stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,))]
271 pub(crate) const SYSCLK_MAX: u32 = 100_000_000; 257 pub(crate) const SYSCLK_MAX: u32 = 100_000_000;
272 #[cfg(any( 258 #[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479,))]
273 stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479,
274 ))]
275 pub(crate) const SYSCLK_MAX: u32 = 180_000_000; 259 pub(crate) const SYSCLK_MAX: u32 = 180_000_000;
276 260
277 pub(crate) const HCLK_OVERDRIVE_FREQUENCY: u32 = 168_000_000; 261 pub(crate) const HCLK_OVERDRIVE_FREQUENCY: u32 = 168_000_000;
diff --git a/embassy-stm32/src/rcc/f7.rs b/embassy-stm32/src/rcc/f7.rs
index f45a725ce..d98aa4018 100644
--- a/embassy-stm32/src/rcc/f7.rs
+++ b/embassy-stm32/src/rcc/f7.rs
@@ -21,18 +21,12 @@ pub struct Config {
21 pub pll48: bool, 21 pub pll48: bool,
22} 22}
23 23
24unsafe fn setup_pll( 24unsafe fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option<u32>, pll48clk: bool) -> PllResults {
25 pllsrcclk: u32,
26 use_hse: bool,
27 pllsysclk: Option<u32>,
28 pll48clk: bool,
29) -> PllResults {
30 use crate::pac::rcc::vals::{Pllp, Pllsrc}; 25 use crate::pac::rcc::vals::{Pllp, Pllsrc};
31 26
32 let sysclk = pllsysclk.unwrap_or(pllsrcclk); 27 let sysclk = pllsysclk.unwrap_or(pllsrcclk);
33 if pllsysclk.is_none() && !pll48clk { 28 if pllsysclk.is_none() && !pll48clk {
34 RCC.pllcfgr() 29 RCC.pllcfgr().modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8)));
35 .modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8)));
36 30
37 return PllResults { 31 return PllResults {
38 use_pll: false, 32 use_pll: false,
@@ -48,11 +42,7 @@ unsafe fn setup_pll(
48 // Sysclk output divisor must be one of 2, 4, 6 or 8 42 // Sysclk output divisor must be one of 2, 4, 6 or 8
49 let sysclk_div = core::cmp::min(8, (432_000_000 / sysclk) & !1); 43 let sysclk_div = core::cmp::min(8, (432_000_000 / sysclk) & !1);
50 44
51 let target_freq = if pll48clk { 45 let target_freq = if pll48clk { 48_000_000 } else { sysclk * sysclk_div };
52 48_000_000
53 } else {
54 sysclk * sysclk_div
55 };
56 46
57 // Find the lowest pllm value that minimize the difference between 47 // Find the lowest pllm value that minimize the difference between
58 // target frequency and the real vco_out frequency. 48 // target frequency and the real vco_out frequency.
@@ -146,11 +136,7 @@ pub(crate) unsafe fn init(config: Config) {
146 assert!((max::PLL_48_CLK as i32 - freq as i32).abs() <= max::PLL_48_TOLERANCE as i32); 136 assert!((max::PLL_48_CLK as i32 - freq as i32).abs() <= max::PLL_48_TOLERANCE as i32);
147 } 137 }
148 138
149 let sysclk = if sysclk_on_pll { 139 let sysclk = if sysclk_on_pll { unwrap!(plls.pllsysclk) } else { sysclk };
150 unwrap!(plls.pllsysclk)
151 } else {
152 sysclk
153 };
154 140
155 // AHB prescaler 141 // AHB prescaler
156 let hclk = config.hclk.map(|h| h.0).unwrap_or(sysclk); 142 let hclk = config.hclk.map(|h| h.0).unwrap_or(sysclk);
diff --git a/embassy-stm32/src/rcc/g0.rs b/embassy-stm32/src/rcc/g0.rs
index be0497290..36b49c711 100644
--- a/embassy-stm32/src/rcc/g0.rs
+++ b/embassy-stm32/src/rcc/g0.rs
@@ -2,8 +2,7 @@ use crate::pac::flash::vals::Latency;
2use crate::pac::rcc::vals::{self, Hpre, Hsidiv, Ppre, Sw}; 2use crate::pac::rcc::vals::{self, Hpre, Hsidiv, Ppre, Sw};
3use crate::pac::{FLASH, PWR, RCC}; 3use crate::pac::{FLASH, PWR, RCC};
4use crate::rcc::{set_freqs, Clocks}; 4use crate::rcc::{set_freqs, Clocks};
5use crate::time::Hertz; 5use crate::time::{Hertz, U32Ext};
6use crate::time::U32Ext;
7 6
8/// HSI speed 7/// HSI speed
9pub const HSI_FREQ: u32 = 16_000_000; 8pub const HSI_FREQ: u32 = 16_000_000;
diff --git a/embassy-stm32/src/rcc/g4.rs b/embassy-stm32/src/rcc/g4.rs
index ce8cca45d..2b8c2b576 100644
--- a/embassy-stm32/src/rcc/g4.rs
+++ b/embassy-stm32/src/rcc/g4.rs
@@ -1,7 +1,6 @@
1use crate::pac::{PWR, RCC}; 1use crate::pac::{PWR, RCC};
2use crate::rcc::{set_freqs, Clocks}; 2use crate::rcc::{set_freqs, Clocks};
3use crate::time::Hertz; 3use crate::time::{Hertz, U32Ext};
4use crate::time::U32Ext;
5 4
6/// HSI speed 5/// HSI speed
7pub const HSI_FREQ: u32 = 16_000_000; 6pub const HSI_FREQ: u32 = 16_000_000;
diff --git a/embassy-stm32/src/rcc/h7.rs b/embassy-stm32/src/rcc/h7.rs
index 0cd89645f..4fa01ade4 100644
--- a/embassy-stm32/src/rcc/h7.rs
+++ b/embassy-stm32/src/rcc/h7.rs
@@ -1,19 +1,16 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use crate::Unborrow;
4use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
4pub use pll::PllConfig;
5use stm32_metapac::rcc::vals::{Mco1, Mco2}; 5use stm32_metapac::rcc::vals::{Mco1, Mco2};
6 6
7use crate::gpio::sealed::AFType; 7use crate::gpio::sealed::AFType;
8use crate::gpio::Speed; 8use crate::gpio::Speed;
9use crate::pac::rcc::vals::Timpre; 9use crate::pac::rcc::vals::{Adcsel, Ckpersel, Dppre, Hpre, Hsidiv, Pllsrc, Sw, Timpre};
10use crate::pac::rcc::vals::{Adcsel, Ckpersel, Dppre, Hpre, Hsidiv, Pllsrc, Sw};
11use crate::pac::{PWR, RCC, SYSCFG}; 10use crate::pac::{PWR, RCC, SYSCFG};
12use crate::peripherals;
13use crate::rcc::{set_freqs, Clocks}; 11use crate::rcc::{set_freqs, Clocks};
14use crate::time::Hertz; 12use crate::time::Hertz;
15 13use crate::{peripherals, Unborrow};
16pub use pll::PllConfig;
17 14
18const HSI: Hertz = Hertz(64_000_000); 15const HSI: Hertz = Hertz(64_000_000);
19const CSI: Hertz = Hertz(4_000_000); 16const CSI: Hertz = Hertz(4_000_000);
@@ -181,8 +178,10 @@ fn sys_ck_setup(config: &mut Config, srcclk: Hertz) -> (Hertz, bool) {
181 // Therefore we must use pll1_p_ck 178 // Therefore we must use pll1_p_ck
182 let pll1_p_ck = match config.pll1.p_ck { 179 let pll1_p_ck = match config.pll1.p_ck {
183 Some(p_ck) => { 180 Some(p_ck) => {
184 assert!(p_ck == sys_ck, 181 assert!(
185 "Error: Cannot set pll1_p_ck independently as it must be used to generate sys_ck"); 182 p_ck == sys_ck,
183 "Error: Cannot set pll1_p_ck independently as it must be used to generate sys_ck"
184 );
186 Some(p_ck) 185 Some(p_ck)
187 } 186 }
188 None => Some(sys_ck), 187 None => Some(sys_ck),
@@ -392,9 +391,7 @@ impl<'d, T: McoInstance> Mco<'d, T> {
392 pin.set_speed(Speed::VeryHigh); 391 pin.set_speed(Speed::VeryHigh);
393 }); 392 });
394 393
395 Self { 394 Self { phantom: PhantomData }
396 phantom: PhantomData,
397 }
398 } 395 }
399} 396}
400 397
@@ -538,33 +535,19 @@ pub(crate) unsafe fn init(mut config: Config) {
538 // Timer prescaler selection 535 // Timer prescaler selection
539 let timpre = Timpre::DEFAULTX2; 536 let timpre = Timpre::DEFAULTX2;
540 537
541 let requested_pclk1 = config 538 let requested_pclk1 = config.pclk1.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2));
542 .pclk1
543 .map(|v| v.0)
544 .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2));
545 let (rcc_pclk1, ppre1_bits, ppre1, rcc_timerx_ker_ck) = 539 let (rcc_pclk1, ppre1_bits, ppre1, rcc_timerx_ker_ck) =
546 ppre_calculate(requested_pclk1, rcc_hclk, pclk_max, Some(timpre)); 540 ppre_calculate(requested_pclk1, rcc_hclk, pclk_max, Some(timpre));
547 541
548 let requested_pclk2 = config 542 let requested_pclk2 = config.pclk2.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2));
549 .pclk2
550 .map(|v| v.0)
551 .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2));
552 let (rcc_pclk2, ppre2_bits, ppre2, rcc_timery_ker_ck) = 543 let (rcc_pclk2, ppre2_bits, ppre2, rcc_timery_ker_ck) =
553 ppre_calculate(requested_pclk2, rcc_hclk, pclk_max, Some(timpre)); 544 ppre_calculate(requested_pclk2, rcc_hclk, pclk_max, Some(timpre));
554 545
555 let requested_pclk3 = config 546 let requested_pclk3 = config.pclk3.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2));
556 .pclk3 547 let (rcc_pclk3, ppre3_bits, ppre3, _) = ppre_calculate(requested_pclk3, rcc_hclk, pclk_max, None);
557 .map(|v| v.0)
558 .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2));
559 let (rcc_pclk3, ppre3_bits, ppre3, _) =
560 ppre_calculate(requested_pclk3, rcc_hclk, pclk_max, None);
561 548
562 let requested_pclk4 = config 549 let requested_pclk4 = config.pclk4.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2));
563 .pclk4 550 let (rcc_pclk4, ppre4_bits, ppre4, _) = ppre_calculate(requested_pclk4, rcc_hclk, pclk_max, None);
564 .map(|v| v.0)
565 .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2));
566 let (rcc_pclk4, ppre4_bits, ppre4, _) =
567 ppre_calculate(requested_pclk4, rcc_hclk, pclk_max, None);
568 551
569 flash_setup(rcc_aclk, pwr_vos); 552 flash_setup(rcc_aclk, pwr_vos);
570 553
@@ -593,11 +576,7 @@ pub(crate) unsafe fn init(mut config: Config) {
593 None => None, 576 None => None,
594 }; 577 };
595 578
596 let pllsrc = if config.hse.is_some() { 579 let pllsrc = if config.hse.is_some() { Pllsrc::HSE } else { Pllsrc::HSI };
597 Pllsrc::HSE
598 } else {
599 Pllsrc::HSI
600 };
601 RCC.pllckselr().modify(|w| w.set_pllsrc(pllsrc)); 580 RCC.pllckselr().modify(|w| w.set_pllsrc(pllsrc));
602 581
603 let enable_pll = |pll| { 582 let enable_pll = |pll| {
@@ -640,8 +619,7 @@ pub(crate) unsafe fn init(mut config: Config) {
640 RCC.d1ccipr().modify(|w| w.set_ckpersel(ckpersel)); 619 RCC.d1ccipr().modify(|w| w.set_ckpersel(ckpersel));
641 620
642 // ADC clock MUX 621 // ADC clock MUX
643 RCC.d3ccipr() 622 RCC.d3ccipr().modify(|w| w.set_adcsel(config.adc_clock_source.adcsel()));
644 .modify(|w| w.set_adcsel(config.adc_clock_source.adcsel()));
645 623
646 let adc_ker_ck = match config.adc_clock_source { 624 let adc_ker_ck = match config.adc_clock_source {
647 AdcClockSource::Pll2PCk => pll2_p_ck.map(Hertz), 625 AdcClockSource::Pll2PCk => pll2_p_ck.map(Hertz),
@@ -823,15 +801,13 @@ mod pll {
823 let pll_x_n = vco_ck_target / ref_x_ck; 801 let pll_x_n = vco_ck_target / ref_x_ck;
824 assert!(pll_x_n >= 4); 802 assert!(pll_x_n >= 4);
825 assert!(pll_x_n <= 512); 803 assert!(pll_x_n <= 512);
826 RCC.plldivr(plln) 804 RCC.plldivr(plln).modify(|w| w.set_divn1((pll_x_n - 1) as u16));
827 .modify(|w| w.set_divn1((pll_x_n - 1) as u16));
828 805
829 // No FRACN 806 // No FRACN
830 RCC.pllcfgr().modify(|w| w.set_pllfracen(plln, false)); 807 RCC.pllcfgr().modify(|w| w.set_pllfracen(plln, false));
831 let vco_ck = ref_x_ck * pll_x_n; 808 let vco_ck = ref_x_ck * pll_x_n;
832 809
833 RCC.plldivr(plln) 810 RCC.plldivr(plln).modify(|w| w.set_divp1(Divp((pll_x_p - 1) as u8)));
834 .modify(|w| w.set_divp1(Divp((pll_x_p - 1) as u8)));
835 RCC.pllcfgr().modify(|w| w.set_divpen(plln, true)); 811 RCC.pllcfgr().modify(|w| w.set_divpen(plln, true));
836 812
837 // Calulate additional output dividers 813 // Calulate additional output dividers
diff --git a/embassy-stm32/src/rcc/l0.rs b/embassy-stm32/src/rcc/l0.rs
index 692791174..2e23833ca 100644
--- a/embassy-stm32/src/rcc/l0.rs
+++ b/embassy-stm32/src/rcc/l0.rs
@@ -3,8 +3,7 @@ use crate::pac::RCC;
3#[cfg(crs)] 3#[cfg(crs)]
4use crate::pac::{CRS, SYSCFG}; 4use crate::pac::{CRS, SYSCFG};
5use crate::rcc::{set_freqs, Clocks}; 5use crate::rcc::{set_freqs, Clocks};
6use crate::time::Hertz; 6use crate::time::{Hertz, U32Ext};
7use crate::time::U32Ext;
8 7
9/// HSI16 speed 8/// HSI16 speed
10pub const HSI16_FREQ: u32 = 16_000_000; 9pub const HSI16_FREQ: u32 = 16_000_000;
diff --git a/embassy-stm32/src/rcc/l1.rs b/embassy-stm32/src/rcc/l1.rs
index dfcbd4f21..80290632e 100644
--- a/embassy-stm32/src/rcc/l1.rs
+++ b/embassy-stm32/src/rcc/l1.rs
@@ -1,8 +1,7 @@
1use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw}; 1use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw};
2use crate::pac::{FLASH, RCC}; 2use crate::pac::{FLASH, RCC};
3use crate::rcc::{set_freqs, Clocks}; 3use crate::rcc::{set_freqs, Clocks};
4use crate::time::Hertz; 4use crate::time::{Hertz, U32Ext};
5use crate::time::U32Ext;
6 5
7/// HSI speed 6/// HSI speed
8pub const HSI_FREQ: u32 = 16_000_000; 7pub const HSI_FREQ: u32 = 16_000_000;
diff --git a/embassy-stm32/src/rcc/l4.rs b/embassy-stm32/src/rcc/l4.rs
index 3b84fb9b8..1905039b9 100644
--- a/embassy-stm32/src/rcc/l4.rs
+++ b/embassy-stm32/src/rcc/l4.rs
@@ -1,8 +1,7 @@
1use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; 1use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw};
2use crate::pac::{FLASH, RCC}; 2use crate::pac::{FLASH, RCC};
3use crate::rcc::{set_freqs, Clocks}; 3use crate::rcc::{set_freqs, Clocks};
4use crate::time::Hertz; 4use crate::time::{Hertz, U32Ext};
5use crate::time::U32Ext;
6 5
7/// HSI16 speed 6/// HSI16 speed
8pub const HSI16_FREQ: u32 = 16_000_000; 7pub const HSI16_FREQ: u32 = 16_000_000;
diff --git a/embassy-stm32/src/rcc/l5.rs b/embassy-stm32/src/rcc/l5.rs
index 4419f3d31..48d12a890 100644
--- a/embassy-stm32/src/rcc/l5.rs
+++ b/embassy-stm32/src/rcc/l5.rs
@@ -3,8 +3,7 @@ use stm32_metapac::PWR;
3use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; 3use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw};
4use crate::pac::{FLASH, RCC}; 4use crate::pac::{FLASH, RCC};
5use crate::rcc::{set_freqs, Clocks}; 5use crate::rcc::{set_freqs, Clocks};
6use crate::time::Hertz; 6use crate::time::{Hertz, U32Ext};
7use crate::time::U32Ext;
8 7
9/// HSI16 speed 8/// HSI16 speed
10pub const HSI16_FREQ: u32 = 16_000_000; 9pub const HSI16_FREQ: u32 = 16_000_000;
@@ -297,8 +296,7 @@ impl Default for Config {
297} 296}
298 297
299pub(crate) unsafe fn init(config: Config) { 298pub(crate) unsafe fn init(config: Config) {
300 PWR.cr1() 299 PWR.cr1().modify(|w| w.set_vos(stm32_metapac::pwr::vals::Vos::RANGE0));
301 .modify(|w| w.set_vos(stm32_metapac::pwr::vals::Vos::RANGE0));
302 let (sys_clk, sw) = match config.mux { 300 let (sys_clk, sw) = match config.mux {
303 ClockSrc::MSI(range) => { 301 ClockSrc::MSI(range) => {
304 // Enable MSI 302 // Enable MSI
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index 959e59265..866b1ffc4 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -1,8 +1,9 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::time::Hertz;
4use core::mem::MaybeUninit; 3use core::mem::MaybeUninit;
5 4
5use crate::time::Hertz;
6
6#[cfg_attr(rcc_f0, path = "f0.rs")] 7#[cfg_attr(rcc_f0, path = "f0.rs")]
7#[cfg_attr(any(rcc_f1, rcc_f1cl), path = "f1.rs")] 8#[cfg_attr(any(rcc_f1, rcc_f1cl), path = "f1.rs")]
8#[cfg_attr(rcc_f2, path = "f2.rs")] 9#[cfg_attr(rcc_f2, path = "f2.rs")]
@@ -41,13 +42,11 @@ pub struct Clocks {
41 // AHB 42 // AHB
42 pub ahb1: Hertz, 43 pub ahb1: Hertz,
43 #[cfg(any( 44 #[cfg(any(
44 rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_g4, rcc_u5, rcc_wb, 45 rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_g4, rcc_u5, rcc_wb, rcc_wl5, rcc_wle
45 rcc_wl5, rcc_wle
46 ))] 46 ))]
47 pub ahb2: Hertz, 47 pub ahb2: Hertz,
48 #[cfg(any( 48 #[cfg(any(
49 rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_u5, rcc_wb, 49 rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_u5, rcc_wb, rcc_wl5, rcc_wle
50 rcc_wl5, rcc_wle
51 ))] 50 ))]
52 pub ahb3: Hertz, 51 pub ahb3: Hertz,
53 #[cfg(any(rcc_h7, rcc_h7ab))] 52 #[cfg(any(rcc_h7, rcc_h7ab))]
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs
index ac1cd06c8..74d3a11eb 100644
--- a/embassy-stm32/src/rcc/u5.rs
+++ b/embassy-stm32/src/rcc/u5.rs
@@ -1,7 +1,8 @@
1use stm32_metapac::rcc::vals::{Hpre, Msirange, Msirgsel, Pllm, Pllsrc, Ppre, Sw};
2
1use crate::pac::{FLASH, RCC}; 3use crate::pac::{FLASH, RCC};
2use crate::rcc::{set_freqs, Clocks}; 4use crate::rcc::{set_freqs, Clocks};
3use crate::time::{Hertz, U32Ext}; 5use crate::time::{Hertz, U32Ext};
4use stm32_metapac::rcc::vals::{Hpre, Msirange, Msirgsel, Pllm, Pllsrc, Ppre, Sw};
5 6
6/// HSI16 speed 7/// HSI16 speed
7pub const HSI16_FREQ: u32 = 16_000_000; 8pub const HSI16_FREQ: u32 = 16_000_000;
diff --git a/embassy-stm32/src/rcc/wb.rs b/embassy-stm32/src/rcc/wb.rs
index eae7c9464..d950e28f8 100644
--- a/embassy-stm32/src/rcc/wb.rs
+++ b/embassy-stm32/src/rcc/wb.rs
@@ -1,7 +1,6 @@
1use crate::pac::RCC; 1use crate::pac::RCC;
2use crate::rcc::{set_freqs, Clocks}; 2use crate::rcc::{set_freqs, Clocks};
3use crate::time::Hertz; 3use crate::time::{Hertz, U32Ext};
4use crate::time::U32Ext;
5 4
6/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC, 5/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC,
7/// and with the addition of the init function to configure a system clock. 6/// and with the addition of the init function to configure a system clock.
diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs
index e74b66237..5b3558c92 100644
--- a/embassy-stm32/src/rng.rs
+++ b/embassy-stm32/src/rng.rs
@@ -1,15 +1,14 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::Unborrow;
4use core::marker::PhantomData; 3use core::marker::PhantomData;
5use core::task::Poll; 4use core::task::Poll;
5
6use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
7use embassy_hal_common::unborrow; 7use embassy_hal_common::unborrow;
8use futures::future::poll_fn; 8use futures::future::poll_fn;
9use rand_core::{CryptoRng, RngCore}; 9use rand_core::{CryptoRng, RngCore};
10 10
11use crate::pac; 11use crate::{pac, peripherals, Unborrow};
12use crate::peripherals;
13 12
14pub(crate) static RNG_WAKER: AtomicWaker = AtomicWaker::new(); 13pub(crate) static RNG_WAKER: AtomicWaker = AtomicWaker::new();
15 14
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs
index a7290e74c..1ebf91b3f 100644
--- a/embassy-stm32/src/sdmmc/mod.rs
+++ b/embassy-stm32/src/sdmmc/mod.rs
@@ -4,8 +4,6 @@ use core::default::Default;
4use core::marker::PhantomData; 4use core::marker::PhantomData;
5use core::task::Poll; 5use core::task::Poll;
6 6
7use crate::interrupt::InterruptExt;
8use crate::Unborrow;
9use embassy::waitqueue::AtomicWaker; 7use embassy::waitqueue::AtomicWaker;
10use embassy_hal_common::drop::OnDrop; 8use embassy_hal_common::drop::OnDrop;
11use embassy_hal_common::unborrow; 9use embassy_hal_common::unborrow;
@@ -15,11 +13,11 @@ use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID,
15use crate::dma::NoDma; 13use crate::dma::NoDma;
16use crate::gpio::sealed::AFType; 14use crate::gpio::sealed::AFType;
17use crate::gpio::{Pull, Speed}; 15use crate::gpio::{Pull, Speed};
18use crate::interrupt::Interrupt; 16use crate::interrupt::{Interrupt, InterruptExt};
19use crate::pac::sdmmc::Sdmmc as RegBlock; 17use crate::pac::sdmmc::Sdmmc as RegBlock;
20use crate::peripherals;
21use crate::rcc::RccPeripheral; 18use crate::rcc::RccPeripheral;
22use crate::time::Hertz; 19use crate::time::Hertz;
20use crate::{peripherals, Unborrow};
23 21
24/// The signalling scheme used on the SDMMC bus 22/// The signalling scheme used on the SDMMC bus
25#[non_exhaustive] 23#[non_exhaustive]
@@ -283,11 +281,7 @@ impl<'d, T: Instance, P: Pins<T>, Dma: SdmmcDma<T>> Sdmmc<'d, T, P, Dma> {
283 } 281 }
284 282
285 #[inline(always)] 283 #[inline(always)]
286 pub async fn read_block( 284 pub async fn read_block(&mut self, block_idx: u32, buffer: &mut DataBlock) -> Result<(), Error> {
287 &mut self,
288 block_idx: u32,
289 buffer: &mut DataBlock,
290 ) -> Result<(), Error> {
291 let card_capacity = self.card()?.card_type; 285 let card_capacity = self.card()?.card_type;
292 let inner = T::inner(); 286 let inner = T::inner();
293 let state = T::state(); 287 let state = T::state();
@@ -475,8 +469,7 @@ impl SdmmcInner {
475 469
476 self.select_card(Some(&card))?; 470 self.select_card(Some(&card))?;
477 471
478 self.get_scr(&mut card, waker_reg, data_transfer_timeout, dma) 472 self.get_scr(&mut card, waker_reg, data_transfer_timeout, dma).await?;
479 .await?;
480 473
481 // Set bus width 474 // Set bus width
482 let (width, acmd_arg) = match bus_width { 475 let (width, acmd_arg) = match bus_width {
@@ -515,12 +508,7 @@ impl SdmmcInner {
515 if freq.0 > 25_000_000 { 508 if freq.0 > 25_000_000 {
516 // Switch to SDR25 509 // Switch to SDR25
517 *signalling = self 510 *signalling = self
518 .switch_signalling_mode( 511 .switch_signalling_mode(Signalling::SDR25, waker_reg, data_transfer_timeout, dma)
519 Signalling::SDR25,
520 waker_reg,
521 data_transfer_timeout,
522 dma,
523 )
524 .await?; 512 .await?;
525 513
526 if *signalling == Signalling::SDR25 { 514 if *signalling == Signalling::SDR25 {
@@ -562,13 +550,7 @@ impl SdmmcInner {
562 let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); 550 let on_drop = OnDrop::new(|| unsafe { self.on_drop() });
563 551
564 unsafe { 552 unsafe {
565 self.prepare_datapath_read( 553 self.prepare_datapath_read(buffer as *mut [u32; 128], 512, 9, data_transfer_timeout, dma);
566 buffer as *mut [u32; 128],
567 512,
568 9,
569 data_transfer_timeout,
570 dma,
571 );
572 self.data_interrupts(true); 554 self.data_interrupts(true);
573 } 555 }
574 self.cmd(Cmd::read_single_block(address), true)?; 556 self.cmd(Cmd::read_single_block(address), true)?;
@@ -617,13 +599,7 @@ impl SdmmcInner {
617 let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); 599 let on_drop = OnDrop::new(|| unsafe { self.on_drop() });
618 600
619 unsafe { 601 unsafe {
620 self.prepare_datapath_write( 602 self.prepare_datapath_write(buffer as *const [u32; 128], 512, 9, data_transfer_timeout, dma);
621 buffer as *const [u32; 128],
622 512,
623 9,
624 data_transfer_timeout,
625 dma,
626 );
627 self.data_interrupts(true); 603 self.data_interrupts(true);
628 } 604 }
629 self.cmd(Cmd::write_single_block(address), true)?; 605 self.cmd(Cmd::write_single_block(address), true)?;
@@ -654,10 +630,7 @@ impl SdmmcInner {
654 630
655 // Try to read card status (ACMD13) 631 // Try to read card status (ACMD13)
656 while timeout > 0 { 632 while timeout > 0 {
657 match self 633 match self.read_sd_status(card, waker_reg, data_transfer_timeout, dma).await {
658 .read_sd_status(card, waker_reg, data_transfer_timeout, dma)
659 .await
660 {
661 Ok(_) => return Ok(()), 634 Ok(_) => return Ok(()),
662 Err(Error::Timeout) => (), // Try again 635 Err(Error::Timeout) => (), // Try again
663 Err(e) => return Err(e), 636 Err(e) => return Err(e),
@@ -732,8 +705,7 @@ impl SdmmcInner {
732 705
733 // NOTE(unsafe) We have exclusive access to the regisers 706 // NOTE(unsafe) We have exclusive access to the regisers
734 707
735 regs.dtimer() 708 regs.dtimer().write(|w| w.set_datatime(data_transfer_timeout));
736 .write(|w| w.set_datatime(data_transfer_timeout));
737 regs.dlenr().write(|w| w.set_datalength(length_bytes)); 709 regs.dlenr().write(|w| w.set_datalength(length_bytes));
738 710
739 cfg_if::cfg_if! { 711 cfg_if::cfg_if! {
@@ -781,8 +753,7 @@ impl SdmmcInner {
781 753
782 // NOTE(unsafe) We have exclusive access to the regisers 754 // NOTE(unsafe) We have exclusive access to the regisers
783 755
784 regs.dtimer() 756 regs.dtimer().write(|w| w.set_datatime(data_transfer_timeout));
785 .write(|w| w.set_datatime(data_transfer_timeout));
786 regs.dlenr().write(|w| w.set_datalength(length_bytes)); 757 regs.dlenr().write(|w| w.set_datalength(length_bytes));
787 758
788 cfg_if::cfg_if! { 759 cfg_if::cfg_if! {
@@ -824,13 +795,7 @@ impl SdmmcInner {
824 } 795 }
825 796
826 /// Sets the CLKDIV field in CLKCR. Updates clock field in self 797 /// Sets the CLKDIV field in CLKCR. Updates clock field in self
827 fn clkcr_set_clkdiv( 798 fn clkcr_set_clkdiv(&self, freq: u32, width: BusWidth, ker_ck: Hertz, clock: &mut Hertz) -> Result<(), Error> {
828 &self,
829 freq: u32,
830 width: BusWidth,
831 ker_ck: Hertz,
832 clock: &mut Hertz,
833 ) -> Result<(), Error> {
834 let regs = self.0; 799 let regs = self.0;
835 800
836 let (clkdiv, new_clock) = clk_div(ker_ck, freq)?; 801 let (clkdiv, new_clock) = clk_div(ker_ck, freq)?;
@@ -882,13 +847,7 @@ impl SdmmcInner {
882 let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); 847 let on_drop = OnDrop::new(|| unsafe { self.on_drop() });
883 848
884 unsafe { 849 unsafe {
885 self.prepare_datapath_read( 850 self.prepare_datapath_read(&mut status as *mut [u32; 16], 64, 6, data_transfer_timeout, dma);
886 &mut status as *mut [u32; 16],
887 64,
888 6,
889 data_transfer_timeout,
890 dma,
891 );
892 self.data_interrupts(true); 851 self.data_interrupts(true);
893 } 852 }
894 self.cmd(Cmd::cmd6(set_function), true)?; // CMD6 853 self.cmd(Cmd::cmd6(set_function), true)?; // CMD6
@@ -970,13 +929,7 @@ impl SdmmcInner {
970 let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); 929 let on_drop = OnDrop::new(|| unsafe { self.on_drop() });
971 930
972 unsafe { 931 unsafe {
973 self.prepare_datapath_read( 932 self.prepare_datapath_read(&mut status as *mut [u32; 16], 64, 6, data_transfer_timeout, dma);
974 &mut status as *mut [u32; 16],
975 64,
976 6,
977 data_transfer_timeout,
978 dma,
979 );
980 self.data_interrupts(true); 933 self.data_interrupts(true);
981 } 934 }
982 self.cmd(Cmd::card_status(0), true)?; 935 self.cmd(Cmd::card_status(0), true)?;
@@ -1473,10 +1426,12 @@ foreach_peripheral!(
1473 1426
1474#[cfg(feature = "sdmmc-rs")] 1427#[cfg(feature = "sdmmc-rs")]
1475mod sdmmc_rs { 1428mod sdmmc_rs {
1476 use super::*;
1477 use core::future::Future; 1429 use core::future::Future;
1430
1478 use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx}; 1431 use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx};
1479 1432
1433 use super::*;
1434
1480 impl<'d, T: Instance, P: Pins<T>> BlockDevice for Sdmmc<'d, T, P> { 1435 impl<'d, T: Instance, P: Pins<T>> BlockDevice for Sdmmc<'d, T, P> {
1481 type Error = Error; 1436 type Error = Error;
1482 type ReadFuture<'a> 1437 type ReadFuture<'a>
@@ -1506,13 +1461,7 @@ mod sdmmc_rs {
1506 // NOTE(unsafe) Block uses align(4) 1461 // NOTE(unsafe) Block uses align(4)
1507 let buf = unsafe { &mut *(block as *mut [u8; 512] as *mut [u32; 128]) }; 1462 let buf = unsafe { &mut *(block as *mut [u8; 512] as *mut [u32; 128]) };
1508 inner 1463 inner
1509 .read_block( 1464 .read_block(address, buf, card_capacity, state, self.config.data_transfer_timeout)
1510 address,
1511 buf,
1512 card_capacity,
1513 state,
1514 self.config.data_transfer_timeout,
1515 )
1516 .await?; 1465 .await?;
1517 address += 1; 1466 address += 1;
1518 } 1467 }
@@ -1520,11 +1469,7 @@ mod sdmmc_rs {
1520 } 1469 }
1521 } 1470 }
1522 1471
1523 fn write<'a>( 1472 fn write<'a>(&'a mut self, blocks: &'a [Block], start_block_idx: BlockIdx) -> Self::WriteFuture<'a> {
1524 &'a mut self,
1525 blocks: &'a [Block],
1526 start_block_idx: BlockIdx,
1527 ) -> Self::WriteFuture<'a> {
1528 async move { 1473 async move {
1529 let card = self.card.as_mut().ok_or(Error::NoCard)?; 1474 let card = self.card.as_mut().ok_or(Error::NoCard)?;
1530 let inner = T::inner(); 1475 let inner = T::inner();
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs
index 3cdc87c70..7c142e507 100644
--- a/embassy-stm32/src/spi/mod.rs
+++ b/embassy-stm32/src/spi/mod.rs
@@ -1,22 +1,20 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::Unborrow;
4use core::marker::PhantomData; 3use core::marker::PhantomData;
5use core::ptr; 4use core::ptr;
5
6use embassy_hal_common::unborrow; 6use embassy_hal_common::unborrow;
7pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
7use futures::future::join; 8use futures::future::join;
8 9
9use self::sealed::WordSize; 10use self::sealed::WordSize;
10use crate::dma::{slice_ptr_parts, NoDma, Transfer}; 11use crate::dma::{slice_ptr_parts, NoDma, Transfer};
11use crate::gpio::sealed::{AFType, Pin as _}; 12use crate::gpio::sealed::{AFType, Pin as _};
12use crate::gpio::AnyPin; 13use crate::gpio::AnyPin;
13use crate::pac::spi::Spi as Regs; 14use crate::pac::spi::{regs, vals, Spi as Regs};
14use crate::pac::spi::{regs, vals};
15use crate::peripherals;
16use crate::rcc::RccPeripheral; 15use crate::rcc::RccPeripheral;
17use crate::time::Hertz; 16use crate::time::Hertz;
18 17use crate::{peripherals, Unborrow};
19pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
20 18
21#[derive(Debug)] 19#[derive(Debug)]
22#[cfg_attr(feature = "defmt", derive(defmt::Format))] 20#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -423,10 +421,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
423 421
424 let tx_request = self.txdma.request(); 422 let tx_request = self.txdma.request();
425 let tx_dst = T::REGS.tx_ptr(); 423 let tx_dst = T::REGS.tx_ptr();
426 unsafe { 424 unsafe { self.txdma.start_write(tx_request, data, tx_dst, Default::default()) }
427 self.txdma
428 .start_write(tx_request, data, tx_dst, Default::default())
429 }
430 let tx_f = Transfer::new(&mut self.txdma); 425 let tx_f = Transfer::new(&mut self.txdma);
431 426
432 unsafe { 427 unsafe {
@@ -472,22 +467,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
472 467
473 let rx_request = self.rxdma.request(); 468 let rx_request = self.rxdma.request();
474 let rx_src = T::REGS.rx_ptr(); 469 let rx_src = T::REGS.rx_ptr();
475 unsafe { 470 unsafe { self.rxdma.start_read(rx_request, rx_src, data, Default::default()) };
476 self.rxdma
477 .start_read(rx_request, rx_src, data, Default::default())
478 };
479 let rx_f = Transfer::new(&mut self.rxdma); 471 let rx_f = Transfer::new(&mut self.rxdma);
480 472
481 let tx_request = self.txdma.request(); 473 let tx_request = self.txdma.request();
482 let tx_dst = T::REGS.tx_ptr(); 474 let tx_dst = T::REGS.tx_ptr();
483 let clock_byte = 0x00u8; 475 let clock_byte = 0x00u8;
484 let tx_f = crate::dma::write_repeated( 476 let tx_f = crate::dma::write_repeated(&mut self.txdma, tx_request, clock_byte, clock_byte_count, tx_dst);
485 &mut self.txdma,
486 tx_request,
487 clock_byte,
488 clock_byte_count,
489 tx_dst,
490 );
491 477
492 unsafe { 478 unsafe {
493 set_txdmaen(T::REGS, true); 479 set_txdmaen(T::REGS, true);
@@ -507,11 +493,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
507 Ok(()) 493 Ok(())
508 } 494 }
509 495
510 async fn transfer_inner<W: Word>( 496 async fn transfer_inner<W: Word>(&mut self, read: *mut [W], write: *const [W]) -> Result<(), Error>
511 &mut self,
512 read: *mut [W],
513 write: *const [W],
514 ) -> Result<(), Error>
515 where 497 where
516 Tx: TxDma<T>, 498 Tx: TxDma<T>,
517 Rx: RxDma<T>, 499 Rx: RxDma<T>,
@@ -537,18 +519,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
537 519
538 let rx_request = self.rxdma.request(); 520 let rx_request = self.rxdma.request();
539 let rx_src = T::REGS.rx_ptr(); 521 let rx_src = T::REGS.rx_ptr();
540 unsafe { 522 unsafe { self.rxdma.start_read(rx_request, rx_src, read, Default::default()) };
541 self.rxdma
542 .start_read(rx_request, rx_src, read, Default::default())
543 };
544 let rx_f = Transfer::new(&mut self.rxdma); 523 let rx_f = Transfer::new(&mut self.rxdma);
545 524
546 let tx_request = self.txdma.request(); 525 let tx_request = self.txdma.request();
547 let tx_dst = T::REGS.tx_ptr(); 526 let tx_dst = T::REGS.tx_ptr();
548 unsafe { 527 unsafe { self.txdma.start_write(tx_request, write, tx_dst, Default::default()) }
549 self.txdma
550 .start_write(tx_request, write, tx_dst, Default::default())
551 }
552 let tx_f = Transfer::new(&mut self.txdma); 528 let tx_f = Transfer::new(&mut self.txdma);
553 529
554 unsafe { 530 unsafe {
@@ -835,9 +811,7 @@ mod eh02 {
835 // some marker traits. For details, see https://github.com/rust-embedded/embedded-hal/pull/289 811 // some marker traits. For details, see https://github.com/rust-embedded/embedded-hal/pull/289
836 macro_rules! impl_blocking { 812 macro_rules! impl_blocking {
837 ($w:ident) => { 813 ($w:ident) => {
838 impl<'d, T: Instance> embedded_hal_02::blocking::spi::Write<$w> 814 impl<'d, T: Instance> embedded_hal_02::blocking::spi::Write<$w> for Spi<'d, T, NoDma, NoDma> {
839 for Spi<'d, T, NoDma, NoDma>
840 {
841 type Error = Error; 815 type Error = Error;
842 816
843 fn write(&mut self, words: &[$w]) -> Result<(), Self::Error> { 817 fn write(&mut self, words: &[$w]) -> Result<(), Self::Error> {
@@ -845,9 +819,7 @@ mod eh02 {
845 } 819 }
846 } 820 }
847 821
848 impl<'d, T: Instance> embedded_hal_02::blocking::spi::Transfer<$w> 822 impl<'d, T: Instance> embedded_hal_02::blocking::spi::Transfer<$w> for Spi<'d, T, NoDma, NoDma> {
849 for Spi<'d, T, NoDma, NoDma>
850 {
851 type Error = Error; 823 type Error = Error;
852 824
853 fn transfer<'w>(&mut self, words: &'w mut [$w]) -> Result<&'w [$w], Self::Error> { 825 fn transfer<'w>(&mut self, words: &'w mut [$w]) -> Result<&'w [$w], Self::Error> {
@@ -876,25 +848,19 @@ mod eh1 {
876 } 848 }
877 } 849 }
878 850
879 impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusRead<W> 851 impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusRead<W> for Spi<'d, T, NoDma, NoDma> {
880 for Spi<'d, T, NoDma, NoDma>
881 {
882 fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> { 852 fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> {
883 self.blocking_read(words) 853 self.blocking_read(words)
884 } 854 }
885 } 855 }
886 856
887 impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusWrite<W> 857 impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusWrite<W> for Spi<'d, T, NoDma, NoDma> {
888 for Spi<'d, T, NoDma, NoDma>
889 {
890 fn write(&mut self, words: &[W]) -> Result<(), Self::Error> { 858 fn write(&mut self, words: &[W]) -> Result<(), Self::Error> {
891 self.blocking_write(words) 859 self.blocking_write(words)
892 } 860 }
893 } 861 }
894 862
895 impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBus<W> 863 impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBus<W> for Spi<'d, T, NoDma, NoDma> {
896 for Spi<'d, T, NoDma, NoDma>
897 {
898 fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> { 864 fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> {
899 self.blocking_transfer(read, write) 865 self.blocking_transfer(read, write)
900 } 866 }
diff --git a/embassy-stm32/src/subghz/mod.rs b/embassy-stm32/src/subghz/mod.rs
index 6736324ce..3b64932fa 100644
--- a/embassy-stm32/src/subghz/mod.rs
+++ b/embassy-stm32/src/subghz/mod.rs
@@ -43,19 +43,20 @@ mod value_error;
43pub use bit_sync::BitSync; 43pub use bit_sync::BitSync;
44pub use cad_params::{CadParams, ExitMode, NbCadSymbol}; 44pub use cad_params::{CadParams, ExitMode, NbCadSymbol};
45pub use calibrate::{Calibrate, CalibrateImage}; 45pub use calibrate::{Calibrate, CalibrateImage};
46use embassy_hal_common::ratio::Ratio;
46pub use fallback_mode::FallbackMode; 47pub use fallback_mode::FallbackMode;
47pub use hse_trim::HseTrim; 48pub use hse_trim::HseTrim;
48pub use irq::{CfgIrq, Irq, IrqLine}; 49pub use irq::{CfgIrq, Irq, IrqLine};
49pub use lora_sync_word::LoRaSyncWord; 50pub use lora_sync_word::LoRaSyncWord;
50pub use mod_params::BpskModParams; 51pub use mod_params::{
51pub use mod_params::{CodingRate, LoRaBandwidth, LoRaModParams, SpreadingFactor}; 52 BpskModParams, CodingRate, FskBandwidth, FskBitrate, FskFdev, FskModParams, FskPulseShape, LoRaBandwidth,
52pub use mod_params::{FskBandwidth, FskBitrate, FskFdev, FskModParams, FskPulseShape}; 53 LoRaModParams, SpreadingFactor,
54};
53pub use ocp::Ocp; 55pub use ocp::Ocp;
54pub use op_error::OpError; 56pub use op_error::OpError;
55pub use pa_config::{PaConfig, PaSel}; 57pub use pa_config::{PaConfig, PaSel};
56pub use packet_params::{ 58pub use packet_params::{
57 AddrComp, BpskPacketParams, CrcType, GenericPacketParams, HeaderType, LoRaPacketParams, 59 AddrComp, BpskPacketParams, CrcType, GenericPacketParams, HeaderType, LoRaPacketParams, PreambleDetection,
58 PreambleDetection,
59}; 60};
60pub use packet_status::{FskPacketStatus, LoRaPacketStatus}; 61pub use packet_status::{FskPacketStatus, LoRaPacketStatus};
61pub use packet_type::PacketType; 62pub use packet_type::PacketType;
@@ -75,17 +76,12 @@ pub use timeout::Timeout;
75pub use tx_params::{RampTime, TxParams}; 76pub use tx_params::{RampTime, TxParams};
76pub use value_error::ValueError; 77pub use value_error::ValueError;
77 78
78use embassy_hal_common::ratio::Ratio; 79use crate::dma::NoDma;
79 80use crate::peripherals::SUBGHZSPI;
80use crate::Unborrow; 81use crate::rcc::sealed::RccPeripheral;
81use crate::{ 82use crate::spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0};
82 dma::NoDma, 83use crate::time::Hertz;
83 pac, 84use crate::{pac, Unborrow};
84 peripherals::SUBGHZSPI,
85 rcc::sealed::RccPeripheral,
86 spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0},
87 time::Hertz,
88};
89 85
90/// Passthrough for SPI errors (for now) 86/// Passthrough for SPI errors (for now)
91pub type Error = crate::spi::Error; 87pub type Error = crate::spi::Error;
@@ -105,8 +101,7 @@ impl Nss {
105 fn clear() { 101 fn clear() {
106 let pwr = pac::PWR; 102 let pwr = pac::PWR;
107 unsafe { 103 unsafe {
108 pwr.subghzspicr() 104 pwr.subghzspicr().modify(|w| w.set_nss(pac::pwr::vals::Nss::LOW));
109 .modify(|w| w.set_nss(pac::pwr::vals::Nss::LOW));
110 } 105 }
111 } 106 }
112 107
@@ -115,8 +110,7 @@ impl Nss {
115 fn set() { 110 fn set() {
116 let pwr = pac::PWR; 111 let pwr = pac::PWR;
117 unsafe { 112 unsafe {
118 pwr.subghzspicr() 113 pwr.subghzspicr().modify(|w| w.set_nss(pac::pwr::vals::Nss::HIGH));
119 .modify(|w| w.set_nss(pac::pwr::vals::Nss::HIGH));
120 } 114 }
121 } 115 }
122} 116}
@@ -286,8 +280,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
286 self.poll_not_busy(); 280 self.poll_not_busy();
287 { 281 {
288 let _nss: Nss = Nss::new(); 282 let _nss: Nss = Nss::new();
289 self.spi 283 self.spi.blocking_write(&[OpCode::WriteBuffer as u8, offset])?;
290 .blocking_write(&[OpCode::WriteBuffer as u8, offset])?;
291 self.spi.blocking_write(data)?; 284 self.spi.blocking_write(data)?;
292 } 285 }
293 self.poll_not_busy(); 286 self.poll_not_busy();
@@ -305,8 +298,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
305 self.poll_not_busy(); 298 self.poll_not_busy();
306 { 299 {
307 let _nss: Nss = Nss::new(); 300 let _nss: Nss = Nss::new();
308 self.spi 301 self.spi.blocking_write(&[OpCode::ReadBuffer as u8, offset])?;
309 .blocking_write(&[OpCode::ReadBuffer as u8, offset])?;
310 self.spi.blocking_transfer_in_place(&mut status_buf)?; 302 self.spi.blocking_transfer_in_place(&mut status_buf)?;
311 self.spi.blocking_transfer_in_place(buf)?; 303 self.spi.blocking_transfer_in_place(buf)?;
312 } 304 }
@@ -678,10 +670,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
678 /// # Ok::<(), embassy_stm32::subghz::Error>(()) 670 /// # Ok::<(), embassy_stm32::subghz::Error>(())
679 /// ``` 671 /// ```
680 pub fn set_rx_timeout_stop(&mut self, rx_timeout_stop: RxTimeoutStop) -> Result<(), Error> { 672 pub fn set_rx_timeout_stop(&mut self, rx_timeout_stop: RxTimeoutStop) -> Result<(), Error> {
681 self.write(&[ 673 self.write(&[OpCode::SetStopRxTimerOnPreamble.into(), rx_timeout_stop.into()])
682 OpCode::SetStopRxTimerOnPreamble.into(),
683 rx_timeout_stop.into(),
684 ])
685 } 674 }
686 675
687 /// Put the radio in non-continuous RX mode. 676 /// Put the radio in non-continuous RX mode.
@@ -730,11 +719,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
730 /// [`RxDone`]: crate::subghz::Irq::RxDone 719 /// [`RxDone`]: crate::subghz::Irq::RxDone
731 /// [`set_rf_frequency`]: crate::subghz::SubGhz::set_rf_frequency 720 /// [`set_rf_frequency`]: crate::subghz::SubGhz::set_rf_frequency
732 /// [`set_standby`]: crate::subghz::SubGhz::set_standby 721 /// [`set_standby`]: crate::subghz::SubGhz::set_standby
733 pub fn set_rx_duty_cycle( 722 pub fn set_rx_duty_cycle(&mut self, rx_period: Timeout, sleep_period: Timeout) -> Result<(), Error> {
734 &mut self,
735 rx_period: Timeout,
736 sleep_period: Timeout,
737 ) -> Result<(), Error> {
738 let rx_period_bits: u32 = rx_period.into_bits(); 723 let rx_period_bits: u32 = rx_period.into_bits();
739 let sleep_period_bits: u32 = sleep_period.into_bits(); 724 let sleep_period_bits: u32 = sleep_period.into_bits();
740 self.write(&[ 725 self.write(&[
@@ -1288,9 +1273,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
1288 /// # Ok::<(), embassy_stm32::subghz::Error>(()) 1273 /// # Ok::<(), embassy_stm32::subghz::Error>(())
1289 /// ``` 1274 /// ```
1290 pub fn lora_packet_status(&mut self) -> Result<LoRaPacketStatus, Error> { 1275 pub fn lora_packet_status(&mut self) -> Result<LoRaPacketStatus, Error> {
1291 Ok(LoRaPacketStatus::from( 1276 Ok(LoRaPacketStatus::from(self.read_n(OpCode::GetPacketStatus)?))
1292 self.read_n(OpCode::GetPacketStatus)?,
1293 ))
1294 } 1277 }
1295 1278
1296 /// Get the instantaneous signal strength during packet reception. 1279 /// Get the instantaneous signal strength during packet reception.
diff --git a/embassy-stm32/src/subghz/pa_config.rs b/embassy-stm32/src/subghz/pa_config.rs
index 8da4ba400..9833368c4 100644
--- a/embassy-stm32/src/subghz/pa_config.rs
+++ b/embassy-stm32/src/subghz/pa_config.rs
@@ -13,58 +13,37 @@ impl PaConfig {
13 /// Optimal settings for +15dBm output power with the low-power PA. 13 /// Optimal settings for +15dBm output power with the low-power PA.
14 /// 14 ///
15 /// This must be used with [`TxParams::LP_15`](super::TxParams::LP_15). 15 /// This must be used with [`TxParams::LP_15`](super::TxParams::LP_15).
16 pub const LP_15: PaConfig = PaConfig::new() 16 pub const LP_15: PaConfig = PaConfig::new().set_pa_duty_cycle(0x6).set_hp_max(0x0).set_pa(PaSel::Lp);
17 .set_pa_duty_cycle(0x6)
18 .set_hp_max(0x0)
19 .set_pa(PaSel::Lp);
20 17
21 /// Optimal settings for +14dBm output power with the low-power PA. 18 /// Optimal settings for +14dBm output power with the low-power PA.
22 /// 19 ///
23 /// This must be used with [`TxParams::LP_14`](super::TxParams::LP_14). 20 /// This must be used with [`TxParams::LP_14`](super::TxParams::LP_14).
24 pub const LP_14: PaConfig = PaConfig::new() 21 pub const LP_14: PaConfig = PaConfig::new().set_pa_duty_cycle(0x4).set_hp_max(0x0).set_pa(PaSel::Lp);
25 .set_pa_duty_cycle(0x4)
26 .set_hp_max(0x0)
27 .set_pa(PaSel::Lp);
28 22
29 /// Optimal settings for +10dBm output power with the low-power PA. 23 /// Optimal settings for +10dBm output power with the low-power PA.
30 /// 24 ///
31 /// This must be used with [`TxParams::LP_10`](super::TxParams::LP_10). 25 /// This must be used with [`TxParams::LP_10`](super::TxParams::LP_10).
32 pub const LP_10: PaConfig = PaConfig::new() 26 pub const LP_10: PaConfig = PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp);
33 .set_pa_duty_cycle(0x1)
34 .set_hp_max(0x0)
35 .set_pa(PaSel::Lp);
36 27
37 /// Optimal settings for +22dBm output power with the high-power PA. 28 /// Optimal settings for +22dBm output power with the high-power PA.
38 /// 29 ///
39 /// This must be used with [`TxParams::HP`](super::TxParams::HP). 30 /// This must be used with [`TxParams::HP`](super::TxParams::HP).
40 pub const HP_22: PaConfig = PaConfig::new() 31 pub const HP_22: PaConfig = PaConfig::new().set_pa_duty_cycle(0x4).set_hp_max(0x7).set_pa(PaSel::Hp);
41 .set_pa_duty_cycle(0x4)
42 .set_hp_max(0x7)
43 .set_pa(PaSel::Hp);
44 32
45 /// Optimal settings for +20dBm output power with the high-power PA. 33 /// Optimal settings for +20dBm output power with the high-power PA.
46 /// 34 ///
47 /// This must be used with [`TxParams::HP`](super::TxParams::HP). 35 /// This must be used with [`TxParams::HP`](super::TxParams::HP).
48 pub const HP_20: PaConfig = PaConfig::new() 36 pub const HP_20: PaConfig = PaConfig::new().set_pa_duty_cycle(0x3).set_hp_max(0x5).set_pa(PaSel::Hp);
49 .set_pa_duty_cycle(0x3)
50 .set_hp_max(0x5)
51 .set_pa(PaSel::Hp);
52 37
53 /// Optimal settings for +17dBm output power with the high-power PA. 38 /// Optimal settings for +17dBm output power with the high-power PA.
54 /// 39 ///
55 /// This must be used with [`TxParams::HP`](super::TxParams::HP). 40 /// This must be used with [`TxParams::HP`](super::TxParams::HP).
56 pub const HP_17: PaConfig = PaConfig::new() 41 pub const HP_17: PaConfig = PaConfig::new().set_pa_duty_cycle(0x2).set_hp_max(0x3).set_pa(PaSel::Hp);
57 .set_pa_duty_cycle(0x2)
58 .set_hp_max(0x3)
59 .set_pa(PaSel::Hp);
60 42
61 /// Optimal settings for +14dBm output power with the high-power PA. 43 /// Optimal settings for +14dBm output power with the high-power PA.
62 /// 44 ///
63 /// This must be used with [`TxParams::HP`](super::TxParams::HP). 45 /// This must be used with [`TxParams::HP`](super::TxParams::HP).
64 pub const HP_14: PaConfig = PaConfig::new() 46 pub const HP_14: PaConfig = PaConfig::new().set_pa_duty_cycle(0x2).set_hp_max(0x2).set_pa(PaSel::Hp);
65 .set_pa_duty_cycle(0x2)
66 .set_hp_max(0x2)
67 .set_pa(PaSel::Hp);
68 47
69 /// Create a new `PaConfig` struct. 48 /// Create a new `PaConfig` struct.
70 /// 49 ///
diff --git a/embassy-stm32/src/subghz/packet_params.rs b/embassy-stm32/src/subghz/packet_params.rs
index ae84ea26a..60b13ba4e 100644
--- a/embassy-stm32/src/subghz/packet_params.rs
+++ b/embassy-stm32/src/subghz/packet_params.rs
@@ -147,10 +147,7 @@ impl GenericPacketParams {
147 /// # assert_eq!(PKT_PARAMS.as_slice()[3], 0x4); 147 /// # assert_eq!(PKT_PARAMS.as_slice()[3], 0x4);
148 /// ``` 148 /// ```
149 #[must_use = "set_preamble_detection returns a modified GenericPacketParams"] 149 #[must_use = "set_preamble_detection returns a modified GenericPacketParams"]
150 pub const fn set_preamble_detection( 150 pub const fn set_preamble_detection(mut self, pb_det: PreambleDetection) -> GenericPacketParams {
151 mut self,
152 pb_det: PreambleDetection,
153 ) -> GenericPacketParams {
154 self.buf[3] = pb_det as u8; 151 self.buf[3] = pb_det as u8;
155 self 152 self
156 } 153 }
diff --git a/embassy-stm32/src/subghz/packet_status.rs b/embassy-stm32/src/subghz/packet_status.rs
index 46eded6f1..a4e348d94 100644
--- a/embassy-stm32/src/subghz/packet_status.rs
+++ b/embassy-stm32/src/subghz/packet_status.rs
@@ -1,6 +1,4 @@
1use super::Ratio; 1use super::{Ratio, Status};
2
3use super::Status;
4 2
5/// (G)FSK packet status. 3/// (G)FSK packet status.
6/// 4///
diff --git a/embassy-stm32/src/subghz/rf_frequency.rs b/embassy-stm32/src/subghz/rf_frequency.rs
index 54c03dcd8..520dc89d7 100644
--- a/embassy-stm32/src/subghz/rf_frequency.rs
+++ b/embassy-stm32/src/subghz/rf_frequency.rs
@@ -89,10 +89,7 @@ impl RfFreq {
89 89
90 // Get the frequency bit value. 90 // Get the frequency bit value.
91 const fn as_bits(&self) -> u32 { 91 const fn as_bits(&self) -> u32 {
92 ((self.buf[1] as u32) << 24) 92 ((self.buf[1] as u32) << 24) | ((self.buf[2] as u32) << 16) | ((self.buf[3] as u32) << 8) | (self.buf[4] as u32)
93 | ((self.buf[2] as u32) << 16)
94 | ((self.buf[3] as u32) << 8)
95 | (self.buf[4] as u32)
96 } 93 }
97 94
98 /// Get the actual frequency. 95 /// Get the actual frequency.
diff --git a/embassy-stm32/src/subghz/sleep_cfg.rs b/embassy-stm32/src/subghz/sleep_cfg.rs
index 3fdcc7133..2d2fe0c9c 100644
--- a/embassy-stm32/src/subghz/sleep_cfg.rs
+++ b/embassy-stm32/src/subghz/sleep_cfg.rs
@@ -49,9 +49,7 @@ impl SleepCfg {
49 /// # assert_eq!(u8::from(SLEEP_CFG), 0b101); 49 /// # assert_eq!(u8::from(SLEEP_CFG), 0b101);
50 /// ``` 50 /// ```
51 pub const fn new() -> SleepCfg { 51 pub const fn new() -> SleepCfg {
52 SleepCfg(0) 52 SleepCfg(0).set_startup(Startup::Warm).set_rtc_wakeup_en(true)
53 .set_startup(Startup::Warm)
54 .set_rtc_wakeup_en(true)
55 } 53 }
56 54
57 /// Set the startup mode. 55 /// Set the startup mode.
diff --git a/embassy-stm32/src/subghz/status.rs b/embassy-stm32/src/subghz/status.rs
index ae50c5193..10a212b99 100644
--- a/embassy-stm32/src/subghz/status.rs
+++ b/embassy-stm32/src/subghz/status.rs
@@ -192,11 +192,6 @@ impl core::fmt::Display for Status {
192#[cfg(feature = "defmt")] 192#[cfg(feature = "defmt")]
193impl defmt::Format for Status { 193impl defmt::Format for Status {
194 fn format(&self, fmt: defmt::Formatter) { 194 fn format(&self, fmt: defmt::Formatter) {
195 defmt::write!( 195 defmt::write!(fmt, "Status {{ mode: {}, cmd: {} }}", self.mode(), self.cmd())
196 fmt,
197 "Status {{ mode: {}, cmd: {} }}",
198 self.mode(),
199 self.cmd()
200 )
201 } 196 }
202} 197}
diff --git a/embassy-stm32/src/subghz/timeout.rs b/embassy-stm32/src/subghz/timeout.rs
index 580d0a640..2a0f5b85e 100644
--- a/embassy-stm32/src/subghz/timeout.rs
+++ b/embassy-stm32/src/subghz/timeout.rs
@@ -145,8 +145,7 @@ impl Timeout {
145 // `core::Duration` were not `const fn`, which leads to the hacks 145 // `core::Duration` were not `const fn`, which leads to the hacks
146 // you see here. 146 // you see here.
147 let nanos: u128 = duration.as_nanos(); 147 let nanos: u128 = duration.as_nanos();
148 const UPPER_LIMIT: u128 = 148 const UPPER_LIMIT: u128 = Timeout::MAX.as_nanos() as u128 + (Timeout::RESOLUTION_NANOS as u128) / 2;
149 Timeout::MAX.as_nanos() as u128 + (Timeout::RESOLUTION_NANOS as u128) / 2;
150 const LOWER_LIMIT: u128 = (((Timeout::RESOLUTION_NANOS as u128) + 1) / 2) as u128; 149 const LOWER_LIMIT: u128 = (((Timeout::RESOLUTION_NANOS as u128) + 1) / 2) as u128;
151 150
152 if nanos > UPPER_LIMIT { 151 if nanos > UPPER_LIMIT {
@@ -420,15 +419,13 @@ impl From<Timeout> for embassy::time::Duration {
420 419
421#[cfg(test)] 420#[cfg(test)]
422mod tests { 421mod tests {
423 use super::{Timeout, ValueError};
424 use core::time::Duration; 422 use core::time::Duration;
425 423
424 use super::{Timeout, ValueError};
425
426 #[test] 426 #[test]
427 fn saturate() { 427 fn saturate() {
428 assert_eq!( 428 assert_eq!(Timeout::from_duration_sat(Duration::from_secs(u64::MAX)), Timeout::MAX);
429 Timeout::from_duration_sat(Duration::from_secs(u64::MAX)),
430 Timeout::MAX
431 );
432 } 429 }
433 430
434 #[test] 431 #[test]
@@ -455,10 +452,7 @@ mod tests {
455 #[test] 452 #[test]
456 fn upper_limit() { 453 fn upper_limit() {
457 let high: Duration = Timeout::MAX.as_duration() + Timeout::RESOLUTION / 2; 454 let high: Duration = Timeout::MAX.as_duration() + Timeout::RESOLUTION / 2;
458 assert_eq!( 455 assert_eq!(Timeout::from_duration(high), Ok(Timeout::from_raw(0xFFFFFF)));
459 Timeout::from_duration(high),
460 Ok(Timeout::from_raw(0xFFFFFF))
461 );
462 456
463 let too_high: Duration = high + Duration::from_nanos(1); 457 let too_high: Duration = high + Duration::from_nanos(1);
464 assert_eq!( 458 assert_eq!(
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs
index b63ed5bd4..38a4adc1d 100644
--- a/embassy-stm32/src/time_driver.rs
+++ b/embassy-stm32/src/time_driver.rs
@@ -1,22 +1,20 @@
1use crate::interrupt::InterruptExt;
2use atomic_polyfill::{AtomicU32, AtomicU8};
3use core::cell::Cell; 1use core::cell::Cell;
4use core::convert::TryInto; 2use core::convert::TryInto;
5use core::sync::atomic::{compiler_fence, Ordering}; 3use core::sync::atomic::{compiler_fence, Ordering};
6use core::{mem, ptr}; 4use core::{mem, ptr};
5
6use atomic_polyfill::{AtomicU32, AtomicU8};
7use embassy::blocking_mutex::raw::CriticalSectionRawMutex; 7use embassy::blocking_mutex::raw::CriticalSectionRawMutex;
8use embassy::blocking_mutex::Mutex; 8use embassy::blocking_mutex::Mutex;
9use embassy::time::driver::{AlarmHandle, Driver}; 9use embassy::time::driver::{AlarmHandle, Driver};
10use embassy::time::TICKS_PER_SECOND; 10use embassy::time::TICKS_PER_SECOND;
11use stm32_metapac::timer::regs; 11use stm32_metapac::timer::regs;
12 12
13use crate::interrupt; 13use crate::interrupt::{CriticalSection, InterruptExt};
14use crate::interrupt::CriticalSection;
15use crate::pac::timer::vals; 14use crate::pac::timer::vals;
16use crate::peripherals;
17use crate::rcc::sealed::RccPeripheral; 15use crate::rcc::sealed::RccPeripheral;
18use crate::timer::sealed::Basic16bitInstance as BasicInstance; 16use crate::timer::sealed::{Basic16bitInstance as BasicInstance, GeneralPurpose16bitInstance as Instance};
19use crate::timer::sealed::GeneralPurpose16bitInstance as Instance; 17use crate::{interrupt, peripherals};
20 18
21#[cfg(not(any(time_driver_tim12, time_driver_tim15)))] 19#[cfg(not(any(time_driver_tim12, time_driver_tim15)))]
22const ALARM_COUNT: usize = 3; 20const ALARM_COUNT: usize = 3;
@@ -271,15 +269,13 @@ impl Driver for RtcDriver {
271 } 269 }
272 270
273 unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { 271 unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
274 let id = self 272 let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| {
275 .alarm_count 273 if x < ALARM_COUNT as u8 {
276 .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { 274 Some(x + 1)
277 if x < ALARM_COUNT as u8 { 275 } else {
278 Some(x + 1) 276 None
279 } else { 277 }
280 None 278 });
281 }
282 });
283 279
284 match id { 280 match id {
285 Ok(id) => Some(AlarmHandle::new(id)), 281 Ok(id) => Some(AlarmHandle::new(id)),
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs
index 3cc6298be..9067fa462 100644
--- a/embassy-stm32/src/timer/mod.rs
+++ b/embassy-stm32/src/timer/mod.rs
@@ -1,8 +1,9 @@
1use crate::interrupt::Interrupt; 1use stm32_metapac::timer::vals;
2 2
3use crate::rcc::{sealed::RccPeripheral as __RccPeri, RccPeripheral}; 3use crate::interrupt::Interrupt;
4use crate::rcc::sealed::RccPeripheral as __RccPeri;
5use crate::rcc::RccPeripheral;
4use crate::time::Hertz; 6use crate::time::Hertz;
5use stm32_metapac::timer::vals;
6 7
7#[cfg(feature = "unstable-pac")] 8#[cfg(feature = "unstable-pac")]
8pub mod low_level { 9pub mod low_level {
@@ -86,8 +87,7 @@ macro_rules! impl_basic_16bit_timer {
86 let timer_f = Self::frequency().0; 87 let timer_f = Self::frequency().0;
87 let pclk_ticks_per_timer_period = timer_f / f; 88 let pclk_ticks_per_timer_period = timer_f / f;
88 let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 16)).try_into()); 89 let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 16)).try_into());
89 let arr: u16 = 90 let arr: u16 = unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into());
90 unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into());
91 91
92 let regs = Self::regs(); 92 let regs = Self::regs();
93 unsafe { 93 unsafe {
@@ -138,8 +138,7 @@ macro_rules! impl_32bit_timer {
138 let timer_f = Self::frequency().0; 138 let timer_f = Self::frequency().0;
139 let pclk_ticks_per_timer_period = (timer_f / f) as u64; 139 let pclk_ticks_per_timer_period = (timer_f / f) as u64;
140 let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 32)).try_into()); 140 let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 32)).try_into());
141 let arr: u32 = 141 let arr: u32 = unwrap!(((pclk_ticks_per_timer_period / (psc as u64 + 1)).try_into()));
142 unwrap!(((pclk_ticks_per_timer_period / (psc as u64 + 1)).try_into()));
143 142
144 let regs = Self::regs_gp32(); 143 let regs = Self::regs_gp32();
145 unsafe { 144 unsafe {
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs
index e2c9f7802..c4703cff2 100644
--- a/embassy-stm32/src/usart/buffered.rs
+++ b/embassy-stm32/src/usart/buffered.rs
@@ -1,6 +1,7 @@
1use atomic_polyfill::{compiler_fence, Ordering};
2use core::future::Future; 1use core::future::Future;
3use core::task::Poll; 2use core::task::Poll;
3
4use atomic_polyfill::{compiler_fence, Ordering};
4use embassy::waitqueue::WakerRegistration; 5use embassy::waitqueue::WakerRegistration;
5use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; 6use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
6use embassy_hal_common::ring_buffer::RingBuffer; 7use embassy_hal_common::ring_buffer::RingBuffer;
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index 2acec874f..a893e4b80 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -1,15 +1,15 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::interrupt::Interrupt;
4use crate::Unborrow;
5use core::marker::PhantomData; 3use core::marker::PhantomData;
4
6use embassy_hal_common::unborrow; 5use embassy_hal_common::unborrow;
7 6
8use crate::dma::NoDma; 7use crate::dma::NoDma;
9use crate::gpio::sealed::AFType; 8use crate::gpio::sealed::AFType;
9use crate::interrupt::Interrupt;
10use crate::pac::usart::{regs, vals}; 10use crate::pac::usart::{regs, vals};
11use crate::peripherals;
12use crate::rcc::RccPeripheral; 11use crate::rcc::RccPeripheral;
12use crate::{peripherals, Unborrow};
13 13
14#[derive(Clone, Copy, PartialEq, Eq, Debug)] 14#[derive(Clone, Copy, PartialEq, Eq, Debug)]
15pub enum DataBits { 15pub enum DataBits {
@@ -314,18 +314,14 @@ mod eh02 {
314 } 314 }
315 } 315 }
316 316
317 impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::serial::Read<u8> 317 impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> {
318 for Uart<'d, T, TxDma, RxDma>
319 {
320 type Error = Error; 318 type Error = Error;
321 fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { 319 fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> {
322 embedded_hal_02::serial::Read::read(&mut self.rx) 320 embedded_hal_02::serial::Read::read(&mut self.rx)
323 } 321 }
324 } 322 }
325 323
326 impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::blocking::serial::Write<u8> 324 impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::blocking::serial::Write<u8> for Uart<'d, T, TxDma, RxDma> {
327 for Uart<'d, T, TxDma, RxDma>
328 {
329 type Error = Error; 325 type Error = Error;
330 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { 326 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
331 self.blocking_write(buffer) 327 self.blocking_write(buffer)
@@ -351,9 +347,7 @@ mod eh1 {
351 } 347 }
352 } 348 }
353 349
354 impl<'d, T: Instance, TxDma, RxDma> embedded_hal_1::serial::ErrorType 350 impl<'d, T: Instance, TxDma, RxDma> embedded_hal_1::serial::ErrorType for Uart<'d, T, TxDma, RxDma> {
355 for Uart<'d, T, TxDma, RxDma>
356 {
357 type Error = Error; 351 type Error = Error;
358 } 352 }
359 353
diff --git a/embassy-stm32/src/usb/mod.rs b/embassy-stm32/src/usb/mod.rs
index 65451917e..fbd1fa823 100644
--- a/embassy-stm32/src/usb/mod.rs
+++ b/embassy-stm32/src/usb/mod.rs
@@ -1,5 +1,4 @@
1use crate::interrupt::Interrupt; 1use crate::interrupt::Interrupt;
2
3use crate::rcc::RccPeripheral; 2use crate::rcc::RccPeripheral;
4 3
5#[cfg(feature = "nightly")] 4#[cfg(feature = "nightly")]
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs
index eaf24f8ae..10eb94e6c 100644
--- a/embassy-stm32/src/usb/usb.rs
+++ b/embassy-stm32/src/usb/usb.rs
@@ -1,11 +1,10 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::interrupt::InterruptExt;
4use crate::Unborrow;
5use atomic_polyfill::{AtomicBool, AtomicU8};
6use core::marker::PhantomData; 3use core::marker::PhantomData;
7use core::sync::atomic::Ordering; 4use core::sync::atomic::Ordering;
8use core::task::Poll; 5use core::task::Poll;
6
7use atomic_polyfill::{AtomicBool, AtomicU8};
9use embassy::time::{block_for, Duration}; 8use embassy::time::{block_for, Duration};
10use embassy::waitqueue::AtomicWaker; 9use embassy::waitqueue::AtomicWaker;
11use embassy_hal_common::unborrow; 10use embassy_hal_common::unborrow;
@@ -16,12 +15,12 @@ use futures::Future;
16use pac::common::{Reg, RW}; 15use pac::common::{Reg, RW};
17use pac::usb::vals::{EpType, Stat}; 16use pac::usb::vals::{EpType, Stat};
18 17
18use super::{DmPin, DpPin, Instance};
19use crate::gpio::sealed::AFType; 19use crate::gpio::sealed::AFType;
20use crate::pac; 20use crate::interrupt::InterruptExt;
21use crate::pac::usb::regs; 21use crate::pac::usb::regs;
22use crate::rcc::sealed::RccPeripheral; 22use crate::rcc::sealed::RccPeripheral;
23 23use crate::{pac, Unborrow};
24use super::{DmPin, DpPin, Instance};
25 24
26const EP_COUNT: usize = 8; 25const EP_COUNT: usize = 8;
27 26
@@ -105,11 +104,7 @@ impl<T: Instance> EndpointBuffer<T> {
105 if i * 2 + 1 < buf.len() { 104 if i * 2 + 1 < buf.len() {
106 val |= (buf[i * 2 + 1] as u16) << 8; 105 val |= (buf[i * 2 + 1] as u16) << 8;
107 } 106 }
108 unsafe { 107 unsafe { T::regs().ep_mem(self.addr as usize / 2 + i).write_value(val) };
109 T::regs()
110 .ep_mem(self.addr as usize / 2 + i)
111 .write_value(val)
112 };
113 } 108 }
114 } 109 }
115} 110}
@@ -146,9 +141,7 @@ impl<'d, T: Instance> Driver<'d, T> {
146 unsafe { 141 unsafe {
147 crate::peripherals::PWR::enable(); 142 crate::peripherals::PWR::enable();
148 143
149 pac::PWR 144 pac::PWR.cr2().modify(|w| w.set_usv(pac::pwr::vals::Usv::VALID));
150 .cr2()
151 .modify(|w| w.set_usv(pac::pwr::vals::Usv::VALID));
152 } 145 }
153 146
154 unsafe { 147 unsafe {
@@ -857,12 +850,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
857 } 850 }
858 } 851 }
859 852
860 fn data_out<'a>( 853 fn data_out<'a>(&'a mut self, buf: &'a mut [u8], first: bool, last: bool) -> Self::DataOutFuture<'a> {
861 &'a mut self,
862 buf: &'a mut [u8],
863 first: bool,
864 last: bool,
865 ) -> Self::DataOutFuture<'a> {
866 async move { 854 async move {
867 let regs = T::regs(); 855 let regs = T::regs();
868 856
diff --git a/embassy-stm32/src/usb_otg.rs b/embassy-stm32/src/usb_otg.rs
index 0f732965c..581754135 100644
--- a/embassy-stm32/src/usb_otg.rs
+++ b/embassy-stm32/src/usb_otg.rs
@@ -1,9 +1,10 @@
1use crate::Unborrow;
2use core::marker::PhantomData; 1use core::marker::PhantomData;
2
3use embassy_hal_common::unborrow; 3use embassy_hal_common::unborrow;
4 4
5use crate::gpio::sealed::AFType; 5use crate::gpio::sealed::AFType;
6use crate::{peripherals, rcc::RccPeripheral}; 6use crate::rcc::RccPeripheral;
7use crate::{peripherals, Unborrow};
7 8
8macro_rules! config_ulpi_pins { 9macro_rules! config_ulpi_pins {
9 ($($pin:ident),*) => { 10 ($($pin:ident),*) => {
@@ -76,8 +77,8 @@ impl<'d, T: Instance> UsbOtg<'d, T> {
76 ulpi_d7: impl Unborrow<Target = impl UlpiD7Pin<T>> + 'd, 77 ulpi_d7: impl Unborrow<Target = impl UlpiD7Pin<T>> + 'd,
77 ) -> Self { 78 ) -> Self {
78 config_ulpi_pins!( 79 config_ulpi_pins!(
79 ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, 80 ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, ulpi_d5, ulpi_d6,
80 ulpi_d5, ulpi_d6, ulpi_d7 81 ulpi_d7
81 ); 82 );
82 83
83 Self { 84 Self {
diff --git a/embassy-usb-hid/src/lib.rs b/embassy-usb-hid/src/lib.rs
index a75cb8c38..b87f57481 100644
--- a/embassy-usb-hid/src/lib.rs
+++ b/embassy-usb-hid/src/lib.rs
@@ -12,13 +12,9 @@ use core::ops::Range;
12use core::sync::atomic::{AtomicUsize, Ordering}; 12use core::sync::atomic::{AtomicUsize, Ordering};
13 13
14use embassy::time::Duration; 14use embassy::time::Duration;
15use embassy_usb::driver::EndpointOut; 15use embassy_usb::control::{ControlHandler, InResponse, OutResponse, Request, RequestType};
16use embassy_usb::{ 16use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut};
17 control::{ControlHandler, InResponse, OutResponse, Request, RequestType}, 17use embassy_usb::Builder;
18 driver::{Driver, Endpoint, EndpointError, EndpointIn},
19 Builder,
20};
21
22#[cfg(feature = "usbd-hid")] 18#[cfg(feature = "usbd-hid")]
23use ssmarshal::serialize; 19use ssmarshal::serialize;
24#[cfg(feature = "usbd-hid")] 20#[cfg(feature = "usbd-hid")]
@@ -145,9 +141,7 @@ fn build<'d, D: Driver<'d>>(
145 (ep_out, ep_in, &state.out_report_offset) 141 (ep_out, ep_in, &state.out_report_offset)
146} 142}
147 143
148impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> 144impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> HidReaderWriter<'d, D, READ_N, WRITE_N> {
149 HidReaderWriter<'d, D, READ_N, WRITE_N>
150{
151 /// Creates a new HidReaderWriter. 145 /// Creates a new HidReaderWriter.
152 /// 146 ///
153 /// This will allocate one IN and one OUT endpoints. If you only need writing (sending) 147 /// This will allocate one IN and one OUT endpoints. If you only need writing (sending)
@@ -178,10 +172,7 @@ impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize>
178 172
179 /// Writes an input report by serializing the given report structure. 173 /// Writes an input report by serializing the given report structure.
180 #[cfg(feature = "usbd-hid")] 174 #[cfg(feature = "usbd-hid")]
181 pub async fn write_serialize<IR: AsInputReport>( 175 pub async fn write_serialize<IR: AsInputReport>(&mut self, r: &IR) -> Result<(), EndpointError> {
182 &mut self,
183 r: &IR,
184 ) -> Result<(), EndpointError> {
185 self.writer.write_serialize(r).await 176 self.writer.write_serialize(r).await
186 } 177 }
187 178
@@ -250,10 +241,7 @@ impl<'d, D: Driver<'d>, const N: usize> HidWriter<'d, D, N> {
250 241
251 /// Writes an input report by serializing the given report structure. 242 /// Writes an input report by serializing the given report structure.
252 #[cfg(feature = "usbd-hid")] 243 #[cfg(feature = "usbd-hid")]
253 pub async fn write_serialize<IR: AsInputReport>( 244 pub async fn write_serialize<IR: AsInputReport>(&mut self, r: &IR) -> Result<(), EndpointError> {
254 &mut self,
255 r: &IR,
256 ) -> Result<(), EndpointError> {
257 let mut buf: [u8; N] = [0; N]; 245 let mut buf: [u8; N] = [0; N];
258 let size = match serialize(&mut buf, r) { 246 let size = match serialize(&mut buf, r) {
259 Ok(size) => size, 247 Ok(size) => size,
@@ -298,8 +286,12 @@ impl<'d, D: Driver<'d>, const N: usize> HidReader<'d, D, N> {
298 match self.read(&mut buf).await { 286 match self.read(&mut buf).await {
299 Ok(len) => { 287 Ok(len) => {
300 let id = if use_report_ids { buf[0] } else { 0 }; 288 let id = if use_report_ids { buf[0] } else { 0 };
301 handler.set_report(ReportId::Out(id), &buf[..len]); } 289 handler.set_report(ReportId::Out(id), &buf[..len]);
302 Err(ReadError::BufferOverflow) => warn!("Host sent output report larger than the configured maximum output report length ({})", N), 290 }
291 Err(ReadError::BufferOverflow) => warn!(
292 "Host sent output report larger than the configured maximum output report length ({})",
293 N
294 ),
303 Err(ReadError::Disabled) => self.ep_out.wait_enabled().await, 295 Err(ReadError::Disabled) => self.ep_out.wait_enabled().await,
304 Err(ReadError::Sync(_)) => unreachable!(), 296 Err(ReadError::Sync(_)) => unreachable!(),
305 } 297 }
diff --git a/embassy-usb-ncm/src/lib.rs b/embassy-usb-ncm/src/lib.rs
index 70870d51a..e796af28f 100644
--- a/embassy-usb-ncm/src/lib.rs
+++ b/embassy-usb-ncm/src/lib.rs
@@ -5,9 +5,11 @@ pub(crate) mod fmt;
5 5
6use core::intrinsics::copy_nonoverlapping; 6use core::intrinsics::copy_nonoverlapping;
7use core::mem::{size_of, MaybeUninit}; 7use core::mem::{size_of, MaybeUninit};
8
8use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; 9use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request};
9use embassy_usb::driver::{Endpoint, EndpointError, EndpointIn, EndpointOut}; 10use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut};
10use embassy_usb::{driver::Driver, types::*, Builder}; 11use embassy_usb::types::*;
12use embassy_usb::Builder;
11 13
12/// This should be used as `device_class` when building the `UsbDevice`. 14/// This should be used as `device_class` when building the `UsbDevice`.
13pub const USB_CLASS_CDC: u8 = 0x02; 15pub const USB_CLASS_CDC: u8 = 0x02;
@@ -358,9 +360,7 @@ impl<'d, D: Driver<'d>> Sender<'d, D> {
358 // First packet is not full, just send it. 360 // First packet is not full, just send it.
359 // No need to send ZLP because it's short for sure. 361 // No need to send ZLP because it's short for sure.
360 buf[OUT_HEADER_LEN..][..data.len()].copy_from_slice(data); 362 buf[OUT_HEADER_LEN..][..data.len()].copy_from_slice(data);
361 self.write_ep 363 self.write_ep.write(&buf[..OUT_HEADER_LEN + data.len()]).await?;
362 .write(&buf[..OUT_HEADER_LEN + data.len()])
363 .await?;
364 } else { 364 } else {
365 let (d1, d2) = data.split_at(MAX_PACKET_SIZE - OUT_HEADER_LEN); 365 let (d1, d2) = data.split_at(MAX_PACKET_SIZE - OUT_HEADER_LEN);
366 366
diff --git a/embassy-usb-serial/src/lib.rs b/embassy-usb-serial/src/lib.rs
index 4587bf713..4d981e3fd 100644
--- a/embassy-usb-serial/src/lib.rs
+++ b/embassy-usb-serial/src/lib.rs
@@ -8,10 +8,12 @@ pub(crate) mod fmt;
8use core::cell::Cell; 8use core::cell::Cell;
9use core::mem::{self, MaybeUninit}; 9use core::mem::{self, MaybeUninit};
10use core::sync::atomic::{AtomicBool, Ordering}; 10use core::sync::atomic::{AtomicBool, Ordering};
11
11use embassy::blocking_mutex::CriticalSectionMutex; 12use embassy::blocking_mutex::CriticalSectionMutex;
12use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; 13use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request};
13use embassy_usb::driver::{Endpoint, EndpointError, EndpointIn, EndpointOut}; 14use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut};
14use embassy_usb::{driver::Driver, types::*, Builder}; 15use embassy_usb::types::*;
16use embassy_usb::Builder;
15 17
16/// This should be used as `device_class` when building the `UsbDevice`. 18/// This should be used as `device_class` when building the `UsbDevice`.
17pub const USB_CLASS_CDC: u8 = 0x02; 19pub const USB_CLASS_CDC: u8 = 0x02;
@@ -162,14 +164,8 @@ impl<'d> ControlHandler for Control<'d> {
162impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> { 164impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> {
163 /// Creates a new CdcAcmClass with the provided UsbBus and max_packet_size in bytes. For 165 /// Creates a new CdcAcmClass with the provided UsbBus and max_packet_size in bytes. For
164 /// full-speed devices, max_packet_size has to be one of 8, 16, 32 or 64. 166 /// full-speed devices, max_packet_size has to be one of 8, 16, 32 or 64.
165 pub fn new( 167 pub fn new(builder: &mut Builder<'d, D>, state: &'d mut State<'d>, max_packet_size: u16) -> Self {
166 builder: &mut Builder<'d, D>, 168 let control = state.control.write(Control { shared: &state.shared });
167 state: &'d mut State<'d>,
168 max_packet_size: u16,
169 ) -> Self {
170 let control = state.control.write(Control {
171 shared: &state.shared,
172 });
173 169
174 let control_shared = &state.shared; 170 let control_shared = &state.shared;
175 171
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs
index 09904949f..1ca24cc08 100644
--- a/embassy-usb/src/builder.rs
+++ b/embassy-usb/src/builder.rs
@@ -1,14 +1,11 @@
1use heapless::Vec; 1use heapless::Vec;
2 2
3use crate::{Interface, STRING_INDEX_CUSTOM_START};
4
5use super::control::ControlHandler; 3use super::control::ControlHandler;
6use super::descriptor::{BosWriter, DescriptorWriter}; 4use super::descriptor::{BosWriter, DescriptorWriter};
7use super::driver::{Driver, Endpoint}; 5use super::driver::{Driver, Endpoint};
8use super::types::*; 6use super::types::*;
9use super::DeviceStateHandler; 7use super::{DeviceStateHandler, UsbDevice, MAX_INTERFACE_COUNT};
10use super::UsbDevice; 8use crate::{Interface, STRING_INDEX_CUSTOM_START};
11use super::MAX_INTERFACE_COUNT;
12 9
13#[derive(Debug, Copy, Clone)] 10#[derive(Debug, Copy, Clone)]
14#[cfg_attr(feature = "defmt", derive(defmt::Format))] 11#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -151,9 +148,7 @@ impl<'d, D: Driver<'d>> Builder<'d, D> {
151 ) -> Self { 148 ) -> Self {
152 // Magic values specified in USB-IF ECN on IADs. 149 // Magic values specified in USB-IF ECN on IADs.
153 if config.composite_with_iads 150 if config.composite_with_iads
154 && (config.device_class != 0xEF 151 && (config.device_class != 0xEF || config.device_sub_class != 0x02 || config.device_protocol != 0x01)
155 || config.device_sub_class != 0x02
156 || config.device_protocol != 0x01)
157 { 152 {
158 panic!("if composite_with_iads is set, you must set device_class = 0xEF, device_sub_class = 0x02, device_protocol = 0x01"); 153 panic!("if composite_with_iads is set, you must set device_class = 0xEF, device_sub_class = 0x02, device_protocol = 0x01");
159 } 154 }
@@ -218,12 +213,7 @@ impl<'d, D: Driver<'d>> Builder<'d, D> {
218 /// with the given class/subclass/protocol, associating all the child interfaces. 213 /// with the given class/subclass/protocol, associating all the child interfaces.
219 /// 214 ///
220 /// If it's not set, no IAD descriptor is added. 215 /// If it's not set, no IAD descriptor is added.
221 pub fn function( 216 pub fn function(&mut self, class: u8, subclass: u8, protocol: u8) -> FunctionBuilder<'_, 'd, D> {
222 &mut self,
223 class: u8,
224 subclass: u8,
225 protocol: u8,
226 ) -> FunctionBuilder<'_, 'd, D> {
227 let iface_count_index = if self.config.composite_with_iads { 217 let iface_count_index = if self.config.composite_with_iads {
228 self.config_descriptor.iad( 218 self.config_descriptor.iad(
229 InterfaceNumber::new(self.interfaces.len() as _), 219 InterfaceNumber::new(self.interfaces.len() as _),
@@ -315,24 +305,14 @@ impl<'a, 'd, D: Driver<'d>> InterfaceBuilder<'a, 'd, D> {
315 /// Alternate setting numbers are guaranteed to be allocated consecutively, starting from 0. 305 /// Alternate setting numbers are guaranteed to be allocated consecutively, starting from 0.
316 /// 306 ///
317 /// The first alternate setting, with number 0, is the default one. 307 /// The first alternate setting, with number 0, is the default one.
318 pub fn alt_setting( 308 pub fn alt_setting(&mut self, class: u8, subclass: u8, protocol: u8) -> InterfaceAltBuilder<'_, 'd, D> {
319 &mut self,
320 class: u8,
321 subclass: u8,
322 protocol: u8,
323 ) -> InterfaceAltBuilder<'_, 'd, D> {
324 let number = self.next_alt_setting_number; 309 let number = self.next_alt_setting_number;
325 self.next_alt_setting_number += 1; 310 self.next_alt_setting_number += 1;
326 self.builder.interfaces[self.interface_number.0 as usize].num_alt_settings += 1; 311 self.builder.interfaces[self.interface_number.0 as usize].num_alt_settings += 1;
327 312
328 self.builder.config_descriptor.interface_alt( 313 self.builder
329 self.interface_number, 314 .config_descriptor
330 number, 315 .interface_alt(self.interface_number, number, class, subclass, protocol, None);
331 class,
332 subclass,
333 protocol,
334 None,
335 );
336 316
337 InterfaceAltBuilder { 317 InterfaceAltBuilder {
338 builder: self.builder, 318 builder: self.builder,
@@ -365,17 +345,10 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
365 /// Descriptors are written in the order builder functions are called. Note that some 345 /// Descriptors are written in the order builder functions are called. Note that some
366 /// classes care about the order. 346 /// classes care about the order.
367 pub fn descriptor(&mut self, descriptor_type: u8, descriptor: &[u8]) { 347 pub fn descriptor(&mut self, descriptor_type: u8, descriptor: &[u8]) {
368 self.builder 348 self.builder.config_descriptor.write(descriptor_type, descriptor)
369 .config_descriptor
370 .write(descriptor_type, descriptor)
371 } 349 }
372 350
373 fn endpoint_in( 351 fn endpoint_in(&mut self, ep_type: EndpointType, max_packet_size: u16, interval: u8) -> D::EndpointIn {
374 &mut self,
375 ep_type: EndpointType,
376 max_packet_size: u16,
377 interval: u8,
378 ) -> D::EndpointIn {
379 let ep = self 352 let ep = self
380 .builder 353 .builder
381 .driver 354 .driver
@@ -387,12 +360,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> {
387 ep 360 ep
388 } 361 }
389 362
390 fn endpoint_out( 363 fn endpoint_out(&mut self, ep_type: EndpointType, max_packet_size: u16, interval: u8) -> D::EndpointOut {
391 &mut self,
392 ep_type: EndpointType,
393 max_packet_size: u16,
394 interval: u8,
395 ) -> D::EndpointOut {
396 let ep = self 364 let ep = self
397 .builder 365 .builder
398 .driver 366 .driver
diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs
index 7f23fd921..b94a4b161 100644
--- a/embassy-usb/src/descriptor.rs
+++ b/embassy-usb/src/descriptor.rs
@@ -1,5 +1,6 @@
1use super::builder::Config; 1use super::builder::Config;
2use super::{types::*, CONFIGURATION_VALUE}; 2use super::types::*;
3use super::CONFIGURATION_VALUE;
3 4
4/// Standard descriptor types 5/// Standard descriptor types
5#[allow(missing_docs)] 6#[allow(missing_docs)]
@@ -113,11 +114,7 @@ impl<'a> DescriptorWriter<'a> {
113 CONFIGURATION_VALUE, // bConfigurationValue 114 CONFIGURATION_VALUE, // bConfigurationValue
114 0, // iConfiguration 115 0, // iConfiguration
115 0x80 | if config.self_powered { 0x40 } else { 0x00 } 116 0x80 | if config.self_powered { 0x40 } else { 0x00 }
116 | if config.supports_remote_wakeup { 117 | if config.supports_remote_wakeup { 0x20 } else { 0x00 }, // bmAttributes
117 0x20
118 } else {
119 0x00
120 }, // bmAttributes
121 (config.max_power / 2) as u8, // bMaxPower 118 (config.max_power / 2) as u8, // bMaxPower
122 ], 119 ],
123 ) 120 )
diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs
index 0680df7a5..bfe44d627 100644
--- a/embassy-usb/src/driver.rs
+++ b/embassy-usb/src/driver.rs
@@ -161,18 +161,12 @@ pub trait ControlPipe {
161 /// 161 ///
162 /// Must be called after `setup()` for requests with `direction` of `Out` 162 /// Must be called after `setup()` for requests with `direction` of `Out`
163 /// and `length` greater than zero. 163 /// and `length` greater than zero.
164 fn data_out<'a>( 164 fn data_out<'a>(&'a mut self, buf: &'a mut [u8], first: bool, last: bool) -> Self::DataOutFuture<'a>;
165 &'a mut self,
166 buf: &'a mut [u8],
167 first: bool,
168 last: bool,
169 ) -> Self::DataOutFuture<'a>;
170 165
171 /// Sends a DATA IN packet with `data` in response to a control read request. 166 /// Sends a DATA IN packet with `data` in response to a control read request.
172 /// 167 ///
173 /// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`. 168 /// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`.
174 fn data_in<'a>(&'a mut self, data: &'a [u8], first: bool, last: bool) 169 fn data_in<'a>(&'a mut self, data: &'a [u8], first: bool, last: bool) -> Self::DataInFuture<'a>;
175 -> Self::DataInFuture<'a>;
176 170
177 /// Accepts a control request. 171 /// Accepts a control request.
178 /// 172 ///
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs
index b691bf11e..f2577d4fc 100644
--- a/embassy-usb/src/lib.rs
+++ b/embassy-usb/src/lib.rs
@@ -15,16 +15,13 @@ pub mod types;
15use embassy::util::{select, Either}; 15use embassy::util::{select, Either};
16use heapless::Vec; 16use heapless::Vec;
17 17
18use crate::descriptor_reader::foreach_endpoint; 18pub use self::builder::{Builder, Config};
19use crate::driver::ControlPipe;
20
21use self::control::*; 19use self::control::*;
22use self::descriptor::*; 20use self::descriptor::*;
23use self::driver::{Bus, Driver, Event}; 21use self::driver::{Bus, Driver, Event};
24use self::types::*; 22use self::types::*;
25 23use crate::descriptor_reader::foreach_endpoint;
26pub use self::builder::Builder; 24use crate::driver::ControlPipe;
27pub use self::builder::Config;
28 25
29/// The global state of the USB device. 26/// The global state of the USB device.
30/// 27///
@@ -418,10 +415,8 @@ impl<'d, D: Driver<'d>> Inner<'d, D> {
418 // Enable all endpoints of selected alt settings. 415 // Enable all endpoints of selected alt settings.
419 foreach_endpoint(self.config_descriptor, |ep| { 416 foreach_endpoint(self.config_descriptor, |ep| {
420 let iface = &self.interfaces[ep.interface as usize]; 417 let iface = &self.interfaces[ep.interface as usize];
421 self.bus.endpoint_set_enabled( 418 self.bus
422 ep.ep_address, 419 .endpoint_set_enabled(ep.ep_address, iface.current_alt_setting == ep.interface_alt);
423 iface.current_alt_setting == ep.interface_alt,
424 );
425 }) 420 })
426 .unwrap(); 421 .unwrap();
427 422
@@ -474,10 +469,8 @@ impl<'d, D: Driver<'d>> Inner<'d, D> {
474 // Enable/disable EPs of this interface as needed. 469 // Enable/disable EPs of this interface as needed.
475 foreach_endpoint(self.config_descriptor, |ep| { 470 foreach_endpoint(self.config_descriptor, |ep| {
476 if ep.interface == req.index as u8 { 471 if ep.interface == req.index as u8 {
477 self.bus.endpoint_set_enabled( 472 self.bus
478 ep.ep_address, 473 .endpoint_set_enabled(ep.ep_address, iface.current_alt_setting == ep.interface_alt);
479 iface.current_alt_setting == ep.interface_alt,
480 );
481 } 474 }
482 }) 475 })
483 .unwrap(); 476 .unwrap();
diff --git a/embassy/src/blocking_mutex/mod.rs b/embassy/src/blocking_mutex/mod.rs
index 859eca075..eb3cd9392 100644
--- a/embassy/src/blocking_mutex/mod.rs
+++ b/embassy/src/blocking_mutex/mod.rs
@@ -2,9 +2,10 @@
2 2
3pub mod raw; 3pub mod raw;
4 4
5use self::raw::RawMutex;
6use core::cell::UnsafeCell; 5use core::cell::UnsafeCell;
7 6
7use self::raw::RawMutex;
8
8/// Any object implementing this trait guarantees exclusive access to the data contained 9/// Any object implementing this trait guarantees exclusive access to the data contained
9/// within the mutex for the duration of the lock. 10/// within the mutex for the duration of the lock.
10/// Adapted from <https://github.com/rust-embedded/mutex-trait>. 11/// Adapted from <https://github.com/rust-embedded/mutex-trait>.
diff --git a/embassy/src/blocking_mutex/raw.rs b/embassy/src/blocking_mutex/raw.rs
index ebeb6dccf..f9d249b08 100644
--- a/embassy/src/blocking_mutex/raw.rs
+++ b/embassy/src/blocking_mutex/raw.rs
@@ -14,9 +14,7 @@ unsafe impl Sync for CriticalSectionRawMutex {}
14 14
15impl CriticalSectionRawMutex { 15impl CriticalSectionRawMutex {
16 pub const fn new() -> Self { 16 pub const fn new() -> Self {
17 Self { 17 Self { _phantom: PhantomData }
18 _phantom: PhantomData,
19 }
20 } 18 }
21} 19}
22 20
@@ -38,9 +36,7 @@ unsafe impl Send for NoopRawMutex {}
38 36
39impl NoopRawMutex { 37impl NoopRawMutex {
40 pub const fn new() -> Self { 38 pub const fn new() -> Self {
41 Self { 39 Self { _phantom: PhantomData }
42 _phantom: PhantomData,
43 }
44 } 40 }
45} 41}
46 42
@@ -66,19 +62,14 @@ mod thread_mode {
66 62
67 impl ThreadModeRawMutex { 63 impl ThreadModeRawMutex {
68 pub const fn new() -> Self { 64 pub const fn new() -> Self {
69 Self { 65 Self { _phantom: PhantomData }
70 _phantom: PhantomData,
71 }
72 } 66 }
73 } 67 }
74 68
75 impl RawMutex for ThreadModeRawMutex { 69 impl RawMutex for ThreadModeRawMutex {
76 const INIT: Self = Self::new(); 70 const INIT: Self = Self::new();
77 fn lock<R>(&self, f: impl FnOnce() -> R) -> R { 71 fn lock<R>(&self, f: impl FnOnce() -> R) -> R {
78 assert!( 72 assert!(in_thread_mode(), "ThreadModeMutex can only be locked from thread mode.");
79 in_thread_mode(),
80 "ThreadModeMutex can only be locked from thread mode."
81 );
82 73
83 f() 74 f()
84 } 75 }
@@ -104,8 +95,7 @@ mod thread_mode {
104 return Some("main") == std::thread::current().name(); 95 return Some("main") == std::thread::current().name();
105 96
106 #[cfg(not(feature = "std"))] 97 #[cfg(not(feature = "std"))]
107 return cortex_m::peripheral::SCB::vect_active() 98 return cortex_m::peripheral::SCB::vect_active() == cortex_m::peripheral::scb::VectActive::ThreadMode;
108 == cortex_m::peripheral::scb::VectActive::ThreadMode;
109 } 99 }
110} 100}
111#[cfg(any(cortex_m, feature = "std"))] 101#[cfg(any(cortex_m, feature = "std"))]
diff --git a/embassy/src/channel/mpmc.rs b/embassy/src/channel/mpmc.rs
index 2377a9665..48056cd8f 100644
--- a/embassy/src/channel/mpmc.rs
+++ b/embassy/src/channel/mpmc.rs
@@ -20,8 +20,7 @@
20 20
21use core::cell::RefCell; 21use core::cell::RefCell;
22use core::pin::Pin; 22use core::pin::Pin;
23use core::task::Context; 23use core::task::{Context, Poll};
24use core::task::Poll;
25 24
26use futures::Future; 25use futures::Future;
27use heapless::Deque; 26use heapless::Deque;
@@ -44,9 +43,7 @@ where
44 M: RawMutex, 43 M: RawMutex,
45{ 44{
46 fn clone(&self) -> Self { 45 fn clone(&self) -> Self {
47 Sender { 46 Sender { channel: self.channel }
48 channel: self.channel,
49 }
50 } 47 }
51} 48}
52 49
@@ -77,9 +74,7 @@ pub struct DynamicSender<'ch, T> {
77 74
78impl<'ch, T> Clone for DynamicSender<'ch, T> { 75impl<'ch, T> Clone for DynamicSender<'ch, T> {
79 fn clone(&self) -> Self { 76 fn clone(&self) -> Self {
80 DynamicSender { 77 DynamicSender { channel: self.channel }
81 channel: self.channel,
82 }
83 } 78 }
84} 79}
85 80
@@ -125,9 +120,7 @@ where
125 M: RawMutex, 120 M: RawMutex,
126{ 121{
127 fn clone(&self) -> Self { 122 fn clone(&self) -> Self {
128 Receiver { 123 Receiver { channel: self.channel }
129 channel: self.channel,
130 }
131 } 124 }
132} 125}
133 126
@@ -158,9 +151,7 @@ pub struct DynamicReceiver<'ch, T> {
158 151
159impl<'ch, T> Clone for DynamicReceiver<'ch, T> { 152impl<'ch, T> Clone for DynamicReceiver<'ch, T> {
160 fn clone(&self) -> Self { 153 fn clone(&self) -> Self {
161 DynamicReceiver { 154 DynamicReceiver { channel: self.channel }
162 channel: self.channel,
163 }
164 } 155 }
165} 156}
166 157
@@ -169,9 +160,7 @@ impl<'ch, T> DynamicReceiver<'ch, T> {
169 /// 160 ///
170 /// See [`Channel::recv()`]. 161 /// See [`Channel::recv()`].
171 pub fn recv(&self) -> DynamicRecvFuture<'_, T> { 162 pub fn recv(&self) -> DynamicRecvFuture<'_, T> {
172 DynamicRecvFuture { 163 DynamicRecvFuture { channel: self.channel }
173 channel: self.channel,
174 }
175 } 164 }
176 165
177 /// Attempt to immediately receive the next value. 166 /// Attempt to immediately receive the next value.
@@ -282,11 +271,7 @@ impl<'ch, T> Future for DynamicSendFuture<'ch, T> {
282impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {} 271impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {}
283 272
284trait DynamicChannel<T> { 273trait DynamicChannel<T> {
285 fn try_send_with_context( 274 fn try_send_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>>;
286 &self,
287 message: T,
288 cx: Option<&mut Context<'_>>,
289 ) -> Result<(), TrySendError<T>>;
290 275
291 fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError>; 276 fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError>;
292} 277}
@@ -346,11 +331,7 @@ impl<T, const N: usize> ChannelState<T, N> {
346 self.try_send_with_context(message, None) 331 self.try_send_with_context(message, None)
347 } 332 }
348 333
349 fn try_send_with_context( 334 fn try_send_with_context(&mut self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>> {
350 &mut self,
351 message: T,
352 cx: Option<&mut Context<'_>>,
353 ) -> Result<(), TrySendError<T>> {
354 match self.queue.push_back(message) { 335 match self.queue.push_back(message) {
355 Ok(()) => { 336 Ok(()) => {
356 self.receiver_waker.wake(); 337 self.receiver_waker.wake();
@@ -425,11 +406,7 @@ where
425 self.lock(|c| c.try_recv_with_context(cx)) 406 self.lock(|c| c.try_recv_with_context(cx))
426 } 407 }
427 408
428 fn try_send_with_context( 409 fn try_send_with_context(&self, m: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>> {
429 &self,
430 m: T,
431 cx: Option<&mut Context<'_>>,
432 ) -> Result<(), TrySendError<T>> {
433 self.lock(|c| c.try_send_with_context(m, cx)) 410 self.lock(|c| c.try_send_with_context(m, cx))
434 } 411 }
435 412
@@ -491,11 +468,7 @@ impl<M, T, const N: usize> DynamicChannel<T> for Channel<M, T, N>
491where 468where
492 M: RawMutex, 469 M: RawMutex,
493{ 470{
494 fn try_send_with_context( 471 fn try_send_with_context(&self, m: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>> {
495 &self,
496 m: T,
497 cx: Option<&mut Context<'_>>,
498 ) -> Result<(), TrySendError<T>> {
499 Channel::try_send_with_context(self, m, cx) 472 Channel::try_send_with_context(self, m, cx)
500 } 473 }
501 474
@@ -512,11 +485,10 @@ mod tests {
512 use futures_executor::ThreadPool; 485 use futures_executor::ThreadPool;
513 use futures_timer::Delay; 486 use futures_timer::Delay;
514 487
488 use super::*;
515 use crate::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}; 489 use crate::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex};
516 use crate::util::Forever; 490 use crate::util::Forever;
517 491
518 use super::*;
519
520 fn capacity<T, const N: usize>(c: &ChannelState<T, N>) -> usize { 492 fn capacity<T, const N: usize>(c: &ChannelState<T, N>) -> usize {
521 c.queue.capacity() - c.queue.len() 493 c.queue.capacity() - c.queue.len()
522 } 494 }
diff --git a/embassy/src/executor/arch/wasm.rs b/embassy/src/executor/arch/wasm.rs
index f069ebc3d..9d5aa31ed 100644
--- a/embassy/src/executor/arch/wasm.rs
+++ b/embassy/src/executor/arch/wasm.rs
@@ -1,11 +1,11 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2
2use js_sys::Promise; 3use js_sys::Promise;
3use wasm_bindgen::prelude::*; 4use wasm_bindgen::prelude::*;
4 5
5use super::{ 6use super::raw::util::UninitCell;
6 raw::{self, util::UninitCell}, 7use super::raw::{self};
7 Spawner, 8use super::Spawner;
8};
9 9
10/// WASM executor, wasm_bindgen to schedule tasks on the JS event loop. 10/// WASM executor, wasm_bindgen to schedule tasks on the JS event loop.
11pub struct Executor { 11pub struct Executor {
diff --git a/embassy/src/executor/raw/mod.rs b/embassy/src/executor/raw/mod.rs
index 5034c0d66..09429c19a 100644
--- a/embassy/src/executor/raw/mod.rs
+++ b/embassy/src/executor/raw/mod.rs
@@ -13,25 +13,25 @@ mod timer_queue;
13pub(crate) mod util; 13pub(crate) mod util;
14mod waker; 14mod waker;
15 15
16use atomic_polyfill::{AtomicU32, Ordering};
17use core::cell::Cell; 16use core::cell::Cell;
18use core::future::Future; 17use core::future::Future;
19use core::pin::Pin; 18use core::pin::Pin;
20use core::ptr::NonNull; 19use core::ptr::NonNull;
21use core::task::{Context, Poll}; 20use core::task::{Context, Poll};
22use core::{mem, ptr}; 21use core::{mem, ptr};
22
23use atomic_polyfill::{AtomicU32, Ordering};
23use critical_section::CriticalSection; 24use critical_section::CriticalSection;
24 25
25use self::run_queue::{RunQueue, RunQueueItem}; 26use self::run_queue::{RunQueue, RunQueueItem};
26use self::util::UninitCell; 27use self::util::UninitCell;
28pub use self::waker::task_from_waker;
27use super::SpawnToken; 29use super::SpawnToken;
28#[cfg(feature = "time")] 30#[cfg(feature = "time")]
29use crate::time::driver::{self, AlarmHandle}; 31use crate::time::driver::{self, AlarmHandle};
30#[cfg(feature = "time")] 32#[cfg(feature = "time")]
31use crate::time::Instant; 33use crate::time::Instant;
32 34
33pub use self::waker::task_from_waker;
34
35/// Task is spawned (has a future) 35/// Task is spawned (has a future)
36pub(crate) const STATE_SPAWNED: u32 = 1 << 0; 36pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
37/// Task is in the executor run queue 37/// Task is in the executor run queue
@@ -97,8 +97,7 @@ impl TaskHeader {
97 } 97 }
98 98
99 // Mark it as scheduled 99 // Mark it as scheduled
100 self.state 100 self.state.store(state | STATE_RUN_QUEUED, Ordering::Relaxed);
101 .store(state | STATE_RUN_QUEUED, Ordering::Relaxed);
102 101
103 // We have just marked the task as scheduled, so enqueue it. 102 // We have just marked the task as scheduled, so enqueue it.
104 let executor = &*self.executor.get(); 103 let executor = &*self.executor.get();
diff --git a/embassy/src/executor/raw/run_queue.rs b/embassy/src/executor/raw/run_queue.rs
index 7aa2079fa..31615da7e 100644
--- a/embassy/src/executor/raw/run_queue.rs
+++ b/embassy/src/executor/raw/run_queue.rs
@@ -1,6 +1,7 @@
1use atomic_polyfill::{AtomicPtr, Ordering};
2use core::ptr; 1use core::ptr;
3use core::ptr::NonNull; 2use core::ptr::NonNull;
3
4use atomic_polyfill::{AtomicPtr, Ordering};
4use critical_section::CriticalSection; 5use critical_section::CriticalSection;
5 6
6use super::TaskHeader; 7use super::TaskHeader;
@@ -63,10 +64,7 @@ impl RunQueue {
63 while let Some(task) = NonNull::new(ptr) { 64 while let Some(task) = NonNull::new(ptr) {
64 // If the task re-enqueues itself, the `next` pointer will get overwritten. 65 // If the task re-enqueues itself, the `next` pointer will get overwritten.
65 // Therefore, first read the next pointer, and only then process the task. 66 // Therefore, first read the next pointer, and only then process the task.
66 let next = unsafe { task.as_ref() } 67 let next = unsafe { task.as_ref() }.run_queue_item.next.load(Ordering::Relaxed);
67 .run_queue_item
68 .next
69 .load(Ordering::Relaxed);
70 68
71 on_task(task); 69 on_task(task);
72 70
diff --git a/embassy/src/executor/raw/timer_queue.rs b/embassy/src/executor/raw/timer_queue.rs
index e96910bb0..62fcfc531 100644
--- a/embassy/src/executor/raw/timer_queue.rs
+++ b/embassy/src/executor/raw/timer_queue.rs
@@ -1,9 +1,10 @@
1use atomic_polyfill::Ordering;
2use core::cell::Cell; 1use core::cell::Cell;
3use core::cmp::min; 2use core::cmp::min;
4use core::ptr; 3use core::ptr;
5use core::ptr::NonNull; 4use core::ptr::NonNull;
6 5
6use atomic_polyfill::Ordering;
7
7use super::{TaskHeader, STATE_TIMER_QUEUED}; 8use super::{TaskHeader, STATE_TIMER_QUEUED};
8use crate::time::Instant; 9use crate::time::Instant;
9 10
@@ -54,11 +55,7 @@ impl TimerQueue {
54 res 55 res
55 } 56 }
56 57
57 pub(crate) unsafe fn dequeue_expired( 58 pub(crate) unsafe fn dequeue_expired(&self, now: Instant, on_task: impl Fn(NonNull<TaskHeader>)) {
58 &self,
59 now: Instant,
60 on_task: impl Fn(NonNull<TaskHeader>),
61 ) {
62 self.retain(|p| { 59 self.retain(|p| {
63 let task = p.as_ref(); 60 let task = p.as_ref();
64 if task.expires_at.get() <= now { 61 if task.expires_at.get() <= now {
diff --git a/embassy/src/executor/spawner.rs b/embassy/src/executor/spawner.rs
index 73c1f786f..884db6b55 100644
--- a/embassy/src/executor/spawner.rs
+++ b/embassy/src/executor/spawner.rs
@@ -2,6 +2,7 @@ use core::marker::PhantomData;
2use core::mem; 2use core::mem;
3use core::ptr::NonNull; 3use core::ptr::NonNull;
4use core::task::Poll; 4use core::task::Poll;
5
5use futures::future::poll_fn; 6use futures::future::poll_fn;
6 7
7use super::raw; 8use super::raw;
diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs
index 5cfd18db7..1b6ff2d4b 100644
--- a/embassy/src/lib.rs
+++ b/embassy/src/lib.rs
@@ -1,8 +1,5 @@
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( 2#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))]
3 feature = "nightly",
4 feature(generic_associated_types, type_alias_impl_trait)
5)]
6#![allow(clippy::new_without_default)] 3#![allow(clippy::new_without_default)]
7 4
8// This mod MUST go first, so that the others see its macros. 5// This mod MUST go first, so that the others see its macros.
diff --git a/embassy/src/mutex.rs b/embassy/src/mutex.rs
index 27353bd4d..7b6bcb147 100644
--- a/embassy/src/mutex.rs
+++ b/embassy/src/mutex.rs
@@ -7,6 +7,7 @@
7use core::cell::{RefCell, UnsafeCell}; 7use core::cell::{RefCell, UnsafeCell};
8use core::ops::{Deref, DerefMut}; 8use core::ops::{Deref, DerefMut};
9use core::task::Poll; 9use core::task::Poll;
10
10use futures::future::poll_fn; 11use futures::future::poll_fn;
11 12
12use crate::blocking_mutex::raw::RawMutex; 13use crate::blocking_mutex::raw::RawMutex;
diff --git a/embassy/src/time/delay.rs b/embassy/src/time/delay.rs
index 06ed8ec4e..83a895e93 100644
--- a/embassy/src/time/delay.rs
+++ b/embassy/src/time/delay.rs
@@ -56,9 +56,10 @@ cfg_if::cfg_if! {
56} 56}
57 57
58mod eh02 { 58mod eh02 {
59 use super::*;
60 use embedded_hal_02::blocking::delay::{DelayMs, DelayUs}; 59 use embedded_hal_02::blocking::delay::{DelayMs, DelayUs};
61 60
61 use super::*;
62
62 impl DelayMs<u8> for Delay { 63 impl DelayMs<u8> for Delay {
63 fn delay_ms(&mut self, ms: u8) { 64 fn delay_ms(&mut self, ms: u8) {
64 block_for(Duration::from_millis(ms as u64)) 65 block_for(Duration::from_millis(ms as u64))
diff --git a/embassy/src/time/driver_std.rs b/embassy/src/time/driver_std.rs
index 0b5c6f85c..cb66f7c19 100644
--- a/embassy/src/time/driver_std.rs
+++ b/embassy/src/time/driver_std.rs
@@ -1,11 +1,10 @@
1use atomic_polyfill::{AtomicU8, Ordering};
2use std::cell::UnsafeCell; 1use std::cell::UnsafeCell;
3use std::mem;
4use std::mem::MaybeUninit; 2use std::mem::MaybeUninit;
5use std::sync::{Condvar, Mutex, Once}; 3use std::sync::{Condvar, Mutex, Once};
6use std::time::Duration as StdDuration; 4use std::time::{Duration as StdDuration, Instant as StdInstant};
7use std::time::Instant as StdInstant; 5use std::{mem, ptr, thread};
8use std::{ptr, thread}; 6
7use atomic_polyfill::{AtomicU8, Ordering};
9 8
10use crate::time::driver::{AlarmHandle, Driver}; 9use crate::time::driver::{AlarmHandle, Driver};
11 10
@@ -106,15 +105,13 @@ impl Driver for TimeDriver {
106 } 105 }
107 106
108 unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { 107 unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
109 let id = self 108 let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| {
110 .alarm_count 109 if x < ALARM_COUNT as u8 {
111 .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { 110 Some(x + 1)
112 if x < ALARM_COUNT as u8 { 111 } else {
113 Some(x + 1) 112 None
114 } else { 113 }
115 None 114 });
116 }
117 });
118 115
119 match id { 116 match id {
120 Ok(id) => Some(AlarmHandle::new(id)), 117 Ok(id) => Some(AlarmHandle::new(id)),
diff --git a/embassy/src/time/driver_wasm.rs b/embassy/src/time/driver_wasm.rs
index 0a9270823..5f585a19a 100644
--- a/embassy/src/time/driver_wasm.rs
+++ b/embassy/src/time/driver_wasm.rs
@@ -1,8 +1,9 @@
1use atomic_polyfill::{AtomicU8, Ordering};
2use std::cell::UnsafeCell; 1use std::cell::UnsafeCell;
3use std::mem::MaybeUninit; 2use std::mem::MaybeUninit;
4use std::ptr; 3use std::ptr;
5use std::sync::{Mutex, Once}; 4use std::sync::{Mutex, Once};
5
6use atomic_polyfill::{AtomicU8, Ordering};
6use wasm_bindgen::prelude::*; 7use wasm_bindgen::prelude::*;
7use wasm_timer::Instant as StdInstant; 8use wasm_timer::Instant as StdInstant;
8 9
@@ -66,15 +67,13 @@ impl Driver for TimeDriver {
66 } 67 }
67 68
68 unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { 69 unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
69 let id = self 70 let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| {
70 .alarm_count 71 if x < ALARM_COUNT as u8 {
71 .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { 72 Some(x + 1)
72 if x < ALARM_COUNT as u8 { 73 } else {
73 Some(x + 1) 74 None
74 } else { 75 }
75 None 76 });
76 }
77 });
78 77
79 match id { 78 match id {
80 Ok(id) => Some(AlarmHandle::new(id)), 79 Ok(id) => Some(AlarmHandle::new(id)),
diff --git a/embassy/src/time/duration.rs b/embassy/src/time/duration.rs
index 47b413f48..d35c2b65f 100644
--- a/embassy/src/time/duration.rs
+++ b/embassy/src/time/duration.rs
@@ -65,30 +65,22 @@ impl Duration {
65 65
66 /// Adds one Duration to another, returning a new Duration or None in the event of an overflow. 66 /// Adds one Duration to another, returning a new Duration or None in the event of an overflow.
67 pub fn checked_add(self, rhs: Duration) -> Option<Duration> { 67 pub fn checked_add(self, rhs: Duration) -> Option<Duration> {
68 self.ticks 68 self.ticks.checked_add(rhs.ticks).map(|ticks| Duration { ticks })
69 .checked_add(rhs.ticks)
70 .map(|ticks| Duration { ticks })
71 } 69 }
72 70
73 /// Subtracts one Duration to another, returning a new Duration or None in the event of an overflow. 71 /// Subtracts one Duration to another, returning a new Duration or None in the event of an overflow.
74 pub fn checked_sub(self, rhs: Duration) -> Option<Duration> { 72 pub fn checked_sub(self, rhs: Duration) -> Option<Duration> {
75 self.ticks 73 self.ticks.checked_sub(rhs.ticks).map(|ticks| Duration { ticks })
76 .checked_sub(rhs.ticks)
77 .map(|ticks| Duration { ticks })
78 } 74 }
79 75
80 /// Multiplies one Duration by a scalar u32, returning a new Duration or None in the event of an overflow. 76 /// Multiplies one Duration by a scalar u32, returning a new Duration or None in the event of an overflow.
81 pub fn checked_mul(self, rhs: u32) -> Option<Duration> { 77 pub fn checked_mul(self, rhs: u32) -> Option<Duration> {
82 self.ticks 78 self.ticks.checked_mul(rhs as _).map(|ticks| Duration { ticks })
83 .checked_mul(rhs as _)
84 .map(|ticks| Duration { ticks })
85 } 79 }
86 80
87 /// Divides one Duration a scalar u32, returning a new Duration or None in the event of an overflow. 81 /// Divides one Duration a scalar u32, returning a new Duration or None in the event of an overflow.
88 pub fn checked_div(self, rhs: u32) -> Option<Duration> { 82 pub fn checked_div(self, rhs: u32) -> Option<Duration> {
89 self.ticks 83 self.ticks.checked_div(rhs as _).map(|ticks| Duration { ticks })
90 .checked_div(rhs as _)
91 .map(|ticks| Duration { ticks })
92 } 84 }
93} 85}
94 86
@@ -96,8 +88,7 @@ impl Add for Duration {
96 type Output = Duration; 88 type Output = Duration;
97 89
98 fn add(self, rhs: Duration) -> Duration { 90 fn add(self, rhs: Duration) -> Duration {
99 self.checked_add(rhs) 91 self.checked_add(rhs).expect("overflow when adding durations")
100 .expect("overflow when adding durations")
101 } 92 }
102} 93}
103 94
@@ -111,8 +102,7 @@ impl Sub for Duration {
111 type Output = Duration; 102 type Output = Duration;
112 103
113 fn sub(self, rhs: Duration) -> Duration { 104 fn sub(self, rhs: Duration) -> Duration {
114 self.checked_sub(rhs) 105 self.checked_sub(rhs).expect("overflow when subtracting durations")
115 .expect("overflow when subtracting durations")
116 } 106 }
117} 107}
118 108
diff --git a/embassy/src/time/instant.rs b/embassy/src/time/instant.rs
index 71adbeb3f..6a4925f47 100644
--- a/embassy/src/time/instant.rs
+++ b/embassy/src/time/instant.rs
@@ -18,9 +18,7 @@ impl Instant {
18 18
19 /// Returns an Instant representing the current time. 19 /// Returns an Instant representing the current time.
20 pub fn now() -> Instant { 20 pub fn now() -> Instant {
21 Instant { 21 Instant { ticks: driver::now() }
22 ticks: driver::now(),
23 }
24 } 22 }
25 23
26 /// Create an Instant from a tick count since system boot. 24 /// Create an Instant from a tick count since system boot.
@@ -107,16 +105,12 @@ impl Instant {
107 105
108 /// Adds one Duration to self, returning a new `Instant` or None in the event of an overflow. 106 /// Adds one Duration to self, returning a new `Instant` or None in the event of an overflow.
109 pub fn checked_add(&self, duration: Duration) -> Option<Instant> { 107 pub fn checked_add(&self, duration: Duration) -> Option<Instant> {
110 self.ticks 108 self.ticks.checked_add(duration.ticks).map(|ticks| Instant { ticks })
111 .checked_add(duration.ticks)
112 .map(|ticks| Instant { ticks })
113 } 109 }
114 110
115 /// Subtracts one Duration to self, returning a new `Instant` or None in the event of an overflow. 111 /// Subtracts one Duration to self, returning a new `Instant` or None in the event of an overflow.
116 pub fn checked_sub(&self, duration: Duration) -> Option<Instant> { 112 pub fn checked_sub(&self, duration: Duration) -> Option<Instant> {
117 self.ticks 113 self.ticks.checked_sub(duration.ticks).map(|ticks| Instant { ticks })
118 .checked_sub(duration.ticks)
119 .map(|ticks| Instant { ticks })
120 } 114 }
121} 115}
122 116
diff --git a/embassy/src/time/timer.rs b/embassy/src/time/timer.rs
index 1b3832f37..2194a4b14 100644
--- a/embassy/src/time/timer.rs
+++ b/embassy/src/time/timer.rs
@@ -1,7 +1,9 @@
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};
4use futures::{future::select, future::Either, pin_mut, Stream}; 4
5use futures::future::{select, Either};
6use futures::{pin_mut, Stream};
5 7
6use crate::executor::raw; 8use crate::executor::raw;
7use crate::time::{Duration, Instant}; 9use crate::time::{Duration, Instant};
@@ -128,10 +130,7 @@ impl Ticker {
128 /// Creates a new ticker that ticks at the specified duration interval. 130 /// Creates a new ticker that ticks at the specified duration interval.
129 pub fn every(duration: Duration) -> Self { 131 pub fn every(duration: Duration) -> Self {
130 let expires_at = Instant::now() + duration; 132 let expires_at = Instant::now() + duration;
131 Self { 133 Self { expires_at, duration }
132 expires_at,
133 duration,
134 }
135 } 134 }
136} 135}
137 136
diff --git a/embassy/src/waitqueue/waker.rs b/embassy/src/waitqueue/waker.rs
index 9eddbdaa1..1ac6054f9 100644
--- a/embassy/src/waitqueue/waker.rs
+++ b/embassy/src/waitqueue/waker.rs
@@ -1,7 +1,8 @@
1use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering};
2use core::ptr::{self, NonNull}; 1use core::ptr::{self, NonNull};
3use core::task::Waker; 2use core::task::Waker;
4 3
4use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering};
5
5use crate::executor::raw::{task_from_waker, wake_task, TaskHeader}; 6use crate::executor::raw::{task_from_waker, wake_task, TaskHeader};
6 7
7/// Utility struct to register and wake a waker. 8/// Utility struct to register and wake a waker.
diff --git a/examples/boot/nrf/src/bin/a.rs b/examples/boot/nrf/src/bin/a.rs
index d45d0ff34..0b9715e49 100644
--- a/examples/boot/nrf/src/bin/a.rs
+++ b/examples/boot/nrf/src/bin/a.rs
@@ -6,12 +6,9 @@
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_nrf::{ 9use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
10 gpio::{Input, Pull}, 10use embassy_nrf::nvmc::Nvmc;
11 gpio::{Level, Output, OutputDrive}, 11use embassy_nrf::Peripherals;
12 nvmc::Nvmc,
13 Peripherals,
14};
15use panic_reset as _; 12use panic_reset as _;
16 13
17static APP_B: &[u8] = include_bytes!("../../b.bin"); 14static APP_B: &[u8] = include_bytes!("../../b.bin");
@@ -35,10 +32,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
35 for chunk in APP_B.chunks(4096) { 32 for chunk in APP_B.chunks(4096) {
36 let mut buf: [u8; 4096] = [0; 4096]; 33 let mut buf: [u8; 4096] = [0; 4096];
37 buf[..chunk.len()].copy_from_slice(chunk); 34 buf[..chunk.len()].copy_from_slice(chunk);
38 updater 35 updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap();
39 .write_firmware(offset, &buf, &mut nvmc, 4096)
40 .await
41 .unwrap();
42 offset += chunk.len(); 36 offset += chunk.len();
43 } 37 }
44 updater.update(&mut nvmc).await.unwrap(); 38 updater.update(&mut nvmc).await.unwrap();
diff --git a/examples/boot/nrf/src/bin/b.rs b/examples/boot/nrf/src/bin/b.rs
index 18bb6330c..a06c20f8b 100644
--- a/examples/boot/nrf/src/bin/b.rs
+++ b/examples/boot/nrf/src/bin/b.rs
@@ -5,11 +5,8 @@
5#![feature(type_alias_impl_trait)] 5#![feature(type_alias_impl_trait)]
6 6
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::{ 8use embassy_nrf::gpio::{Level, Output, OutputDrive};
9 gpio::{Level, Output, OutputDrive}, 9use embassy_nrf::Peripherals;
10 Peripherals,
11};
12
13use panic_reset as _; 10use panic_reset as _;
14 11
15#[embassy::main] 12#[embassy::main]
diff --git a/examples/boot/stm32f3/src/bin/a.rs b/examples/boot/stm32f3/src/bin/a.rs
index 9ad798389..4ff18d7c7 100644
--- a/examples/boot/stm32f3/src/bin/a.rs
+++ b/examples/boot/stm32f3/src/bin/a.rs
@@ -2,6 +2,8 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
6use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
7use embassy_stm32::exti::ExtiInput; 9use embassy_stm32::exti::ExtiInput;
@@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
10use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
11use panic_reset as _; 13use panic_reset as _;
12 14
13#[cfg(feature = "defmt-rtt")]
14use defmt_rtt::*;
15
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 15static APP_B: &[u8] = include_bytes!("../../b.bin");
17 16
18#[embassy::main] 17#[embassy::main]
@@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
32 for chunk in APP_B.chunks(2048) { 31 for chunk in APP_B.chunks(2048) {
33 let mut buf: [u8; 2048] = [0; 2048]; 32 let mut buf: [u8; 2048] = [0; 2048];
34 buf[..chunk.len()].copy_from_slice(chunk); 33 buf[..chunk.len()].copy_from_slice(chunk);
35 updater 34 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
36 .write_firmware(offset, &buf, &mut flash, 2048)
37 .await
38 .unwrap();
39 offset += chunk.len(); 35 offset += chunk.len();
40 } 36 }
41 updater.update(&mut flash).await.unwrap(); 37 updater.update(&mut flash).await.unwrap();
diff --git a/examples/boot/stm32f3/src/bin/b.rs b/examples/boot/stm32f3/src/bin/b.rs
index 814275988..4487e586e 100644
--- a/examples/boot/stm32f3/src/bin/b.rs
+++ b/examples/boot/stm32f3/src/bin/b.rs
@@ -2,15 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy::executor::Spawner; 7use embassy::executor::Spawner;
6use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
7use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
8use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
9use panic_reset as _; 11use panic_reset as _;
10 12
11#[cfg(feature = "defmt-rtt")]
12use defmt_rtt::*;
13
14#[embassy::main] 13#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
16 let mut led = Output::new(p.PA5, Level::High, Speed::Low); 15 let mut led = Output::new(p.PA5, Level::High, Speed::Low);
diff --git a/examples/boot/stm32f7/src/bin/a.rs b/examples/boot/stm32f7/src/bin/a.rs
index b4f49d579..9c7921a1a 100644
--- a/examples/boot/stm32f7/src/bin/a.rs
+++ b/examples/boot/stm32f7/src/bin/a.rs
@@ -2,6 +2,8 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
6use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
7use embassy_stm32::exti::ExtiInput; 9use embassy_stm32::exti::ExtiInput;
@@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
10use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
11use panic_reset as _; 13use panic_reset as _;
12 14
13#[cfg(feature = "defmt-rtt")]
14use defmt_rtt::*;
15
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 15static APP_B: &[u8] = include_bytes!("../../b.bin");
17 16
18#[embassy::main] 17#[embassy::main]
@@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
32 let mut buf: [u8; 256 * 1024] = [0; 256 * 1024]; 31 let mut buf: [u8; 256 * 1024] = [0; 256 * 1024];
33 for chunk in APP_B.chunks(256 * 1024) { 32 for chunk in APP_B.chunks(256 * 1024) {
34 buf[..chunk.len()].copy_from_slice(chunk); 33 buf[..chunk.len()].copy_from_slice(chunk);
35 updater 34 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
36 .write_firmware(offset, &buf, &mut flash, 2048)
37 .await
38 .unwrap();
39 offset += chunk.len(); 35 offset += chunk.len();
40 } 36 }
41 updater.update(&mut flash).await.unwrap(); 37 updater.update(&mut flash).await.unwrap();
diff --git a/examples/boot/stm32f7/src/bin/b.rs b/examples/boot/stm32f7/src/bin/b.rs
index ed37137f5..aa05bbcdd 100644
--- a/examples/boot/stm32f7/src/bin/b.rs
+++ b/examples/boot/stm32f7/src/bin/b.rs
@@ -2,15 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy::executor::Spawner; 7use embassy::executor::Spawner;
6use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
7use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
8use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
9use panic_reset as _; 11use panic_reset as _;
10 12
11#[cfg(feature = "defmt-rtt")]
12use defmt_rtt::*;
13
14#[embassy::main] 13#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
16 Timer::after(Duration::from_millis(300)).await; 15 Timer::after(Duration::from_millis(300)).await;
diff --git a/examples/boot/stm32h7/src/bin/a.rs b/examples/boot/stm32h7/src/bin/a.rs
index 1d196e8a5..704979dba 100644
--- a/examples/boot/stm32h7/src/bin/a.rs
+++ b/examples/boot/stm32h7/src/bin/a.rs
@@ -2,6 +2,8 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
6use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
7use embassy_stm32::exti::ExtiInput; 9use embassy_stm32::exti::ExtiInput;
@@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
10use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
11use panic_reset as _; 13use panic_reset as _;
12 14
13#[cfg(feature = "defmt-rtt")]
14use defmt_rtt::*;
15
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 15static APP_B: &[u8] = include_bytes!("../../b.bin");
17 16
18#[embassy::main] 17#[embassy::main]
@@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
32 let mut buf: [u8; 128 * 1024] = [0; 128 * 1024]; 31 let mut buf: [u8; 128 * 1024] = [0; 128 * 1024];
33 for chunk in APP_B.chunks(128 * 1024) { 32 for chunk in APP_B.chunks(128 * 1024) {
34 buf[..chunk.len()].copy_from_slice(chunk); 33 buf[..chunk.len()].copy_from_slice(chunk);
35 updater 34 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
36 .write_firmware(offset, &buf, &mut flash, 2048)
37 .await
38 .unwrap();
39 offset += chunk.len(); 35 offset += chunk.len();
40 } 36 }
41 updater.update(&mut flash).await.unwrap(); 37 updater.update(&mut flash).await.unwrap();
diff --git a/examples/boot/stm32h7/src/bin/b.rs b/examples/boot/stm32h7/src/bin/b.rs
index 233b93e1a..ea0140253 100644
--- a/examples/boot/stm32h7/src/bin/b.rs
+++ b/examples/boot/stm32h7/src/bin/b.rs
@@ -2,15 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy::executor::Spawner; 7use embassy::executor::Spawner;
6use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
7use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
8use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
9use panic_reset as _; 11use panic_reset as _;
10 12
11#[cfg(feature = "defmt-rtt")]
12use defmt_rtt::*;
13
14#[embassy::main] 13#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
16 Timer::after(Duration::from_millis(300)).await; 15 Timer::after(Duration::from_millis(300)).await;
diff --git a/examples/boot/stm32l0/src/bin/a.rs b/examples/boot/stm32l0/src/bin/a.rs
index d4b252bf0..ce620347b 100644
--- a/examples/boot/stm32l0/src/bin/a.rs
+++ b/examples/boot/stm32l0/src/bin/a.rs
@@ -2,6 +2,8 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
6use embassy_boot_stm32::FirmwareUpdater; 8use embassy_boot_stm32::FirmwareUpdater;
7use embassy_embedded_hal::adapter::BlockingAsync; 9use embassy_embedded_hal::adapter::BlockingAsync;
@@ -11,9 +13,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
11use embassy_stm32::Peripherals; 13use embassy_stm32::Peripherals;
12use panic_reset as _; 14use panic_reset as _;
13 15
14#[cfg(feature = "defmt-rtt")]
15use defmt_rtt::*;
16
17static APP_B: &[u8] = include_bytes!("../../b.bin"); 16static APP_B: &[u8] = include_bytes!("../../b.bin");
18 17
19#[embassy::main] 18#[embassy::main]
@@ -34,10 +33,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
34 for chunk in APP_B.chunks(128) { 33 for chunk in APP_B.chunks(128) {
35 let mut buf: [u8; 128] = [0; 128]; 34 let mut buf: [u8; 128] = [0; 128];
36 buf[..chunk.len()].copy_from_slice(chunk); 35 buf[..chunk.len()].copy_from_slice(chunk);
37 updater 36 updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap();
38 .write_firmware(offset, &buf, &mut flash, 128)
39 .await
40 .unwrap();
41 offset += chunk.len(); 37 offset += chunk.len();
42 } 38 }
43 39
diff --git a/examples/boot/stm32l0/src/bin/b.rs b/examples/boot/stm32l0/src/bin/b.rs
index ed774fd70..0b585a14c 100644
--- a/examples/boot/stm32l0/src/bin/b.rs
+++ b/examples/boot/stm32l0/src/bin/b.rs
@@ -2,15 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy::executor::Spawner; 7use embassy::executor::Spawner;
6use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
7use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
8use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
9use panic_reset as _; 11use panic_reset as _;
10 12
11#[cfg(feature = "defmt-rtt")]
12use defmt_rtt::*;
13
14#[embassy::main] 13#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
16 let mut led = Output::new(p.PB6, Level::High, Speed::Low); 15 let mut led = Output::new(p.PB6, Level::High, Speed::Low);
diff --git a/examples/boot/stm32l1/src/bin/a.rs b/examples/boot/stm32l1/src/bin/a.rs
index d4b252bf0..ce620347b 100644
--- a/examples/boot/stm32l1/src/bin/a.rs
+++ b/examples/boot/stm32l1/src/bin/a.rs
@@ -2,6 +2,8 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
6use embassy_boot_stm32::FirmwareUpdater; 8use embassy_boot_stm32::FirmwareUpdater;
7use embassy_embedded_hal::adapter::BlockingAsync; 9use embassy_embedded_hal::adapter::BlockingAsync;
@@ -11,9 +13,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
11use embassy_stm32::Peripherals; 13use embassy_stm32::Peripherals;
12use panic_reset as _; 14use panic_reset as _;
13 15
14#[cfg(feature = "defmt-rtt")]
15use defmt_rtt::*;
16
17static APP_B: &[u8] = include_bytes!("../../b.bin"); 16static APP_B: &[u8] = include_bytes!("../../b.bin");
18 17
19#[embassy::main] 18#[embassy::main]
@@ -34,10 +33,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
34 for chunk in APP_B.chunks(128) { 33 for chunk in APP_B.chunks(128) {
35 let mut buf: [u8; 128] = [0; 128]; 34 let mut buf: [u8; 128] = [0; 128];
36 buf[..chunk.len()].copy_from_slice(chunk); 35 buf[..chunk.len()].copy_from_slice(chunk);
37 updater 36 updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap();
38 .write_firmware(offset, &buf, &mut flash, 128)
39 .await
40 .unwrap();
41 offset += chunk.len(); 37 offset += chunk.len();
42 } 38 }
43 39
diff --git a/examples/boot/stm32l1/src/bin/b.rs b/examples/boot/stm32l1/src/bin/b.rs
index ed774fd70..0b585a14c 100644
--- a/examples/boot/stm32l1/src/bin/b.rs
+++ b/examples/boot/stm32l1/src/bin/b.rs
@@ -2,15 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy::executor::Spawner; 7use embassy::executor::Spawner;
6use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
7use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
8use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
9use panic_reset as _; 11use panic_reset as _;
10 12
11#[cfg(feature = "defmt-rtt")]
12use defmt_rtt::*;
13
14#[embassy::main] 13#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
16 let mut led = Output::new(p.PB6, Level::High, Speed::Low); 15 let mut led = Output::new(p.PB6, Level::High, Speed::Low);
diff --git a/examples/boot/stm32l4/src/bin/a.rs b/examples/boot/stm32l4/src/bin/a.rs
index 23b1d98bb..bf6099355 100644
--- a/examples/boot/stm32l4/src/bin/a.rs
+++ b/examples/boot/stm32l4/src/bin/a.rs
@@ -2,6 +2,8 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
6use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
7use embassy_stm32::exti::ExtiInput; 9use embassy_stm32::exti::ExtiInput;
@@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
10use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
11use panic_reset as _; 13use panic_reset as _;
12 14
13#[cfg(feature = "defmt-rtt")]
14use defmt_rtt::*;
15
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 15static APP_B: &[u8] = include_bytes!("../../b.bin");
17 16
18#[embassy::main] 17#[embassy::main]
@@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
32 for chunk in APP_B.chunks(2048) { 31 for chunk in APP_B.chunks(2048) {
33 let mut buf: [u8; 2048] = [0; 2048]; 32 let mut buf: [u8; 2048] = [0; 2048];
34 buf[..chunk.len()].copy_from_slice(chunk); 33 buf[..chunk.len()].copy_from_slice(chunk);
35 updater 34 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
36 .write_firmware(offset, &buf, &mut flash, 2048)
37 .await
38 .unwrap();
39 offset += chunk.len(); 35 offset += chunk.len();
40 } 36 }
41 updater.update(&mut flash).await.unwrap(); 37 updater.update(&mut flash).await.unwrap();
diff --git a/examples/boot/stm32l4/src/bin/b.rs b/examples/boot/stm32l4/src/bin/b.rs
index 814275988..4487e586e 100644
--- a/examples/boot/stm32l4/src/bin/b.rs
+++ b/examples/boot/stm32l4/src/bin/b.rs
@@ -2,15 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy::executor::Spawner; 7use embassy::executor::Spawner;
6use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
7use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
8use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
9use panic_reset as _; 11use panic_reset as _;
10 12
11#[cfg(feature = "defmt-rtt")]
12use defmt_rtt::*;
13
14#[embassy::main] 13#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
16 let mut led = Output::new(p.PA5, Level::High, Speed::Low); 15 let mut led = Output::new(p.PA5, Level::High, Speed::Low);
diff --git a/examples/boot/stm32wl/src/bin/a.rs b/examples/boot/stm32wl/src/bin/a.rs
index 1089eff1e..dc1eb9bed 100644
--- a/examples/boot/stm32wl/src/bin/a.rs
+++ b/examples/boot/stm32wl/src/bin/a.rs
@@ -2,6 +2,8 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::FirmwareUpdater;
6use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
7use embassy_stm32::exti::ExtiInput; 9use embassy_stm32::exti::ExtiInput;
@@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
10use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
11use panic_reset as _; 13use panic_reset as _;
12 14
13#[cfg(feature = "defmt-rtt")]
14use defmt_rtt::*;
15
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 15static APP_B: &[u8] = include_bytes!("../../b.bin");
17 16
18#[embassy::main] 17#[embassy::main]
@@ -34,10 +33,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
34 let mut buf: [u8; 2048] = [0; 2048]; 33 let mut buf: [u8; 2048] = [0; 2048];
35 buf[..chunk.len()].copy_from_slice(chunk); 34 buf[..chunk.len()].copy_from_slice(chunk);
36 // defmt::info!("Writing chunk at 0x{:x}", offset); 35 // defmt::info!("Writing chunk at 0x{:x}", offset);
37 updater 36 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
38 .write_firmware(offset, &buf, &mut flash, 2048)
39 .await
40 .unwrap();
41 offset += chunk.len(); 37 offset += chunk.len();
42 } 38 }
43 updater.update(&mut flash).await.unwrap(); 39 updater.update(&mut flash).await.unwrap();
diff --git a/examples/boot/stm32wl/src/bin/b.rs b/examples/boot/stm32wl/src/bin/b.rs
index ffe15b661..f2344bd53 100644
--- a/examples/boot/stm32wl/src/bin/b.rs
+++ b/examples/boot/stm32wl/src/bin/b.rs
@@ -2,15 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
5use embassy::executor::Spawner; 7use embassy::executor::Spawner;
6use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
7use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
8use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
9use panic_reset as _; 11use panic_reset as _;
10 12
11#[cfg(feature = "defmt-rtt")]
12use defmt_rtt::*;
13
14#[embassy::main] 13#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
16 let mut led = Output::new(p.PB15, Level::High, Speed::Low); 15 let mut led = Output::new(p.PB15, Level::High, Speed::Low);
diff --git a/examples/nrf/src/bin/awaitable_timer.rs b/examples/nrf/src/bin/awaitable_timer.rs
index 810b4bd6a..34a657cb9 100644
--- a/examples/nrf/src/bin/awaitable_timer.rs
+++ b/examples/nrf/src/bin/awaitable_timer.rs
@@ -4,12 +4,9 @@
4 4
5use defmt::info; 5use defmt::info;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_nrf::interrupt;
8use embassy_nrf::timer::Timer; 7use embassy_nrf::timer::Timer;
9use embassy_nrf::Peripherals; 8use embassy_nrf::{interrupt, Peripherals};
10 9use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 10
14#[embassy::main] 11#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/blinky.rs b/examples/nrf/src/bin/blinky.rs
index 4828b08fb..23d16f796 100644
--- a/examples/nrf/src/bin/blinky.rs
+++ b/examples/nrf/src/bin/blinky.rs
@@ -6,9 +6,7 @@ use embassy::executor::Spawner;
6use embassy::time::{Duration, Timer}; 6use embassy::time::{Duration, Timer};
7use embassy_nrf::gpio::{Level, Output, OutputDrive}; 7use embassy_nrf::gpio::{Level, Output, OutputDrive};
8use embassy_nrf::Peripherals; 8use embassy_nrf::Peripherals;
9 9use {defmt_rtt as _, panic_probe as _};
10use defmt_rtt as _; // global logger
11use panic_probe as _;
12 10
13#[embassy::main] 11#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/buffered_uart.rs b/examples/nrf/src/bin/buffered_uart.rs
index 782c39499..18dd698bf 100644
--- a/examples/nrf/src/bin/buffered_uart.rs
+++ b/examples/nrf/src/bin/buffered_uart.rs
@@ -4,13 +4,11 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_nrf::buffered_uarte::State; 7use embassy_nrf::buffered_uarte::{BufferedUarte, State};
8use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals}; 8use embassy_nrf::{interrupt, uarte, Peripherals};
9use embedded_io::asynch::{BufRead, Write}; 9use embedded_io::asynch::{BufRead, Write};
10use futures::pin_mut; 10use futures::pin_mut;
11 11use {defmt_rtt as _, panic_probe as _};
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 12
15#[embassy::main] 13#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/channel.rs b/examples/nrf/src/bin/channel.rs
index 12b463581..c57b91a42 100644
--- a/examples/nrf/src/bin/channel.rs
+++ b/examples/nrf/src/bin/channel.rs
@@ -9,9 +9,7 @@ use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
10use embassy_nrf::gpio::{Level, Output, OutputDrive}; 10use embassy_nrf::gpio::{Level, Output, OutputDrive};
11use embassy_nrf::Peripherals; 11use embassy_nrf::Peripherals;
12 12use {defmt_rtt as _, panic_probe as _};
13use defmt_rtt as _; // global logger
14use panic_probe as _;
15 13
16enum LedState { 14enum LedState {
17 On, 15 On,
diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf/src/bin/channel_sender_receiver.rs
index 1742dcc9e..847ce2382 100644
--- a/examples/nrf/src/bin/channel_sender_receiver.rs
+++ b/examples/nrf/src/bin/channel_sender_receiver.rs
@@ -10,9 +10,7 @@ use embassy::time::{Duration, Timer};
10use embassy::util::Forever; 10use embassy::util::Forever;
11use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; 11use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin};
12use embassy_nrf::Peripherals; 12use embassy_nrf::Peripherals;
13 13use {defmt_rtt as _, panic_probe as _};
14use defmt_rtt as _; // global logger
15use panic_probe as _;
16 14
17enum LedState { 15enum LedState {
18 On, 16 On,
diff --git a/examples/nrf/src/bin/executor_fairness_test.rs b/examples/nrf/src/bin/executor_fairness_test.rs
index 7a356d14b..5a4221519 100644
--- a/examples/nrf/src/bin/executor_fairness_test.rs
+++ b/examples/nrf/src/bin/executor_fairness_test.rs
@@ -3,13 +3,12 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::task::Poll; 5use core::task::Poll;
6
6use defmt::{info, unwrap}; 7use defmt::{info, unwrap};
7use embassy::executor::Spawner; 8use embassy::executor::Spawner;
8use embassy::time::{Duration, Instant, Timer}; 9use embassy::time::{Duration, Instant, Timer};
9use embassy_nrf::Peripherals; 10use embassy_nrf::Peripherals;
10 11use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 12
14#[embassy::task] 13#[embassy::task]
15async fn run1() { 14async fn run1() {
diff --git a/examples/nrf/src/bin/gpiote_channel.rs b/examples/nrf/src/bin/gpiote_channel.rs
index 339f779f8..ad8f37c6e 100644
--- a/examples/nrf/src/bin/gpiote_channel.rs
+++ b/examples/nrf/src/bin/gpiote_channel.rs
@@ -7,9 +7,7 @@ use 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; 9use embassy_nrf::Peripherals;
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/gpiote_port.rs b/examples/nrf/src/bin/gpiote_port.rs
index dc6bd301f..30b87b3a7 100644
--- a/examples/nrf/src/bin/gpiote_port.rs
+++ b/examples/nrf/src/bin/gpiote_port.rs
@@ -6,9 +6,7 @@ use defmt::{info, unwrap};
6use embassy::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; 8use embassy_nrf::Peripherals;
9 9use {defmt_rtt as _, panic_probe as _};
10use defmt_rtt as _; // global logger
11use panic_probe as _;
12 10
13#[embassy::task(pool_size = 4)] 11#[embassy::task(pool_size = 4)]
14async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) { 12async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) {
diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs
index abda18aa5..1a4598e21 100644
--- a/examples/nrf/src/bin/multiprio.rs
+++ b/examples/nrf/src/bin/multiprio.rs
@@ -64,9 +64,7 @@ use embassy::util::Forever;
64use embassy_nrf::executor::{Executor, InterruptExecutor}; 64use embassy_nrf::executor::{Executor, InterruptExecutor};
65use embassy_nrf::interrupt; 65use embassy_nrf::interrupt;
66use embassy_nrf::interrupt::InterruptExt; 66use embassy_nrf::interrupt::InterruptExt;
67 67use {defmt_rtt as _, panic_probe as _};
68use defmt_rtt as _; // global logger
69use panic_probe as _;
70 68
71#[embassy::task] 69#[embassy::task]
72async fn run_high() { 70async fn run_high() {
diff --git a/examples/nrf/src/bin/mutex.rs b/examples/nrf/src/bin/mutex.rs
index db1b72f6d..92e01976c 100644
--- a/examples/nrf/src/bin/mutex.rs
+++ b/examples/nrf/src/bin/mutex.rs
@@ -8,9 +8,7 @@ use embassy::executor::Spawner;
8use embassy::mutex::Mutex; 8use embassy::mutex::Mutex;
9use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
10use embassy_nrf::Peripherals; 10use embassy_nrf::Peripherals;
11 11use {defmt_rtt as _, panic_probe as _};
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 12
15static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0); 13static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0);
16 14
diff --git a/examples/nrf/src/bin/nvmc.rs b/examples/nrf/src/bin/nvmc.rs
index 7a57399f8..b55ef1f6c 100644
--- a/examples/nrf/src/bin/nvmc.rs
+++ b/examples/nrf/src/bin/nvmc.rs
@@ -8,9 +8,7 @@ use embassy::time::{Duration, Timer};
8use embassy_nrf::nvmc::Nvmc; 8use embassy_nrf::nvmc::Nvmc;
9use embassy_nrf::Peripherals; 9use embassy_nrf::Peripherals;
10use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 10use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
11 11use {defmt_rtt as _, panic_probe as _};
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 12
15#[embassy::main] 13#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/ppi.rs b/examples/nrf/src/bin/ppi.rs
index 3c9a8148a..004a1bfa4 100644
--- a/examples/nrf/src/bin/ppi.rs
+++ b/examples/nrf/src/bin/ppi.rs
@@ -3,6 +3,7 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::future::pending; 5use core::future::pending;
6
6use defmt::info; 7use defmt::info;
7use embassy::executor::Spawner; 8use embassy::executor::Spawner;
8use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; 9use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
@@ -10,9 +11,7 @@ use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity};
10use embassy_nrf::ppi::Ppi; 11use embassy_nrf::ppi::Ppi;
11use embassy_nrf::Peripherals; 12use embassy_nrf::Peripherals;
12use gpiote::{OutputChannel, OutputChannelPolarity}; 13use gpiote::{OutputChannel, OutputChannelPolarity};
13 14use {defmt_rtt as _, panic_probe as _};
14use defmt_rtt as _; // global logger
15use panic_probe as _;
16 15
17#[embassy::main] 16#[embassy::main]
18async fn main(_spawner: Spawner, p: Peripherals) { 17async fn main(_spawner: Spawner, p: Peripherals) {
@@ -60,12 +59,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
60 let mut ppi = Ppi::new_one_to_one(p.PPI_CH2, button3.event_in(), led1.task_set()); 59 let mut ppi = Ppi::new_one_to_one(p.PPI_CH2, button3.event_in(), led1.task_set());
61 ppi.enable(); 60 ppi.enable();
62 61
63 let mut ppi = Ppi::new_one_to_two( 62 let mut ppi = Ppi::new_one_to_two(p.PPI_CH3, button4.event_in(), led1.task_out(), led2.task_out());
64 p.PPI_CH3,
65 button4.event_in(),
66 led1.task_out(),
67 led2.task_out(),
68 );
69 ppi.enable(); 63 ppi.enable();
70 64
71 info!("PPI setup!"); 65 info!("PPI setup!");
diff --git a/examples/nrf/src/bin/pwm.rs b/examples/nrf/src/bin/pwm.rs
index 7939e79e4..aec5dd73a 100644
--- a/examples/nrf/src/bin/pwm.rs
+++ b/examples/nrf/src/bin/pwm.rs
@@ -7,81 +7,67 @@ use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::pwm::{Prescaler, SimplePwm}; 8use embassy_nrf::pwm::{Prescaler, SimplePwm};
9use embassy_nrf::Peripherals; 9use embassy_nrf::Peripherals;
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14// for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='') 12// for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='')
15static DUTY: [u16; 1024] = [ 13static DUTY: [u16; 1024] = [
16 8191, 8272, 8353, 8434, 8516, 8598, 8681, 8764, 8847, 8931, 9015, 9099, 9184, 9269, 9354, 9440, 14 8191, 8272, 8353, 8434, 8516, 8598, 8681, 8764, 8847, 8931, 9015, 9099, 9184, 9269, 9354, 9440, 9526, 9613, 9700,
17 9526, 9613, 9700, 9787, 9874, 9962, 10050, 10139, 10227, 10316, 10406, 10495, 10585, 10675, 15 9787, 9874, 9962, 10050, 10139, 10227, 10316, 10406, 10495, 10585, 10675, 10766, 10857, 10948, 11039, 11131, 11223,
18 10766, 10857, 10948, 11039, 11131, 11223, 11315, 11407, 11500, 11592, 11685, 11779, 11872, 16 11315, 11407, 11500, 11592, 11685, 11779, 11872, 11966, 12060, 12154, 12248, 12343, 12438, 12533, 12628, 12723,
19 11966, 12060, 12154, 12248, 12343, 12438, 12533, 12628, 12723, 12818, 12914, 13010, 13106, 17 12818, 12914, 13010, 13106, 13202, 13298, 13394, 13491, 13587, 13684, 13781, 13878, 13975, 14072, 14169, 14266,
20 13202, 13298, 13394, 13491, 13587, 13684, 13781, 13878, 13975, 14072, 14169, 14266, 14364, 18 14364, 14461, 14558, 14656, 14754, 14851, 14949, 15046, 15144, 15242, 15339, 15437, 15535, 15632, 15730, 15828,
21 14461, 14558, 14656, 14754, 14851, 14949, 15046, 15144, 15242, 15339, 15437, 15535, 15632, 19 15925, 16023, 16120, 16218, 16315, 16412, 16510, 16607, 16704, 16801, 16898, 16995, 17091, 17188, 17284, 17380,
22 15730, 15828, 15925, 16023, 16120, 16218, 16315, 16412, 16510, 16607, 16704, 16801, 16898, 20 17477, 17572, 17668, 17764, 17859, 17955, 18050, 18145, 18239, 18334, 18428, 18522, 18616, 18710, 18803, 18896,
23 16995, 17091, 17188, 17284, 17380, 17477, 17572, 17668, 17764, 17859, 17955, 18050, 18145, 21 18989, 19082, 19174, 19266, 19358, 19449, 19540, 19631, 19722, 19812, 19902, 19991, 20081, 20169, 20258, 20346,
24 18239, 18334, 18428, 18522, 18616, 18710, 18803, 18896, 18989, 19082, 19174, 19266, 19358, 22 20434, 20521, 20608, 20695, 20781, 20867, 20952, 21037, 21122, 21206, 21290, 21373, 21456, 21538, 21620, 21701,
25 19449, 19540, 19631, 19722, 19812, 19902, 19991, 20081, 20169, 20258, 20346, 20434, 20521, 23 21782, 21863, 21943, 22022, 22101, 22179, 22257, 22335, 22412, 22488, 22564, 22639, 22714, 22788, 22861, 22934,
26 20608, 20695, 20781, 20867, 20952, 21037, 21122, 21206, 21290, 21373, 21456, 21538, 21620, 24 23007, 23079, 23150, 23220, 23290, 23360, 23429, 23497, 23564, 23631, 23698, 23763, 23828, 23892, 23956, 24019,
27 21701, 21782, 21863, 21943, 22022, 22101, 22179, 22257, 22335, 22412, 22488, 22564, 22639, 25 24081, 24143, 24204, 24264, 24324, 24383, 24441, 24499, 24555, 24611, 24667, 24721, 24775, 24828, 24881, 24933,
28 22714, 22788, 22861, 22934, 23007, 23079, 23150, 23220, 23290, 23360, 23429, 23497, 23564, 26 24983, 25034, 25083, 25132, 25180, 25227, 25273, 25319, 25363, 25407, 25451, 25493, 25535, 25575, 25615, 25655,
29 23631, 23698, 23763, 23828, 23892, 23956, 24019, 24081, 24143, 24204, 24264, 24324, 24383, 27 25693, 25731, 25767, 25803, 25838, 25873, 25906, 25939, 25971, 26002, 26032, 26061, 26089, 26117, 26144, 26170,
30 24441, 24499, 24555, 24611, 24667, 24721, 24775, 24828, 24881, 24933, 24983, 25034, 25083, 28 26195, 26219, 26242, 26264, 26286, 26307, 26327, 26346, 26364, 26381, 26397, 26413, 26427, 26441, 26454, 26466,
31 25132, 25180, 25227, 25273, 25319, 25363, 25407, 25451, 25493, 25535, 25575, 25615, 25655, 29 26477, 26487, 26496, 26505, 26512, 26519, 26525, 26530, 26534, 26537, 26539, 26540, 26541, 26540, 26539, 26537,
32 25693, 25731, 25767, 25803, 25838, 25873, 25906, 25939, 25971, 26002, 26032, 26061, 26089, 30 26534, 26530, 26525, 26519, 26512, 26505, 26496, 26487, 26477, 26466, 26454, 26441, 26427, 26413, 26397, 26381,
33 26117, 26144, 26170, 26195, 26219, 26242, 26264, 26286, 26307, 26327, 26346, 26364, 26381, 31 26364, 26346, 26327, 26307, 26286, 26264, 26242, 26219, 26195, 26170, 26144, 26117, 26089, 26061, 26032, 26002,
34 26397, 26413, 26427, 26441, 26454, 26466, 26477, 26487, 26496, 26505, 26512, 26519, 26525, 32 25971, 25939, 25906, 25873, 25838, 25803, 25767, 25731, 25693, 25655, 25615, 25575, 25535, 25493, 25451, 25407,
35 26530, 26534, 26537, 26539, 26540, 26541, 26540, 26539, 26537, 26534, 26530, 26525, 26519, 33 25363, 25319, 25273, 25227, 25180, 25132, 25083, 25034, 24983, 24933, 24881, 24828, 24775, 24721, 24667, 24611,
36 26512, 26505, 26496, 26487, 26477, 26466, 26454, 26441, 26427, 26413, 26397, 26381, 26364, 34 24555, 24499, 24441, 24383, 24324, 24264, 24204, 24143, 24081, 24019, 23956, 23892, 23828, 23763, 23698, 23631,
37 26346, 26327, 26307, 26286, 26264, 26242, 26219, 26195, 26170, 26144, 26117, 26089, 26061, 35 23564, 23497, 23429, 23360, 23290, 23220, 23150, 23079, 23007, 22934, 22861, 22788, 22714, 22639, 22564, 22488,
38 26032, 26002, 25971, 25939, 25906, 25873, 25838, 25803, 25767, 25731, 25693, 25655, 25615, 36 22412, 22335, 22257, 22179, 22101, 22022, 21943, 21863, 21782, 21701, 21620, 21538, 21456, 21373, 21290, 21206,
39 25575, 25535, 25493, 25451, 25407, 25363, 25319, 25273, 25227, 25180, 25132, 25083, 25034, 37 21122, 21037, 20952, 20867, 20781, 20695, 20608, 20521, 20434, 20346, 20258, 20169, 20081, 19991, 19902, 19812,
40 24983, 24933, 24881, 24828, 24775, 24721, 24667, 24611, 24555, 24499, 24441, 24383, 24324, 38 19722, 19631, 19540, 19449, 19358, 19266, 19174, 19082, 18989, 18896, 18803, 18710, 18616, 18522, 18428, 18334,
41 24264, 24204, 24143, 24081, 24019, 23956, 23892, 23828, 23763, 23698, 23631, 23564, 23497, 39 18239, 18145, 18050, 17955, 17859, 17764, 17668, 17572, 17477, 17380, 17284, 17188, 17091, 16995, 16898, 16801,
42 23429, 23360, 23290, 23220, 23150, 23079, 23007, 22934, 22861, 22788, 22714, 22639, 22564, 40 16704, 16607, 16510, 16412, 16315, 16218, 16120, 16023, 15925, 15828, 15730, 15632, 15535, 15437, 15339, 15242,
43 22488, 22412, 22335, 22257, 22179, 22101, 22022, 21943, 21863, 21782, 21701, 21620, 21538, 41 15144, 15046, 14949, 14851, 14754, 14656, 14558, 14461, 14364, 14266, 14169, 14072, 13975, 13878, 13781, 13684,
44 21456, 21373, 21290, 21206, 21122, 21037, 20952, 20867, 20781, 20695, 20608, 20521, 20434, 42 13587, 13491, 13394, 13298, 13202, 13106, 13010, 12914, 12818, 12723, 12628, 12533, 12438, 12343, 12248, 12154,
45 20346, 20258, 20169, 20081, 19991, 19902, 19812, 19722, 19631, 19540, 19449, 19358, 19266, 43 12060, 11966, 11872, 11779, 11685, 11592, 11500, 11407, 11315, 11223, 11131, 11039, 10948, 10857, 10766, 10675,
46 19174, 19082, 18989, 18896, 18803, 18710, 18616, 18522, 18428, 18334, 18239, 18145, 18050, 44 10585, 10495, 10406, 10316, 10227, 10139, 10050, 9962, 9874, 9787, 9700, 9613, 9526, 9440, 9354, 9269, 9184, 9099,
47 17955, 17859, 17764, 17668, 17572, 17477, 17380, 17284, 17188, 17091, 16995, 16898, 16801, 45 9015, 8931, 8847, 8764, 8681, 8598, 8516, 8434, 8353, 8272, 8191, 8111, 8031, 7952, 7873, 7794, 7716, 7638, 7561,
48 16704, 16607, 16510, 16412, 16315, 16218, 16120, 16023, 15925, 15828, 15730, 15632, 15535, 46 7484, 7407, 7331, 7255, 7180, 7105, 7031, 6957, 6883, 6810, 6738, 6665, 6594, 6522, 6451, 6381, 6311, 6241, 6172,
49 15437, 15339, 15242, 15144, 15046, 14949, 14851, 14754, 14656, 14558, 14461, 14364, 14266, 47 6104, 6036, 5968, 5901, 5834, 5767, 5702, 5636, 5571, 5507, 5443, 5379, 5316, 5253, 5191, 5130, 5068, 5008, 4947,
50 14169, 14072, 13975, 13878, 13781, 13684, 13587, 13491, 13394, 13298, 13202, 13106, 13010, 48 4888, 4828, 4769, 4711, 4653, 4596, 4539, 4482, 4426, 4371, 4316, 4261, 4207, 4153, 4100, 4047, 3995, 3943, 3892,
51 12914, 12818, 12723, 12628, 12533, 12438, 12343, 12248, 12154, 12060, 11966, 11872, 11779, 49 3841, 3791, 3741, 3691, 3642, 3594, 3546, 3498, 3451, 3404, 3358, 3312, 3267, 3222, 3178, 3134, 3090, 3047, 3005,
52 11685, 11592, 11500, 11407, 11315, 11223, 11131, 11039, 10948, 10857, 10766, 10675, 10585, 50 2962, 2921, 2879, 2839, 2798, 2758, 2719, 2680, 2641, 2603, 2565, 2528, 2491, 2454, 2418, 2382, 2347, 2312, 2278,
53 10495, 10406, 10316, 10227, 10139, 10050, 9962, 9874, 9787, 9700, 9613, 9526, 9440, 9354, 9269, 51 2244, 2210, 2177, 2144, 2112, 2080, 2048, 2017, 1986, 1956, 1926, 1896, 1867, 1838, 1810, 1781, 1754, 1726, 1699,
54 9184, 9099, 9015, 8931, 8847, 8764, 8681, 8598, 8516, 8434, 8353, 8272, 8191, 8111, 8031, 7952, 52 1673, 1646, 1620, 1595, 1570, 1545, 1520, 1496, 1472, 1449, 1426, 1403, 1380, 1358, 1336, 1315, 1294, 1273, 1252,
55 7873, 7794, 7716, 7638, 7561, 7484, 7407, 7331, 7255, 7180, 7105, 7031, 6957, 6883, 6810, 6738, 53 1232, 1212, 1192, 1173, 1154, 1135, 1117, 1099, 1081, 1063, 1046, 1029, 1012, 996, 980, 964, 948, 933, 918, 903,
56 6665, 6594, 6522, 6451, 6381, 6311, 6241, 6172, 6104, 6036, 5968, 5901, 5834, 5767, 5702, 5636, 54 888, 874, 860, 846, 833, 819, 806, 793, 781, 768, 756, 744, 733, 721, 710, 699, 688, 677, 667, 657, 647, 637, 627,
57 5571, 5507, 5443, 5379, 5316, 5253, 5191, 5130, 5068, 5008, 4947, 4888, 4828, 4769, 4711, 4653, 55 618, 609, 599, 591, 582, 574, 565, 557, 549, 541, 534, 526, 519, 512, 505, 498, 492, 485, 479, 473, 467, 461, 455,
58 4596, 4539, 4482, 4426, 4371, 4316, 4261, 4207, 4153, 4100, 4047, 3995, 3943, 3892, 3841, 3791, 56 450, 444, 439, 434, 429, 424, 419, 415, 410, 406, 402, 398, 394, 390, 386, 383, 379, 376, 373, 370, 367, 364, 361,
59 3741, 3691, 3642, 3594, 3546, 3498, 3451, 3404, 3358, 3312, 3267, 3222, 3178, 3134, 3090, 3047, 57 359, 356, 354, 351, 349, 347, 345, 343, 342, 340, 338, 337, 336, 334, 333, 332, 331, 330, 330, 329, 328, 328, 328,
60 3005, 2962, 2921, 2879, 2839, 2798, 2758, 2719, 2680, 2641, 2603, 2565, 2528, 2491, 2454, 2418, 58 327, 327, 327, 327, 327, 328, 328, 328, 329, 330, 330, 331, 332, 333, 334, 336, 337, 338, 340, 342, 343, 345, 347,
61 2382, 2347, 2312, 2278, 2244, 2210, 2177, 2144, 2112, 2080, 2048, 2017, 1986, 1956, 1926, 1896, 59 349, 351, 354, 356, 359, 361, 364, 367, 370, 373, 376, 379, 383, 386, 390, 394, 398, 402, 406, 410, 415, 419, 424,
62 1867, 1838, 1810, 1781, 1754, 1726, 1699, 1673, 1646, 1620, 1595, 1570, 1545, 1520, 1496, 1472, 60 429, 434, 439, 444, 450, 455, 461, 467, 473, 479, 485, 492, 498, 505, 512, 519, 526, 534, 541, 549, 557, 565, 574,
63 1449, 1426, 1403, 1380, 1358, 1336, 1315, 1294, 1273, 1252, 1232, 1212, 1192, 1173, 1154, 1135, 61 582, 591, 599, 609, 618, 627, 637, 647, 657, 667, 677, 688, 699, 710, 721, 733, 744, 756, 768, 781, 793, 806, 819,
64 1117, 1099, 1081, 1063, 1046, 1029, 1012, 996, 980, 964, 948, 933, 918, 903, 888, 874, 860, 62 833, 846, 860, 874, 888, 903, 918, 933, 948, 964, 980, 996, 1012, 1029, 1046, 1063, 1081, 1099, 1117, 1135, 1154,
65 846, 833, 819, 806, 793, 781, 768, 756, 744, 733, 721, 710, 699, 688, 677, 667, 657, 647, 637, 63 1173, 1192, 1212, 1232, 1252, 1273, 1294, 1315, 1336, 1358, 1380, 1403, 1426, 1449, 1472, 1496, 1520, 1545, 1570,
66 627, 618, 609, 599, 591, 582, 574, 565, 557, 549, 541, 534, 526, 519, 512, 505, 498, 492, 485, 64 1595, 1620, 1646, 1673, 1699, 1726, 1754, 1781, 1810, 1838, 1867, 1896, 1926, 1956, 1986, 2017, 2048, 2080, 2112,
67 479, 473, 467, 461, 455, 450, 444, 439, 434, 429, 424, 419, 415, 410, 406, 402, 398, 394, 390, 65 2144, 2177, 2210, 2244, 2278, 2312, 2347, 2382, 2418, 2454, 2491, 2528, 2565, 2603, 2641, 2680, 2719, 2758, 2798,
68 386, 383, 379, 376, 373, 370, 367, 364, 361, 359, 356, 354, 351, 349, 347, 345, 343, 342, 340, 66 2839, 2879, 2921, 2962, 3005, 3047, 3090, 3134, 3178, 3222, 3267, 3312, 3358, 3404, 3451, 3498, 3546, 3594, 3642,
69 338, 337, 336, 334, 333, 332, 331, 330, 330, 329, 328, 328, 328, 327, 327, 327, 327, 327, 328, 67 3691, 3741, 3791, 3841, 3892, 3943, 3995, 4047, 4100, 4153, 4207, 4261, 4316, 4371, 4426, 4482, 4539, 4596, 4653,
70 328, 328, 329, 330, 330, 331, 332, 333, 334, 336, 337, 338, 340, 342, 343, 345, 347, 349, 351, 68 4711, 4769, 4828, 4888, 4947, 5008, 5068, 5130, 5191, 5253, 5316, 5379, 5443, 5507, 5571, 5636, 5702, 5767, 5834,
71 354, 356, 359, 361, 364, 367, 370, 373, 376, 379, 383, 386, 390, 394, 398, 402, 406, 410, 415, 69 5901, 5968, 6036, 6104, 6172, 6241, 6311, 6381, 6451, 6522, 6594, 6665, 6738, 6810, 6883, 6957, 7031, 7105, 7180,
72 419, 424, 429, 434, 439, 444, 450, 455, 461, 467, 473, 479, 485, 492, 498, 505, 512, 519, 526, 70 7255, 7331, 7407, 7484, 7561, 7638, 7716, 7794, 7873, 7952, 8031, 8111,
73 534, 541, 549, 557, 565, 574, 582, 591, 599, 609, 618, 627, 637, 647, 657, 667, 677, 688, 699,
74 710, 721, 733, 744, 756, 768, 781, 793, 806, 819, 833, 846, 860, 874, 888, 903, 918, 933, 948,
75 964, 980, 996, 1012, 1029, 1046, 1063, 1081, 1099, 1117, 1135, 1154, 1173, 1192, 1212, 1232,
76 1252, 1273, 1294, 1315, 1336, 1358, 1380, 1403, 1426, 1449, 1472, 1496, 1520, 1545, 1570, 1595,
77 1620, 1646, 1673, 1699, 1726, 1754, 1781, 1810, 1838, 1867, 1896, 1926, 1956, 1986, 2017, 2048,
78 2080, 2112, 2144, 2177, 2210, 2244, 2278, 2312, 2347, 2382, 2418, 2454, 2491, 2528, 2565, 2603,
79 2641, 2680, 2719, 2758, 2798, 2839, 2879, 2921, 2962, 3005, 3047, 3090, 3134, 3178, 3222, 3267,
80 3312, 3358, 3404, 3451, 3498, 3546, 3594, 3642, 3691, 3741, 3791, 3841, 3892, 3943, 3995, 4047,
81 4100, 4153, 4207, 4261, 4316, 4371, 4426, 4482, 4539, 4596, 4653, 4711, 4769, 4828, 4888, 4947,
82 5008, 5068, 5130, 5191, 5253, 5316, 5379, 5443, 5507, 5571, 5636, 5702, 5767, 5834, 5901, 5968,
83 6036, 6104, 6172, 6241, 6311, 6381, 6451, 6522, 6594, 6665, 6738, 6810, 6883, 6957, 7031, 7105,
84 7180, 7255, 7331, 7407, 7484, 7561, 7638, 7716, 7794, 7873, 7952, 8031, 8111,
85]; 71];
86 72
87#[embassy::main] 73#[embassy::main]
diff --git a/examples/nrf/src/bin/pwm_double_sequence.rs b/examples/nrf/src/bin/pwm_double_sequence.rs
index 6fc429214..facafa775 100644
--- a/examples/nrf/src/bin/pwm_double_sequence.rs
+++ b/examples/nrf/src/bin/pwm_double_sequence.rs
@@ -6,13 +6,10 @@ use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::pwm::{ 8use embassy_nrf::pwm::{
9 Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequencer, 9 Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequencer, StartSequence,
10 StartSequence,
11}; 10};
12use embassy_nrf::Peripherals; 11use embassy_nrf::Peripherals;
13 12use {defmt_rtt as _, panic_probe as _};
14use defmt_rtt as _; // global logger
15use panic_probe as _;
16 13
17#[embassy::main] 14#[embassy::main]
18async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs
index 3b2919ba5..b7cb385c7 100644
--- a/examples/nrf/src/bin/pwm_sequence.rs
+++ b/examples/nrf/src/bin/pwm_sequence.rs
@@ -5,13 +5,9 @@
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::pwm::{ 8use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer};
9 Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer,
10};
11use embassy_nrf::Peripherals; 9use embassy_nrf::Peripherals;
12 10use {defmt_rtt as _, panic_probe as _};
13use defmt_rtt as _; // global logger
14use panic_probe as _;
15 11
16#[embassy::main] 12#[embassy::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/pwm_sequence_ppi.rs b/examples/nrf/src/bin/pwm_sequence_ppi.rs
index 1f3662c60..7d020e48d 100644
--- a/examples/nrf/src/bin/pwm_sequence_ppi.rs
+++ b/examples/nrf/src/bin/pwm_sequence_ppi.rs
@@ -4,18 +4,15 @@
4#![feature(array_from_fn)] 4#![feature(array_from_fn)]
5 5
6use core::future::pending; 6use core::future::pending;
7
7use defmt::*; 8use defmt::*;
8use embassy::executor::Spawner; 9use embassy::executor::Spawner;
9use embassy_nrf::gpio::{Input, Pull}; 10use embassy_nrf::gpio::{Input, Pull};
10use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; 11use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity};
11use embassy_nrf::ppi::Ppi; 12use embassy_nrf::ppi::Ppi;
12use embassy_nrf::pwm::{ 13use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer};
13 Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer,
14};
15use embassy_nrf::Peripherals; 14use embassy_nrf::Peripherals;
16 15use {defmt_rtt as _, panic_probe as _};
17use defmt_rtt as _; // global logger
18use panic_probe as _;
19 16
20#[embassy::main] 17#[embassy::main]
21async fn main(_spawner: Spawner, p: Peripherals) { 18async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs b/examples/nrf/src/bin/pwm_sequence_ws2812b.rs
index 8bfe1d50f..0dee8c949 100644
--- a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs
+++ b/examples/nrf/src/bin/pwm_sequence_ws2812b.rs
@@ -6,13 +6,10 @@ use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::pwm::{ 8use embassy_nrf::pwm::{
9 Config, Prescaler, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode, 9 Config, Prescaler, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode, SingleSequencer,
10 SingleSequencer,
11}; 10};
12use embassy_nrf::Peripherals; 11use embassy_nrf::Peripherals;
13 12use {defmt_rtt as _, panic_probe as _};
14use defmt_rtt as _; // global logger
15use panic_probe as _;
16 13
17// WS2812B LED light demonstration. Drives just one light. 14// WS2812B LED light demonstration. Drives just one light.
18// The following reference on WS2812B may be of use: 15// The following reference on WS2812B may be of use:
diff --git a/examples/nrf/src/bin/pwm_servo.rs b/examples/nrf/src/bin/pwm_servo.rs
index 40863bf3c..71a90a948 100644
--- a/examples/nrf/src/bin/pwm_servo.rs
+++ b/examples/nrf/src/bin/pwm_servo.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::pwm::{Prescaler, SimplePwm}; 8use embassy_nrf::pwm::{Prescaler, SimplePwm};
9use embassy_nrf::Peripherals; 9use embassy_nrf::Peripherals;
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/qdec.rs b/examples/nrf/src/bin/qdec.rs
index bf5b11468..9529c7bb6 100644
--- a/examples/nrf/src/bin/qdec.rs
+++ b/examples/nrf/src/bin/qdec.rs
@@ -4,14 +4,9 @@
4 4
5use defmt::info; 5use defmt::info;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_nrf::{ 7use embassy_nrf::qdec::{self, Qdec};
8 interrupt, 8use embassy_nrf::{interrupt, Peripherals};
9 qdec::{self, Qdec}, 9use {defmt_rtt as _, panic_probe as _};
10 Peripherals,
11};
12
13use defmt_rtt as _; // global logger
14use panic_probe as _;
15 10
16#[embassy::main] 11#[embassy::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/qspi.rs b/examples/nrf/src/bin/qspi.rs
index 8673b7961..96c90f9c8 100644
--- a/examples/nrf/src/bin/qspi.rs
+++ b/examples/nrf/src/bin/qspi.rs
@@ -4,11 +4,8 @@
4 4
5use defmt::{assert_eq, info, unwrap}; 5use defmt::{assert_eq, info, unwrap};
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_nrf::Peripherals; 7use embassy_nrf::{interrupt, qspi, Peripherals};
8use embassy_nrf::{interrupt, qspi}; 8use {defmt_rtt as _, panic_probe as _};
9
10use defmt_rtt as _; // global logger
11use panic_probe as _;
12 9
13const PAGE_SIZE: usize = 4096; 10const PAGE_SIZE: usize = 4096;
14 11
diff --git a/examples/nrf/src/bin/qspi_lowpower.rs b/examples/nrf/src/bin/qspi_lowpower.rs
index 255ce5d5e..ce2e40b23 100644
--- a/examples/nrf/src/bin/qspi_lowpower.rs
+++ b/examples/nrf/src/bin/qspi_lowpower.rs
@@ -3,14 +3,12 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::mem; 5use core::mem;
6
6use defmt::{info, unwrap}; 7use defmt::{info, unwrap};
7use embassy::executor::Spawner; 8use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
9use embassy_nrf::Peripherals; 10use embassy_nrf::{interrupt, qspi, Peripherals};
10use embassy_nrf::{interrupt, qspi}; 11use {defmt_rtt as _, panic_probe as _};
11
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 12
15// Workaround for alignment requirements. 13// Workaround for alignment requirements.
16// Nicer API will probably come in the future. 14// Nicer API will probably come in the future.
diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs
index 1d9d3ed51..d564b6b26 100644
--- a/examples/nrf/src/bin/raw_spawn.rs
+++ b/examples/nrf/src/bin/raw_spawn.rs
@@ -2,15 +2,14 @@
2#![no_main] 2#![no_main]
3 3
4use core::mem; 4use core::mem;
5
5use cortex_m_rt::entry; 6use cortex_m_rt::entry;
6use defmt::{info, unwrap}; 7use defmt::{info, unwrap};
7use embassy::executor::raw::TaskStorage; 8use embassy::executor::raw::TaskStorage;
8use embassy::executor::Executor; 9use embassy::executor::Executor;
9use embassy::time::{Duration, Timer}; 10use embassy::time::{Duration, Timer};
10use embassy::util::Forever; 11use embassy::util::Forever;
11 12use {defmt_rtt as _, panic_probe as _};
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 13
15async fn run1() { 14async fn run1() {
16 loop { 15 loop {
diff --git a/examples/nrf/src/bin/rng.rs b/examples/nrf/src/bin/rng.rs
index 4b4b3a19b..08d3abe10 100644
--- a/examples/nrf/src/bin/rng.rs
+++ b/examples/nrf/src/bin/rng.rs
@@ -3,13 +3,10 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use embassy::executor::Spawner; 5use embassy::executor::Spawner;
6use embassy_nrf::interrupt;
7use embassy_nrf::rng::Rng; 6use embassy_nrf::rng::Rng;
8use embassy_nrf::Peripherals; 7use embassy_nrf::{interrupt, Peripherals};
9use rand::Rng as _; 8use rand::Rng as _;
10 9use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 10
14#[embassy::main] 11#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner, p: Peripherals) {
@@ -27,12 +24,6 @@ async fn main(_spawner: Spawner, p: Peripherals) {
27 rng.fill_bytes(&mut bytes).await; 24 rng.fill_bytes(&mut bytes).await;
28 let zero_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_zeros()); 25 let zero_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_zeros());
29 let one_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_ones()); 26 let one_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_ones());
30 defmt::info!( 27 defmt::info!("Chance of zero: {}%", zero_count * 100 / (bytes.len() as u32 * 8));
31 "Chance of zero: {}%", 28 defmt::info!("Chance of one: {}%", one_count * 100 / (bytes.len() as u32 * 8));
32 zero_count * 100 / (bytes.len() as u32 * 8)
33 );
34 defmt::info!(
35 "Chance of one: {}%",
36 one_count * 100 / (bytes.len() as u32 * 8)
37 );
38} 29}
diff --git a/examples/nrf/src/bin/saadc.rs b/examples/nrf/src/bin/saadc.rs
index 5835be31f..cb9289784 100644
--- a/examples/nrf/src/bin/saadc.rs
+++ b/examples/nrf/src/bin/saadc.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::saadc::{ChannelConfig, Config, Saadc}; 8use embassy_nrf::saadc::{ChannelConfig, Config, Saadc};
9use embassy_nrf::{interrupt, Peripherals}; 9use embassy_nrf::{interrupt, Peripherals};
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, mut p: Peripherals) { 13async fn main(_spawner: Spawner, mut p: Peripherals) {
diff --git a/examples/nrf/src/bin/saadc_continuous.rs b/examples/nrf/src/bin/saadc_continuous.rs
index 5e357f79b..234294eae 100644
--- a/examples/nrf/src/bin/saadc_continuous.rs
+++ b/examples/nrf/src/bin/saadc_continuous.rs
@@ -8,9 +8,7 @@ use embassy::time::Duration;
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_nrf::{interrupt, Peripherals};
11 11use {defmt_rtt as _, panic_probe as _};
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 12
15// 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
16 14
diff --git a/examples/nrf/src/bin/self_spawn.rs b/examples/nrf/src/bin/self_spawn.rs
index 35e73a8dd..4b8ac04bc 100644
--- a/examples/nrf/src/bin/self_spawn.rs
+++ b/examples/nrf/src/bin/self_spawn.rs
@@ -6,9 +6,7 @@ use defmt::{info, unwrap};
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::Peripherals; 8use embassy_nrf::Peripherals;
9 9use {defmt_rtt as _, panic_probe as _};
10use defmt_rtt as _; // global logger
11use panic_probe as _;
12 10
13#[embassy::task(pool_size = 2)] 11#[embassy::task(pool_size = 2)]
14async fn my_task(spawner: Spawner, n: u32) { 12async fn my_task(spawner: Spawner, n: u32) {
diff --git a/examples/nrf/src/bin/self_spawn_current_executor.rs b/examples/nrf/src/bin/self_spawn_current_executor.rs
index 4850d295d..3c3379ce6 100644
--- a/examples/nrf/src/bin/self_spawn_current_executor.rs
+++ b/examples/nrf/src/bin/self_spawn_current_executor.rs
@@ -6,9 +6,7 @@ use defmt::{info, unwrap};
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::Peripherals; 8use embassy_nrf::Peripherals;
9 9use {defmt_rtt as _, panic_probe as _};
10use defmt_rtt as _; // global logger
11use panic_probe as _;
12 10
13#[embassy::task(pool_size = 2)] 11#[embassy::task(pool_size = 2)]
14async fn my_task(n: u32) { 12async fn my_task(n: u32) {
diff --git a/examples/nrf/src/bin/spim.rs b/examples/nrf/src/bin/spim.rs
index f2a4ab388..62040168a 100644
--- a/examples/nrf/src/bin/spim.rs
+++ b/examples/nrf/src/bin/spim.rs
@@ -5,11 +5,8 @@
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_nrf::gpio::{Level, Output, OutputDrive}; 7use embassy_nrf::gpio::{Level, Output, OutputDrive};
8use embassy_nrf::Peripherals; 8use embassy_nrf::{interrupt, spim, Peripherals};
9use embassy_nrf::{interrupt, spim}; 9use {defmt_rtt as _, panic_probe as _};
10
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 10
14#[embassy::main] 11#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/temp.rs b/examples/nrf/src/bin/temp.rs
index aa807910f..939cb39e7 100644
--- a/examples/nrf/src/bin/temp.rs
+++ b/examples/nrf/src/bin/temp.rs
@@ -5,10 +5,9 @@
5use defmt::info; 5use defmt::info;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::{interrupt, temp::Temp, Peripherals}; 8use embassy_nrf::temp::Temp;
9 9use embassy_nrf::{interrupt, Peripherals};
10use defmt_rtt as _; // global logger 10use {defmt_rtt as _, panic_probe as _};
11use panic_probe as _;
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/timer.rs b/examples/nrf/src/bin/timer.rs
index ff8ee9a86..64376dd78 100644
--- a/examples/nrf/src/bin/timer.rs
+++ b/examples/nrf/src/bin/timer.rs
@@ -6,9 +6,7 @@ use defmt::{info, unwrap};
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_nrf::Peripherals; 8use embassy_nrf::Peripherals;
9 9use {defmt_rtt as _, panic_probe as _};
10use defmt_rtt as _; // global logger
11use panic_probe as _;
12 10
13#[embassy::task] 11#[embassy::task]
14async fn run1() { 12async fn run1() {
diff --git a/examples/nrf/src/bin/twim.rs b/examples/nrf/src/bin/twim.rs
index 08c614157..fb8372a12 100644
--- a/examples/nrf/src/bin/twim.rs
+++ b/examples/nrf/src/bin/twim.rs
@@ -10,9 +10,7 @@ use defmt::*;
10use embassy::executor::Spawner; 10use embassy::executor::Spawner;
11use embassy_nrf::twim::{self, Twim}; 11use embassy_nrf::twim::{self, Twim};
12use embassy_nrf::{interrupt, Peripherals}; 12use embassy_nrf::{interrupt, Peripherals};
13 13use {defmt_rtt as _, panic_probe as _};
14use defmt_rtt as _; // global logger
15use panic_probe as _;
16 14
17const ADDRESS: u8 = 0x50; 15const ADDRESS: u8 = 0x50;
18 16
diff --git a/examples/nrf/src/bin/twim_lowpower.rs b/examples/nrf/src/bin/twim_lowpower.rs
index 45b347ea0..c9c2d503e 100644
--- a/examples/nrf/src/bin/twim_lowpower.rs
+++ b/examples/nrf/src/bin/twim_lowpower.rs
@@ -9,14 +9,13 @@
9#![feature(type_alias_impl_trait)] 9#![feature(type_alias_impl_trait)]
10 10
11use core::mem; 11use core::mem;
12
12use defmt::*; 13use defmt::*;
13use embassy::executor::Spawner; 14use embassy::executor::Spawner;
14use embassy::time::{Duration, Timer}; 15use embassy::time::{Duration, Timer};
15use embassy_nrf::twim::{self, Twim}; 16use embassy_nrf::twim::{self, Twim};
16use embassy_nrf::{interrupt, Peripherals}; 17use embassy_nrf::{interrupt, Peripherals};
17 18use {defmt_rtt as _, panic_probe as _};
18use defmt_rtt as _; // global logger
19use panic_probe as _;
20 19
21const ADDRESS: u8 = 0x50; 20const ADDRESS: u8 = 0x50;
22 21
diff --git a/examples/nrf/src/bin/uart.rs b/examples/nrf/src/bin/uart.rs
index 91f7f4fdd..c8c4a67a5 100644
--- a/examples/nrf/src/bin/uart.rs
+++ b/examples/nrf/src/bin/uart.rs
@@ -5,9 +5,7 @@
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_nrf::{interrupt, uarte, Peripherals}; 7use embassy_nrf::{interrupt, uarte, Peripherals};
8 8use {defmt_rtt as _, panic_probe as _};
9use defmt_rtt as _; // global logger
10use panic_probe as _;
11 9
12#[embassy::main] 10#[embassy::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/uart_idle.rs b/examples/nrf/src/bin/uart_idle.rs
index 89336faaf..6679b28da 100644
--- a/examples/nrf/src/bin/uart_idle.rs
+++ b/examples/nrf/src/bin/uart_idle.rs
@@ -5,9 +5,7 @@
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_nrf::{interrupt, uarte, Peripherals}; 7use embassy_nrf::{interrupt, uarte, Peripherals};
8 8use {defmt_rtt as _, panic_probe as _};
9use defmt_rtt as _; // global logger
10use panic_probe as _;
11 9
12#[embassy::main] 10#[embassy::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner, p: Peripherals) {
@@ -16,9 +14,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
16 config.baudrate = uarte::Baudrate::BAUD115200; 14 config.baudrate = uarte::Baudrate::BAUD115200;
17 15
18 let irq = interrupt::take!(UARTE0_UART0); 16 let irq = interrupt::take!(UARTE0_UART0);
19 let mut uart = uarte::UarteWithIdle::new( 17 let mut uart = uarte::UarteWithIdle::new(p.UARTE0, p.TIMER0, p.PPI_CH0, p.PPI_CH1, irq, p.P0_08, p.P0_06, config);
20 p.UARTE0, p.TIMER0, p.PPI_CH0, p.PPI_CH1, irq, p.P0_08, p.P0_06, config,
21 );
22 18
23 info!("uarte initialized!"); 19 info!("uarte initialized!");
24 20
diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs
index 958cfeba0..1ffb63706 100644
--- a/examples/nrf/src/bin/uart_split.rs
+++ b/examples/nrf/src/bin/uart_split.rs
@@ -9,9 +9,7 @@ use embassy::executor::Spawner;
9use embassy_nrf::peripherals::UARTE0; 9use embassy_nrf::peripherals::UARTE0;
10use embassy_nrf::uarte::UarteRx; 10use embassy_nrf::uarte::UarteRx;
11use embassy_nrf::{interrupt, uarte, Peripherals}; 11use embassy_nrf::{interrupt, uarte, Peripherals};
12 12use {defmt_rtt as _, panic_probe as _};
13use defmt_rtt as _; // global logger
14use panic_probe as _;
15 13
16static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); 14static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new();
17 15
diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs
index 3d85d22bb..a20321fe8 100644
--- a/examples/nrf/src/bin/usb_ethernet.rs
+++ b/examples/nrf/src/bin/usb_ethernet.rs
@@ -6,6 +6,7 @@
6use core::mem; 6use core::mem;
7use core::sync::atomic::{AtomicBool, Ordering}; 7use core::sync::atomic::{AtomicBool, Ordering};
8use core::task::Waker; 8use core::task::Waker;
9
9use defmt::*; 10use defmt::*;
10use embassy::blocking_mutex::raw::ThreadModeRawMutex; 11use embassy::blocking_mutex::raw::ThreadModeRawMutex;
11use embassy::channel::mpmc::Channel; 12use embassy::channel::mpmc::Channel;
@@ -13,18 +14,13 @@ use embassy::executor::Spawner;
13use embassy::util::Forever; 14use embassy::util::Forever;
14use embassy_net::tcp::TcpSocket; 15use embassy_net::tcp::TcpSocket;
15use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; 16use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources};
16use embassy_nrf::pac;
17use embassy_nrf::rng::Rng; 17use embassy_nrf::rng::Rng;
18use embassy_nrf::usb::Driver; 18use embassy_nrf::usb::Driver;
19use embassy_nrf::Peripherals; 19use embassy_nrf::{interrupt, pac, peripherals, Peripherals};
20use embassy_nrf::{interrupt, peripherals};
21use embassy_usb::{Builder, Config, UsbDevice}; 20use embassy_usb::{Builder, Config, UsbDevice};
22use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; 21use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
23
24use defmt_rtt as _;
25use embedded_io::asynch::{Read, Write}; 22use embedded_io::asynch::{Read, Write};
26// global logger 23use {defmt_rtt as _, panic_probe as _};
27use panic_probe as _;
28 24
29type MyDriver = Driver<'static, peripherals::USBD>; 25type MyDriver = Driver<'static, peripherals::USBD>;
30 26
@@ -180,9 +176,7 @@ async fn main(spawner: Spawner, p: Peripherals) {
180 let seed = u64::from_le_bytes(seed); 176 let seed = u64::from_le_bytes(seed);
181 177
182 // Init network stack 178 // Init network stack
183 let device = Device { 179 let device = Device { mac_addr: our_mac_addr };
184 mac_addr: our_mac_addr,
185 };
186 let stack = &*forever!(Stack::new( 180 let stack = &*forever!(Stack::new(
187 device, 181 device,
188 config, 182 config,
diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs
index 98e7dd696..97ec861d8 100644
--- a/examples/nrf/src/bin/usb_hid_keyboard.rs
+++ b/examples/nrf/src/bin/usb_hid_keyboard.rs
@@ -5,25 +5,22 @@
5 5
6use core::mem; 6use core::mem;
7use core::sync::atomic::{AtomicBool, Ordering}; 7use core::sync::atomic::{AtomicBool, Ordering};
8
8use defmt::*; 9use defmt::*;
9use embassy::channel::signal::Signal; 10use embassy::channel::signal::Signal;
10use embassy::executor::Spawner; 11use embassy::executor::Spawner;
11use embassy::time::Duration; 12use embassy::time::Duration;
12use embassy::util::{select, select3, Either, Either3}; 13use embassy::util::{select, select3, Either, Either3};
13use embassy_nrf::gpio::{Input, Pin, Pull}; 14use embassy_nrf::gpio::{Input, Pin, Pull};
14use embassy_nrf::interrupt;
15use embassy_nrf::interrupt::InterruptExt; 15use embassy_nrf::interrupt::InterruptExt;
16use embassy_nrf::pac;
17use embassy_nrf::usb::Driver; 16use embassy_nrf::usb::Driver;
18use embassy_nrf::Peripherals; 17use embassy_nrf::{interrupt, pac, Peripherals};
19use embassy_usb::control::OutResponse; 18use embassy_usb::control::OutResponse;
20use embassy_usb::{Builder, Config, DeviceStateHandler}; 19use embassy_usb::{Builder, Config, DeviceStateHandler};
21use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; 20use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State};
22use futures::future::join; 21use futures::future::join;
23use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; 22use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor};
24 23use {defmt_rtt as _, panic_probe as _};
25use defmt_rtt as _; // global logger
26use panic_probe as _;
27 24
28static ENABLE_USB: Signal<bool> = Signal::new(); 25static ENABLE_USB: Signal<bool> = Signal::new();
29static SUSPENDED: AtomicBool = AtomicBool::new(false); 26static SUSPENDED: AtomicBool = AtomicBool::new(false);
@@ -182,9 +179,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
182 power_irq.unpend(); 179 power_irq.unpend();
183 power_irq.enable(); 180 power_irq.enable();
184 181
185 power 182 power.intenset.write(|w| w.usbdetected().set().usbremoved().set());
186 .intenset
187 .write(|w| w.usbdetected().set().usbremoved().set());
188 183
189 // Run everything concurrently. 184 // Run everything concurrently.
190 // If we had made everything `'static` above instead, we could do this using separate tasks instead. 185 // If we had made everything `'static` above instead, we could do this using separate tasks instead.
@@ -260,9 +255,7 @@ impl DeviceStateHandler for MyDeviceStateHandler {
260 fn configured(&self, configured: bool) { 255 fn configured(&self, configured: bool) {
261 self.configured.store(configured, Ordering::Relaxed); 256 self.configured.store(configured, Ordering::Relaxed);
262 if configured { 257 if configured {
263 info!( 258 info!("Device configured, it may now draw up to the configured current limit from Vbus.")
264 "Device configured, it may now draw up to the configured current limit from Vbus."
265 )
266 } else { 259 } else {
267 info!("Device is no longer configured, the Vbus current limit is 100mA."); 260 info!("Device is no longer configured, the Vbus current limit is 100mA.");
268 } 261 }
@@ -275,9 +268,7 @@ impl DeviceStateHandler for MyDeviceStateHandler {
275 } else { 268 } else {
276 SUSPENDED.store(false, Ordering::Release); 269 SUSPENDED.store(false, Ordering::Release);
277 if self.configured.load(Ordering::Relaxed) { 270 if self.configured.load(Ordering::Relaxed) {
278 info!( 271 info!("Device resumed, it may now draw up to the configured current limit from Vbus");
279 "Device resumed, it may now draw up to the configured current limit from Vbus"
280 );
281 } else { 272 } else {
282 info!("Device resumed, the Vbus current limit is 100mA"); 273 info!("Device resumed, the Vbus current limit is 100mA");
283 } 274 }
diff --git a/examples/nrf/src/bin/usb_hid_mouse.rs b/examples/nrf/src/bin/usb_hid_mouse.rs
index c526c1c6f..9c44e5cc8 100644
--- a/examples/nrf/src/bin/usb_hid_mouse.rs
+++ b/examples/nrf/src/bin/usb_hid_mouse.rs
@@ -4,21 +4,18 @@
4#![feature(type_alias_impl_trait)] 4#![feature(type_alias_impl_trait)]
5 5
6use core::mem; 6use core::mem;
7
7use defmt::*; 8use defmt::*;
8use embassy::executor::Spawner; 9use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 10use embassy::time::{Duration, Timer};
10use embassy_nrf::interrupt;
11use embassy_nrf::pac;
12use embassy_nrf::usb::Driver; 11use embassy_nrf::usb::Driver;
13use embassy_nrf::Peripherals; 12use embassy_nrf::{interrupt, pac, Peripherals};
14use embassy_usb::control::OutResponse; 13use embassy_usb::control::OutResponse;
15use embassy_usb::{Builder, Config}; 14use embassy_usb::{Builder, Config};
16use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; 15use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State};
17use futures::future::join; 16use futures::future::join;
18use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; 17use usbd_hid::descriptor::{MouseReport, SerializedDescriptor};
19 18use {defmt_rtt as _, panic_probe as _};
20use defmt_rtt as _; // global logger
21use panic_probe as _;
22 19
23#[embassy::main] 20#[embassy::main]
24async fn main(_spawner: Spawner, p: Peripherals) { 21async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/usb_serial.rs b/examples/nrf/src/bin/usb_serial.rs
index 2551c4ba1..f108db46d 100644
--- a/examples/nrf/src/bin/usb_serial.rs
+++ b/examples/nrf/src/bin/usb_serial.rs
@@ -4,19 +4,16 @@
4#![feature(type_alias_impl_trait)] 4#![feature(type_alias_impl_trait)]
5 5
6use core::mem; 6use core::mem;
7
7use defmt::{info, panic}; 8use defmt::{info, panic};
8use embassy::executor::Spawner; 9use embassy::executor::Spawner;
9use embassy_nrf::interrupt;
10use embassy_nrf::pac;
11use embassy_nrf::usb::{Driver, Instance}; 10use embassy_nrf::usb::{Driver, Instance};
12use embassy_nrf::Peripherals; 11use embassy_nrf::{interrupt, pac, Peripherals};
13use embassy_usb::driver::EndpointError; 12use embassy_usb::driver::EndpointError;
14use embassy_usb::{Builder, Config}; 13use embassy_usb::{Builder, Config};
15use embassy_usb_serial::{CdcAcmClass, State}; 14use embassy_usb_serial::{CdcAcmClass, State};
16use futures::future::join; 15use futures::future::join;
17 16use {defmt_rtt as _, panic_probe as _};
18use defmt_rtt as _; // global logger
19use panic_probe as _;
20 17
21#[embassy::main] 18#[embassy::main]
22async fn main(_spawner: Spawner, p: Peripherals) { 19async fn main(_spawner: Spawner, p: Peripherals) {
@@ -104,9 +101,7 @@ impl From<EndpointError> for Disconnected {
104 } 101 }
105} 102}
106 103
107async fn echo<'d, T: Instance + 'd>( 104async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> {
108 class: &mut CdcAcmClass<'d, Driver<'d, T>>,
109) -> Result<(), Disconnected> {
110 let mut buf = [0; 64]; 105 let mut buf = [0; 64];
111 loop { 106 loop {
112 let n = class.read_packet(&mut buf).await?; 107 let n = class.read_packet(&mut buf).await?;
diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs
index 0e82ba313..dc503e67c 100644
--- a/examples/nrf/src/bin/usb_serial_multitask.rs
+++ b/examples/nrf/src/bin/usb_serial_multitask.rs
@@ -4,19 +4,16 @@
4#![feature(type_alias_impl_trait)] 4#![feature(type_alias_impl_trait)]
5 5
6use core::mem; 6use core::mem;
7
7use defmt::{info, panic, unwrap}; 8use defmt::{info, panic, unwrap};
8use embassy::executor::Spawner; 9use embassy::executor::Spawner;
9use embassy::util::Forever; 10use embassy::util::Forever;
10use embassy_nrf::pac;
11use embassy_nrf::usb::Driver; 11use embassy_nrf::usb::Driver;
12use embassy_nrf::Peripherals; 12use embassy_nrf::{interrupt, pac, peripherals, Peripherals};
13use embassy_nrf::{interrupt, peripherals};
14use embassy_usb::driver::EndpointError; 13use embassy_usb::driver::EndpointError;
15use embassy_usb::{Builder, Config, UsbDevice}; 14use embassy_usb::{Builder, Config, UsbDevice};
16use embassy_usb_serial::{CdcAcmClass, State}; 15use embassy_usb_serial::{CdcAcmClass, State};
17 16use {defmt_rtt as _, panic_probe as _};
18use defmt_rtt as _; // global logger
19use panic_probe as _;
20 17
21type MyDriver = Driver<'static, peripherals::USBD>; 18type MyDriver = Driver<'static, peripherals::USBD>;
22 19
diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf/src/bin/wdt.rs
index 431ccca8b..280e23bcf 100644
--- a/examples/nrf/src/bin/wdt.rs
+++ b/examples/nrf/src/bin/wdt.rs
@@ -7,9 +7,7 @@ use 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; 9use embassy_nrf::Peripherals;
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/rp/src/bin/blinky.rs b/examples/rp/src/bin/blinky.rs
index 6f199d07e..35612a4cf 100644
--- a/examples/rp/src/bin/blinky.rs
+++ b/examples/rp/src/bin/blinky.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_rp::{gpio, Peripherals}; 8use embassy_rp::{gpio, Peripherals};
9use gpio::{Level, Output}; 9use gpio::{Level, Output};
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs
index 2418ad012..980e54ea1 100644
--- a/examples/rp/src/bin/button.rs
+++ b/examples/rp/src/bin/button.rs
@@ -5,9 +5,7 @@
5use embassy::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; 7use embassy_rp::Peripherals;
8 8use {defmt_rtt as _, panic_probe as _};
9use defmt_rtt as _; // global logger
10use panic_probe as _;
11 9
12#[embassy::main] 10#[embassy::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 11async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/rp/src/bin/spi.rs b/examples/rp/src/bin/spi.rs
index b38424363..d97aa94b3 100644
--- a/examples/rp/src/bin/spi.rs
+++ b/examples/rp/src/bin/spi.rs
@@ -4,13 +4,10 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_rp::spi;
8use embassy_rp::spi::Spi; 7use embassy_rp::spi::Spi;
9use embassy_rp::{gpio, Peripherals}; 8use embassy_rp::{gpio, spi, Peripherals};
10use gpio::{Level, Output}; 9use gpio::{Level, Output};
11 10use {defmt_rtt as _, panic_probe as _};
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 11
15#[embassy::main] 12#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/rp/src/bin/spi_display.rs b/examples/rp/src/bin/spi_display.rs
index 5c3c4c4c5..f4a411ba6 100644
--- a/examples/rp/src/bin/spi_display.rs
+++ b/examples/rp/src/bin/spi_display.rs
@@ -3,13 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::cell::RefCell; 5use core::cell::RefCell;
6
6use defmt::*; 7use defmt::*;
7use embassy::executor::Spawner; 8use embassy::executor::Spawner;
8use embassy::time::Delay; 9use embassy::time::Delay;
9use embassy_rp::gpio::{Level, Output}; 10use embassy_rp::gpio::{Level, Output};
10use embassy_rp::spi;
11use embassy_rp::spi::Spi; 11use embassy_rp::spi::Spi;
12use embassy_rp::Peripherals; 12use embassy_rp::{spi, Peripherals};
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;
@@ -18,14 +18,12 @@ use embedded_graphics::prelude::*;
18use embedded_graphics::primitives::{PrimitiveStyleBuilder, Rectangle}; 18use embedded_graphics::primitives::{PrimitiveStyleBuilder, Rectangle};
19use embedded_graphics::text::Text; 19use embedded_graphics::text::Text;
20use st7789::{Orientation, ST7789}; 20use st7789::{Orientation, ST7789};
21use {defmt_rtt as _, panic_probe as _};
21 22
22use crate::my_display_interface::SPIDeviceInterface; 23use crate::my_display_interface::SPIDeviceInterface;
23use crate::shared_spi::SpiDeviceWithCs; 24use crate::shared_spi::SpiDeviceWithCs;
24use crate::touch::Touch; 25use crate::touch::Touch;
25 26
26use defmt_rtt as _; // global logger
27use panic_probe as _;
28
29//const DISPLAY_FREQ: u32 = 64_000_000; 27//const DISPLAY_FREQ: u32 = 64_000_000;
30const TOUCH_FREQ: u32 = 200_000; 28const TOUCH_FREQ: u32 = 200_000;
31 29
@@ -94,9 +92,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
94 92
95 loop { 93 loop {
96 if let Some((x, y)) = touch.read() { 94 if let Some((x, y)) = touch.read() {
97 let style = PrimitiveStyleBuilder::new() 95 let style = PrimitiveStyleBuilder::new().fill_color(Rgb565::BLUE).build();
98 .fill_color(Rgb565::BLUE)
99 .build();
100 96
101 Rectangle::new(Point::new(x - 1, y - 1), Size::new(3, 3)) 97 Rectangle::new(Point::new(x - 1, y - 1), Size::new(3, 3))
102 .into_styled(style) 98 .into_styled(style)
diff --git a/examples/rp/src/bin/uart.rs b/examples/rp/src/bin/uart.rs
index bc941dd8b..99072253a 100644
--- a/examples/rp/src/bin/uart.rs
+++ b/examples/rp/src/bin/uart.rs
@@ -4,9 +4,7 @@
4 4
5use embassy::executor::Spawner; 5use embassy::executor::Spawner;
6use embassy_rp::{uart, Peripherals}; 6use embassy_rp::{uart, Peripherals};
7 7use {defmt_rtt as _, panic_probe as _};
8use defmt_rtt as _; // global logger
9use panic_probe as _;
10 8
11#[embassy::main] 9#[embassy::main]
12async fn main(_spawner: Spawner, p: Peripherals) { 10async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/std/src/serial_port.rs b/examples/std/src/serial_port.rs
index 6825cbebc..c41abd4d0 100644
--- a/examples/std/src/serial_port.rs
+++ b/examples/std/src/serial_port.rs
@@ -1,18 +1,16 @@
1use std::io;
2use std::os::unix::io::{AsRawFd, RawFd};
3
1use nix::errno::Errno; 4use nix::errno::Errno;
2use nix::fcntl::OFlag; 5use nix::fcntl::OFlag;
3use nix::sys::termios; 6use nix::sys::termios;
4use std::io;
5use std::os::unix::io::{AsRawFd, RawFd};
6 7
7pub struct SerialPort { 8pub struct SerialPort {
8 fd: RawFd, 9 fd: RawFd,
9} 10}
10 11
11impl SerialPort { 12impl SerialPort {
12 pub fn new<P: ?Sized + nix::NixPath>( 13 pub fn new<P: ?Sized + nix::NixPath>(path: &P, baudrate: termios::BaudRate) -> io::Result<Self> {
13 path: &P,
14 baudrate: termios::BaudRate,
15 ) -> io::Result<Self> {
16 let fd = nix::fcntl::open( 14 let fd = nix::fcntl::open(
17 path, 15 path,
18 OFlag::O_RDWR | OFlag::O_NOCTTY | OFlag::O_NONBLOCK, 16 OFlag::O_RDWR | OFlag::O_NOCTTY | OFlag::O_NONBLOCK,
diff --git a/examples/std/src/tuntap.rs b/examples/std/src/tuntap.rs
index b70767a3a..a0cace7f7 100644
--- a/examples/std/src/tuntap.rs
+++ b/examples/std/src/tuntap.rs
@@ -1,9 +1,10 @@
1use async_io::Async;
2use log::*;
3use std::io; 1use std::io;
4use std::io::{Read, Write}; 2use std::io::{Read, Write};
5use std::os::unix::io::{AsRawFd, RawFd}; 3use std::os::unix::io::{AsRawFd, RawFd};
6 4
5use async_io::Async;
6use log::*;
7
7pub const SIOCGIFMTU: libc::c_ulong = 0x8921; 8pub const SIOCGIFMTU: libc::c_ulong = 0x8921;
8pub const _SIOCGIFINDEX: libc::c_ulong = 0x8933; 9pub const _SIOCGIFINDEX: libc::c_ulong = 0x8933;
9pub const _ETH_P_ALL: libc::c_short = 0x0003; 10pub const _ETH_P_ALL: libc::c_short = 0x0003;
@@ -32,11 +33,7 @@ fn ifreq_for(name: &str) -> ifreq {
32 ifreq 33 ifreq
33} 34}
34 35
35fn ifreq_ioctl( 36fn ifreq_ioctl(lower: libc::c_int, ifreq: &mut ifreq, cmd: libc::c_ulong) -> io::Result<libc::c_int> {
36 lower: libc::c_int,
37 ifreq: &mut ifreq,
38 cmd: libc::c_ulong,
39) -> io::Result<libc::c_int> {
40 unsafe { 37 unsafe {
41 let res = libc::ioctl(lower, cmd as _, ifreq as *mut ifreq); 38 let res = libc::ioctl(lower, cmd as _, ifreq as *mut ifreq);
42 if res == -1 { 39 if res == -1 {
@@ -141,11 +138,10 @@ impl TunTapDevice {
141} 138}
142 139
143use core::task::Waker; 140use core::task::Waker;
144use embassy_net::{
145 Device, DeviceCapabilities, LinkState, Packet, PacketBox, PacketBoxExt, PacketBuf,
146};
147use std::task::Context; 141use std::task::Context;
148 142
143use embassy_net::{Device, DeviceCapabilities, LinkState, Packet, PacketBox, PacketBoxExt, PacketBuf};
144
149impl Device for TunTapDevice { 145impl Device for TunTapDevice {
150 fn is_transmit_ready(&mut self) -> bool { 146 fn is_transmit_ready(&mut self) -> bool {
151 true 147 true
diff --git a/examples/stm32f0/src/bin/hello.rs b/examples/stm32f0/src/bin/hello.rs
index 975e94f34..225f1c3ae 100644
--- a/examples/stm32f0/src/bin/hello.rs
+++ b/examples/stm32f0/src/bin/hello.rs
@@ -6,9 +6,7 @@ use defmt::info;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::Peripherals; 8use embassy_stm32::Peripherals;
9 9use {defmt_rtt as _, panic_probe as _};
10use defmt_rtt as _; // global logger
11use panic_probe as _;
12 10
13#[embassy::main] 11#[embassy::main]
14async fn main(_spawner: Spawner, _p: Peripherals) -> ! { 12async fn main(_spawner: Spawner, _p: Peripherals) -> ! {
diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs
index af403423d..09904d4cc 100644
--- a/examples/stm32f1/src/bin/adc.rs
+++ b/examples/stm32f1/src/bin/adc.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy::time::{Delay, Duration, Timer}; 7use embassy::time::{Delay, Duration, Timer};
8use embassy_stm32::adc::Adc; 8use embassy_stm32::adc::Adc;
9use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs
index 657bcdd1d..c98d0cdad 100644
--- a/examples/stm32f1/src/bin/blinky.rs
+++ b/examples/stm32f1/src/bin/blinky.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs
index 8054a8993..82f11bc28 100644
--- a/examples/stm32f1/src/bin/hello.rs
+++ b/examples/stm32f1/src/bin/hello.rs
@@ -6,11 +6,8 @@ use defmt::info;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
9use embassy_stm32::Config; 9use embassy_stm32::{Config, Peripherals};
10use embassy_stm32::Peripherals; 10use {defmt_rtt as _, panic_probe as _};
11
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 11
15fn config() -> Config { 12fn config() -> Config {
16 let mut config = Config::default(); 13 let mut config = Config::default();
diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs
index fe4aa4cc9..d06315d76 100644
--- a/examples/stm32f1/src/bin/usb_serial.rs
+++ b/examples/stm32f1/src/bin/usb_serial.rs
@@ -2,24 +2,18 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::panic; 5use defmt::{panic, *};
6use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy::executor::Spawner; 6use embassy::executor::Spawner;
9use embassy::time::Duration; 7use embassy::time::{Duration, Timer};
10use embassy::time::Timer; 8use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::gpio::Level;
12use embassy_stm32::gpio::Output;
13use embassy_stm32::gpio::Speed;
14use embassy_stm32::interrupt;
15use embassy_stm32::time::Hertz; 9use embassy_stm32::time::Hertz;
16use embassy_stm32::usb::{Driver, Instance}; 10use embassy_stm32::usb::{Driver, Instance};
17use embassy_stm32::{Config, Peripherals}; 11use embassy_stm32::{interrupt, Config, Peripherals};
18use embassy_usb::driver::EndpointError; 12use embassy_usb::driver::EndpointError;
19use embassy_usb::Builder; 13use embassy_usb::Builder;
20use embassy_usb_serial::{CdcAcmClass, State}; 14use embassy_usb_serial::{CdcAcmClass, State};
21use futures::future::join; 15use futures::future::join;
22use panic_probe as _; 16use {defmt_rtt as _, panic_probe as _};
23 17
24fn config() -> Config { 18fn config() -> Config {
25 let mut config = Config::default(); 19 let mut config = Config::default();
@@ -104,9 +98,7 @@ impl From<EndpointError> for Disconnected {
104 } 98 }
105} 99}
106 100
107async fn echo<'d, T: Instance + 'd>( 101async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> {
108 class: &mut CdcAcmClass<'d, Driver<'d, T>>,
109) -> Result<(), Disconnected> {
110 let mut buf = [0; 64]; 102 let mut buf = [0; 64];
111 loop { 103 loop {
112 let n = class.read_packet(&mut buf).await?; 104 let n = class.read_packet(&mut buf).await?;
diff --git a/examples/stm32f2/src/bin/blinky.rs b/examples/stm32f2/src/bin/blinky.rs
index 395f4df51..dd20ba85a 100644
--- a/examples/stm32f2/src/bin/blinky.rs
+++ b/examples/stm32f2/src/bin/blinky.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f2/src/bin/pll.rs b/examples/stm32f2/src/bin/pll.rs
index 4bd74f0bd..b09d64b0b 100644
--- a/examples/stm32f2/src/bin/pll.rs
+++ b/examples/stm32f2/src/bin/pll.rs
@@ -3,20 +3,16 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::convert::TryFrom; 5use core::convert::TryFrom;
6
6use defmt::*; 7use defmt::*;
7use embassy::executor::Spawner; 8use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
9use embassy_stm32::{ 10use embassy_stm32::rcc::{
10 rcc::{ 11 APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLL48Div, PLLConfig, PLLMainDiv, PLLMul, PLLPreDiv, PLLSrc,
11 APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLL48Div, PLLConfig, PLLMainDiv, PLLMul,
12 PLLPreDiv, PLLSrc,
13 },
14 time::Hertz,
15 Config, Peripherals,
16}; 12};
17 13use embassy_stm32::time::Hertz;
18use defmt_rtt as _; // global logger 14use embassy_stm32::{Config, Peripherals};
19use panic_probe as _; 15use {defmt_rtt as _, panic_probe as _};
20 16
21// Example config for maximum performance on a NUCLEO-F207ZG board 17// Example config for maximum performance on a NUCLEO-F207ZG board
22fn config() -> Config { 18fn config() -> Config {
diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs
index 4b181a784..4d0b33f61 100644
--- a/examples/stm32f3/src/bin/blinky.rs
+++ b/examples/stm32f3/src/bin/blinky.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f3/src/bin/button.rs b/examples/stm32f3/src/bin/button.rs
index 207381bdd..b55bf3901 100644
--- a/examples/stm32f3/src/bin/button.rs
+++ b/examples/stm32f3/src/bin/button.rs
@@ -4,9 +4,8 @@
4 4
5use cortex_m_rt::entry; 5use cortex_m_rt::entry;
6use defmt::*; 6use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use panic_probe as _; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[entry] 10#[entry]
12fn main() -> ! { 11fn main() -> ! {
diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs
index 593701799..45862ddc6 100644
--- a/examples/stm32f3/src/bin/button_events.rs
+++ b/examples/stm32f3/src/bin/button_events.rs
@@ -19,9 +19,7 @@ use embassy_stm32::exti::ExtiInput;
19use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; 19use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed};
20use embassy_stm32::peripherals::PA0; 20use embassy_stm32::peripherals::PA0;
21use embassy_stm32::Peripherals; 21use embassy_stm32::Peripherals;
22 22use {defmt_rtt as _, panic_probe as _};
23use defmt_rtt as _; // global logger
24use panic_probe as _;
25 23
26struct Leds<'a> { 24struct Leds<'a> {
27 leds: [Output<'a, AnyPin>; 8], 25 leds: [Output<'a, AnyPin>; 8],
@@ -57,8 +55,7 @@ impl<'a> Leds<'a> {
57 self.process_event(new_message).await; 55 self.process_event(new_message).await;
58 } else { 56 } else {
59 self.leds[self.current_led].set_low(); 57 self.leds[self.current_led].set_low();
60 if let Ok(new_message) = with_timeout(Duration::from_millis(200), CHANNEL.recv()).await 58 if let Ok(new_message) = with_timeout(Duration::from_millis(200), CHANNEL.recv()).await {
61 {
62 self.process_event(new_message).await; 59 self.process_event(new_message).await;
63 } 60 }
64 } 61 }
@@ -137,22 +134,16 @@ async fn button_waiter(mut button: ExtiInput<'static, PA0>) {
137 134
138 button.wait_for_rising_edge().await; 135 button.wait_for_rising_edge().await;
139 loop { 136 loop {
140 if with_timeout( 137 if with_timeout(Duration::from_millis(HOLD_DELAY), button.wait_for_falling_edge())
141 Duration::from_millis(HOLD_DELAY), 138 .await
142 button.wait_for_falling_edge(), 139 .is_err()
143 )
144 .await
145 .is_err()
146 { 140 {
147 info!("Hold"); 141 info!("Hold");
148 CHANNEL.send(ButtonEvent::Hold).await; 142 CHANNEL.send(ButtonEvent::Hold).await;
149 button.wait_for_falling_edge().await; 143 button.wait_for_falling_edge().await;
150 } else if with_timeout( 144 } else if with_timeout(Duration::from_millis(DOUBLE_CLICK_DELAY), button.wait_for_rising_edge())
151 Duration::from_millis(DOUBLE_CLICK_DELAY), 145 .await
152 button.wait_for_rising_edge(), 146 .is_err()
153 )
154 .await
155 .is_err()
156 { 147 {
157 info!("Single click"); 148 info!("Single click");
158 CHANNEL.send(ButtonEvent::SingleClick).await; 149 CHANNEL.send(ButtonEvent::SingleClick).await;
diff --git a/examples/stm32f3/src/bin/button_exti.rs b/examples/stm32f3/src/bin/button_exti.rs
index 68d166367..add6712b4 100644
--- a/examples/stm32f3/src/bin/button_exti.rs
+++ b/examples/stm32f3/src/bin/button_exti.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f3/src/bin/flash.rs b/examples/stm32f3/src/bin/flash.rs
index 3890f0514..ce16f6de7 100644
--- a/examples/stm32f3/src/bin/flash.rs
+++ b/examples/stm32f3/src/bin/flash.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
8use embassy_stm32::Peripherals; 8use embassy_stm32::Peripherals;
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f3/src/bin/hello.rs b/examples/stm32f3/src/bin/hello.rs
index a79d6838c..3b89f1c72 100644
--- a/examples/stm32f3/src/bin/hello.rs
+++ b/examples/stm32f3/src/bin/hello.rs
@@ -6,11 +6,8 @@ use defmt::info;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
9use embassy_stm32::Config; 9use embassy_stm32::{Config, Peripherals};
10use embassy_stm32::Peripherals; 10use {defmt_rtt as _, panic_probe as _};
11
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 11
15fn config() -> Config { 12fn config() -> Config {
16 let mut config = Config::default(); 13 let mut config = Config::default();
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs
index 684295609..4f2cf9a6f 100644
--- a/examples/stm32f3/src/bin/multiprio.rs
+++ b/examples/stm32f3/src/bin/multiprio.rs
@@ -57,16 +57,14 @@
57#![no_main] 57#![no_main]
58#![feature(type_alias_impl_trait)] 58#![feature(type_alias_impl_trait)]
59 59
60use defmt::*;
61use defmt_rtt as _; // global logger
62use panic_probe as _;
63
64use cortex_m_rt::entry; 60use cortex_m_rt::entry;
61use defmt::*;
65use embassy::time::{Duration, Instant, Timer}; 62use embassy::time::{Duration, Instant, Timer};
66use embassy::util::Forever; 63use embassy::util::Forever;
67use embassy_stm32::executor::{Executor, InterruptExecutor}; 64use embassy_stm32::executor::{Executor, InterruptExecutor};
68use embassy_stm32::interrupt; 65use embassy_stm32::interrupt;
69use embassy_stm32::interrupt::InterruptExt; 66use embassy_stm32::interrupt::InterruptExt;
67use {defmt_rtt as _, panic_probe as _};
70 68
71#[embassy::task] 69#[embassy::task]
72async fn run_high() { 70async fn run_high() {
diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs
index 6d80c4087..ece1ae6fe 100644
--- a/examples/stm32f3/src/bin/spi_dma.rs
+++ b/examples/stm32f3/src/bin/spi_dma.rs
@@ -4,14 +4,14 @@
4 4
5use core::fmt::Write; 5use core::fmt::Write;
6use core::str::from_utf8; 6use core::str::from_utf8;
7
7use defmt::*; 8use defmt::*;
8use defmt_rtt as _; // global logger
9use embassy::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; 12use embassy_stm32::Peripherals;
13use heapless::String; 13use heapless::String;
14use panic_probe as _; 14use {defmt_rtt as _, panic_probe as _};
15 15
16#[embassy::main] 16#[embassy::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 17async fn main(_spawner: Spawner, p: Peripherals) {
@@ -32,9 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
32 let mut write: String<128> = String::new(); 32 let mut write: String<128> = String::new();
33 let mut read = [0; 128]; 33 let mut read = [0; 128];
34 core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); 34 core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap();
35 spi.transfer(&mut read[0..write.len()], write.as_bytes()) 35 spi.transfer(&mut read[0..write.len()], write.as_bytes()).await.ok();
36 .await
37 .ok();
38 info!("read via spi+dma: {}", from_utf8(&read).unwrap()); 36 info!("read via spi+dma: {}", from_utf8(&read).unwrap());
39 } 37 }
40} 38}
diff --git a/examples/stm32f3/src/bin/usart_dma.rs b/examples/stm32f3/src/bin/usart_dma.rs
index 859749eb7..4660f812e 100644
--- a/examples/stm32f3/src/bin/usart_dma.rs
+++ b/examples/stm32f3/src/bin/usart_dma.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::fmt::Write; 5use core::fmt::Write;
6
6use defmt::*; 7use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy::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; 11use embassy_stm32::Peripherals;
12use heapless::String; 12use heapless::String;
13use panic_probe as _; 13use {defmt_rtt as _, panic_probe as _};
14 14
15#[embassy::main] 15#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 16async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs
index fc33d0bc7..8a76d4546 100644
--- a/examples/stm32f3/src/bin/usb_serial.rs
+++ b/examples/stm32f3/src/bin/usb_serial.rs
@@ -2,24 +2,18 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::panic; 5use defmt::{panic, *};
6use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy::executor::Spawner; 6use embassy::executor::Spawner;
9use embassy::time::Duration; 7use embassy::time::{Duration, Timer};
10use embassy::time::Timer; 8use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::gpio::Level;
12use embassy_stm32::gpio::Output;
13use embassy_stm32::gpio::Speed;
14use embassy_stm32::interrupt;
15use embassy_stm32::time::U32Ext; 9use embassy_stm32::time::U32Ext;
16use embassy_stm32::usb::{Driver, Instance}; 10use embassy_stm32::usb::{Driver, Instance};
17use embassy_stm32::{Config, Peripherals}; 11use embassy_stm32::{interrupt, Config, Peripherals};
18use embassy_usb::driver::EndpointError; 12use embassy_usb::driver::EndpointError;
19use embassy_usb::Builder; 13use embassy_usb::Builder;
20use embassy_usb_serial::{CdcAcmClass, State}; 14use embassy_usb_serial::{CdcAcmClass, State};
21use futures::future::join; 15use futures::future::join;
22use panic_probe as _; 16use {defmt_rtt as _, panic_probe as _};
23 17
24fn config() -> Config { 18fn config() -> Config {
25 let mut config = Config::default(); 19 let mut config = Config::default();
@@ -103,9 +97,7 @@ impl From<EndpointError> for Disconnected {
103 } 97 }
104} 98}
105 99
106async fn echo<'d, T: Instance + 'd>( 100async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> {
107 class: &mut CdcAcmClass<'d, Driver<'d, T>>,
108) -> Result<(), Disconnected> {
109 let mut buf = [0; 64]; 101 let mut buf = [0; 64];
110 loop { 102 loop {
111 let n = class.read_packet(&mut buf).await?; 103 let n = class.read_packet(&mut buf).await?;
diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs
index f0b1ad232..84ddbfd3c 100644
--- a/examples/stm32f4/src/bin/adc.rs
+++ b/examples/stm32f4/src/bin/adc.rs
@@ -2,14 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy::time::{Delay, Duration, Timer}; 7use embassy::time::{Delay, Duration, Timer};
11use embassy_stm32::adc::Adc; 8use embassy_stm32::adc::Adc;
12use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _};
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs
index 8b85ca96d..907492b3d 100644
--- a/examples/stm32f4/src/bin/blinky.rs
+++ b/examples/stm32f4/src/bin/blinky.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs
index 4f9af7fbd..b13e64531 100644
--- a/examples/stm32f4/src/bin/button.rs
+++ b/examples/stm32f4/src/bin/button.rs
@@ -4,9 +4,8 @@
4 4
5use cortex_m_rt::entry; 5use cortex_m_rt::entry;
6use defmt::*; 6use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use panic_probe as _; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[entry] 10#[entry]
12fn main() -> ! { 11fn main() -> ! {
diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs
index 78f2e6ee2..24ece9927 100644
--- a/examples/stm32f4/src/bin/button_exti.rs
+++ b/examples/stm32f4/src/bin/button_exti.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs
index 0f41d6860..8abce87a2 100644
--- a/examples/stm32f4/src/bin/can.rs
+++ b/examples/stm32f4/src/bin/can.rs
@@ -2,15 +2,13 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use cortex_m_rt::entry; 5use cortex_m_rt::entry;
9use defmt::*; 6use defmt::*;
10use embassy_stm32::can::bxcan::filter::Mask32; 7use embassy_stm32::can::bxcan::filter::Mask32;
11use embassy_stm32::can::bxcan::{Frame, StandardId}; 8use embassy_stm32::can::bxcan::{Frame, StandardId};
12use embassy_stm32::can::Can; 9use embassy_stm32::can::Can;
13use embassy_stm32::gpio::{Input, Pull}; 10use embassy_stm32::gpio::{Input, Pull};
11use {defmt_rtt as _, panic_probe as _};
14 12
15#[entry] 13#[entry]
16fn main() -> ! { 14fn main() -> ! {
diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs
index 92d87cedf..8e69e89d1 100644
--- a/examples/stm32f4/src/bin/hello.rs
+++ b/examples/stm32f4/src/bin/hello.rs
@@ -6,11 +6,8 @@ use defmt::info;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
9use embassy_stm32::Config; 9use embassy_stm32::{Config, Peripherals};
10use embassy_stm32::Peripherals; 10use {defmt_rtt as _, panic_probe as _};
11
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 11
15fn config() -> Config { 12fn config() -> Config {
16 let mut config = Config::default(); 13 let mut config = Config::default();
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs
index 684295609..4f2cf9a6f 100644
--- a/examples/stm32f4/src/bin/multiprio.rs
+++ b/examples/stm32f4/src/bin/multiprio.rs
@@ -57,16 +57,14 @@
57#![no_main] 57#![no_main]
58#![feature(type_alias_impl_trait)] 58#![feature(type_alias_impl_trait)]
59 59
60use defmt::*;
61use defmt_rtt as _; // global logger
62use panic_probe as _;
63
64use cortex_m_rt::entry; 60use cortex_m_rt::entry;
61use defmt::*;
65use embassy::time::{Duration, Instant, Timer}; 62use embassy::time::{Duration, Instant, Timer};
66use embassy::util::Forever; 63use embassy::util::Forever;
67use embassy_stm32::executor::{Executor, InterruptExecutor}; 64use embassy_stm32::executor::{Executor, InterruptExecutor};
68use embassy_stm32::interrupt; 65use embassy_stm32::interrupt;
69use embassy_stm32::interrupt::InterruptExt; 66use embassy_stm32::interrupt::InterruptExt;
67use {defmt_rtt as _, panic_probe as _};
70 68
71#[embassy::task] 69#[embassy::task]
72async fn run_high() { 70async fn run_high() {
diff --git a/examples/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs
index eab0fad4a..b08d26f49 100644
--- a/examples/stm32f4/src/bin/sdmmc.rs
+++ b/examples/stm32f4/src/bin/sdmmc.rs
@@ -2,14 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_stm32::sdmmc::Sdmmc; 7use embassy_stm32::sdmmc::Sdmmc;
11use embassy_stm32::time::U32Ext; 8use embassy_stm32::time::U32Ext;
12use embassy_stm32::{interrupt, Config, Peripherals}; 9use embassy_stm32::{interrupt, Config, Peripherals};
10use {defmt_rtt as _, panic_probe as _};
13 11
14fn config() -> Config { 12fn config() -> Config {
15 let mut config = Config::default(); 13 let mut config = Config::default();
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs
index 69be81432..05b48f478 100644
--- a/examples/stm32f4/src/bin/spi.rs
+++ b/examples/stm32f4/src/bin/spi.rs
@@ -2,15 +2,13 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use cortex_m_rt::entry; 5use cortex_m_rt::entry;
9use defmt::*; 6use defmt::*;
10use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
11use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
12use embassy_stm32::spi::{Config, Spi}; 9use embassy_stm32::spi::{Config, Spi};
13use embassy_stm32::time::Hertz; 10use embassy_stm32::time::Hertz;
11use {defmt_rtt as _, panic_probe as _};
14 12
15#[entry] 13#[entry]
16fn main() -> ! { 14fn main() -> ! {
diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs
index 1bf9b856d..f3c0f2cd5 100644
--- a/examples/stm32f4/src/bin/spi_dma.rs
+++ b/examples/stm32f4/src/bin/spi_dma.rs
@@ -4,14 +4,14 @@
4 4
5use core::fmt::Write; 5use core::fmt::Write;
6use core::str::from_utf8; 6use core::str::from_utf8;
7
7use defmt::*; 8use defmt::*;
8use defmt_rtt as _; // global logger
9use embassy::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; 12use embassy_stm32::Peripherals;
13use heapless::String; 13use heapless::String;
14use panic_probe as _; 14use {defmt_rtt as _, panic_probe as _};
15 15
16#[embassy::main] 16#[embassy::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 17async fn main(_spawner: Spawner, p: Peripherals) {
@@ -32,9 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
32 let mut write: String<128> = String::new(); 32 let mut write: String<128> = String::new();
33 let mut read = [0; 128]; 33 let mut read = [0; 128];
34 core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); 34 core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap();
35 spi.transfer(&mut read[0..write.len()], write.as_bytes()) 35 spi.transfer(&mut read[0..write.len()], write.as_bytes()).await.ok();
36 .await
37 .ok();
38 info!("read via spi+dma: {}", from_utf8(&read).unwrap()); 36 info!("read via spi+dma: {}", from_utf8(&read).unwrap());
39 } 37 }
40} 38}
diff --git a/examples/stm32f4/src/bin/usart.rs b/examples/stm32f4/src/bin/usart.rs
index a302667e2..90ad882b8 100644
--- a/examples/stm32f4/src/bin/usart.rs
+++ b/examples/stm32f4/src/bin/usart.rs
@@ -4,10 +4,9 @@
4 4
5use cortex_m_rt::entry; 5use cortex_m_rt::entry;
6use defmt::*; 6use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
9use embassy_stm32::usart::{Config, Uart}; 8use embassy_stm32::usart::{Config, Uart};
10use panic_probe as _; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[entry] 11#[entry]
13fn main() -> ! { 12fn main() -> ! {
diff --git a/examples/stm32f4/src/bin/usart_buffered.rs b/examples/stm32f4/src/bin/usart_buffered.rs
index 2a613ee4f..039e43bd2 100644
--- a/examples/stm32f4/src/bin/usart_buffered.rs
+++ b/examples/stm32f4/src/bin/usart_buffered.rs
@@ -3,13 +3,12 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
9use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; 8use embassy_stm32::usart::{BufferedUart, Config, State, Uart};
10use embassy_stm32::{interrupt, Peripherals}; 9use embassy_stm32::{interrupt, Peripherals};
11use embedded_io::asynch::BufRead; 10use embedded_io::asynch::BufRead;
12use panic_probe as _; 11use {defmt_rtt as _, panic_probe as _};
13 12
14#[embassy::main] 13#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs
index cf45b71c5..8d06f8439 100644
--- a/examples/stm32f4/src/bin/usart_dma.rs
+++ b/examples/stm32f4/src/bin/usart_dma.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::fmt::Write; 5use core::fmt::Write;
6
6use defmt::*; 7use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy::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; 11use embassy_stm32::Peripherals;
12use heapless::String; 12use heapless::String;
13use panic_probe as _; 13use {defmt_rtt as _, panic_probe as _};
14 14
15#[embassy::main] 15#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 16async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f7/build.rs b/examples/stm32f7/build.rs
index b72dd55ec..c4e15f19c 100644
--- a/examples/stm32f7/build.rs
+++ b/examples/stm32f7/build.rs
@@ -1,7 +1,8 @@
1//! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs 1//! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs
2use std::env; 2use std::env;
3use std::fs::File; 3use std::fs::File;
4use std::io::{self, prelude::*}; 4use std::io::prelude::*;
5use std::io::{self};
5use std::path::PathBuf; 6use std::path::PathBuf;
6 7
7#[derive(Debug)] 8#[derive(Debug)]
diff --git a/examples/stm32f7/src/bin/adc.rs b/examples/stm32f7/src/bin/adc.rs
index 87f5d30dd..fc8359622 100644
--- a/examples/stm32f7/src/bin/adc.rs
+++ b/examples/stm32f7/src/bin/adc.rs
@@ -2,14 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy::time::{Delay, Duration, Timer}; 7use embassy::time::{Delay, Duration, Timer};
11use embassy_stm32::adc::Adc; 8use embassy_stm32::adc::Adc;
12use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _};
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f7/src/bin/blinky.rs b/examples/stm32f7/src/bin/blinky.rs
index 8b85ca96d..907492b3d 100644
--- a/examples/stm32f7/src/bin/blinky.rs
+++ b/examples/stm32f7/src/bin/blinky.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f7/src/bin/button.rs b/examples/stm32f7/src/bin/button.rs
index 4f9af7fbd..b13e64531 100644
--- a/examples/stm32f7/src/bin/button.rs
+++ b/examples/stm32f7/src/bin/button.rs
@@ -4,9 +4,8 @@
4 4
5use cortex_m_rt::entry; 5use cortex_m_rt::entry;
6use defmt::*; 6use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use panic_probe as _; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[entry] 10#[entry]
12fn main() -> ! { 11fn main() -> ! {
diff --git a/examples/stm32f7/src/bin/button_exti.rs b/examples/stm32f7/src/bin/button_exti.rs
index 78f2e6ee2..24ece9927 100644
--- a/examples/stm32f7/src/bin/button_exti.rs
+++ b/examples/stm32f7/src/bin/button_exti.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs
index af012f826..dc0b3c605 100644
--- a/examples/stm32f7/src/bin/eth.rs
+++ b/examples/stm32f7/src/bin/eth.rs
@@ -13,13 +13,10 @@ use embassy_stm32::eth::{Ethernet, State};
13use embassy_stm32::peripherals::ETH; 13use embassy_stm32::peripherals::ETH;
14use embassy_stm32::rng::Rng; 14use embassy_stm32::rng::Rng;
15use embassy_stm32::time::U32Ext; 15use embassy_stm32::time::U32Ext;
16use embassy_stm32::Config; 16use embassy_stm32::{interrupt, Config, Peripherals};
17use embassy_stm32::{interrupt, Peripherals};
18use embedded_io::asynch::Write; 17use embedded_io::asynch::Write;
19
20use defmt_rtt as _; // global logger
21use panic_probe as _;
22use rand_core::RngCore; 18use rand_core::RngCore;
19use {defmt_rtt as _, panic_probe as _};
23 20
24macro_rules! forever { 21macro_rules! forever {
25 ($val:expr) => {{ 22 ($val:expr) => {{
diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs
index 9eb8e4b94..af66275d4 100644
--- a/examples/stm32f7/src/bin/flash.rs
+++ b/examples/stm32f7/src/bin/flash.rs
@@ -8,9 +8,7 @@ use embassy::time::{Duration, Timer};
8use embassy_stm32::flash::Flash; 8use embassy_stm32::flash::Flash;
9use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 10use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
11 11use {defmt_rtt as _, panic_probe as _};
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 12
15#[embassy::main] 13#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
@@ -40,8 +38,8 @@ async fn main(_spawner: Spawner, p: Peripherals) {
40 unwrap!(f.write( 38 unwrap!(f.write(
41 ADDR, 39 ADDR,
42 &[ 40 &[
43 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 41 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
44 25, 26, 27, 28, 29, 30, 31, 32 42 30, 31, 32
45 ] 43 ]
46 )); 44 ));
47 45
@@ -52,8 +50,8 @@ async fn main(_spawner: Spawner, p: Peripherals) {
52 assert_eq!( 50 assert_eq!(
53 &buf[..], 51 &buf[..],
54 &[ 52 &[
55 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 53 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
56 25, 26, 27, 28, 29, 30, 31, 32 54 30, 31, 32
57 ] 55 ]
58 ); 56 );
59} 57}
diff --git a/examples/stm32f7/src/bin/hello.rs b/examples/stm32f7/src/bin/hello.rs
index 92d87cedf..8e69e89d1 100644
--- a/examples/stm32f7/src/bin/hello.rs
+++ b/examples/stm32f7/src/bin/hello.rs
@@ -6,11 +6,8 @@ use defmt::info;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
9use embassy_stm32::Config; 9use embassy_stm32::{Config, Peripherals};
10use embassy_stm32::Peripherals; 10use {defmt_rtt as _, panic_probe as _};
11
12use defmt_rtt as _; // global logger
13use panic_probe as _;
14 11
15fn config() -> Config { 12fn config() -> Config {
16 let mut config = Config::default(); 13 let mut config = Config::default();
diff --git a/examples/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs
index dae07c303..1af1061ba 100644
--- a/examples/stm32f7/src/bin/sdmmc.rs
+++ b/examples/stm32f7/src/bin/sdmmc.rs
@@ -2,14 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_stm32::sdmmc::Sdmmc; 7use embassy_stm32::sdmmc::Sdmmc;
11use embassy_stm32::time::U32Ext; 8use embassy_stm32::time::U32Ext;
12use embassy_stm32::{interrupt, Config, Peripherals}; 9use embassy_stm32::{interrupt, Config, Peripherals};
10use {defmt_rtt as _, panic_probe as _};
13 11
14fn config() -> Config { 12fn config() -> Config {
15 let mut config = Config::default(); 13 let mut config = Config::default();
diff --git a/examples/stm32f7/src/bin/usart_dma.rs b/examples/stm32f7/src/bin/usart_dma.rs
index 69fa21a0d..d8551620c 100644
--- a/examples/stm32f7/src/bin/usart_dma.rs
+++ b/examples/stm32f7/src/bin/usart_dma.rs
@@ -3,15 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::fmt::Write; 5use core::fmt::Write;
6
6use defmt::*; 7use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy::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; 11use embassy_stm32::Peripherals;
12use panic_probe as _;
13
14use heapless::String; 12use heapless::String;
13use {defmt_rtt as _, panic_probe as _};
15 14
16#[embassy::main] 15#[embassy::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 16async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32g0/src/bin/blinky.rs b/examples/stm32g0/src/bin/blinky.rs
index 8b85ca96d..907492b3d 100644
--- a/examples/stm32g0/src/bin/blinky.rs
+++ b/examples/stm32g0/src/bin/blinky.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32g0/src/bin/button.rs b/examples/stm32g0/src/bin/button.rs
index 78d7ba1f2..72a3f5cbf 100644
--- a/examples/stm32g0/src/bin/button.rs
+++ b/examples/stm32g0/src/bin/button.rs
@@ -4,9 +4,8 @@
4 4
5use cortex_m_rt::entry; 5use cortex_m_rt::entry;
6use defmt::*; 6use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy_stm32::gpio::{Input, Pull}; 7use embassy_stm32::gpio::{Input, Pull};
9use panic_probe as _; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[entry] 10#[entry]
12fn main() -> ! { 11fn main() -> ! {
diff --git a/examples/stm32g0/src/bin/button_exti.rs b/examples/stm32g0/src/bin/button_exti.rs
index 4b1cadcb5..924feeb33 100644
--- a/examples/stm32g0/src/bin/button_exti.rs
+++ b/examples/stm32g0/src/bin/button_exti.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs
index 92ec2b579..cd4883276 100644
--- a/examples/stm32g4/src/bin/blinky.rs
+++ b/examples/stm32g4/src/bin/blinky.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32g4/src/bin/button.rs b/examples/stm32g4/src/bin/button.rs
index f6c981309..15abd86d9 100644
--- a/examples/stm32g4/src/bin/button.rs
+++ b/examples/stm32g4/src/bin/button.rs
@@ -4,9 +4,8 @@
4 4
5use cortex_m_rt::entry; 5use cortex_m_rt::entry;
6use defmt::*; 6use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy_stm32::gpio::{Input, Pull}; 7use embassy_stm32::gpio::{Input, Pull};
9use panic_probe as _; 8use {defmt_rtt as _, panic_probe as _};
10 9
11#[entry] 10#[entry]
12fn main() -> ! { 11fn main() -> ! {
diff --git a/examples/stm32g4/src/bin/button_exti.rs b/examples/stm32g4/src/bin/button_exti.rs
index 78f2e6ee2..24ece9927 100644
--- a/examples/stm32g4/src/bin/button_exti.rs
+++ b/examples/stm32g4/src/bin/button_exti.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs
index 3770f6f36..525b6001f 100644
--- a/examples/stm32g4/src/bin/pwm.rs
+++ b/examples/stm32g4/src/bin/pwm.rs
@@ -3,13 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::pwm::{simple_pwm::SimplePwm, Channel}; 8use embassy_stm32::pwm::simple_pwm::SimplePwm;
9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::U32Ext; 10use embassy_stm32::time::U32Ext;
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use panic_probe as _; 12use {defmt_rtt as _, panic_probe as _};
13 13
14#[embassy::main] 14#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs
index b12bca307..e24390741 100644
--- a/examples/stm32h7/src/bin/adc.rs
+++ b/examples/stm32h7/src/bin/adc.rs
@@ -2,16 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*;
5use embassy::executor::Spawner; 6use embassy::executor::Spawner;
6use embassy::time::{Delay, Duration, Timer}; 7use embassy::time::{Delay, Duration, Timer};
7use embassy_stm32::adc::{Adc, SampleTime}; 8use embassy_stm32::adc::{Adc, SampleTime};
8use embassy_stm32::rcc::AdcClockSource; 9use embassy_stm32::rcc::AdcClockSource;
9use embassy_stm32::time::U32Ext; 10use embassy_stm32::time::U32Ext;
10use embassy_stm32::{Config, Peripherals}; 11use embassy_stm32::{Config, Peripherals};
11 12use {defmt_rtt as _, panic_probe as _};
12use defmt::*;
13use defmt_rtt as _; // global logger
14use panic_probe as _;
15 13
16pub fn config() -> Config { 14pub fn config() -> Config {
17 let mut config = Config::default(); 15 let mut config = Config::default();
diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs
index 2329125a6..7982f4a0b 100644
--- a/examples/stm32h7/src/bin/blinky.rs
+++ b/examples/stm32h7/src/bin/blinky.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32h7/src/bin/button_exti.rs b/examples/stm32h7/src/bin/button_exti.rs
index 78f2e6ee2..24ece9927 100644
--- a/examples/stm32h7/src/bin/button_exti.rs
+++ b/examples/stm32h7/src/bin/button_exti.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs
index 3311ba858..918eab659 100644
--- a/examples/stm32h7/src/bin/camera.rs
+++ b/examples/stm32h7/src/bin/camera.rs
@@ -7,14 +7,10 @@ use embassy::time::{Duration, Timer};
7use embassy_stm32::dcmi::{self, *}; 7use embassy_stm32::dcmi::{self, *};
8use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::i2c::I2c; 9use embassy_stm32::i2c::I2c;
10use embassy_stm32::interrupt;
11use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; 10use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
12use embassy_stm32::time::U32Ext; 11use embassy_stm32::time::U32Ext;
13use embassy_stm32::Config; 12use embassy_stm32::{interrupt, Config, Peripherals};
14use embassy_stm32::Peripherals; 13use {defmt_rtt as _, panic_probe as _};
15
16use defmt_rtt as _; // global logger
17use panic_probe as _;
18 14
19#[allow(unused)] 15#[allow(unused)]
20pub fn config() -> Config { 16pub fn config() -> Config {
@@ -43,15 +39,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
43 39
44 let mut led = Output::new(p.PE3, Level::High, Speed::Low); 40 let mut led = Output::new(p.PE3, Level::High, Speed::Low);
45 let i2c_irq = interrupt::take!(I2C1_EV); 41 let i2c_irq = interrupt::take!(I2C1_EV);
46 let cam_i2c = I2c::new( 42 let cam_i2c = I2c::new(p.I2C1, p.PB8, p.PB9, i2c_irq, p.DMA1_CH1, p.DMA1_CH2, 100u32.khz());
47 p.I2C1,
48 p.PB8,
49 p.PB9,
50 i2c_irq,
51 p.DMA1_CH1,
52 p.DMA1_CH2,
53 100u32.khz(),
54 );
55 43
56 let mut camera = Ov7725::new(cam_i2c, mco); 44 let mut camera = Ov7725::new(cam_i2c, mco);
57 45
@@ -60,17 +48,13 @@ async fn main(_spawner: Spawner, p: Peripherals) {
60 let manufacturer_id = defmt::unwrap!(camera.read_manufacturer_id().await); 48 let manufacturer_id = defmt::unwrap!(camera.read_manufacturer_id().await);
61 let camera_id = defmt::unwrap!(camera.read_product_id().await); 49 let camera_id = defmt::unwrap!(camera.read_product_id().await);
62 50
63 defmt::info!( 51 defmt::info!("manufacturer: 0x{:x}, pid: 0x{:x}", manufacturer_id, camera_id);
64 "manufacturer: 0x{:x}, pid: 0x{:x}",
65 manufacturer_id,
66 camera_id
67 );
68 52
69 let dcmi_irq = interrupt::take!(DCMI); 53 let dcmi_irq = interrupt::take!(DCMI);
70 let config = dcmi::Config::default(); 54 let config = dcmi::Config::default();
71 let mut dcmi = Dcmi::new_8bit( 55 let mut dcmi = Dcmi::new_8bit(
72 p.DCMI, p.DMA1_CH0, dcmi_irq, p.PC6, p.PC7, p.PE0, p.PE1, p.PE4, p.PD3, p.PE5, p.PE6, 56 p.DCMI, p.DMA1_CH0, dcmi_irq, p.PC6, p.PC7, p.PE0, p.PE1, p.PE4, p.PD3, p.PE5, p.PE6, p.PB7, p.PA4, p.PA6,
73 p.PB7, p.PA4, p.PA6, config, 57 config,
74 ); 58 );
75 59
76 defmt::info!("attempting capture"); 60 defmt::info!("attempting capture");
@@ -258,10 +242,8 @@ mod ov7725 {
258 let com3 = self.read(Register::Com3).await?; 242 let com3 = self.read(Register::Com3).await?;
259 let vflip = com3 & 0x80 > 0; 243 let vflip = com3 & 0x80 > 0;
260 244
261 self.modify(Register::HRef, |reg| { 245 self.modify(Register::HRef, |reg| reg & 0xbf | if vflip { 0x40 } else { 0x40 })
262 reg & 0xbf | if vflip { 0x40 } else { 0x40 } 246 .await?;
263 })
264 .await?;
265 247
266 if horizontal <= 320 || vertical <= 240 { 248 if horizontal <= 320 || vertical <= 240 {
267 self.write(Register::HStart, 0x3f).await?; 249 self.write(Register::HStart, 0x3f).await?;
@@ -291,11 +273,7 @@ mod ov7725 {
291 .map_err(Error::I2c) 273 .map_err(Error::I2c)
292 } 274 }
293 275
294 async fn modify<F: FnOnce(u8) -> u8>( 276 async fn modify<F: FnOnce(u8) -> u8>(&mut self, register: Register, f: F) -> Result<(), Error<Bus::Error>> {
295 &mut self,
296 register: Register,
297 f: F,
298 ) -> Result<(), Error<Bus::Error>> {
299 let value = self.read(register).await?; 277 let value = self.read(register).await?;
300 let value = f(value); 278 let value = f(value);
301 self.write(register, value).await 279 self.write(register, value).await
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs
index 86c874a6a..8ed33350c 100644
--- a/examples/stm32h7/src/bin/dac.rs
+++ b/examples/stm32h7/src/bin/dac.rs
@@ -2,14 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use cortex_m_rt::entry; 5use cortex_m_rt::entry;
9use defmt::*; 6use defmt::*;
10use embassy_stm32::dac::{Channel, Dac, Value}; 7use embassy_stm32::dac::{Channel, Dac, Value};
11use embassy_stm32::time::U32Ext; 8use embassy_stm32::time::U32Ext;
12use embassy_stm32::Config; 9use embassy_stm32::Config;
10use {defmt_rtt as _, panic_probe as _};
13 11
14pub fn config() -> Config { 12pub fn config() -> Config {
15 let mut config = Config::default(); 13 let mut config = Config::default();
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs
index 649ff2605..6dabadc4b 100644
--- a/examples/stm32h7/src/bin/eth.rs
+++ b/examples/stm32h7/src/bin/eth.rs
@@ -13,13 +13,10 @@ use embassy_stm32::eth::{Ethernet, State};
13use embassy_stm32::peripherals::ETH; 13use embassy_stm32::peripherals::ETH;
14use embassy_stm32::rng::Rng; 14use embassy_stm32::rng::Rng;
15use embassy_stm32::time::U32Ext; 15use embassy_stm32::time::U32Ext;
16use embassy_stm32::Config; 16use embassy_stm32::{interrupt, Config, Peripherals};
17use embassy_stm32::{interrupt, Peripherals};
18use embedded_io::asynch::Write; 17use embedded_io::asynch::Write;
19
20use defmt_rtt as _; // global logger
21use panic_probe as _;
22use rand_core::RngCore; 18use rand_core::RngCore;
19use {defmt_rtt as _, panic_probe as _};
23 20
24macro_rules! forever { 21macro_rules! forever {
25 ($val:expr) => {{ 22 ($val:expr) => {{
diff --git a/examples/stm32h7/src/bin/flash.rs b/examples/stm32h7/src/bin/flash.rs
index b008c0884..5f97d2b31 100644
--- a/examples/stm32h7/src/bin/flash.rs
+++ b/examples/stm32h7/src/bin/flash.rs
@@ -3,13 +3,12 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::flash::Flash; 8use embassy_stm32::flash::Flash;
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 10use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
12use panic_probe as _; 11use {defmt_rtt as _, panic_probe as _};
13 12
14#[embassy::main] 13#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
@@ -39,8 +38,8 @@ async fn main(_spawner: Spawner, p: Peripherals) {
39 unwrap!(f.write( 38 unwrap!(f.write(
40 ADDR, 39 ADDR,
41 &[ 40 &[
42 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 41 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
43 25, 26, 27, 28, 29, 30, 31, 32 42 30, 31, 32
44 ] 43 ]
45 )); 44 ));
46 45
@@ -51,8 +50,8 @@ async fn main(_spawner: Spawner, p: Peripherals) {
51 assert_eq!( 50 assert_eq!(
52 &buf[..], 51 &buf[..],
53 &[ 52 &[
54 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 53 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
55 25, 26, 27, 28, 29, 30, 31, 32 54 30, 31, 32
56 ] 55 ]
57 ); 56 );
58} 57}
diff --git a/examples/stm32h7/src/bin/fmc.rs b/examples/stm32h7/src/bin/fmc.rs
index ba8215d6a..2f55479c1 100644
--- a/examples/stm32h7/src/bin/fmc.rs
+++ b/examples/stm32h7/src/bin/fmc.rs
@@ -3,14 +3,12 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Delay, Duration, Timer}; 7use embassy::time::{Delay, Duration, Timer};
9use embassy_stm32::fmc::Fmc; 8use embassy_stm32::fmc::Fmc;
10use embassy_stm32::time::U32Ext; 9use embassy_stm32::time::U32Ext;
11use embassy_stm32::Config; 10use embassy_stm32::{Config, Peripherals};
12use embassy_stm32::Peripherals; 11use {defmt_rtt as _, panic_probe as _};
13use panic_probe as _;
14 12
15pub fn config() -> Config { 13pub fn config() -> Config {
16 let mut config = Config::default(); 14 let mut config = Config::default();
@@ -62,16 +60,8 @@ async fn main(_spawner: Spawner, p: Peripherals) {
62 const REGION_WRITE_BACK: u32 = 0x01; 60 const REGION_WRITE_BACK: u32 = 0x01;
63 const REGION_ENABLE: u32 = 0x01; 61 const REGION_ENABLE: u32 = 0x01;
64 62
65 crate::assert_eq!( 63 crate::assert_eq!(size & (size - 1), 0, "SDRAM memory region size must be a power of 2");
66 size & (size - 1), 64 crate::assert_eq!(size & 0x1F, 0, "SDRAM memory region size must be 32 bytes or more");
67 0,
68 "SDRAM memory region size must be a power of 2"
69 );
70 crate::assert_eq!(
71 size & 0x1F,
72 0,
73 "SDRAM memory region size must be 32 bytes or more"
74 );
75 fn log2minus1(sz: u32) -> u32 { 65 fn log2minus1(sz: u32) -> u32 {
76 for i in 5..=31 { 66 for i in 5..=31 {
77 if sz == (1 << i) { 67 if sz == (1 << i) {
@@ -104,8 +94,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
104 94
105 // Enable 95 // Enable
106 unsafe { 96 unsafe {
107 mpu.ctrl 97 mpu.ctrl.modify(|r| r | MPU_DEFAULT_MMAP_FOR_PRIVILEGED | MPU_ENABLE);
108 .modify(|r| r | MPU_DEFAULT_MMAP_FOR_PRIVILEGED | MPU_ENABLE);
109 98
110 scb.shcsr.modify(|r| r | MEMFAULTENA); 99 scb.shcsr.modify(|r| r | MEMFAULTENA);
111 100
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs
index 647c5a8fa..3a728a0dd 100644
--- a/examples/stm32h7/src/bin/low_level_timer_api.rs
+++ b/examples/stm32h7/src/bin/low_level_timer_api.rs
@@ -3,8 +3,6 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::marker::PhantomData; 5use core::marker::PhantomData;
6use defmt_rtt as _; // global logger
7use panic_probe as _;
8 6
9use defmt::*; 7use defmt::*;
10use embassy::executor::Spawner; 8use embassy::executor::Spawner;
@@ -13,9 +11,8 @@ use embassy_stm32::gpio::low_level::AFType;
13use embassy_stm32::gpio::Speed; 11use embassy_stm32::gpio::Speed;
14use embassy_stm32::pwm::*; 12use embassy_stm32::pwm::*;
15use embassy_stm32::time::{Hertz, U32Ext}; 13use embassy_stm32::time::{Hertz, U32Ext};
16use embassy_stm32::unborrow; 14use embassy_stm32::{unborrow, Config, Peripherals, Unborrow};
17use embassy_stm32::Unborrow; 15use {defmt_rtt as _, panic_probe as _};
18use embassy_stm32::{Config, Peripherals};
19 16
20pub fn config() -> Config { 17pub fn config() -> Config {
21 let mut config = Config::default(); 18 let mut config = Config::default();
@@ -108,25 +105,18 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
108 105
109 pub fn enable(&mut self, channel: Channel) { 106 pub fn enable(&mut self, channel: Channel) {
110 unsafe { 107 unsafe {
111 T::regs_gp32() 108 T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true));
112 .ccer()
113 .modify(|w| w.set_cce(channel.raw(), true));
114 } 109 }
115 } 110 }
116 111
117 pub fn disable(&mut self, channel: Channel) { 112 pub fn disable(&mut self, channel: Channel) {
118 unsafe { 113 unsafe {
119 T::regs_gp32() 114 T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false));
120 .ccer()
121 .modify(|w| w.set_cce(channel.raw(), false));
122 } 115 }
123 } 116 }
124 117
125 pub fn set_freq<F: Into<Hertz>>(&mut self, freq: F) { 118 pub fn set_freq<F: Into<Hertz>>(&mut self, freq: F) {
126 <T as embassy_stm32::timer::low_level::GeneralPurpose32bitInstance>::set_frequency( 119 <T as embassy_stm32::timer::low_level::GeneralPurpose32bitInstance>::set_frequency(&mut self.inner, freq);
127 &mut self.inner,
128 freq,
129 );
130 } 120 }
131 121
132 pub fn get_max_duty(&self) -> u32 { 122 pub fn get_max_duty(&self) -> u32 {
@@ -135,10 +125,6 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
135 125
136 pub fn set_duty(&mut self, channel: Channel, duty: u32) { 126 pub fn set_duty(&mut self, channel: Channel, duty: u32) {
137 defmt::assert!(duty < self.get_max_duty()); 127 defmt::assert!(duty < self.get_max_duty());
138 unsafe { 128 unsafe { T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) }
139 T::regs_gp32()
140 .ccr(channel.raw())
141 .modify(|w| w.set_ccr(duty))
142 }
143 } 129 }
144} 130}
diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs
index a6735036f..6f03b5479 100644
--- a/examples/stm32h7/src/bin/mco.rs
+++ b/examples/stm32h7/src/bin/mco.rs
@@ -3,13 +3,12 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; 9use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
11use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
12use panic_probe as _; 11use {defmt_rtt as _, panic_probe as _};
13 12
14#[embassy::main] 13#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs
index c33ba066e..0e85b8d80 100644
--- a/examples/stm32h7/src/bin/pwm.rs
+++ b/examples/stm32h7/src/bin/pwm.rs
@@ -3,13 +3,13 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::pwm::{simple_pwm::SimplePwm, Channel}; 8use embassy_stm32::pwm::simple_pwm::SimplePwm;
9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::U32Ext; 10use embassy_stm32::time::U32Ext;
11use embassy_stm32::{Config, Peripherals}; 11use embassy_stm32::{Config, Peripherals};
12use panic_probe as _; 12use {defmt_rtt as _, panic_probe as _};
13 13
14pub fn config() -> Config { 14pub fn config() -> Config {
15 let mut config = Config::default(); 15 let mut config = Config::default();
diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs
index b914fa709..2b42a6afd 100644
--- a/examples/stm32h7/src/bin/rng.rs
+++ b/examples/stm32h7/src/bin/rng.rs
@@ -3,11 +3,10 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::rng::Rng; 7use embassy_stm32::rng::Rng;
9use embassy_stm32::Peripherals; 8use embassy_stm32::Peripherals;
10use panic_probe as _; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy::main] 11#[embassy::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs
index c3b2ebcda..4a74780f4 100644
--- a/examples/stm32h7/src/bin/sdmmc.rs
+++ b/examples/stm32h7/src/bin/sdmmc.rs
@@ -2,14 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_stm32::sdmmc::Sdmmc; 7use embassy_stm32::sdmmc::Sdmmc;
11use embassy_stm32::time::U32Ext; 8use embassy_stm32::time::U32Ext;
12use embassy_stm32::{interrupt, Config, Peripherals}; 9use embassy_stm32::{interrupt, Config, Peripherals};
10use {defmt_rtt as _, panic_probe as _};
13 11
14fn config() -> Config { 12fn config() -> Config {
15 let mut config = Config::default(); 13 let mut config = Config::default();
diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs
index c63b2836c..f798b1c92 100644
--- a/examples/stm32h7/src/bin/signal.rs
+++ b/examples/stm32h7/src/bin/signal.rs
@@ -2,17 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5// global logger
6use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
7use defmt_rtt as _;
8
9use panic_probe as _;
10
11use embassy::channel::signal::Signal; 6use embassy::channel::signal::Signal;
12use embassy::executor::Spawner; 7use embassy::executor::Spawner;
13use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
14
15use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _};
16 11
17static SIGNAL: Signal<u32> = Signal::new(); 12static SIGNAL: Signal<u32> = Signal::new();
18 13
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs
index a0acb03db..d4ee44292 100644
--- a/examples/stm32h7/src/bin/spi.rs
+++ b/examples/stm32h7/src/bin/spi.rs
@@ -2,21 +2,19 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use core::fmt::Write; 5use core::fmt::Write;
9use core::str::from_utf8; 6use core::str::from_utf8;
7
10use cortex_m_rt::entry; 8use cortex_m_rt::entry;
11use defmt::*; 9use defmt::*;
12use embassy::executor::Executor; 10use embassy::executor::Executor;
13use embassy::util::Forever; 11use embassy::util::Forever;
14use embassy_stm32::dma::NoDma; 12use embassy_stm32::dma::NoDma;
15use embassy_stm32::peripherals::SPI3; 13use embassy_stm32::peripherals::SPI3;
16use embassy_stm32::spi;
17use embassy_stm32::time::U32Ext; 14use embassy_stm32::time::U32Ext;
18use embassy_stm32::Config; 15use embassy_stm32::{spi, Config};
19use heapless::String; 16use heapless::String;
17use {defmt_rtt as _, panic_probe as _};
20 18
21pub fn config() -> Config { 19pub fn config() -> Config {
22 let mut config = Config::default(); 20 let mut config = Config::default();
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs
index 8f77b1d09..003bc7add 100644
--- a/examples/stm32h7/src/bin/spi_dma.rs
+++ b/examples/stm32h7/src/bin/spi_dma.rs
@@ -2,20 +2,18 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use core::fmt::Write; 5use core::fmt::Write;
9use core::str::from_utf8; 6use core::str::from_utf8;
7
10use cortex_m_rt::entry; 8use cortex_m_rt::entry;
11use defmt::*; 9use defmt::*;
12use embassy::executor::Executor; 10use embassy::executor::Executor;
13use embassy::util::Forever; 11use embassy::util::Forever;
14use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; 12use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3};
15use embassy_stm32::spi;
16use embassy_stm32::time::U32Ext; 13use embassy_stm32::time::U32Ext;
17use embassy_stm32::Config; 14use embassy_stm32::{spi, Config};
18use heapless::String; 15use heapless::String;
16use {defmt_rtt as _, panic_probe as _};
19 17
20pub fn config() -> Config { 18pub fn config() -> Config {
21 let mut config = Config::default(); 19 let mut config = Config::default();
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs
index 0982a6ac6..fc3db5a33 100644
--- a/examples/stm32h7/src/bin/usart.rs
+++ b/examples/stm32h7/src/bin/usart.rs
@@ -2,15 +2,13 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use cortex_m_rt::entry;
5use defmt::*; 6use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Executor; 7use embassy::executor::Executor;
8use embassy::util::Forever; 8use embassy::util::Forever;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use panic_probe as _; 11use {defmt_rtt as _, panic_probe as _};
12
13use cortex_m_rt::entry;
14 12
15#[embassy::task] 13#[embassy::task]
16async fn main_task() { 14async fn main_task() {
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs
index 74de8b2a3..d3325b0c1 100644
--- a/examples/stm32h7/src/bin/usart_dma.rs
+++ b/examples/stm32h7/src/bin/usart_dma.rs
@@ -3,16 +3,15 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::fmt::Write; 5use core::fmt::Write;
6
7use cortex_m_rt::entry;
6use defmt::*; 8use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy::executor::Executor; 9use embassy::executor::Executor;
9use embassy::util::Forever; 10use embassy::util::Forever;
10use embassy_stm32::dma::NoDma; 11use embassy_stm32::dma::NoDma;
11use embassy_stm32::usart::{Config, Uart}; 12use embassy_stm32::usart::{Config, Uart};
12use panic_probe as _;
13
14use cortex_m_rt::entry;
15use heapless::String; 13use heapless::String;
14use {defmt_rtt as _, panic_probe as _};
16 15
17#[embassy::task] 16#[embassy::task]
18async fn main_task() { 17async fn main_task() {
diff --git a/examples/stm32h7/src/bin/usart_split.rs b/examples/stm32h7/src/bin/usart_split.rs
index eb3f9578c..678d8c911 100644
--- a/examples/stm32h7/src/bin/usart_split.rs
+++ b/examples/stm32h7/src/bin/usart_split.rs
@@ -3,17 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::blocking_mutex::raw::ThreadModeRawMutex; 6use embassy::blocking_mutex::raw::ThreadModeRawMutex;
8use embassy::channel::mpmc::Channel; 7use embassy::channel::mpmc::Channel;
9use embassy::executor::Spawner; 8use embassy::executor::Spawner;
10use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
11use embassy_stm32::{ 10use embassy_stm32::peripherals::{DMA1_CH1, UART7};
12 peripherals::{DMA1_CH1, UART7}, 11use embassy_stm32::usart::{Config, Uart, UartRx};
13 usart::{Config, Uart, UartRx}, 12use embassy_stm32::Peripherals;
14 Peripherals, 13use {defmt_rtt as _, panic_probe as _};
15};
16use panic_probe as _;
17 14
18#[embassy::task] 15#[embassy::task]
19async fn writer(mut usart: Uart<'static, UART7, NoDma, NoDma>) { 16async fn writer(mut usart: Uart<'static, UART7, NoDma, NoDma>) {
diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs
index 72f13f06d..e027192bc 100644
--- a/examples/stm32l0/src/bin/blinky.rs
+++ b/examples/stm32l0/src/bin/blinky.rs
@@ -2,14 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
11use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
12use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _};
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs
index dfa91259a..43ea8c2a5 100644
--- a/examples/stm32l0/src/bin/button.rs
+++ b/examples/stm32l0/src/bin/button.rs
@@ -3,11 +3,10 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use embassy_stm32::Peripherals; 8use embassy_stm32::Peripherals;
10use panic_probe as _; 9use {defmt_rtt as _, panic_probe as _};
11 10
12#[embassy::main] 11#[embassy::main]
13async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l0/src/bin/button_exti.rs b/examples/stm32l0/src/bin/button_exti.rs
index b1892e2c6..d87870a01 100644
--- a/examples/stm32l0/src/bin/button_exti.rs
+++ b/examples/stm32l0/src/bin/button_exti.rs
@@ -2,14 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
12use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _};
13 11
14fn config() -> embassy_stm32::Config { 12fn config() -> embassy_stm32::Config {
15 let mut config = embassy_stm32::Config::default(); 13 let mut config = embassy_stm32::Config::default();
diff --git a/examples/stm32l0/src/bin/flash.rs b/examples/stm32l0/src/bin/flash.rs
index c2ccb5b69..a2fec9291 100644
--- a/examples/stm32l0/src/bin/flash.rs
+++ b/examples/stm32l0/src/bin/flash.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
8use embassy_stm32::Peripherals; 8use embassy_stm32::Peripherals;
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l0/src/bin/lorawan.rs b/examples/stm32l0/src/bin/lorawan.rs
index c3b97de53..8b7e8f824 100644
--- a/examples/stm32l0/src/bin/lorawan.rs
+++ b/examples/stm32l0/src/bin/lorawan.rs
@@ -6,20 +6,16 @@
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 defmt_rtt as _; // global logger 9use embassy_lora::sx127x::*;
10use panic_probe as _; 10use embassy_lora::LoraTimer;
11 11use embassy_stm32::exti::ExtiInput;
12use embassy_lora::{sx127x::*, LoraTimer}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::{ 13use embassy_stm32::rng::Rng;
14 exti::ExtiInput, 14use embassy_stm32::time::U32Ext;
15 gpio::{Input, Level, Output, Pull, Speed}, 15use embassy_stm32::{spi, Peripherals};
16 rng::Rng,
17 spi,
18 time::U32Ext,
19 Peripherals,
20};
21use lorawan::default_crypto::DefaultFactory as Crypto; 16use lorawan::default_crypto::DefaultFactory as Crypto;
22use lorawan_device::async_device::{region, Device, JoinMode}; 17use lorawan_device::async_device::{region, Device, JoinMode};
18use {defmt_rtt as _, panic_probe as _};
23 19
24fn config() -> embassy_stm32::Config { 20fn config() -> embassy_stm32::Config {
25 let mut config = embassy_stm32::Config::default(); 21 let mut config = embassy_stm32::Config::default();
@@ -49,13 +45,10 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
49 let ready = Input::new(p.PB4, Pull::Up); 45 let ready = Input::new(p.PB4, Pull::Up);
50 let ready_pin = ExtiInput::new(ready, p.EXTI4); 46 let ready_pin = ExtiInput::new(ready, p.EXTI4);
51 47
52 let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch) 48 let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch).await.unwrap();
53 .await
54 .unwrap();
55 49
56 let region = region::EU868::default().into(); 50 let region = region::EU868::default().into();
57 let mut device: Device<_, Crypto, _, _> = 51 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG));
58 Device::new(region, radio, LoraTimer, Rng::new(p.RNG));
59 52
60 defmt::info!("Joining LoRaWAN network"); 53 defmt::info!("Joining LoRaWAN network");
61 54
diff --git a/examples/stm32l0/src/bin/raw_spawn.rs b/examples/stm32l0/src/bin/raw_spawn.rs
index 4601d85df..dfe2cddb6 100644
--- a/examples/stm32l0/src/bin/raw_spawn.rs
+++ b/examples/stm32l0/src/bin/raw_spawn.rs
@@ -1,17 +1,15 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3 3
4use defmt::*;
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use core::mem; 4use core::mem;
9use cortex_m_rt::entry;
10 5
6use cortex_m_rt::entry;
7use defmt::*;
11use embassy::executor::raw::TaskStorage; 8use embassy::executor::raw::TaskStorage;
12use embassy::executor::Executor; 9use embassy::executor::Executor;
13use embassy::time::{Duration, Timer}; 10use embassy::time::{Duration, Timer};
14use embassy::util::Forever; 11use embassy::util::Forever;
12use {defmt_rtt as _, panic_probe as _};
15 13
16async fn run1() { 14async fn run1() {
17 loop { 15 loop {
diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs
index 5ed783b10..dba0b281d 100644
--- a/examples/stm32l0/src/bin/spi.rs
+++ b/examples/stm32l0/src/bin/spi.rs
@@ -2,17 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_stm32::gpio::{Level, Output, Speed};
11
12use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
8use embassy_stm32::gpio::{Level, Output, Speed};
13use embassy_stm32::spi::{Config, Spi}; 9use embassy_stm32::spi::{Config, Spi};
14use embassy_stm32::time::Hertz; 10use embassy_stm32::time::Hertz;
15use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use {defmt_rtt as _, panic_probe as _};
16 13
17#[embassy::main] 14#[embassy::main]
18async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l0/src/bin/usart_dma.rs b/examples/stm32l0/src/bin/usart_dma.rs
index b3fdcacbe..861241639 100644
--- a/examples/stm32l0/src/bin/usart_dma.rs
+++ b/examples/stm32l0/src/bin/usart_dma.rs
@@ -2,25 +2,15 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9
10use embassy::executor::Spawner; 6use embassy::executor::Spawner;
11use embassy_stm32::usart::{Config, Uart}; 7use embassy_stm32::usart::{Config, Uart};
12use embassy_stm32::Peripherals; 8use embassy_stm32::Peripherals;
9use {defmt_rtt as _, panic_probe as _};
13 10
14#[embassy::main] 11#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 12async fn main(_spawner: Spawner, p: Peripherals) {
16 let mut usart = Uart::new( 13 let mut usart = Uart::new(p.USART1, p.PB7, p.PB6, p.DMA1_CH2, p.DMA1_CH3, Config::default());
17 p.USART1,
18 p.PB7,
19 p.PB6,
20 p.DMA1_CH2,
21 p.DMA1_CH3,
22 Config::default(),
23 );
24 14
25 usart.write(b"Hello Embassy World!\r\n").await.unwrap(); 15 usart.write(b"Hello Embassy World!\r\n").await.unwrap();
26 info!("wrote Hello, starting echo"); 16 info!("wrote Hello, starting echo");
diff --git a/examples/stm32l0/src/bin/usart_irq.rs b/examples/stm32l0/src/bin/usart_irq.rs
index 4413a2945..09b1b0b03 100644
--- a/examples/stm32l0/src/bin/usart_irq.rs
+++ b/examples/stm32l0/src/bin/usart_irq.rs
@@ -2,18 +2,13 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _;
6use embedded_io::asynch::{Read, Write};
7// global logger
8use panic_probe as _;
9
10use defmt::*; 5use defmt::*;
11
12use embassy::executor::Spawner; 6use embassy::executor::Spawner;
13use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
14use embassy_stm32::interrupt;
15use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; 8use embassy_stm32::usart::{BufferedUart, Config, State, Uart};
16use embassy_stm32::Peripherals; 9use embassy_stm32::{interrupt, Peripherals};
10use embedded_io::asynch::{Read, Write};
11use {defmt_rtt as _, panic_probe as _};
17 12
18#[embassy::main] 13#[embassy::main]
19async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l1/src/bin/blinky.rs b/examples/stm32l1/src/bin/blinky.rs
index e81455524..bace53d91 100644
--- a/examples/stm32l1/src/bin/blinky.rs
+++ b/examples/stm32l1/src/bin/blinky.rs
@@ -2,14 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
11use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
12use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10use {defmt_rtt as _, panic_probe as _};
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l1/src/bin/flash.rs b/examples/stm32l1/src/bin/flash.rs
index eea838cba..fc519b079 100644
--- a/examples/stm32l1/src/bin/flash.rs
+++ b/examples/stm32l1/src/bin/flash.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
8use embassy_stm32::Peripherals; 8use embassy_stm32::Peripherals;
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs
index bced0c54e..81ccba4e1 100644
--- a/examples/stm32l1/src/bin/spi.rs
+++ b/examples/stm32l1/src/bin/spi.rs
@@ -2,17 +2,14 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_stm32::gpio::{Level, Output, Speed};
11
12use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
8use embassy_stm32::gpio::{Level, Output, Speed};
13use embassy_stm32::spi::{Config, Spi}; 9use embassy_stm32::spi::{Config, Spi};
14use embassy_stm32::time::Hertz; 10use embassy_stm32::time::Hertz;
15use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use {defmt_rtt as _, panic_probe as _};
16 13
17#[embassy::main] 14#[embassy::main]
18async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs
index 58ef6ebaa..499ea47dc 100644
--- a/examples/stm32l4/src/bin/adc.rs
+++ b/examples/stm32l4/src/bin/adc.rs
@@ -2,13 +2,11 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::time::Delay; 6use embassy::time::Delay;
10use embassy_stm32::adc::{Adc, Resolution}; 7use embassy_stm32::adc::{Adc, Resolution};
11use embassy_stm32::pac; 8use embassy_stm32::pac;
9use {defmt_rtt as _, panic_probe as _};
12 10
13#[cortex_m_rt::entry] 11#[cortex_m_rt::entry]
14fn main() -> ! { 12fn main() -> ! {
diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs
index e24a5bd37..54f8e03b2 100644
--- a/examples/stm32l4/src/bin/blinky.rs
+++ b/examples/stm32l4/src/bin/blinky.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs
index ff270b519..73b1962e8 100644
--- a/examples/stm32l4/src/bin/button.rs
+++ b/examples/stm32l4/src/bin/button.rs
@@ -3,9 +3,8 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy_stm32::gpio::{Input, Pull}; 6use embassy_stm32::gpio::{Input, Pull};
8use panic_probe as _; 7use {defmt_rtt as _, panic_probe as _};
9 8
10#[cortex_m_rt::entry] 9#[cortex_m_rt::entry]
11fn main() -> ! { 10fn main() -> ! {
diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs
index 4b1cadcb5..924feeb33 100644
--- a/examples/stm32l4/src/bin/button_exti.rs
+++ b/examples/stm32l4/src/bin/button_exti.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs
index c26e7e709..d6e744aa6 100644
--- a/examples/stm32l4/src/bin/dac.rs
+++ b/examples/stm32l4/src/bin/dac.rs
@@ -2,12 +2,10 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy_stm32::dac::{Channel, Dac, Value}; 6use embassy_stm32::dac::{Channel, Dac, Value};
10use embassy_stm32::pac; 7use embassy_stm32::pac;
8use {defmt_rtt as _, panic_probe as _};
11 9
12#[cortex_m_rt::entry] 10#[cortex_m_rt::entry]
13fn main() -> ! { 11fn main() -> ! {
diff --git a/examples/stm32l4/src/bin/i2c.rs b/examples/stm32l4/src/bin/i2c.rs
index 467765642..a22b52184 100644
--- a/examples/stm32l4/src/bin/i2c.rs
+++ b/examples/stm32l4/src/bin/i2c.rs
@@ -2,16 +2,13 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
11use embassy_stm32::i2c::I2c; 8use embassy_stm32::i2c::I2c;
12use embassy_stm32::interrupt;
13use embassy_stm32::time::Hertz; 9use embassy_stm32::time::Hertz;
14use embassy_stm32::Peripherals; 10use embassy_stm32::{interrupt, Peripherals};
11use {defmt_rtt as _, panic_probe as _};
15 12
16const ADDRESS: u8 = 0x5F; 13const ADDRESS: u8 = 0x5F;
17const WHOAMI: u8 = 0x0F; 14const WHOAMI: u8 = 0x0F;
diff --git a/examples/stm32l4/src/bin/i2c_blocking_async.rs b/examples/stm32l4/src/bin/i2c_blocking_async.rs
index eb74223b0..6c4a86703 100644
--- a/examples/stm32l4/src/bin/i2c_blocking_async.rs
+++ b/examples/stm32l4/src/bin/i2c_blocking_async.rs
@@ -2,18 +2,15 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_embedded_hal::adapter::BlockingAsync; 7use embassy_embedded_hal::adapter::BlockingAsync;
11use embassy_stm32::dma::NoDma; 8use embassy_stm32::dma::NoDma;
12use embassy_stm32::i2c::I2c; 9use embassy_stm32::i2c::I2c;
13use embassy_stm32::interrupt;
14use embassy_stm32::time::Hertz; 10use embassy_stm32::time::Hertz;
15use embassy_stm32::Peripherals; 11use embassy_stm32::{interrupt, Peripherals};
16use embedded_hal_async::i2c::I2c as I2cTrait; 12use embedded_hal_async::i2c::I2c as I2cTrait;
13use {defmt_rtt as _, panic_probe as _};
17 14
18const ADDRESS: u8 = 0x5F; 15const ADDRESS: u8 = 0x5F;
19const WHOAMI: u8 = 0x0F; 16const WHOAMI: u8 = 0x0F;
diff --git a/examples/stm32l4/src/bin/i2c_dma.rs b/examples/stm32l4/src/bin/i2c_dma.rs
index 886a0e09f..48d2e92cf 100644
--- a/examples/stm32l4/src/bin/i2c_dma.rs
+++ b/examples/stm32l4/src/bin/i2c_dma.rs
@@ -2,15 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_stm32::i2c::I2c; 7use embassy_stm32::i2c::I2c;
11use embassy_stm32::interrupt;
12use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
13use embassy_stm32::Peripherals; 9use embassy_stm32::{interrupt, Peripherals};
10use {defmt_rtt as _, panic_probe as _};
14 11
15const ADDRESS: u8 = 0x5F; 12const ADDRESS: u8 = 0x5F;
16const WHOAMI: u8 = 0x0F; 13const WHOAMI: u8 = 0x0F;
@@ -18,15 +15,7 @@ const WHOAMI: u8 = 0x0F;
18#[embassy::main] 15#[embassy::main]
19async fn main(_spawner: Spawner, p: Peripherals) -> ! { 16async fn main(_spawner: Spawner, p: Peripherals) -> ! {
20 let irq = interrupt::take!(I2C2_EV); 17 let irq = interrupt::take!(I2C2_EV);
21 let mut i2c = I2c::new( 18 let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, p.DMA1_CH4, p.DMA1_CH5, Hertz(100_000));
22 p.I2C2,
23 p.PB10,
24 p.PB11,
25 irq,
26 p.DMA1_CH4,
27 p.DMA1_CH5,
28 Hertz(100_000),
29 );
30 19
31 let mut data = [0u8; 1]; 20 let mut data = [0u8; 1];
32 unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data).await); 21 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 03773e61b..7aaa122ed 100644
--- a/examples/stm32l4/src/bin/rng.rs
+++ b/examples/stm32l4/src/bin/rng.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; 7use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv};
9use embassy_stm32::rng::Rng; 8use embassy_stm32::rng::Rng;
10use embassy_stm32::{Config, Peripherals}; 9use embassy_stm32::{Config, Peripherals};
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13fn config() -> Config { 12fn config() -> Config {
14 let mut config = Config::default(); 13 let mut config = Config::default();
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs
index 44fdf81a8..76e316a25 100644
--- a/examples/stm32l4/src/bin/spi.rs
+++ b/examples/stm32l4/src/bin/spi.rs
@@ -2,14 +2,12 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy_stm32::dma::NoDma; 6use embassy_stm32::dma::NoDma;
10use embassy_stm32::gpio::{Level, Output, Speed}; 7use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::spi::{Config, Spi}; 8use embassy_stm32::spi::{Config, Spi};
12use embassy_stm32::time::Hertz; 9use embassy_stm32::time::Hertz;
10use {defmt_rtt as _, panic_probe as _};
13 11
14#[cortex_m_rt::entry] 12#[cortex_m_rt::entry]
15fn main() -> ! { 13fn main() -> ! {
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs
index e1a400107..20a2ff802 100644
--- a/examples/stm32l4/src/bin/spi_blocking_async.rs
+++ b/examples/stm32l4/src/bin/spi_blocking_async.rs
@@ -2,9 +2,6 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_embedded_hal::adapter::BlockingAsync; 7use embassy_embedded_hal::adapter::BlockingAsync;
@@ -14,6 +11,7 @@ use embassy_stm32::spi::{Config, Spi};
14use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
15use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
16use embedded_hal_async::spi::SpiBus; 13use embedded_hal_async::spi::SpiBus;
14use {defmt_rtt as _, panic_probe as _};
17 15
18#[embassy::main] 16#[embassy::main]
19async fn main(_spawner: Spawner, p: Peripherals) { 17async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs
index 88d02c7e1..d0c3609af 100644
--- a/examples/stm32l4/src/bin/spi_dma.rs
+++ b/examples/stm32l4/src/bin/spi_dma.rs
@@ -2,15 +2,13 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy::executor::Spawner; 6use embassy::executor::Spawner;
10use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
11use embassy_stm32::spi::{Config, Spi}; 8use embassy_stm32::spi::{Config, Spi};
12use embassy_stm32::time::Hertz; 9use embassy_stm32::time::Hertz;
13use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use {defmt_rtt as _, panic_probe as _};
14 12
15#[embassy::main] 13#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 14async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs
index b38f55456..4a4b46c53 100644
--- a/examples/stm32l4/src/bin/usart.rs
+++ b/examples/stm32l4/src/bin/usart.rs
@@ -2,12 +2,10 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*; 5use defmt::*;
9use embassy_stm32::dma::NoDma; 6use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 7use embassy_stm32::usart::{Config, Uart};
8use {defmt_rtt as _, panic_probe as _};
11 9
12#[cortex_m_rt::entry] 10#[cortex_m_rt::entry]
13fn main() -> ! { 11fn main() -> ! {
diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs
index 40e2c3671..7ae7e9e15 100644
--- a/examples/stm32l4/src/bin/usart_dma.rs
+++ b/examples/stm32l4/src/bin/usart_dma.rs
@@ -3,14 +3,14 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::fmt::Write; 5use core::fmt::Write;
6
6use defmt::*; 7use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy::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; 11use embassy_stm32::Peripherals;
12use heapless::String; 12use heapless::String;
13use panic_probe as _; 13use {defmt_rtt as _, panic_probe as _};
14 14
15#[embassy::main] 15#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 16async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l5/src/bin/button_exti.rs b/examples/stm32l5/src/bin/button_exti.rs
index 304ce0a8a..c7a6cfa28 100644
--- a/examples/stm32l5/src/bin/button_exti.rs
+++ b/examples/stm32l5/src/bin/button_exti.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l5/src/bin/rng.rs b/examples/stm32l5/src/bin/rng.rs
index 5f75c1ff1..d3627d2c2 100644
--- a/examples/stm32l5/src/bin/rng.rs
+++ b/examples/stm32l5/src/bin/rng.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; 7use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv};
9use embassy_stm32::rng::Rng; 8use embassy_stm32::rng::Rng;
10use embassy_stm32::{Config, Peripherals}; 9use embassy_stm32::{Config, Peripherals};
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13fn config() -> Config { 12fn config() -> Config {
14 let mut config = Config::default(); 13 let mut config = Config::default();
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs
index 526b27530..d711616ef 100644
--- a/examples/stm32l5/src/bin/usb_ethernet.rs
+++ b/examples/stm32l5/src/bin/usb_ethernet.rs
@@ -5,29 +5,24 @@
5 5
6use core::sync::atomic::{AtomicBool, Ordering}; 6use core::sync::atomic::{AtomicBool, Ordering};
7use core::task::Waker; 7use core::task::Waker;
8
8use defmt::*; 9use defmt::*;
9use defmt_rtt as _; // global logger
10use embassy::blocking_mutex::raw::ThreadModeRawMutex; 10use embassy::blocking_mutex::raw::ThreadModeRawMutex;
11use embassy::channel::mpmc::Channel; 11use embassy::channel::mpmc::Channel;
12use embassy::executor::Spawner; 12use embassy::executor::Spawner;
13use embassy::util::Forever; 13use embassy::util::Forever;
14use embassy_net::tcp::TcpSocket; 14use embassy_net::tcp::TcpSocket;
15use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; 15use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources};
16use embassy_stm32::interrupt;
17use embassy_stm32::rcc::*; 16use embassy_stm32::rcc::*;
18use embassy_stm32::rng::Rng; 17use embassy_stm32::rng::Rng;
19use embassy_stm32::time::Hertz; 18use embassy_stm32::time::Hertz;
20use embassy_stm32::usb::Driver; 19use embassy_stm32::usb::Driver;
21use embassy_stm32::{Config, Peripherals}; 20use embassy_stm32::{interrupt, Config, Peripherals};
22use embassy_usb::{Builder, UsbDevice}; 21use embassy_usb::{Builder, UsbDevice};
23use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; 22use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
24use panic_probe as _;
25
26use defmt_rtt as _;
27use embedded_io::asynch::{Read, Write}; 23use embedded_io::asynch::{Read, Write};
28// global logger
29use panic_probe as _;
30use rand_core::RngCore; 24use rand_core::RngCore;
25use {defmt_rtt as _, panic_probe as _};
31 26
32type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; 27type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>;
33 28
@@ -92,13 +87,7 @@ fn config() -> Config {
92 let mut config = Config::default(); 87 let mut config = Config::default();
93 config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); 88 config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000));
94 89
95 config.rcc.mux = ClockSrc::PLL( 90 config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None);
96 PLLSource::HSI16,
97 PLLClkDiv::Div2,
98 PLLSrcDiv::Div1,
99 PLLMul::Mul10,
100 None,
101 );
102 config.rcc.hsi48 = true; 91 config.rcc.hsi48 = true;
103 92
104 config 93 config
@@ -186,9 +175,7 @@ async fn main(spawner: Spawner, p: Peripherals) {
186 let seed = rng.next_u64(); 175 let seed = rng.next_u64();
187 176
188 // Init network stack 177 // Init network stack
189 let device = Device { 178 let device = Device { mac_addr: our_mac_addr };
190 mac_addr: our_mac_addr,
191 };
192 let stack = &*forever!(Stack::new( 179 let stack = &*forever!(Stack::new(
193 device, 180 device,
194 config, 181 config,
diff --git a/examples/stm32l5/src/bin/usb_hid_mouse.rs b/examples/stm32l5/src/bin/usb_hid_mouse.rs
index d275aba36..d139e6bb1 100644
--- a/examples/stm32l5/src/bin/usb_hid_mouse.rs
+++ b/examples/stm32l5/src/bin/usb_hid_mouse.rs
@@ -6,31 +6,22 @@
6use defmt::*; 6use defmt::*;
7use embassy::executor::Spawner; 7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::interrupt;
10use embassy_stm32::rcc::*; 9use embassy_stm32::rcc::*;
11use embassy_stm32::time::Hertz; 10use embassy_stm32::time::Hertz;
12use embassy_stm32::usb::Driver; 11use embassy_stm32::usb::Driver;
13use embassy_stm32::{Config, Peripherals}; 12use embassy_stm32::{interrupt, Config, Peripherals};
14use embassy_usb::control::OutResponse; 13use embassy_usb::control::OutResponse;
15use embassy_usb::Builder; 14use embassy_usb::Builder;
16use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; 15use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State};
17use futures::future::join; 16use futures::future::join;
18use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; 17use usbd_hid::descriptor::{MouseReport, SerializedDescriptor};
19 18use {defmt_rtt as _, panic_probe as _};
20use defmt_rtt as _; // global logger
21use panic_probe as _;
22 19
23fn config() -> Config { 20fn config() -> Config {
24 let mut config = Config::default(); 21 let mut config = Config::default();
25 config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); 22 config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000));
26 23
27 config.rcc.mux = ClockSrc::PLL( 24 config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None);
28 PLLSource::HSI16,
29 PLLClkDiv::Div2,
30 PLLSrcDiv::Div1,
31 PLLMul::Mul10,
32 None,
33 );
34 config.rcc.hsi48 = true; 25 config.rcc.hsi48 = true;
35 26
36 config 27 config
diff --git a/examples/stm32l5/src/bin/usb_serial.rs b/examples/stm32l5/src/bin/usb_serial.rs
index 987f1b692..8dab001c6 100644
--- a/examples/stm32l5/src/bin/usb_serial.rs
+++ b/examples/stm32l5/src/bin/usb_serial.rs
@@ -2,32 +2,23 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::panic; 5use defmt::{panic, *};
6use defmt::*;
7use defmt_rtt as _; // global logger
8use embassy::executor::Spawner; 6use embassy::executor::Spawner;
9use embassy_stm32::interrupt;
10use embassy_stm32::rcc::*; 7use embassy_stm32::rcc::*;
11use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
12use embassy_stm32::usb::{Driver, Instance}; 9use embassy_stm32::usb::{Driver, Instance};
13use embassy_stm32::{Config, Peripherals}; 10use embassy_stm32::{interrupt, Config, Peripherals};
14use embassy_usb::driver::EndpointError; 11use embassy_usb::driver::EndpointError;
15use embassy_usb::Builder; 12use embassy_usb::Builder;
16use embassy_usb_serial::{CdcAcmClass, State}; 13use embassy_usb_serial::{CdcAcmClass, State};
17use futures::future::join; 14use futures::future::join;
18use panic_probe as _; 15use {defmt_rtt as _, panic_probe as _};
19 16
20fn config() -> Config { 17fn config() -> Config {
21 let mut config = Config::default(); 18 let mut config = Config::default();
22 config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); 19 config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000));
23 20
24 config.rcc.mux = ClockSrc::PLL( 21 config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None);
25 PLLSource::HSI16,
26 PLLClkDiv::Div2,
27 PLLSrcDiv::Div1,
28 PLLMul::Mul10,
29 None,
30 );
31 config.rcc.hsi48 = true; 22 config.rcc.hsi48 = true;
32 23
33 config 24 config
@@ -99,9 +90,7 @@ impl From<EndpointError> for Disconnected {
99 } 90 }
100} 91}
101 92
102async fn echo<'d, T: Instance + 'd>( 93async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> {
103 class: &mut CdcAcmClass<'d, Driver<'d, T>>,
104) -> Result<(), Disconnected> {
105 let mut buf = [0; 64]; 94 let mut buf = [0; 64];
106 loop { 95 loop {
107 let n = class.read_packet(&mut buf).await?; 96 let n = class.read_packet(&mut buf).await?;
diff --git a/examples/stm32u5/src/bin/blinky.rs b/examples/stm32u5/src/bin/blinky.rs
index e1bcccf58..4910e0b98 100644
--- a/examples/stm32u5/src/bin/blinky.rs
+++ b/examples/stm32u5/src/bin/blinky.rs
@@ -3,13 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _;
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11// global logger 10use {defmt_rtt as _, panic_probe as _};
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) -> ! { 13async fn main(_spawner: Spawner, p: Peripherals) -> ! {
diff --git a/examples/stm32u5/src/bin/boot.rs b/examples/stm32u5/src/bin/boot.rs
index e04021349..e2112ce5c 100644
--- a/examples/stm32u5/src/bin/boot.rs
+++ b/examples/stm32u5/src/bin/boot.rs
@@ -3,10 +3,7 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger 6use {defmt_rtt as _, embassy_stm32 as _, panic_probe as _};
7use panic_probe as _;
8
9use embassy_stm32 as _;
10 7
11#[cortex_m_rt::entry] 8#[cortex_m_rt::entry]
12fn main() -> ! { 9fn main() -> ! {
diff --git a/examples/stm32wb/src/bin/blinky.rs b/examples/stm32wb/src/bin/blinky.rs
index 59324161a..8ab9b749d 100644
--- a/examples/stm32wb/src/bin/blinky.rs
+++ b/examples/stm32wb/src/bin/blinky.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32wb/src/bin/button_exti.rs b/examples/stm32wb/src/bin/button_exti.rs
index a30a4a216..2ddeb887c 100644
--- a/examples/stm32wb/src/bin/button_exti.rs
+++ b/examples/stm32wb/src/bin/button_exti.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32wl/src/bin/blinky.rs b/examples/stm32wl/src/bin/blinky.rs
index 78079bfd3..9393af1c6 100644
--- a/examples/stm32wl/src/bin/blinky.rs
+++ b/examples/stm32wl/src/bin/blinky.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32wl/src/bin/button.rs b/examples/stm32wl/src/bin/button.rs
index f80b9ab4f..982a7a112 100644
--- a/examples/stm32wl/src/bin/button.rs
+++ b/examples/stm32wl/src/bin/button.rs
@@ -2,12 +2,10 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use cortex_m_rt::entry;
5use defmt::*; 6use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
8use panic_probe as _; 8use {defmt_rtt as _, panic_probe as _};
9
10use cortex_m_rt::entry;
11 9
12#[entry] 10#[entry]
13fn main() -> ! { 11fn main() -> ! {
diff --git a/examples/stm32wl/src/bin/button_exti.rs b/examples/stm32wl/src/bin/button_exti.rs
index 9a427c2d3..7d5c1b3cb 100644
--- a/examples/stm32wl/src/bin/button_exti.rs
+++ b/examples/stm32wl/src/bin/button_exti.rs
@@ -3,12 +3,11 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use defmt_rtt as _; // global logger
7use embassy::executor::Spawner; 6use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 7use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
11use panic_probe as _; 10use {defmt_rtt as _, panic_probe as _};
12 11
13#[embassy::main] 12#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32wl/src/bin/flash.rs b/examples/stm32wl/src/bin/flash.rs
index f84818224..6531feae9 100644
--- a/examples/stm32wl/src/bin/flash.rs
+++ b/examples/stm32wl/src/bin/flash.rs
@@ -7,9 +7,7 @@ use embassy::executor::Spawner;
7use embassy_stm32::flash::Flash; 7use embassy_stm32::flash::Flash;
8use embassy_stm32::Peripherals; 8use embassy_stm32::Peripherals;
9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; 9use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
10 10use {defmt_rtt as _, panic_probe as _};
11use defmt_rtt as _; // global logger
12use panic_probe as _;
13 11
14#[embassy::main] 12#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) { 13async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32wl/src/bin/lorawan.rs b/examples/stm32wl/src/bin/lorawan.rs
index 393828c85..4f0dc7dfc 100644
--- a/examples/stm32wl/src/bin/lorawan.rs
+++ b/examples/stm32wl/src/bin/lorawan.rs
@@ -5,20 +5,16 @@
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 defmt_rtt as _; // global logger 8use embassy_lora::stm32wl::*;
9use panic_probe as _; 9use embassy_lora::LoraTimer;
10 10use embassy_stm32::dma::NoDma;
11use embassy_lora::{stm32wl::*, LoraTimer}; 11use embassy_stm32::gpio::{Level, Output, Pin, Speed};
12use embassy_stm32::{ 12use embassy_stm32::rng::Rng;
13 dma::NoDma, 13use embassy_stm32::subghz::*;
14 gpio::{Level, Output, Pin, Speed}, 14use embassy_stm32::{interrupt, pac, Peripherals};
15 interrupt, pac,
16 rng::Rng,
17 subghz::*,
18 Peripherals,
19};
20use lorawan::default_crypto::DefaultFactory as Crypto; 15use lorawan::default_crypto::DefaultFactory as Crypto;
21use lorawan_device::async_device::{region, Device, JoinMode}; 16use lorawan_device::async_device::{region, Device, JoinMode};
17use {defmt_rtt as _, panic_probe as _};
22 18
23fn config() -> embassy_stm32::Config { 19fn config() -> embassy_stm32::Config {
24 let mut config = embassy_stm32::Config::default(); 20 let mut config = embassy_stm32::Config::default();
@@ -43,8 +39,7 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
43 let radio = unsafe { SubGhzRadio::new(&mut RADIO_STATE, radio, rfs, irq) }; 39 let radio = unsafe { SubGhzRadio::new(&mut RADIO_STATE, radio, rfs, irq) };
44 40
45 let region = region::EU868::default().into(); 41 let region = region::EU868::default().into();
46 let mut device: Device<_, Crypto, _, _> = 42 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG));
47 Device::new(region, radio, LoraTimer, Rng::new(p.RNG));
48 43
49 defmt::info!("Joining LoRaWAN network"); 44 defmt::info!("Joining LoRaWAN network");
50 45
diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs
index f5f9b6a32..c5f6e502a 100644
--- a/examples/stm32wl/src/bin/subghz.rs
+++ b/examples/stm32wl/src/bin/subghz.rs
@@ -5,18 +5,15 @@
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 defmt_rtt as _; // global logger
9use panic_probe as _;
10
11use defmt::*; 8use defmt::*;
12use embassy::channel::signal::Signal; 9use embassy::channel::signal::Signal;
13use embassy_stm32::dma::NoDma; 10use embassy_stm32::dma::NoDma;
14use embassy_stm32::exti::ExtiInput; 11use embassy_stm32::exti::ExtiInput;
15use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
16use embassy_stm32::interrupt;
17use embassy_stm32::interrupt::{Interrupt, InterruptExt}; 13use embassy_stm32::interrupt::{Interrupt, InterruptExt};
18use embassy_stm32::subghz::*; 14use embassy_stm32::subghz::*;
19use embassy_stm32::Peripherals; 15use embassy_stm32::{interrupt, Peripherals};
16use {defmt_rtt as _, panic_probe as _};
20 17
21const PING_DATA: &str = "PING"; 18const PING_DATA: &str = "PING";
22const DATA_LEN: u8 = PING_DATA.len() as u8; 19const DATA_LEN: u8 = PING_DATA.len() as u8;
@@ -46,20 +43,13 @@ const LORA_MOD_PARAMS: LoRaModParams = LoRaModParams::new()
46 43
47// configuration for +10 dBm output power 44// configuration for +10 dBm output power
48// see table 35 "PA optimal setting and operating modes" 45// see table 35 "PA optimal setting and operating modes"
49const PA_CONFIG: PaConfig = PaConfig::new() 46const PA_CONFIG: PaConfig = PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp);
50 .set_pa_duty_cycle(0x1)
51 .set_hp_max(0x0)
52 .set_pa(PaSel::Lp);
53 47
54const TCXO_MODE: TcxoMode = TcxoMode::new() 48const TCXO_MODE: TcxoMode = TcxoMode::new()
55 .set_txco_trim(TcxoTrim::Volts1pt7) 49 .set_txco_trim(TcxoTrim::Volts1pt7)
56 .set_timeout(Timeout::from_duration_sat( 50 .set_timeout(Timeout::from_duration_sat(core::time::Duration::from_millis(10)));
57 core::time::Duration::from_millis(10),
58 ));
59 51
60const TX_PARAMS: TxParams = TxParams::new() 52const TX_PARAMS: TxParams = TxParams::new().set_power(0x0D).set_ramp_time(RampTime::Micros40);
61 .set_power(0x0D)
62 .set_ramp_time(RampTime::Micros40);
63 53
64fn config() -> embassy_stm32::Config { 54fn config() -> embassy_stm32::Config {
65 let mut config = embassy_stm32::Config::default(); 55 let mut config = embassy_stm32::Config::default();
diff --git a/examples/wasm/src/lib.rs b/examples/wasm/src/lib.rs
index 0aa32a70b..61757ebd7 100644
--- a/examples/wasm/src/lib.rs
+++ b/examples/wasm/src/lib.rs
@@ -1,10 +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::{ 4use embassy::executor::Spawner;
5 executor::Spawner, 5use embassy::time::{Duration, Timer};
6 time::{Duration, Timer},
7};
8 6
9#[embassy::task] 7#[embassy::task]
10async fn ticker() { 8async fn ticker() {
@@ -13,13 +11,9 @@ async fn ticker() {
13 let mut counter = 0; 11 let mut counter = 0;
14 loop { 12 loop {
15 let document = window.document().expect("should have a document on window"); 13 let document = window.document().expect("should have a document on window");
16 let list = document 14 let list = document.get_element_by_id("log").expect("should have a log element");
17 .get_element_by_id("log")
18 .expect("should have a log element");
19 15
20 let li = document 16 let li = document.create_element("li").expect("error creating list item element");
21 .create_element("li")
22 .expect("error creating list item element");
23 li.set_text_content(Some(&format!("tick {}", counter))); 17 li.set_text_content(Some(&format!("tick {}", counter)));
24 18
25 list.append_child(&li).expect("error appending list item"); 19 list.append_child(&li).expect("error appending list item");
diff --git a/stm32-gen-features/src/main.rs b/stm32-gen-features/src/main.rs
index 72a907522..f40925169 100644
--- a/stm32-gen-features/src/main.rs
+++ b/stm32-gen-features/src/main.rs
@@ -1,6 +1,5 @@
1use gen_features::{ 1use gen_features::{
2 chip_names_and_cores, embassy_stm32_needed_data, generate_cargo_toml_file, 2 chip_names_and_cores, embassy_stm32_needed_data, generate_cargo_toml_file, stm32_metapac_needed_data,
3 stm32_metapac_needed_data,
4}; 3};
5 4
6fn main() { 5fn main() {
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs
index f5d61ca31..0d761508f 100644
--- a/stm32-metapac-gen/src/lib.rs
+++ b/stm32-metapac-gen/src/lib.rs
@@ -1,16 +1,16 @@
1use chiptool::generate::CommonModule;
2use chiptool::{generate, ir, transform};
3use proc_macro2::TokenStream;
4use regex::Regex;
5use std::collections::{BTreeMap, HashMap, HashSet}; 1use std::collections::{BTreeMap, HashMap, HashSet};
6use std::fmt::{Debug, Write as _}; 2use std::fmt::{Debug, Write as _};
7use std::fs; 3use std::fs;
8use std::fs::File; 4use std::fs::File;
9use std::io::Write; 5use std::io::Write;
10use std::path::Path; 6use std::path::{Path, PathBuf};
11use std::path::PathBuf;
12use std::str::FromStr; 7use std::str::FromStr;
13 8
9use chiptool::generate::CommonModule;
10use chiptool::{generate, ir, transform};
11use proc_macro2::TokenStream;
12use regex::Regex;
13
14mod data; 14mod data;
15use data::*; 15use data::*;
16 16
@@ -56,12 +56,7 @@ impl Gen {
56 56
57 let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new(); 57 let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new();
58 58
59 let gpio_base = core 59 let gpio_base = core.peripherals.iter().find(|p| p.name == "GPIOA").unwrap().address as u32;
60 .peripherals
61 .iter()
62 .find(|p| p.name == "GPIOA")
63 .unwrap()
64 .address as u32;
65 let gpio_stride = 0x400; 60 let gpio_stride = 0x400;
66 61
67 for p in &core.peripherals { 62 for p in &core.peripherals {
@@ -75,9 +70,7 @@ impl Gen {
75 }; 70 };
76 71
77 if let Some(bi) = &p.registers { 72 if let Some(bi) = &p.registers {
78 if let Some(old_version) = 73 if let Some(old_version) = peripheral_versions.insert(bi.kind.clone(), bi.version.clone()) {
79 peripheral_versions.insert(bi.kind.clone(), bi.version.clone())
80 {
81 if old_version != bi.version { 74 if old_version != bi.version {
82 panic!( 75 panic!(
83 "Peripheral {} has multiple versions: {} and {}", 76 "Peripheral {} has multiple versions: {} and {}",
@@ -113,8 +106,7 @@ impl Gen {
113 ); 106 );
114 107
115 for (module, version) in &peripheral_versions { 108 for (module, version) in &peripheral_versions {
116 self.all_peripheral_versions 109 self.all_peripheral_versions.insert((module.clone(), version.clone()));
117 .insert((module.clone(), version.clone()));
118 write!( 110 write!(
119 &mut extra, 111 &mut extra,
120 "#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n", 112 "#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n",
@@ -122,45 +114,15 @@ impl Gen {
122 ) 114 )
123 .unwrap(); 115 .unwrap();
124 } 116 }
125 write!( 117 write!(&mut extra, "pub const CORE_INDEX: usize = {};\n", core_index).unwrap();
126 &mut extra,
127 "pub const CORE_INDEX: usize = {};\n",
128 core_index
129 )
130 .unwrap();
131 118
132 let flash = chip.memory.iter().find(|r| r.name == "BANK_1").unwrap(); 119 let flash = chip.memory.iter().find(|r| r.name == "BANK_1").unwrap();
133 write!( 120 write!(&mut extra, "pub const FLASH_BASE: usize = {};\n", flash.address,).unwrap();
134 &mut extra, 121 write!(&mut extra, "pub const FLASH_SIZE: usize = {};\n", flash.size,).unwrap();
135 "pub const FLASH_BASE: usize = {};\n",
136 flash.address,
137 )
138 .unwrap();
139 write!(
140 &mut extra,
141 "pub const FLASH_SIZE: usize = {};\n",
142 flash.size,
143 )
144 .unwrap();
145 if let Some(settings) = &flash.settings { 122 if let Some(settings) = &flash.settings {
146 write!( 123 write!(&mut extra, "pub const ERASE_SIZE: usize = {};\n", settings.erase_size,).unwrap();
147 &mut extra, 124 write!(&mut extra, "pub const WRITE_SIZE: usize = {};\n", settings.write_size,).unwrap();
148 "pub const ERASE_SIZE: usize = {};\n", 125 write!(&mut extra, "pub const ERASE_VALUE: u8 = {};\n", settings.erase_value,).unwrap();
149 settings.erase_size,
150 )
151 .unwrap();
152 write!(
153 &mut extra,
154 "pub const WRITE_SIZE: usize = {};\n",
155 settings.write_size,
156 )
157 .unwrap();
158 write!(
159 &mut extra,
160 "pub const ERASE_VALUE: u8 = {};\n",
161 settings.erase_value,
162 )
163 .unwrap();
164 } 126 }
165 127
166 // Cleanups! 128 // Cleanups!
@@ -260,11 +222,7 @@ impl Gen {
260 } 222 }
261 223
262 fn load_chip(&mut self, name: &str) -> Chip { 224 fn load_chip(&mut self, name: &str) -> Chip {
263 let chip_path = self 225 let chip_path = self.opts.data_dir.join("chips").join(&format!("{}.json", name));
264 .opts
265 .data_dir
266 .join("chips")
267 .join(&format!("{}.json", name));
268 let chip = fs::read(chip_path).expect(&format!("Could not load chip {}", name)); 226 let chip = fs::read(chip_path).expect(&format!("Could not load chip {}", name));
269 serde_yaml::from_slice(&chip).unwrap() 227 serde_yaml::from_slice(&chip).unwrap()
270 } 228 }
@@ -313,9 +271,7 @@ impl Gen {
313 271
314 let mut ir: ir::IR = serde_yaml::from_reader(File::open(regs_path).unwrap()).unwrap(); 272 let mut ir: ir::IR = serde_yaml::from_reader(File::open(regs_path).unwrap()).unwrap();
315 273
316 transform::expand_extends::ExpandExtends {} 274 transform::expand_extends::ExpandExtends {}.run(&mut ir).unwrap();
317 .run(&mut ir)
318 .unwrap();
319 275
320 transform::map_names(&mut ir, |k, s| match k { 276 transform::map_names(&mut ir, |k, s| match k {
321 transform::NameKind::Block => *s = format!("{}", s), 277 transform::NameKind::Block => *s = format!("{}", s),
@@ -378,9 +334,7 @@ impl Gen {
378} 334}
379 335
380fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> { 336fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option<usize> {
381 haystack 337 haystack.windows(needle.len()).position(|window| window == needle)
382 .windows(needle.len())
383 .position(|window| window == needle)
384} 338}
385 339
386fn stringify<T: Debug>(metadata: T) -> String { 340fn stringify<T: Debug>(metadata: T) -> String {
diff --git a/stm32-metapac-gen/src/main.rs b/stm32-metapac-gen/src/main.rs
index 391441302..40a73adf8 100644
--- a/stm32-metapac-gen/src/main.rs
+++ b/stm32-metapac-gen/src/main.rs
@@ -1,5 +1,6 @@
1use std::env::args; 1use std::env::args;
2use std::path::PathBuf; 2use std::path::PathBuf;
3
3use stm32_metapac_gen::*; 4use stm32_metapac_gen::*;
4 5
5fn main() { 6fn main() {
diff --git a/stm32-metapac/build.rs b/stm32-metapac/build.rs
index 2b3fca809..0c183fa21 100644
--- a/stm32-metapac/build.rs
+++ b/stm32-metapac/build.rs
@@ -1,5 +1,6 @@
1use std::env; 1use std::env;
2use std::path::PathBuf; 2use std::path::PathBuf;
3
3use stm32_metapac_gen::*; 4use stm32_metapac_gen::*;
4 5
5fn parse_chip_core(chip_and_core: &str) -> (String, Option<String>) { 6fn parse_chip_core(chip_and_core: &str) -> (String, Option<String>) {
diff --git a/stm32-metapac/build_pregenerated.rs b/stm32-metapac/build_pregenerated.rs
index 660a95533..0f0358071 100644
--- a/stm32-metapac/build_pregenerated.rs
+++ b/stm32-metapac/build_pregenerated.rs
@@ -25,10 +25,7 @@ fn main() {
25 crate_dir.display(), 25 crate_dir.display(),
26 chip_core_name 26 chip_core_name
27 ); 27 );
28 println!( 28 println!("cargo:rustc-env=STM32_METAPAC_PAC_PATH=chips/{}/pac.rs", chip_core_name);
29 "cargo:rustc-env=STM32_METAPAC_PAC_PATH=chips/{}/pac.rs",
30 chip_core_name
31 );
32 println!( 29 println!(
33 "cargo:rustc-env=STM32_METAPAC_METADATA_PATH=chips/{}/metadata.rs", 30 "cargo:rustc-env=STM32_METAPAC_METADATA_PATH=chips/{}/metadata.rs",
34 chip_core_name 31 chip_core_name
diff --git a/tests/stm32/src/example_common.rs b/tests/stm32/src/example_common.rs
index 11b11d685..c47ed75c4 100644
--- a/tests/stm32/src/example_common.rs
+++ b/tests/stm32/src/example_common.rs
@@ -1,14 +1,12 @@
1#![macro_use] 1#![macro_use]
2 2
3use defmt_rtt as _; 3use core::sync::atomic::{AtomicUsize, Ordering};
4
5pub use defmt::*;
4#[allow(unused)] 6#[allow(unused)]
5use embassy_stm32::time::Hertz; 7use embassy_stm32::time::Hertz;
6use embassy_stm32::Config; 8use embassy_stm32::Config;
7use panic_probe as _; 9use {defmt_rtt as _, panic_probe as _};
8
9pub use defmt::*;
10
11use core::sync::atomic::{AtomicUsize, Ordering};
12 10
13defmt::timestamp! {"{=u64}", { 11defmt::timestamp! {"{=u64}", {
14 static COUNT: AtomicUsize = AtomicUsize::new(0); 12 static COUNT: AtomicUsize = AtomicUsize::new(0);
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index d8d5e07da..b8b453fd0 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -1,10 +1,9 @@
1#![allow(dead_code)] 1#![allow(dead_code)]
2#![deny(unused_must_use)] 2#![deny(unused_must_use)]
3 3
4use std::format; 4use std::path::{Path, PathBuf};
5use std::{env, fs, path::PathBuf}; 5use std::{env, format, fs};
6 6
7use std::path::Path;
8use walkdir::WalkDir; 7use walkdir::WalkDir;
9use xshell::{cmd, Cmd}; 8use xshell::{cmd, Cmd};
10use yaml_rust::YamlLoader; 9use yaml_rust::YamlLoader;
@@ -67,10 +66,7 @@ impl Realm {
67fn task_check(realm: Realm) -> Result<(), anyhow::Error> { 66fn task_check(realm: Realm) -> Result<(), anyhow::Error> {
68 let _e = xshell::pushenv("CI", "true"); 67 let _e = xshell::pushenv("CI", "true");
69 68
70 let matrix_yaml = root_dir() 69 let matrix_yaml = root_dir().join(".github").join("workflows").join("rust.yml");
71 .join(".github")
72 .join("workflows")
73 .join("rust.yml");
74 70
75 let matrix = YamlLoader::load_from_str(&*fs::read_to_string(matrix_yaml).unwrap()).unwrap(); 71 let matrix = YamlLoader::load_from_str(&*fs::read_to_string(matrix_yaml).unwrap()).unwrap();
76 72