testMonitor.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #!/usr/bin/env bash
  2. #
  3. # Syntax:
  4. # ./testMonitor.sh <example_name> <target> <keyword>
  5. #
  6. # Example:
  7. #
  8. # ./testMonitor.sh wolfssl_test esp32c6 WIP
  9. #
  10. # Define ESPIDF_PUTTY_MONITOR to a non-blank value to call putty
  11. # instead of using `idf.py monitor`
  12. #========================================================================================
  13. # Run shell check to ensure this a good script.
  14. shellcheck "$0"
  15. PUTTY_EXE="/mnt/c/tools/putty.exe"
  16. THIS_HOME_DIR="$(pwd)"
  17. # export WOLFSSL_ESPIDF="/mnt/c/workspace/wolfssl-master/IDE/Espressif/ESP-IDF/examples"
  18. # the first parameter is expected to be a project name in the WOLFSSL_ESPIDF directory.
  19. if [ $# -lt 3 ]; then
  20. echo "Usage: $0 <example_name> <target> <keyword>"
  21. exit 1
  22. else
  23. THIS_EXAMPLE="$1"
  24. # pushd "${WOLFSSL_ESPIDF}" || exit 1
  25. # pushd "./${THIS_EXAMPLE}" || exit 1
  26. THIS_TARGET="$2"
  27. THIS_KEYWORD="$3"
  28. fi
  29. echo "testMonitor current path:"
  30. pwd
  31. #ESP32c2 monitor is 78800
  32. # These are the WSL Serial Ports for each respective ESP32 SoC Device.
  33. # Unfortunately they are currently hard coded and computer-specific.
  34. esp32_PORT="/dev/ttyS9"
  35. esp32c2_PORT="/dev/ttyS79"
  36. esp32c3_PORT="/dev/ttyS35"
  37. esp32c6_PORT="/dev/ttyS36"
  38. esp32h2_PORT="/dev/ttyS31"
  39. esp32s2_PORT="/dev/ttyS30"
  40. esp32s3_PORT="/dev/ttyS24"
  41. esp8266_PORT="/dev/ttyS70"
  42. esp8684_PORT="/dev/ttyS49"
  43. # esp32c2_PORT="/dev/ttyS49" #8684
  44. # Load putty profiles. Note profiles names need to have been previously
  45. # defined and saved in putty! These are the saved sessions in putty:
  46. esp32_PUTTY="COM9"
  47. esp32c2_PUTTY="COM79 - ESP32-C2 74880"
  48. esp32c3_PUTTY="COM35"
  49. esp32c6_PUTTY="COM36"
  50. esp32h2_PUTTY="COM31"
  51. esp32s2_PUTTY="COM30"
  52. esp32s3_PUTTY="COM24"
  53. esp8684_PUTTY="COM49"
  54. esp8266_PUTTY="COM70 - 74880"
  55. echo "esp32_PORT: $esp32_PORT"
  56. echo "esp32c2_PORT: $esp32c2_PORT"
  57. echo "esp32c3_PORT: $esp32c3_PORT"
  58. echo "esp32c6_PORT: $esp32c6_PORT"
  59. echo "esp32s2_PORT: $esp32s2_PORT"
  60. echo "esp32s3_PORT: $esp32s3_PORT"
  61. echo "esp32h2_PORT: $esp32h2_PORT"
  62. echo "esp8266_PORT: $esp8266_PORT"
  63. echo "esp8684_PORT: $esp8684_PORT"
  64. # given a THIS_TARGET, assign THIS_TARGET_PORT to the respective port.
  65. THIS_TARGET_PORT="${THIS_TARGET}_PORT"
  66. # Check that THIS_TARGET_PORT is defined.
  67. if [ -z "$THIS_TARGET_PORT" ]; then
  68. echo "Error: No port defined for ${THIS_TARGET}"
  69. exit 1
  70. else
  71. echo "THIS_TARGET_PORT=${THIS_TARGET_PORT}"
  72. fi
  73. THIS_TARGET_PORT="${!THIS_TARGET_PORT}"
  74. echo THIS_TARGET_PORT="${THIS_TARGET_PORT}"
  75. # The use of putty is optional
  76. THIS_TARGET_PUTTY="${THIS_TARGET}_PUTTY"
  77. if [ -z "$ESPIDF_PUTTY_MONITOR" ]; then
  78. echo "Using ESP-IDF monitor"
  79. else
  80. # Check that THIS_TARGET_PUTTY is defined.
  81. echo ""
  82. echo "Using saved putty profile session names:"
  83. echo "esp32_PUTTY: $esp32_PUTTY"
  84. echo "esp32c2_PUTTY: $esp32c2_PUTTY"
  85. echo "esp32c3_PUTTY: $esp32c3_PUTTY"
  86. echo "esp32c6_PUTTY: $esp32c6_PUTTY"
  87. echo "esp32s2_PUTTY: $esp32s2_PUTTY"
  88. echo "esp32s3_PUTTY: $esp32s3_PUTTY"
  89. echo "esp32h2_PUTTY: $esp32h2_PUTTY"
  90. echo "esp8684_PUTTY: $esp8684_PUTTY"
  91. echo "esp8266_PUTTY: $esp8266_PUTTY"
  92. echo ""
  93. if [ -z "$THIS_TARGET_PUTTY" ]; then
  94. echo "Error: No putty profile defined for ${THIS_TARGET}"
  95. exit 1
  96. else
  97. echo "THIS_TARGET_PUTTY=${THIS_TARGET_PUTTY}"
  98. fi
  99. THIS_TARGET_PUTTY="${!THIS_TARGET_PUTTY}"
  100. echo THIS_TARGET_PUTTY="${THIS_TARGET_PUTTY}"
  101. fi
  102. if [[ "$THIS_TARGET" == "esp8684" ]]; then
  103. echo "Treating esp8684 like an esp32c2"
  104. THIS_TARGET=esp32c2
  105. fi
  106. # Assemble some log file names.
  107. echo ""
  108. BUILD_LOG="${THIS_HOME_DIR}/logs/${THIS_EXAMPLE}_build_IDF_v5.1_${THIS_TARGET}_${THIS_KEYWORD}.txt"
  109. FLASH_LOG="${THIS_HOME_DIR}/logs/${THIS_EXAMPLE}_flash_IDF_v5.1_${THIS_TARGET}_${THIS_KEYWORD}.txt"
  110. THIS_LOG="${THIS_HOME_DIR}/logs/${THIS_EXAMPLE}_output_IDF_v5.1_${THIS_TARGET}_${THIS_KEYWORD}.txt"
  111. THIS_CFG="${THIS_HOME_DIR}/logs/${THIS_EXAMPLE}_user_settings_IDF_v5.1_${THIS_TARGET}_${THIS_KEYWORD}.txt"
  112. THIS_WLOG="logs\\${THIS_TARGET}_output.log"
  113. # cp ./components/wolfssl/include/user_settings.h "${THIS_CFG}"
  114. echo "BUILD_LOG = ${BUILD_LOG}"
  115. echo "FLASH_LOG = ${FLASH_LOG}"
  116. echo "THIS_LOG = ${THIS_LOG}"
  117. echo "THIS_CFG = ${THIS_CFG}"
  118. if [[ "$THIS_TARGET" == "esp8266" ]]; then
  119. # idf.py for the ESP8266 does not support --version
  120. echo "ESP8266 using $IDF_PATH"
  121. else
  122. idf.py --version > "${BUILD_LOG}" 2>&1
  123. fi
  124. echo "Full clean for $THIS_TARGET..."
  125. #---------------------------------------------------------------------
  126. idf.py fullclean >> "${BUILD_LOG}" 2>&1
  127. THIS_ERROR_CODE=$?
  128. if [ $THIS_ERROR_CODE -ne 0 ]; then
  129. echo ""
  130. echo "Error during fullclean. Deleting build directory."
  131. rm -rf ./build
  132. fi
  133. #---------------------------------------------------------------------
  134. if [[ "$THIS_TARGET" == "esp8266" ]]; then
  135. #always start with a fresh sdkconfig-debug (or sdkconfig-release) from defaults
  136. rm -f ./sdkconfig-debug
  137. rm -f ./sdkconfig-release
  138. # idf.py for the ESP8266 does not support --set-target
  139. echo "Target is $THIS_TARGET"
  140. # Since we don't "set-target" for the ESP8266, ensure the sdkconfig is not present
  141. rm -f ./sdkconfig
  142. else
  143. # Start with fresh sdkconfig
  144. rm -f ./sdkconfig
  145. # ESP8266 debug and release files not used for non-ESP8266 targets here,delete anyhow:
  146. rm -f ./sdkconfig-debug
  147. rm -f ./sdkconfig-release
  148. echo "idf.py set-target $THIS_TARGET"
  149. idf.py "set-target" "$THIS_TARGET" >> "${BUILD_LOG}" 2>&1
  150. THIS_ERROR_CODE=$?
  151. if [ $THIS_ERROR_CODE -ne 0 ]; then
  152. echo ""
  153. tail -n 5 "${BUILD_LOG}"
  154. echo "Error during set-target"
  155. exit 1
  156. fi
  157. fi
  158. #---------------------------------------------------------------------
  159. echo ""
  160. echo "Build $THIS_TARGET..."
  161. echo "idf.py build"
  162. idf.py build >> "${BUILD_LOG}" 2>&1
  163. THIS_ERROR_CODE=$?
  164. if [ $THIS_ERROR_CODE -ne 0 ]; then
  165. echo ""
  166. tail -n 5 "${BUILD_LOG}"
  167. echo "Error during build for $THIS_TARGET"
  168. echo ""
  169. echo ""
  170. exit 1
  171. fi
  172. #---------------------------------------------------------------------
  173. echo ""
  174. echo "Flash $THIS_TARGET..."
  175. echo "idf.py flash -p ${THIS_TARGET_PORT} -b 115200"
  176. idf.py flash -p "${THIS_TARGET_PORT}" -b 115200 2>&1 | tee -a "${FLASH_LOG}"
  177. THIS_ERROR_CODE=$?
  178. if [ $THIS_ERROR_CODE -ne 0 ]; then
  179. echo ""
  180. tail -n 5 "${FLASH_LOG}"
  181. echo "Error during flash"
  182. exit 1
  183. fi
  184. # popd || exit 1
  185. # popd || exit 1
  186. # Note both of the options spawn a separate process:
  187. if [ -z "$ESPIDF_PUTTY_MONITOR" ]; then
  188. echo "Monitor..."
  189. echo ./wolfssl_monitor.py --port "${THIS_TARGET_PORT}" --baudrate 115200 --logfile "${THIS_LOG}"
  190. ./wolfssl_monitor.py --port "${THIS_TARGET_PORT}" --baudrate 115200 --logfile "${THIS_LOG}" &
  191. else
  192. echo "Calling putty..."
  193. echo "$PUTTY_EXE -load \"$THIS_TARGET_PUTTY\""
  194. $PUTTY_EXE -load "$THIS_TARGET_PUTTY" -logoverwrite -sessionlog "${THIS_WLOG}" &
  195. fi