{"record":{"id":"a52791027c7ccbe6","repo":"embassy-rs/embassy","slug":"invalid-channel-for-pwm-input","errorCode":null,"errorMessage":"Invalid channel for PWM input","messagePattern":"Invalid channel for PWM input","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/timer/pwm_input.rs","lineNumber":74,"sourceCode":"        inner.set_counting_mode(CountingMode::EdgeAlignedUp);\n        inner.set_tick_freq(freq);\n        inner.enable_outputs(); // Required for advanced timers, see GeneralInstance4Channel for details\n        inner.generate_update_event();\n        inner.start();\n\n        // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.6\n        // or ST RM0008 (STM32F103) chapter 15.3.6 Input capture mode\n        // or ST RM0440 (STM32G4) chapter 30.4.8 PWM input mode\n        inner.set_input_capture_selection(ch1, InputCaptureSelection::Normal);\n        inner.set_input_capture_mode(ch1, InputCaptureMode::Rising);\n\n        inner.set_input_capture_selection(ch2, InputCaptureSelection::Alternate);\n        inner.set_input_capture_mode(ch2, InputCaptureMode::Falling);\n\n        inner.set_trigger_source(match ch1 {\n            Channel::Ch1 => TriggerSource::Ti1fp1,\n            Channel::Ch2 => TriggerSource::Ti2fp2,\n            _ => panic!(\"Invalid channel for PWM input\"),\n        });\n\n        inner.set_slave_mode(SlaveMode::ResetMode);\n\n        // Must call the `enable` function after\n\n        // enable NVIC interrupt\n        T::CaptureCompareInterrupt::unpend();\n        unsafe { T::CaptureCompareInterrupt::enable() };\n\n        Self {\n            channel: ch1,\n            inner,\n            _wake_guard: T::RCC_INFO.wake_guard(),\n        }\n    }\n\n    /// Enable the given channel.","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/timer/pwm_input.rs#L56-L92","documentation":"PWM input capture requires the trigger to come from TI1FP1 or TI2FP2, which only exist for Channel::Ch1 and Channel::Ch2. new_inner panics if the configured channel is Ch3/Ch4, since those channels cannot serve as the PWM-input trigger source.","triggerScenarios":"Constructing a PwmInput with channel Ch3 or Ch4 passed to new / new_inner on a timer where only ch1/ch2 are valid trigger inputs.","commonSituations":"Wiring the input pin to CH3/CH4 and passing that channel to PwmInput::new; assuming any input-capture channel works for PWM-input mode.","solutions":["Use Channel::Ch1 or Channel::Ch2 (i.e. a pin mapped to TIMx_CH1 or TIMx_CH2) for the PWM input.","Remap your signal to a pin on CH1/CH2 of the timer, or pick a timer whose CH1/CH2 pins are reachable on your board."],"exampleFix":"// before\nlet mut pwm_input = PwmInput::new(p.TIM3, p.PB0, Channel::Ch3, config);\n// after (PB0 is TIM3_CH3; use a CH1/CH2 pin, e.g. PA6 = TIM3_CH1)\nlet mut pwm_input = PwmInput::new(p.TIM3, p.PA6, Channel::Ch1, config);","handlingStrategy":"validation","validationCode":"fn pwm_input_channel_ok(ch: Channel) -> bool { matches!(ch, Channel::Ch1 | Channel::Ch2) }","typeGuard":"fn is_ch1_or_ch2(ch: Channel) -> bool { matches!(ch, Channel::Ch1 | Channel::Ch2) }","tryCatchPattern":null,"preventionTips":["Always wire PWM-input capture to TIMx_CH1 or TIMx_CH2 pins.","Verify the pin-to-channel mapping (e.g. via embassy-stm32's peripheral signals table) before calling PwmInput::new.","Reserve Ch3/Ch4 channels for output-compare or plain input capture, not PWM-input mode."],"tags":["timer","pwm-input","embedded","panic"],"backgroundTag":"invalid-argument-value","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}