Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on: push
name: Clippy check

# Make sure CI fails on all warnings, including Clippy lints
env:
RUSTFLAGS: "-Dwarnings"

jobs:
clippy_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Add targets
run: |
rustup component add --toolchain nightly-x86_64-unknown-linux-gnu clippy && \
rustup target add thumbv8m.main-none-eabihf && \
rustup target add thumbv7em-none-eabihf && \
rustup target add thumbv7em-none-eabi && \
rustup target add thumbv6m-none-eabi

- name: Run Clippy
run: make clippy
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CRATES := common ob-dap ch32v203 ch32v305 rp235x stm32c071 stm32g431

clippy: $(addprefix clippy-,$(CRATES))

clippy-%:
cd $(CURDIR)/$* && cargo clippy
3 changes: 2 additions & 1 deletion ch32v203/src/bin/usb_dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use hal::bind_interrupts;
use hal::gpio::{Flex, Level, Output, Speed};
use hal::usbd::Driver;

use ch32v203::my_println;
use ch32v203::usb_dap_task::dap_task;
use ch32v203::{bytes_to_hex, my_println};
use rust_link_common::bytes_to_hex;

use static_cell::StaticCell;

Expand Down
9 changes: 6 additions & 3 deletions ch32v203/src/bin/usb_dap_ppk2_uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use hal::gpio::{Flex, Level, Output, Speed};
use hal::usart::{Config as UartConfig, Uart};
use hal::usbd::Driver;

use ch32v203::my_println;
use ch32v203::usb_dap_task::dap_task;
use ch32v203::usb_ppk2_task::ppk2_task;
use ch32v203::usb_uart_task::{usb_rx_uart_tx_task, usb_tx_uart_rx_task};
use ch32v203::{bytes_to_hex, my_println};

use rust_link_common::bytes_to_hex;
use rust_link_common::usb_ppk2_dfu::{Ppk2DfuClass, State as DfuState};

use static_cell::StaticCell;
Expand Down Expand Up @@ -43,8 +44,10 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {

#[embassy_executor::main(entry = "qingke_rt::entry")]
async fn main(spawner: Spawner) {
let mut config = hal::Config::default();
config.rcc = hal::rcc::Config::SYSCLK_FREQ_144MHZ_HSI;
let mut config = hal::Config {
rcc: hal::rcc::Config::SYSCLK_FREQ_144MHZ_HSI,
..Default::default()
};
config.rcc.apb2_pre = ch32_hal::rcc::APBPrescaler::DIV2;
let p = hal::init(config);

Expand Down
16 changes: 6 additions & 10 deletions ch32v203/src/bin/usb_ppk2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ use rust_link_common::usb_ppk2_dfu::{Ppk2DfuClass, State as DfuState};

use static_cell::StaticCell;

#[macro_export]
macro_rules! my_println {
($($arg:tt)*) => {
()
};
}

// Println fucks up because it is blocking
// When no debugger is connected, the fw just hangs
// TODO: Switch to ringbuffer + defmt (see defmt_rtt crate for inspiration or use this: https://crates.io/crates/defmt-bbq)
use my_println as println;
// use hal::println;
use ch32v203::my_println as println;

bind_interrupts!(struct Irqs {
USB_LP_CAN1_RX0 => hal::usbd::InterruptHandler<hal::peripherals::USBD>;
Expand All @@ -41,8 +35,10 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
#[embassy_executor::main(entry = "qingke_rt::entry")]
async fn main(spawner: Spawner) {
hal::debug::SDIPrint::enable();
let mut config = hal::Config::default();
config.rcc = hal::rcc::Config::SYSCLK_FREQ_144MHZ_HSI;
let mut config = hal::Config {
rcc: hal::rcc::Config::SYSCLK_FREQ_144MHZ_HSI,
..Default::default()
};
config.rcc.apb2_pre = ch32_hal::rcc::APBPrescaler::DIV2;
let p = hal::init(config);

Expand Down
10 changes: 2 additions & 8 deletions ch32v203/src/bin/usb_serial_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ use hal::peripherals::USBD;
use hal::usbd::Driver;
use static_cell::StaticCell;

#[macro_export]
macro_rules! my_println {
($($arg:tt)*) => {
()
};
}

// Println fucks up because it is blocking
// When no debugger is connected, the fw just hangs
// TODO: Switch to ringbuffer + defmt (see defmt_rtt crate for inspiration or use this: https://crates.io/crates/defmt-bbq)
use my_println as println;
// use hal::println;
use ch32v203::my_println as println;

bind_interrupts!(struct Irqs {
USB_LP_CAN1_RX0 => hal::usbd::InterruptHandler<hal::peripherals::USBD>;
Expand Down
10 changes: 2 additions & 8 deletions ch32v203/src/bin/usb_uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ use static_cell::StaticCell;

use ch32v203::usb_uart_task::{usb_rx_uart_tx_task, usb_tx_uart_rx_task};

#[macro_export]
macro_rules! my_println {
($($arg:tt)*) => {
()
};
}

// Println fucks up because it is blocking
// When no debugger is connected, the fw just hangs
// TODO: Switch to ringbuffer + defmt (see defmt_rtt crate for inspiration or use this: https://crates.io/crates/defmt-bbq)
use my_println as println;
// use hal::println;
use ch32v203::my_println as println;

bind_interrupts!(struct Irqs {
USB_LP_CAN1_RX0 => hal::usbd::InterruptHandler<hal::peripherals::USBD>;
Expand Down
29 changes: 0 additions & 29 deletions ch32v203/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,3 @@ macro_rules! my_println {
()
};
}

pub fn bytes_to_hex<'a>(bytes: &[u8], out: &'a mut [u8]) -> Result<&'a str, ()> {
// Need exactly 2 chars per byte
if out.len() < bytes.len() * 2 {
return Err(());
}

let mut i = 0;
for &b in bytes {
let hi = b >> 4;
let lo = b & 0x0F;

out[i] = hex_char(hi);
out[i + 1] = hex_char(lo);
i += 2;
}

// SAFETY: we only write valid ASCII hex characters
Ok(core::str::from_utf8(&out[..i]).unwrap())
}

#[inline]
const fn hex_char(n: u8) -> u8 {
match n {
0..=9 => b'0' + n,
10..=15 => b'A' + (n - 10),
_ => b'?',
}
}
6 changes: 3 additions & 3 deletions ch32v203/src/usb_dap_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl MyDelay {
fn delay_micros(&self, mut us: u32) {
while us > 0x1fff {
let ticks = (us & 0x1fff) * self.ticks_per_us;
self.delay_ticks(ticks as u32);
self.delay_ticks(ticks);
us -= us & 0x1fff;
}
}
Expand Down Expand Up @@ -151,11 +151,11 @@ impl<'a> DebuggerPin<'a> {
}

impl<'a> DbgPin for DebuggerPin<'a> {
fn into_input(&mut self) {
fn set_as_input(&mut self) {
self.pin.set_as_input(self.pull_input);
self.is_output = false;
}
fn into_output_in_state(&mut self, state: PinState) {
fn set_as_output_with_state(&mut self, state: PinState) {
match state {
PinState::High => self.pin.set_high(),
PinState::Low => self.pin.set_low(),
Expand Down
4 changes: 2 additions & 2 deletions ch32v203/src/usb_ppk2_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use embassy_usb::class::cdc_acm::CdcAcmClass;

use ch32_hal::{self as hal, pac, Peri};
use hal::adc::{AdcChannel, AnyAdcChannel, SampleTime};
use hal::dma::{ReadableRingBuffer, Request, TransferOptions};
use hal::dma::{ReadableRingBuffer, TransferOptions};
use hal::gpio::{Level, Output, Speed};
use hal::peripherals::{ADC1, DMA1_CH1, PA6, PB4, TIM3, USBD};
use hal::time::Hertz;
Expand Down Expand Up @@ -124,7 +124,7 @@ fn dma_setup<'d>(
let mut ring_buf = unsafe {
ReadableRingBuffer::new(
dma_channel,
Request::default(),
(),
pac::ADC1.rdatar().as_ptr() as *mut u16,
adc_buffer,
dma_options,
Expand Down
56 changes: 26 additions & 30 deletions ch32v203/src/usb_uart_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,27 @@ pub async fn usb_tx_uart_rx_task(
) -> ! {
let mut buf = [0; 64];

usb_tx.wait_connection().await;
println!("Usb tx Connected");
loop {
usb_tx.wait_connection().await;
println!("Usb tx Connected");
loop {
match select(
usb_control.control_changed(),
uart_rx.read_until_idle(&mut buf),
)
.await
{
Either::First(_) => {
let baud = usb_tx.line_coding().data_rate();
println!("Setting baud to: {}", baud);
uart_config.baudrate = baud;
if let Err(_err) = uart_rx.set_config(&uart_config) {
println!("Uart config error: {:?}", _err);
}
match select(
usb_control.control_changed(),
uart_rx.read_until_idle(&mut buf),
)
.await
{
Either::First(_) => {
let baud = usb_tx.line_coding().data_rate();
println!("Setting baud to: {}", baud);
uart_config.baudrate = baud;
if let Err(_err) = uart_rx.set_config(&uart_config) {
println!("Uart config error: {:?}", _err);
}
Either::Second(Err(_err)) => println!("uart rx error! {:?}", _err),
Either::Second(Ok(n)) => {
if let Err(_err) = usb_tx.write_packet(&buf[..n]).await {
println!("Usb tx error! {:?}", _err)
}
}
Either::Second(Err(_err)) => println!("uart rx error! {:?}", _err),
Either::Second(Ok(n)) => {
if let Err(_err) = usb_tx.write_packet(&buf[..n]).await {
println!("Usb tx error! {:?}", _err)
}
}
}
Expand All @@ -57,18 +55,16 @@ pub async fn usb_rx_uart_tx_task(
mut uart_tx: UartTx<'static, peripherals::USART2, Async>,
) -> ! {
let mut buf = [0; 64];
usb_rx.wait_connection().await;
println!("Usb rx Connected");
loop {
usb_rx.wait_connection().await;
println!("Usb rx Connected");
loop {
match usb_rx.read_packet(&mut buf).await {
Ok(n) => {
if let Err(_err) = uart_tx.write(&buf[..n]).await {
println!("uart tx error! {:?}", _err);
}
match usb_rx.read_packet(&mut buf).await {
Ok(n) => {
if let Err(_err) = uart_tx.write(&buf[..n]).await {
println!("uart tx error! {:?}", _err);
}
Err(_err) => println!("Usb rx error: {:?}", _err),
}
Err(_err) => println!("Usb rx error: {:?}", _err),
}
}
}
3 changes: 2 additions & 1 deletion ch32v305/src/bin/usb_dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use hal::usb::EndpointDataBuffer512;
use hal::usbhs::{Driver, InterruptHandler, WakeupInterruptHandler};

use ch32v305::usb_dap_task::dap_task;
use ch32v305::{bytes_to_hex, my_println};
use ch32v305::{my_println};
use rust_link_common::bytes_to_hex;

use static_cell::StaticCell;

Expand Down
19 changes: 6 additions & 13 deletions ch32v305/src/bin/usb_multi_ppk2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ use rust_link_common::usb_ppk2::{run as ppk2_run, Adc};
use rust_link_common::usb_ppk2_dfu::{Ppk2DfuClass, State as DfuState};
use static_cell::StaticCell;

#[macro_export]
macro_rules! my_println {
($($arg:tt)*) => {
()
};
}

const MAX_NR_OF_ENPOINTS: usize = 8;
const PPK2_ENDPOINT_DATA_BUFFER_SIZE: usize = 64;
type Ppk2EndpointDataBuffer = EndpointDataBuffer<PPK2_ENDPOINT_DATA_BUFFER_SIZE>;
Expand All @@ -29,7 +22,7 @@ type Ppk2EndpointDataBuffer = EndpointDataBuffer<PPK2_ENDPOINT_DATA_BUFFER_SIZE>
// When no debugger is connected, the fw just hangs
// TODO: Switch to ringbuffer + defmt (see defmt_rtt crate for inspiration or use this: https://crates.io/crates/defmt-bbq)
// use hal::println;
use my_println as println;
use ch32v305::my_println as println;

bind_interrupts!(struct Irqs {
USBHS => InterruptHandler<hal::peripherals::USBHS>;
Expand Down Expand Up @@ -67,7 +60,7 @@ impl Adc for DummyAdc {
return self.buffer;
}
Timer::at(self.next_send_time).await;
self.next_send_time = self.next_send_time + Duration::from_micros(ADC_SEND_INTERVAL_US);
self.next_send_time += Duration::from_micros(ADC_SEND_INTERVAL_US);
let first_value = self.buffer.last().unwrap().wrapping_add(1);
for i in 0..self.buffer.len() {
self.buffer[i] = first_value.wrapping_add(i as u16);
Expand Down Expand Up @@ -168,8 +161,8 @@ async fn main(spawner: Spawner) {
let power_out_enable = Output::new(p.PC9, Level::High, Speed::Low);
static ADC_BUFFER_1: StaticCell<[u16; ADC_BUFFER_SIZE]> = StaticCell::new();
let buffer = ADC_BUFFER_1.init([0; ADC_BUFFER_SIZE]);
for i in 0..buffer.len() {
buffer[i] = i as u16;
for (i, val) in buffer.iter_mut().enumerate() {
*val = i as u16;
}

spawner
Expand All @@ -193,8 +186,8 @@ async fn main(spawner: Spawner) {
let power_out_enable = Output::new(p.PC8, Level::High, Speed::Low);
static ADC_BUFFER_2: StaticCell<[u16; ADC_BUFFER_SIZE]> = StaticCell::new();
let buffer = ADC_BUFFER_2.init([0; ADC_BUFFER_SIZE]);
for i in 0..buffer.len() {
buffer[i] = i as u16;
for (i, val) in buffer.iter_mut().enumerate() {
*val = i as u16;
}

spawner
Expand Down
12 changes: 2 additions & 10 deletions ch32v305/src/bin/usb_serial_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@ use hal::bind_interrupts;
use hal::usbhs::{InterruptHandler, WakeupInterruptHandler, Driver};
use static_cell::StaticCell;

// use hal::println;

#[macro_export]
macro_rules! my_println {
($($arg:tt)*) => {
()
};
}

// Println fucks up because it is blocking
// When no debugger is connected, the fw just hangs
// TODO: Switch to ringbuffer + defmt (see defmt_rtt crate for inspiration or use this: https://crates.io/crates/defmt-bbq)
use my_println as println;
// use hal::println;
use ch32v305::my_println as println;

bind_interrupts!(struct Irqs {
USBHS => InterruptHandler<hal::peripherals::USBHS>;
Expand Down
Loading
Loading