+ All Categories
Home > Documents > Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

Date post: 07-Jul-2018
Category:
Upload: borellam7606
View: 228 times
Download: 0 times
Share this document with a friend

of 23

Transcript
  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    1/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 1/23

    Jorge Aparicio's blog on Electronics, Robotics and more...

    Embedded

    Programmer 

    Thursday, September 13, 2012

    STM32F4DISCOVERY Development with GCC in Eclipse

    First of all, I want to thank the OpenOCD Project for its latest release of OpenOCD. Thanks to

    this release, its possible to get a working development environment for the

    STM32F4DISCOVERY relatively fast.

    This Development Environment can also be used for other STM32 / Cortex M microcontrollers

    and development boards. I have tested this Development Environment with the

    STM32VLDISCOVERY, STM32F4DISCOVERY and F4Dev.

    For now this post is Ubuntu specific. Setting the Development Enviroment on other platformsshould be fairly similar.

    You need a GCC (GNU Compiler Collection) for ARM Cortex processors: You can use the official

    GCC build (4.6.2)  or the Mentor Graphics (former Code Sourcery) GCC build (4.5.2)  (Do not use

    the CodeSourcery GCC, the latest library code requires GCC version 4.6 or later).

    I'll cover how to install the official GCC build, sinc e it's a newer version.

    Grab the installer , follow the installation steps, and check the "Add path to environment variable"

    checkbox just before finishing the installation.

    Grab the Linux installation tarball.

    Untar the tarball and that's it, no need to launch a installer.

    Note: Ubuntu 12.10 users, use the command line tar instead of the GUI archive manager. The

    latter will result in missing binaries in the bin folder. See image below.

    Dependency: GCC

    Windows

    Linux

    Prima di tutto digitare: sudo apt-get install automake autoconf

    http://embeddedprogrammer.blogspot.it/http://embeddedprogrammer.blogspot.it/http://embeddedprogrammer.blogspot.it/http://embeddedprogrammer.blogspot.it/http://embeddedprogrammer.blogspot.it/http://embeddedprogrammer.blogspot.it/https://launchpad.net/gcc-arm-embedded/4.6/4.6-2012-q4-update/+download/gcc-arm-none-eabi-4_6-2012q4-20121016.tar.bz2https://launchpad.net/gcc-arm-embedded/4.6/4.6-2012-q4-update/+download/gcc-arm-none-eabi-4_6-2012q4-20121016.exehttp://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/request?id=e023fac2-e611-476b-a702-90eabb2aeca8&downloadlite=scblite2012&fmpath=/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/formhttps://launchpad.net/gcc-arm-embeddedhttp://embeddedprogrammer.blogspot.com/2012/08/f4dev-open-source-development-board-for.htmlhttp://embeddedprogrammer.blogspot.it/

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    2/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 2/23

    Do not use the GUI archive manager 

    Use the following command instead:

    tar jxf gcc-arm-none-eabi-4_6-2012q2-20120614.tar.bz2

    Let's add the GCC binaries folder to the PATH environment variable, for easier use.

    gedit $HOME/.profile

     Append to this file the following lines:

    Do a soft reboot to update the PATH variable.

    The binaries should be accessible from the command line, let's check.

    arm-none-eabi-gcc --version

    You should see an output similar to the following lines:

    If instead you get the following error and you are using a 64bit Ubuntu/Linux OS:

    It means you are missing some 32 bit libraries. The easiest way to solve this is to install all the

    32 bit libraries using the following command:

    sudo apt-get install ia32-libs

    123

    if  [ -d "/gcc-arm-none-eabi-

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    3/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 3/23

    Now test again the arm-none-eabi-gcc command and it should work.

    That's it for the GCC dependency.

    You'll need Eclipse C/C++ Development Tooling. I recommend using Eclipse Indigo instead of 

    Eclipse Juno, because there is a bug with the content assist when using namespaces.

    Grab the correct package from here. (If you still want to use the Juno version, get the package

    from here)

    Untar / unzip the tarball / zip file, and you are done.

    If you don't have Java installed, head to this link. Grab the correct installer (x86 or AMD64), then

    follow the installation steps.

     After installing Java, Eclipse should work.

    With this plugin, Eclipse will be able to detect the ARM GCC.

    In Eclipse, go to (Help > Install New Software).

    On this new window, click the add button, and insert the following text.

    http://gnuarmeclipse.sourceforge.net/updates

    Click OK and a component named "CDT GNU Cross Development Tools" will appear, check it,

    then click the Next button and following the installation instructions.

    You'll be prompted to reset Eclipse, do so.

    You're done with this plugin.

    Dependency: Eclipse CDT

    Windows

    Dependency: GNU ARM Plugin

    http://2.bp.blogspot.com/-y4oTBP1U6bI/UFE-HoOfbfI/AAAAAAAAAbM/IyHPisIm68I/s1600/GNU+ARM+Install.pnghttp://2.bp.blogspot.com/-DL2GCEjzp9A/UFE9gWT1rMI/AAAAAAAAAbE/WSLYKPHruBc/s1600/GNU+ARM.pnghttp://www.java.com/en/download/manual.jsphttp://www.eclipse.org/downloads/packages/node/818http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers-includes-incubating-components/indigosr2http://www.eclipse.org/cdt/

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    4/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 4/23

    This plugin is necessary to flash and debug within Eclipse.

    In Eclipse, go to (Help > Install New Software).

    On this new window, click the add button, and insert the following text.

    http://opensource.zylin.com/zylincdt 

    Click OK and a component named "Zylin Embedded CDT" will appear, check it, then click the

    Next button and following the installation instructions.

    You'll be prompted to reset Eclipse, do so.

    You're done with this plugin.

    With this software, your PC will be able to flash and debug STM32 targets via a USB JTAG

    interface.

    Grab the zip from here. Unzip the file. Copy the uncompressed folder in your C drive.

     Append ";C:\openocd-0.6.1\bin" or ";C:\openocd-0.6.1\bin-x64" to your PATH variable. See

    thispost  if you don't know how to edit the PATH environment variable.

    Grab the version 0.6.0 tarball from here.

    Untar the tarball.

    Use the following installation commands:

    Dependency: Zylin Embedded CDT Plugin

    Dependency: OpenOCD

    Windows

    Linux

    Installare openocd con il Gestore Applicazioni

    http://sourceforge.net/projects/openocd/files/latest/download?source=fileshttp://embeddedprogrammer.blogspot.com/2012/10/windows-environment-variables-for-mingw.htmlhttp://www.freddiechopin.info/en/download/category/4-openocd?download=77%3Aopenocd-0.6.1http://3.bp.blogspot.com/-3FBVYakjJaE/UFFAItCY8cI/AAAAAAAAAbc/SwcxIAxusNo/s1600/Zylin+Install.pnghttp://3.bp.blogspot.com/-9Kkvj0AeP_A/UFFAAZLd33I/AAAAAAAAAbU/F2fXYRLtsCU/s1600/Zylin.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    5/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 5/23

    sudo apt-get install libftdi-dev

    cd

    ./configure --enable-ft2232_libftdi --enable-stlink

    make

    sudo make install

    You're done with the OpenOCD installation.

    If you don't have Git installed. Grab the installer from here. Follow the installations steps, but

    choose the "Run Git from the Windows Command Prompt" instead of the default option.

    Windows doesn't come with a "make" tool by default. The easiest way to get "make" is

    downloading this MinGW (**). Then unzip the downloaded zip archive in your C drive.

    (**) The trolltech ftp server has been shutdown, luckily ShaoLin has posted a mirror on his Google

    Drive, check his post for information on how to download MinGW.

     And append ";C:\mingw\bin" to your PATH variable. See this post  if you don't know how to edit

    the PATH environment variable.

    Grab the Eclipse project template I have developed: bareCortexM

    cd # choose some directory

    git clone https://github.com/JorgeAparicio/bareCortexM.git

    In Eclipse, go to (File > Import).

    In this window, select (General > Existing Project into Workspace).

    Git (Windows)

    Make (Windows)

    The Eclipse Project Template

    Importing the Eclipse Project

    Se non gia' installato,

    installare git con il comando:

    sudo apt-get install git

    copiare i pacchetti .jar prelevati dahttp://embsysregview.sourceforge.net/ nella dir di eclipse chiamata plugins

    https://github.com/JorgeAparicio/bareCortexMhttp://embeddedprogrammer.blogspot.com/2012/10/windows-environment-variables-for-mingw.htmlhttp://nosymbolfound.blogspot.com/2012/12/since-until-now-qt-under-windows-is.htmlftp://ftp.trolltech.com/misc/MinGW-gcc440_1.ziphttp://git-scm.com/download/win

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    6/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 6/23

    In this new window, click the Browse button next to the "Select root directory" box and select thebareCortexM folder.

    In this project, go to the "src" folder and open the "main.cpp" file. You should see a single function

    named int main().

    From the Eclipse menu select (Project > Properties).

    In this windows, select the C/C++ Build.

    Click the Manage Configuration button next to the Configuration combo box.

    Select your platform and click the Set Active button. (By default the Linux platform is selected).

    http://4.bp.blogspot.com/--YdI9u3WJPI/UFFHu05-VNI/AAAAAAAAAcA/3eiHSdeLlbE/s1600/importBareCortexM.pnghttp://3.bp.blogspot.com/-n4MNeHUR_YE/UFFHCb-JzLI/AAAAAAAAAb4/gTIRXHPZwlY/s1600/importProject.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    7/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 7/23

    ** Windows: Edit the (Eclipse > Project > Properties > C/C++ Build > Build command) to

    "mingw32-make" or whatever make you are using.

    Now try building the project, if you correctly followed the previous steps the build should be

    successful.

    Before flashing your target (in this case the STM32F4DISCOVERY) it's necessary to configure

    the project for your specific target.

    The linker script contains the memory map of your target device.

    In the Eclipse menu, go to (Project > Properties).

    Now select C/C++ (Build > Settings).

    Select (ARM Sourcery GCC C++ Linker > General).

    Modify the file in the Script File text box, to match your target device.

    Configuring the project for your target

    Linker Script selection

    http://4.bp.blogspot.com/-n7he0pdVFyI/UFFInguDznI/AAAAAAAAAcI/D95KqCJrabM/s1600/build.pnghttp://3.bp.blogspot.com/-wQj5mwEM81c/UFFMCG1fjBI/AAAAAAAAAck/tEvVzl7MZcM/s1600/platformSelection.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    8/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 8/23

    You can see the list of supported devices in the linker folder.

    You'll need to tell OpenOCD which interface and target you plan to use.

    In the Eclipse menu, (Run > External Tools > External Tool Configurations).

    In this new window, select (Program > OpenOCD).

    On the Main tab, make sure the OpenOCD location is correct. Then modify the arguments as

    necessary.

    OpenOCD interface/target configuration

    http://3.bp.blogspot.com/-frdqGOXElpk/UFFPd84qLVI/AAAAAAAAAdI/NLzGW1xpR9g/s1600/linkerScriptSupport.pnghttp://2.bp.blogspot.com/-hfRDYs12n-4/UFFO7d9rwXI/AAAAAAAAAdA/GpIGkj2ORdw/s1600/linkerScript.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    9/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 9/23

    The first argument to modify is the interface: "-f openocd/interface/.cfg". You can

    see the list of supported interfaces in the (openocd > interface) folder.

    The second argument to modify is the target: "-f openocd/target/.cfg". You can see

    the list of supported targets in the (openocd > target) folder.

    modificare la riga:

    /usr/local/bin/openocd

    in

    /usr/bin/openocd

    http://1.bp.blogspot.com/-z613kR4o_10/UFFUhjjjocI/AAAAAAAAAds/jIykmhH4Dtw/s1600/interfaceSupport.pnghttp://1.bp.blogspot.com/-aE0kBhg3VQA/UFFTVn25XbI/AAAAAAAAAdk/OlGydQulx7U/s1600/OpenOCD+configuration.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    10/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 10/23

    The GDB script contains the flash and debug information.

    In the Eclipse menu, go to (Run > Debug Configurations).

    In this new window, select (Zylin Embedded debug (Native) > Flash and Debug).

    On the Debugger tab, you'll need to select an appropriate GDB script in the GDB command file

    text box.

    You can see the list of supported devices in the gdb folder.

    GDB script selection

    http://3.bp.blogspot.com/-lgTnQw5YIUY/UFFW88r-CLI/AAAAAAAAAd8/J6uv4nrHEGI/s1600/gdbScriptSelection.pnghttp://4.bp.blogspot.com/-rGjbmGVBcmM/UFFUlhaBCaI/AAAAAAAAAd0/9KzKi_U1xTU/s1600/targetSupport.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    11/23

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    12/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 12/23

    + red toolbox icon) or go to (Menu > Run > External Tools > OpenOCD).

     And...

    What the...?

    If you are a Linux user, you'll probably bump into that error. You'll need to give permission to your 

    interface device, this way a non-rooted Eclipse will be able to flash and debug the target device.

    Grab the libusb-win32  library. Unzip the downloaded zip archive in your C drive. Enter in the

    uncompressed folder, then enter into the bin folder and execute the inf-wizard .

    Follow the instructions, select the right device ("Single RS232-HS" or similar) from the list. Save

    the .inf file anywhere and finally select Install Now.

    To grant permission to your interface device you'll have create a file using the following command.

    gksudo gedit /etc/udev/rules.d/33-openocd.rules

    (You can choose any other number, instead of 33)

    In this new file you'll need to add the following text:

    USB Permissions/Drivers

    Windows (for FTDI devices)

    Linux

    123456789

    10111213

    #FT232ATTRS{idProduct}=="6014", ATTRS{idVendor}=="0403", MODE="666" #FT2232ATTRS{idProduct}=="6010", ATTRS{idVendor}=="0403", MODE="666" #FT230XATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403", MODE="666" #STLINK V1ATTRS{idProduct}=="3744", ATTRS{idVendor}=="0483", MODE="666" #STLINK V2

    ?

    http://embeddedprogrammer.blogspot.it/2012/09/stm32f4discovery-development-with-gcc.html#http://sourceforge.net/projects/libusb-win32/files/latest/download?source=fileshttp://3.bp.blogspot.com/-oGozkDsiJnA/UFFgeCz7IQI/AAAAAAAAAfQ/_UBqOk7ee8k/s1600/permissionDenied.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    13/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 13/23

    This will give permission to all the FTDI based JTAG-dongles and to the ST-LINK v2 JTAG

    interface present in the STM32F4DISCOVERY.

    If you are using or planning to use the STM32VLDISCOVERY, then you need these additional

    steps:

    gksudo gedit /etc/modprobe.d/stlink_v1.conf

    Inside that new file, insert the following text:

    NOTE: Currently, ST-LINK v1 via OpenOCD can't modify the target device flash protection. This

    means, that if your STM32VLDISCOVERY has its flash protection enabled, you won't be able to

    flash it. On the other hand, if you manage to disable the flash protection using other JTAG dongle,

    then you'll be able to use the ST-LINK v1 connection. OpenOCD will probably provide better 

    support for ST-LINK v1 in the future.

     A reboot is necessary to update the last changes.

     After that, the permission problem should be fixed.

     As before, launch OpenOCD. You should get the following output this time.

    That X breakpoints and Y watchpoints is the equivalent of success. Now that you have

    established a link between your PC and the microcontroller, you can begin the flash and debug

    session.

    Click the Flash and Debug action in the Debug menu (the green bug icon). The flashing process

    will start, and it will take a while... around 20s (if you using a device with big flash memory,

    otherwise it's faster).

    14   ATTRS{idProduct}=="3748", ATTRS{idVendor}=="0483", MODE="666"

    1   options usb-storage quirks=483:3744:i

    Back to the first program

    ?

    http://embeddedprogrammer.blogspot.it/2012/09/stm32f4discovery-development-with-gcc.html#http://1.bp.blogspot.com/-tjxiBEPTQ-o/UFFnzxY-3TI/AAAAAAAAAfs/ZvCvfr1WGeI/s1600/openOCD.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    14/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 14/23

    NOTE: Actually flashing your program is quite fast, since is probably around 200-300 bytes, what

    takes so much time is erasing the old memory. The whole flash memory get erased before writing

    the new program. You can achieve faster flashing times if you only "use" a fraction of the

    memory, when using scripts like stm32f4_16kb, stm32f4_32kb, etc.

     After the flashing is over, you'll go into the debug session. You'll be prompted if you want to

    change to the Debug perspective, answer yes.

    Let's do some debugging now. First, let's examine this new perspective.

    In the top left window, you'll see Debug window. Inside this window you'll see Thread 1, this is

    the program that's currently running, notice that it says suspended, this means that the ARM core

    is halted. Also, below Thread 1 you can see the stack of functions called, right now it says the

    program is at 0x00000000, this is because the JTAG interface hasn't asked for information yet.

     Also in the debug window you can see some buttons, that I have labelled from 1 to 7. Now I'l lcover what they do:

    N Button Description

    1 Resume (F8) Leaves the suspended status.

    2 Suspend Halts the program execution.

    3  Terminate (Ctrl +

    F2)  Finishes the program.

    4 Step into (F5) Goes (if possible) into the current subroutine.

    5 Step over (F6)  Executes the current line of code and moves onto the

    next.

    6 Step return (F7) Leaves the current subroutine.

    7  Instruction Stepping

    Mode

    Enables/disables the instruction stepping mode.

    (Disabled by default)

    Ok, now hit the Resume button and then click the Suspend button. You'll end in a state similar to

    the following image.

    Debugging 101

    http://4.bp.blogspot.com/-ptGEZt3bZYo/UFFsPedtKDI/AAAAAAAAAgI/V81LyL_dmqM/s1600/debug.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    15/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 15/23

    You can see that the middle left window changed, and now is showing the main.cpp file. Also,

    there is a highlighted line, this is where the halted program currently is. You can also see the

    disassembly of the current program in the middle right window, if you can't, then you can enable

    the disassembly from (Menu > Window > Show View > Disassembly).

    NOTE: Read this note if your program ends in the defaultExceptionHandler() function instead.

    This is a common error (bug?) that appears when you are using ST-LINK connections (in the

    STM32VLDISC OVERY or STM32F4DISCOVERY). In this case, terminate (red square button)

    the debug session and the OpenOCD connection. And then do the build > launch OpenOCD >

    start debug session process again.

    Let's watch some variables now, select the Variables tab of the top right window and right click

    the empty space, then click on Add Global Variables.

    Check the foo variable and then click OK. You can now watch the value of foo. Try resuming the

    program for a while and then suspend it again. You should see a noticeable increment in the value

    of foo.

    Now, let's see how breakpoints work. Right click the line 27 (it doesn't matter if you can't see the

    http://2.bp.blogspot.com/-a2Gvzv5VQKI/UFF2BrQRRbI/AAAAAAAAAhQ/HcQIZgiPstM/s1600/debug4.pnghttp://3.bp.blogspot.com/-80m3vCmcsks/UFF1SOppuEI/AAAAAAAAAhI/fF_Ns4xAGlI/s1600/debug3.pnghttp://2.bp.blogspot.com/-iH-NwVl3fmk/UFF01_osN3I/AAAAAAAAAhA/Q4vmbdJauXQ/s1600/debug2.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    16/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 16/23

    line number) and select Toggle Breakpoint. Now hit the Resume button.

    The program will stop as soon as it reaches the breakpoint, you'll notice that foo's value increased

    in one.

    Let's terminate the program (Flash and Debug) and then terminate the OpenOCD session and

     jump into something more interesting.

    bareCortexM is a barebone project template, you'll need a peripheral library to do more than just

    numerical operations. This is where libstm32pp  comes in.

    Let's place the libstm32pp project inside the bareCortexM project.

    cd

    git clone https://github.com/JorgeAparicio/libstm32pp.git

    Go back to eclipse, and right click the project name (bareCortexM) and select the Refresh action.

    You should see the libstm32pp folder inside the project.

    Blinking a LED

    Adding the libstm32pp library to the project

    https://github.com/JorgeAparicio/libstm32pphttp://2.bp.blogspot.com/-7d7MPIigkBQ/UFIIAQ8IIyI/AAAAAAAAAhw/BiC998zyjec/s1600/debug5.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    17/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 17/23

    Now, you'll need to add the library to the include path.

    In Eclipse menu, go to (Project > Properties).

    Go to (C/C++ General > Paths and Symbol).

    In the Includes tab, select the GNU C++ in languages and then click the Add button.

    In this new window, click the Workspace button and select the (libstm32pp > include) folder.

    You'll need to configure the library to match your target, head to the (libstm32pp > include) folder 

    and open the device_select.hpp. There you can select your target's family by commenting and

    uncommenting the defines in that file.

    Configuring the library

    http://2.bp.blogspot.com/-jj_nNydDN_0/UFISwAyXUbI/AAAAAAAAAjA/bl2rpodUoG8/s1600/includePath.pnghttp://3.bp.blogspot.com/-CyGBMyuMlbE/UFIScynjVGI/AAAAAAAAAi4/_UJQdcbKVmI/s1600/bareCortexM.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    18/23

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    19/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 19/23

    clock.hpp file. As in device_select.hpp, by commenting / uncommenting defines you can

    configure the clock to fit your needs.

    The clock will be configured when you call the function clk::initialize(). You should call this

    function as earlier as possible in your main function. If you are using any of the external

    crystals/oscillators (HSE or LSE) then you'll need to define the functions: clk::hseFailureHandler 

    and clk::lseFailureHandler. These functions will be called in case the external oscillators doesn't

    stabilize in some time as dictated by HSE_TIMEOUT and LSE_TIMEOUT.

    The STM32 microcontrollers use various buses (AHB, APB) to move data between the processor 

    and the peripherals. These buses define the operating frequency of various peripherals and these

    buses can be clocked at different frequencies. All this configuration is carried in the clock.hpp file,

    you can check the final frequencies using the cPrint statement:

    The cPrints statement prints its argument as an error. In the above image I used the cPrint

    statement to print the value of clk::AHB which the working AHB frequency. You can use cPrint to

    print other compile time known values, as cPrint creates an error, be sure to remove it or comment it after using it.

    http://1.bp.blogspot.com/-9L_hgG3_cTw/UFItnRynduI/AAAAAAAAAmA/MIt0-RBqopo/s1600/cPrint.pnghttp://4.bp.blogspot.com/-uQtaopgsRxI/UFInZc8GCvI/AAAAAAAAAlg/2pa3jdQGP-0/s1600/clockInitialize.pnghttp://4.bp.blogspot.com/-0KiNtk1dwq4/UFIjdnAwCKI/AAAAAAAAAlA/eO79k4JhFrc/s1600/clockConfiguration.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    20/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 20/23

    NOTE: As far as I know, the STM32F4 devices from the revision "A" can't use the ART

    accelerator (see the errata sheet here), for these devices the LATENCY parameter is important

    when configuring the clock. From my observations the following latencies work well:

    Clock Frequency

    (AHB)  LATENCY Comment

    Up to 42 MHz Zero Solid Rock Stable.

    From 42 Mhz to 84

    MHz  One Seems stable.

    168 MHz Three  Some WTFs when using interrupts and

    enabling optimization.

    NOTE: 84 MHz and latency one SHOULD be equivalent to 42 MHz, since the uC will execute

    one instruction and wait one cycle before executing the next instruction. However, when you take

    in consideration that instructions can take more than one cycle (e.g. FPU operations) and program

     jumps (due to functions and interrupts), calculating the "real" operating frequency gets really hard.

    My recommendation: Stick to 42 MHz max with zero latency while developing your application.

     After everything works fine, try increasing the clock and try different values for the latency until

    you get something stable. Then check if you are actually getting better performance on the AHB

    bus peripherals.

    The most important feature in every microcontroller are the interrupts. With these interrupts the

    microcontroller can handle various internal/external events as they come by.

    To enable interrupts you'll need to map the interrupt handlers in memory. I've already done this

     job, so you only need to include "interrupt_cpp.hpp" file in the "interrupts.cpp" source file (this is in

    the src folder).

    Let's try a demo now, go to the (libstm32pp > demo) folder and open the tim_blink_led.hpp file, or 

    if you are using a STM32F4DISCOVERY go to (libstm32pp > demo > f4discovery) folder and

    open the led_wheel.hpp file. Copy the content of the file to main.cpp.

    In the tim_blink_led demo you might want to change the LED from PA0 to some other pin. In

    either demo you can change the LED blink frequency by changing the configurePeriodicInterrupt

    function argument.

    Handling interrupts

    http://1.bp.blogspot.com/-6GXE6Wx4KL4/UFIwlIyaO9I/AAAAAAAAAmg/ewzpyCHRZaU/s1600/interrupts.pnghttp://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/ERRATA_SHEET/DM00037591.pdf

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    21/23

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    22/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    embeddedprogrammer.blogspot. it/2012/09/stm32f4discovery-development-with-gcc.html 22/23

    Let's do a quick demo about the new operator. Write in your main.cpp source file the following

    code:

    Build, run OpenOCD and start a debugging session as usual.

    The first thing you'll notice is that this small program takes around 90KB of flash. That's the price

    to pay for using dynamically allocated memory. If you watch the foo variable after running the

    program for some time, you'll notice that the pointer has a value around 0x20000000, this is the

    address that the new operator assigned it and also you can see the value stored in that address,

    which would be the first element of the array.

    There is a printf demo in the (libstm32pp > demo) folder. You can use printf with any of the 6

    new demo

    1

    23456789

    1011121314

    15

    #define SIZE 10

    int  *foo; int  main(){  foo = new int[SIZE]; 

    for  (int  i = 0; i < SIZE; i++)  foo[i] = 0;  while  (true) {

      for  (int  i = 0; i < SIZE; i++)  foo[i]++;  }

    }

    printf demo

    ?

    http://embeddedprogrammer.blogspot.it/2012/09/stm32f4discovery-development-with-gcc.html#http://4.bp.blogspot.com/-btU_Xhmf5Ms/UFJmnjmxbII/AAAAAAAAAog/duMXeR_SnOs/s1600/newDemo.pnghttp://1.bp.blogspot.com/-g98w-6WjUcE/UFJjGjDpGFI/AAAAAAAAAoA/6CAQctdCi3Y/s1600/startupLibraries.png

  • 8/18/2019 Embedded Programmer_ STM32F4DISCOVERY Development With GCC in Eclipse

    23/23

    18/12/13 Embedded Programmer: STM32F4DISCOVERY Development with GCC in Eclipse

    UART modules, which needs to be specified in the system_call.hpp file (this is in the (libstm32pp

    > include) folder). You'll also need a USB UART converter to get the UART output into your 

    PC. In your PC, you'll need a serial port terminal emulator like minicom or qSerialTerm.

    Finally, let's cover how to do optimization.

    In eclipse, go to (Menu > Project > Properties).

    Go to (C/C++ Build > Settings).

    In the Tool Settings tab, go to (ARM GCC C++ Compiler > Optimization).

    Select in the Optimization Level, the option that fits your need.

    My recommendation: When developing an application, I recommend working with the optimization

    turned off and turning it on after you have finished developing. This is because the optimization

    will complicate the debugging process, as the compiler will optimize out some variables and also

    some breakpoints might misbehave.

    Optimization

    http://1.bp.blogspot.com/-37XwSGamZ1s/UFJuxifCOMI/AAAAAAAAApA/oSt3nkqy2HY/s1600/optimization.pnghttp://embeddedprogrammer.blogspot.com/2012/06/qserialterm-qt-based-serial-port.html

Recommended