diff options
| author | Corey Schuhen <[email protected]> | 2024-03-24 15:13:55 +1000 |
|---|---|---|
| committer | Corey Schuhen <[email protected]> | 2024-03-28 09:32:13 +1000 |
| commit | 2217b802781b5f2188b4da659aca47f9d89ee032 (patch) | |
| tree | 3054378ec4087372858312e74091f9a16ce26efd /tests/stm32/src/bin/fdcan.rs | |
| parent | f5daa50a7baceb44f2aad44bf6ce055bccb08433 (diff) | |
CAN: Unify API's between BXCAN and FDCAN. Use Envelope for all read methods instead of a tuple sometimes.
Diffstat (limited to 'tests/stm32/src/bin/fdcan.rs')
| -rw-r--r-- | tests/stm32/src/bin/fdcan.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/tests/stm32/src/bin/fdcan.rs b/tests/stm32/src/bin/fdcan.rs index c7373e294..bddfa7684 100644 --- a/tests/stm32/src/bin/fdcan.rs +++ b/tests/stm32/src/bin/fdcan.rs | |||
| @@ -79,8 +79,8 @@ async fn main(_spawner: Spawner) { | |||
| 79 | let options = options(); | 79 | let options = options(); |
| 80 | let peripherals = embassy_stm32::init(options.config); | 80 | let peripherals = embassy_stm32::init(options.config); |
| 81 | 81 | ||
| 82 | let mut can = can::FdcanConfigurator::new(peripherals.FDCAN1, peripherals.PB8, peripherals.PB9, Irqs1); | 82 | let mut can = can::CanConfigurator::new(peripherals.FDCAN1, peripherals.PB8, peripherals.PB9, Irqs1); |
| 83 | let mut can2 = can::FdcanConfigurator::new(peripherals.FDCAN2, peripherals.PB12, peripherals.PB13, Irqs2); | 83 | let mut can2 = can::CanConfigurator::new(peripherals.FDCAN2, peripherals.PB12, peripherals.PB13, Irqs2); |
| 84 | 84 | ||
| 85 | // 250k bps | 85 | // 250k bps |
| 86 | can.set_bitrate(250_000); | 86 | can.set_bitrate(250_000); |
| @@ -102,13 +102,13 @@ async fn main(_spawner: Spawner) { | |||
| 102 | 102 | ||
| 103 | let mut i: u8 = 0; | 103 | let mut i: u8 = 0; |
| 104 | loop { | 104 | loop { |
| 105 | let tx_frame = can::frame::ClassicFrame::new_standard(0x123, &[i; 1]).unwrap(); | 105 | let tx_frame = can::frame::Frame::new_standard(0x123, &[i; 1]).unwrap(); |
| 106 | 106 | ||
| 107 | info!("Transmitting frame..."); | 107 | info!("Transmitting frame..."); |
| 108 | let tx_ts = Instant::now(); | 108 | let tx_ts = Instant::now(); |
| 109 | can.write(&tx_frame).await; | 109 | can.write(&tx_frame).await; |
| 110 | 110 | ||
| 111 | let (frame, timestamp) = can.read().await.unwrap(); | 111 | let (frame, timestamp) = can.read().await.unwrap().parts(); |
| 112 | info!("Frame received!"); | 112 | info!("Frame received!"); |
| 113 | 113 | ||
| 114 | // Check data. | 114 | // Check data. |
| @@ -139,13 +139,13 @@ async fn main(_spawner: Spawner) { | |||
| 139 | 139 | ||
| 140 | let mut i: u8 = 0; | 140 | let mut i: u8 = 0; |
| 141 | loop { | 141 | loop { |
| 142 | let tx_frame = can::frame::ClassicFrame::new_standard(0x123, &[i; 1]).unwrap(); | 142 | let tx_frame = can::frame::Frame::new_standard(0x123, &[i; 1]).unwrap(); |
| 143 | 143 | ||
| 144 | info!("Transmitting frame..."); | 144 | info!("Transmitting frame..."); |
| 145 | let tx_ts = Instant::now(); | 145 | let tx_ts = Instant::now(); |
| 146 | can2.write(&tx_frame).await; | 146 | can2.write(&tx_frame).await; |
| 147 | 147 | ||
| 148 | let (frame, timestamp) = can2.read().await.unwrap(); | 148 | let (frame, timestamp) = can2.read().await.unwrap().parts(); |
| 149 | info!("Frame received!"); | 149 | info!("Frame received!"); |
| 150 | 150 | ||
| 151 | //print_regs().await; | 151 | //print_regs().await; |
| @@ -182,20 +182,20 @@ async fn main(_spawner: Spawner) { | |||
| 182 | // in each FIFO so make sure we write enough to fill them both up before reading. | 182 | // in each FIFO so make sure we write enough to fill them both up before reading. |
| 183 | for i in 0..3 { | 183 | for i in 0..3 { |
| 184 | // Try filling up the RX FIFO0 buffers with standard packets | 184 | // Try filling up the RX FIFO0 buffers with standard packets |
| 185 | let tx_frame = can::frame::ClassicFrame::new_standard(0x123, &[i; 1]).unwrap(); | 185 | let tx_frame = can::frame::Frame::new_standard(0x123, &[i; 1]).unwrap(); |
| 186 | info!("Transmitting frame {}", i); | 186 | info!("Transmitting frame {}", i); |
| 187 | can.write(&tx_frame).await; | 187 | can.write(&tx_frame).await; |
| 188 | } | 188 | } |
| 189 | for i in 3..max_buffered { | 189 | for i in 3..max_buffered { |
| 190 | // Try filling up the RX FIFO0 buffers with extended packets | 190 | // Try filling up the RX FIFO0 buffers with extended packets |
| 191 | let tx_frame = can::frame::ClassicFrame::new_extended(0x1232344, &[i; 1]).unwrap(); | 191 | let tx_frame = can::frame::Frame::new_extended(0x1232344, &[i; 1]).unwrap(); |
| 192 | info!("Transmitting frame {}", i); | 192 | info!("Transmitting frame {}", i); |
| 193 | can.write(&tx_frame).await; | 193 | can.write(&tx_frame).await; |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | // Try and receive all 6 packets | 196 | // Try and receive all 6 packets |
| 197 | for i in 0..max_buffered { | 197 | for i in 0..max_buffered { |
| 198 | let (frame, _ts) = can.read().await.unwrap(); | 198 | let (frame, _ts) = can.read().await.unwrap().parts(); |
| 199 | match frame.id() { | 199 | match frame.id() { |
| 200 | embedded_can::Id::Extended(id) => { | 200 | embedded_can::Id::Extended(id) => { |
| 201 | info!("Extended received! {:x} {} {}", id.as_raw(), frame.data()[0], i); | 201 | info!("Extended received! {:x} {} {}", id.as_raw(), frame.data()[0], i); |
| @@ -210,20 +210,20 @@ async fn main(_spawner: Spawner) { | |||
| 210 | let (mut tx, mut rx) = can.split(); | 210 | let (mut tx, mut rx) = can.split(); |
| 211 | for i in 0..3 { | 211 | for i in 0..3 { |
| 212 | // Try filling up the RX FIFO0 buffers with standard packets | 212 | // Try filling up the RX FIFO0 buffers with standard packets |
| 213 | let tx_frame = can::frame::ClassicFrame::new_standard(0x123, &[i; 1]).unwrap(); | 213 | let tx_frame = can::frame::Frame::new_standard(0x123, &[i; 1]).unwrap(); |
| 214 | info!("Transmitting frame {}", i); | 214 | info!("Transmitting frame {}", i); |
| 215 | tx.write(&tx_frame).await; | 215 | tx.write(&tx_frame).await; |
| 216 | } | 216 | } |
| 217 | for i in 3..max_buffered { | 217 | for i in 3..max_buffered { |
| 218 | // Try filling up the RX FIFO0 buffers with extended packets | 218 | // Try filling up the RX FIFO0 buffers with extended packets |
| 219 | let tx_frame = can::frame::ClassicFrame::new_extended(0x1232344, &[i; 1]).unwrap(); | 219 | let tx_frame = can::frame::Frame::new_extended(0x1232344, &[i; 1]).unwrap(); |
| 220 | info!("Transmitting frame {}", i); | 220 | info!("Transmitting frame {}", i); |
| 221 | tx.write(&tx_frame).await; | 221 | tx.write(&tx_frame).await; |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | // Try and receive all 6 packets | 224 | // Try and receive all 6 packets |
| 225 | for i in 0..max_buffered { | 225 | for i in 0..max_buffered { |
| 226 | let (frame, _ts) = rx.read().await.unwrap(); | 226 | let (frame, _ts) = rx.read().await.unwrap().parts(); |
| 227 | match frame.id() { | 227 | match frame.id() { |
| 228 | embedded_can::Id::Extended(id) => { | 228 | embedded_can::Id::Extended(id) => { |
| 229 | info!("Extended received! {:x} {} {}", id.as_raw(), frame.data()[0], i); | 229 | info!("Extended received! {:x} {} {}", id.as_raw(), frame.data()[0], i); |
