diff options
Diffstat (limited to 'tests/stm32')
| -rw-r--r-- | tests/stm32/Cargo.toml | 3 | ||||
| -rw-r--r-- | tests/stm32/build.rs | 1 | ||||
| -rw-r--r-- | tests/stm32/src/bin/fdcan.rs | 111 | ||||
| -rw-r--r-- | tests/stm32/src/common.rs | 13 |
4 files changed, 44 insertions, 84 deletions
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 8554682a4..828a28e2c 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -26,7 +26,7 @@ stm32l4a6zg = ["embassy-stm32/stm32l4a6zg", "chrono", "not-gpdma", "rng", "hash" | |||
| 26 | stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng"] | 26 | stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng"] |
| 27 | stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash"] | 27 | stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash"] |
| 28 | stm32u585ai = ["embassy-stm32/stm32u585ai", "chrono", "rng", "hash"] | 28 | stm32u585ai = ["embassy-stm32/stm32u585ai", "chrono", "rng", "hash"] |
| 29 | stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "chrono", "rng"] | 29 | stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "chrono", "rng", "hash"] |
| 30 | stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng"] | 30 | stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng"] |
| 31 | stm32wba52cg = ["embassy-stm32/stm32wba52cg", "chrono", "rng", "hash"] | 31 | stm32wba52cg = ["embassy-stm32/stm32wba52cg", "chrono", "rng", "hash"] |
| 32 | stm32wl55jc = ["embassy-stm32/stm32wl55jc-cm4", "not-gpdma", "rng", "chrono"] | 32 | stm32wl55jc = ["embassy-stm32/stm32wl55jc-cm4", "not-gpdma", "rng", "chrono"] |
| @@ -69,6 +69,7 @@ cortex-m-rt = "0.7.0" | |||
| 69 | embedded-hal = "0.2.6" | 69 | embedded-hal = "0.2.6" |
| 70 | embedded-hal-1 = { package = "embedded-hal", version = "1.0" } | 70 | embedded-hal-1 = { package = "embedded-hal", version = "1.0" } |
| 71 | embedded-hal-async = { version = "1.0" } | 71 | embedded-hal-async = { version = "1.0" } |
| 72 | embedded-can = { version = "0.4" } | ||
| 72 | micromath = "2.0.0" | 73 | micromath = "2.0.0" |
| 73 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 74 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 74 | rand_core = { version = "0.6", default-features = false } | 75 | rand_core = { version = "0.6", default-features = false } |
diff --git a/tests/stm32/build.rs b/tests/stm32/build.rs index bc5589164..176adff62 100644 --- a/tests/stm32/build.rs +++ b/tests/stm32/build.rs | |||
| @@ -16,6 +16,7 @@ fn main() -> Result<(), Box<dyn Error>> { | |||
| 16 | feature = "stm32l073rz", | 16 | feature = "stm32l073rz", |
| 17 | // wrong ram size in stm32-data | 17 | // wrong ram size in stm32-data |
| 18 | feature = "stm32wl55jc", | 18 | feature = "stm32wl55jc", |
| 19 | feature = "stm32u5a5zj", | ||
| 19 | // no VTOR, so interrupts can't work when running from RAM | 20 | // no VTOR, so interrupts can't work when running from RAM |
| 20 | feature = "stm32f091rc", | 21 | feature = "stm32f091rc", |
| 21 | )) { | 22 | )) { |
diff --git a/tests/stm32/src/bin/fdcan.rs b/tests/stm32/src/bin/fdcan.rs index 7363eaa16..398e31ffc 100644 --- a/tests/stm32/src/bin/fdcan.rs +++ b/tests/stm32/src/bin/fdcan.rs | |||
| @@ -36,7 +36,7 @@ fn options() -> TestOptions { | |||
| 36 | c.rcc.fdcan_clock_source = rcc::FdCanClockSource::HSE; | 36 | c.rcc.fdcan_clock_source = rcc::FdCanClockSource::HSE; |
| 37 | TestOptions { | 37 | TestOptions { |
| 38 | config: c, | 38 | config: c, |
| 39 | max_latency: Duration::from_micros(3800), | 39 | max_latency: Duration::from_micros(1200), |
| 40 | second_fifo_working: false, | 40 | second_fifo_working: false, |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| @@ -53,12 +53,12 @@ fn options() -> TestOptions { | |||
| 53 | c.rcc.fdcan_clock_source = rcc::FdCanClockSource::HSE; | 53 | c.rcc.fdcan_clock_source = rcc::FdCanClockSource::HSE; |
| 54 | TestOptions { | 54 | TestOptions { |
| 55 | config: c, | 55 | config: c, |
| 56 | max_latency: Duration::from_micros(5500), | 56 | max_latency: Duration::from_micros(1200), |
| 57 | second_fifo_working: false, | 57 | second_fifo_working: false, |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | #[cfg(any(feature = "stm32g491re"))] | 61 | #[cfg(any(feature = "stm32g491re", feature = "stm32g431cb"))] |
| 62 | fn options() -> TestOptions { | 62 | fn options() -> TestOptions { |
| 63 | info!("G4 config"); | 63 | info!("G4 config"); |
| 64 | TestOptions { | 64 | TestOptions { |
| @@ -75,14 +75,14 @@ async fn main(_spawner: Spawner) { | |||
| 75 | let options = options(); | 75 | let options = options(); |
| 76 | let peripherals = embassy_stm32::init(options.config); | 76 | let peripherals = embassy_stm32::init(options.config); |
| 77 | 77 | ||
| 78 | let mut can = can::Fdcan::new(peripherals.FDCAN1, peripherals.PB8, peripherals.PB9, Irqs); | 78 | let mut can = can::FdcanConfigurator::new(peripherals.FDCAN1, peripherals.PB8, peripherals.PB9, Irqs); |
| 79 | 79 | ||
| 80 | // 250k bps | 80 | // 250k bps |
| 81 | can.set_bitrate(250_000); | 81 | can.set_bitrate(250_000); |
| 82 | 82 | ||
| 83 | can.can.set_extended_filter( | 83 | can.set_extended_filter( |
| 84 | can::filter::ExtendedFilterSlot::_0, | 84 | can::fd::filter::ExtendedFilterSlot::_0, |
| 85 | can::filter::ExtendedFilter::accept_all_into_fifo1(), | 85 | can::fd::filter::ExtendedFilter::accept_all_into_fifo1(), |
| 86 | ); | 86 | ); |
| 87 | 87 | ||
| 88 | let mut can = can.into_internal_loopback_mode(); | 88 | let mut can = can.into_internal_loopback_mode(); |
| @@ -91,31 +91,21 @@ async fn main(_spawner: Spawner) { | |||
| 91 | 91 | ||
| 92 | let mut i: u8 = 0; | 92 | let mut i: u8 = 0; |
| 93 | loop { | 93 | loop { |
| 94 | let tx_frame = can::TxFrame::new( | 94 | let tx_frame = can::frame::ClassicFrame::new_standard(0x123, &[i; 1]).unwrap(); |
| 95 | can::TxFrameHeader { | ||
| 96 | len: 1, | ||
| 97 | frame_format: can::FrameFormat::Standard, | ||
| 98 | id: can::StandardId::new(0x123).unwrap().into(), | ||
| 99 | bit_rate_switching: false, | ||
| 100 | marker: None, | ||
| 101 | }, | ||
| 102 | &[i], | ||
| 103 | ) | ||
| 104 | .unwrap(); | ||
| 105 | 95 | ||
| 106 | info!("Transmitting frame..."); | 96 | info!("Transmitting frame..."); |
| 107 | let tx_ts = Instant::now(); | 97 | let tx_ts = Instant::now(); |
| 108 | can.write(&tx_frame).await; | 98 | can.write(&tx_frame).await; |
| 109 | 99 | ||
| 110 | let envelope = can.read().await.unwrap(); | 100 | let (frame, timestamp) = can.read().await.unwrap(); |
| 111 | info!("Frame received!"); | 101 | info!("Frame received!"); |
| 112 | 102 | ||
| 113 | // Check data. | 103 | // Check data. |
| 114 | assert!(i == envelope.data()[0], "{} == {}", i, envelope.data()[0]); | 104 | assert!(i == frame.data()[0], "{} == {}", i, frame.data()[0]); |
| 115 | 105 | ||
| 116 | info!("loopback time {}", envelope.header.time_stamp); | 106 | info!("loopback time {}", timestamp); |
| 117 | info!("loopback frame {=u8}", envelope.data()[0]); | 107 | info!("loopback frame {=u8}", frame.data()[0]); |
| 118 | let latency = envelope.timestamp.saturating_duration_since(tx_ts); | 108 | let latency = timestamp.saturating_duration_since(tx_ts); |
| 119 | info!("loopback latency {} us", latency.as_micros()); | 109 | info!("loopback latency {} us", latency.as_micros()); |
| 120 | 110 | ||
| 121 | // Theoretical minimum latency is 55us, actual is usually ~80us | 111 | // Theoretical minimum latency is 55us, actual is usually ~80us |
| @@ -143,47 +133,26 @@ async fn main(_spawner: Spawner) { | |||
| 143 | // in each FIFO so make sure we write enough to fill them both up before reading. | 133 | // in each FIFO so make sure we write enough to fill them both up before reading. |
| 144 | for i in 0..3 { | 134 | for i in 0..3 { |
| 145 | // Try filling up the RX FIFO0 buffers with standard packets | 135 | // Try filling up the RX FIFO0 buffers with standard packets |
| 146 | let tx_frame = can::TxFrame::new( | 136 | let tx_frame = can::frame::ClassicFrame::new_standard(0x123, &[i; 1]).unwrap(); |
| 147 | can::TxFrameHeader { | ||
| 148 | len: 1, | ||
| 149 | frame_format: can::FrameFormat::Standard, | ||
| 150 | id: can::StandardId::new(0x123).unwrap().into(), | ||
| 151 | bit_rate_switching: false, | ||
| 152 | marker: None, | ||
| 153 | }, | ||
| 154 | &[i], | ||
| 155 | ) | ||
| 156 | .unwrap(); | ||
| 157 | info!("Transmitting frame {}", i); | 137 | info!("Transmitting frame {}", i); |
| 158 | can.write(&tx_frame).await; | 138 | can.write(&tx_frame).await; |
| 159 | } | 139 | } |
| 160 | for i in 3..max_buffered { | 140 | for i in 3..max_buffered { |
| 161 | // Try filling up the RX FIFO0 buffers with extended packets | 141 | // Try filling up the RX FIFO0 buffers with extended packets |
| 162 | let tx_frame = can::TxFrame::new( | 142 | let tx_frame = can::frame::ClassicFrame::new_extended(0x1232344, &[i; 1]).unwrap(); |
| 163 | can::TxFrameHeader { | ||
| 164 | len: 1, | ||
| 165 | frame_format: can::FrameFormat::Standard, | ||
| 166 | id: can::ExtendedId::new(0x1232344).unwrap().into(), | ||
| 167 | bit_rate_switching: false, | ||
| 168 | marker: None, | ||
| 169 | }, | ||
| 170 | &[i], | ||
| 171 | ) | ||
| 172 | .unwrap(); | ||
| 173 | |||
| 174 | info!("Transmitting frame {}", i); | 143 | info!("Transmitting frame {}", i); |
| 175 | can.write(&tx_frame).await; | 144 | can.write(&tx_frame).await; |
| 176 | } | 145 | } |
| 177 | 146 | ||
| 178 | // Try and receive all 6 packets | 147 | // Try and receive all 6 packets |
| 179 | for i in 0..max_buffered { | 148 | for i in 0..max_buffered { |
| 180 | let envelope = can.read().await.unwrap(); | 149 | let (frame, _ts) = can.read().await.unwrap(); |
| 181 | match envelope.header.id { | 150 | match frame.id() { |
| 182 | can::Id::Extended(id) => { | 151 | embedded_can::Id::Extended(id) => { |
| 183 | info!("Extended received! {:x} {} {}", id.as_raw(), envelope.data()[0], i); | 152 | info!("Extended received! {:x} {} {}", id.as_raw(), frame.data()[0], i); |
| 184 | } | 153 | } |
| 185 | can::Id::Standard(id) => { | 154 | embedded_can::Id::Standard(id) => { |
| 186 | info!("Standard received! {:x} {} {}", id.as_raw(), envelope.data()[0], i); | 155 | info!("Standard received! {:x} {} {}", id.as_raw(), frame.data()[0], i); |
| 187 | } | 156 | } |
| 188 | } | 157 | } |
| 189 | } | 158 | } |
| @@ -192,48 +161,26 @@ async fn main(_spawner: Spawner) { | |||
| 192 | let (mut tx, mut rx) = can.split(); | 161 | let (mut tx, mut rx) = can.split(); |
| 193 | for i in 0..3 { | 162 | for i in 0..3 { |
| 194 | // Try filling up the RX FIFO0 buffers with standard packets | 163 | // Try filling up the RX FIFO0 buffers with standard packets |
| 195 | let tx_frame = can::TxFrame::new( | 164 | let tx_frame = can::frame::ClassicFrame::new_standard(0x123, &[i; 1]).unwrap(); |
| 196 | can::TxFrameHeader { | ||
| 197 | len: 1, | ||
| 198 | frame_format: can::FrameFormat::Standard, | ||
| 199 | id: can::StandardId::new(0x123).unwrap().into(), | ||
| 200 | bit_rate_switching: false, | ||
| 201 | marker: None, | ||
| 202 | }, | ||
| 203 | &[i], | ||
| 204 | ) | ||
| 205 | .unwrap(); | ||
| 206 | |||
| 207 | info!("Transmitting frame {}", i); | 165 | info!("Transmitting frame {}", i); |
| 208 | tx.write(&tx_frame).await; | 166 | tx.write(&tx_frame).await; |
| 209 | } | 167 | } |
| 210 | for i in 3..max_buffered { | 168 | for i in 3..max_buffered { |
| 211 | // Try filling up the RX FIFO0 buffers with extended packets | 169 | // Try filling up the RX FIFO0 buffers with extended packets |
| 212 | let tx_frame = can::TxFrame::new( | 170 | let tx_frame = can::frame::ClassicFrame::new_extended(0x1232344, &[i; 1]).unwrap(); |
| 213 | can::TxFrameHeader { | ||
| 214 | len: 1, | ||
| 215 | frame_format: can::FrameFormat::Standard, | ||
| 216 | id: can::ExtendedId::new(0x1232344).unwrap().into(), | ||
| 217 | bit_rate_switching: false, | ||
| 218 | marker: None, | ||
| 219 | }, | ||
| 220 | &[i], | ||
| 221 | ) | ||
| 222 | .unwrap(); | ||
| 223 | |||
| 224 | info!("Transmitting frame {}", i); | 171 | info!("Transmitting frame {}", i); |
| 225 | tx.write(&tx_frame).await; | 172 | tx.write(&tx_frame).await; |
| 226 | } | 173 | } |
| 227 | 174 | ||
| 228 | // Try and receive all 6 packets | 175 | // Try and receive all 6 packets |
| 229 | for i in 0..max_buffered { | 176 | for i in 0..max_buffered { |
| 230 | let envelope = rx.read().await.unwrap(); | 177 | let (frame, _ts) = rx.read().await.unwrap(); |
| 231 | match envelope.header.id { | 178 | match frame.id() { |
| 232 | can::Id::Extended(id) => { | 179 | embedded_can::Id::Extended(id) => { |
| 233 | info!("Extended received! {:x} {} {}", id.as_raw(), envelope.data()[0], i); | 180 | info!("Extended received! {:x} {} {}", id.as_raw(), frame.data()[0], i); |
| 234 | } | 181 | } |
| 235 | can::Id::Standard(id) => { | 182 | embedded_can::Id::Standard(id) => { |
| 236 | info!("Standard received! {:x} {} {}", id.as_raw(), envelope.data()[0], i); | 183 | info!("Standard received! {:x} {} {}", id.as_raw(), frame.data()[0], i); |
| 237 | } | 184 | } |
| 238 | } | 185 | } |
| 239 | } | 186 | } |
diff --git a/tests/stm32/src/common.rs b/tests/stm32/src/common.rs index 50a7f9bae..1e6b1cce9 100644 --- a/tests/stm32/src/common.rs +++ b/tests/stm32/src/common.rs | |||
| @@ -577,7 +577,18 @@ pub fn config() -> Config { | |||
| 577 | #[cfg(any(feature = "stm32u585ai", feature = "stm32u5a5zj"))] | 577 | #[cfg(any(feature = "stm32u585ai", feature = "stm32u5a5zj"))] |
| 578 | { | 578 | { |
| 579 | use embassy_stm32::rcc::*; | 579 | use embassy_stm32::rcc::*; |
| 580 | config.rcc.mux = ClockSrc::MSI(Msirange::RANGE_48MHZ); | 580 | config.rcc.hsi = true; |
| 581 | config.rcc.pll1 = Some(Pll { | ||
| 582 | source: PllSource::HSI, // 16 MHz | ||
| 583 | prediv: PllPreDiv::DIV1, | ||
| 584 | mul: PllMul::MUL10, | ||
| 585 | divp: None, | ||
| 586 | divq: None, | ||
| 587 | divr: Some(PllDiv::DIV1), // 160 MHz | ||
| 588 | }); | ||
| 589 | config.rcc.mux = ClockSrc::PLL1_R; | ||
| 590 | config.rcc.voltage_range = VoltageScale::RANGE1; | ||
| 591 | config.rcc.hsi48 = Some(Hsi48Config { sync_from_usb: true }); // needed for USB | ||
| 581 | } | 592 | } |
| 582 | 593 | ||
| 583 | #[cfg(feature = "stm32wba52cg")] | 594 | #[cfg(feature = "stm32wba52cg")] |
