Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USART transmit is clipped to 500kbaud #37

Open
silibattlebot opened this issue Jul 14, 2024 · 0 comments
Open

USART transmit is clipped to 500kbaud #37

silibattlebot opened this issue Jul 14, 2024 · 0 comments
Assignees

Comments

@silibattlebot
Copy link

CH32V003F4U6, nanoCHV32003 v1.0

If the user tries to set uart_config.baudrate above 500_000, the USART still only transmits at 500kbaud. Datasheet and usart/mod.rs indicate 3 Mbps should be possible. It may be a clocking problem with my usage of hal::Config::default().

#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]

use embassy_executor::Spawner;
use embassy_time::Timer;
use hal::gpio::{AnyPin, Level, Output, Pin};
//use hal::println;
use ch32_hal::usart::UartTx;
use {ch32_hal as hal, panic_halt as _};

use heapless::String;

#[embassy_executor::task]
async fn blink(pin: AnyPin, interval_ms: u64) {
    let mut led = Output::new(pin, Level::Low, Default::default());

    loop {
        led.set_high();
        Timer::after_millis(interval_ms).await;
        led.set_low();
        Timer::after_millis(interval_ms).await;
    }
}

#[embassy_executor::main(entry = "qingke_rt::entry")]
async fn main(spawner: Spawner) -> ! {
    let p = hal::init(hal::Config::default());
    hal::embassy::init();


    let mut uart_config: ch32_hal::usart::Config = Default::default();

    uart_config.baudrate = 500000;

    let mut uart = UartTx::new_blocking(p.USART1, p.PD0, uart_config).unwrap();

    // Adjust the LED GPIO according to your board
    spawner.spawn(blink(p.PD6.degrade(), 100)).unwrap();

    loop {
        Timer::after_millis(100).await;
        uart.blocking_write(b"Hello world!\r\n").unwrap();
    }
}
@andelf andelf self-assigned this Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants