|
|||||
STM32F4 Discovery project with CMSIS library; Step by step configuration in Keil uVision In this step-by-step tutorial we will set new project for STM32F4 Discovery board and show, how to use ow to use CMSIS libraries, which are integrated in Keil uVision.1. Open Keil uVision MDK v5. 2. On top menu select Project -> Manage -> Pack Installer... 3. Make sure these are installed:
Install them manually, if they are not listed, you can download pack 1.0.8 for STM32F4 here. 4. Close Pack installer 5. Download necessary files for CMSIS & Drivers, ... from here (which is a file like this:) 6. In Keil, select Project -> New uVision Project... 7. Save it to STM32F4xx_template, subfolder Project-001. Name your project; for example "GPIO", then click Save. 8. A new window should be opened, "Select Device For Target 'Target 1'...", select STM32F407VG (for STM32F4 Discovery board) and click OK. 9. A new window “Manage Run-Time Environment” should be opened. Select options:
Click OK, window will be closed. 10. Press in the toolbar to Configure file extensions. "Manage Project Items" window will be open. By the use of icons, manage your project items like this: 11. In the Groups select STM32F4xx_StdPeriph (just like in the above image), then click on Add Files. Go to "...\STM32F4xx_template\STM32F4xx_StdPeriph_Driver\src" and add stm32f4xx_gpio.c and stm32f4xx_rcc.c. In the "Manage Project Items" click OK, window will be closed. 12. In the "Project" window click on "plus" on the left under "Device" group to see "system_stm32f4xx.c (startup)". 13. Open "system_stm32f4xx.c (startup)" file and search for
Change line 254 to #define PLL_M 8 Cause of this change is that, STM32F4-Discovery has 8MHz crystal. We would like to run the core at 168MHz. In order to generate a core clock frequency of 168MHz, according to formulae in reference manual (which Mentioned in line 253 of "system_stm32f4xx.c (startup)"), we need PLL_M=8, PLL_N=336 and PLL_P=2. 14. Press the magic wand in the toolbar to show the "Options for target" window and configure target options. Select the Target tab and: By the use of icons, setup compiler include paths: 15. In the "Debug" tab: In "Cortex-M Target Driver Setup": 16. In the Utilities tab: 17. In uVision program, under Main Source folder on the left make right click and select "Add New Item to Group 'src'..". Then create "main.c" and save it in the "./src" path. Note: If we wanted to use an existing file (.c, .cpp, .h or etc.), we had to choose "Add Existing file to '?'...". 18. Type your main.c code. (Click here to see a main.c example) 19. Press F7 (or click on ) to compile and make sure there is no errors.
20. Click on to download code to flash memory.
THE END.
Rename file of this example to "LastName-StudentID-001", we use it as a template for our future projects and exercises. Sharif University of Technology, Tehran, Iran |