Skip to content

Commit

Permalink
test(spim0): print on uDMA UART
Browse files Browse the repository at this point in the history
  • Loading branch information
hegza committed Nov 5, 2024
1 parent cc16a78 commit 8dbed2d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions examples/sysctrl/hello-sysctrl/examples/spim0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@
#![no_main]

use core::arch::asm;
use headsail_bsp::apb_uart::ApbUart0;
use headsail_bsp::{pac::Sysctrl, rt::entry, sysctrl::udma::Udma};
use headsail_bsp::{
pac::Sysctrl,
rt::entry,
sysctrl::{soc_ctrl, udma::Udma},
ufmt,
};
use hello_sysctrl::{print_example_name, sprintln};

#[entry]
fn main() -> ! {
// These lines are necessary to initialize uDMA UART prints for sprint-macro
soc_ctrl::periph_clk_div_set(0);
hello_sysctrl::UdmaUart::init();
print_example_name!();

let sysctrl = unsafe { Sysctrl::steal() };
let udma = Udma(sysctrl.udma());

// Split uDMA into sub-drivers for each peripheral
let udma_periphs = udma.split();

let (soc_freq, baud) = (30_000_000, 115_200);
let mut uart = ApbUart0::init(soc_freq, baud);

let mut spim = udma_periphs.spim.enable();
uart.write_str("SPI enabled!\n\r");
sprintln!("SPI enabled!");

let tx_data: [u8; 8] = [0x01, 0x42, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08];
let rx_data: [u8; 8] = [0; 8];
Expand All @@ -32,7 +39,7 @@ fn main() -> ! {
// Send 8 bytes
spim.send_data(&tx_data);
spim.write_eot_keep_cs();
uart.write_str("Data sent!\n\r");
sprintln!("Data sent!\n\r");

for _ in 0..10_000 {
unsafe { asm!("nop") }
Expand All @@ -41,7 +48,7 @@ fn main() -> ! {
// Receive 8 bytes
spim.receive_data(&rx_data);
spim.write_eot();
uart.write_str("Data received!\n\r");
sprintln!("Data received!\n\r");

loop {
continue;
Expand Down

0 comments on commit 8dbed2d

Please sign in to comment.