Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (31 sloc) 3.02 KB

STM32 ArmCortexM4Analysis

This example was written for the STM32F411 development board. It's the program used in my blog post In Depth Analysis of an ARM Cortex-M4 Program.

 

Foreword

I currently (Winter 2018) use Windows as my main development machine, however, I'm fairly certain all of the following steps can be similarly done using a typical Linux distro or possibly even MacOS.

 

Prerequisites

  1. An STMF32F411 development board. Currently they can be ordered from the usual sites for around $15 USD plus shipping.
  2. Download and install the GNU Arm Embedded Toolchain
  3. Download and install GNU Make for Windows
  4. Download OpenOCD and uncompress it (preferably to c:\OpenOCD).
  5. Download and install the STM32 ST-Link Utility.

 

Compiling and Flashing the Program to the Dev Board

  1. Open a GCC Command Prompt. Note that a "GCC Command Prompt" option was installed when installing the GNU Arm Embedded Toolchain and should be available from Windows Start Menu.
  2. Change to the ArmCortexM4Analysis directory and run "make". This will compile the C program (main.c) and the startup assembly file (startup.s) and use the LinkerScript.ld file to create the ELF file which is then converted to out.bin - the actual binary that will run on the STM32F411.
  3. Open the STM32 ST-Link Utility and select "Program" from the "Target" pulldown menu.
  4. Navigate to the ArmCortexM4Analysis directory and select out.bin.
  5. Click "Start" to flash out.bin to the development board. After this is done you should see LEDs on the development board blinking (i.e. the program is running on the board).

 

Debugging from the Command Line

  1. Make sure to close the STM32 ST-Link Utility so OpenOCD will be able to connect to the dev board.
  2. Open another command prompt.
  3. Change directory to the ArmCortexM4Analysis directory.
  4. Run OpenOCD.bat. Note that if you did NOT uncompress OpenOCD to c:\OpenOCD you'll have to modify the first line of OpenOCD.bat to point to the directory that OpenOCD exists in.
  5. Switch to the original GCC command prompt you opened when compiling and run arm-none-eabi-gdb.
  6. After GDB starts up, at the prompt, type "target remote localhost:3333" and press enter. This will connect to OpenOCD.
  7. Next, type "monitor reset halt" at the GDB prompt to stop the currently running program.
  8. Then, load the ELF file into GDB by entering "file out.ELF". It'll ask you "Are you sure you want to change the file?", answer "y" for "yes".
  9. You can then use "si" to step through each instruction of the program.