#!/bin/sh
PROJ="${1?'project'}"
OPENOCD=openocd
OPENOCD_BOARD_DIR=/usr/share/openocd/scripts/board
OPENOCD_PROC_FILE=stm32f4discovery.cfg
if [ "x`lsusb -d 0483:374b`" != "x" ]; then
for fn in st_nucleo_f4.cfg st_nucleo_f401re.cfg; do
if [ -f "$OPENOCD_BOARD_DIR/$fn" ]; then
OPENOCD_PROC_FILE="$fn"
fi
done
fi
$OPENOCD -f $OPENOCD_BOARD_DIR/$OPENOCD_PROC_FILE &
GDB=arm-none-eabi-gdb
$GDB -ex "target remote localhost:3333" -ex "set remote hardware-breakpoint-limit 6" -ex "set remote hardware-watchpoint-limit 4" $PROJ.elf
kill -9 $(pidof $OPENOCD)