Skip to content

Flashing/Baudrate issues #36

@DeltaCore

Description

@DeltaCore

Good day,

yesterday i migrated from ESPTool v3.0.3 to the ESPDotNet v5.0.1.

With this i encountered some issues:

  • When changing baud rate i can't flash and always get timeout exceptions
  • When using default baud rate of 115200 i frequently get CRC and timeout exceptions.
    Both exceptions are thrown by firmwareUploadTool.UploadFirmwareAsync

One of the CRC errors: FlashDeflData failed (command 0x11): InvalidCRC.
Timeout error: Timeout waiting for serial data after 5.000ms.

The device i try to flash is proven to work and can be flashed successfully with the old ESPTool v3.0.3 and esptool from espressif, even at high Baudrates of 921600 an higher.

Both issues occur with the FlashUploadDeflatedTool as well as the FlashUploadTool.

This is not my exact code, i removed a lot of UI code and events.
I am running Windows 11 and v5.0.1 of the ESPDotNet Package.

private async void Flash(){ 
    const int loader_baud = 115200;
    const int flash_baud = 921600;
    ILoader? bootloader = null;
    SoftLoader? softloader = null;
    EspDotNet.Config.DeviceConfig? device_config = null;
    var config = ConfigProvider.LoadDefaultConfig();
    var port = new SerialPort("COM4", loader_baud);

    FirmwareArchive? firmware = await LocalProvider.FromPackage(_selected_package_file);

    if (firmware is null)
        return;

    port.Open();
    var communicator = new Communicator(port);
    
    var bootloaderTool = new BootloaderTool(communicator, config.BootloaderSequence);
    try
    {
        bootloader = await bootloaderTool.StartBootloaderAsync();
    }
    catch (Exception) { }

    if (bootloader is null)
        return;

    var chipDetectTool = new ChipTypeDetectTool(bootloader, config);
    Logger.Log($"Getting chiptype...");
    try
    {
        device_config = await chipDetectTool.DetectAndGetDeviceConfigAsync(default);
        Logger.Log($"Got chip type {device_config.ChipType}. Starting softloader...");
    }
    catch (Exception) { }

    if (device_config == null || device_config.ChipType == ChipTypes.Unknown)
        return;

    var stub = DefaultFirmwareProviders.GetSoftloaderForDevice(device_config.ChipType);
    var ramUploadTool = new RamUploadTool(bootloader, device_config);
    var softLoaderTool = new SoftLoaderTool(communicator, ramUploadTool);
    try
    {
        softloader = await softLoaderTool.StartAsync(stub);
        Logger.Log($"Softloader started");
    }
    catch (Exception) { }

    if (softloader == null)
        return;

    var baudTool = new ChangeBaudRateTool(softloader);
    try
    {
        await baudTool.ChangeBaudAsync(flash_baud, loader_baud, default);
        Logger.Log($"Baud changed to {flash_baud}");
    }
    catch (Exception) { }

    try
    {
        Logger.Log($"Creating flash tool");
        IUploadTool uploader;

        if (CheckBoxCompression.Checked)
            uploader = new FlashUploadDeflatedTool(softloader, device_config);
        else
            uploader = new FlashUploadTool(softloader, device_config);

        var firmwareUploadTool = new FirmwareUploadTool(uploader)
        {
            Progress = _progressBarBinder.Bind()
        };

        Logger.Log($"Uploading");
        await firmwareUploadTool.UploadFirmwareAsync(firmware, default);
    }
    catch (Exception ex)
    {
        Logger.Log("error flashing device", ex.Message);
        return;
    }

    Logger.Log($"Resetting device");
    var resetTool = new ResetDeviceTool(communicator, config.ResetSequence);
    await resetTool.ResetAsync();

    Logger.Log($"Ok. done");
}

If you need anything else, please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions