Skip to content

Commit 1ebf007

Browse files
authored
L47x and L48x use 110C as the calibration temp, rest use 130 (#265)
Rename the calibration structs to Low/High instead of 30/130 for clarity * 130 makes no sense when L47 uses 110 and Call30 and Cal30 can also be easily mistaken at a glance High constant is conditional on the device product feature
1 parent 4a3d984 commit 1ebf007

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/adc.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
},
1616
pac,
1717
rcc::{Enable, Reset, AHB2, CCIPR},
18-
signature::{VrefCal, VtempCal130, VtempCal30, VDDA_CALIB_MV},
18+
signature::{VrefCal, VtempCalHigh, VtempCalLow, VDDA_CALIB_MV},
1919
};
2020

2121
use pac::{ADC1, ADC_COMMON};
@@ -201,6 +201,7 @@ impl ADC {
201201
pub fn enable_temperature(&mut self, delay: &mut impl DelayUs<u32>) -> Temperature {
202202
self.common.ccr.modify(|_, w| w.ch17sel().set_bit());
203203

204+
// FIXME: This note from the reference manual is currently not possible
204205
// rm0351 section 18.4.32 pg580 (L47/L48/L49/L4A models)
205206
// Note:
206207
// The sensor has a startup time after waking from power-down mode before it can output VTS
@@ -278,12 +279,14 @@ impl ADC {
278279
/// Convert a raw sample from the `Temperature` to deg C
279280
pub fn to_degrees_centigrade(&self, sample: u16) -> f32 {
280281
let sample = (u32::from(sample) * self.calibrated_vdda) / VDDA_CALIB_MV;
281-
(VtempCal130::TEMP_DEGREES - VtempCal30::TEMP_DEGREES) as f32
282+
(VtempCalHigh::TEMP_DEGREES - VtempCalLow::TEMP_DEGREES) as f32
282283
// as signed because RM0351 doesn't specify against this being an
283284
// inverse relation (which would result in a negative differential)
284-
/ (VtempCal130::get().read() as i32 - VtempCal30::get().read() as i32) as f32
285+
/ (VtempCalHigh::get().read() as i32 - VtempCalLow::get().read() as i32) as f32
285286
// this can definitely be negative so must be done as a signed value
286-
* (sample as i32 - VtempCal30::get().read() as i32) as f32
287+
* (sample as i32 - VtempCalLow::get().read() as i32) as f32
288+
// while it would make sense for this to be `VtempCalLow::TEMP_DEGREES` (which is 30*C),
289+
// the RM specifically uses 30*C so this will too
287290
+ 30.0
288291
}
289292

src/signature.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ impl VrefCal {
9696
/// aka TS_CAL1 in reference manual
9797
#[derive(Debug)]
9898
#[repr(C)]
99-
pub struct VtempCal30(u16);
100-
define_ptr_type!(VtempCal30, 0x1FFF_75A8);
99+
pub struct VtempCalLow(u16);
100+
define_ptr_type!(VtempCalLow, 0x1FFF_75A8);
101101

102-
impl VtempCal30 {
102+
impl VtempCalLow {
103103
/// aka TS_CAL1_TEMP in reference manual
104104
pub const TEMP_DEGREES: u16 = 30;
105105
/// Read calibration value
@@ -112,13 +112,29 @@ impl VtempCal30 {
112112
/// aka TS_CAL2 in reference manual
113113
#[derive(Debug)]
114114
#[repr(C)]
115-
pub struct VtempCal130(u16);
116-
define_ptr_type!(VtempCal130, 0x1FFF_75CA);
115+
pub struct VtempCalHigh(u16);
116+
define_ptr_type!(VtempCalHigh, 0x1FFF_75CA);
117117

118-
impl VtempCal130 {
118+
impl VtempCalHigh {
119119
/// aka TS_CAL2_TEMP in reference manual
120120
/// Feature gate Required: this is 110 for L47x/L48x, 130 for other L4s according to
121121
/// https://github.com/STMicroelectronics/STM32CubeL4/blob/5e1553e07706491bd11f4edd304e093b6e4b83a4/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_ll_adc.h#L352-L356
122+
123+
// L47/L48
124+
#[cfg(any(
125+
feature = "stm32l471",
126+
feature = "stm32l475",
127+
feature = "stm32l476",
128+
feature = "stm32l486"
129+
))]
130+
pub const TEMP_DEGREES: u16 = 110;
131+
// else
132+
#[cfg(not(any(
133+
feature = "stm32l471",
134+
feature = "stm32l475",
135+
feature = "stm32l476",
136+
feature = "stm32l486"
137+
)))]
122138
pub const TEMP_DEGREES: u16 = 130;
123139
/// Read calibration value
124140
pub fn read(&self) -> u16 {

0 commit comments

Comments
 (0)