aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-08-03 12:22:32 -0400
committerBrian Cully <bjc@kublai.com>2022-08-03 12:22:32 -0400
commit5062ac0818f07bfe07714039c46018172a79ee76 (patch)
tree30fc652f05e8e148d80c1cd02c29046dea075c56 /src
parent17cac5fe6421e144619f4828409e8174986f3e3b (diff)
downloadluchie-5062ac0818f07bfe07714039c46018172a79ee76.tar.gz
luchie-5062ac0818f07bfe07714039c46018172a79ee76.zip
Blinking achieved.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main.rs53
1 files changed, 50 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 0f77639..c0d41d3 100755
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,10 +4,49 @@
#![no_main]
use core::arch::asm;
+use gd32vf103_pac::Peripherals;
#[no_mangle]
fn main(_hartid: usize) -> ! {
- loop {}
+ // let peripherals = Peripherals::take().unwrap();
+ let peripherals = unsafe { Peripherals::steal() };
+
+ let rcu = peripherals.RCU;
+ // enable RCU_GPIOA
+ rcu.apb2en.write(|w| {
+ w.paen().set_bit()
+ });
+
+ let gpio = peripherals.GPIOA;
+ // led is gpioa pin 7 output push/pull 50mhz
+ gpio.ctl0.write(|w| unsafe {
+ // output mode, push-pull
+ w.ctl7().bits(0b00);
+ // 50 mhz output rate
+ w.md7().bits(0b11);
+ w
+ });
+
+ let mut led_on = false;
+ loop {
+ if led_on {
+ gpio.bc.write(|w| w.cr7().set_bit());
+ if gpio.octl.read().octl7().bit() {
+ panic!("not set");
+ }
+ } else {
+ gpio.bop.write(|w| w.bop7().set_bit());
+ if !gpio.octl.read().octl7().bit() {
+ panic!("set");
+ }
+ }
+ led_on = !led_on;
+
+ let mut a = 0;
+ for _ in 1..100_000 {
+ a = gpio.octl.read().bits();
+ }
+ }
}
#[naked]
@@ -27,12 +66,20 @@ unsafe extern "C" fn _start() -> ! {
"csrr a0, mhartid",
"la sp, _stack_top",
- "j main",
+ "tail main",
options(noreturn)
)
}
#[panic_handler]
-fn panic(_info: &core::panic::PanicInfo) -> ! {
+fn panic(info: &core::panic::PanicInfo) -> ! {
+ if let Some(loc) = info.location() {
+ let _file = loc.file();
+ let _line = loc.line();
+ if let Some(_msg) = info.payload().downcast_ref::<&str>() {
+ loop {}
+ }
+ loop {}
+ }
loop {}
}