gn_stm32_example.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2023 Project CHIP Authors
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # Build script for GN STM32 examples GitHub workflow.
  18. set -e
  19. echo_green() {
  20. echo -e "\033[0;32m$*\033[0m"
  21. }
  22. echo_blue() {
  23. echo -e "\033[1;34m$*\033[0m"
  24. }
  25. if [[ -z "${MATTER_ROOT}" ]]; then
  26. echo "Using default path for Matter root"
  27. CHIP_ROOT="$(dirname "$0")/../.."
  28. else
  29. echo "Using ENV path for Matter root"
  30. CHIP_ROOT="$MATTER_ROOT"
  31. fi
  32. source "$CHIP_ROOT/scripts/activate.sh"
  33. set -x
  34. env
  35. USE_WIFI=false
  36. #ST_THREAD_TARGET=\""../st:ot-stm32-cert"\"
  37. USAGE="./scripts/examples/gn_stm32_example.sh <AppRootFolder> <outputFolder> <stm32_board_name> [<Build options>]"
  38. if [ "$#" == "0" ]; then
  39. echo "Build script for stm32 Matter apps
  40. Format:
  41. $USAGE
  42. <AppRootFolder>
  43. Root Location of the app e.g: examples/lighting-app/stm32/
  44. <outputFolder>
  45. Desired location for the output files
  46. <stm32_board_name>
  47. Identifier of the board for which this app is built
  48. Currently Supported :
  49. STM32WB5MM-DK
  50. <Build options> - optional noteworthy build options for stm32
  51. chip_build_libshell
  52. Enable libshell support. (Default false)
  53. chip_logging
  54. Current value (Default true)
  55. chip_openthread_ftd
  56. Use openthread Full Thread Device, else, use Minimal Thread Device. (Default true)
  57. stm32_sdk_root
  58. Location for an alternate or modified stm32 SDK
  59. enable_heap_monitoring
  60. Monitor & log memory usage at runtime. (Default false)
  61. enable_openthread_cli
  62. Enables openthread cli without matter shell. (Default true)
  63. kvs_max_entries
  64. Set the maxium Kvs entries that can be store in NVM (Default 75)
  65. Thresholds: 30 <= kvs_max_entries <= 255
  66. show_qr_code
  67. Enables QR code on LCD for devices with an LCD
  68. setupDiscriminator
  69. Discriminatoor value used for BLE connexion. (Default 3840)
  70. setupPinCode
  71. PIN code for PASE session establishment. (Default 20202021)
  72. enable_sleepy_device
  73. Enable Sleepy end device. (Default false)
  74. Must also set chip_openthread_ftd=false
  75. use_mxchip
  76. Build wifi example with MXCHIP extension board. (Default false)
  77. 'import("//with_pw_rpc.gni")'
  78. Use to build the example with pigweed RPC
  79. OTA_periodic_query_timeout
  80. Periodic query timeout variable for OTA in seconds
  81. wifi_wpa3_only
  82. Support for WPA3 only mode
  83. Presets
  84. --sed
  85. enable sleepy end device, set thread mtd
  86. For minimum consumption, disable openthread cli and qr code
  87. --wifi <mxchip>
  88. build wifi example variant for given extension board
  89. --additional_data_advertising
  90. enable Addition data advertissing and rotating device ID
  91. --use_ot_lib
  92. use the STMicroelectronics openthread library
  93. "
  94. elif [ "$#" -lt "2" ]; then
  95. echo "Invalid number of arguments
  96. Format:
  97. $USAGE"
  98. else
  99. ROOT=$1
  100. OUTDIR=$2
  101. if [ "$#" -gt "2" ]; then
  102. STM32_BOARD=$3
  103. shift
  104. fi
  105. shift
  106. shift
  107. while [ $# -gt 0 ]; do
  108. case $1 in
  109. --wifi)
  110. if [ -z "$2" ]; then
  111. echo "--wifi requires mxchip"
  112. exit 1
  113. fi
  114. if [ "$2" = "mxchip" ]; then
  115. optArgs+="use_mxchip=true"
  116. else
  117. echo "Wifi usage: --wifi mxchip"
  118. exit 1
  119. fi
  120. USE_WIFI=true
  121. shift
  122. shift
  123. ;;
  124. --sed)
  125. optArgs+="enable_sleepy_device=true chip_openthread_ftd=false "
  126. shift
  127. ;;
  128. --chip_enable_wifi_ipv4)
  129. optArgs+="chip_enable_wifi_ipv4=true "
  130. shift
  131. ;;
  132. --additional_data_advertising)
  133. optArgs+="chip_enable_additional_data_advertising=true chip_enable_rotating_device_id=true "
  134. shift
  135. ;;
  136. --use_ot_lib)
  137. optArgs+="use_st_thread_lib=true chip_openthread_target=$ST_THREAD_TARGET openthread_external_platform=\"""\" "
  138. shift
  139. ;;
  140. --use_ot_coap_lib)
  141. optArgs+="use_st_thread_lib=true chip_openthread_target=$ST_THREAD_TARGET openthread_external_platform=\"""\" use_thread_coap_lib=true "
  142. shift
  143. ;;
  144. *)
  145. if [ "$1" =~ *"use_mxchip=true"* ]; then
  146. USE_WIFI=true
  147. fi
  148. optArgs+=$1" "
  149. shift
  150. ;;
  151. esac
  152. done
  153. if [ -z "$STM32_BOARD" ]; then
  154. echo "STM32_BOARD not defined"
  155. exit 1
  156. fi
  157. BUILD_DIR=$OUTDIR/$STM32_BOARD
  158. echo BUILD_DIR="$BUILD_DIR"
  159. if [ "$USE_WIFI" == true ]; then
  160. gn gen --check --fail-on-unused-args --export-compile-commands --root="$ROOT" --dotfile="$ROOT"/build_for_wifi_gnfile.gn --args="stm32_board=\"$STM32_BOARD\" $optArgs" "$BUILD_DIR"
  161. else
  162. # thread build
  163. #
  164. if [ -z "$optArgs" ]; then
  165. gn gen --check --fail-on-unused-args --export-compile-commands --root="$ROOT" --args="stm32_board=\"$STM32_BOARD\" treat_warnings_as_errors=false" --ide=json "$BUILD_DIR"
  166. else
  167. gn gen --check --fail-on-unused-args --export-compile-commands --root="$ROOT" --args="stm32_board=\"$STM32_BOARD\" $optArgs treat_warnings_as_errors=false" --ide=json "$BUILD_DIR"
  168. fi
  169. fi
  170. ninja -v -C "$BUILD_DIR"/
  171. #print stats
  172. arm-none-eabi-size "$BUILD_DIR"/*.elf
  173. arm-none-eabi-objcopy -O binary "$BUILD_DIR"/*.elf """$BUILD_DIR/*.elf.bin"
  174. set +x
  175. echo_green "Finished building target: ""$BUILD_DIR/*.elf"
  176. fi