esptool-js
esptool-js copied to clipboard
Connect ESP32-S2 built-in USB_CDC Error: Timeout
esptool.js v0.1-dev Serial port WebSerial VendorID 0x303a ProductID 0x2 Connecting.........._ Detecting chip type... ESP32-S2 Chip is ESP32-S2 Features: Wi-Fi Crystal is 40MHz MAC: 68:67:25:2d:f4:0c Uploading stub... Error: Timeout
When try to do it again:
esptool.js v0.1-dev
Serial port WebSerial VendorID 0x303a ProductID 0x2
Connecting....Error: Failed to set control signals.
I am having this same issue with my board!
Is there anything I am doing wrong?
I am facing exactly the same error, is there an update on this? In my case, it decides to randomly work one in 10 times.
Same here. Any stub or baud rate eventually times-out sometime during flash_write. This is my first time using this, and frankly the JS/TS docs are a little vague. I've also tried in both production and dev webpack environments, with the same error.
Same, Is there anything I'm doing wrong?
Example Invoking Update Function:
export const updateDFUDeviceTest = async (
devType = DFUDeviceTypes.TESTDevice,
erase = false,
newFirmware?: File,
offset?: number
) => {
console.log("Updating Device FW!");
// const romBaudRate = 115200;
//Attempt to get the most recent firmware
if (devType.getUpdatedFirmware) {
const updates = await devType.getUpdatedFirmware();
devType = { ...devType, ...updates };
if (devType.firmwareFile)
console.log(`Updated Firmware is ${devType.firmwareFile.name}`);
}
try {
// Look for devices in DFU mode
const port = await navigator.serial.requestPort({
filters: webSerialDFUDeviceFilters,
});
if (!port) throw new Error("No DFU Device");
const loader = new ESPLoader(
new Transport(port),
devType.programBaud,
undefined,
devType.romBaud
);
loader.MAX_TIMEOUT = 2000;
await loader.connect(devType.connectResetMode, 10, false);
// Get the Chip's STA MAC ADDRESS (SERIAL NUMBER)
const name = loader.chip.CHIP_NAME;
const sizes = Object.keys(loader.chip.FLASH_SIZES).join(",");
console.log(`Connected to ${name} with Flash Sizes: ${sizes}`);
const desc = await loader.chip.get_chip_description(loader);
if (desc !== "ESP32-S2FH32") throw new Error("Not a Synergy ESP32-S2");
console.log(`Devie Description matches Synergy: ${desc}`);
const freq = await loader.chip.get_crystal_freq(loader);
console.log(`CPU Cryastal Freq: ${freq}Mhz`);
const features = (await loader.chip.get_chip_features(loader)).join(",");
console.log(`Chip Features: ${features}`);
const mac = await loader.chip.read_mac(loader);
console.log(`Chip STA MAC Address (USB S/N): ${mac}`);
// Load default bin files into our command
const flashSections = [] as { address: number; data: string }[];
if (devType.bootloaderFile) {
const bBA = await devType.bootloaderFile.arrayBuffer();
const bBytesString = new TextDecoder().decode(bBA);
console.log(
`Using Bootloader Image ${devType.bootloaderFile.name} at 0x${
devType.bootloaderOffset?.toString(16) || 0
}`
);
flashSections.push({
address: devType.bootloaderOffset || 0x1000,
data: bBytesString,
});
}
if (devType.partitionsMapFile) {
const pBA = await devType.partitionsMapFile.arrayBuffer();
const pBytesString = new TextDecoder().decode(pBA);
console.log(
`Using Partition Table Image ${devType.partitionsMapFile.name} at 0x${
devType.partitionsMapOffset?.toString(16) || 0
}`
);
flashSections.push({
address: devType.partitionsMapOffset || 0x8000,
data: pBytesString,
});
}
if (devType.uf2AppFile) {
const uBA = await devType.uf2AppFile.arrayBuffer();
const uBytesString = new TextDecoder().decode(uBA);
console.log(
`Using UF2 Update App Image ${devType.uf2AppFile.name} at 0x${
devType.uf2AppOffset?.toString(16) || 0
}`
);
flashSections.push({
address: devType.uf2AppOffset || 0x2d000,
data: uBytesString,
});
}
// Override firmware file with argument if needed
if (newFirmware) {
const byteArray = await newFirmware.arrayBuffer();
const bytesString = new TextDecoder().decode(byteArray);
console.log(
`Overriding Firmware With New Image ${newFirmware.name} at 0x${
offset?.toString(16) || 0x10000
}`
);
flashSections.push({
address: offset || 0x10000,
data: bytesString,
});
} else if (devType.firmwareFile && !newFirmware) {
// Just use the default file firmware for the device
const fwBA = await devType.firmwareFile.arrayBuffer();
const fwBytesString = new TextDecoder().decode(fwBA);
console.log(
`Using Firmware Image ${devType.firmwareFile.name} at 0x${
devType.firmwareOffset?.toString(16) || 0
}`
);
flashSections.push({
address: devType.firmwareOffset || 0x10000,
data: fwBytesString,
});
}
if (flashSections.length == 0) {
throw new Error("No files to flash!");
}
await sleep(100);
await loader.write_flash(
flashSections,
devType.flashSize,
devType.flashMode,
devType.flashFreq,
erase
);
} catch (e) {
if (e instanceof Error) {
console.warn(`Error: ${e.message}`);
}
}
};
Consistently produces the result:
Downloading FW from /fw/synergy/synergy_fw_0_95_64.bin
VM76369 SynergyV0.ts:35 Downloading Bootloader from /fw/synergy/synergy-bootloader-tinyuf2.bin
VM76369 SynergyV0.ts:42 Downloading Partition Table from /fw/synergy/synergy-partitions.bin
VM76369 SynergyV0.ts:49 Downloading UF2 Updater App from /fw/synergy/synergy-tinyuf2-updater.bin
VM76362 DeviceSerialUpdate.ts:128 Updated Firmware is synergy_fw_0_95_64.bin
esploader.js:129 esptool.js
esploader.js:129 Serial port WebSerial VendorID 0x303a ProductID 0x2
esploader.js:129 Connecting...
2esploader.js:129 .
esploader.js:129
VM76362 DeviceSerialUpdate.ts:142 Connected to ESP32-S2 with Flash Sizes: 1MB,2MB,4MB,8MB,16MB
VM76362 DeviceSerialUpdate.ts:145 Devie Description matches Synergy: ESP32-S2FH32
VM76362 DeviceSerialUpdate.ts:147 CPU Cryastal Freq: 40Mhz
VM76362 DeviceSerialUpdate.ts:149 Chip Features: Wi-Fi,Embedded 4MB Flash,ADC and temperature sensor calibration in BLK2 of efuse
VM76362 DeviceSerialUpdate.ts:151 Chip STA MAC Address (USB S/N): 84:f7:03:d2:94:cc
VM76362 DeviceSerialUpdate.ts:198 Using Firmware Image synergy_fw_0_95_64.bin at 0x10000
esploader.js:129 Compressed 719084 bytes to 351416...
esploader.js:129 Took 0.0s to erase flash block
esploader.js:129 Writing at 0x10000... (4%)
react_devtools_backend_compact.js:2367 Error: Timeout
You are doing nothing wrong. Flashing S2 via CDC does not work with esptool.js @brianignacio5 any time target when this bug will be fixed?
Is there activity and if yes when can a fix be expected? Imho this bug should be fixed before doing optical code manufactoring
@Jason2866 At the moment, no one from Espressif is working on this issue.
The main reason why this type of issues doesn't get resolved quickly is that they require someone with deep knowledge of both ESP boot and with web development skills (JS/TS) to contribute. Since these two topics are pretty far apart, people with both of these skills are hard to come by.
I think after https://github.com/espressif/esptool-js/pull/107 it will get easier to compare the traces against esptool.py implementation, so issues like this will get easier to troubleshoot. Then the task will become somewhat simpler. Instead of "figure out why this timeout is happening" it will be something like "change this code so that it produces the same trace as that reference implementation".
Longer term, the plan is to get the whole flashing algorithm from https://github.com/esp-rs/espflash (compiled to WebAssembly) and hide it behind the same-ish API as we have now. This way we will have to troubleshoot fewer independent implementations of the flashing protocol, which means fewer issues or faster response times.
@igrr Thank you for this infos. Knowing the reasons why "something" makes no visible process does help ;-)
Hello @Jason2866 @musicmindmachine @danielminson @newpsgo @Wind-stormger @jonasniesner
Have you guys tried the latest master to see if this issue is fixed ? There is a now a tracing feature to track the communication too. Please check the live example.
I have similar issue
esptool.js
esploader.js:158 Serial port WebSerial VendorID 0x303a ProductID 0x2
esploader.js:158 Connecting...
esploader.js:158 Debug: _connect_attempt default_reset false
esploader.js:158 Debug: Timeout
esploader.js:158 Debug: Sync
esploader.js:158 Debug: Sync err Error: Timeout
esploader.js:158 .
esploader.js:158 Debug: Sync
esploader.js:158 Debug: Sync err Error: Timeout
esploader.js:158 .
esploader.js:158 Debug: Sync
esploader.js:158 Debug: Sync err Error: Timeout
esploader.js:158 .
esploader.js:158 Debug: Sync
esploader.js:158 Debug: Sync err Error: Timeout
esploader.js:158 .
esploader.js:158 Debug: Sync
esploader.js:158 Debug: Sync err Error: Timeout
esploader.js:158 .
esploader.js:158 Debug: Sync
esploader.js:158 Debug: Sync err Error: Timeout
esploader.js:158 .
esploader.js:158 Debug: Sync
esploader.js:158 Debug: Sync err Error: Timeout
esploader.js:158 .
esploader.js:158 Debug: _connect_attempt default_reset true
esploader.js:158 Debug: Timeout
esploader.js:158 Debug: Sync
esploader.js:158 Debug: Sync err Error: Timeout
esploader.js:158 _
esploader.js:158 Debug: Sync
esploader.js:158 Debug: 538052359
esploader.js:158
esploader.js:158 Debug: Chip Magic 7c6
esploader.js:158 Detecting chip type...
esploader.js:158 ESP32-S2
esploader.js:158 Chip is ESP32-S2FH32
esploader.js:158 Features: Wi-Fi,Embedded 4MB Flash,ADC and temperature sensor calibration in BLK2 of efuse
esploader.js:158 Crystal is 40MHz
esploader.js:158 MAC: 84:f7:03:f4:f1:fc
esploader.js:158 Uploading stub...
esploader.js:158 Debug: mem_begin 4336 1 6144 40028000
esploader.js:158 Debug: check_command enter RAM download mode
esploader.js:158 Debug: check_command write to target RAM
install-web-dialog.ts:192 Error: Timeout
at Zi.read (webserial.js:128:27)
at async $i.read_packet (esploader.js:221:19)
at async $i.check_command (esploader.js:391:15)
at async $i.mem_block (esploader.js:412:40)
at async $i.run_stub (esploader.js:667:46)
at async $i.main_fn (esploader.js:728:43)
at async u._handleInstall (install-web-dialog.ts:188:7)
_handleInstall @ install-web-dialog.ts:192
await in _handleInstall (async)
firstUpdated @ install-web-dialog.ts:165
_$AE @ state.js:3
performUpdate @ state.js:3
scheduleUpdate @ state.js:3
_$E_ @ state.js:3
await in _$E_ (async)
requestUpdate @ state.js:3
o @ state.js:3
Ht @ state.js:3
Ut @ base.js:2
u @ install-web-dialog.ts:29
T @ index.ts:39
await in T (async)
_handleRetry @ install-web-dialog.ts:174
handleEvent @ animate.js:1
install-web-dialog.ts:246 Closing port
@brianignacio5 After cloning and building the main branch, and running the TS example, I can confirm that I still get a timeout when trying to connect to an ESP32-S2. trace output of esptool.js: https://pastebin.com/tq6Pcx48 trace output of esptool.py: https://pastebin.com/hr0n3qKW
EDIT: I just noticed, that the detected chip is slightly wrong with the js tool:
esptool.js
Serial port WebSerial VendorID 0x303a ProductID 0x2
Connecting....
Detecting chip type... ESP32-S2
Chip is ESP32-S2FH32
Features: Wi-Fi,Embedded 4MB Flash,ADC and temperature sensor calibration in BLK2 of efuse
Crystal is 40MHz
MAC: 84:f7:03:ea:b5:8a
Uploading stub...
Error: Timeout
Compared to python:
esptool.py v4.7.0
Found 2 serial ports
Serial port COM8
Connecting...
Detecting chip type... Unsupported detection protocol, switching and trying again...
Detecting chip type... ESP32-S2
Chip is ESP32-S2FNR2 (revision v0.0)
Features: WiFi, Embedded Flash 4MB, Embedded PSRAM 2MB, ADC and temperature sensor calibration in BLK2 of efuse V1
Crystal is 40MHz
MAC: 84:f7:03:ea:b5:8a
Uploading stub...
Running stub...