firware-flash.bat 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. set CLI_FOUND_FOLLOW_UP=0
  4. set CLI_TEMP=%TEMP%\arduino-cli
  5. set COMPILE_FLAG=firmware\compile.flag
  6. set CONFIG_FILE=--config-file .\arduino-cli.yaml
  7. set DEFAULT_BOARD_FQBN=esp32:esp32:esp32cam
  8. set FIRMWARE_SRC=firmware\firmware.ino
  9. set SELECTED_BOARD=%DEFAULT_BOARD_FQBN%
  10. chcp 65001 > nul
  11. echo ┏┓ ┓ ┏┳┓ ┓
  12. echo ┃ ┏┓┏┫┓┏ ┃ ┏┓┃┏┓┏┓┏┓
  13. echo ┗┛┗┛┗┻┗┫ ┻ ┗┛┗┗ ┛┗┗
  14. echo ┛ https://github.com/CodyTolene
  15. echo.
  16. echo Flipper Zero - ESP32-CAM Firmware Flasher - Windows 10+
  17. echo https://github.com/CodyTolene/Flipper-Zero-Camera-Suite
  18. echo.
  19. echo ------------------------------------------------------------------------------
  20. echo Before you begin please make sure your Flipper Zero is plugged into your PC.
  21. echo Then on your Flipper Zero, open the GPIO menu and select USB-UART Bridge.
  22. echo ------------------------------------------------------------------------------
  23. echo.
  24. pause
  25. echo.
  26. echo Initializing...
  27. :checkCLI
  28. if not exist "arduino-cli.exe" (
  29. echo.
  30. echo The "arduino-cli.exe" file cannot be found. Please download it manually from the following link:
  31. echo https://arduino.github.io/arduino-cli/latest/installation/#download
  32. echo Extract the "arduino-cli.exe" file to the same directory as this script, root of the project.
  33. echo.
  34. echo When the file is ready, press any key to check again.
  35. set /a CLI_FOUND_FOLLOW_UP+=1
  36. if %CLI_FOUND_FOLLOW_UP% geq 2 (
  37. echo If you're still having issues, feel free to open a ticket at the following link:
  38. echo https://github.com/CodyTolene/Flipper-Zero-Camera-Suite/issues
  39. )
  40. pause
  41. goto :checkCLI
  42. )
  43. if %CLI_FOUND_FOLLOW_UP% geq 1 (
  44. echo File "arduino-cli.exe" found. Continuing...
  45. )
  46. echo Checking configs...
  47. arduino-cli %CONFIG_FILE% config set directories.data %CLI_TEMP%\data
  48. arduino-cli %CONFIG_FILE% config set directories.downloads %CLI_TEMP%\downloads
  49. arduino-cli %CONFIG_FILE% config set directories.user %CLI_TEMP%\user %*
  50. echo Fetching assets...
  51. set DATA_FLAG=0
  52. if not exist "%CLI_TEMP%\data" (
  53. set /a "DATA_FLAG+=1"
  54. )
  55. if not exist "%CLI_TEMP%\downloads" (
  56. set /a "DATA_FLAG+=1"
  57. )
  58. if %DATA_FLAG% gtr 0 (
  59. arduino-cli %CONFIG_FILE% core update-index
  60. arduino-cli %CONFIG_FILE% core install esp32:esp32
  61. ) else (
  62. echo Assets already installed. Skipping...
  63. )
  64. if not exist "%COMPILE_FLAG%" (
  65. goto :compileFirmware
  66. )
  67. if exist "%COMPILE_FLAG%" (
  68. echo.
  69. set /p RECOMPILE="A previous firmware build was found, would you like to use it? (Y/N): "
  70. if /i "!RECOMPILE!"=="N" (
  71. goto :compileFirmware
  72. )
  73. )
  74. :exitCompileFirmware
  75. echo.
  76. echo Firmware ready for serial installation...
  77. echo Fetching and displaying USB devices for upload...
  78. echo.
  79. arduino-cli board list
  80. echo Please find your Flipper Zero USB port name from the list above (may show as unknown).
  81. set /p PORT_NUMBER="Enter the port name here. For example 'COM3' capitalized with no quotes: "
  82. echo.
  83. echo Your ESP32-CAM is ready to be flashed. Please follow the instructions below:
  84. :uploadFirmware
  85. echo.
  86. echo 1. Ensure IO0 pin on ESP32-CAM is grounded to the proper GND pin.
  87. echo 2. Hold reset, and plug in your ESP32-CAM; hold for a few seconds and release.
  88. echo 3. Try to time your release simultaneously with continuing to the next step.
  89. echo 4. ESP32-CAM should now be in flash mode; allow some time for firmware upload.
  90. echo 5. Failure is common; verify all connections if errors persist and try again.
  91. echo 6. Disconnecting and reconnecting USB between attempts may sometimes work.
  92. echo.
  93. pause
  94. set RETRY_COUNT=1
  95. :uploadLoop
  96. echo.
  97. echo Preparing firmware upload... Attempt number !RETRY_COUNT!...
  98. arduino-cli %CONFIG_FILE% upload -p %PORT_NUMBER% --fqbn !SELECTED_BOARD! %FIRMWARE_SRC%
  99. if !ERRORLEVEL! EQU 0 (
  100. goto :uploadSuccess
  101. ) else (
  102. if !RETRY_COUNT! lss 3 (
  103. set /a RETRY_COUNT+=1
  104. goto :uploadLoop
  105. ) else (
  106. echo.
  107. set /p UPLOAD_TRY_AGAIN="Upload failed after 3 attempts, dont give up friend. Would you like to try again? (Y/N): "
  108. if /i "!UPLOAD_TRY_AGAIN!"=="Y" (
  109. set RETRY_COUNT=1
  110. goto :uploadFirmware
  111. ) else (
  112. echo.
  113. echo If you're still having issues, feel free to open a ticket at the following link:
  114. echo https://github.com/CodyTolene/Flipper-Zero-Camera-Suite/issues
  115. )
  116. )
  117. )
  118. :uploadSuccess
  119. echo.
  120. echo Firmware upload was successful.
  121. echo Cleaning up...
  122. echo Restoring default configs...
  123. arduino-cli %CONFIG_FILE% config set directories.data C:\temp\arduino-cli\data
  124. arduino-cli %CONFIG_FILE% config set directories.downloads C:\temp\arduino-cli\staging
  125. arduino-cli %CONFIG_FILE% config set directories.user C:\temp\arduino-cli\user
  126. set /p DELETE_TEMP="Would you like to delete the temporary files? (Y/N): "
  127. if /i "!DELETE_TEMP!"=="Y" (
  128. rmdir /s /q %CLI_TEMP%
  129. )
  130. echo.
  131. echo Fin. Happy programming.
  132. echo.
  133. pause
  134. exit /b
  135. :compileFirmware
  136. set /p USE_DEFAULT_BOARD="Install to default AI-Thinker ESP32-CAM board with FQBN '%DEFAULT_BOARD_FQBN%'? (Y/N): "
  137. if /i "%USE_DEFAULT_BOARD%"=="N" (
  138. echo Warning - This script has not been tested with other boards. Please use at your own risk.
  139. set /p SHOW_BOARDS="Display all possible ESP32 board names and FQBN's? (Y/N): "
  140. if /i "!SHOW_BOARDS!"=="Y" (
  141. echo.
  142. arduino-cli board listall
  143. )
  144. set /p SELECTED_BOARD="Please enter your board FQBN. For example '%DEFAULT_BOARD_FQBN%' with no quotes: "
  145. )
  146. echo.
  147. echo Compiling firmware, this will take a moment...
  148. echo.
  149. arduino-cli %CONFIG_FILE% compile --fqbn !SELECTED_BOARD! %FIRMWARE_SRC%
  150. if %ERRORLEVEL% EQU 0 (
  151. echo.
  152. echo Firmware compiled successfully.
  153. type nul > %COMPILE_FLAG%
  154. ) else (
  155. echo Firmware failed to compile. Please see the error log and try again.
  156. exit /b
  157. )
  158. goto :exitCompileFirmware