Skip to content

Commit

Permalink
Added bin/xstm32cubeide .
Browse files Browse the repository at this point in the history
  • Loading branch information
waynegramlich committed Mar 28, 2021
1 parent d126ac7 commit 9ed6e6d
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,11 @@ The current files in the `bin` directory are:
environment that has been configured to work with the `stm32cube` software for supporting
STM32 micro-controllers.

* `xstm32cubeid`:
This is a shell script that attempt to attach to an externel (i.e. remote) ST-Link
before starting the stm32cube.
This is preformed using an the `usbip` (i.e. USB Internet Protocol) for remote access to USB devices.

More scripts are likely to be added over time.

#### Coding Style
Expand Down
103 changes: 103 additions & 0 deletions bin/xstm32cubeid
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
# This file is licensed using the "MIT License" below:
#
####################################################################################################
#
# MIT License
#
# Copyright 2021 Home Brew Robotics Club
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
####################################################################################################
#<---------------------------------------- 100 Characters ---------------------------------------->#

# A program to run the stm32cubeid with a remote connection to the ST-Link on the nucleo.
#
# This code makes a destinction between whether the HR2_REMOTE environment variable in one of 3 states:
#
# 1. Unset:
# In the unset state, no attempt is made to attach to the remote ST-Link.
# An annoying message is output to tell the user to set the HR2_REMOTE environment variable.
# 2. Set to empty:
# When set to the empty string, the user is saying, do not bother with attempt to to attach
# to a remote ST-Link. No annoying message is generated either.
# 3. Set to non-empty:
# When set to an none empty value, this code will attempt to find and attach to the ST-Link
# device on that machine.
#
# This is accomplished by a very obsure bash syntax that goes by the name of "parameter expanson".
# The syntax is ${VAR+DEFAULT} returns the value of VAR if it is set and "DEFAULT" if it is not set.
# You have been warned.

PORT_NAME=""
if [ "$HR2_REMOTE" ]
then
# HR2_REMOTE is non-empty. Search for remote ST-link.
if [ "$(which usbip)" ]
then
BUS_NAME=$(usbip list -r "$HR2_REMOTE" 2>&1 | grep 0483 | sed "s,:.*,," | sed "s, *,,g")
if [ "$BUS_NAME" ]
then
echo "You may be prompted for your sudo password (i.e. your login password)."
echo "Attempting attach to ST-Link at $HR2_REMOTE via $BUS_NAME ..."
sudo usbip attach -r "$HR2_REMOTE" -b "$BUS_NAME"
sleep 5
PORT_NAME="$(usbip port 2>&1 | grep Port | sed 's,Port ,,' | sed 's,:.*,,')"
echo "PORT_NAME=$PORT_NAME"
if [ "$PORT_NAME" ]
then
echo "Remote ST-Link appears to have been found."
else
echo "Remote ST-Link was found, but attach failed."
fi
else
echo "Unable to find remote ST-Link."
fi
else
echo "/usb/bin/usbip is not installed. Not attempting to find remote ST-Link."
fi
else
# See the comment about bash parameter expansion to understand what the '+' is doing.
# HR2_REMOTE is either empty or not set:
if [ ! "${HR2_REMOTE+IS_SET}" ]
then
# HR2_REMOTE is not set; let the user know that they have to set this value:
echo "HR2_REMOTE environment variable is not set; not searching for remote ST-Link."
echo "Set HR2_REMOTE to empty string to suppress this message."
echo "For example, `export HR2_REMOTE=''`"
# elses
# HR2_REMOTE is set to empty value; means the user does not want to try to find remote STM.
# echo "HR2_REMOTE is set to an empty string" # For debugging only
fi
fi

# Now run stme32cubeide:
stm32cubeide

# Attempt to detach from ST-Link
if [ "$PORT_NAME" ]
then
echo "Attempting to detach from ST-Link. (sudo may prompt for password)"
sudo usbip detach -p "$PORT_NAME"
PORT_NAME="$(usbip port 2>&1 | grep Port | sed 's,Port ,,' | sed 's,:.*,,')"
if [ "$PORT_NAME" ]
then
echo "Detach failed"
fi
fi
33 changes: 30 additions & 3 deletions software/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
<!--
MIT License
Copyright 2020-21 Home Brew Robotics Club
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
-->

# HR2 Robot Software

<!-- ==================================== 100 Characters ======================================= -->
Expand Down Expand Up @@ -833,7 +856,7 @@ The basic steps are as follows:
3. [Create a New User Account](#create-a-new-user-account):
It is useful to create a new user account with `sudo` access.

4. [Set Up Zero Configuration](#set-up-zero_configuration):
4. [Set Up Zero Configuration](#set-up-zero-configuration):
This allows you to be able to connect to the robot with the robot name.

5. [Login into Robot from Development Computer](#login-into-robot-from-development-computer):
Expand All @@ -842,7 +865,11 @@ The basic steps are as follows:
6. [Configure Wifi](#configure-wifi):
Configure your WiFi access.

7. [Final Configuration Notes](#final-configuration-notes):
7. [Remote USB Installation](#remote-usb-installation):
This configures a system call `usbip`
for remote access to the ST-Link device on the Robot Microcontroller.

8. [Final Configuration Notes](#final-configuration-notes):
Some final comments on configuration.

##### Change the login password:
Expand Down Expand Up @@ -1160,7 +1187,7 @@ Run the `usbip` command:

usbip list -l # List various local (i.e. `-l`) USB ports

<!-- USBIB Notes:
<!-- USBIP Notes:
`usbip` is a protocol for connecting
Expand Down

0 comments on commit 9ed6e6d

Please sign in to comment.