Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow flashing Olimex board with different devices. #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions scripts/flash.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
#!/bin/bash

if [ $1 = "olimex-stm32-e407" ]; then
openocd -f interface/ftdi/olimex-arm-usb-ocd-h.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"
elif [ $1 = "stm32l1" ]; then
# Source tools
currdir="${0%/*}"
. $currdir/tools.sh

# lsusb dependency installation
install_dep usbutils

if [ $1 = "olimex-stm32-e407" ];then
if lsusb -d 15BA:002a; then
openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"
elif lsusb -d 15BA:0003;then
openocd -f interface/ftdi/olimex-arm-usb-ocd.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"
elif lsusb -d 15BA:002b;then
openocd -f interface/ftdi/olimex-arm-usb-ocd-h.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"
else
echo "Error. Unsuported olimex-stm32-e407 flashing device. Try openocd"
fi
elif [ $1 = "stm32l1" ];then
openocd -f interface/stlink-v2.cfg -f target/stm32l1.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"
else
echo "Error. Try: ./flash.sh olimex-stm32-e407 or ./flash.sh stm32l1"
fi

49 changes: 49 additions & 0 deletions scripts/tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash


# Returns if a command is available in the current machine
function has_command() {
command -v "$1" >/dev/null 2>&1
}

# Sets multiple variables with system specifics.
# INSTALL_COMMAND: is the package manager of the linux distribution
# INSTALL_OPTIONS: are the options to install packages without any input from the user required
# INSTALL_QUERY: command and options to use for checking the existence of packages.
function set_host_installer() {
if [ -f /etc/arch-release ]; then
if has_command pacman; then
INSTALL_COMMAND="pacman"
INSTALL_OPTIONS="-S"
INSTALL_QUERY="pacman -Qi"
fi
elif [ -f /etc/debian_version ]; then
if has_command apt-get; then
INSTALL_COMMAND="apt-get"
INSTALL_OPTIONS="install -y"
INSTALL_QUERY="dpkg -s"
fi
fi
}

# Takes a list of pakages and sets MISSING_PKGS with those missing in the current system.
function filter_installed() {
for package in "$@"
do
if $INSTALL_QUERY $package; then
echo $package "Already installed"
else
MISSING_PKGS+=" "$package
fi
done
}

# Install the list of packages in the current system.
function install_dep() {
set_host_installer
filter_installed "$@"
if ! test -z MISSING_PKGS; then
$INSTALL_COMMAND $INSTALL_OPTIONS $MISSING_PKGS
fi

}