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
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
device:
- stm32g431
- stm32g441
- stm32g471
- stm32g473
- stm32g474
- stm32g483
Expand All @@ -28,8 +27,8 @@ jobs:
- log-rtt,defmt
# TODO: -log-rtt # log-rtt without defmt, more combos?
- log-itm
- log-semihost
- cordic,log-rtt,defmt
- log-semihost,can
- cordic,usb,log-rtt,defmt

steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
],
"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
"rust-analyzer.cargo.features": [
"stm32g473",
"stm32g484",
"defmt",
"cordic"
]
}
}
35 changes: 16 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ version = "0.0.2"
nb = "1"
stm32g4 = { version = "0.22.0", package = "stm32g4-staging" }
paste = "1.0"
bitflags = "1.2"
vcell = "0.1"
static_assertions = "1.1"
fugit = "0.3.7"
stm32-usbd = { version = "0.7.0", optional = true }
fixed = { version = "1.28.0", optional = true }
Expand All @@ -30,15 +27,12 @@ features = ["critical-section-single-core"]
[dependencies.fdcan]
version = "0.2.1"
features = ["fdcan_g0_g4_l5"]
optional = true

[dependencies.cast]
version = "0.2.7"
default-features = false

[dependencies.bare-metal]
features = ["const-fn"]
version = "0.2.5"

[dependencies.embedded-hal-old]
package = "embedded-hal"
features = ["unproven"]
Expand All @@ -54,12 +48,8 @@ version = "0.1.2"
default-features = false
version = "1.0.2"

[dependencies.stable_deref_trait]
default-features = false
version = "1.1"

[dependencies.defmt]
version = "0.3.2"
version = "1"
optional = true

[dev-dependencies]
Expand Down Expand Up @@ -89,13 +79,12 @@ rt = ["stm32g4/rt"]
usb = ["dep:stm32-usbd"]
stm32g431 = ["stm32g4/stm32g431"]
stm32g441 = ["stm32g4/stm32g441"]
stm32g471 = ["stm32g4/stm32g471"]
stm32g473 = ["stm32g4/stm32g473"]
stm32g474 = ["stm32g4/stm32g474"]
stm32g483 = ["stm32g4/stm32g483"]
stm32g484 = ["stm32g4/stm32g484"]
stm32g491 = ["stm32g4/stm32g491"]
stm32g4a1 = ["stm32g4/stm32g4a1"]
stm32g473 = ["stm32g4/stm32g473", "adc3", "adc4", "adc5"]
stm32g474 = ["stm32g4/stm32g474", "adc3", "adc4", "adc5"]
stm32g483 = ["stm32g4/stm32g483", "adc3", "adc4", "adc5"]
stm32g484 = ["stm32g4/stm32g484", "adc3", "adc4", "adc5"]
stm32g491 = ["stm32g4/stm32g491", "adc3"]
stm32g4a1 = ["stm32g4/stm32g4a1", "adc3"]
log-itm = ["cortex-m-log/itm"]
log-rtt = []
log-semihost = ["cortex-m-log/semihosting"]
Expand All @@ -107,6 +96,10 @@ defmt = [
"embedded-io/defmt-03",
]
cordic = ["dep:fixed"]
adc3 = []
adc4 = []
adc5 = []
can = ["dep:fdcan"]

[profile.dev]
codegen-units = 1
Expand All @@ -127,6 +120,10 @@ codegen-units = 1
incremental = false
lto = true

[[example]]
name = "can-echo"
required-features = ["can"]

[[example]]
name = "flash_with_rtic"
required-features = ["stm32g474"]
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ probe-rs chip list

For furher information, see the documentation for [probe-rs](https://github.com/probe-rs/probe-rs).

#### Running tests on a Nucleo-G474RE

First move jumper from CN12 and put it between A1 and A2 on CN8

```bash
cargo test --features stm32g474,defmt,cordic --tests -- --chip stm32g474RETx
```

### Using as a Dependency

When using this crate as a dependency in your project, the microcontroller can
Expand Down
16 changes: 9 additions & 7 deletions examples/adc-continious-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::hal::{
adc::{
config,
config::{Continuous, Dma as AdcDma, SampleTime, Sequence},
AdcClaim, ClockSource, Temperature, Vref,
AdcClaim, Vref,
},
delay::SYSTDelayExt,
dma::{channel::DMAExt, config::DmaConfig, TransferExt},
Expand All @@ -18,7 +18,10 @@ use crate::hal::{
signature::{VrefCal, VDDA_CALIB},
stm32::Peripherals,
};
use stm32g4xx_hal as hal;
use stm32g4xx_hal::{
self as hal,
adc::{temperature::Temperature, AdcCommonExt},
};

use cortex_m_rt::entry;

Expand Down Expand Up @@ -49,12 +52,11 @@ fn main() -> ! {
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 adc12_common = dp.ADC12_COMMON.claim(Default::default(), &mut rcc);
let mut adc = adc12_common.claim(dp.ADC1, &mut delay);

adc.enable_temperature(&dp.ADC12_COMMON);
adc.enable_vref(&dp.ADC12_COMMON);
adc12_common.enable_temperature();
adc12_common.enable_vref();
adc.set_continuous(Continuous::Continuous);
adc.reset_sequence();
adc.configure_channel(&pa0, Sequence::One, SampleTime::Cycles_640_5);
Expand Down
16 changes: 9 additions & 7 deletions examples/adc-continious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::hal::{
adc::{
config::{Continuous, Resolution, SampleTime, Sequence},
AdcClaim, ClockSource, Temperature, Vref,
AdcClaim, Vref,
},
delay::SYSTDelayExt,
gpio::GpioExt,
Expand All @@ -13,7 +13,10 @@ use crate::hal::{
signature::{VrefCal, VDDA_CALIB},
stm32::Peripherals,
};
use stm32g4xx_hal as hal;
use stm32g4xx_hal::{
self as hal,
adc::{temperature::Temperature, AdcCommonExt},
};

use cortex_m_rt::entry;

Expand Down Expand Up @@ -43,12 +46,11 @@ fn main() -> ! {

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 adc12_common = dp.ADC12_COMMON.claim(Default::default(), &mut rcc);
let mut adc = adc12_common.claim(dp.ADC1, &mut delay);

adc.enable_temperature(&dp.ADC12_COMMON);
adc.enable_vref(&dp.ADC12_COMMON);
adc12_common.enable_temperature();
adc12_common.enable_vref();
adc.set_auto_delay(true);
adc.set_continuous(Continuous::Continuous);
adc.reset_sequence();
Expand Down
14 changes: 8 additions & 6 deletions examples/adc-one-shot-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cortex_m_rt::entry;
use crate::hal::{
adc::{
config::{Continuous, Dma as AdcDma, Resolution, SampleTime, Sequence},
AdcClaim, ClockSource, Temperature,
AdcClaim,
},
delay::SYSTDelayExt,
dma::{channel::DMAExt, config::DmaConfig, TransferExt},
Expand All @@ -15,7 +15,10 @@ use crate::hal::{
rcc::{Config, RccExt},
stm32::Peripherals,
};
use stm32g4xx_hal as hal;
use stm32g4xx_hal::{
self as hal,
adc::{temperature::Temperature, AdcCommonExt},
};

#[macro_use]
mod utils;
Expand Down Expand Up @@ -49,11 +52,10 @@ fn main() -> ! {
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 adc12_common = dp.ADC12_COMMON.claim(Default::default(), &mut rcc);
let mut adc = adc12_common.claim(dp.ADC1, &mut delay);

adc.enable_temperature(&dp.ADC12_COMMON);
adc12_common.enable_temperature();
adc.set_continuous(Continuous::Single);
adc.reset_sequence();
adc.configure_channel(&pa0, Sequence::One, SampleTime::Cycles_640_5);
Expand Down
9 changes: 4 additions & 5 deletions examples/adc-one-shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::hal::{
stm32::Peripherals,
};
use hal::prelude::*;
use stm32g4xx_hal as hal;
use stm32g4xx_hal::{self as hal, adc::AdcCommonExt};

use cortex_m_rt::entry;

Expand All @@ -33,12 +33,11 @@ fn main() -> ! {

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

info!("Setup Gpio");
Expand Down
14 changes: 9 additions & 5 deletions examples/observe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ use hal::{
stm32,
};
use rt::entry;
use stm32g4xx_hal::{self as hal, adc::config::SampleTime, delay::DelayExt as _, stasis::Freeze};
use stm32g4xx_hal::{
self as hal,
adc::{config::SampleTime, AdcCommonExt},
delay::DelayExt as _,
stasis::Freeze,
};

#[entry]
fn main() -> ! {
Expand All @@ -40,12 +45,11 @@ fn main() -> ! {
let _comp1 = comp1.enable(); // <-- TODO: Do things with comparator

let mut delay = cp.SYST.delay(&rcc.clocks);
let mut adc = dp.ADC1.claim_and_configure(
stm32g4xx_hal::adc::ClockSource::SystemClock,
&rcc,
let adc12_common = dp.ADC12_COMMON.claim(Default::default(), &mut rcc);
let mut adc = adc12_common.claim_and_configure(
dp.ADC1,
stm32g4xx_hal::adc::config::AdcConfig::default(),
&mut delay,
false,
);

// Can not reconfigure pa1 here
Expand Down
7 changes: 3 additions & 4 deletions examples/opamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![no_main]

use stm32g4xx_hal::adc::AdcClaim;
use stm32g4xx_hal::adc::ClockSource;
use stm32g4xx_hal::adc::AdcCommonExt;
use stm32g4xx_hal::opamp::Gain;
use stm32g4xx_hal::prelude::*;
use stm32g4xx_hal::pwr::PwrExt;
Expand Down Expand Up @@ -66,9 +66,8 @@ fn main() -> ! {
let opamp2 = opamp2.lock();

let mut delay = cp.SYST.delay(&rcc.clocks);
let mut adc = dp
.ADC2
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
let adc12_common = dp.ADC12_COMMON.claim(Default::default(), &mut rcc);
let mut adc = adc12_common.claim(dp.ADC2, &mut delay);

loop {
// Here we can sample the output of opamp2 as if it was a regular AD pin
Expand Down
Loading
Loading