Skip to content

Commit ce1da43

Browse files
authored
Fix stm32g4 examples (#7)
* Remove examples * Cleanup * use defmt v1 * Bring back g4 examples as sub crate * Add examples to CI * Add examples to CI * Update examples for hal changes
1 parent b658b23 commit ce1da43

File tree

15 files changed

+131
-84
lines changed

15 files changed

+131
-84
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,33 @@ jobs:
4040
target: thumbv7em-none-eabihf
4141
override: true
4242

43+
- name: fmt
44+
run: cargo fmt --check
4345
- name: Regular build
4446
run: cargo check --features ${{ matrix.device }} --features ${{ matrix.features }}
45-
- name: Build examples
46-
run: cargo check --examples --features ${{ matrix.device }} --features ${{ matrix.features }}
4747
- name: Clippy
4848
run: cargo clippy --examples --features ${{ matrix.device }} --features ${{ matrix.features }}
49+
50+
examples:
51+
runs-on: ubuntu-latest
52+
strategy:
53+
matrix:
54+
include:
55+
- { family: stm32g4, device: stm32g474 }
56+
- { family: stm32g4, device: stm32g484 }
57+
#- { family: stm32f3, device: stm32f334 }
58+
#- { family: stm32h7, device: stm32h743 }
59+
steps:
60+
- uses: actions/checkout@v2
61+
- uses: actions-rs/toolchain@v1
62+
with:
63+
profile: minimal
64+
toolchain: stable
65+
target: thumbv7em-none-eabihf
66+
override: true
67+
- name: fmt
68+
run: cd examples/${{ matrix.family }}; cargo fmt --check
69+
- name: Build ${{ matrix.family }} examples
70+
run: cd examples/${{ matrix.family }}; cargo check --bins --features ${{ matrix.device }}
71+
- name: Clippy
72+
run: cd examples/${{ matrix.family }}; cargo clippy --bins --features ${{ matrix.device }}

Cargo.toml

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,19 @@ name = "stm32-hrtim"
33
version = "0.1.0"
44
edition = "2021"
55

6-
[patch.crates-io]
7-
stm32-hrtim = { path = "." }
8-
9-
[patch."https://github.com/usbalbin/stm32-hrtim"]
10-
stm32-hrtim = { path = "." }
11-
126
[dependencies]
137
stm32f3 = { git = "https://github.com/stm32-rs/stm32-rs-nightlies", optional = true }
148
stm32h7 = { git = "https://github.com/stm32-rs/stm32-rs-nightlies", features = ["critical-section"], optional = true }
159
stm32g4 = { version = "0.22.0", package = "stm32g4-staging", optional = true }
1610

17-
defmt = { version = "0.3.10", optional = true }
11+
defmt = { version = "1", optional = true }
1812
fugit = "0.3.7"
1913

2014
[dev-dependencies]
2115
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
2216
defmt-rtt = "0.4.0"
2317
cortex-m-rt = "0.7.2"
2418
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
25-
stm32g4xx-hal = { git = "https://github.com/usbalbin/stm32g4xx-hal", branch = "hrtim", features = ["defmt", "hrtim"] }
2619

2720
[features]
2821
default = []
@@ -46,53 +39,6 @@ stm32h753 = ["stm32h7/stm32h753", "hrtim_v1_1"]
4639
#stm32h755 = ["stm32h7/stm32h755", "hrtim_v1_1"]
4740
#stm32h757 = ["stm32h7/stm32h757", "hrtim_v1_1"]
4841

49-
stm32g474 = ["stm32g4/stm32g474", "stm32g4xx-hal/stm32g474", "hrtim_v2"]
50-
stm32g484 = ["stm32g4/stm32g484", "stm32g4xx-hal/stm32g484", "hrtim_v2"]
42+
stm32g474 = ["stm32g4/stm32g474", "hrtim_v2"]
43+
stm32g484 = ["stm32g4/stm32g484", "hrtim_v2"]
5144
defmt = ["dep:defmt", "fugit/defmt"]
52-
53-
# G4
54-
55-
[[example]]
56-
name = "stm32g4-adc-trigger"
57-
required-features = ["stm32g4"]
58-
path = "examples/stm32g4/adc-trigger.rs"
59-
60-
[[example]]
61-
name = "stm32g4-capture"
62-
required-features = ["stm32g4"]
63-
path = "examples/stm32g4/capture.rs"
64-
65-
[[example]]
66-
name = "stm32g4-capture-dma"
67-
required-features = ["stm32g4"]
68-
path = "examples/stm32g4/capture-dma.rs"
69-
70-
[[example]]
71-
name = "stm32g4-eev-comp"
72-
required-features = ["stm32g4"]
73-
path = "examples/stm32g4/eev-comp.rs"
74-
75-
[[example]]
76-
name = "stm32g4-eev"
77-
required-features = ["stm32g4"]
78-
path = "examples/stm32g4/eev.rs"
79-
80-
[[example]]
81-
name = "stm32g4-flt-comp"
82-
required-features = ["stm32g4"]
83-
path = "examples/stm32g4/flt-comp.rs"
84-
85-
[[example]]
86-
name = "stm32g4-flt"
87-
required-features = ["stm32g4"]
88-
path = "examples/stm32g4/flt.rs"
89-
90-
[[example]]
91-
name = "stm32g4"
92-
required-features = ["stm32g4"]
93-
path = "examples/stm32g4/hrtim.rs"
94-
95-
[[example]]
96-
name = "stm32g4-master"
97-
required-features = ["stm32g4"]
98-
path = "examples/stm32g4/master.rs"

examples/stm32g4/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
3+
Cargo.lock

examples/stm32g4/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "stm32-rs-hrtim-stm32g4-examples"
3+
version = "0.1.0"
4+
edition = "2024"
5+
publish = ["gitea"]
6+
7+
[patch.crates-io]
8+
stm32-hrtim = { path = "../../" }
9+
10+
[patch."https://github.com/usbalbin/stm32-hrtim"]
11+
stm32-hrtim = { path = "../../" }
12+
13+
[dependencies]
14+
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
15+
defmt-rtt = "0.4.0"
16+
cortex-m-rt = "0.7.2"
17+
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
18+
stm32g4xx-hal = { git = "https://github.com/usbalbin/stm32g4xx-hal", branch = "hrtim", features = ["defmt", "hrtim"] }
19+
stm32-hrtim = { path = "../../", features = ["defmt"] }
20+
defmt = "1.0.1"
21+
fugit = "0.3.7"
22+
23+
[features]
24+
stm32g474 = ["stm32-hrtim/stm32g474", "stm32g4xx-hal/stm32g474"]
25+
stm32g484 = ["stm32-hrtim/stm32g484", "stm32g4xx-hal/stm32g484"]

examples/stm32g4/memory.x

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
MEMORY
2+
{
3+
/* NOTE K = KiBi = 1024 bytes */
4+
/* TODO Adjust these memory regions to match your device memory layout */
5+
FLASH : ORIGIN = 0x8000000, LENGTH = 128K
6+
RAM : ORIGIN = 0x20000000, LENGTH = 32K
7+
}

examples/stm32g4/adc-trigger.rs renamed to examples/stm32g4/src/bin/adc-trigger.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#![no_std]
22
#![no_main]
33

4+
use defmt_rtt as _;
5+
46
/// Example showcasing the use of the HRTIM peripheral to trigger the ADC at various points of the switch cycle off HRTIM_TIMA
57
use cortex_m_rt::entry;
68
use panic_probe as _;
79
use stm32_hrtim::{
8-
compare_register::HrCompareRegister, output::HrOutput, timer::HrTimer, HrParts, HrPwmAdvExt,
9-
Pscl4,
10+
HrParts, HrPwmAdvExt, Pscl4, compare_register::HrCompareRegister, output::HrOutput,
11+
timer::HrTimer,
1012
};
1113
use stm32g4xx_hal::{
1214
adc::{self, AdcClaim, ClockSource, Temperature, Vref},
1315
delay::SYSTDelayExt,
14-
dma::{self, channel::DMAExt, config::DmaConfig, TransferExt},
16+
dma::{self, TransferExt, channel::DMAExt, config::DmaConfig},
1517
gpio::GpioExt,
1618
hrtim::{HrControltExt, HrPwmBuilderExt},
1719
pwr::PwrExt,

examples/stm32g4/capture-dma.rs renamed to examples/stm32g4/src/bin/capture-dma.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#![no_std]
22
#![no_main]
33

4+
use defmt_rtt as _;
5+
46
/// Example showcasing the use of the HRTIM peripheral's capture function to detect phase shift between a digital event and the output of HRTIM_TIMA
57
use cortex_m_rt::entry;
68
use panic_probe as _;
79
use stm32_hrtim::{
8-
capture,
10+
HrParts, HrPwmAdvExt, Pscl128, capture,
911
compare_register::HrCompareRegister,
1012
external_event::{self, ToExternalEventSource},
1113
output::HrOutput,
1214
timer::{HrSlaveTimerCpt, HrTimer, TimerSplitCapture},
13-
HrParts, HrPwmAdvExt, Pscl128,
1415
};
1516
use stm32g4xx_hal::{
16-
dma::{channel::DMAExt, config::DmaConfig, TransferExt},
17+
dma::{TransferExt, channel::DMAExt, config::DmaConfig},
1718
gpio::GpioExt,
18-
hrtim::{external_event::EevInputExt, HrControltExt, HrPwmBuilderExt},
19+
hrtim::{HrControltExt, HrPwmBuilderExt, external_event::EevInputExt},
1920
pwr::PwrExt,
2021
rcc::{self, RccExt},
2122
stm32::Peripherals,

examples/stm32g4/capture.rs renamed to examples/stm32g4/src/bin/capture.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
#![no_std]
22
#![no_main]
33

4+
use defmt_rtt as _;
5+
46
/// Example showcasing the use of the HRTIM peripheral's capture function to detect phase shift between a digital event and the output of HRTIM_TIMA
57
use cortex_m_rt::entry;
68
use panic_probe as _;
79
use stm32_hrtim::{
10+
HrParts, HrPwmAdvExt, Pscl128,
811
capture::HrCapture,
912
compare_register::HrCompareRegister,
1013
external_event::{self, ToExternalEventSource},
1114
output::HrOutput,
1215
timer::{HrSlaveTimerCpt, HrTimer},
13-
HrParts, HrPwmAdvExt, Pscl128,
1416
};
1517
use stm32g4xx_hal::{
1618
gpio::GpioExt,
17-
hrtim::{external_event::EevInputExt, HrControltExt, HrPwmBuilderExt},
19+
hrtim::{HrControltExt, HrPwmBuilderExt, external_event::EevInputExt},
1820
pwr::PwrExt,
1921
rcc::{self, RccExt},
2022
stm32::Peripherals,

examples/stm32g4/eev-comp.rs renamed to examples/stm32g4/src/bin/eev-comp.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
#![no_std]
22
#![no_main]
33

4+
use defmt_rtt as _;
5+
46
/// Example showcasing the use of the HRTIM peripheral together with a comparator to implement a cycle by cycle current limit.
57
/// Once the comparator input exceeds the reference set by the DAC, the output is set low thus limiting the pulse width and in turn the current.
68
use cortex_m_rt::entry;
79
use panic_probe as _;
810
use stm32_hrtim::{
11+
HrParts, HrPwmAdvExt, Polarity, Pscl4,
912
compare_register::HrCompareRegister,
1013
external_event::{self, ToExternalEventSource},
1114
output::HrOutput,
1215
timer::HrTimer,
1316
timer_eev_cfg::{EevCfg, EevCfgs},
14-
HrParts, HrPwmAdvExt, Polarity, Pscl4,
1517
};
1618
use stm32g4xx_hal::{
1719
comparator::{self, ComparatorExt, ComparatorSplit},
1820
dac::{self, DacExt, DacOut},
1921
delay::SYSTDelayExt,
2022
gpio::{GpioExt, SignalEdge},
21-
hrtim::{external_event::EevInputExt, HrControltExt, HrPwmBuilderExt},
23+
hrtim::{HrControltExt, HrPwmBuilderExt, external_event::EevInputExt},
2224
pwr::PwrExt,
2325
rcc::{self, RccExt},
2426
stm32::{CorePeripherals, Peripherals},
@@ -53,7 +55,7 @@ fn main() -> ! {
5355
let pin_a = gpioa.pa8;
5456

5557
let dac1ch1 = dp.DAC1.constrain(dac::Dac1IntSig1, &mut rcc);
56-
let mut dac = dac1ch1.calibrate_buffer(&mut delay).enable();
58+
let mut dac = dac1ch1.calibrate_buffer(&mut delay).enable(&mut rcc);
5759

5860
// Use dac to define the fault threshold
5961
// 2^12 / 2 = 2^11 for about half of VCC

examples/stm32g4/eev.rs renamed to examples/stm32g4/src/bin/eev.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
#![no_std]
22
#![no_main]
33

4+
use defmt_rtt as _;
5+
46
/// Example showcasing the use of the HRTIM peripheral together with a digital input to implement a cycle by cycle current limit.
57
/// Once the digital input goes high, the output is set low thus limiting the pulse width and in turn the current.
68
use cortex_m_rt::entry;
79
use panic_probe as _;
810
use stm32_hrtim::{
11+
HrParts, HrPwmAdvExt, Polarity, Pscl4,
912
compare_register::HrCompareRegister,
1013
external_event::{self, ToExternalEventSource},
1114
output::HrOutput,
1215
timer::HrTimer,
1316
timer_eev_cfg::EevCfgs,
14-
HrParts, HrPwmAdvExt, Polarity, Pscl4,
1517
};
1618
use stm32g4xx_hal::{
1719
gpio::GpioExt,
18-
hrtim::{external_event::EevInputExt, HrControltExt, HrPwmBuilderExt},
20+
hrtim::{HrControltExt, HrPwmBuilderExt, external_event::EevInputExt},
1921
pwr::PwrExt,
2022
rcc::{self, RccExt},
2123
stm32::Peripherals,

0 commit comments

Comments
 (0)