Skip to content

Commit 02c1c5e

Browse files
committed
Merge branch 'master' into tim2-pwm
# Conflicts: # CHANGELOG.md
2 parents b757368 + 72b0bea commit 02c1c5e

11 files changed

+670
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
### Added
11-
12-
- PWM capability for TIM2
13-
14-
- PWM complementary output capability for TIM1 with new example to demonstrate
15-
1610
### Changed
1711

1812
- Updated the `cast` dependency from 0.2 to 0.3
@@ -21,10 +15,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2115

2216
- Provide getters to serial status flags idle/txe/rxne/tc.
2317
- Provide ability to reset timer UIF interrupt flag
18+
- PWM complementary output capability for TIM1 with new example to demonstrate
19+
- Implement interface for reading and writing to the internal flash memory and an example for demonstration.
20+
- PWM output on complementary channels only for single channel timers (TIM16 + TIM17)
21+
- PWM capability for TIM2
2422

2523
### Fixed
2624

2725
- Wrong mode when using PWM channel 2 of a two-channel timer
26+
- `adc_values` example conversion error
27+
- `invalid_reference_casting` Compilation error in spi.rs for Rust version 1.73+ (
28+
See [PR#112431](https://github.com/rust-lang/rust/pull/112431) for more info)
29+
- `unused_doc_comments` Warning in rcc.rs
2830

2931
## [v0.18.0] - 2021-11-14
3032

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ nb = "1"
3939
void = { version = "1.0", default-features = false }
4040
stm32-usbd = { version = "0.6", optional = true }
4141
bxcan = "0.6.0"
42+
embedded-storage = "0.3.0"
4243

4344
[dev-dependencies]
4445
cortex-m-rt = "0.7"

examples/adc_values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn SysTick() {
7979
if let Some(ref mut shared) = SHARED.borrow(cs).borrow_mut().deref_mut() {
8080
// Read temperature data from internal sensor using ADC
8181
let t = hal::adc::VTemp::read(&mut shared.adc, None);
82-
writeln!(shared.tx, "Temperature {}.{}C\r", t / 100, t % 100).ok();
82+
writeln!(shared.tx, "Temperature {}.{}C\r", t / 10, t % 10).ok();
8383

8484
// Read volatage reference data from internal sensor using ADC
8585
let t = hal::adc::VRef::read_vdda(&mut shared.adc);

examples/flash_read_write.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
use panic_halt as _;
5+
use stm32f0xx_hal as hal;
6+
7+
use crate::hal::{
8+
flash::{FlashExt, LockedFlash},
9+
pac,
10+
prelude::*,
11+
};
12+
13+
use cortex_m_rt::entry;
14+
use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
15+
16+
/// # NOTE
17+
/// This example assumes a flash size of more than 16K. If your MCU has less or equal than 16K Bytes
18+
/// of flash memory, adjust the `memory.x` file and `OFFSET_START` + `OFFSET_END` constants accordingly.
19+
#[entry]
20+
fn main() -> ! {
21+
if let Some(mut p) = pac::Peripherals::take() {
22+
let _ = p.RCC.configure().freeze(&mut p.FLASH);
23+
24+
// Check that flash is big enough for this example
25+
assert!(p.FLASH.len() > 16 * 1024);
26+
27+
// All examples use the first 16K of flash for the program so we use the first page after that
28+
const OFFSET_START: u32 = 16 * 1024;
29+
const OFFSET_END: u32 = OFFSET_START + 1024;
30+
// Unlock flash before writing
31+
let mut unlocked_flash = p.FLASH.unlocked();
32+
33+
NorFlash::erase(&mut unlocked_flash, OFFSET_START, OFFSET_END).unwrap();
34+
35+
// Write some data to the start of that page
36+
let write_data = [0xC0_u8, 0xFF_u8, 0xEE_u8, 0x00_u8];
37+
match NorFlash::write(&mut unlocked_flash, OFFSET_START, &write_data) {
38+
Err(_) => panic!(),
39+
Ok(_) => (),
40+
}
41+
42+
// Read back the written data from flash
43+
let mut read_buffer: [u8; 4] = [0; 4];
44+
unlocked_flash.read(OFFSET_START, &mut read_buffer).unwrap();
45+
assert_eq!(write_data, read_buffer);
46+
47+
// Lock flash by dropping it
48+
drop(unlocked_flash);
49+
50+
// It is also possible to read "manually" using core functions
51+
let read_data = unsafe {
52+
core::slice::from_raw_parts(
53+
(p.FLASH.address() + OFFSET_START as usize) as *const u8,
54+
write_data.len(),
55+
)
56+
};
57+
for (i, d) in read_data.iter().enumerate() {
58+
read_buffer[i] = *d;
59+
}
60+
61+
assert_eq!(write_data, read_buffer);
62+
63+
// Reading is also possible on locked flash
64+
let mut locked_flash = LockedFlash::new(p.FLASH);
65+
locked_flash.read(OFFSET_START, &mut read_buffer).unwrap();
66+
67+
assert_eq!(write_data, read_buffer);
68+
}
69+
loop {
70+
continue;
71+
}
72+
}

0 commit comments

Comments
 (0)