{"record":{"id":"bfa4149e61d5449e","repo":"embassy-rs/embassy","slug":"implementation-is-limited-to-unique-sample-time","errorCode":null,"errorMessage":"Implementation is limited to {} unique sample times among all channels.","messagePattern":"Implementation is limited to (.+?) unique sample times among all channels\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/adc/v3.rs","lineNumber":324,"sourceCode":"            let mut last_channel: u8 = 0;\n\n            self.chselr_1().write(|w| {\n                for (i, ((channel, _), sample_time)) in sequence.enumerate() {\n                    // Determine if we can use sequencer\n                    needs_hw = needs_hw || channel > CHSELR_SQ_MAX_CHANNEL;\n                    is_ordered_up = is_ordered_up && (channel > last_channel || i == 0);\n                    is_ordered_down = is_ordered_down && (channel < last_channel || i == 0);\n                    hw_channel_selection |= 1 << channel;\n                    last_channel = channel;\n\n                    // Assign & check sample times\n                    self.smpr().write(|smpr| {\n                        if let Some(j) = sample_times.iter().position(|&t| t == sample_time) {\n                            smpr.set_smpsel(channel.into(), (j as u8).into());\n                        } else {\n                            smpr.set_sample_time(sample_times.len(), sample_time);\n                            if let Err(_) = sample_times.push(sample_time) {\n                                panic!(\n                                    \"Implementation is limited to {} unique sample times among all channels.\",\n                                    SAMPLE_TIMES_CAPACITY\n                                );\n                            }\n                        }\n                    });\n\n                    // Prepare sequencer\n                    if !needs_hw {\n                        w.set_sq(i, channel.into());\n                    }\n                }\n\n                // Terminate sequence\n                for i in sequence_len..CHSELR_SQ_SIZE {\n                    w.set_sq(i, Sq::Eos);\n                }\n            });","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/adc/v3.rs#L306-L342","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlet pts = [SampleTime::Cycles1_5, SampleTime::Cycles7_5, SampleTime::Cycles13_5, SampleTime::Cycles28_5, ...]; // > capacity distinct values\n// after\nlet pts = [SampleTime::Cycles239_5; N]; // single shared sample time","handlingStrategy":"validation","validationCode":"let unique: std::collections::HashSet<_> = sample_times.iter().collect();\nassert!(unique.len() <= SAMPLE_TIMES_CAPACITY, \"too many distinct ADC sample times\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["embedded","stm32","adc","rust"],"backgroundTag":"value-out-of-range","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}