Skip to content

Instantly share code, notes, and snippets.

@agrif
Last active January 30, 2026 19:28
Show Gist options
  • Select an option

  • Save agrif/3bfc8afdafc01e0e9d2d95cc358e6d8f to your computer and use it in GitHub Desktop.

Select an option

Save agrif/3bfc8afdafc01e0e9d2d95cc358e6d8f to your computer and use it in GitHub Desktop.
#![no_main]
#![no_std]
use core::fmt::Write;
use panic_halt as _;
use rk3506_m0_pac as pac;
struct Buffer<const N: usize>([u8; N], usize);
impl<const N: usize> Buffer<N> {
pub const fn new() -> Self {
Self([0; N], 0)
}
pub fn reset(&mut self) {
self.1 = 0;
}
}
impl<const N: usize> core::fmt::Write for Buffer<N> {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
let buf = &mut self.0[self.1..];
if s.len() <= buf.len() {
buf[..s.len()].copy_from_slice(s.as_bytes());
self.1 += s.len();
Ok(())
} else {
Err(core::fmt::Error)
}
}
}
#[cortex_m_rt::entry]
fn main() -> ! {
static mut BUF: Buffer<256> = Buffer::new();
static mut COUNT_UP: u32 = 0;
static mut STATE: bool = false;
pac::GPIO1.swport_ddr(0).write_value(0x0001_0001);
loop {
*COUNT_UP += 1;
if *COUNT_UP > 50_000 {
*STATE = !*STATE;
*COUNT_UP = 0;
}
pac::GPIO1
.swport_dr(0)
.write_value(if *STATE { 0x0001_0001 } else { 0x0001_0000 });
BUF.reset();
write!(
BUF,
"Rockchip doesn't want you to know this but the SRAM other \
than 0xfff84000 is free and you can take them home I have \
{} loops. Version: {:#08x}",
COUNT_UP,
pac::GPIO0.ver_id().read(),
)
.unwrap();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment