Skip to content

Commit 47a292f

Browse files
authored
Port to embedded-hal 1.x.x (#151)
* port to embedded-hal 1.x.x * code cleanup * embedded-hal 1.x.x i2c * embedded-hal 1.x.x spi * update SPI implementation
1 parent 7b45680 commit 47a292f

37 files changed

+395
-725
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"rust-analyzer.cargo.target": "thumbv6m-none-eabi",
44
"rust-analyzer.cargo.features": [
55
"rt",
6-
"stm32g071"
6+
"stm32g081"
77
]
88
}

Cargo.toml

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,31 @@ default-target = "thumbv6m-none-eabi"
1717

1818
[dependencies]
1919
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
20-
nb = "1.0.0"
21-
fugit = "0.3.5"
20+
nb = "1.1.0"
21+
fugit = "0.3.7"
22+
embedded-hal = "1.0.0"
23+
bare-metal = "1.0.0"
2224

2325
[dependencies.stm32g0]
2426
version = "0.15.1"
2527
features = ["rt"]
2628

27-
[dependencies.bare-metal]
28-
version = "1.0.0"
29-
30-
[dependencies.embedded-hal]
31-
features = ["unproven"]
32-
version = "0.2.6"
33-
3429
[dependencies.void]
3530
default-features = false
3631
version = "1.0.2"
3732

3833
[dev-dependencies]
39-
cortex-m-rt = "0.7.1"
40-
cortex-m-rtic = "1.0.0"
41-
cortex-m-semihosting = "0.3.5"
42-
embedded-graphics = "0.5"
43-
embedded-sdmmc = "0.2.1"
44-
infrared = "0.11.0"
45-
panic-halt = "0.2.0"
46-
panic-semihosting = "0.5.3"
47-
smart-leds = "0.3.0"
48-
st7735-lcd = "0.6.1"
49-
ws2812-spi = { version = "0.3.0", features = [] }
34+
cortex-m-rt = "0.7.5"
35+
cortex-m-rtic = "1.1.4"
36+
cortex-m-semihosting = "0.5.0"
37+
panic-halt = "1.0.0"
38+
panic-semihosting = "0.6.0"
5039

5140
[features]
5241
default = ["i2c-blocking"]
5342
device-selected = []
5443
rt = ["stm32g0/rt"]
44+
defmt = ["embedded-hal/defmt-03"]
5545
stm32g030 = ["stm32g0/stm32g030", "stm32g0x0", "device-selected"]
5646
stm32g070 = ["stm32g0/stm32g070", "stm32g0x0", "device-selected"]
5747
stm32g031 = ["stm32g0/stm32g031", "stm32g0x1", "device-selected"]

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT LICENSE
22

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

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

examples/adc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ fn main() -> ! {
4141
loop {
4242
let u_mv = adc.read_voltage(&mut adc_pin).expect("adc read failed");
4343
let u_bat = adc.read_voltage(&mut vbat).expect("adc read failed");
44-
hprintln!("VBat: {}mV | PA0: {}mV", u_bat * 3, u_mv).unwrap();
44+
hprintln!("VBat: {}mV | PA0: {}mV", u_bat * 3, u_mv);
4545
}
4646
}

examples/adc_ext_trig_double_dma_serial.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// command build: cargo build --example adc_ext_trig_double_dma_serial --features stm32g031
33
// command run: cargo run --example adc_ext_trig_double_dma_serial --features stm32g031
44

5-
#![deny(warnings)]
65
#![no_main]
76
#![no_std]
87

@@ -24,14 +23,12 @@ use rt::entry;
2423
use core::cell::RefCell;
2524
use cortex_m::interrupt::Mutex;
2625

26+
use crate::hal::analog::adc::DmaMode;
27+
use crate::hal::analog::adc::InjectMode;
2728
use crate::hal::stm32::{interrupt, Interrupt};
2829
use hal::analog::adc::{InjTrigSource, Precision, SampleTime}; //, VTemp
29-
3030
use hal::dma::{self, Channel, Target};
3131

32-
use crate::hal::analog::adc::DmaMode;
33-
use crate::hal::analog::adc::InjectMode;
34-
3532
// Make dma globally available
3633
static G_DMA: Mutex<RefCell<Option<hal::dma::Channels>>> = Mutex::new(RefCell::new(None));
3734

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

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

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

169166
adc.set_oversampling_ratio(adc::OversamplingRatio::X_16);
170167
adc.set_oversampling_shift(4);

examples/blinky_random.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ fn main() -> ! {
2929
let mut rng = dp.RNG.constrain(Config::default(), &mut rcc);
3030
let mut random_bytes = [0u16; 3];
3131
match rng.fill(&mut random_bytes) {
32-
Ok(()) => hprintln!("random bytes: {:?}", random_bytes).unwrap(),
33-
Err(err) => hprintln!("RNG error: {:?}", err).unwrap(),
32+
Ok(()) => hprintln!("random bytes: {:?}", random_bytes),
33+
Err(err) => hprintln!("RNG error: {:?}", err),
3434
}
3535
loop {
3636
match rng.gen_range(20, 200) {
3737
Ok(period) => {
38-
led.toggle().unwrap();
38+
led.toggle().ok();
3939
delay.delay(period.millis());
4040
}
41-
Err(err) => hprintln!("RNG error: {:?}", err).unwrap(),
41+
Err(err) => hprintln!("RNG error: {:?}", err),
4242
}
4343
}
4444
}
4545

4646
#[allow(clippy::empty_loop)]
4747
#[exception]
4848
unsafe fn HardFault(ef: &ExceptionFrame) -> ! {
49-
hprintln!("Hard fault {:#?}", ef).unwrap();
49+
hprintln!("Hard fault {:#?}", ef);
5050
loop {}
5151
}

examples/button.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() -> ! {
2121
let mut delay = cp.SYST.delay(&mut rcc);
2222

2323
let gpioc = dp.GPIOC.split(&mut rcc);
24-
let button = gpioc.pc13.into_pull_up_input();
24+
let mut button = gpioc.pc13.into_pull_up_input();
2525

2626
let gpioa = dp.GPIOA.split(&mut rcc);
2727
let mut led = gpioa.pa5.into_push_pull_output();

examples/crc.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ fn main() -> ! {
3434
"crc32: 0x{:x}, crc32b: 0x{:x}",
3535
hash_sum,
3636
hash_sum ^ 0xffff_ffff
37-
)
38-
.unwrap();
37+
);
3938

4039
crc.reset();
4140
crc.feed(b"The quick brown fox jumps over the lazy dog");
@@ -44,7 +43,6 @@ fn main() -> ! {
4443
"crc32: 0x{:x}, crc32b: 0x{:x}",
4544
hash_sum,
4645
hash_sum ^ 0xffff_ffff
47-
)
48-
.unwrap();
46+
);
4947
}
5048
}

examples/dac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ extern crate panic_halt;
1212
extern crate stm32g0xx_hal as hal;
1313

1414
use hal::analog::dac::GeneratorConfig;
15-
use hal::hal::Direction;
1615
use hal::prelude::*;
1716
use hal::rcc::Config;
1817
use hal::stm32;
18+
use hal::timer::qei::Direction;
1919
use rt::entry;
2020

2121
#[entry]

examples/flash.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ fn main() -> ! {
3535
hprintln!(
3636
"{:02X?}",
3737
u64::from_le_bytes((&buffer[0..8]).try_into().expect("never fails"))
38-
)
39-
.ok();
38+
);
4039
}
41-
Err(_) => hprintln!("Cannot unlock flash").unwrap(),
40+
Err(_) => hprintln!("Cannot unlock flash"),
4241
}
4342

4443
loop {}

0 commit comments

Comments
 (0)