Stm32f4

1. Install packages
Get the actual ecpilse from www.eclipse.org
then

sudo apt-get install git zlib1g-dev libtool flex 
bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev 
autoconf texinfo build-essential libftdi-dev libusb-1.0.0-dev pkg-config

2. Download the gcc-arm-none-eabi-linux package from

https://launchpad.net/gcc-arm-embedded

tar xjvf gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2 
sudo mv gcc-arm-none-eabi-4_8-2014q1 /opt/ARM
echo "PATH=$PATH:/opt/ARM/bin" >> ~/.bashrc
source ~/.bashrc 
arm-none-eabi-gcc --version

3. Install ST-Link

The STM32F4 Discovery has the STLinkV2 programmer on board. The stlink tool for linux is available only as source code and needs to be compiled first:

username@linux:~/$ mkdir src && cd src
git clone git://github.com/texane/stlink.git
cd stlink
./autogen.sh
./configure
make

Okay so now the stlink tool needs to be installed and made availabe via the PATH variable.

sudo mkdir /opt/stlink
cd /opt/stlink
sudo cp ~/src/stlink/st-flash .
sudo cp ~/src/stlink/st-util .
echo "PATH=$PATH:/opt/stlink" >> ~/.bashrc
source ~/.bashrc

Now both tools need to be granted access of the devices via USB.
For STlink/V2 dongles (as found on STM32F4 Discovery) it’s as simple as:

sudo cp ~/src/stlink/49-stlinkv2.rules /etc/udev/rules.d
sudo udevadm control --reload-rules

4. Setting up a working directory
If you’re using the STM32F4 Discovery, clone from here:

mkdir stm32
cd stm32
git clone git://github.com/Torrentula/STM32F4-workarea.git

5. Reading and writing flash from STM32F4 (as backup for example)

st-flash read backup.bin 0x08000000

erasing device

st-flash erase

covert any hexfile to a binary by

arm-none-eabi-objcopy -I ihex -O binary my.hex my.bin

write back to device

st-flash write my.bin 0x08000000

6. Installing the GNU-ARM-Toolchain in Eclipse follow the following links:
http://www.emb4fun.de/archive/eclipse/index.html
http://gnuarmeclipse.livius.net/blog/
http://mcuoneclipse.com/2013/07/21/diy-free-toolchain-for-kinetis-part-2-eclipse-ide/

7. Create a Eclipse project (Blinky - GNU ARM Plugin Example)

  • Open a new C-Project give a name and select "STM32F4xx C/C++ Project" then NEXT ->
  • Select your chip "STM32F429" and select the content "Blinky" then NEXT -> NEXT -> FINISH
  • Select the toolchain path "/opt/ARM/bin"
  • Open file "BlinkLed.h" and change the pin for the LED according to your device (e.g. the STM32F429-Discovery requires Pin PG13 for the green LED: Port=6 Pin=13 Active=High)
  • Under "Project->Properties->C/C++Build->Settings->Cross ARM C Compiler—>Preprocessor" the selected device can be changed (e.g. change from STM32F429 to STM32F407)
  • Under "Project->Properties->C/C++Build->Settings->Cross ARM GNU Create Flash Image->General" the output format can be selected to be BIN (ihex is default, rawbinary is required for flashing)
  • To build the project, press the "Hammer" symbol (Build Button), a successfull build creates a .bin file that can be flashed into the target with st-flash

8. Setting up OpenOCD:
Download the latest OpenOCD version from: http://sourceforge.net/projects/openocd/files/openocd/
Make and install as in the Readme-File (./configure; make; sudo make install) !
In eclipse: "Run->ExternalTools->ExternalToolsConfiguration->New Config" add "Location: /usr/local/bin/openocd", "WorkingDirectory: ${project_loc}", "Arguments: -f board/stm32f429discovery.cfg"

9. Setting up the debugger:
"Run->Debug configurations…->GDBHardwareDebugging->*projectname* Debug->Debugger: /opt/ARM/bin/arm-none-eabi-gdb" with Port number 3333 (for stm32f429discovery-board). The run the external tool (openocd).
On sucessfull connection to the board, the console will show the board core voltage and the number of hardware breakpoints.
The press the debug button and start debugging (switch to the Debug-View-Perspecive).

10. Setup Eclipse workspace for usage with STM32Cube Libraries and Examples

  • The STM32Cube includes the STM32Cube libraries from a "old" version. First replace the libraries in your project:
    • under "/system/src/stm32f4-hal" and "../system/include/stm32f4-hal" by the latest STM32Cube libs.
    • under "/system/include/cmsis/" replace by the latest STM32Cube libs from "STM32Cube_FW_F4_V1.3.0/Drivers/CMSIS/Include"
    • under "/system/include/cmsis/" replace by the latest STM32Cube libs from "STM32Cube_FW_F4_V1.3.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include"
    • keep "/system/include/cmsis/cmsis_device.h"
    • under "/system/src/cmsis" replace "system_stm32f4xx.c" by the latest STM32Cube libs from "STM32Cube_FW_F4_V1.3.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c"
  • Enable all files under "../system/src/stm32f4-hal" to be included in the build (right click->Resource configurations->Exclude from build)
  • To run examples for the STM32F429-disco board, copy the files from "STM32Cube_FW_F4_V1.3.0/Drivers/BSP/STM32F429I-Discovery" to the project "/src" and "/include" directories.
  • In "/include" remove the old "stm32f4xx_hal_conf.h" with the "stm32f4xx_hal_conf_template.h" from "/system/include/stm32f4-hal" and rename it to "stm32f4xx_hal_conf.h".

11. Examples
http://mikrocontroller.bplaced.net/wordpress/?page_id=2736

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License