Skip to content

Commit 4ef6ee7

Browse files
committed
adc: determine ADC lines based on hardware generation
The ADC channels 0 and 1 on the STM32MP1 are a bit special, in that they are not muxable as GPIOs but connected directly to the ADC peripheral. This has cause us a bit of trouble in the past, because these pins seem to leak current (like all other channels did until the transition into ADC standby was fixed by unmuxing the ADC pins beforehand). We could once again try to fix the issue with these pins, but that could also turn out to be impossible to do (since the pins can not be muxed away). This is why we have instead decided to just not use these pins on generation 3 (and likely later) hardware and use other pins instead. This means we have to detect which ADC pins we should use based on if we are running on Gen 1 / Gen 2 or Gen 3. Signed-off-by: Leonard Göhrs <[email protected]>
1 parent 3c0d187 commit 4ef6ee7

File tree

9 files changed

+70
-13
lines changed

9 files changed

+70
-13
lines changed

src/adc.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use async_std::task::sleep;
2323

2424
use crate::broker::{BrokerBuilder, Topic};
2525
use crate::measurement::{Measurement, Timestamp};
26+
use crate::system::HardwareGeneration;
2627
use crate::watched_tasks::WatchedTasksBuilder;
2728

2829
const HISTORY_LENGTH: usize = 200;
@@ -78,8 +79,12 @@ pub struct Adc {
7879
}
7980

8081
impl Adc {
81-
pub async fn new(bb: &mut BrokerBuilder, wtb: &mut WatchedTasksBuilder) -> Result<Self> {
82-
let stm32_thread = IioThread::new_stm32(wtb).await?;
82+
pub async fn new(
83+
bb: &mut BrokerBuilder,
84+
wtb: &mut WatchedTasksBuilder,
85+
hardware_generation: HardwareGeneration,
86+
) -> Result<Self> {
87+
let stm32_thread = IioThread::new_stm32(wtb, hardware_generation).await?;
8388
let powerboard_thread = IioThread::new_powerboard(wtb).await?;
8489

8590
let adc = Self {

src/adc/iio/demo_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub struct IioThread {
160160
}
161161

162162
impl IioThread {
163-
pub async fn new_stm32<W>(_wtb: &W) -> Result<Arc<Self>> {
163+
pub async fn new_stm32<W, G>(_wtb: &W, _hardware_generation: G) -> Result<Arc<Self>> {
164164
let mut demo_magic = block_on(DEMO_MAGIC_STM32.lock());
165165

166166
// Only ever set up a single demo_mode "IioThread" per ADC

src/adc/iio/hardware.rs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use log::{debug, error, warn};
3232
use thread_priority::*;
3333

3434
use crate::measurement::{Measurement, Timestamp};
35+
use crate::system::HardwareGeneration;
3536
use crate::watched_tasks::WatchedTasksBuilder;
3637

3738
struct ChannelDesc {
@@ -43,7 +44,7 @@ struct ChannelDesc {
4344
// Hard coded list of channels using the internal STM32MP1 ADC.
4445
// Consists of the IIO channel name, the location of the calibration data
4546
// in the device tree and an internal name for the channel.
46-
const CHANNELS_STM32: &[ChannelDesc] = &[
47+
const CHANNELS_STM32_GEN1_GEN2: &[ChannelDesc] = &[
4748
ChannelDesc {
4849
kernel_name: "voltage13",
4950
calibration_path: "baseboard-factory-data/usb-host-curr",
@@ -86,6 +87,49 @@ const CHANNELS_STM32: &[ChannelDesc] = &[
8687
},
8788
];
8889

90+
const CHANNELS_STM32_GEN3: &[ChannelDesc] = &[
91+
ChannelDesc {
92+
kernel_name: "voltage13",
93+
calibration_path: "baseboard-factory-data/usb-host-curr",
94+
name: "usb-host-curr",
95+
},
96+
ChannelDesc {
97+
kernel_name: "voltage15",
98+
calibration_path: "baseboard-factory-data/usb-host1-curr",
99+
name: "usb-host1-curr",
100+
},
101+
ChannelDesc {
102+
kernel_name: "voltage18",
103+
calibration_path: "baseboard-factory-data/usb-host2-curr",
104+
name: "usb-host2-curr",
105+
},
106+
ChannelDesc {
107+
kernel_name: "voltage14",
108+
calibration_path: "baseboard-factory-data/usb-host3-curr",
109+
name: "usb-host3-curr",
110+
},
111+
ChannelDesc {
112+
kernel_name: "voltage2",
113+
calibration_path: "baseboard-factory-data/out0-volt",
114+
name: "out0-volt",
115+
},
116+
ChannelDesc {
117+
kernel_name: "voltage10",
118+
calibration_path: "baseboard-factory-data/out1-volt",
119+
name: "out1-volt",
120+
},
121+
ChannelDesc {
122+
kernel_name: "voltage5",
123+
calibration_path: "baseboard-factory-data/iobus-curr",
124+
name: "iobus-curr",
125+
},
126+
ChannelDesc {
127+
kernel_name: "voltage9",
128+
calibration_path: "baseboard-factory-data/iobus-volt",
129+
name: "iobus-volt",
130+
},
131+
];
132+
89133
// The same as for the STM32MP1 channels but for the discrete ADC on the power
90134
// board.
91135
const CHANNELS_PWR: &[ChannelDesc] = &[
@@ -431,14 +475,22 @@ impl IioThread {
431475
Ok(thread)
432476
}
433477

434-
pub async fn new_stm32(wtb: &mut WatchedTasksBuilder) -> Result<Arc<Self>> {
478+
pub async fn new_stm32(
479+
wtb: &mut WatchedTasksBuilder,
480+
hardware_generation: HardwareGeneration,
481+
) -> Result<Arc<Self>> {
482+
let channels = match hardware_generation {
483+
HardwareGeneration::Gen1 | HardwareGeneration::Gen2 => CHANNELS_STM32_GEN1_GEN2,
484+
HardwareGeneration::Gen3 => CHANNELS_STM32_GEN3,
485+
};
486+
435487
Self::new(
436488
wtb,
437489
"adc-stm32",
438490
"48003000.adc:adc@0",
439491
"tim4_trgo",
440492
80,
441-
CHANNELS_STM32,
493+
channels,
442494
4,
443495
)
444496
.await

src/adc/iio/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub struct IioThread {
107107
}
108108

109109
impl IioThread {
110-
pub async fn new_stm32<W>(_wtb: &W) -> Result<Arc<Self>> {
110+
pub async fn new_stm32<W, G>(_wtb: &W, _hardware_generation: G) -> Result<Arc<Self>> {
111111
let mut channels = Vec::new();
112112

113113
for name in CHANNELS_STM32 {

src/digital_io/gpio/demo_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl LineHandle {
3232
// It is just a hack to let adc/iio/demo_mode.rs
3333
// communicate with this function so that toggling an output
3434
// has an effect on the measured values.
35-
let iio_thread_stm32 = block_on(IioThread::new_stm32(&())).unwrap();
35+
let iio_thread_stm32 = block_on(IioThread::new_stm32(&(), ())).unwrap();
3636
let iio_thread_pwr = block_on(IioThread::new_powerboard(&())).unwrap();
3737

3838
match self.name.as_str() {

src/dut_power.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ mod tests {
631631

632632
let (adc, dut_pwr, led) = {
633633
let mut bb = BrokerBuilder::new();
634-
let adc = block_on(Adc::new(&mut bb, &mut wtb)).unwrap();
634+
let adc = block_on(Adc::new(&mut bb, &mut wtb, hardware_generation)).unwrap();
635635
let led = Topic::anonymous(None);
636636

637637
let dut_pwr = block_on(DutPwrThread::new(
@@ -792,7 +792,7 @@ mod tests {
792792

793793
let (adc, dut_pwr) = {
794794
let mut bb = BrokerBuilder::new();
795-
let adc = block_on(Adc::new(&mut bb, &mut wtb)).unwrap();
795+
let adc = block_on(Adc::new(&mut bb, &mut wtb, hardware_generation)).unwrap();
796796
let led = Topic::anonymous(None);
797797

798798
let dut_pwr = block_on(DutPwrThread::new(

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async fn init(screenshooter: ScreenShooter) -> Result<(Ui, WatchedTasksBuilder)>
7575
// Expose hardware on the TAC via the broker framework.
7676
let backlight = Backlight::new(&mut bb, &mut wtb)?;
7777
let led = Led::new(&mut bb, &mut wtb)?;
78-
let adc = Adc::new(&mut bb, &mut wtb).await?;
78+
let adc = Adc::new(&mut bb, &mut wtb, hardware_generation).await?;
7979
let dut_pwr = DutPwrThread::new(
8080
&mut bb,
8181
&mut wtb,

src/regulators.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod reg {
3232

3333
pub fn regulator_set(name: &str, state: bool) -> Result<()> {
3434
if name == "output_iobus_12v" {
35-
let iio_thread = block_on(IioThread::new_stm32(&())).unwrap();
35+
let iio_thread = block_on(IioThread::new_stm32(&(), ())).unwrap();
3636

3737
iio_thread
3838
.clone()

src/usb_hub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ mod rw {
9494

9595
for (path_tail, iio_channel) in DISABLE_CHANNELS {
9696
if path.ends_with(path_tail) {
97-
let iio_thread = block_on(IioThread::new_stm32(&())).unwrap();
97+
let iio_thread = block_on(IioThread::new_stm32(&(), ())).unwrap();
9898

9999
iio_thread
100100
.get_channel(iio_channel)

0 commit comments

Comments
 (0)