STM32/ARM Cortex-M3 HOWTO: Development under Ubuntu (Debian)

start_server.bsh

When it comes to OpenOCD and what config to load, it does takes some time to create the uniq config file for your target and the jtag you use. So OpenOCD has a method of loading multiple config files, and it also provides some config files that for those parts.

To illustrate this I created a small script called start_server.bsh, for now it lives in the FunTechCortexMX_test project over at github.

Let's have a look at this script.

Filename: start_server.bsh

#!/bin/bash 

#First a check if OpenOCD is installed.
which openocd 
if [ "$?" != "0" ]
then
    echo "OpenOCD is not in the path" 
    exit 1
fi

#Then where is it installed? 
if [ -d /usr/local/share/openocd/ ]
then
    echo "Using local openocd install"
    cfg_path="/usr/local/share/openocd/scripts/"
else
    echo "Using the openocd package"
    cfg_path="/usr/share/openocd/scripts/"
fi

cfg_port="res/openocd_ports.cfg"


#What jtag is connected?
#Olimex jtag?
lsusb -d 15ba:0003
if [ "$?" == "0" ]
then
    echo "Found: ID 15ba:0003 Olimex Ltd. OpenOCD JTAG"
    cfg_interface=$cfg_path"interface/olimex-arm-usb-ocd.cfg"
fi

#Flyswatter jtag?
lsusb -d 0403:6010
if [ "$?" == "0" ]
then
    echo "Found: ID 0403:6010 Future Technology Devices International, Ltd FT2232C Dual USB-UART/FIFO IC"
    cfg_interface=$cfg_path"interface/flyswatter.cfg"
fi

#And stop right here if we don't have one
if [ "$cfg_interface" == "" ]
then
    echo "No jtag found"
    exit 1
fi


# Then it is hard to guess what target we have connected to the jtag, 
# so that is something you need to add yourself...

#cfg_target=$cfg_path"target/lpc1768.cfg"
#cfg_target=$cfg_path"target/stm32.cfg"
cfg_target=$cfg_path"board/olimex_stm32_h103.cfg"


# Then check so the different config files can be found on the system.
if [ ! -d $cfg_path ] 
then 
    echo "Error cfg_path" $cfg_path
    exit 1
fi

if [ ! -f $cfg_port ] 
then 
    echo "Error cfg_port" $cfg_port
    exit 1
fi

if [ ! -f $cfg_interface ] 
then 
    echo "Error cfg_interface" $cfg_interface
    exit 1
fi

if [ ! -f $cfg_target ] 
then 
    echo "Error cfg_target" $cfg_target
    exit 1
fi

# If the server is not running, then we start it.
if [ `ps -A | grep openocd | wc -l` = 0 ]
then
    echo "Start the OpenOCD server"
    xterm -e "openocd -f $cfg_port -f $cfg_interface -f $cfg_target -s $cfg_path" &
    #openocd -f $cfg_port -f $cfg_interface -f $cfg_target -s $cfg_path &

    # Then wait some time so OpenOCD has some time to configure the jtag.
    sleep 5
fi

#Did it start? 
if [ `ps -A | grep openocd | wc -l` = 0 ]
then
    exit 1
fi

# kill `ps -A | grep openocd | awk '{print $1}'`

echo "OpenOCD should be running now."
exit 0

Filename: openocd_ports.cfg

#daemon configuration
telnet_port 4444
gdb_port 3333

Have fun.

Fatal error: Uncaught Error: Call to a member function link_ext() on null in /customers/9/b/5/fun-tech.se/httpd.www/stm32/class.page.php:62 Stack trace: #0 /customers/9/b/5/fun-tech.se/httpd.www/stm32/OpenOCD/start_server.php(64): page->getFoot() #1 {main} thrown in /customers/9/b/5/fun-tech.se/httpd.www/stm32/class.page.php on line 62