#!/bin/bash
#
# BASH
#
# Copyright 2021-2025 MicroEJ Corp. All rights reserved.
# MicroEJ Corp. PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.

# 'run.sh' is responsible for flashing the executable file on the target device 
# then resetting target device

if [ -z "$1" ]; then
    APPLICATION_FILE="$(pwd)/application.out"
else
    APPLICATION_FILE="$(cd $(dirname $1) ; pwd)/$(basename $1)"
fi

# JLinkExe command to flash the device
JLINK_CMD=$(cat <<EOF
device LEOPARD
speed 4000
if SWD
loadfile $APPLICATION_FILE
r
g
exit
EOF
)

# Execute the JLinkExe command
echo "$JLINK_CMD" | JLinkExe
