Skip to content

Commit 01d6564

Browse files
committed
Merge branch 'marti157/main'
2 parents b903828 + 1780cd0 commit 01d6564

File tree

7 files changed

+76
-13
lines changed

7 files changed

+76
-13
lines changed

build.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ fn main() {
2424
.unwrap()
2525
.to_ascii_lowercase();
2626

27-
// Add family cfg flags on the fly
28-
let chip_family = if chip_name.starts_with("ch32") {
29-
// On of ch32x0, ch32v0, ch32v1, ch32v2, ch32v3, ch32l1
30-
chip_name[..6].to_string()
27+
// Add chip name and family cfg flags on the fly
28+
let (chip_base_name, chip_family) = if chip_name.starts_with("ch32") {
29+
(chip_name[..8].to_string(), chip_name[..6].to_string())
3130
} else {
3231
// On of ch643, ch641
33-
chip_name[..4].to_string()
32+
(chip_name[..4].to_string(), chip_name[..4].to_string())
3433
};
35-
println!("cargo:rustc-cfg={}", chip_family);
34+
println!("cargo:rustc-cfg={}", chip_base_name); // ch32v103, ch32v003, ch32x035, ch643, ch641, etc.
35+
println!("cargo:rustc-cfg={}", chip_family); // On of ch32x0, ch32v0, ch32v1, ch32v2, ch32v3, ch32l1, ch643, ch641
3636

3737
// Add Qingke IP core version cfg flags on the fly
3838
// qingke_v2, qingke_v3, qingke_v4

examples/ch32v208/.cargo/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build]
2+
target = "riscv32imac-unknown-none-elf"
3+
4+
[target."riscv32imac-unknown-none-elf"]
5+
runner = "wlink -v flash --enable-sdi-print --watch-serial"
6+
# runner = "wlink -v flash"

examples/ch32v208/Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "ch32v208-examples"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
ch32-hal = { path = "../../", features = [
8+
"ch32v208wbu6",
9+
"defmt",
10+
"embassy",
11+
"rt",
12+
], default-features = false }
13+
embassy-executor = { version = "0.5.0", features = [
14+
"nightly",
15+
"integrated-timers",
16+
"arch-riscv32",
17+
"executor-thread",
18+
] }
19+
embassy-time = { version = "0.3.0" }
20+
21+
qingke-rt = { version = "0.2.0" }
22+
qingke = { version = "0.2.0" }
23+
# qingke-rt = { version = "0.2.0", path = "../../../qingke/qingke-rt" }
24+
# qingke = { version = "0.2.0", path = "../../../qingke" }
25+
26+
panic-halt = "0.2.0"
27+
28+
[profile.release]
29+
strip = false # symbols are not flashed to the microcontroller, so don't strip them.
30+
lto = true
31+
opt-level = "z" # Optimize for size.

examples/ch32v208/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
// println!("cargo:rustc-link-arg-bins=--nmagic");
3+
println!("cargo:rustc-link-arg-bins=-Tlink.x");
4+
// println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
5+
}

examples/ch32v208/src/bin/blinky.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![no_std]
2+
#![no_main]
3+
#![feature(type_alias_impl_trait)]
4+
5+
use hal::gpio::{Level, Output};
6+
use qingke::riscv;
7+
use {ch32_hal as hal, panic_halt as _};
8+
9+
#[qingke_rt::entry]
10+
fn main() -> ! {
11+
let p = hal::init(Default::default());
12+
13+
let mut led = Output::new(p.PB8, Level::Low, Default::default());
14+
loop {
15+
led.toggle();
16+
17+
unsafe {
18+
riscv::asm::delay(1000000);
19+
}
20+
}
21+
}

src/timer/low_level.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'d, T: CoreInstance> Timer<'d, T> {
188188
Self { tim }
189189
}
190190

191-
#[cfg(any(ch32l0, ch32v3))]
191+
#[cfg(any(ch32l1, ch32v208))]
192192
fn regs_gp32_unchecked(&self) -> crate::pac::timer::Gptm32 {
193193
unsafe { crate::pac::timer::Gptm32::from_ptr(T::regs()) }
194194
}
@@ -248,7 +248,7 @@ impl<'d, T: BasicInstance> Timer<'d, T> {
248248
regs.swevgr().write(|r| r.set_ug(true));
249249
regs.ctlr1().modify(|r| r.set_urs(vals::Urs::ANYEVENT));
250250
}
251-
#[cfg(any(ch32l0, ch32v3))]
251+
#[cfg(any(ch32l1, ch32v208))]
252252
TimerBits::Bits32 => {
253253
let pclk_ticks_per_timer_period = (timer_f / f) as u64;
254254
let psc: u16 = (((pclk_ticks_per_timer_period - 1) / (1 << 32)).try_into()).unwrap();
@@ -303,7 +303,7 @@ impl<'d, T: BasicInstance> Timer<'d, T> {
303303

304304
timer_f / arr / (psc + 1)
305305
}
306-
#[cfg(any(ch32l0, ch32v3))]
306+
#[cfg(any(ch32l1, ch32v208))]
307307
TimerBits::Bits32 => {
308308
let regs = self.regs_gp32_unchecked();
309309
let arr = regs.atrlr().read();
@@ -347,7 +347,7 @@ impl<'d, T: GeneralInstance16bit> Timer<'d, T> {
347347
pub fn get_max_compare_value(&self) -> u32 {
348348
match T::BITS {
349349
TimerBits::Bits16 => self.regs_gp16().atrlr().read() as u32,
350-
#[cfg(any(ch32l0, ch32v3))]
350+
#[cfg(any(ch32l1, ch32v208))]
351351
TimerBits::Bits32 => self.regs_gp32_unchecked().atrlr().read(),
352352
}
353353
}
@@ -466,7 +466,7 @@ impl<'d, T: GeneralInstance16bit> Timer<'d, T> {
466466
let value = (u16::try_from(value)).unwrap();
467467
self.regs_gp16().chcvr(channel.index()).write_value(value);
468468
}
469-
#[cfg(any(ch32l0, ch32v3))]
469+
#[cfg(any(ch32l1, ch32v208))]
470470
TimerBits::Bits32 => {
471471
self.regs_gp32_unchecked().chcvr(channel.index()).write_value(value);
472472
}
@@ -477,7 +477,7 @@ impl<'d, T: GeneralInstance16bit> Timer<'d, T> {
477477
pub fn get_compare_value(&self, channel: Channel) -> u32 {
478478
match T::BITS {
479479
TimerBits::Bits16 => self.regs_gp16().chcvr(channel.index()).read() as u32,
480-
#[cfg(any(ch32l0, ch32v3))]
480+
#[cfg(any(ch32l1, ch32v208))]
481481
TimerBits::Bits32 => self.regs_gp32_unchecked().chcvr(channel.index()).read(),
482482
}
483483
}

src/timer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub enum TimerBits {
5050
/// 16 bits.
5151
Bits16,
5252
/// 32 bits.
53-
#[cfg(any(ch32l0, ch32v3))]
53+
#[cfg(any(ch32l1, ch32v208))]
5454
Bits32,
5555
}
5656

0 commit comments

Comments
 (0)