embassy-rs/embassy · error
Implementation is limited to
Error message
Implementation is limited to {} unique sample times among all channels. What it means
The v3 (F3/G0-style) ADC implementation caches at most SAMPLE_TIMES_CAPACITY distinct sample-time values because each SMPR register can hold a limited table of unique sample times (SMPSEL indirection). If a sequence introduces more distinct sample times than the capacity, the driver panics — this is a limitation of the driver's modeling, not of the hardware itself.
Solutions
- Reduce the number of distinct SampleTime values — use one common sample time for all channels in the sequence
- Split the sequence into multiple configure_sequence calls grouped by sample time
- Adjust channel sampling needs so channels share sample times where accuracy permits
Example fix
// before let pts = [SampleTime::Cycles1_5, SampleTime::Cycles7_5, SampleTime::Cycles13_5, SampleTime::Cycles28_5, ...]; // > capacity distinct values // after let pts = [SampleTime::Cycles239_5; N]; // single shared sample time
Defensive patterns
Strategy: validation
Validate before calling
let unique: std::collections::HashSet<_> = sample_times.iter().collect(); assert!(unique.len() <= SAMPLE_TIMES_CAPACITY, "too many distinct ADC sample times");
Prevention
- Use a single SampleTime for all channels in a sequence unless accuracy demands otherwise
- Group channels by sample time into separate sequences
- Check SAMPLE_TIMES_CAPACITY in adc/v3.rs before designing long mixed sequences
- Review sample times when porting examples from other families
When it happens
Trigger: Calling `configure_sequence` (e.g. via `sample_sequence`) with channels whose requested SampleTime values span more unique values than SAMPLE_TIMES_CAPACITY across all channels in one sequence.
Common situations: Configuring a long sequence where each channel got a slightly different sample time copy-pasted from examples; mixing 1.5/7.5/239.5-cycle times across many channels; upgrading embassy and hitting a newly added capacity limit.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Maximal allowed frequency for ADC4 is
- Maximal allowed frequency for the ADC is
- Maximal allowed frequency for the ADC is
- Invalid channel to sample
- Selected PCLK2 frequency is too high for ADC with largest…
AI-assisted analysis of embassy-rs/embassy@463a07b963 (2026-09-10).
Data as JSON: /api/errors/bfa4149e61d5449e.
Report an issue: GitHub.
Appendix: source
Thrown at embassy-stm32/src/adc/v3.rs:324
let mut last_channel: u8 = 0;
self.chselr_1().write(|w| {
for (i, ((channel, _), sample_time)) in sequence.enumerate() {
// Determine if we can use sequencer
needs_hw = needs_hw || channel > CHSELR_SQ_MAX_CHANNEL;
is_ordered_up = is_ordered_up && (channel > last_channel || i == 0);
is_ordered_down = is_ordered_down && (channel < last_channel || i == 0);
hw_channel_selection |= 1 << channel;
last_channel = channel;
// Assign & check sample times
self.smpr().write(|smpr| {
if let Some(j) = sample_times.iter().position(|&t| t == sample_time) {
smpr.set_smpsel(channel.into(), (j as u8).into());
} else {
smpr.set_sample_time(sample_times.len(), sample_time);
if let Err(_) = sample_times.push(sample_time) {
panic!(
"Implementation is limited to {} unique sample times among all channels.",
SAMPLE_TIMES_CAPACITY
);
}
}
});
// Prepare sequencer
if !needs_hw {
w.set_sq(i, channel.into());
}
}
// Terminate sequence
for i in sequence_len..CHSELR_SQ_SIZE {
w.set_sq(i, Sq::Eos);
}
});View on GitHub (pinned to 463a07b963)