Change the world

The following section will provide example code for the STM32F4-Discovery Board.  It is highly recommened to read through the User Manual to get a clear understanding of the operation of the board.  For further detail the STM32F407VGT6 Datasheet and Reference Manual may also be needed.

Download the STM32F4-Discovery Firmware Package (STSW-STM32068) and unzip into a folder of your choice (e.g. G:\STM32).  Follow the steps in the How to configure KEIL ARM-MDK and STMicroelectronics firmware examples to work with the STM32F4DISCOVERY board document to get the Demonstration Project to compile and to download in Keil uVision4.

To load the example program(s), do the following:

  1. Copy the example program(s) to the Demonstration Project's folder (e.g. G:\STM32\STM32F4-Discovery_FW_V1.1.0\Project\Demonstration).
  2. Load the Demonstration Project from the MDK-ARM folder (e.g. G:\STM32\STM32F4-Discovery_FW_V1.1.0\Project\Demonstration\MDK-ARM\Demo.uvproj) in Keil uVision4.
  3. Once in Keil uVision4, expand the User folder in the Project window.
  4. Right-click on the "main.c" source file and select Remove File.  This will not physically delete the file, it will just remove it from the project.  You could also just highlight the file and press DEL on the keyboard. 
  5. Right-click on the User folder and click on Add Files to Group 'User'.  You can also just double-click on the User folder.
  6. Select the example program from the Demonstration Project's folder (e.g. G:\STM32\STM32F4-Discovery_FW_V1.1.0\Project\Demonstration\ex1_flash_leds.c).
  7. Click Add and then Close.
  8. Click Project -> Build target to compile the program.
  9. Click Flash -> Download to download the code to the board.

To load other examples, you will repeat from step 4.  If the example makes use of a user defined library (e.g. "servo_f4.c"), then make sure to also copy this library into the Demonstration folder.  This will also be the case for when you are going to use this library in you own new source files.


To create your own programs, it will be easier using the existing Demonstration Project and just adding your own source files.  This way all the project setup sequences have done for you.  With the Demonstration Project open in uVsion4, do the following:

  1. Remove the previous source file from the User folder (step 4 above).
  2. Click File -> New.
  3. Click File -> Save as...
  4. Select the Demonstration Project's folder (e.g. G:\STM32\STM32F4-Discovery_FW_V1.1.0\Project\Demonstration).
  5. Type a name for the new source file (e.g. "TestServo.c") and remember to add ".c" at the end.
  6. Click Save.
  7. Add the source file to the User folder as described in steps 5 - 7 above.
  8. Start typing the code for the file and compile and download as described before.