Merge branch 'main' into add-rng
This commit is contained in:
175
examples/mimxrt6/src/bin/crc.rs
Normal file
175
examples/mimxrt6/src/bin/crc.rs
Normal file
@@ -0,0 +1,175 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate embassy_imxrt_examples;
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_imxrt::crc::{Config, Crc, Polynomial};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut p = embassy_imxrt::init(Default::default());
|
||||
let data = b"123456789";
|
||||
|
||||
info!("Initializing CRC");
|
||||
|
||||
// CRC-CCITT
|
||||
let mut crc = Crc::new(p.CRC.reborrow(), Default::default());
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x29b1);
|
||||
|
||||
// CRC16-ARC
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc16,
|
||||
reverse_in: true,
|
||||
reverse_out: true,
|
||||
complement_out: false,
|
||||
seed: 0,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0xbb3d);
|
||||
|
||||
// CRC16-CMS
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc16,
|
||||
reverse_in: false,
|
||||
reverse_out: false,
|
||||
complement_out: false,
|
||||
seed: 0xffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0xaee7);
|
||||
|
||||
// CRC16-DDS-110
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc16,
|
||||
reverse_in: false,
|
||||
reverse_out: false,
|
||||
complement_out: false,
|
||||
seed: 0x800d,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x9ecf);
|
||||
|
||||
// CRC16-MAXIM-DOW
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc16,
|
||||
reverse_in: true,
|
||||
reverse_out: true,
|
||||
complement_out: true,
|
||||
seed: 0,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x44c2);
|
||||
|
||||
// CRC16-MODBUS
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc16,
|
||||
reverse_in: true,
|
||||
reverse_out: true,
|
||||
complement_out: false,
|
||||
seed: 0xffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x4b37);
|
||||
|
||||
// CRC32-BZIP2
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc32,
|
||||
reverse_in: false,
|
||||
reverse_out: false,
|
||||
complement_out: true,
|
||||
seed: 0xffff_ffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0xfc89_1918);
|
||||
|
||||
// CRC32-CKSUM
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc32,
|
||||
reverse_in: false,
|
||||
reverse_out: false,
|
||||
complement_out: true,
|
||||
seed: 0,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x765e_7680);
|
||||
|
||||
// CRC32-ISO-HDLC
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc32,
|
||||
reverse_in: true,
|
||||
reverse_out: true,
|
||||
complement_out: true,
|
||||
seed: 0xffff_ffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0xcbf4_3926);
|
||||
|
||||
// CRC32-JAMCRC
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc32,
|
||||
reverse_in: true,
|
||||
reverse_out: true,
|
||||
complement_out: false,
|
||||
seed: 0xffff_ffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x340b_c6d9);
|
||||
|
||||
// CRC32-MPEG-2
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc32,
|
||||
reverse_in: false,
|
||||
reverse_out: false,
|
||||
complement_out: false,
|
||||
seed: 0xffff_ffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x0376_e6e7);
|
||||
|
||||
info!("end program");
|
||||
cortex_m::asm::bkpt();
|
||||
}
|
||||
64
examples/rp/src/bin/overclock.rs
Normal file
64
examples/rp/src/bin/overclock.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
//! # Overclocking the RP2040 to 200 MHz
|
||||
//!
|
||||
//! This example demonstrates how to configure the RP2040 to run at 200 MHz.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::clocks::{clk_sys_freq, ClockConfig};
|
||||
use embassy_rp::config::Config;
|
||||
use embassy_rp::gpio::{Level, Output};
|
||||
use embassy_time::{Duration, Instant, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const COUNT_TO: i64 = 10_000_000;
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
// Set up for clock frequency of 200 MHz, setting all necessary defaults.
|
||||
let config = Config::new(ClockConfig::system_freq(200_000_000));
|
||||
|
||||
// Show the voltage scale for verification
|
||||
info!("System core voltage: {}", Debug2Format(&config.clocks.core_voltage));
|
||||
|
||||
// Initialize the peripherals
|
||||
let p = embassy_rp::init(config);
|
||||
|
||||
// Show CPU frequency for verification
|
||||
let sys_freq = clk_sys_freq();
|
||||
info!("System clock frequency: {} MHz", sys_freq / 1_000_000);
|
||||
|
||||
// LED to indicate the system is running
|
||||
let mut led = Output::new(p.PIN_25, Level::Low);
|
||||
|
||||
loop {
|
||||
// Reset the counter at the start of measurement period
|
||||
let mut counter = 0;
|
||||
|
||||
// Turn LED on while counting
|
||||
led.set_high();
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
// This is a busy loop that will take some time to complete
|
||||
while counter < COUNT_TO {
|
||||
counter += 1;
|
||||
}
|
||||
|
||||
let elapsed = Instant::now() - start;
|
||||
|
||||
// Report the elapsed time
|
||||
led.set_low();
|
||||
info!(
|
||||
"At {}Mhz: Elapsed time to count to {}: {}ms",
|
||||
sys_freq / 1_000_000,
|
||||
counter,
|
||||
elapsed.as_millis()
|
||||
);
|
||||
|
||||
// Wait 2 seconds before starting the next measurement
|
||||
Timer::after(Duration::from_secs(2)).await;
|
||||
}
|
||||
}
|
||||
79
examples/rp/src/bin/overclock_manual.rs
Normal file
79
examples/rp/src/bin/overclock_manual.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
//! # Overclocking the RP2040 to 200 MHz manually
|
||||
//!
|
||||
//! This example demonstrates how to manually configure the RP2040 to run at 200 MHz.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::clocks;
|
||||
use embassy_rp::clocks::{ClockConfig, CoreVoltage, PllConfig};
|
||||
use embassy_rp::config::Config;
|
||||
use embassy_rp::gpio::{Level, Output};
|
||||
use embassy_time::{Duration, Instant, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const COUNT_TO: i64 = 10_000_000;
|
||||
|
||||
/// Configure the RP2040 for 200 MHz operation by manually specifying the PLL settings.
|
||||
fn configure_manual_overclock() -> Config {
|
||||
// Set the PLL configuration manually, starting from default values
|
||||
let mut config = Config::default();
|
||||
|
||||
// Set the system clock to 200 MHz
|
||||
config.clocks = ClockConfig::manual_pll(
|
||||
12_000_000, // Crystal frequency, 12 MHz is common. If using custom, set to your value.
|
||||
PllConfig {
|
||||
refdiv: 1, // Reference divider
|
||||
fbdiv: 100, // Feedback divider
|
||||
post_div1: 3, // Post divider 1
|
||||
post_div2: 2, // Post divider 2
|
||||
},
|
||||
CoreVoltage::V1_15, // Core voltage, should be set to V1_15 for 200 MHz
|
||||
);
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
// Initialize with our manual overclock configuration
|
||||
let p = embassy_rp::init(configure_manual_overclock());
|
||||
|
||||
// Verify the actual system clock frequency
|
||||
let sys_freq = clocks::clk_sys_freq();
|
||||
info!("System clock frequency: {} MHz", sys_freq / 1_000_000);
|
||||
|
||||
// LED to indicate the system is running
|
||||
let mut led = Output::new(p.PIN_25, Level::Low);
|
||||
|
||||
loop {
|
||||
// Reset the counter at the start of measurement period
|
||||
let mut counter = 0;
|
||||
|
||||
// Turn LED on while counting
|
||||
led.set_high();
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
// This is a busy loop that will take some time to complete
|
||||
while counter < COUNT_TO {
|
||||
counter += 1;
|
||||
}
|
||||
|
||||
let elapsed = Instant::now() - start;
|
||||
|
||||
// Report the elapsed time
|
||||
led.set_low();
|
||||
info!(
|
||||
"At {}Mhz: Elapsed time to count to {}: {}ms",
|
||||
sys_freq / 1_000_000,
|
||||
counter,
|
||||
elapsed.as_millis()
|
||||
);
|
||||
|
||||
// Wait 2 seconds before starting the next measurement
|
||||
Timer::after(Duration::from_secs(2)).await;
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ use rand::RngCore;
|
||||
use static_cell::{ConstStaticCell, StaticCell};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
type UartAsyncMutex = mutex::Mutex<CriticalSectionRawMutex, UartTx<'static, UART0, uart::Async>>;
|
||||
type UartAsyncMutex = mutex::Mutex<CriticalSectionRawMutex, UartTx<'static, uart::Async>>;
|
||||
|
||||
struct MyType {
|
||||
inner: u32,
|
||||
|
||||
@@ -48,7 +48,7 @@ async fn main(spawner: Spawner) {
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn reader(mut rx: BufferedUartRx<'static, UART0>) {
|
||||
async fn reader(mut rx: BufferedUartRx) {
|
||||
info!("Reading...");
|
||||
loop {
|
||||
let mut buf = [0; 31];
|
||||
|
||||
@@ -39,7 +39,7 @@ async fn main(spawner: Spawner) {
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn reader(mut rx: UartRx<'static, UART1, Async>) {
|
||||
async fn reader(mut rx: UartRx<'static, Async>) {
|
||||
info!("Reading...");
|
||||
loop {
|
||||
// read a total of 4 transmissions (32 / 8) and then print the result
|
||||
|
||||
@@ -31,7 +31,7 @@ use rand::RngCore;
|
||||
use static_cell::{ConstStaticCell, StaticCell};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
type UartAsyncMutex = mutex::Mutex<CriticalSectionRawMutex, UartTx<'static, UART0, uart::Async>>;
|
||||
type UartAsyncMutex = mutex::Mutex<CriticalSectionRawMutex, UartTx<'static, uart::Async>>;
|
||||
|
||||
struct MyType {
|
||||
inner: u32,
|
||||
|
||||
@@ -48,7 +48,7 @@ async fn main(spawner: Spawner) {
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn reader(mut rx: BufferedUartRx<'static, UART0>) {
|
||||
async fn reader(mut rx: BufferedUartRx) {
|
||||
info!("Reading...");
|
||||
loop {
|
||||
let mut buf = [0; 31];
|
||||
|
||||
@@ -39,7 +39,7 @@ async fn main(spawner: Spawner) {
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn reader(mut rx: UartRx<'static, UART1, Async>) {
|
||||
async fn reader(mut rx: UartRx<'static, Async>) {
|
||||
info!("Reading...");
|
||||
loop {
|
||||
// read a total of 4 transmissions (32 / 8) and then print the result
|
||||
|
||||
Reference in New Issue
Block a user