aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Goger <klaus.goger@theobroma-systems.com>2017-06-01 14:34:19 +0200
committerKlaus Goger <klaus.goger@theobroma-systems.com>2017-06-01 15:00:52 +0200
commit15c965c129243e9e7899ab48a9e8495db19c11a5 (patch)
treec00d5888c229638c0d5cf900e4a1c599b291b4cd
parent8a906eba82e7292549e85e00583c364dfcb7ed6e (diff)
import companion controller tools
Most Theobroma Systems SoMs feature a Cortex-M0 companion controller. This commit includes: * a shell script for resetting and flashing the MCU * a OpenOCD config file for onboard debugging
-rw-r--r--companion-controller/README.md30
-rwxr-xr-xcompanion-controller/cortex-m0.sh124
-rw-r--r--companion-controller/openocd.cfg30
3 files changed, 184 insertions, 0 deletions
diff --git a/companion-controller/README.md b/companion-controller/README.md
new file mode 100644
index 0000000..226e8cb
--- /dev/null
+++ b/companion-controller/README.md
@@ -0,0 +1,30 @@
+# cortex-m0.sh
+
+`cortex-m0.sh` is a helper script to control the on-module companion controller.
+
+Parameters:
+
+ --reset - resets the Cortex M0
+ --dfu - enables DFU loader
+ --disable - keep Cortex M0 in reset
+ --flash [<firmware>] - flash the given firmware
+
+# openocd.cfg
+
+On some modules GPIO based SWD support is available. A config file is
+provided in the tools directory.
+
+ openocd -f tools/openocd.cfg
+
+To select a specific board set the q7_module variable
+
+ openocd -c "set q7_module a64" -f tools/openocd.cfg
+
+OpenOCD in Debian Stretch and Ubuntu Xenial are missing the sysfsgpio
+interface and you have to rebuild it from sourceāˆµ
+
+ git clone git://repo.or.cz/openocd.git openocd-code
+ cd openocd-code
+ ./bootstrap
+ ./configure --exec-prefix=~/openocd --prefix=~/openocd --enable-sysfsgpio
+ make && make install
diff --git a/companion-controller/cortex-m0.sh b/companion-controller/cortex-m0.sh
new file mode 100755
index 0000000..7f259b0
--- /dev/null
+++ b/companion-controller/cortex-m0.sh
@@ -0,0 +1,124 @@
+#!/bin/bash
+
+SYSFSPATH=/sys/class/gpio
+
+# defaults
+RESET_INVERT=0
+BOOT0_INVERT=0
+FIRMWARE=/usr/local/share/cortex-m0/cortex-m0.dfu
+
+die() {
+ echo "$*" 1>&2
+ exit 1
+}
+
+usage() {
+ echo "Usage: $0 [--reset|--dfu|--disable|--flash [<firmwarea>]]"
+ echo " --reset - resets the Cortex M0"
+ echo " --dfu - enables DFU loader"
+ echo " --disable - keep Cortex M0 in reset"
+ echo " --flash [<firmware>] - flash the given firmware"
+
+ exit 1
+}
+
+gpiosetup() {
+ for PIN in ${RESET_PIN},${RESET_INVERT} ${BOOT0_PIN},${BOOT0_INVERT}
+ do
+ IFS=',' read PINNUM INVERT <<< "${PIN}"
+ if [ ! -d ${SYSFSPATH}/gpio${PINNUM} ] ; then
+ echo ${PINNUM} > ${SYSFSPATH}/export
+ fi
+ echo out > ${SYSFSPATH}/gpio${PINNUM}/direction
+ echo ${INVERT} > ${SYSFSPATH}/gpio${PINNUM}/active_low
+ done
+}
+
+reset_stm32() {
+ echo 0 > ${SYSFSPATH}/gpio${RESET_PIN}/value
+ echo 0 > ${SYSFSPATH}/gpio${BOOT0_PIN}/value
+ sleep 0.1
+ echo 1 > ${SYSFSPATH}/gpio${RESET_PIN}/value
+}
+
+enable_dfu() {
+ gpiosetup
+ echo 0 > ${SYSFSPATH}/gpio${RESET_PIN}/value
+ echo 1 > ${SYSFSPATH}/gpio${BOOT0_PIN}/value
+ sleep 0.1
+ echo 1 > ${SYSFSPATH}/gpio${RESET_PIN}/value
+}
+
+[ -f /proc/device-tree/model ] || die "can't determine hardware version"
+
+MODEL=$(cat /proc/device-tree/model | tr -d '\000')
+
+case "$MODEL" in
+ "Theobroma Systems A31 Pangolin")
+ RESET_PIN=90
+ BOOT0_PIN=67
+ ;;
+ "Theobroma Systems A80 Armadillo")
+ RESET_PIN=128
+ BOOT0_PIN=129
+ ;;
+ "Theobroma Systems A64-uQ7 SoM")
+ RESET_PIN=195
+ BOOT0_PIN=197
+ ;;
+ "Theobroma Systems RK3399-Q7 SoM")
+ RESET_PIN=56
+ BOOT0_PIN=76
+ RESET_INVERT=1
+ BOOT0_INVERT=1
+ ;;
+ *)
+ die "${MODEL} not supported"
+ ;;
+esac
+
+case "$1" in
+--reset) echo "reseting Cortex M0"
+ gpiosetup
+ reset_stm32
+ ;;
+--dfu) echo "enabling DFU loader"
+ gpiosetup
+ enable_dfu
+ ;;
+--disable) echo "disabling Cortex M0"
+ gpiosetup
+ echo 0 > ${SYSFSPATH}/gpio${RESET_PIN}/value
+ ;;
+--flash)
+ if [ $# -eq 2 ] ; then
+ [ -f "$2" ] || die "flash file ${2} does not exist"
+ FIRMWARE=$2
+ elif [ $# -gt 2 ] ; then
+ usage
+ fi
+ command -v dfu-util >/dev/null 2>&1 || die "dfu-util needed but not found"
+ echo "flashing Cortex M0"
+ gpiosetup
+ enable_dfu
+ echo waiting for DFU loader
+ if command -v lsusb >/dev/null 2>&1; then
+ while ! lsusb -d 0483:df11 > /dev/null
+ do
+ sleep .1
+ echo -n .
+ done
+ echo -e "\nfound"
+ else
+ sleep 5
+ fi
+ dfu-util -a 0 -D ${FIRMWARE}
+ reset_stm32
+ ;;
+--*) usage
+ ;;
+*) usage
+ ;;
+esac
+
+exit 0
diff --git a/companion-controller/openocd.cfg b/companion-controller/openocd.cfg
new file mode 100644
index 0000000..71a1297
--- /dev/null
+++ b/companion-controller/openocd.cfg
@@ -0,0 +1,30 @@
+interface sysfsgpio
+
+if { ! [ info exists q7_module ] } {
+# set default module here
+ set q7_module rk3399
+}
+
+switch $q7_module {
+ rk3399 {
+ sysfsgpio_swdio_num 106
+ sysfsgpio_swclk_num 111
+ sysfsgpio_srst_num 45
+ echo "INFO: If reset isn't working set SRST to active low"
+ echo "INFO: echo 1 > /sys/class/gpio/gpio45/active_low"
+ }
+
+ a64 {
+ sysfsgpio_swdio_num 131
+ sysfsgpio_swclk_num 130
+ sysfsgpio_srst_num 195
+ }
+
+ default {
+ echo "Error: Unkown module $q7_module"
+ shutdown
+ }
+}
+
+transport select swd
+source [find target/stm32f0x.cfg]