Openocd tutorial stm32


  • Debugging the STM32F4 using openocd, gdb and Eclipse
  • STM32 Debugging with printf() by using SWV or OpenOCD
  • Bare Metal STM32 Development on Windows
  • STM32 debugging with ST-Link, OpenOCD & VisualGDB
  • Qt Documentation
  • Debugging the STM32F4 using openocd, gdb and Eclipse

    Also, install eclipse as is described there and import the sample makefile project. Set the project name and choose the. This can look something like this: Make sure that the project is built before so you can choose the correct. Now, go to the Debugger tab and set the correct path to gdb. Starting the openocd server Create a file called stm32f4discovery. Now, from the same directory, run openocd with the following command: openocd -f stm32f4discovery. Now that openocd is running, you can launch the debug configuration in Eclipse and open the Debug perspective.

    Then you should see something like the screenshot in the beginning. Note that when you start debugging, the program will be uploaded to flash of the STM32 as well. When the debug session is started, you can click on Resume F8 to start execution. Then the program will run until you click Suspend or until you hit a breakpoint, then you will see the current line you are executing in the source code and the variables and their values in the current scope.

    If this is done while the program is running, it will halt as soon as the breakpoint is hit. This can often be solved by stopping openocd, unplugging and re-plugging the board and then starting openocd again. Some variables cannot be seen or changed and the assembler code does not seem to match the c-code perfectly. This is most likely because the code is compiled with optimizations enabled. This can happen when the program is compiled without the -g option.

    This option will tell the compiler to generate: symbol names type information for the symbols file and line numbers where the symbols came from This information is then used to display the line numbers and variables in the source file.

    STM32 Debugging with printf() by using SWV or OpenOCD

    Thanks to the feedbacks I have received, I reached to the conclusion that it's really hard to cover a topic like this one in the room of a blog post. So, I started writing a book about the STM32 platform. In the free book sample you can find the whole complete procedure better explained. You can download it from here. In the first part of this series we've successfully setup a minimal yet working tool-chain to develop applications for the STM32 family we've especially focused on STM32Nucleo developing board.

    This might be enough to develop every type of application based on the STM32 family. Using the Nucleo integrated Virtual COM port, we could print messages to debug the firmware this is the common way to debug Arduino sketches. However, we can use just few other tools to do a live debugging on our Nucleo, placing breakpoints, doing step-by-step debugging, accessing to internal registers and memory.

    In this post we'll focus on how to use GDB to do step-by-step debugging. Freddie Chopin has created the precompiled version of this tool for Windows.

    I think that a knowledge of how the debug process works, even partial one, can be really useful to better understand how to customize the debugging environment. OpenOCD and ST-Link interaction To flash a MCU and eventually to debug it we usually need an external piece of hardware called programmer sometimes, they are also called dongle, on-chip programmer, etc. The Nucleo board already integrates the ST-Link programmer and it's even detachable from the main board and it can be used as stand-alone programmer.

    So we don't need any external hardware tool to flash our Nucleo MCU. Thanks to these connections, OpenOCD can be instructed to upload the firmware on the target MCU, to setup breakpoints, to inspect memory status and so on.

    However, this work can be automatized and made simpler using Eclipse and the plug-ins we installed in the first part of this series. Let's install OpenOCD. I suggest to use at least 0. The download file is a ZIP archive compressed using 7-zip utility. Next, rename the OpenOCD directory from openocd This operation is not strictly needed. However, this will allow us to update OpenOCD when a new release is available without changing Eclipse configurations.

    The plug-ins we installed in the first part of this series allow us to use both the configuration methods. However, I experienced some issues with the first method. The only solution to this issue is removing the Nucleo board from USB port and connecting it again. I read around that is a problem related with the driver provided from ST. In the rest of this post I assume that you've already opened and compiled the test1 project made in the first post.

    Click the "External tools" configuration icon, and then click on "External Tools Configurations Fill the configuration fields as shown in the following picture: This is the meaning of each field. This path is used as base for paths in OpenOCD scripts and configuration files.

    Arguments: are the arguments passed to the command line to OpenOCD.

    Now, from the same directory, run openocd with the following command: openocd -f stm32f4discovery.

    Bare Metal STM32 Development on Windows

    Now that openocd is running, you can launch the debug configuration in Eclipse and open the Debug perspective. Then you should see something like the screenshot in the beginning. Note that when you start debugging, the program will be uploaded to flash of the STM32 as well. When the debug session is started, you can click on Resume F8 to start execution. So, I started writing a book about the STM32 platform. In the free book sample you can find the whole complete procedure better explained.

    You can download it from here. In the first part of this series we've successfully setup a minimal yet working tool-chain to develop applications for the STM32 family we've especially focused on STM32Nucleo developing board. This might be enough to develop every type of application based on the STM32 family.

    Using the Nucleo integrated Virtual COM port, we could print messages to debug the firmware this is the common way to debug Arduino sketches. However, we can use just few other tools to do a live debugging on our Nucleo, placing breakpoints, doing step-by-step debugging, accessing to internal registers and memory. In this post we'll focus on how to use GDB to do step-by-step debugging. Freddie Chopin has created the precompiled version of this tool for Windows.

    I think that a knowledge of how the debug process works, even partial one, can be really useful to better understand how to customize the debugging environment. In the Startup mode field, select the mode to start the debug server provider in. In the Host field, select the host name and port number to connect to the debug server provider.

    In the Executable file field, enter the path to the debug server provider executable.

    STM32 debugging with ST-Link, OpenOCD & VisualGDB

    In the Script file field, enter the path to a device script file. In the Verbosity level field, enter the level of verbose logging. Select the Connect under reset check box to use the ST-Link interface.

    Deselect the check box for hot-plugging. In the Type field, select the interface type. In the Speed field, enter the interface speed between and kiloherz kHz. Select the Disable cache check box to disable the EBlink flash cache.

    Select the Auto shutdown check box to automatically shut down the EBlink server after disconnecting.

    Qt Documentation

    In the Init commands field, enter the commands to execute when initializing the connection. In the Reset commands field, enter the commands to execute when resetting the connection. Select Apply to add the debug server provider.


    Openocd tutorial stm32