Skip to content

Commit

Permalink
IEP-902 Make flash over combo with UART, JTAG and DFU (#716)
Browse files Browse the repository at this point in the history
* Make flash-over combo with UART, JTAG and DFU
  • Loading branch information
sigmaaa authored Mar 20, 2023
1 parent eff13db commit e312273
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 216 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,13 @@ which there is no driver installed (probably it is Interface 2) and don't re-ins

After meeting requirements you are free to build and flash via DFU. How to use DFU:

- Activate the DFU toggle button on the toolbar.
- Select the correct target and port through the target panel
- Now, if you will use the build command an extra file will be created (dfu.bin), which will be later used for flashing.
- Edit the active launch configuration.
- In the main tab, select the 'Flash over DFU' option.
- Select a suitable IDF target for DFU
- Now, if you use the build command, an extra file (dfu.bin) will be created, which can be used later for flashing.

![DFU actions](https://user-images.githubusercontent.com/24419842/226182180-286099d3-9c1c-4394-abb0-212d43054529.png)

![DFU actions](https://user-images.githubusercontent.com/24419842/175890153-42bd711e-a916-408e-a568-9b008f86a8b6.png)

Additional information, including common errors and known issues, is mentioned in this [guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/dfu.html#usb-drivers-windows-only).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ public final class IDFLaunchConstants
public static final String DEBUG_LAUNCH_CONFIG_TYPE= "com.espressif.idf.debug.gdbjtag.openocd.launchConfigurationType"; //$NON-NLS-1$
public static final String RUN_LAUNCH_CONFIG_TYPE = "com.espressif.idf.launch.serial.launchConfigurationType"; //$NON-NLS-1$
public static final String FLASH_OVER_JTAG = "FLASH_OVER_JTAG"; //$NON-NLS-1$
public static final String DFU = "DFU"; //$NON-NLS-1$
public static final String JTAG_FLASH_VOLTAGE = "com.espressif.idf.debug.gdbjtag.openocd.jtagFlashVoltage"; //$NON-NLS-1$
public static final String TARGET_FOR_JTAG = "com.espressif.idf.debug.gdbjtag.openocd.jtagTarget"; //$NON-NLS-1$
public static final String JTAG_BOARD = "com.espressif.idf.debug.gdbjtag.openocd.jtagBoard"; //$NON-NLS-1$
public static final String ATTR_SERIAL_FLASH_ARGUMENTS = "com.espressif.idf.launch.serial.core.serialFlashArguments"; //$NON-NLS-1$
public static final String ATTR_DFU_FLASH_ARGUMENTS = "com.espressif.idf.launch.serial.core.dfuFlashArguments"; //$NON-NLS-1$
public static final String ATTR_JTAG_FLASH_ARGUMENTS = "com.espressif.idf.debug.gdbjtag.openocd.jtagFlashArguments"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,45 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.launchbar.core.ILaunchBarManager;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;

import com.espressif.idf.core.IDFCorePlugin;
import com.espressif.idf.core.IDFEnvironmentVariables;
import com.espressif.idf.core.build.IDFLaunchConstants;
import com.espressif.idf.core.logging.Logger;

public class DfuCommandsUtil
{

public static final String DFU_COMMAND = "com.espressif.idf.ui.command.dfu"; //$NON-NLS-1$
public static final String TOGGLE_STATUS = "org.eclipse.ui.commands.toggleState"; //$NON-NLS-1$
private static final String[] SUPPORTED_TARGETS = { "esp32s2", "esp32s3" }; //$NON-NLS-1$ //$NON-NLS-2$
private static final String DFU_FLASH_COMMAND = "dfu-flash"; //$NON-NLS-1$

public static boolean isDfu()
{
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
boolean isDfu = (boolean) commandService.getCommand(DFU_COMMAND).getState(TOGGLE_STATUS).getValue();
return isDfu;
try
{
ILaunchConfiguration configuration = IDFCorePlugin.getService(ILaunchBarManager.class)
.getActiveLaunchConfiguration();
return configuration.getAttribute(IDFLaunchConstants.DFU, false);
}
catch (CoreException e)
{
Logger.log(e);
}
return false;
}

public static boolean isDfuSupported(ILaunchTarget launchTarget)
{
String targetName = launchTarget.getAttribute("com.espressif.idf.launch.serial.core.idfTarget", ""); //$NON-NLS-1$
boolean isDfuSupported = Arrays.stream(SUPPORTED_TARGETS).anyMatch(target -> target.contentEquals(targetName));
boolean isDfuSupported = isTargetSupportDfu(launchTarget);
Display.getDefault().asyncExec(new Runnable()
{
@Override
Expand All @@ -66,6 +76,24 @@ public void run()
return isDfuSupported;
}

public static boolean isTargetSupportDfu(ILaunchTarget launchTarget)
{
String targetName = launchTarget.getAttribute("com.espressif.idf.launch.serial.core.idfTarget", //$NON-NLS-1$
StringUtil.EMPTY);
boolean isDfuSupported = Arrays.stream(SUPPORTED_TARGETS).anyMatch(target -> target.contentEquals(targetName));
return isDfuSupported;
}

public static String getDfuFlashCommand()
{
List<String> commands = new ArrayList<>();
commands.add(IDFUtil.getIDFPythonEnvPath());
commands.add(IDFUtil.getIDFPythonScriptFile().getAbsolutePath());
commands.add(DFU_FLASH_COMMAND);

return String.join(" ", commands); //$NON-NLS-1$
}

public static Process dfuBuild(IProject project, ConsoleOutputStream infoStream, IBuildConfiguration config,
List<IEnvironmentVariable> envVars) throws IOException, CoreException
{
Expand Down Expand Up @@ -93,14 +121,21 @@ private static Process startProcess(List<String> commands, IProject project, Con
return process;
}

public static void flashDfuBins(IProject project, ILaunch launch, IProgressMonitor monitor, String serialPort)
public static void flashDfuBins(ILaunchConfiguration configuration, IProject project, ILaunch launch,
IProgressMonitor monitor)
{
List<String> flashCommandList = new ArrayList<>();
try
{
flashCommandList = Arrays.asList(configuration
.getAttribute(IDFLaunchConstants.ATTR_DFU_FLASH_ARGUMENTS, getDfuFlashCommand()).split(" ")); //$NON-NLS-1$
}
catch (CoreException e1)
{
Logger.log(e1);
}
List<String> commands = new ArrayList<>();
commands.add(IDFUtil.getIDFPythonEnvPath());
commands.add(IDFUtil.getIDFPythonScriptFile().getAbsolutePath());
commands.add("-p"); //$NON-NLS-1$
commands.add(serialPort);
commands.add("dfu-flash"); //$NON-NLS-1$
commands.addAll(flashCommandList);
File workingDir = null;
workingDir = new File(project.getLocationURI());
Map<String, String> envMap = new IDFEnvironmentVariables().getSystemEnvMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
serialPort = ((SerialFlashLaunch) launch).getLaunchTarget()
.getAttribute(SerialFlashLaunchTargetProvider.ATTR_SERIAL_PORT, ""); //$NON-NLS-1$
if (DfuCommandsUtil.isDfu()) {
if (checkIfPortIsEmpty(configuration)) {
return;
}
DfuCommandsUtil.flashDfuBins(getProject(configuration), launch, monitor, serialPort);
DfuCommandsUtil.flashDfuBins(configuration, getProject(configuration), launch, monitor);
return;
}
if (isFlashOverJtag) {
Expand Down
Loading

0 comments on commit e312273

Please sign in to comment.