This simple project is indended to act as a testbed before working on the main application. It serves a number of purposes.
- Set the basic project directory structure
- Define the
.gitignore
file to ensure only properly portable content is kept under version control - Describe how to maintain a project from outside the workspace in STM32CubeIDE
- Act as a template for further applications
- Ilustrate how to connect the
stdio
functionsprintf()
andscanf(0)
to the serial port. - Show how to keep application code separate from the CubeMX generated code.
- STM32CubeIDE generates and maintains everything in the Core and Drivers directories
- The actual application lives in the Application directory.
- Make sure the project includes list includes
${ProjectDir}/Application
- Add the Application directory to the list of sources. Check this is done for both Debug and Release configurations
- The project must be of C++ type
- In the STM32CubeIDe MX generator, under
Project Manager\Code Generator
Select the option to generate peripheral initialisation as a pair of '.c/.h' files per peripheral. this lets you include the peripheral descriptions in the user application code. - Modify Core/Src/main.c :
- Near the beginning, find the
Private Includes
section and modify it to read:
- Near the beginning, find the
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "app_main.h"
/* USER CODE END Includes */
- In the
main()
funtion, find theUSER CODE BEGIN 2
section and, in there add a call toapp_main()
:
/* USER CODE BEGIN 2 */
app_main();
/* USER CODE END 2 */
Core/Src/main.c
should includeapp_main.h
which will declare a single entry pointint app_main(void)
.
├── Application # holds the application source code
├── Core # holds the CubeMX generated code
│ ├── Inc
│ ├── Src
│ └── Startup
├── Docs # application documentation
├── Drivers # generated by the CubeMX configuration
│ ├── CMSIS
│ │ ├── Device
│ │ │ └── ST
│ │ │ └── STM32F4xx
│ │ │ ├── Include
│ │ │ └── Source
│ │ │ └── Templates
│ │ └── Include
│ └── STM32F4xx_HAL_Driver
│ ├── Inc
│ │ └── Legacy
│ └── Src
├── Debug # build artifacts for Debug configuration
└── Release # build artifacts for Release configuration