diff --git a/src/components/DeviceFlasher.tsx b/src/components/DeviceFlasher.tsx index 5dbb0d2..e1c9956 100644 --- a/src/components/DeviceFlasher.tsx +++ b/src/components/DeviceFlasher.tsx @@ -16,10 +16,12 @@ import { toast } from "sonner" import { buildFlashParts } from "../lib/espFlashLayout" import { ensureSerialPortClosed, + ESP_FLASH_BAUD_OPTIONS, ESP_FLASH_WEB_BAUD, isSerialUserCancelledError, pulseUsbBootloaderOnPort, runEspFlash, + type EspFlashBaud, type FlashPhase, } from "../lib/espFlashRun" import { inferTargetFamilyFromBundle, inferTargetFamilyFromEnv } from "../lib/flashTargetFamily" @@ -84,6 +86,7 @@ export default function DeviceFlasher({ const [busy, setBusy] = useState(false) const shareDialogRef = useRef(null) const [eraseFlashForFactory, setEraseFlashForFactory] = useState(false) + const [flashBaud, setFlashBaud] = useState(ESP_FLASH_WEB_BAUD) const [bundleFamily, setBundleFamily] = useState(inferTargetFamilyFromEnv(targetEnv) ?? "esp32") const [bundleCanErase, setBundleCanErase] = useState(false) const [flashProgress, setFlashProgress] = useState(null) @@ -175,7 +178,7 @@ export default function DeviceFlasher({ await runEspFlash({ port, parts: plan.parts, - baud: ESP_FLASH_WEB_BAUD, + baud: flashBaud, eraseAll: eraseFlashForFactory || plan.eraseAll, onPhase: phase => { setFlashProgress({ kind: "indeterminate", label: PHASE_LABEL[phase] }) @@ -212,7 +215,7 @@ export default function DeviceFlasher({ setFlashProgress(null) } } - }, [eraseFlashForFactory, prepareBundle, canEspFlash, flashBlockedReason, resolvedFamily]) + }, [eraseFlashForFactory, flashBaud, prepareBundle, canEspFlash, flashBlockedReason, resolvedFamily]) const shareUrlTrimmed = useMemo(() => sharePageUrl?.trim() ?? "", [sharePageUrl]) const canNativeShare = typeof navigator !== "undefined" && typeof navigator.share === "function" @@ -299,6 +302,25 @@ export default function DeviceFlasher({ Full device reset + + {resolvedFamily === "esp32" ? ( + + ) : null} {!canFullReset ? ( diff --git a/src/lib/espFlashRun.ts b/src/lib/espFlashRun.ts index 51ebb92..edc08da 100644 --- a/src/lib/espFlashRun.ts +++ b/src/lib/espFlashRun.ts @@ -195,8 +195,12 @@ export async function runEspFlash(options: { await transport.disconnect() } -/** Conservative default for `runEspFlash` over Web Serial (fewer cable/hub issues than 921600). */ -export const ESP_FLASH_WEB_BAUD = 115200 +/** Supported Web Serial baud rates for ESP flashing. First entry is the default. */ +export const ESP_FLASH_BAUD_OPTIONS = [921600, 460800, 230400, 115200] as const +export type EspFlashBaud = (typeof ESP_FLASH_BAUD_OPTIONS)[number] + +/** Default baud for `runEspFlash` over Web Serial. Matches PlatformIO; lower if cables/hubs are flaky. */ +export const ESP_FLASH_WEB_BAUD: EspFlashBaud = ESP_FLASH_BAUD_OPTIONS[0] /** Match MeshCore `lib/dfu.js` CDC touch timing (1200 baud → close → wait for re-enumeration). */ const CDC_TOUCH_OPEN_MS = 100