Skip to content
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
66 changes: 66 additions & 0 deletions STM32Resources/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
= Compiling and Flashing STM Board on Linux

. Go to StudentOrganisationForAerospaceResearch repo > DevelopmentResources, and clone.

. Navigate to STM32Resources and run the auto installer using `sudo ./install.sh`.
This should download STLink, gcc4mbed, and CubeMX2Makefile and add them all to the path.

. http://www.st.com/en/development-tools/stm32cubemx.html[Go to the download page of the official ST website by clicking this link^].

. Scroll to the bottom of the page to the *GET SOFTWARE* section and click *Get Software*.

. Follow the instructions and download CubeMX.

. Extract files from `.zip` file using a preferred method.
For example, use `unzip file.zip`.

. Navigate to the directory the files were extracted to.

. Run *SetupSTM32CubeMX-VERSION.linux* using `./SetupSTM32CubeMX-{var}.linux` where {var} is the version of CubeMx that is being installed.

. Follow the instructions in the Installation Wizard.


== Generating Code with CubeMX

. Open CubeMX. The default path is `~/STM32CubeMX`.

. Select New Project.

. Click on the Board Selector Tab and scroll to STM32F4DISCOVERY then click OK.

. Go to Project > Settings.

. Name the project, set the project location, and change the Toolchain/IDE to SW4STM32.
*If this isn't done, CubeMX2Makefile won't work!*
CubeMX2Makefile looks for an SW4STM32 project which was created by CubeMX.
If the Toolchain/IDE is not set to SW4STM32, it will be in the format of a different IDE, not CubeMX.
For example, EWARM is for the IAR Embedded Workbench IDE and CubeMX2Makefile will not know what to do with that format.

. Make note of the Toolchain Folder Location, which will also be the project folder location.

. Click OK and download any dependencies that are needed, then click OK again.

. Make pin assignments then go to Project > Generate Code, and then save project.


== Generating a Makefile and Compiling

. Create the makefile using `CubeMX2Makefile /path/to/project/folder`.

. Go to the directory that the Makefile was made then compile using `make`.
* Need to double check that the right compiler is being used. In our case, this would be `arm-none-eabi-g++`.
** If your system has different type of arm compilers installed, they should be removed using `sudo dnf remove compilername` to prevent ambiguity

. Navigate to the build directory and there should be a `<project>.bin` file. Where `<project>` is the project name.

== Flashing
Flashing is how the `.bin` that was made is put onto the board. This is how the processor on the board is able to carry out the instructions that were generated from the code.

To flash the board use `st-flash write /path/to/project/build/<project>.bin 0x8000000`.

If a board isn't connected, and it ran successfully, the output should be:
----
st-flash 1.3.0-dev
DATE/TIME WARN /opt/stlink/src/usb.c: Couldn't find any ST-Link/V2 devices
----
40 changes: 32 additions & 8 deletions STM32Resources/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,30 @@ if [[ $UID != 0 ]]; then
exit 1
fi

apt-get -y install build-essential git libsane:i386 ia32-libs-multiarch autoconf libusb-1.0-0-dev lib32ncurses5 libncurses5:i386 software-properties-common pkg-config cmake
# Determine what distribution of Linux the user has
DISTRO= $(. /etc/os-release; echo $NAME)

# Install files according to Linux distribution that the user has
if [ "$DISTRO" = "Ubuntu" ]; then
BASH_PROFILE = "~./profile" # set bash profile
apt-get -y install build-essential git libsane:i386 ia32-libs-multiarch autoconf libusb-1.0-0-dev lib32ncurses5 libncurses5:i386 software-properties-common pkg-config cmake

elif [ "$DISTRO" = "Fedora" ]; then
BASH_PROFILE = "~./bashrc" # set bash profile

# Install necessary 32-bit compliant packages
dnf install --skip-broken glibc.i686 arts.i686 audiofile.i686 bzip2-libs.i686 cairo.i686 cyrus-sasl-lib.i686 dbus-libs.i686 directfb.i686 esound-libs.i686 fltk.i686 freeglut.i686 gtk2.i686 hal-libs.i686 imlib.i686 lcms-libs.i686 lesstif.i686 libacl.i686 libao.i686 libattr.i686 libcap.i686 libdrm.i686 libexif.i686 libgnomecanvas.i686 libICE.i686 libieee1284.i686 libsigc++20.i686 libSM.i686 libtool-ltdl.i686 libusb.i686 libwmf.i686 libwmf-lite.i686 libX11.i686 libXau.i686 libXaw.i686 libXcomposite.i686 libXdamage.i686 libXdmcp.i686 libXext.i686 libXfixes.i686 libxkbfile.i686 libxml2.i686 libXmu.i686 libXp.i686 libXpm.i686 libXScrnSaver.i686 libxslt.i686 libXt.i686 libXtst.i686 libXv.i686 libXxf86vm.i686 lzo.i686 mesa-libGL.i686 mesa-libGLU.i686 nas-libs.i686 nss_ldap.i686 cdk.i686 openldap.i686 pam.i686 popt.i686 pulseaudio-libs.i686 sane-backends-libs-gphoto2.i686 sane-backends-libs.i686 SDL.i686 svgalib.i686 unixODBC.i686 zlib.i686 compat-expat1.i686 compat-libstdc++-33.i686 openal-soft.i686 alsa-oss-libs.i686 redhat-lsb.i686 alsa-plugins-pulseaudio.i686 alsa-plugins-oss.i686 alsa-lib.i686 nspluginwrapper.i686 libXv.i686 libXScrnSaver.i686 qt.i686 qt-x11.i686 pulseaudio-libs.i686 pulseaudio-libs-glib2.i686 alsa-plugins-pulseaudio.i686

# Install cmake
dnf install cmake

# Install libusb library
dnf install libusbx-devel-1.0.21-2.fc26.x86_64 #This is a 64 bit compliant package
dnf install libusbx-devel-1.0.21-2.fc26.i686 #This is a 32 bit compliant package
else
echo "Sorry, your system is not supported!"
exit 1
fi

# Install STLink
if ! type "st-flash" > /dev/null; then
Expand All @@ -17,10 +40,11 @@ if ! type "st-flash" > /dev/null; then
ln -s /opt/stlink/build/st-flash /usr/local/bin/st-flash
ln -s /opt/stlink/build/st-info /usr/local/bin/st-info
ln -s /opt/stlink/build/src/gdbserver/st-util /usr/local/bin/st-util
echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/opt/stlink/build" >> ~/.profile
echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/opt/stlink/build" >> $BASH_PROFILE
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/stlink/build
echo "export PATH=\$PATH:/opt/stlink/build" >> ~/.profile
echo "export PATH=\$PATH:/opt/stlink/build" >> $BASH_PROFILE
export PATH=$PATH:/opt/stlink/build
cp ~/.bashrc /root/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to use the $BASH_PROFILE var.

else
echo "*** ST Link already installed"
fi
Expand All @@ -34,7 +58,7 @@ if ! type "CubeMX2Makefile" > /dev/null; then
echo "ABS_PATH=\"\$(readlink -f \$1)\"" >> /usr/local/bin/CubeMX2Makefile
echo "(cd /opt/CubeMX2Makefile && python CubeMX2Makefile.py \$ABS_PATH)" >> /usr/local/bin/CubeMX2Makefile
chmod +x /usr/local/bin/CubeMX2Makefile
echo "export PATH=\$PATH:/opt/CubeMX2Makefile" >> ~/.profile
echo "export PATH=\$PATH:/opt/CubeMX2Makefile" >> $BASH_PROFILE
export PATH=$PATH:/opt/CubeMX2Makefile
else
echo "*** CubeMX2Makefile already installed"
Expand All @@ -48,13 +72,13 @@ if [ ! -d "/opt/gcc4mbed" ]; then
chmod +x linux_install && \
sed -i '108d;109d;110d;147d' linux_install && \
./linux_install)
if ! grep "export PATH=\$PATH:/opt/gcc4mbed/gcc-arm-none-eabi/bin/" ~/.profile; then
echo "export PATH=\$PATH:/opt/gcc4mbed/gcc-arm-none-eabi/bin/" >> ~/.profile
if ! grep "export PATH=\$PATH:/opt/gcc4mbed/gcc-arm-none-eabi/bin/" $BASH_PROFILE; then
echo "export PATH=\$PATH:/opt/gcc4mbed/gcc-arm-none-eabi/bin/" >> $BASH_PROFILE
fi
export PATH=$PATH:/opt/gcc4mbed/gcc-arm-none-eabi/bin/
else
echo "*** ARM compiler already installed"
fi

# Sourcing Profile
source ~/.profile
# Sourcing
source $BASH_PROFILE #sourcing the appropriate profile