firware-flash.bat 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. set CLI_TEMP=%TEMP%\arduino-cli
  4. set CONFIG_FILE=--config-file .\arduino-cli.yaml
  5. set DEFAULT_BOARD_FQBN=esp32:esp32:esp32cam
  6. set SELECTED_BOARD=%DEFAULT_BOARD_FQBN%
  7. set CLI_FOUND_FOLLOW_UP=0
  8. set COMPILE_FLAG=firmware\compile.flag
  9. set FIRMWARE_SRC=firmware\firmware.ino
  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. Make sure you've grounded your IO0 pin on your ESP32-CAM module to the correct GND pin.
  87. echo 2. Plug in your ESP32-CAM module with the reset button pressed a few seconds before continuing.
  88. echo 3. When continuing to the next step, simultaneously release the reset button at the same time.
  89. echo 4. Your ESP32-CAM should now be in flash mode. Allow the firmware to upload, this will take a moment.
  90. echo 5. It's not uncommon for this to fail many times, keep trying and double check your connections.
  91. echo.
  92. pause
  93. set RETRY_COUNT=1
  94. :uploadLoop
  95. echo.
  96. echo Preparing firmware upload... Attempt number !RETRY_COUNT!...
  97. arduino-cli %CONFIG_FILE% upload -p %PORT_NUMBER% --fqbn !SELECTED_BOARD! %FIRMWARE_SRC%
  98. if !ERRORLEVEL! EQU 0 (
  99. goto :uploadSuccess
  100. ) else (
  101. if !RETRY_COUNT! lss 3 (
  102. set /a RETRY_COUNT+=1
  103. goto :uploadLoop
  104. ) else (
  105. echo.
  106. set /p UPLOAD_TRY_AGAIN="Upload failed after 3 attempts, would you like to retry? (Y/N): "
  107. if /i "!UPLOAD_TRY_AGAIN!"=="Y" (
  108. set RETRY_COUNT=1
  109. goto :uploadFirmware
  110. ) else (
  111. echo.
  112. echo If you're still having issues, feel free to open a ticket at the following link:
  113. echo https://github.com/CodyTolene/Flipper-Zero-Camera-Suite/issues
  114. )
  115. )
  116. )
  117. :uploadSuccess
  118. echo.
  119. echo Firmware upload was successful.
  120. echo.
  121. echo Fin. Happy programming friend.
  122. echo.
  123. pause
  124. exit /b
  125. :compileFirmware
  126. set /p USE_DEFAULT_BOARD="Install to default AI-Thinker ESP32-CAM board with FQBN '%DEFAULT_BOARD_FQBN%'? (Y/N): "
  127. if /i "%USE_DEFAULT_BOARD%"=="N" (
  128. echo Warning - This script has not been tested with other boards. Please use at your own risk.
  129. set /p SHOW_BOARDS="Display all possible ESP32 board names and FQBN's? (Y/N): "
  130. if /i "!SHOW_BOARDS!"=="Y" (
  131. echo.
  132. arduino-cli board listall
  133. )
  134. set /p SELECTED_BOARD="Please enter your board FQBN. For example '%DEFAULT_BOARD_FQBN%' with no quotes: "
  135. )
  136. echo.
  137. echo Compiling firmware, this will take a moment...
  138. echo.
  139. arduino-cli %CONFIG_FILE% compile --fqbn !SELECTED_BOARD! %FIRMWARE_SRC%
  140. if %ERRORLEVEL% EQU 0 (
  141. echo.
  142. echo Firmware compiled successfully.
  143. type nul > %COMPILE_FLAG%
  144. ) else (
  145. echo Firmware failed to compile. Please see the error log and try again.
  146. exit /b
  147. )
  148. goto :exitCompileFirmware