Creating a project using STM32F407VET6 with V1.9.0 standard library#
1. Creating a new project directory#
For a completely new project, you need to create a new empty project directory. Create a new folder and place 5 subfolders inside it, named Core, Hardware, Library, System, and User. Each folder will contain different project files in the future.
2. Downloading the STM32 firmware library#
The STM32 firmware library includes the library functions (c files and h files) corresponding to the STM32 peripherals, as well as the necessary startup files, etc. The firmware library also needs to be downloaded from the official website. Here, I provide a Lanzou download link.
3. Copying the files from the firmware library to the project path#
First, you need to copy the peripheral files from the firmware library to the project path. Copy the src
and inc
folders under the firmware library path \STM32F4xx_DSP_StdPeriph_Lib_V1.9.0\Libraries\STM32F4xx_StdPeriph_Driver
to the project directory Library
. The src
folder contains the firmware library .c
files, and the inc
folder contains the corresponding .h
files.
Copy the folder \STM32F4xx_DSP_StdPeriph_Lib_V1.9.0\Libraries\CMSIS\Device\ST\STM32F4xx\Source\Templates\arm
from the firmware library to the project directory Core
. The file startup_stm32f40_41xxx.s
is the startup file.
Copy the following core files from the firmware library \STM32F4xx_DSP_StdPeriph_Lib_V1.9.0\Libraries\CMSIS\Include
to the project directory Core
.
Now, these files have been copied to the Core
directory.
Copy the folder \STM32F4xx_DSP_StdPeriph_Lib_V1.9.0\Project\STM32F4xx_StdPeriph_Templates
from the firmware library to the project directory User
.
4. Creating a new project in Keil#
Open Keil5 and select Project → New uVision Project
from the top menu bar to create a new project. If you have other projects, click on Project → Close Project first.
Save it to the directory of the folder we just created, and name the file STM32F407VEProject
.
Select the chip STM32F407VETx
.
Click OK, then close the window below.
Click Manage Project Items
.
Modify it to the following form.
Add the following files to Core
.
Add all files inside the Library/src
folder to Library
.
Add the following files to User
.
Click OK to close the window.
Click on the magic wand to add file paths.
Add the following paths.
Click OK, then add the global macro definition identifier STM32F40_41xxx,USE_STDPERIPH_DRIVER
.
Click OK again.
Open main.c
and clear the internal data, leaving only the main function.
Then, delete the import of the main.h
header file on line 32 and the content of the SysTick_Handler
function on line 144 in the stm32f4xx_it.c
file under the User
group.
Finally, find stm32f4xx_fmc.c
in Library
, right-click and select Options
.
Uncheck include in Target Build
in front of stm32f4xx_fmc.c
. stm32f4xx_fmc.c
is specific to the STM32F42
and STM32F43
series, so we need to remove it from the project (note that it is stm32f4xx_fmc.c
, not stm32f4xx_fsmc.c
).
After removing FMC and FSMC, you may encounter the following situation during compilation:
After the compilation is complete, we find that there are still errors. Double-click on the error message with the mouse to find the location of the error.
The reason is that it is defined repeatedly, which can be considered as an official bug. You need to comment out the code that causes the error:
Comment out this part and the warning will disappear.
At this point, the project has been created. Here is the link to the project I created.