Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
af954fb
Use fugit https://github.com/stm32-rs/stm32g4xx-hal/pull/68
usbalbin Jun 7, 2023
35c8157
Fix warnings (#4)
usbalbin Jun 7, 2023
96498d7
Fix defmt examples (#7)
usbalbin Jun 7, 2023
bdb1f3b
Ci2 (#6)
usbalbin Jun 7, 2023
bef3d5d
Opamp pga2 (#8)
usbalbin Jun 8, 2023
66968ff
Comp and dac2 (#9)
usbalbin Jun 8, 2023
6750a27
WIP
usbalbin May 9, 2023
8fe636b
Untested sort of maybe working chaos
usbalbin May 20, 2023
12b5f0b
Dual channel support and cargo fmt
usbalbin May 20, 2023
465fd7a
Almost...
usbalbin May 20, 2023
28afbe0
Still untested but might actually work, maybe
usbalbin May 20, 2023
ace583e
Adjust doc
usbalbin May 20, 2023
117ead4
Enable outputs in example
usbalbin May 20, 2023
754536c
Further cleanup
usbalbin May 20, 2023
1c001a4
Fix 'Error: section found, but no version symbol'
usbalbin May 27, 2023
d3f095f
Tested and verified on NUCLEO-G474RE
usbalbin Jun 7, 2023
3510c29
hrtim_simple also tested and verified on NUCLEO-G474RE
usbalbin Jun 7, 2023
1c0265c
Hrtim cleanup, add pins for all timers but HRTIM_TIMF
usbalbin Jun 9, 2023
9e56edc
Add more comparator impls
usbalbin Jun 14, 2023
2fcbd71
Comparator does not need to consume its positive input pin
usbalbin Jun 14, 2023
8e8e794
Several changes and fixes
usbalbin Jun 20, 2023
8fd0faf
Start work on hrtim fault
usbalbin Jun 12, 2023
3c65236
Add hrtim fault example
usbalbin Jun 20, 2023
124c77c
TOO MANY CHANGES
usbalbin Jun 28, 2023
0957259
Add ADC triggers among a lot of things to hrtim
usbalbin Aug 25, 2023
0679cbe
Fix bug in opamp
usbalbin Aug 25, 2023
8ac8459
Disable push pull
usbalbin Aug 25, 2023
ea83f58
NOT DONE add pwr config
usbalbin Sep 4, 2023
99db708
Add some usable DMA function for reading the entire buffer
usbalbin Sep 4, 2023
c0cfd7d
NOT DONE - Losts of hrtim stuff
usbalbin Sep 4, 2023
b2e3a40
Add methods for setting subgroup length for ADC Discontinuous mode
usbalbin Sep 4, 2023
f8696b3
Added src/independent_watchdog.rs and example from stm32h7xx-hal - co…
usbalbin Sep 14, 2023
85b35e5
Start work on voltage scaling
usbalbin Sep 14, 2023
ff7046d
Adapted watchdog for this crate
usbalbin Sep 14, 2023
c9cf1e9
Fix DMA to DMAMUX mapping
usbalbin Sep 14, 2023
d556f8a
DMA add some useful methods
usbalbin Sep 14, 2023
83aedc5
ADC fmt subgroup_len
usbalbin Sep 14, 2023
24a1cc5
IWDT fmt
usbalbin Sep 14, 2023
8b6cb2e
IWDT - Update to use fugit, bringing it closer to stm32h7 again
usbalbin Sep 14, 2023
82e9188
Make adc-continious-dma example use utils for logger
usbalbin Sep 14, 2023
8842b9a
Add methods for checking for ADC overrun
usbalbin Sep 14, 2023
b6d0e5c
Forgot to add mod pwr import
usbalbin Oct 24, 2023
fe461c6
Multiple hrtim changes
usbalbin Oct 24, 2023
806ebb5
Add way to get reset reason
usbalbin Oct 24, 2023
4129ea9
Serial - Implement marker traits to allow using usart with defmt-serial
usbalbin Oct 24, 2023
ca290c2
Add MillisSecond
usbalbin Oct 24, 2023
be8df78
HRTIM: Fix bad pin mapping
usbalbin Oct 24, 2023
fb8e58f
HRTIM - Rework EventSource system and add deadtime support
usbalbin Oct 24, 2023
7e3b7b7
HRTIM refactor
usbalbin Nov 3, 2023
fac7c13
More hrtim refactor
usbalbin Nov 4, 2023
8a80ccf
EEV
usbalbin Nov 5, 2023
64e9609
More work on hrtim eev
usbalbin Nov 6, 2023
d537d1b
even more eev hrtim
usbalbin Nov 6, 2023
fbe1d1a
more eev hrtim
usbalbin Nov 7, 2023
d6c773c
Update hrtim examples. TODO: Make sure timers are started
usbalbin Nov 8, 2023
72d249d
Fix examples for the RCC PWR change
usbalbin Nov 8, 2023
d931c01
OP follower can be used by ADC
usbalbin Nov 8, 2023
36036c8
DAC - Add TODO about problem when not buffer calibrated
usbalbin Nov 8, 2023
2f1cb88
Fix warning in gpio
usbalbin Nov 8, 2023
18b5fb0
PWR allow dead code for function that will be used to change voltage …
usbalbin Nov 8, 2023
000f316
PWM fix clippy warning
usbalbin Nov 8, 2023
5a9aa77
PWR fix leftovers
usbalbin Nov 8, 2023
8d8b9c6
EXTI - TODO: Why where those checks there?
usbalbin Nov 8, 2023
2634c9c
HRTIM examples
usbalbin Nov 8, 2023
03d0a6c
Fix warnings for hrtim
usbalbin Nov 8, 2023
8ed19d2
DMA make it compile on all devices
usbalbin Nov 8, 2023
501f2ff
COMP make compile for all devices
usbalbin Nov 8, 2023
f689146
COMP make compile for all devices
usbalbin Nov 8, 2023
3000742
ADC make compile for all devices
usbalbin Nov 8, 2023
dbabd19
OPAMP fix warnings in example
usbalbin Nov 8, 2023
091a592
DAC fmt
usbalbin Nov 8, 2023
8893cd7
Replace casts of &T to &mut T with UnsafeCell
no111u3 Nov 28, 2023
3ec2830
HRTIM - Move timer interrupt enable and clear to trait
usbalbin Dec 15, 2023
7288d27
Changes to Flash.rs
amcelroy Sep 14, 2023
8288726
Added changes systec-ms
amcelroy Nov 14, 2023
4a32801
FlashWriter.write requires additional user input
amcelroy Nov 16, 2023
b2989c1
Fix warnings, remove wrong files from repo
no111u3 Nov 28, 2023
47b80d3
Post review changes
amcelroy Nov 28, 2023
0a4e980
Start fix dual bank related bugs in flash.rs
usbalbin Dec 15, 2023
8b1a661
PWR - Boost mode inverted
usbalbin Dec 15, 2023
bab61ae
Add simple flash example
usbalbin Dec 15, 2023
095df33
Cleanup rtic flash example
usbalbin Dec 15, 2023
3928f49
Flash - Update to be closer to RM
usbalbin Dec 17, 2023
8e1f026
Flash - In the middle of some troubleshooting
usbalbin Dec 17, 2023
434cb3b
Cleanup and fix flash (`fn read` still needs some though)
usbalbin Dec 18, 2023
87350ef
Fmt flash example
usbalbin Dec 18, 2023
b3007bf
spi fmt
usbalbin Dec 18, 2023
176f228
Use stm32-rs/stm32-rs commit with fixed hrtim_hrtimf registers ab9082…
usbalbin Dec 18, 2023
0764406
Undo some Cargo stuff
usbalbin Dec 19, 2023
7780612
HRTIM: Start work on capture support
usbalbin Jan 17, 2024
382a773
HRTIM: Add capture.rs
usbalbin Jan 18, 2024
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
16 changes: 14 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ jobs:
matrix:
rust:
- stable
feature:
device:
- stm32g431
- stm32g441
- stm32g471
- stm32g473
- stm32g474
- stm32g483
- stm32g484
#- stm32g491 # Does not seem ready yet
#- stm32g4a1 # Does not seem ready yet
features:
- rt
- log-rtt,defmt
# TODO: -log-rtt # log-rtt without defmt, more combos?
- log-itm
- log-semihost

steps:
- uses: actions/checkout@v2
Expand All @@ -29,4 +37,8 @@ jobs:
override: true

- name: Regular build
run: cargo check --features ${{ matrix.feature }}
run: cargo check --features ${{ matrix.device }} --features ${{ matrix.features }}
- name: Build examples
run: cargo check --examples --features ${{ matrix.device }} --features ${{ matrix.features }}
- name: Clippy
run: cargo clippy --examples --features ${{ matrix.device }} --features ${{ matrix.features }}
2 changes: 1 addition & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --features=stm32g431 --target thumbv7em-none-eabihf
args: --features=stm32g484,log-rtt,defmt --target thumbv7em-none-eabihf
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/target/
**/*.orig
**/*.rs.bk
Cargo.lock
Cargo.lock

# Remove idea files
.idea/
42 changes: 40 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ readme = "README.md"
repository = "https://github.com/stm32-rs/stm32g4xx-hal"
version = "0.0.1"

[patch.crates-io]
stm32g4 = { path = "../stm32-rs/stm32g4" }

[dependencies]
nb = "0.1.1"
stm32g4 = "0.15.1"
paste = "1.0"
bitflags = "1.2"
vcell = "0.1"
static_assertions = "1.1"
fugit = "0.3.5"

[dependencies.cortex-m]
version = "0.7.7"
Expand Down Expand Up @@ -67,8 +71,6 @@ lazy_static = { version = "1.4", features = ["spin_no_std"] }
log = "0.4.11"
cortex-m-log = { version = "0.7", features = ["log-integration"] }
cfg-if = "0.1.10"
rtt-target = { version = "0.3.0", features = ["cortex-m"] }
panic-rtt-target = { version = "0.1.1", features = ["cortex-m"] }
mpu6050 = "0.1.4"
bme680 = "0.6.0"
embedded-sdmmc = "0.3.0"
Expand Down Expand Up @@ -102,3 +104,39 @@ debug = false
codegen-units = 1
incremental = false
lto = true

[[example]]
name = "hrtim-adc-trigger"
path = "examples/hrtim/adc-trigger.rs"

[[example]]
name = "hrtim-eev-comp"
path = "examples/hrtim/eev-comp.rs"

[[example]]
name = "hrtim-eev-up-down"
path = "examples/hrtim/eev-up-down.rs"

[[example]]
name = "hrtim-eev"
path = "examples/hrtim/eev.rs"

[[example]]
name = "hrtim-flt-comp"
path = "examples/hrtim/flt-comp.rs"

[[example]]
name = "hrtim-flt"
path = "examples/hrtim/flt.rs"

[[example]]
name = "hrtim"
path = "examples/hrtim/hrtim.rs"

[[example]]
name = "hrtim-master"
path = "examples/hrtim/master.rs"

[[example]]
name = "hrtim-simple"
path = "examples/hrtim/simple.rs"
12 changes: 9 additions & 3 deletions examples/adc-continious-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ use crate::hal::{
delay::SYSTDelayExt,
dma::{config::DmaConfig, stream::DMAExt, TransferExt},
gpio::GpioExt,
pwr::PwrExt,
rcc::{Config, RccExt},
stm32::Peripherals,
};
use stm32g4xx_hal as hal;

use log::info;
use utils::logger::info;

#[macro_use]
mod utils;
Expand All @@ -32,7 +33,8 @@ fn main() -> ! {

info!("rcc");
let rcc = dp.RCC.constrain();
let mut rcc = rcc.freeze(Config::hsi());
let pwr = dp.PWR.constrain().freeze();
let mut rcc = rcc.freeze(Config::hsi(), pwr);

let streams = dp.DMA1.split(&rcc);
let config = DmaConfig::default()
Expand Down Expand Up @@ -69,13 +71,17 @@ fn main() -> ! {
loop {
let mut b = [0_u16; 4];
let r = transfer.read_exact(&mut b);
assert!(
!transfer.get_overrun_flag(),
"DMA did not have time to read the ADC value before ADC was done with a new conversion"
);

info!("read: {}", r);
assert!(r == b.len());

let millivolts = Vref::sample_to_millivolts((b[0] + b[2]) / 2);
info!("pa3: {}mV", millivolts);
let temp = Temperature::temperature_to_degrees_centigrade((b[1] + b[3]) / 2);
info!("temp: {}℃C", temp); // Note: Temperature seems quite low...
info!("temp: {}℃", temp); // Note: Temperature seems quite low...
}
}
6 changes: 4 additions & 2 deletions examples/adc-continious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ use crate::hal::{
},
delay::SYSTDelayExt,
gpio::GpioExt,
pwr::PwrExt,
rcc::{Config, RccExt},
stm32::Peripherals,
};
use stm32g4xx_hal as hal;

use cortex_m_rt::entry;

use log::info;
use utils::logger::info;

#[macro_use]
mod utils;
Expand All @@ -32,7 +33,8 @@ fn main() -> ! {
info!("rcc");

let rcc = dp.RCC.constrain();
let mut rcc = rcc.freeze(Config::hsi());
let pwr = dp.PWR.constrain().freeze();
let mut rcc = rcc.freeze(Config::hsi(), pwr);

info!("Setup Gpio");
let gpioa = dp.GPIOA.split(&mut rcc);
Expand Down
4 changes: 3 additions & 1 deletion examples/adc-one-shot-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::hal::{
delay::SYSTDelayExt,
dma::{config::DmaConfig, stream::DMAExt, TransferExt},
gpio::GpioExt,
pwr::PwrExt,
rcc::{Config, RccExt},
stm32::Peripherals,
};
Expand All @@ -33,7 +34,8 @@ fn main() -> ! {
info!("rcc");

let rcc = dp.RCC.constrain();
let mut rcc = rcc.freeze(Config::hsi());
let pwr = dp.PWR.constrain().freeze();
let mut rcc = rcc.freeze(Config::hsi(), pwr);

let mut streams = dp.DMA1.split(&rcc);
let config = DmaConfig::default()
Expand Down
24 changes: 15 additions & 9 deletions examples/adc-one-shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#![no_std]

use crate::hal::{
adc::{config::SampleTime, AdcClaim, ClockSource},
adc::{config::SampleTime, AdcClaim},
delay::SYSTDelayExt,
pwr::PwrExt,
rcc::Config,
stm32::Peripherals,
};
Expand All @@ -12,7 +13,7 @@ use stm32g4xx_hal as hal;

use cortex_m_rt::entry;

use log::info;
use utils::logger::info;

#[macro_use]
mod utils;
Expand All @@ -29,26 +30,31 @@ fn main() -> ! {
info!("rcc");

let rcc = dp.RCC.constrain();
let mut rcc = rcc.freeze(Config::hsi());
let pwr = dp.PWR.constrain().freeze();
let mut rcc = rcc.freeze(Config::hsi(), pwr);

info!("Setup Adc1");
let mut delay = cp.SYST.delay(&rcc.clocks);
let mut adc = dp
.ADC1
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
let mut adc = dp.ADC2.claim_and_configure(
stm32g4xx_hal::adc::ClockSource::SystemClock,
&rcc,
stm32g4xx_hal::adc::config::AdcConfig::default(),
&mut delay,
false,
);

info!("Setup Gpio");

let gpioa = dp.GPIOA.split(&mut rcc);
let pa0 = gpioa.pa0.into_analog();
let pa7 = gpioa.pa7.into_analog();

info!("Enter Loop");

loop {
info!("Convert");
let sample = adc.convert(&pa0, SampleTime::Cycles_640_5);
let sample = adc.convert(&pa7, SampleTime::Cycles_640_5);
info!("sample to mv");
let millivolts = adc.sample_to_millivolts(sample);
info!("pa3: {}mV", millivolts);
info!("pa7: {}mV", millivolts);
}
}
81 changes: 81 additions & 0 deletions examples/bench.rs_
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#![no_main]
#![no_std]

use crate::hal::{
adc::{config::SampleTime, AdcClaim, ClockSource},
delay::SYSTDelayExt,
rcc::Config,
stm32::Peripherals,
};
use hal::prelude::*;
use stm32g4xx_hal as hal;

use cortex_m::peripheral::DWT;
use cortex_m_rt::entry;

use utils::logger::info;

#[macro_use]
mod utils;

macro_rules! bench {
($data:expr, $op:ident, $($arg:expr, )*) => {{
let start_cyc = DWT::cycle_count();
for i in 0..10000 {
$data = $data.$op($($arg, )*);
}
let cycles = DWT::cycle_count() - start_cyc;

defmt::info!("$op: {} cycles - {}", cycles, $data);
}};
}

#[entry]
fn main() -> ! {
defmt::info!("init");

let dp = Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");

let rcc = dp.RCC.constrain();
let mut rcc = rcc.freeze(Config::hsi());

info!("Setup Adc1");
let mut delay = cp.SYST.delay(&rcc.clocks);
let mut adc = dp
.ADC1
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);

info!("Setup Gpio");

let gpioa = dp.GPIOA.split(&mut rcc);
let pa0 = gpioa.pa0.into_analog();

let sample = adc.convert(&pa0, SampleTime::Cycles_640_5) as f32;

info!("Enter Loop");

let mut data = sample;

bench!(data, sin,);
bench!(data, sqrt,);
bench!(data, atan2, sample,);
bench!(data, atan2, sample,);

info!("done!");
loop {}
}

/// Hardware sqrt
fn hsqrt(x: f32) -> f32 {
let mut result: f32;
unsafe {
core::arch::asm!(
"VSQRT.F32 {}, {}",
out(sreg) result, // Sreg for fpu register
in(sreg) x,
);
}

result
}
8 changes: 5 additions & 3 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ use hal::stm32;
use stm32g4xx_hal as hal;

use cortex_m_rt::entry;
use log::info;

#[macro_use]
mod utils;

use utils::logger::info;

#[entry]
fn main() -> ! {
utils::logger::init();
Expand All @@ -27,11 +28,12 @@ fn main() -> ! {

loop {
info!("Set Led low");
for _ in 0..100_000 {
for _ in 0..10_000_000 {
led.set_low().unwrap();
}

info!("Set Led High");
for _ in 0..100_000 {
for _ in 0..10_000_000 {
led.set_high().unwrap();
}
}
Expand Down
Loading