Skip to content

Commit 052411d

Browse files
authored
Merge pull request #212 from Sh3Rm4n/more-tests
Add more tests
2 parents 8652760 + 2f02c3b commit 052411d

28 files changed

+1028
-183
lines changed

.cargo/config.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
# and only avaliable under the -Z extra-link-arg flag.
99
# See https://github.com/rust-lang/cargo/pull/8441
1010
[target.thumbv7em-none-eabihf]
11-
runner = "arm-none-eabi-gdb"
11+
# runner = "arm-none-eabi-gdb"
1212
# Chip can be set via `--chip STM32F303VCTx` or `export PROBE_RUN_CHIP=STM32F303VCTx`
13-
# runner = "probe-run"
13+
runner = "probe-run --chip STM32F303VCTx --connect-under-reset"
1414
rustflags = [
15+
"-C", "link-arg=--nmagic",
1516
"-C", "link-arg=-Tlink.x",
16-
# "-C", "link-arg=-Tdefmt.x",
17+
"-C", "link-arg=-Tdefmt.x",
18+
# "-C", "linker=flip-link",
1719
]
1820

1921
[build]

.github/workflows/ci.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,9 @@ jobs:
9292
command: check
9393
args: --features=stm32f303xc,stm32-usbd,rt,can,ld --lib --examples
9494

95-
check-tests:
96-
name: Check Tests
95+
build-testsuite:
96+
name: Build Testsuite
9797
runs-on: ubuntu-latest
98-
strategy:
99-
matrix:
100-
test:
101-
- rcc
102-
mcu:
103-
- stm32f303xc
104-
- stm32f303xd
10598
steps:
10699
- uses: actions/checkout@v2
107100
- uses: actions-rs/toolchain@v1
@@ -112,8 +105,8 @@ jobs:
112105
profile: minimal
113106
- uses: actions-rs/cargo@v1
114107
with:
115-
command: check
116-
args: --features=ld,defmt,${{ matrix.mcu }} --test ${{ matrix.test }}
108+
command: test
109+
args: -p testsuite --no-run
117110

118111
check-doc:
119112
name: Check Documentation Build
@@ -177,7 +170,7 @@ jobs:
177170
override: true
178171
profile: minimal
179172
components: rustfmt
180-
- run: cd codegen && cargo check
173+
- run: cargo check --target "x86_64-unknown-linux-gnu" -p codegen
181174

182175
markdown-lint:
183176
name: Markdown Lint

CHANGELOG.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1818
- Support for GPIO interrupts ([#189])
1919
- `ld` feature, which enables the memory.x generation ([#216])
2020
- Implement `DelayMs` for `Milliseconds` and `DelayUs` for `Microseconds` ([#234])
21+
- ADC can now be `free()`'d ([#212])
2122

2223
### Changed
2324

@@ -44,11 +45,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4445
// The supplied frequencies must be in `MHz`.
4546
let clocks = rcc
4647
.cfgr
47-
.use_hse(8u32.MHz())
48-
.hclk(48u32.MHz())
49-
.sysclk(48u32.MHz())
50-
.pclk1(12u32.MHz())
51-
.pclk2(12u32.MHz())
48+
.use_hse(8.MHz())
49+
.hclk(48.MHz())
50+
.sysclk(48.MHz())
51+
.pclk1(12.MHz())
52+
.pclk2(12.MHz())
5253
```
5354

5455
- You always required to select a sub-target for target chips ([#216])
@@ -329,6 +330,7 @@ let clocks = rcc
329330
[#220]: https://github.com/stm32-rs/stm32f3xx-hal/pull/220
330331
[#217]: https://github.com/stm32-rs/stm32f3xx-hal/pull/217
331332
[#216]: https://github.com/stm32-rs/stm32f3xx-hal/pull/216
333+
[#212]: https://github.com/stm32-rs/stm32f3xx-hal/pull/212
332334
[#210]: https://github.com/stm32-rs/stm32f3xx-hal/pull/210
333335
[#208]: https://github.com/stm32-rs/stm32f3xx-hal/pull/208
334336
[#203]: https://github.com/stm32-rs/stm32f3xx-hal/issues/203

Cargo.toml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ exclude = [
2020
]
2121
resolver = "2"
2222

23+
[workspace]
24+
members = [
25+
".",
26+
"testsuite",
27+
"codegen"
28+
]
29+
2330
[package.metadata.docs.rs]
2431
features = ["stm32f303xc", "rt", "stm32-usbd", "can"]
2532
targets = ["thumbv7em-none-eabihf"]
@@ -134,15 +141,27 @@ defmt-info = ["defmt"]
134141
defmt-warn = ["defmt"]
135142
defmt-error = ["defmt"]
136143

144+
# cargo build/run
137145
[profile.dev]
138-
debug = true
146+
debug = 2
139147
lto = true
140148

149+
# cargo test
150+
[profile.test]
151+
debug = 2
152+
opt-level = 3 # <-
153+
154+
# cargo build/run --release
141155
[profile.release]
142-
debug = true
156+
debug = 2
143157
lto = true
144158
opt-level = "s"
145159

160+
# cargo test --release
161+
[profile.bench]
162+
debug = 2
163+
opt-level = "s"
164+
146165
[[example]]
147166
name = "pwm"
148167
required-features = ["ld", "stm32f303xc"]
@@ -186,8 +205,3 @@ required-features = ["ld", "stm32f303xc"]
186205
[[example]]
187206
name = "gpio_interrupts"
188207
required-features = ["ld", "rt", "stm32f303xc"]
189-
190-
[[test]]
191-
name = "rcc"
192-
required-features = ["ld", "defmt"]
193-
harness = false

README.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,5 @@ compile with older versions but that may change in any new patch release.
170170

171171
### Running Tests
172172

173-
Tests are run via the integration test pattern and are executed on a target
174-
chip, rather than on a host system. First, install
175-
[probe-run](https://crates.io/crates/probe-run) via `cargo install probe-run`.
176-
Next, you'll need to modify `.cargo/config` to link defmt and use `probe-run`
177-
configured for your chip. See details within the comments in that file.
178-
179-
Now, you can execute a test by setting your device, defmt, and any test specific
180-
features:
181-
182-
```bash
183-
cargo test --test rcc --features=stm32f303xc,defmt,rt
184-
```
185-
186-
The result _always_ shows a backtrace, even in the case of success.
187-
Exit code of 0 means that the run was successful.
173+
See [`testsuite/README.md`](testsuite/README.md) for how to set up and run
174+
tests on the target.

build.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,26 @@ This may be due to incorrect feature configuration in Cargo.toml or stm32f3xx-ha
169169
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
170170
let mut file = File::create(out_dir.join("memory.x")).unwrap();
171171
writeln!(file, "MEMORY {{").unwrap();
172-
writeln!(file, " FLASH (rx) : o = 0x8000000, l = {}K", flash).unwrap();
172+
writeln!(
173+
file,
174+
" FLASH (rx) : ORIGIN = 0x8000000, LENGTH = {}K",
175+
flash
176+
)
177+
.unwrap();
173178
if ccmram > 0 {
174-
writeln!(file, " CCMRAM (rwx) : o = 0x10000000, l = {}K", ccmram).unwrap();
179+
writeln!(
180+
file,
181+
" CCMRAM (rwx) : ORIGIN = 0x10000000, LENGTH = {}K",
182+
ccmram
183+
)
184+
.unwrap();
175185
}
176-
writeln!(file, " RAM (rwx) : o = 0x20000000, l = {}K", ram).unwrap();
186+
writeln!(
187+
file,
188+
" RAM (rwx) : ORIGIN = 0x20000000, LENGTH = {}K",
189+
ram
190+
)
191+
.unwrap();
177192
writeln!(file, "}}").unwrap();
178193
println!("cargo:rustc-link-search={}", out_dir.display());
179194
}
File renamed without changes.

examples/adc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ fn main() -> ! {
3232

3333
// Set up pin PA0 as analog pin.
3434
// This pin is connected to the user button on the stm32f3discovery board.
35-
let mut gpio_a = dp.GPIOA.split(&mut rcc.ahb);
36-
let mut adc1_in1_pin = gpio_a.pa0.into_analog(&mut gpio_a.moder, &mut gpio_a.pupdr);
35+
let mut gpioa = dp.GPIOA.split(&mut rcc.ahb);
36+
let mut adc1_in1_pin = gpioa.pa0.into_analog(&mut gpioa.moder, &mut gpioa.pupdr);
3737

3838
// Be aware that the values in the table below depend on the input of VREF.
3939
// To have a stable VREF input, put a condensator and a volt limiting diode in front of it.

examples/can.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ fn main() -> ! {
3131

3232
let _clocks = rcc
3333
.cfgr
34-
.use_hse(32u32.MHz())
35-
.sysclk(32u32.MHz())
36-
.pclk1(16u32.MHz())
37-
.pclk2(16u32.MHz())
34+
.use_hse(32.MHz())
35+
.sysclk(32.MHz())
36+
.pclk1(16.MHz())
37+
.pclk2(16.MHz())
3838
.freeze(&mut flash.acr);
3939

4040
// Configure CAN RX and TX pins (AF9)
@@ -58,13 +58,13 @@ fn main() -> ! {
5858
.into_push_pull_output(&mut gpiob.moder, &mut gpiob.otyper);
5959
led0.set_high().unwrap();
6060

61-
let filter = CanFilter::from_mask(0b100, ID as u32);
61+
let filter = CanFilter::from_mask(0b100, ID.into());
6262
rx0.set_filter(filter);
6363

6464
// Watchdog makes sure this gets restarted periodically if nothing happens
6565
let mut iwdg = IndependentWatchDog::new(dp.IWDG);
6666
iwdg.stop_on_debug(&dp.DBGMCU, true);
67-
iwdg.start(100u32.milliseconds());
67+
iwdg.start(100.milliseconds());
6868

6969
// Send an initial message!
7070
asm::delay(100_000);

examples/i2c_scanner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() -> ! {
4141
let mut i2c = hal::i2c::I2c::new(
4242
dp.I2C1,
4343
(scl, sda),
44-
100u32.kHz().try_into().unwrap(),
44+
100.kHz().try_into().unwrap(),
4545
clocks,
4646
&mut rcc.apb1,
4747
);

0 commit comments

Comments
 (0)