diff --git a/examples/ch32/v003/Cargo.lock b/examples/ch32/v003/Cargo.lock index e5ea63b..2f00fe5 100644 --- a/examples/ch32/v003/Cargo.lock +++ b/examples/ch32/v003/Cargo.lock @@ -69,7 +69,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "ch32-hal" version = "0.1.0" -source = "git+https://github.com/ch32-rs/ch32-hal#2ed4f3cab40f42b81d7355f1632ae4cb9ad4d5f1" +source = "git+https://github.com/ch32-rs/ch32-hal#b15ec6347bb3c59c05ff72924c2ed7e8e49e49e3" dependencies = [ "bitmaps", "ch32-metapac 0.1.0 (git+https://github.com/ch32-rs/ch32-metapac?rev=7cd6fb70d07de3a987c63d0d8f5547bb8261e403)", @@ -468,8 +468,8 @@ dependencies = [ [[package]] name = "qingke" -version = "0.6.1" -source = "git+https://github.com/OpenServoCore/qingke?branch=main#44d490b2ff429ed4689bd7dd1653146f4fff506a" +version = "0.7.0" +source = "git+https://github.com/ch32-rs/qingke?branch=main#2ef31f069bb6d32eb4a129e8075e71e6bbf46c85" dependencies = [ "bit_field", "cfg-if", @@ -479,8 +479,8 @@ dependencies = [ [[package]] name = "qingke-rt" -version = "0.6.1" -source = "git+https://github.com/OpenServoCore/qingke?branch=main#44d490b2ff429ed4689bd7dd1653146f4fff506a" +version = "0.7.0" +source = "git+https://github.com/ch32-rs/qingke?branch=main#2ef31f069bb6d32eb4a129e8075e71e6bbf46c85" dependencies = [ "qingke", "qingke-rt-macros", @@ -488,8 +488,8 @@ dependencies = [ [[package]] name = "qingke-rt-macros" -version = "0.6.1" -source = "git+https://github.com/OpenServoCore/qingke?branch=main#44d490b2ff429ed4689bd7dd1653146f4fff506a" +version = "0.7.0" +source = "git+https://github.com/ch32-rs/qingke?branch=main#2ef31f069bb6d32eb4a129e8075e71e6bbf46c85" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/examples/ch32/v003/Cargo.toml b/examples/ch32/v003/Cargo.toml index 71cf130..83aaa58 100644 --- a/examples/ch32/v003/Cargo.toml +++ b/examples/ch32/v003/Cargo.toml @@ -19,5 +19,5 @@ codegen-units = 1 panic = "abort" [patch.crates-io] -qingke = { git = "https://github.com/OpenServoCore/qingke", branch = "main" } -qingke-rt = { git = "https://github.com/OpenServoCore/qingke", branch = "main" } +qingke = { git = "https://github.com/ch32-rs/qingke", branch = "main" } +qingke-rt = { git = "https://github.com/ch32-rs/qingke", branch = "main" } diff --git a/examples/ch32/v003/app/Cargo.toml b/examples/ch32/v003/app/Cargo.toml index 21a0dc7..9581ffc 100644 --- a/examples/ch32/v003/app/Cargo.toml +++ b/examples/ch32/v003/app/Cargo.toml @@ -8,7 +8,7 @@ tinyboot-ch32 = { path = "../../../../ch32", default-features = false } embedded-io = "0.7" critical-section = "1" ch32-hal = { git = "https://github.com/ch32-rs/ch32-hal", default-features = false } -qingke-rt = { version = "0.6", features = ["v2"] } +qingke-rt = { version = "0.7", features = ["v2"] } defmt = "1.0" defmt-rtt = "1.1" diff --git a/examples/ch32/v00x/Cargo.lock b/examples/ch32/v00x/Cargo.lock index e5ea63b..bfdf796 100644 --- a/examples/ch32/v00x/Cargo.lock +++ b/examples/ch32/v00x/Cargo.lock @@ -69,7 +69,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "ch32-hal" version = "0.1.0" -source = "git+https://github.com/ch32-rs/ch32-hal#2ed4f3cab40f42b81d7355f1632ae4cb9ad4d5f1" +source = "git+https://github.com/ch32-rs/ch32-hal?branch=fix%2Fv00x-48mhz#2a47fef9b58e3b5366e425a7e530b99dfebaec05" dependencies = [ "bitmaps", "ch32-metapac 0.1.0 (git+https://github.com/ch32-rs/ch32-metapac?rev=7cd6fb70d07de3a987c63d0d8f5547bb8261e403)", @@ -468,8 +468,8 @@ dependencies = [ [[package]] name = "qingke" -version = "0.6.1" -source = "git+https://github.com/OpenServoCore/qingke?branch=main#44d490b2ff429ed4689bd7dd1653146f4fff506a" +version = "0.7.0" +source = "git+https://github.com/ch32-rs/qingke?branch=main#2ef31f069bb6d32eb4a129e8075e71e6bbf46c85" dependencies = [ "bit_field", "cfg-if", @@ -479,8 +479,8 @@ dependencies = [ [[package]] name = "qingke-rt" -version = "0.6.1" -source = "git+https://github.com/OpenServoCore/qingke?branch=main#44d490b2ff429ed4689bd7dd1653146f4fff506a" +version = "0.7.0" +source = "git+https://github.com/ch32-rs/qingke?branch=main#2ef31f069bb6d32eb4a129e8075e71e6bbf46c85" dependencies = [ "qingke", "qingke-rt-macros", @@ -488,8 +488,8 @@ dependencies = [ [[package]] name = "qingke-rt-macros" -version = "0.6.1" -source = "git+https://github.com/OpenServoCore/qingke?branch=main#44d490b2ff429ed4689bd7dd1653146f4fff506a" +version = "0.7.0" +source = "git+https://github.com/ch32-rs/qingke?branch=main#2ef31f069bb6d32eb4a129e8075e71e6bbf46c85" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/examples/ch32/v00x/Cargo.toml b/examples/ch32/v00x/Cargo.toml index 5aa1300..85edab2 100644 --- a/examples/ch32/v00x/Cargo.toml +++ b/examples/ch32/v00x/Cargo.toml @@ -20,5 +20,6 @@ codegen-units = 1 panic = "abort" [patch.crates-io] -qingke = { git = "https://github.com/OpenServoCore/qingke", branch = "main" } -qingke-rt = { git = "https://github.com/OpenServoCore/qingke", branch = "main" } +qingke = { git = "https://github.com/ch32-rs/qingke", branch = "main" } +qingke-rt = { git = "https://github.com/ch32-rs/qingke", branch = "main" } + diff --git a/examples/ch32/v00x/app/Cargo.toml b/examples/ch32/v00x/app/Cargo.toml index 1de7455..b96ad63 100644 --- a/examples/ch32/v00x/app/Cargo.toml +++ b/examples/ch32/v00x/app/Cargo.toml @@ -7,8 +7,9 @@ edition.workspace = true tinyboot-ch32 = { path = "../../../../ch32", default-features = false } embedded-io = "0.7" critical-section = "1" -ch32-hal = { git = "https://github.com/ch32-rs/ch32-hal", default-features = false } -qingke-rt = { version = "0.6", features = ["v2"] } +# See https://github.com/ch32-rs/ch32-hal/pull/169 +ch32-hal = { git = "https://github.com/ch32-rs/ch32-hal", branch = "fix/v00x-48mhz", default-features = false } +qingke-rt = { version = "0.7", features = ["v2"] } defmt = "1.0" defmt-rtt = "1.1" diff --git a/examples/ch32/v00x/app/build.rs b/examples/ch32/v00x/app/build.rs index 03a542f..6f19fb3 100644 --- a/examples/ch32/v00x/app/build.rs +++ b/examples/ch32/v00x/app/build.rs @@ -11,7 +11,9 @@ fn main() { match (system_flash, user_flash) { (true, false) => "system-flash", (false, true) => "user-flash", - _ => panic!("Enable exactly one flash mode: `system-flash`, `user-flash`, or `standalone`"), + _ => panic!( + "Enable exactly one flash mode: `system-flash`, `user-flash`, or `standalone`" + ), } }; diff --git a/examples/ch32/v00x/app/src/main.rs b/examples/ch32/v00x/app/src/main.rs index 3bfe0c4..1d76d75 100644 --- a/examples/ch32/v00x/app/src/main.rs +++ b/examples/ch32/v00x/app/src/main.rs @@ -34,7 +34,9 @@ static LED: Shared> = Mutex::new(RefCell::new(None)); #[qingke_rt::entry] fn main() -> ! { - let p = ch32_hal::init(Default::default()); + let mut config = ch32_hal::Config::default(); + config.rcc = ch32_hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI; + let p = ch32_hal::init(config); // LED blink via TIM2 interrupt (2 Hz toggle = 1 Hz blink) critical_section::with(|cs| { @@ -54,7 +56,7 @@ fn main() -> ! { // 2: TX=PD0, RX=PD1 // 3: TX=PC0, RX=PC1 let mut uart_config = usart::Config::default(); - uart_config.baudrate = 115200; + uart_config.baudrate = 3_000_000; let uart = Uart::new_blocking::<3>(p.USART1, p.PC1, p.PC0, uart_config).unwrap(); let (tx, rx) = uart.split(); let mut rx = transport::Rx(rx); diff --git a/examples/ch32/v00x/app/src/transport.rs b/examples/ch32/v00x/app/src/transport.rs index 6f6b0c1..db47aa6 100644 --- a/examples/ch32/v00x/app/src/transport.rs +++ b/examples/ch32/v00x/app/src/transport.rs @@ -1,7 +1,13 @@ //! embedded_io adapters for ch32-hal blocking UART with optional RS-485 DE/RE. +//! +//! RX bypasses ch32-hal's `blocking_read` and polls `STATR.RXNE` / `DATAR` +//! directly — at 48 MHz with a 3 Mbps line, each byte arrives every ~160 +//! cycles and the per-byte overhead of `check_rx_flags` + the `embedded_io` +//! adapter chain is enough to overrun. use ch32_hal::gpio::{Level, Output}; use ch32_hal::mode::Blocking; +use ch32_hal::pac; use ch32_hal::usart::{Instance, UartRx, UartTx}; use core::convert::Infallible; use embedded_io::{ErrorType, Read, Write}; @@ -17,8 +23,12 @@ impl Read for Rx<'_, T> { if buf.is_empty() { return Ok(0); } - let _ = self.0.blocking_read(&mut buf[..1]); - Ok(1) + let regs = pac::USART1; + for slot in buf.iter_mut() { + while !regs.statr().read().rxne() {} + *slot = regs.datar().read().dr() as u8; + } + Ok(buf.len()) } } diff --git a/examples/ch32/v00x/boot/src/main.rs b/examples/ch32/v00x/boot/src/main.rs index 466a982..becf5df 100644 --- a/examples/ch32/v00x/boot/src/main.rs +++ b/examples/ch32/v00x/boot/src/main.rs @@ -13,9 +13,30 @@ use tinyboot_ch32_rt as _; tinyboot_ch32::boot::boot_version!(); use tinyboot_ch32::boot::prelude::*; +use tinyboot_ch32::pac::{ + FLASH, RCC, + rcc::vals::{Hpre, Pllsrc, Sw}, +}; + +fn init_48mhz_hsi_pll() { + FLASH.actlr().modify(|w| w.set_latency(2)); + + RCC.cfgr0().modify(|w| { + w.set_pllsrc(Pllsrc::HSI); + w.set_hpre(Hpre::DIV1); + }); + + RCC.ctlr().modify(|w| w.set_pllon(true)); + while !RCC.ctlr().read().pllrdy() {} + + RCC.cfgr0().modify(|w| w.set_sw(Sw::PLL)); + while RCC.cfgr0().read().sws() != Sw::PLL {} +} #[unsafe(export_name = "main")] fn main() -> ! { + init_48mhz_hsi_pll(); + // USART1 transport. Remap options (CH32V00x): // Remap0 (default): TX=PD5, RX=PD6 // Remap1: TX=PD6, RX=PD5 @@ -35,11 +56,14 @@ fn main() -> ! { // tx_en: Some(TxEnConfig { pin: Pin::PC2, tx_level: Level::High }), let transport = Usart::new(&UsartConfig { duplex: Duplex::Full, - baud: BaudRate::B115200, - pclk: 8_000_000, + baud: BaudRate::B3000000, + pclk: 48_000_000, mapping: UsartMapping::Usart1Remap3, rx_pull: Pull::None, - tx_en: Some(TxEnConfig { pin: Pin::PC2, tx_level: Level::High }), + tx_en: Some(TxEnConfig { + pin: Pin::PC2, + tx_level: Level::High, + }), }); tinyboot_ch32::boot::run(transport, BootCtl::new()); } diff --git a/examples/ch32/v103/Cargo.lock b/examples/ch32/v103/Cargo.lock index e5ea63b..2f00fe5 100644 --- a/examples/ch32/v103/Cargo.lock +++ b/examples/ch32/v103/Cargo.lock @@ -69,7 +69,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "ch32-hal" version = "0.1.0" -source = "git+https://github.com/ch32-rs/ch32-hal#2ed4f3cab40f42b81d7355f1632ae4cb9ad4d5f1" +source = "git+https://github.com/ch32-rs/ch32-hal#b15ec6347bb3c59c05ff72924c2ed7e8e49e49e3" dependencies = [ "bitmaps", "ch32-metapac 0.1.0 (git+https://github.com/ch32-rs/ch32-metapac?rev=7cd6fb70d07de3a987c63d0d8f5547bb8261e403)", @@ -468,8 +468,8 @@ dependencies = [ [[package]] name = "qingke" -version = "0.6.1" -source = "git+https://github.com/OpenServoCore/qingke?branch=main#44d490b2ff429ed4689bd7dd1653146f4fff506a" +version = "0.7.0" +source = "git+https://github.com/ch32-rs/qingke?branch=main#2ef31f069bb6d32eb4a129e8075e71e6bbf46c85" dependencies = [ "bit_field", "cfg-if", @@ -479,8 +479,8 @@ dependencies = [ [[package]] name = "qingke-rt" -version = "0.6.1" -source = "git+https://github.com/OpenServoCore/qingke?branch=main#44d490b2ff429ed4689bd7dd1653146f4fff506a" +version = "0.7.0" +source = "git+https://github.com/ch32-rs/qingke?branch=main#2ef31f069bb6d32eb4a129e8075e71e6bbf46c85" dependencies = [ "qingke", "qingke-rt-macros", @@ -488,8 +488,8 @@ dependencies = [ [[package]] name = "qingke-rt-macros" -version = "0.6.1" -source = "git+https://github.com/OpenServoCore/qingke?branch=main#44d490b2ff429ed4689bd7dd1653146f4fff506a" +version = "0.7.0" +source = "git+https://github.com/ch32-rs/qingke?branch=main#2ef31f069bb6d32eb4a129e8075e71e6bbf46c85" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/examples/ch32/v103/Cargo.toml b/examples/ch32/v103/Cargo.toml index 71cf130..83aaa58 100644 --- a/examples/ch32/v103/Cargo.toml +++ b/examples/ch32/v103/Cargo.toml @@ -19,5 +19,5 @@ codegen-units = 1 panic = "abort" [patch.crates-io] -qingke = { git = "https://github.com/OpenServoCore/qingke", branch = "main" } -qingke-rt = { git = "https://github.com/OpenServoCore/qingke", branch = "main" } +qingke = { git = "https://github.com/ch32-rs/qingke", branch = "main" } +qingke-rt = { git = "https://github.com/ch32-rs/qingke", branch = "main" } diff --git a/examples/ch32/v103/app/Cargo.toml b/examples/ch32/v103/app/Cargo.toml index fdc97a0..315880d 100644 --- a/examples/ch32/v103/app/Cargo.toml +++ b/examples/ch32/v103/app/Cargo.toml @@ -8,7 +8,7 @@ tinyboot-ch32 = { path = "../../../../ch32", default-features = false } embedded-io = "0.7" critical-section = "1" ch32-hal = { git = "https://github.com/ch32-rs/ch32-hal", default-features = false } -qingke-rt = { version = "0.6", features = ["v3a"] } +qingke-rt = { version = "0.7", features = ["v3a"] } defmt = "1.0" defmt-rtt = "1.1"