esp32使用c而不是python进行 Flink

kokeuurv  于 2023-05-22  发布在  Python
关注(0)|答案(2)|浏览(219)

我想把我的二进制文件flash到esp32。有没有一种不使用esptool.py工具的简单方法来flash二进制文件?是我自己移植esptool.py的唯一选择吗?

kq4fsx7k

kq4fsx7k1#

您可以将python程序构建为独立的.exe文件。

REM Script for building esptool.exe
@REM Author: Paul Abbott, 2019
@ECHO OFF
SETLOCAL EnableDelayedExpansion

REM %CD% gives current dir, but 
SET THISDIR=%CD%
REM %~dp0 gives the directory of this batch file (with a trailing \)
SET SCRIPTDIR=%~dp0
SET "PROGRAMMER=%SCRIPTDIR%..\..\Tools\esp-idf\components\esptool_py\esptool\esptool.py"

pip2 install pyinstaller pyserial

rmdir /s /q build_tmp
mkdir build_tmp
C:\Python27\scripts\pyinstaller ^
    --onefile ^
    --specpath build_tmp ^
    --workpath build_tmp\build ^
    --distpath %SCRIPTDIR% ^
    %PROGRAMMER%
    
REM Output: build_tmp\dist\esptool.exe

输出esptool.exe将工作,而无需在任何Windows XP,7,10上安装任何东西。(可能也有类似的方法来构建其他操作系统)
现在您可以调用从生产编程脚本生成的.exe文件。下面是我的batchprog-esp 32.cmd示例:

@REM Script for assembly line programming of ESP32
@REM Author: Paul Abbott, 2019
@ECHO OFF
SETLOCAL EnableDelayedExpansion

REM %CD% gives current dir, but 
SET THISDIR=%CD%
REM %~dp0 gives the directory of this batch file (with a trailing \)
SET SCRIPTDIR=%~dp0

SET "PROGRAMMER=%SCRIPTDIR%\esptool.exe"
SET /a DUTNUMBER=1

IF /i NOT EXIST %PROGRAMMER% (
    MORE %SCRIPTDIR%readme.md
    ECHO Programmer %PROGRAMMER% does not exist!.
    GOTO :DIE
)

rem Restore the color of the screen
COLOR 07
CLS
ECHO Batch Programmer
ECHO/
ECHO In Directory:
ECHO  %THISDIR%
ECHO/
ECHO Found .bin files in directory:
ECHO **************************************************************************
SET AppSel=0
SET AppIndex=0
SET FDataSel=0
SET FDataIndex=0
FOR %%F IN (%THISDIR%\*.bin) DO (
  SET THISFILE=%%~nxF
  IF NOT "!THISFILE:bootloader=!"=="!THISFILE!" (
    ECHO Bootloader: %%~nxF
    SET BOOTLOADER_BIN=%%~nxF
  ) ELSE IF NOT "!THISFILE:partitions=!"=="!THISFILE!" (
    ECHO Partitions: %%~nxF
    SET PARTITION_BIN=%%~nxF
  ) ELSE IF NOT "!THISFILE:ota_data=!"=="!THISFILE!" (
    ECHO OTA_Init: %%~nxF
    SET OTAINITDATA_BIN=%%~nxF
  ) ELSE IF NOT "!THISFILE:nvs_data=!"=="!THISFILE!" (
    ECHO NVS_Init: %%~nxF
    SET NVSINITDATA_BIN=%%~nxF
  ) ELSE IF NOT "!THISFILE:phy_init=!"=="!THISFILE!" (
    ECHO PHY-Init: %%~nxF
    SET PHYINITDATA_BIN=%%~nxF
  ) ELSE IF NOT "!THISFILE:factory_data=!"=="!THISFILE!" (
    SET FDataSel.!FDataIndex!=%%~nxF
    ECHO FData: %%~nxF
    SET /A FDataSel = !FDataIndex!
    SET /A FDataIndex += 1
  ) ELSE (
  REM Print all other .bin files that didn't match above as potential Factory App
    SET AppSel.!AppIndex!=%%~nxF
    ECHO App: %%~nxF
    SET /A AppSel = !AppIndex!
    SET /A AppIndex += 1
  )
)
ECHO **************************************************************************
ECHO/

IF !AppIndex! LEQ 1 GOTO :SKIP_APP_SELECT
REM App Select
ECHO Please choose factory app from this list:
ECHO **************************************************************************
SET /A NUMAPPS=!AppIndex!-1
FOR /L %%G IN (0,1,%NUMAPPS%) DO (
    ECHO %%G: !AppSel.%%G!
)
ECHO **************************************************************************
ECHO/
SET /P AppSel= Choose the file to program to Factory App Partition [%AppSel%]^>
:SKIP_APP_SELECT
IF "!AppSel.%AppSel%!"=="" (
    ECHO WARNING: No App Partition!   
) ELSE (
    SET FACTORYAPP_BIN=!AppSel.%AppSel%!
)

IF !FDataIndex! LEQ 0 (
    REM no factorydata partition found, assume app offset at 0x10000
    SET FACTORYAPP_OFFSET=0x10000
) ELSE (
    REM found a factorydata partition (new format), assume app offset at 0x20000
    SET FACTORYAPP_OFFSET=0x20000
)
IF !FDataIndex! LEQ 1 GOTO :SKIP_FDATA_SELECT
REM FData Select
ECHO Please choose factory data from this list:
ECHO **************************************************************************
SET /A NUMFDATAS=!FDataIndex!-1
FOR /L %%G IN (0,1,%NUMFDATAS%) DO (
    ECHO %%G: !FDataSel.%%G!
)
ECHO **************************************************************************
ECHO/
SET /P AppSel= Choose the file to program to Factory Data Partition [%FDataSel%]^>
:SKIP_FDATA_SELECT
IF NOT "!FDataSel.%FDataSel%!"=="" SET FACTORYDATA_BIN=!FDataSel.%FDataSel%!

REM Configure COM port
if NOT EXIST UART_COM.CFG (
    set SERCOMNO=COM1
) else (
    set /P SERCOMNO= < UART_COM.CFG
)
REM remove spaces
set SERCOMNO=%SERCOMNO: =%
echo Enter the COM_PORT_NUMBER (as COM1 ~ COM99) [%SERCOMNO%]
set /p SERCOMNO=
REM remove spaces
set SERCOMNO=%SERCOMNO: =%
IF !SERCOMNO!=="" GOTO :DIE
echo %SERCOMNO% > UART_COM.CFG

SET PROGRAMMER=%PROGRAMMER% --chip esp32 ^
--port !SERCOMNO! ^
--baud 921600 ^
--before default_reset ^
--after no_reset ^
write_flash -z ^
--flash_mode dio ^
--flash_freq 80m ^
--flash_size 16MB

IF NOT "%NVSINITDATA_BIN%"=="" SET PROGRAMMER=%PROGRAMMER% 0x9000 %THISDIR%/%NVSINITDATA_BIN%
IF NOT "%OTAINITDATA_BIN%"=="" SET PROGRAMMER=%PROGRAMMER% 0xd000 %THISDIR%/%OTAINITDATA_BIN%
IF NOT "%BOOTLOADER_BIN%"=="" SET PROGRAMMER=%PROGRAMMER% 0x1000 %THISDIR%/%BOOTLOADER_BIN%
IF NOT "%PHYINITDATA_BIN%"=="" SET PROGRAMMER=%PROGRAMMER% 0xf000 %THISDIR%/%PHYINITDATA_BIN%
IF NOT "%PARTITION_BIN%"=="" SET PROGRAMMER=%PROGRAMMER% 0x8000 %THISDIR%/%PARTITION_BIN%
IF NOT "%FACTORYDATA_BIN%"=="" SET PROGRAMMER=%PROGRAMMER% 0x10000 %THISDIR%/%FACTORYDATA_BIN%
IF NOT "%FACTORYAPP_BIN%"=="" SET PROGRAMMER=%PROGRAMMER% %FACTORYAPP_OFFSET% %THISDIR%/%FACTORYAPP_BIN%

REM Restore the color of the screen
COLOR 07
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
:START
ECHO/
ECHO/
ECHO/
ECHO/
ECHO Batch Programmer
ECHO/
ECHO In Directory:
ECHO  %THISDIR%
ECHO/ 
ECHO Programming these files:
ECHO **************************************************************************
IF NOT "%NVSINITDATA_BIN%"=="" ECHO %NVSINITDATA_BIN%
IF NOT "%OTAINITDATA_BIN%"=="" ECHO %OTAINITDATA_BIN%
IF NOT "%BOOTLOADER_BIN%"=="" ECHO %BOOTLOADER_BIN%
IF NOT "%PHYINITDATA_BIN%"=="" ECHO %PHYINITDATA_BIN% 
IF NOT "%PARTITION_BIN%"=="" ECHO %PARTITION_BIN% 
IF NOT "%FACTORYDATA_BIN%"=="" ECHO %FACTORYDATA_BIN% 
IF NOT "%FACTORYAPP_BIN%"=="" ECHO %FACTORYAPP_BIN% to %FACTORYAPP_OFFSET%
ECHO **************************************************************************
ECHO/
SET /P G= Hit 'Enter' to Program device #%DUTNUMBER%^>

REM Restore the color of the screen
COLOR 07
ECHO %PROGRAMMER%
ECHO/
ECHO/
ECHO Starting Programmer.  Please Wait...
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
ECHO/
CALL %PROGRAMMER%
IF %ERRORLEVEL% NEQ 0 goto :FAILURE

:SUCCESS
REM Color the screen green
color 2f
ECHO *********************************
ECHO ***    Programming SUCCESS^^!   ***
ECHO *********************************
ECHO/
SET /a DUTNUMBER=%DUTNUMBER% + 1
goto :START

:FAILURE
REM Color the screen red
color 4f
ECHO *********************************
ECHO ***    Programming FAILURE^^!   ***
ECHO *********************************
ECHO/
goto :START

:DIE
REM Color the screen red
COLOR 4f
ECHO ERROR!
PAUSE
GOTO :QUIT

:QUIT
REM Restore the Color of the screen
COLOR 07
GOTO :eof

现在我只需要将esptool.exe文件和batchprog-esp 32.cmd脚本与我的发布二进制文件沿着推送到git存储库中。我的合同制造商拉回购,可以编程,而不安装任何东西。

wvmv3b1j

wvmv3b1j2#

此外,Espressif Systems本身还提供了一个基于Windows的应用程序Flash Download Tools。压缩文件不仅有可执行文件,还有一个全面的PDF应用程序说明和一些屏幕截图。

相关问题