Skip to main content

Crate ch57x_hal

Crate ch57x_hal 

Source
Expand description

§ch57x-hal

Github Actions Crates.io Crates.io docs.rs

HAL for CH57x RISC-V BLE microcontrollers from WCH.

This crate is under active development and should currently be treated as experimental.

§What This Crate Provides

  • CH57x peripheral abstractions built on top of ch57x-pac
  • Runtime integration via qingke-rt
  • Optional Embassy support (embassy feature)
  • Optional BLE bindings (ble feature, backed by vendor libraries in vendor/)

§Development Setup

  1. Install Rust target: rustup target add riscv32imac-unknown-none-elf

  2. Optional nightly toolchain (needed by several examples using #![feature(type_alias_impl_trait)]): rustup toolchain install nightly

  3. Install a flasher tool used by .cargo/config.toml:

  • default runner: wlink -v flash
  • alternatives are commented in .cargo/config.toml
  1. Validate baseline:
  • library: cargo check
  • one example at a time: cargo check --example blinky
  • flash one example: cargo run --release --example blinky

§Current Status

  • Library crate compiles on stable with warnings.
  • Many examples are still mid-migration from CH58x style APIs to CH57x and do not all compile yet.
  • Migration tracking docs:
    • progress.md
    • plan.md
    • learnings.md
    • docs/ch572ds1-mapping.md

§Features

  • Basic: clock init, delay, interrupt, etc.

  • Dedicated runtime: interrupt table, hardware stack push, highcode support, critical section implementation

  • embassy support

    • time driver with SysTick, defaults to 32KHz tick
    • about 7k flash rom overhead
  • GPIO, with async support

  • UART, basic blocking tx, rx

  • RTC, with datetime support

  • SysTick delay (conflicts with embassy time driver)

  • ADC, with Temperature sensor, VBAT sensor

  • SPI

  • libISP ROM functions

  • Basic BLE library support

§Usage

[dependencies]
ch57x-hal = { package = "ch57x-hal-raynhardt", version = "0.0.6" }

Feature examples:

[dependencies]
ch57x-hal = { package = "ch57x-hal-raynhardt", version = "0.0.6", default-features = false, features = ["embassy", "ble"] }

See the examples/ directory for end-to-end usage.

§Crates.io

Add dependency:

[dependencies]
ch57x-hal = { package = "ch57x-hal-raynhardt", version = "0.0.6" }

Release process is tracked in RELEASING.md.

§Notes

  • UNDOCUMENTED: tags in code comments means the information is not from official documents.

§References

Re-exports§

pub use self::peripherals::Peripherals;
pub use ch57x_pac as pac;

Modules§

adc
ble
delay
Simple busy-loop delay provider
dma
embassy
gpio
GPIO_ModeIN_Floating, // floating input GPIO_ModeIN_PU, // pull-up input GPIO_ModeIN_PD, // pull-down input GPIO_ModeOut_PP_5mA, // push-pull output (max 5mA) GPIO_ModeOut_PP_20mA, // push-pull output (max 20mA)
interrupt
isp
The libISP583 library.
peripherals
prelude
rtc
Real time clock
signature
spi
SPI, Serial Peripheral Interface
sysctl
timer
TMRx Timer.
uart
UART, Universal Asynchronous Receiver/Transmitter

Macros§

impl_peripheral
println

Structs§

Config
PeripheralRef
An exclusive reference to a peripheral.

Statics§

SERIAL

Traits§

Peripheral
Trait for any type that can be used as a peripheral of type P.
U32Ext
Extension trait that adds convenience methods to the u32 type

Functions§

delay_ms
delay_us
init
reset
System reset
set_default_serial
soft_reset
Software reset
stack_free
with_safe_access

Type Aliases§

BitsPerSecond
Bits per second