-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BSP: * Depend optionally on headsail-pac * Expose PAC * Fix GPIO bug * Add periph_clk_div_set * Sanitize feature hierarchy * Add HAL for uDMA UART SysCtrl tests: * Update led test notes * Use debug syms in release builds * gdb(sysctrl): load program on connect * Use -Fpanic-apb-uart0 * Use -Fbsp/sysctrl-pac * Rename apb_uart0 * Add test: original raw led blinker * Add test: PAC-based uDMA UART * Add test: uDMA UART HAL
- Loading branch information
Showing
17 changed files
with
295 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
//! Abstractions that only exist on SysCtrl | ||
pub mod gpio; | ||
pub mod soc_ctrl; | ||
#[cfg(feature = "pac")] | ||
pub mod udma; | ||
|
||
mod interrupt; | ||
mod mmap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
pub mod uart; | ||
|
||
use core::marker::PhantomData; | ||
|
||
use crate::pac; | ||
pub use uart::UdmaUart; | ||
|
||
/// Type-state trait for uDMA peripherals in different states | ||
pub trait UdmaPeriphState {} | ||
|
||
pub struct Enabled; | ||
impl UdmaPeriphState for Enabled {} | ||
|
||
pub struct Disabled; | ||
impl UdmaPeriphState for Disabled {} | ||
|
||
/// Relocatable driver for uDMA IP | ||
pub struct Udma<'u>(pub &'u pac::sysctrl::Udma); | ||
|
||
pub struct UdmaParts<'u> { | ||
pub uart: UdmaUart<'u, Disabled>, | ||
} | ||
|
||
impl<'u> Udma<'u> { | ||
pub fn split(self) -> UdmaParts<'u> { | ||
UdmaParts { | ||
uart: UdmaUart::<Disabled>(self.0, PhantomData::default()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use core::marker::PhantomData; | ||
|
||
use super::{Disabled, Enabled}; | ||
use crate::pac; | ||
|
||
/// Obtain an instance by calling [Udma::split] | ||
pub struct UdmaUart<'u, UdmaPeriphState>( | ||
pub(crate) &'u pac::sysctrl::Udma, | ||
pub(crate) PhantomData<UdmaPeriphState>, | ||
); | ||
|
||
type UartSetupW = pac::sysctrl::udma::uart_setup::W; | ||
|
||
impl<'u> UdmaUart<'u, Disabled> { | ||
#[inline] | ||
pub fn enable<F>(self, setup_spec: F) -> UdmaUart<'u, Enabled> | ||
where | ||
F: FnOnce(&mut UartSetupW) -> &mut UartSetupW, | ||
{ | ||
let udma = &self.0; | ||
|
||
// Turn on the clock gates for UART | ||
udma.ctrl_cfg_cg().modify(|_r, w| w.cg_uart().set_bit()); | ||
|
||
// Setup UART | ||
udma.uart_setup().write(|w| unsafe { w.bits(0) }); | ||
udma.uart_setup().write(setup_spec); | ||
|
||
UdmaUart::<Enabled>(self.0, PhantomData::default()) | ||
} | ||
} | ||
|
||
impl<'u> UdmaUart<'u, Enabled> { | ||
#[inline] | ||
pub fn disable(self) -> UdmaUart<'u, Disabled> { | ||
self.0.ctrl_cfg_cg().modify(|_r, w| w.cg_uart().clear_bit()); | ||
UdmaUart::<Disabled>(self.0, PhantomData::default()) | ||
} | ||
|
||
/// # Safety | ||
/// | ||
/// This will not configure the UART in any way. | ||
#[inline] | ||
pub unsafe fn steal(udma: &'static pac::sysctrl::Udma) -> Self { | ||
Self(udma, PhantomData::default()) | ||
} | ||
|
||
#[inline] | ||
pub fn write(&mut self, buf: &[u8]) { | ||
let udma = &self.0; | ||
|
||
// Write buffer location & len | ||
udma.uart_tx_saddr() | ||
.write(|w| unsafe { w.bits(buf.as_ptr() as u32) }); | ||
udma.uart_tx_size() | ||
.write(|w| unsafe { w.bits(buf.len() as u32) }); | ||
|
||
// Dispatch transmission | ||
udma.uart_tx_cfg().write( | ||
|w| w.en().set_bit(), // If we want "continuous mode". In continuous mode, uDMA reloads the address and transmits it again | ||
//.continous().set_bit() | ||
); | ||
|
||
// Poll until finished (prevents `buf` leakage) | ||
while udma.uart_tx_saddr().read().bits() != 0 {} | ||
} | ||
|
||
#[inline] | ||
pub fn write_str(&mut self, s: &str) { | ||
self.write(s.as_bytes()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[workspace] | ||
members = ["hello-sysctrl"] | ||
resolver = "2" | ||
|
||
[profile.release] | ||
debug = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Sysctrl is exposed at to 3333 | ||
target remote :3333 | ||
backtrace | ||
load | ||
backtrace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//! Blinks a LED | ||
//! | ||
//! Tested working on ASIC: 2024-08-23 | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::ptr; | ||
use headsail_bsp::rt::entry; | ||
|
||
// Below addresses are in SysCtrl memory space | ||
const GPIO: usize = 0x1a10_1000; | ||
const GPIO_DIR: usize = GPIO + 0x0; | ||
const GPIO_OUT: usize = GPIO + 0xc; | ||
const SOC_CONTROL: usize = 0x1a10_4000; | ||
const PADMUX0: usize = SOC_CONTROL + 0x10; | ||
|
||
// Number of nops SysCtrl is capable of executing at 30 MHz reference clocks | ||
const NOPS_PER_SEC: usize = match () { | ||
#[cfg(debug_assertions)] | ||
// This is an experimentally found value | ||
() => 2_000_000 / 9, | ||
#[cfg(not(debug_assertions))] | ||
// This is just a guess for now (10x debug) | ||
() => 200_000 / 9, | ||
}; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
unsafe { | ||
ptr::write_volatile(PADMUX0 as *mut _, 0); | ||
ptr::write_volatile(GPIO_DIR as *mut _, 0); | ||
|
||
// Padmux enable GPIO9 | ||
ptr::write_volatile(PADMUX0 as *mut _, 0x40000); | ||
|
||
// Set GPIO 9 as output | ||
ptr::write_volatile(GPIO_DIR as *mut _, 1 << 9); | ||
} | ||
|
||
loop { | ||
unsafe { | ||
// Toggle GPIO | ||
let mut r = ptr::read_volatile(GPIO_OUT as *mut u32); | ||
r ^= 1 << 9; | ||
ptr::write_volatile(GPIO_OUT as *mut u32, r); | ||
|
||
// 1 second period | ||
for _ in 0..NOPS_PER_SEC { | ||
core::arch::asm!("nop"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! Prints over SysCtrl UART | ||
#![no_std] | ||
#![no_main] | ||
|
||
use headsail_bsp::{pac, rt::entry, sysctrl::udma::Udma}; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let sysctrl = unsafe { pac::Sysctrl::steal() }; | ||
let udma = Udma(sysctrl.udma()); | ||
|
||
// Set the bit length, enable TX, set clk_div | ||
let (soc_freq, baud) = (30_000_000, 9600_u32); | ||
let clk_div: u16 = (soc_freq / baud) as u16; | ||
let mut uart = udma.split().uart.enable(|w| { | ||
unsafe { | ||
w | ||
// Use this if using parity bit | ||
.parity_ena() | ||
.bit(false) | ||
.bit_length() | ||
.bits(0b11) | ||
// Stop bit? | ||
.stop_bits() | ||
.bit(false) | ||
.tx_ena() | ||
.bit(true) | ||
.rx_ena() | ||
.bit(true) | ||
.clkdiv() | ||
.bits(clk_div) | ||
} | ||
}); | ||
|
||
uart.write(b"Hello uDMA UART HAL\r\n"); | ||
|
||
loop {} | ||
} |
Oops, something went wrong.