{"record":{"id":"3940309ee7e5808e","repo":"embassy-rs/embassy","slug":"could-not-find-swd-pin-to-cfg-gate","errorCode":null,"errorMessage":"Could not find SWD pin to cfg gate","messagePattern":"Could not find SWD pin to cfg gate","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-mspm0/build.rs","lineNumber":534,"sourceCode":"        let pin = singletons\n            .iter_mut()\n            .find(|s| s.name == pin.pin)\n            .expect(\"Could not find NRST pin to cfg gate\");\n\n        pin.cfg = Some(quote! { #[cfg(feature = \"nrst-pin-as-gpio\")] });\n    }\n\n    let debugss = METADATA\n        .peripherals\n        .iter()\n        .find(|p| p.name == \"DEBUGSS\")\n        .expect(\"Could not find DEBUGSS peripheral\");\n\n    for pin in debugss.pins.iter() {\n        let pin = singletons\n            .iter_mut()\n            .find(|s| s.name == pin.pin)\n            .expect(\"Could not find SWD pin to cfg gate\");\n\n        pin.cfg = Some(quote! { #[cfg(feature = \"swd-pins-as-gpio\")] });\n    }\n}\n\nfn generate_singletons(singletons: &[Singleton]) -> TokenStream {\n    let singletons_peripherals_struct = singletons\n        .iter()\n        .map(|s| {\n            let cfg = s.cfg.clone().unwrap_or_default();\n\n            let ident = format_ident!(\"{}\", s.name);\n\n            quote! {\n                #cfg\n                #ident\n            }\n        })","sourceCodeStart":516,"sourceCodeEnd":552,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-mspm0/build.rs#L516-L552","documentation":"For each pin exposed by DEBUGSS, the build script searches the singletons for the corresponding GPIO and panics if the SWD pin cannot be matched to a generated singleton. This is an internal consistency check between the DEBUGSS pin list and the GPIO singletons of the package.","triggerScenarios":"Building embassy-mspm0 when DEBUGSS.pins references a pin (e.g. PA19/PA20 for SWDIO/SWCLK) whose name does not match any entry in the generated singletons vector, inside generate_code -> pin_features.","commonSituations":"Pin-name mismatch between the DEBUGSS metadata and GPIO singleton naming (wrong pin number/letter case); a package variant where the SWD pad is named differently; edited metadata introducing a typo.","solutions":["Verify the pin names in DEBUGSS.pins exactly match the GPIO singleton names generated for the package.","Fix the chip metadata (SWCLK/SWDIO pin assignments) and rebuild.","Regenerate metadata from vendor sources to restore consistent pin naming."],"exampleFix":"// before (metadata)\n- { signal: SWDIO, pin: PA18 }  // no PA18 singleton\n// after\n- { signal: SWDIO, pin: PA19 }  // matches generated PA19 singleton","handlingStrategy":"validation","validationCode":"for pin in &debugss.pins {\n    assert!(singletons.iter().any(|s| s.name == pin.pin), \"DEBUGSS pin {} missing singleton\", pin.pin);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify SWCLK/SWDIO pin numbers against the datasheet for each package variant.","Keep one naming convention (PAxx) across all metadata pin references.","Add a metadata consistency test comparing DEBUGSS pins to GPIO singletons."],"tags":["build-script","embedded","gpio","panic","rust"],"backgroundTag":"resource-not-found","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"}