#
# Please make sure the J-Link software package is installed
#
set -e
if [[ "$OSTYPE" == "linux-gnu" ]]; then
  JLINK_SEARCH_PATH=/opt/SEGGER/JLink/
elif [[ "$OSTYPE" == "darwin"* ]]; then
   JLINK_SEARCH_PATH=/Applications/SEGGER/JLink/
else
  echo "Unknown OS, exiting"
  exit 1
fi

if [ "x$JLINK_SEARCH_PATH" = "x" ]; then
    echo "J-Link package not found, please install from https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack !"
    exit 1
fi
JLINKEXE=$( find  $JLINK_SEARCH_PATH -name JLinkExe 2> /dev/null| sort | tail -n 1 )
$JLINKEXE -device MK66FN2M0XXX18 -CommanderScript CommandFile.jlink
