Nucleo Boards

From RobolaboWiki
Revision as of 16:23, 4 September 2016 by Aguti (Talk | contribs)

Jump to: navigation, search

Configuring the environment

Install Compiler gcc-arm-none-eabi

Download last version of GCC ARM Embedded from: https://launchpad.net/gcc-arm-embedded/+download

Untar the compiler:

tar -xvjf gcc-arm-none-eabi-<VERSION>.tar.bz2

Copy it to a common place:

sudo cp -r gcc-arm-none-eabi-<VERSION> /opt/compilerNucleoST

Install OpenOCD On-Chip Debugger

Instal dependencies:

sudo apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo build-essential \\
libftdi-dev libusb-1.0-0-dev libexpat1-dev

Download last version of Openocd from: http://openocd.org/

Untar openocd:

tar -xvzf openocd-<VERSION>.tar.gz

Go into the directory:

cd openocd-<VERSION>

Configure openocd compilation:

./configure --prefix=/opt/openocdNucleoST --enable-maintainer-mode --enable-stlink

Compile it:

make

Install:

sudo make install

Prepare its use according to udev:

sudo cp -r contrib/99-openocd.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules

In order to connect to the device:

openocd -s /opt/openocdNucleoST/share/openocd/scripts/ -f openocd.cfg -c "init" -c "halt" -c "reset halt"

where openocd.cfg should be on your working dir.

Hello World experiment

Download STMCube

STMicroelectronics introduces STMCube as an initiative to ease developers life. They are sharing packages containing libraries, documentation and examples. Packages are delivered per series (such as STM32CubeF4 for STM32F4 series)

Go: http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/LN1897?icmp=tt2930_gl_pron_oct2015&sc=stm32cube-pr14

And select the STMCubeXX according to your microcontroller (e.g. STM32CubeL4 for STM32L4 series) and load it in a prefered directory:

Untar STM32CubeXX:

unzip stm32cubexx.zip

This will create a Firmware directory which will be referred in this tutorial as <STM32_CUBE_FW_ROOTDIR>.

Create the experiment

The example is done for a toggle led experiment. It will be compiled for a specific nucleo board, named in this tutoral as <STM32_NUCLEO_BOARD>.

Create experiment dir in your prefered directory:

mkdir helloWorld
mkdir helloWorld/bin

Copy experiment sources:

cp -r <STM32_CUBE_FW_ROOTDIR>/Projects/<STM32_NUCLEO_BOARD>/Examples/GPIO/GPIO_IOToggle/Src hellowWorld/src
cp -r <STM32_CUBE_FW_ROOTDIR>/Projects/<STM32_NUCLEO_BOARD>/Examples/GPIO/GPIO_IOToggle/Inc helloWorld/include

Copy STM32 libraries:

cp -r <STM32_CUBE_FW_ROODIR>/Drivers/ helloWorld/lib

Copy startup code to src dir:

cp <STM32_CUBE_FW_ROOTDIR>/Projects/<STM32_NUCLEO_BOARD>/Templates/SW4STM32/startup_<NUCLEO_BOARD>.s helloWorld/src

where <NUCLE_BOARD> refers to your nucleo board model.

Important If SW4STM32 does not exists use TrueStudio instead.


Copy linker file:

cp <STM32_CUBE_FW_ROOTDIR>/Projects/<STM32_NUCLEO_BOARD>/Templates/SW4STM32/<STM32_NUCLEO_BOARD>_Nucleo/<NUCLEO_BOARD>_FLASH.ld helloWorld/

where <NUCLE_BOARD> refers to your nucleo board model.

Important If TrueStudio does not exists use SW4STM32 instead.


Create an environment file to export PATH:

cd helloWorld
echo $PATH > env.sh

Edit env.sh and at the begining of the line include:

export PATH=/opt/openocdNucleoST/bin:/opt/compilerNucleoST/bin:

Your file should look like this:

export PATH=/opt/openocdNucleoST/bin:/opt/compilerNucleoST/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games


Download Makefile , rename it as "Makefile" and copy it to <HELLOWORLD> dir.

Open makefile and substitute:

  • <PROJECT_NAME> with the name you want to give to your project
  • <STM32_NUCLEO_BOARD> with the nucleo board name (e.g. STM32F4xx).
  • <STM32_LNKER_FILE> with the name of the linker file in <HELLOWORLD> dir (e.g. STM32F446RETx_FLASH.ld)
  • <STM32_MICROCONTROLLER> with the compilation directive of your microcontroller (e.g. STM32F446xx) found in src/system_stm32xxxx.c
  • <CPU_INFO> with the mcpu of the controller (e.g. cortex-m0plus)
  • <STARTUP_NAME> with the name of your startup filename. (e.g. startup_stm32f446xx) found in src dir (important: name it without extension).