- Download and install STM32CubeMX 6.6.1 according to your operating system: https://www.st.com/en/development-tools/stm32cubemx.html
- Download and install STM32CubeIDE 1.10.1 according to your operating system: https://www.st.com/en/development-tools/stm32cubeide.html
- If you prefer to use JLink(recommended), download and install the newest version of SEGGER J-link drivers: https://www.segger.com/products/debug-probes/j-link/technology/flash-download/
- If you prefer to use ST-Link, download and install the newest version of STM32CubeProg https://www.st.com/en/development-tools/stm32cubeprog.html
- You can use JLink as a flasher and project in-circuit debugger and programmer
- You can use an ST-Link as a flasher and project debugger but we recommend converting ST-Link into J-Link by following instructions: https://www.segger.com/products/debug-probes/j-link/models/other-j-links/st-link-on-board/
- Clone this repo to the local machine
- In STM32CubeIDE import project:
File/Import/General/Existing Projects into Workspace/Select root directory/Browse...
- Select the directory
.../STM32Samples
- Do not select:
Copy project into workspace
- Press:
Finish
- Build project:
Project/Build All
or useCTRL+B
- Look at the
Console
tab if the build is successfully build - Debug project:
- Make sure that you have connected your debugger to the PC and to the target
- Go to:
Run/Debug configurations...
- Double click on
STM32 C/C++ Application
- Go to newly created configuration and select:
Debugger/Debug probe/SEGGER J-LINK
orST-LINK (ST-LINK GDB server)
depending on used debugger - Select:
Interface/SWD
- Select:
Interface/Initial Speed
select max - Go to
Main
tab, clickSeatch Project...
and select the*.elf
target which will be debugg - Press apply and debug
- You should be able to step your code instructions
- In the
Build Target
tab are the 5 make instructions that can be used during development. Double click to command to execute:all
- build all project targetsclean
- clean entire project including unit testsclient
- build client project targeterase_jlink
- erase entire MCU flash by using JLink toolsflash_client_jlink
- flash MCU by using JLink tools and client targetflash_server_jlink
- flash MCU by using JLink tools and server targetreset_jlink
- reset MCU by using JLink toolserase_stlink
- erase entire MCU flash by using ST-Link toolsflash_client_stlink
- flash MCU by using ST-Link tools and client targetflash_server_stlink
- flash MCU by using ST-Link tools and server targetreset_stlink
- reset MCU by using ST-Link toolstest
- run unit test
- If you would like to have an addon to edit README.md install: https://marketplace.eclipse.org/content/markdown-text-editor
- If you would like to have an addon to git in eclipse follow the instructions: https://www.geeksforgeeks.org/how-to-add-git-credentials-in-eclipse/
The source code can be built from the console level by using the command:
make
- build the entire projectmake all
- build all project targetsmake clean
- clean entire project including unit testsmake client
- build client project targetmake erase_jlink
- erase entire MCU flash by using JLink toolsmake flash_client_jlink
- flash MCU by using JLink tools and client targetmake flash_server_jlink
- flash MCU by using JLink tools and server targetmake reset_jlink
- reset MCU by using JLink toolsmake erase_stlink
- erase entire MCU flash by using ST-Link toolsmake flash_client_stlink
- flash MCU by using ST-Link tools and client targetmake flash_server_stlink
- flash MCU by using ST-Link tools and server targetmake reset_stlink
- reset MCU by using ST-Link toolsmake test
- run unit test
- If a toolchain is not found in Eclipse, add a toolchain to the
PATCH
- Go to:
Project/Properties/C/C++Build/Environment/
- Select
PATCH
thenEdit
and add a patch to your toolchain
- Go to:
- If a ST-Link programer is not found in Eclipse, add a ST-Link to the
PATCH
- Go to:
Project/Properties/C/C++Build/Environment/
- Select
PATCH
thenEdit
and add a patch to your ST-Linkbin
directory location
- Go to:
- If a ST-Link programer is not found when calling makefile
- Add a patch to your ST-Link
bin
directory location to the PATCH - Open:
vi ~/.profile
- Add a line to the file(example directory):
export PATH="/home/user/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin:$PATH"
- Log out and log in again
- Add a patch to your ST-Link
.
├── build // build output directory - automatically generated
├── common // common files directory
├── drivers // peripheral drivers
├── external // external source
│ ├── CMSIS // CMSIS source
│ └── STM32F1xx_HAL_Driver // STM32 HAL and LL dreiwers source
├── hal // Hardware Abstraction layer
├── features // SW features files directory
├── gen_pkgs.sh // CI package generation script
├── LICENSE // License file
├── Makefile // Makefile
├── README.md // Readme file
├── src // Main source directory
│ └── main.c // Main file
├── stm32f1xx // STM32F1 specific file
│ ├── erase.jlink // J-Link erase script
│ ├── flash.jlink // J-Link flash script
│ ├── reset.jlink // J-Link reset script
│ ├── startup_stm32f103xb.s // STM32F1 startup file
│ ├── stm32_assert.h // STM32F1 HAL asserts file
│ ├── STM32F103CBUx_FLASH.ld // STM32F1 linker script
│ ├── stm32f1xx_conf.h // STM32F1 LL heder
│ ├── stm32f1xx_it.c // STM32F1 system IRQ implementation
│ ├── stm32f1xx_it.h // STM32F1 system IRQ implementation
│ └── system_stm32f1xx.c // STM32F1 MCU initialization implementation
└── test // Unit tests directory
└── build // Unit tests build output directory - automatically generated
└── test // Test files
└── config.yml // Unity/Cmock configuration file
└── Makefile // Unit test Makefile
To port this source code to another platform you must port the entire hal
directory.
The hardware abstraction layer implements firmware interaction with platform-specific peripherals and features.
Rest of the code in directories: drivers
and src
is platform independent.
Directories external
and stm32f1xx
are platform specific and should not be ported.
- To enable or disable logs use
LOG_ENABLE
in fileLog.h
. There are three types of logs that can be selectively enabled or disabled:- Log Error enable by
LOG_ERROR_ENABLE
flag in fileLog.h
- this log type inform about a critical code failures - Log Warnings enable by
LOG_WARNING_ENABLE
flag in fileLog.h
- this log type inform about warning situations - Log Debug enable by
LOG_DEBUG_ENABLE
flag in fileLog.h
- this log is used for information and debug purpose
- Log Error enable by
- To enable or disable asserts use
ASSERT_ENABLE
in fileAssert.h
. Disabling assert allows saving Flash memory. It is recommended to keep this flag enabled. - To enable or disable logs for all transmitted and received UART frames use
UART_FRAME_LOGGER_ENABLE
in fileUartFrame.h
. Disabling this flag allows saving Flash memory. Enabling this flag can cause a lot of traffic on the logger. It is recommended to use this flag only for debugging purposes. MCU_CLIENT
andMCU_SERVER
are flags injected by a makefile during compilation. These flags are defined depending on a selected type of project to build.