From 01355f98736c163790694f52c977b1cd3f853ede Mon Sep 17 00:00:00 2001 From: Yilin Sun Date: Sat, 28 Jan 2023 23:27:13 +0800 Subject: [PATCH] Fixed build issues. Signed-off-by: Yilin Sun --- .cargo/config.toml | 3 ++- Cargo.lock | 1 + Cargo.toml | 2 +- src/main.rs | 27 +++++++++++++++++++++------ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 64f6f8c..32a0542 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,7 +1,8 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] rustflags = [ # LLD (shipped with the Rust toolchain) is used as the default linker "-C", "link-arg=-Tlink.x", ] [build] -target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ +target = "thumbv6m-none-eabi" diff --git a/Cargo.lock b/Cargo.lock index a76b67c..ea6d988 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,6 +46,7 @@ checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9" dependencies = [ "bare-metal", "bitfield", + "critical-section", "embedded-hal", "volatile-register", ] diff --git a/Cargo.toml b/Cargo.toml index da65136..2e67c57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] ch57x-pac = {git = "https://git.minori.work/Embedded_SDK/WCH_CH57x_PAC.git", features = ["critical-section"]} -cortex-m = "0.7.6" +cortex-m = {version = "0.7.6", features = ["critical-section-single-core"]} cortex-m-rt = "0.6.13" cortex-m-semihosting = "0.3.3" panic-halt = "0.2.0" diff --git a/src/main.rs b/src/main.rs index 87488db..743e1f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ use panic_halt as _; -use cortex_m::asm; use cortex_m::peripheral::syst; use cortex_m_rt::entry; @@ -17,14 +16,30 @@ fn main() -> ! { let mut systick = core_peripherals.SYST; systick.set_clock_source(syst::SystClkSource::Core); - systick.set_reload(16_000); + systick.set_reload(8_000_000); systick.clear_current(); systick.enable_counter(); - while !systick.has_wrapped() { - asm::nop(); - } + let ch57x_sys = peripherals.SYS; - loop {} + /* PB0: LED, data set to 1 */ + ch57x_sys.r32_pb_out__r8_slv_rd_data.modify(|r, w| unsafe { + w.bits(r.bits() | 0x01) + }); + + /* PB0: LED, direction set to output */ + ch57x_sys.r32_pb_dir.modify(|r, w| unsafe { + w.bits(r.bits() | 0x01) + }); + + loop { + while !systick.has_wrapped() { + } + + /* Toggle LED */ + ch57x_sys.r32_pb_out__r8_slv_rd_data.modify(|r, w| unsafe { + w.bits(r.bits() ^ 0x01) + }); + } }