|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | + |
| 4 | +target_config_name=${TARGET_CONFIG[${MCU_FAMILY}]} |
| 5 | +declare -n target_config=$target_config_name |
| 6 | + |
| 7 | +target_sel_name=${TARGET_SEL[${MCU_FAMILY}]} |
| 8 | +declare -n target_sel=$target_sel_name |
| 9 | + |
| 10 | +interface_config_name=${INTERFACE_CONFIG[${MCU_FAMILY}]} |
| 11 | +declare -n interface_config=$interface_config_name |
| 12 | + |
| 13 | + |
| 14 | +COMMON_CONFIG=$(cat << EOM |
| 15 | +{ |
| 16 | + "name": "Debug Test", |
| 17 | + "type": "cppdbg", |
| 18 | + "request": "launch", |
| 19 | + "program": "\${workspaceFolder}/${BUILD_DIR}/${TESTS_DIR}/${PROJECT_NAME}_test.elf", |
| 20 | + "args": [], |
| 21 | + "stopAtEntry": false, |
| 22 | + "cwd": "\${workspaceFolder}", |
| 23 | + "environment": [], |
| 24 | + "externalConsole": false, |
| 25 | + "MIMode": "gdb", |
| 26 | + "miDebuggerPath": "/usr/bin/gdb-multiarch", |
| 27 | + "setupCommands": [ |
| 28 | + { |
| 29 | + "description": "Enable pretty-printing for gdb", |
| 30 | + "text": "-enable-pretty-printing", |
| 31 | + "ignoreFailures": true |
| 32 | + } |
| 33 | + ] |
| 34 | +} |
| 35 | +EOM |
| 36 | +) |
| 37 | + |
| 38 | +DEDICATED_CONFIGS="" |
| 39 | +for cores in ${MCU_SRC_DIRS[@]}; do |
| 40 | + |
| 41 | + svd_file=$(find "${PROJECT_NAME}" -name '*.svd' ) |
| 42 | + |
| 43 | + BOARD_OR_TARGET=${target_sel[$cores]} |
| 44 | + BOARD_OR_TARGET_VALUE=${target_config[$cores]} |
| 45 | + INTERFACE=${interface_config[$cores]} |
| 46 | + |
| 47 | + if [[ ${#MCU_SRC_DIRS[@]} -gt 1 ]];then |
| 48 | + |
| 49 | + executable=\"./${BUILD_DIR}/${PROJECT_NAME}_${cores}.elf\" |
| 50 | + cores=${cores^^} |
| 51 | + svd_file=$(echo "${svd_file}" | grep -E "${UPPERCASE_MCU_FAMILY:0:8}[a-z A-Z 0-9]_C${cores:0:3}\.svd$") |
| 52 | + else |
| 53 | + cores="" |
| 54 | + executable=\"./${BUILD_DIR}/${PROJECT_NAME}.elf\" |
| 55 | + fi |
| 56 | + |
| 57 | + svd_file="${svd_file#*/}" |
| 58 | + cores=${cores,,} |
| 59 | + DEDICATED_CONFIGS+=$(cat << EOM |
| 60 | +{ |
| 61 | + "name": "Cortex Debug ${cores}", |
| 62 | + "cwd": "${workspaceFolder}", |
| 63 | + "executable": $executable, |
| 64 | + "request": "launch", |
| 65 | + "type": "cortex-debug", |
| 66 | + "runToEntryPoint": "main", |
| 67 | + "servertype": "openocd", |
| 68 | + "configFiles": [ |
| 69 | + "/usr/local/share/openocd/scripts/interface/${INTERFACE}.cfg", |
| 70 | + "/usr/local/share/openocd/scripts/${BOARD_OR_TARGET}/${BOARD_OR_TARGET_VALUE}.cfg" |
| 71 | + ], |
| 72 | + "svdFile": "${svd_file}" |
| 73 | +
|
| 74 | +}, |
| 75 | +{ |
| 76 | + "name": "Flash and Debug ${cores}", |
| 77 | + "cwd": "${workspaceFolder}", |
| 78 | + "executable": $executable, |
| 79 | + "request": "launch", |
| 80 | + "type": "cortex-debug", |
| 81 | + "runToEntryPoint": "main", |
| 82 | + "servertype": "openocd", |
| 83 | + "configFiles": [ |
| 84 | + "/usr/local/share/openocd/scripts/interface/${INTERFACE}.cfg", |
| 85 | + "/usr/local/share/openocd/scripts/${BOARD_OR_TARGET}/${BOARD_OR_TARGET_VALUE}.cfg" |
| 86 | + ], |
| 87 | + "preLaunchTask": "Flash Core ${cores}" |
| 88 | +}, |
| 89 | +EOM |
| 90 | +) |
| 91 | +done |
| 92 | + |
| 93 | +LAUNCH_JSON=$(cat << EOM |
| 94 | +{ |
| 95 | + "version": "0.2.0", |
| 96 | + "configurations": [ |
| 97 | + $COMMON_CONFIG, |
| 98 | + $DEDICATED_CONFIGS |
| 99 | + ] |
| 100 | +} |
| 101 | +EOM |
| 102 | +) |
| 103 | + |
| 104 | +echo "${LAUNCH_JSON}" > $PROJECT_NAME/.vscode/launch.json |
| 105 | + |
0 commit comments