noxime / hello-wch Goto Github PK
View Code? Open in Web Editor NEWRust example for the CH32V003
Rust example for the CH32V003
I compile hello-wch
and flash it to ch32v003 chip, and it works ok (LED blink):
#[entry]
fn main() -> ! {
let RCC_APB2PCENR: *mut u32 = 0x4002_1018 as _;
let GPIOC_CFGLR: *mut u32 = 0x4001_1000 as _;
let GPIOC_OUTDR: *mut u32 = 0x4001_100C as _;
unsafe {
// Enable clocks to the GPIOC bank
RCC_APB2PCENR.write_volatile(0b10000);
// Set pin 1 to output
GPIOC_CFGLR.write_volatile(0b0001_0000);
loop {
// Set pin 1 to high
GPIOC_OUTDR.write_volatile(0b1_0);
riscv::asm::delay(1_000_000);
// Set pin 1 to low
GPIOC_OUTDR.write_volatile(0b0_0);
riscv::asm::delay(2_000_000);
}
}
}
when I change the 2 delay value to the same value, it also works:
diff --git a/src/main.rs b/src/main.rs
index f65de71..addfb51 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,11 +19,11 @@ fn main() -> ! {
loop {
// Set pin 1 to high
GPIOC_OUTDR.write_volatile(0b1_0);
- riscv::asm::delay(1_000_000);
+ riscv::asm::delay(2_000_000);
// Set pin 1 to low
GPIOC_OUTDR.write_volatile(0b0_0);
- riscv::asm::delay(1_000_000);
+ riscv::asm::delay(2_000_000);
}
}
}
But when I change only one delay value, it does not work (LED not blink):
diff --git a/src/main.rs b/src/main.rs
index f65de71..1a1f0d9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,7 +23,7 @@ fn main() -> ! {
// Set pin 1 to low
GPIOC_OUTDR.write_volatile(0b0_0);
- riscv::asm::delay(1_000_000);
+ riscv::asm::delay(2_000_000);
}
}
}
I do not know what is wrong. Help wanted !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.