#! /bin/sh
# This is a wrapper script to be run by the Lazarus IDE when interactively
# debugging a Raspberry Pi Pico (RP2040 etc.) using a second Pico with the
# Picoprobe firmware. It automatically starts a terminal emulator, plus a
# copy of OpenOCD in the background typically listening for a gdb connection
# on port 3333.
#
# To bring GNU Screen to the foreground use the screen -r command. To send
# it to the background use <Ctrl>ad To terminate it when used as a terminal
# emulator use <Ctrl>ak and confirm the prompt. MarkMLl
#############################################################################
# Specify the serial port provided by the Picoprobe. This is likely to change
# whenever it is removed and replaced, particularly if there are other USB
# devices of the communications class.
UART=/dev/ttyACM0
# Specify the location of the OpenOCD binary, and command lines for the most
# popular terminal emulators.
OPENOCD=/usr/local/share/fpcupdeluxed/ccr/develtools4fpc/bin/openocd-rp2040
GTKTERM="gtkterm -p $UART -s 115200"
MINICOM="minicom -D $UART -b 115200"
SCREEN="screen $UART 115200"
# Specify which of the above terminal emulators is to be used.
TERMINALEMULATOR=$GTKTERM
# Start the terminal emulator and a copy of OpenOCD if not already running.
# If one or the other has been terminated it will be necessary to clean up
# manually (see note on using GNU Screen etc. at the start of this file).
if [ ! -d /proc/`cat $HOME/openocd.3333`/fd ] ; then
$TERMINALEMULATOR > /dev/null 2>&1 &
screen -d -m $OPENOCD -f board/pico.cfg
ps ax | grep pico.cfg | grep Ssl | cut -d ' ' -f 1 > $HOME/openocd.3333
echo -n 'OpenOCD started'
else
echo -n 'OpenOCD already running'
fi
echo ", PID `cat $HOME/openocd.3333`"