Compare commits
25 Commits
doc-bind-i
...
ci-cache-t
Author | SHA1 | Date | |
---|---|---|---|
e579095a90 | |||
7b9b22d7f8 | |||
879c0ad989 | |||
2c3d399220 | |||
b17f16f0af | |||
1279a1b7f6 | |||
876faa5685 | |||
915423fc63 | |||
6782fb1efa | |||
14f41a71b6 | |||
3626deecaa | |||
b34c8e3eb1 | |||
13af76af88 | |||
2d2bd679ee | |||
dfba51d3f2 | |||
343be37f39 | |||
78f709a362 | |||
e99649e37d | |||
4051aead0f | |||
e0e5f66c4b | |||
5973e69244 | |||
4d3fcd8d2d | |||
6629c7525b | |||
02b7a833d9 | |||
a4d53c7cb1 |
2
.github/ci/build-stable.sh
vendored
2
.github/ci/build-stable.sh
vendored
@ -27,4 +27,4 @@ sed -i 's/channel.*/channel = "beta"/g' rust-toolchain.toml
|
||||
|
||||
# Save lockfiles
|
||||
echo Saving lockfiles...
|
||||
find . -type f -name Cargo.lock -exec tar -cf /ci/cache/lockfiles.tar '{}' \+
|
||||
find . -type f -name Cargo.lock -exec tar -cf /ci/cache/lockfiles.tar '{}' \+
|
||||
|
2
.github/ci/build.sh
vendored
2
.github/ci/build.sh
vendored
@ -31,4 +31,4 @@ hashtime save /ci/cache/filetime.json
|
||||
|
||||
# Save lockfiles
|
||||
echo Saving lockfiles...
|
||||
find . -type f -name Cargo.lock -exec tar -cf /ci/cache/lockfiles.tar '{}' \+
|
||||
find . -type f -name Cargo.lock -exec tar -cf /ci/cache/lockfiles.tar '{}' \+
|
||||
|
2
.github/ci/crlf.sh
vendored
2
.github/ci/crlf.sh
vendored
@ -14,4 +14,4 @@ else
|
||||
echo -e "ERROR: Found ${NR_FILES} files with CRLF endings."
|
||||
echo "$FILES_WITH_CRLF"
|
||||
exit "$NR_FILES"
|
||||
fi
|
||||
fi
|
||||
|
4
.github/ci/test.sh
vendored
4
.github/ci/test.sh
vendored
@ -4,6 +4,10 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
export RUSTUP_HOME=/ci/cache/rustup
|
||||
export CARGO_HOME=/ci/cache/cargo
|
||||
export CARGO_TARGET_DIR=/ci/cache/target
|
||||
|
||||
MIRIFLAGS=-Zmiri-ignore-leaks cargo miri test --manifest-path ./embassy-executor/Cargo.toml
|
||||
MIRIFLAGS=-Zmiri-ignore-leaks cargo miri test --manifest-path ./embassy-executor/Cargo.toml --features nightly
|
||||
|
||||
|
@ -45,6 +45,8 @@ The BOOTLOADER_STATE partition must be big enough to store one word per page in
|
||||
|
||||
The bootloader has a platform-agnostic part, which implements the power fail safe swapping algorithm given the boundaries set by the partitions. The platform-specific part is a minimal shim that provides additional functionality such as watchdogs or supporting the nRF52 softdevice.
|
||||
|
||||
NOTE: The linker scripts for the application and bootloader look similar, but the FLASH region must point to the BOOTLOADER partition for the bootloader, and the ACTIVE partition for the application.
|
||||
|
||||
=== FirmwareUpdater
|
||||
|
||||
The `FirmwareUpdater` is an object for conveniently flashing firmware to the DFU partition and subsequently marking it as being ready for swapping with the active partition on the next reset. Its principle methods are `write_firmware`, which is called once per the size of the flash "write block" (typically 4KiB), and `mark_updated`, which is the final call.
|
||||
@ -91,4 +93,4 @@ cp $FIRMWARE_DIR/myfirmware $FIRMWARE_DIR/myfirmware+signed
|
||||
tail -n1 $SECRETS_DIR/message.txt.sig | base64 -d -i - | dd ibs=10 skip=1 >> $FIRMWARE_DIR/myfirmware+signed
|
||||
----
|
||||
|
||||
Remember, guard the `$SECRETS_DIR/key.sec` key as compromising it means that another party can sign your firmware.
|
||||
Remember, guard the `$SECRETS_DIR/key.sec` key as compromising it means that another party can sign your firmware.
|
||||
|
@ -8,6 +8,24 @@ The bootloader can be used either as a library or be flashed directly with the d
|
||||
|
||||
By design, the bootloader does not provide any network capabilities. Networking capabilities for fetching new firmware can be provided by the user application, using the bootloader as a library for updating the firmware, or by using the bootloader as a library and adding this capability yourself.
|
||||
|
||||
## Overview
|
||||
|
||||
The bootloader divides the storage into 4 main partitions, configurable when creating the bootloader instance or via linker scripts:
|
||||
|
||||
* BOOTLOADER - Where the bootloader is placed. The bootloader itself consumes about 8kB of flash, but if you need to debug it and have space available, increasing this to 24kB will allow you to run the bootloader with probe-rs.
|
||||
* ACTIVE - Where the main application is placed. The bootloader will attempt to load the application at the start of this partition. The minimum size required for this partition is the size of your application.
|
||||
* DFU - Where the application-to-be-swapped is placed. This partition is written to by the application. This partition must be at least 1 page bigger than the ACTIVE partition.
|
||||
* BOOTLOADER STATE - Where the bootloader stores the current state describing if the active and dfu partitions need to be swapped.
|
||||
|
||||
For any partition, the following preconditions are required:
|
||||
|
||||
* Partitions must be aligned on the page size.
|
||||
* Partitions must be a multiple of the page size.
|
||||
|
||||
The linker scripts for the application and bootloader look similar, but the FLASH region must point to the BOOTLOADER partition for the bootloader, and the ACTIVE partition for the application.
|
||||
|
||||
For more details on the bootloader, see [the documentation](https://embassy.dev/book/dev/bootloader.html).
|
||||
|
||||
## Hardware support
|
||||
|
||||
The bootloader supports different hardware in separate crates:
|
||||
@ -16,6 +34,7 @@ The bootloader supports different hardware in separate crates:
|
||||
* `embassy-boot-rp` - for the RP2040 microcontrollers.
|
||||
* `embassy-boot-stm32` - for the STM32 microcontrollers.
|
||||
|
||||
|
||||
## Minimum supported Rust version (MSRV)
|
||||
|
||||
`embassy-boot` is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release.
|
||||
|
@ -135,51 +135,44 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash> BootLoader<ACTIVE, DFU, S
|
||||
/// The provided aligned_buf argument must satisfy any alignment requirements
|
||||
/// given by the partition flashes. All flash operations will use this buffer.
|
||||
///
|
||||
/// SWAPPING
|
||||
/// ## SWAPPING
|
||||
///
|
||||
/// Assume a flash size of 3 pages for the active partition, and 4 pages for the DFU partition.
|
||||
/// The swap index contains the copy progress, as to allow continuation of the copy process on
|
||||
/// power failure. The index counter is represented within 1 or more pages (depending on total
|
||||
/// flash size), where a page X is considered swapped if index at location (X + WRITE_SIZE)
|
||||
/// flash size), where a page X is considered swapped if index at location (`X + WRITE_SIZE`)
|
||||
/// contains a zero value. This ensures that index updates can be performed atomically and
|
||||
/// avoid a situation where the wrong index value is set (page write size is "atomic").
|
||||
///
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
///
|
||||
/// | Partition | Swap Index | Page 0 | Page 1 | Page 3 | Page 4 |
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
/// |-----------|------------|--------|--------|--------|--------|
|
||||
/// | Active | 0 | 1 | 2 | 3 | - |
|
||||
/// | DFU | 0 | 3 | 2 | 1 | X |
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
///
|
||||
/// The algorithm starts by copying 'backwards', and after the first step, the layout is
|
||||
/// as follows:
|
||||
///
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
/// | Partition | Swap Index | Page 0 | Page 1 | Page 3 | Page 4 |
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
/// |-----------|------------|--------|--------|--------|--------|
|
||||
/// | Active | 1 | 1 | 2 | 1 | - |
|
||||
/// | DFU | 1 | 3 | 2 | 1 | 3 |
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
///
|
||||
/// The next iteration performs the same steps
|
||||
///
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
/// | Partition | Swap Index | Page 0 | Page 1 | Page 3 | Page 4 |
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
/// |-----------|------------|--------|--------|--------|--------|
|
||||
/// | Active | 2 | 1 | 2 | 1 | - |
|
||||
/// | DFU | 2 | 3 | 2 | 2 | 3 |
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
///
|
||||
/// And again until we're done
|
||||
///
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
/// | Partition | Swap Index | Page 0 | Page 1 | Page 3 | Page 4 |
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
/// |-----------|------------|--------|--------|--------|--------|
|
||||
/// | Active | 3 | 3 | 2 | 1 | - |
|
||||
/// | DFU | 3 | 3 | 1 | 2 | 3 |
|
||||
/// +-----------+------------+--------+--------+--------+--------+
|
||||
///
|
||||
/// REVERTING
|
||||
/// ## REVERTING
|
||||
///
|
||||
/// The reverting algorithm uses the swap index to discover that images were swapped, but that
|
||||
/// the application failed to mark the boot successful. In this case, the revert algorithm will
|
||||
@ -190,28 +183,21 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash> BootLoader<ACTIVE, DFU, S
|
||||
///
|
||||
/// The revert algorithm works forwards, by starting copying into the 'unused' DFU page at the start.
|
||||
///
|
||||
/// +-----------+--------------+--------+--------+--------+--------+
|
||||
/// | Partition | Revert Index | Page 0 | Page 1 | Page 3 | Page 4 |
|
||||
//*/
|
||||
/// +-----------+--------------+--------+--------+--------+--------+
|
||||
/// |-----------|--------------|--------|--------|--------|--------|
|
||||
/// | Active | 3 | 1 | 2 | 1 | - |
|
||||
/// | DFU | 3 | 3 | 1 | 2 | 3 |
|
||||
/// +-----------+--------------+--------+--------+--------+--------+
|
||||
///
|
||||
///
|
||||
/// +-----------+--------------+--------+--------+--------+--------+
|
||||
/// | Partition | Revert Index | Page 0 | Page 1 | Page 3 | Page 4 |
|
||||
/// +-----------+--------------+--------+--------+--------+--------+
|
||||
/// |-----------|--------------|--------|--------|--------|--------|
|
||||
/// | Active | 3 | 1 | 2 | 1 | - |
|
||||
/// | DFU | 3 | 3 | 2 | 2 | 3 |
|
||||
/// +-----------+--------------+--------+--------+--------+--------+
|
||||
///
|
||||
/// +-----------+--------------+--------+--------+--------+--------+
|
||||
/// | Partition | Revert Index | Page 0 | Page 1 | Page 3 | Page 4 |
|
||||
/// +-----------+--------------+--------+--------+--------+--------+
|
||||
/// |-----------|--------------|--------|--------|--------|--------|
|
||||
/// | Active | 3 | 1 | 2 | 3 | - |
|
||||
/// | DFU | 3 | 3 | 2 | 1 | 3 |
|
||||
/// +-----------+--------------+--------+--------+--------+--------+
|
||||
///
|
||||
pub fn prepare_boot(&mut self, aligned_buf: &mut [u8]) -> Result<State, BootError> {
|
||||
// Ensure we have enough progress pages to store copy progress
|
||||
@ -224,6 +210,7 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash> BootLoader<ACTIVE, DFU, S
|
||||
assert_eq!(0, aligned_buf.len() % ACTIVE::WRITE_SIZE);
|
||||
assert_eq!(0, aligned_buf.len() % DFU::WRITE_SIZE);
|
||||
|
||||
// Ensure our partitions are able to handle boot operations
|
||||
assert_partitions(&self.active, &self.dfu, &self.state, Self::PAGE_SIZE);
|
||||
|
||||
// Copy contents from partition N to active
|
||||
@ -398,6 +385,7 @@ fn assert_partitions<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>(
|
||||
) {
|
||||
assert_eq!(active.capacity() as u32 % page_size, 0);
|
||||
assert_eq!(dfu.capacity() as u32 % page_size, 0);
|
||||
// DFU partition has to be bigger than ACTIVE partition to handle swap algorithm
|
||||
assert!(dfu.capacity() as u32 - active.capacity() as u32 >= page_size);
|
||||
assert!(2 + 2 * (active.capacity() as u32 / page_size) <= state.capacity() as u32 / STATE::WRITE_SIZE as u32);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
//! Atomic reusable ringbuffer.
|
||||
use core::slice;
|
||||
use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
|
||||
|
||||
@ -14,8 +15,9 @@ use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
|
||||
/// One concurrent writer and one concurrent reader are supported, even at
|
||||
/// different execution priorities (like main and irq).
|
||||
pub struct RingBuffer {
|
||||
#[doc(hidden)]
|
||||
pub buf: AtomicPtr<u8>,
|
||||
pub len: AtomicUsize,
|
||||
len: AtomicUsize,
|
||||
|
||||
// start and end wrap at len*2, not at len.
|
||||
// This allows distinguishing "full" and "empty".
|
||||
@ -24,11 +26,16 @@ pub struct RingBuffer {
|
||||
//
|
||||
// This avoids having to consider the ringbuffer "full" at len-1 instead of len.
|
||||
// The usual solution is adding a "full" flag, but that can't be made atomic
|
||||
#[doc(hidden)]
|
||||
pub start: AtomicUsize,
|
||||
#[doc(hidden)]
|
||||
pub end: AtomicUsize,
|
||||
}
|
||||
|
||||
/// A type which can only read from a ring buffer.
|
||||
pub struct Reader<'a>(&'a RingBuffer);
|
||||
|
||||
/// A type which can only write to a ring buffer.
|
||||
pub struct Writer<'a>(&'a RingBuffer);
|
||||
|
||||
impl RingBuffer {
|
||||
@ -89,10 +96,12 @@ impl RingBuffer {
|
||||
Writer(self)
|
||||
}
|
||||
|
||||
/// Return length of buffer.
|
||||
pub fn len(&self) -> usize {
|
||||
self.len.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Check if buffer is full.
|
||||
pub fn is_full(&self) -> bool {
|
||||
let len = self.len.load(Ordering::Relaxed);
|
||||
let start = self.start.load(Ordering::Relaxed);
|
||||
@ -101,6 +110,7 @@ impl RingBuffer {
|
||||
self.wrap(start + len) == end
|
||||
}
|
||||
|
||||
/// Check if buffer is empty.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
let start = self.start.load(Ordering::Relaxed);
|
||||
let end = self.end.load(Ordering::Relaxed);
|
||||
@ -238,6 +248,7 @@ impl<'a> Writer<'a> {
|
||||
[(unsafe { buf.add(end) }, n0), (buf, n1)]
|
||||
}
|
||||
|
||||
/// Mark n bytes as written and advance the write index.
|
||||
pub fn push_done(&mut self, n: usize) {
|
||||
trace!(" ringbuf: push {:?}", n);
|
||||
let end = self.0.end.load(Ordering::Relaxed);
|
||||
@ -323,6 +334,7 @@ impl<'a> Reader<'a> {
|
||||
(unsafe { buf.add(start) }, n)
|
||||
}
|
||||
|
||||
/// Mark n bytes as read and allow advance the read index.
|
||||
pub fn pop_done(&mut self, n: usize) {
|
||||
trace!(" ringbuf: pop {:?}", n);
|
||||
|
||||
|
@ -1,16 +1,20 @@
|
||||
//! Types for controlling when drop is invoked.
|
||||
use core::mem;
|
||||
use core::mem::MaybeUninit;
|
||||
|
||||
#[must_use = "to delay the drop handler invokation to the end of the scope"]
|
||||
/// A type to delay the drop handler invocation.
|
||||
#[must_use = "to delay the drop handler invocation to the end of the scope"]
|
||||
pub struct OnDrop<F: FnOnce()> {
|
||||
f: MaybeUninit<F>,
|
||||
}
|
||||
|
||||
impl<F: FnOnce()> OnDrop<F> {
|
||||
/// Create a new instance.
|
||||
pub fn new(f: F) -> Self {
|
||||
Self { f: MaybeUninit::new(f) }
|
||||
}
|
||||
|
||||
/// Prevent drop handler from running.
|
||||
pub fn defuse(self) {
|
||||
mem::forget(self)
|
||||
}
|
||||
@ -34,6 +38,7 @@ pub struct DropBomb {
|
||||
}
|
||||
|
||||
impl DropBomb {
|
||||
/// Create a new instance.
|
||||
pub fn new() -> Self {
|
||||
Self { _private: () }
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#![no_std]
|
||||
#![allow(clippy::new_without_default)]
|
||||
#![doc = include_str!("../README.md")]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
// This mod MUST go first, so that the others see its macros.
|
||||
pub(crate) mod fmt;
|
||||
|
@ -1,3 +1,4 @@
|
||||
/// Types for the peripheral singletons.
|
||||
#[macro_export]
|
||||
macro_rules! peripherals_definition {
|
||||
($($(#[$cfg:meta])? $name:ident),*$(,)?) => {
|
||||
@ -29,6 +30,7 @@ macro_rules! peripherals_definition {
|
||||
};
|
||||
}
|
||||
|
||||
/// Define the peripherals struct.
|
||||
#[macro_export]
|
||||
macro_rules! peripherals_struct {
|
||||
($($(#[$cfg:meta])? $name:ident),*$(,)?) => {
|
||||
@ -87,6 +89,7 @@ macro_rules! peripherals_struct {
|
||||
};
|
||||
}
|
||||
|
||||
/// Defining peripheral type.
|
||||
#[macro_export]
|
||||
macro_rules! peripherals {
|
||||
($($(#[$cfg:meta])? $name:ident),*$(,)?) => {
|
||||
@ -105,6 +108,7 @@ macro_rules! peripherals {
|
||||
};
|
||||
}
|
||||
|
||||
/// Convenience converting into reference.
|
||||
#[macro_export]
|
||||
macro_rules! into_ref {
|
||||
($($name:ident),*) => {
|
||||
@ -114,6 +118,7 @@ macro_rules! into_ref {
|
||||
}
|
||||
}
|
||||
|
||||
/// Implement the peripheral trait.
|
||||
#[macro_export]
|
||||
macro_rules! impl_peripheral {
|
||||
($type:ident) => {
|
||||
|
@ -20,6 +20,7 @@ pub struct PeripheralRef<'a, T> {
|
||||
}
|
||||
|
||||
impl<'a, T> PeripheralRef<'a, T> {
|
||||
/// Create a new reference to a peripheral.
|
||||
#[inline]
|
||||
pub fn new(inner: T) -> Self {
|
||||
Self {
|
||||
|
@ -1,3 +1,4 @@
|
||||
//! Types for dealing with rational numbers.
|
||||
use core::ops::{Add, Div, Mul};
|
||||
|
||||
use num_traits::{CheckedAdd, CheckedDiv, CheckedMul};
|
||||
|
@ -58,7 +58,7 @@ rand_core = "0.6.3"
|
||||
sdio-host = "0.5.0"
|
||||
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
|
||||
critical-section = "1.1"
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-019a5da1c47c092c199bc39a7f84fb444f2adcdf" }
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-91cee0d1fdcb4e447b65a09756b506f4af91b7e2" }
|
||||
vcell = "0.1.3"
|
||||
bxcan = "0.7.0"
|
||||
nb = "1.0.0"
|
||||
@ -76,7 +76,7 @@ critical-section = { version = "1.1", features = ["std"] }
|
||||
[build-dependencies]
|
||||
proc-macro2 = "1.0.36"
|
||||
quote = "1.0.15"
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-019a5da1c47c092c199bc39a7f84fb444f2adcdf", default-features = false, features = ["metadata"]}
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-91cee0d1fdcb4e447b65a09756b506f4af91b7e2", default-features = false, features = ["metadata"]}
|
||||
|
||||
|
||||
[features]
|
||||
@ -120,6 +120,10 @@ time-driver-tim3 = ["_time-driver"]
|
||||
time-driver-tim4 = ["_time-driver"]
|
||||
## Use TIM5 as time driver
|
||||
time-driver-tim5 = ["_time-driver"]
|
||||
## Use TIM9 as time driver
|
||||
time-driver-tim9 = ["_time-driver"]
|
||||
## Use TIM11 as time driver
|
||||
time-driver-tim11 = ["_time-driver"]
|
||||
## Use TIM12 as time driver
|
||||
time-driver-tim12 = ["_time-driver"]
|
||||
## Use TIM15 as time driver
|
||||
|
@ -187,6 +187,8 @@ fn main() {
|
||||
Some("tim3") => "TIM3",
|
||||
Some("tim4") => "TIM4",
|
||||
Some("tim5") => "TIM5",
|
||||
Some("tim9") => "TIM9",
|
||||
Some("tim11") => "TIM11",
|
||||
Some("tim12") => "TIM12",
|
||||
Some("tim15") => "TIM15",
|
||||
Some("any") => {
|
||||
@ -198,12 +200,16 @@ fn main() {
|
||||
"TIM4"
|
||||
} else if singletons.contains(&"TIM5".to_string()) {
|
||||
"TIM5"
|
||||
} else if singletons.contains(&"TIM9".to_string()) {
|
||||
"TIM9"
|
||||
} else if singletons.contains(&"TIM11".to_string()) {
|
||||
"TIM11"
|
||||
} else if singletons.contains(&"TIM12".to_string()) {
|
||||
"TIM12"
|
||||
} else if singletons.contains(&"TIM15".to_string()) {
|
||||
"TIM15"
|
||||
} else {
|
||||
panic!("time-driver-any requested, but the chip doesn't have TIM2, TIM3, TIM4, TIM5, TIM12 or TIM15.")
|
||||
panic!("time-driver-any requested, but the chip doesn't have TIM2, TIM3, TIM4, TIM5, TIM9, TIM11, TIM12 or TIM15.")
|
||||
}
|
||||
}
|
||||
_ => panic!("unknown time_driver {:?}", time_driver),
|
||||
|
@ -308,6 +308,7 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
sys: sys_clk,
|
||||
hclk1: ahb_freq,
|
||||
hclk2: ahb_freq,
|
||||
hclk3: ahb_freq,
|
||||
pclk1: apb1_freq,
|
||||
pclk1_tim: apb1_tim_freq,
|
||||
pclk2: apb2_freq,
|
||||
|
@ -95,6 +95,7 @@ pub struct Clocks {
|
||||
rcc_h7rm0433,
|
||||
rcc_h7ab,
|
||||
rcc_u5,
|
||||
rcc_g4,
|
||||
rcc_wb,
|
||||
rcc_wl5,
|
||||
rcc_wle
|
||||
|
@ -43,7 +43,10 @@ type T = peripherals::TIM3;
|
||||
type T = peripherals::TIM4;
|
||||
#[cfg(time_driver_tim5)]
|
||||
type T = peripherals::TIM5;
|
||||
|
||||
#[cfg(time_driver_tim9)]
|
||||
type T = peripherals::TIM9;
|
||||
#[cfg(time_driver_tim11)]
|
||||
type T = peripherals::TIM11;
|
||||
#[cfg(time_driver_tim12)]
|
||||
type T = peripherals::TIM12;
|
||||
#[cfg(time_driver_tim15)]
|
||||
@ -82,6 +85,22 @@ foreach_interrupt! {
|
||||
DRIVER.on_interrupt()
|
||||
}
|
||||
};
|
||||
(TIM9, timer, $block:ident, UP, $irq:ident) => {
|
||||
#[cfg(time_driver_tim9)]
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn $irq() {
|
||||
DRIVER.on_interrupt()
|
||||
}
|
||||
};
|
||||
(TIM11, timer, $block:ident, UP, $irq:ident) => {
|
||||
#[cfg(time_driver_tim11)]
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn $irq() {
|
||||
DRIVER.on_interrupt()
|
||||
}
|
||||
};
|
||||
(TIM12, timer, $block:ident, UP, $irq:ident) => {
|
||||
#[cfg(time_driver_tim12)]
|
||||
#[cfg(feature = "rt")]
|
||||
|
@ -77,7 +77,7 @@ pub(crate) mod sealed {
|
||||
Self::regs().dier().write(|r| r.set_uie(enable));
|
||||
}
|
||||
|
||||
fn set_autoreload_preload(&mut self, enable: vals::Arpe) {
|
||||
fn set_autoreload_preload(&mut self, enable: bool) {
|
||||
Self::regs().cr1().modify(|r| r.set_arpe(enable));
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,14 @@ pub struct Config {
|
||||
/// Set this to true to swap the RX and TX pins.
|
||||
#[cfg(any(usart_v3, usart_v4))]
|
||||
pub swap_rx_tx: bool,
|
||||
|
||||
/// Set this to true to invert TX pin signal values (V<sub>DD</sub> =0/mark, Gnd = 1/idle).
|
||||
#[cfg(any(usart_v3, usart_v4))]
|
||||
pub invert_tx: bool,
|
||||
|
||||
/// Set this to true to invert RX pin signal values (V<sub>DD</sub> =0/mark, Gnd = 1/idle).
|
||||
#[cfg(any(usart_v3, usart_v4))]
|
||||
pub invert_rx: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@ -147,6 +155,10 @@ impl Default for Config {
|
||||
assume_noise_free: false,
|
||||
#[cfg(any(usart_v3, usart_v4))]
|
||||
swap_rx_tx: false,
|
||||
#[cfg(any(usart_v3, usart_v4))]
|
||||
invert_tx: false,
|
||||
#[cfg(any(usart_v3, usart_v4))]
|
||||
invert_rx: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -972,7 +984,11 @@ fn configure(
|
||||
});
|
||||
|
||||
#[cfg(any(usart_v3, usart_v4))]
|
||||
w.set_swap(config.swap_rx_tx);
|
||||
{
|
||||
w.set_txinv(config.invert_tx);
|
||||
w.set_rxinv(config.invert_rx);
|
||||
w.set_swap(config.swap_rx_tx);
|
||||
}
|
||||
});
|
||||
|
||||
#[cfg(not(usart_v1))]
|
||||
|
@ -263,7 +263,7 @@ impl<'d, T: Instance> Driver<'d, T> {
|
||||
|
||||
let regs = T::regs();
|
||||
|
||||
#[cfg(stm32l5)]
|
||||
#[cfg(any(stm32l5, stm32wb))]
|
||||
crate::pac::PWR.cr2().modify(|w| w.set_usv(true));
|
||||
|
||||
#[cfg(pwr_h5)]
|
||||
|
67
examples/stm32f1/src/bin/can.rs
Normal file
67
examples/stm32f1/src/bin/can.rs
Normal file
@ -0,0 +1,67 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::can::bxcan::filter::Mask32;
|
||||
use embassy_stm32::can::bxcan::{Fifo, Frame, Id, StandardId};
|
||||
use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler};
|
||||
use embassy_stm32::peripherals::CAN;
|
||||
use embassy_stm32::{bind_interrupts, Config};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
USB_LP_CAN1_RX0 => Rx0InterruptHandler<CAN>;
|
||||
CAN1_RX1 => Rx1InterruptHandler<CAN>;
|
||||
CAN1_SCE => SceInterruptHandler<CAN>;
|
||||
USB_HP_CAN1_TX => TxInterruptHandler<CAN>;
|
||||
});
|
||||
|
||||
// This example is configured to work with real CAN transceivers on B8/B9.
|
||||
// See other examples for loopback.
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Config::default());
|
||||
|
||||
// Set alternate pin mapping to B8/B9
|
||||
embassy_stm32::pac::AFIO.mapr().modify(|w| w.set_can1_remap(2));
|
||||
|
||||
let mut can = Can::new(p.CAN, p.PB8, p.PB9, Irqs);
|
||||
|
||||
can.as_mut()
|
||||
.modify_filters()
|
||||
.enable_bank(0, Fifo::Fifo0, Mask32::accept_all());
|
||||
|
||||
can.as_mut()
|
||||
.modify_config()
|
||||
.set_loopback(false)
|
||||
.set_silent(false)
|
||||
.leave_disabled();
|
||||
|
||||
can.set_bitrate(250_000);
|
||||
|
||||
can.enable().await;
|
||||
|
||||
let mut i: u8 = 0;
|
||||
loop {
|
||||
let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]);
|
||||
can.write(&tx_frame).await;
|
||||
|
||||
match can.read().await {
|
||||
Ok(env) => match env.frame.id() {
|
||||
Id::Extended(id) => {
|
||||
defmt::println!("Extended Frame id={:x}", id.as_raw());
|
||||
}
|
||||
Id::Standard(id) => {
|
||||
defmt::println!("Standard Frame id={:x}", id.as_raw());
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
defmt::println!("Error {}", err);
|
||||
}
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user