firmware-flash.bat 6.2 KB

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