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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"rust-analyzer.cargo.target": "thumbv6m-none-eabi",
"rust-analyzer.cargo.features": [
"rt",
"stm32g071"
"stm32g081"
]
}
30 changes: 10 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,31 @@ default-target = "thumbv6m-none-eabi"

[dependencies]
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
nb = "1.0.0"
fugit = "0.3.5"
nb = "1.1.0"
fugit = "0.3.7"
embedded-hal = "1.0.0"
bare-metal = "1.0.0"

[dependencies.stm32g0]
version = "0.15.1"
features = ["rt"]

[dependencies.bare-metal]
version = "1.0.0"

[dependencies.embedded-hal]
features = ["unproven"]
version = "0.2.6"

[dependencies.void]
default-features = false
version = "1.0.2"

[dev-dependencies]
cortex-m-rt = "0.7.1"
cortex-m-rtic = "1.0.0"
cortex-m-semihosting = "0.3.5"
embedded-graphics = "0.5"
embedded-sdmmc = "0.2.1"
infrared = "0.11.0"
panic-halt = "0.2.0"
panic-semihosting = "0.5.3"
smart-leds = "0.3.0"
st7735-lcd = "0.6.1"
ws2812-spi = { version = "0.3.0", features = [] }
cortex-m-rt = "0.7.5"
cortex-m-rtic = "1.1.4"
cortex-m-semihosting = "0.5.0"
panic-halt = "1.0.0"
panic-semihosting = "0.6.0"

[features]
default = ["i2c-blocking"]
device-selected = []
rt = ["stm32g0/rt"]
defmt = ["embedded-hal/defmt-03"]
stm32g030 = ["stm32g0/stm32g030", "stm32g0x0", "device-selected"]
stm32g070 = ["stm32g0/stm32g070", "stm32g0x0", "device-selected"]
stm32g031 = ["stm32g0/stm32g031", "stm32g0x1", "device-selected"]
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT LICENSE

Copyright (c) 2018-2023 Vitaly Domnikov <[email protected]>
Copyright (c) 2018-2024 Vitaly Domnikov <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ fn main() -> ! {
loop {
let u_mv = adc.read_voltage(&mut adc_pin).expect("adc read failed");
let u_bat = adc.read_voltage(&mut vbat).expect("adc read failed");
hprintln!("VBat: {}mV | PA0: {}mV", u_bat * 3, u_mv).unwrap();
hprintln!("VBat: {}mV | PA0: {}mV", u_bat * 3, u_mv);
}
}
19 changes: 8 additions & 11 deletions examples/adc_ext_trig_double_dma_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// command build: cargo build --example adc_ext_trig_double_dma_serial --features stm32g031
// command run: cargo run --example adc_ext_trig_double_dma_serial --features stm32g031

#![deny(warnings)]
#![no_main]
#![no_std]

Expand All @@ -24,14 +23,12 @@ use rt::entry;
use core::cell::RefCell;
use cortex_m::interrupt::Mutex;

use crate::hal::analog::adc::DmaMode;
use crate::hal::analog::adc::InjectMode;
use crate::hal::stm32::{interrupt, Interrupt};
use hal::analog::adc::{InjTrigSource, Precision, SampleTime}; //, VTemp

use hal::dma::{self, Channel, Target};

use crate::hal::analog::adc::DmaMode;
use crate::hal::analog::adc::InjectMode;

// Make dma globally available
static G_DMA: Mutex<RefCell<Option<hal::dma::Channels>>> = Mutex::new(RefCell::new(None));

Expand Down Expand Up @@ -120,10 +117,10 @@ fn main() -> ! {
.set_peripheral_address(adc_data_register_addr, false);
dma.ch1.set_transfer_length(adc_buffer1.len() as u16);

hprintln!("adc_data_register_addr {:?}", adc_buffer1_addr).unwrap(); // will output addr in dec
// in gdb read the data bytes with: x /32xh 0x??????? (last is addr in hex)
// or put addr in dec format: x /32xh 536878092
// https://sourceware.org/gdb/current/onlinedocs/gdb/Memory.html
hprintln!("adc_data_register_addr {:?}", adc_buffer1_addr); // will output addr in dec
// in gdb read the data bytes with: x /32xh 0x??????? (last is addr in hex)
// or put addr in dec format: x /32xh 536878092
// https://sourceware.org/gdb/current/onlinedocs/gdb/Memory.html

// dma ch1 reads from ADC register into memory
dma.ch1.select_peripheral(hal::dmamux::DmaMuxIndex::ADC);
Expand Down Expand Up @@ -162,9 +159,9 @@ fn main() -> ! {
adc.set_sample_time(SampleTime::T_80);
adc.set_precision(Precision::B_12);
let mut pa3 = gpioa.pa5.into_analog();
let u_raw: u32 = adc.read(&mut pa3).expect("adc read failed");
let u_raw = adc.read(&mut pa3).expect("adc read failed");
let u = u_raw.saturating_sub(32) as f32 / 4_096_f32 * 3.3;
hprintln!("u: {:.4} V ", u).unwrap();
hprintln!("u: {:.4} V ", u);

adc.set_oversampling_ratio(adc::OversamplingRatio::X_16);
adc.set_oversampling_shift(4);
Expand Down
10 changes: 5 additions & 5 deletions examples/blinky_random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ fn main() -> ! {
let mut rng = dp.RNG.constrain(Config::default(), &mut rcc);
let mut random_bytes = [0u16; 3];
match rng.fill(&mut random_bytes) {
Ok(()) => hprintln!("random bytes: {:?}", random_bytes).unwrap(),
Err(err) => hprintln!("RNG error: {:?}", err).unwrap(),
Ok(()) => hprintln!("random bytes: {:?}", random_bytes),
Err(err) => hprintln!("RNG error: {:?}", err),
}
loop {
match rng.gen_range(20, 200) {
Ok(period) => {
led.toggle().unwrap();
led.toggle().ok();
delay.delay(period.millis());
}
Err(err) => hprintln!("RNG error: {:?}", err).unwrap(),
Err(err) => hprintln!("RNG error: {:?}", err),
}
}
}

#[allow(clippy::empty_loop)]
#[exception]
unsafe fn HardFault(ef: &ExceptionFrame) -> ! {
hprintln!("Hard fault {:#?}", ef).unwrap();
hprintln!("Hard fault {:#?}", ef);
loop {}
}
2 changes: 1 addition & 1 deletion examples/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() -> ! {
let mut delay = cp.SYST.delay(&mut rcc);

let gpioc = dp.GPIOC.split(&mut rcc);
let button = gpioc.pc13.into_pull_up_input();
let mut button = gpioc.pc13.into_pull_up_input();

let gpioa = dp.GPIOA.split(&mut rcc);
let mut led = gpioa.pa5.into_push_pull_output();
Expand Down
6 changes: 2 additions & 4 deletions examples/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ fn main() -> ! {
"crc32: 0x{:x}, crc32b: 0x{:x}",
hash_sum,
hash_sum ^ 0xffff_ffff
)
.unwrap();
);

crc.reset();
crc.feed(b"The quick brown fox jumps over the lazy dog");
Expand All @@ -44,7 +43,6 @@ fn main() -> ! {
"crc32: 0x{:x}, crc32b: 0x{:x}",
hash_sum,
hash_sum ^ 0xffff_ffff
)
.unwrap();
);
}
}
2 changes: 1 addition & 1 deletion examples/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ extern crate panic_halt;
extern crate stm32g0xx_hal as hal;

use hal::analog::dac::GeneratorConfig;
use hal::hal::Direction;
use hal::prelude::*;
use hal::rcc::Config;
use hal::stm32;
use hal::timer::qei::Direction;
use rt::entry;

#[entry]
Expand Down
5 changes: 2 additions & 3 deletions examples/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ fn main() -> ! {
hprintln!(
"{:02X?}",
u64::from_le_bytes((&buffer[0..8]).try_into().expect("never fails"))
)
.ok();
);
}
Err(_) => hprintln!("Cannot unlock flash").unwrap(),
Err(_) => hprintln!("Cannot unlock flash"),
}

loop {}
Expand Down
2 changes: 1 addition & 1 deletion examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rt::entry;
#[allow(clippy::empty_loop)]
#[entry]
fn main() -> ! {
hprintln!("Hello, STM32G0!").unwrap();
hprintln!("Hello, STM32G0!");

loop {}
}
4 changes: 2 additions & 2 deletions examples/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fn main() -> ! {
let buf: [u8; 1] = [0];
loop {
match i2c.write(0x3c, &buf) {
Ok(_) => hprintln!("ok").unwrap(),
Err(err) => hprintln!("error: {:?}", err).unwrap(),
Ok(_) => hprintln!("ok"),
Err(err) => hprintln!("error: {:?}", err),
}
}
}
89 changes: 0 additions & 89 deletions examples/ir_remote.rs

This file was deleted.

4 changes: 2 additions & 2 deletions examples/qei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ fn main() -> ! {
let gpioa = dp.GPIOA.split(&mut rcc);
let gpioc = dp.GPIOC.split(&mut rcc);

let switch = gpioc.pc5.into_pull_up_input();
let mut switch = gpioc.pc5.into_pull_up_input();
let qei = dp.TIM1.qei((gpioa.pa8, gpioa.pa9), &mut rcc);

loop {
let count = qei.count();
if switch.is_low().unwrap() {
hprintln!("Counter: {}", count).unwrap();
hprintln!("Counter: {}", count);
}
}
}
2 changes: 1 addition & 1 deletion examples/rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod app {
fn button_click(ctx: button_click::Context) {
let date = ctx.local.rtc.get_date();
let time = ctx.local.rtc.get_time();
hprintln!("Button pressed @ {:?} {:?}", date, time).unwrap();
hprintln!("Button pressed @ {:?} {:?}", date, time);
ctx.local.exti.unpend(Event::GPIO13);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/rtic_low_power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mod app {
let gpioc = ctx.device.GPIOC.split(&mut rcc);

let led = gpioa.pa5.into_push_pull_output();
let button = gpioc.pc13.listen(SignalEdge::Falling, &mut exti);
let mut button = gpioc.pc13.listen(SignalEdge::Falling, &mut exti);

let mut power = ctx.device.PWR.constrain(&mut rcc);
power.set_mode(PowerMode::UltraLowPower(LowPowerMode::StopMode2));
Expand Down
Loading
Loading