{"record":{"id":"79f9873a855e44a1","repo":"embassy-rs/embassy","slug":"invalid-max-packet-size-0-the-allowed-values-are","errorCode":null,"errorMessage":"invalid max_packet_size_0, the allowed values are 8, 16, 32 or 64","messagePattern":"invalid max_packet_size_0, the allowed values are 8, 16, 32 or 64","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-usb/src/builder.rs","lineNumber":209,"sourceCode":"        control_buf: &'d mut [u8],\n    ) -> Self {\n        // Magic values specified in USB-IF ECN on IADs.\n        if config.composite_with_iads\n            && (config.device_class != 0xEF || config.device_sub_class != 0x02 || config.device_protocol != 0x01)\n        {\n            panic!(\n                \"if composite_with_iads is set, you must set device_class = 0xEF, device_sub_class = 0x02, device_protocol = 0x01\"\n            );\n        }\n\n        assert!(\n            config.max_power <= 500,\n            \"The maximum allowed value for `max_power` is 500mA\"\n        );\n\n        match config.max_packet_size_0 {\n            8 | 16 | 32 | 64 => {}\n            _ => panic!(\"invalid max_packet_size_0, the allowed values are 8, 16, 32 or 64\"),\n        }\n\n        let mut config_descriptor = DescriptorWriter::new(config_descriptor_buf);\n        let mut bos_descriptor = BosWriter::new(DescriptorWriter::new(bos_descriptor_buf));\n\n        config_descriptor.configuration(&config);\n        bos_descriptor.bos();\n\n        Builder {\n            driver,\n            config,\n            interfaces: Vec::new(),\n            handlers: Vec::new(),\n            control_buf,\n            next_string_index: STRING_INDEX_CUSTOM_START,\n\n            config_descriptor,\n            bos_descriptor,","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-usb/src/builder.rs#L191-L227","documentation":"Builder::new validates that UsbConfig::max_packet_size_0 is one of the USB-legal control endpoint sizes 8, 16, 32, or 64 and panics otherwise. EP0's max packet size goes straight into the device descriptor bMaxPacketSize0, which only permits these values.","triggerScenarios":"Constructing a UsbDevice with max_packet_size_0 set to any value other than 8/16/32/64 (0, 128, 512, or a bulk-endpoint size).","commonSituations":"Reusing an endpoint's max_packet_size for EP0; computing sizes for high-speed and copying them into EP0; default-then-overwrite patterns that leave an invalid value.","solutions":["Set max_packet_size_0: 64 (standard for full/high-speed devices).","Restrict the value to 8/16/32/64 before constructing the Builder.","Define the control EP size as a const so it is validated at compile time."],"exampleFix":"// before\nlet config = Config { max_packet_size_0: ep_size, .. }; // ep_size = 512\n// after\nlet config = Config { max_packet_size_0: 64, .. };","handlingStrategy":"validation","validationCode":"fn valid_max_packet_size_0(n: u16) -> bool { matches!(n, 8 | 16 | 32 | 64) }\nassert!(valid_max_packet_size_0(config.max_packet_size_0));","typeGuard":"fn valid_max_packet_size_0(n: u16) -> bool { matches!(n, 8 | 16 | 32 | 64) }","tryCatchPattern":null,"preventionTips":["Default to 64 for EP0","Never copy endpoint max_packet_size values into max_packet_size_0","Add a unit test that builds your Config"],"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"}