{"record":{"id":"4a007f22a1689429","repo":"embassy-rs/embassy","slug":"unsupported-ep0-size","errorCode":null,"errorMessage":"Unsupported EP0 size: {}","messagePattern":"Unsupported EP0 size: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-usb-synopsys-otg/src/lib.rs","lineNumber":1998,"sourceCode":"\n/// Translates HAL [EndpointType] into PAC [vals::Eptyp]\nfn to_eptyp(ep_type: EndpointType) -> vals::Eptyp {\n    match ep_type {\n        EndpointType::Control => vals::Eptyp::CONTROL,\n        EndpointType::Isochronous => vals::Eptyp::ISOCHRONOUS,\n        EndpointType::Bulk => vals::Eptyp::BULK,\n        EndpointType::Interrupt => vals::Eptyp::INTERRUPT,\n    }\n}\n\n/// Calculates MPSIZ value for EP0, which uses special values.\nfn ep0_mpsiz(max_packet_size: u16) -> u16 {\n    match max_packet_size {\n        8 => 0b11,\n        16 => 0b10,\n        32 => 0b01,\n        64 => 0b00,\n        other => panic!(\"Unsupported EP0 size: {}\", other),\n    }\n}\n\n/// Hardware-dependent USB IP configuration.\n#[derive(Copy, Clone)]\npub struct OtgInstance<'d, M = CriticalSectionRawMutex>\nwhere\n    M: RawMutex + Copy,\n{\n    /// The USB peripheral.\n    pub regs: Otg,\n    /// Shared driver/interrupt state from [`State::as_state`].\n    pub state: State<'d, M>,\n    /// FIFO depth in words.\n    pub fifo_depth_words: u16,\n    /// The PHY type.\n    pub phy_type: PhyType,\n    /// Extra RX FIFO words needed by some implementations.","sourceCodeStart":1980,"sourceCodeEnd":2016,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-usb-synopsys-otg/src/lib.rs#L1980-L2016","documentation":"The Synopsys OTG USB driver encodes the EP0 (control endpoint) max packet size into the MPSIZ field, which hardware supports only for sizes 8, 16, 32, or 64. ep0_mpsiz panics on any other value rather than programming an invalid hardware register.","triggerScenarios":"Setting UsbConfig::max_packet_size_0 (or the value reaching ep0_mpsiz) to something other than 8/16/32/64 — e.g. 0, 128, or a packet size intended for a bulk endpoint.","commonSituations":"Copying a max_packet_size from a bulk/interrupt endpoint config into max_packet_size_0; typos like 512; constructing config programmatically with computed values.","solutions":["Set max_packet_size_0 to 64 (the standard control-endpoint size for full/high speed).","Use only 8, 16, 32, or 64 for EP0.","Add a compile-time constant for the control EP size so it cannot drift with endpoint-specific values."],"exampleFix":"// before\nlet config = Config { max_packet_size_0: 128, .. };\n// after\nlet config = Config { max_packet_size_0: 64, .. };","handlingStrategy":"validation","validationCode":"fn valid_ep0_size(n: u16) -> bool { matches!(n, 8 | 16 | 32 | 64) }\nassert!(valid_ep0_size(config.max_packet_size_0), \"EP0 size must be 8/16/32/64\");","typeGuard":"fn valid_ep0_size(n: u16) -> bool { matches!(n, 8 | 16 | 32 | 64) }","tryCatchPattern":null,"preventionTips":["Hardcode max_packet_size_0 to 64","Keep EP0 size constant and separate from endpoint sizes","Validate config structs before passing to the driver"],"tags":["embedded","usb","config","panic"],"backgroundTag":"invalid-config-value","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"}