Communication between PC and STM32 using USART and DMA peripherals.
Transmit data using USART1 and DMA in the one-shot mode without interruption of CPU. The DMA is restarted after every 2 seconds. This project does not require any IDE like CubeIde, any text editor will work including notepad and vim. For a better debugging experience, VSCode is preferred.
- make Make utility is required for configuring and building this project. You can install make on Linux by running the command:
# for Debian-based Linux distros
sudo apt install build-essential
# for macOS
xcode-select --install
# for macOS using brew formulae
brew install make
- gcc-arm-none-eabi toolchain ARM cross-platform toolchain is required to build applications for arm MCUs. The toolchain can be installed by running the following command:
# for Debian-based Linux distros
sudo apt install gcc-arm-none-eabi
# for macOS
brew install --cask gcc-arm-embedded
- openocd It is an Open On Circuit Debugging tool used to flash and debug arm microcontrollers. You can install openocd on Linux by running the command:
# for Debian-based Linux distros
sudo apt install openocd -y
# for macOS
brew install openocd
- stlink-tools This program is required for uploading binaries to the STM32 boards. You can install stlink tools by running the command:
# for Debian-based Linux distros
sudo apt install stlink-tools
# for macOS
brew install stlink
- Cortex Debug extension This extension for VSCode helps debug the application on Blue Pill. The contents of registers as well as memory are visible in the context menu. Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
ext install marus25.cortex-debug
src
directory contains all source files for the projectinclude
directory contains all header files for the project
stm32f1.ld
- linker script for stm32f103src/main.c
- main application codesrc/startup_stm32f1.c
- boot sequence for arm cortex-m3 processorssrc/system_stm32f1xx.c
- clock configuration and system initialization functions
Running the project is super easy. Just clone, build and flash. Clone this project using the Code button above.
All the configuration required for building this project is given below.
-
Build output directory In
Makefile
, the output directory can be configured using the variableBUILD_DIR
. -
Build type In
Makefile
, the build type can be configured using the variableBUILD_TYPE
. Possible values areDebug
andRelease
. -
Binary name In
Makefile
, the output binary name can be configured using theTARGET
variable. ** update the target name in theexecutable
property.vscode/launch.json
for the debugger to work.
Run the following command in the terminal to generate flashable binaries for the blue pill board. Build files will be written to Build Output Directory as configured.
make
- Connect Stlink to PC and blue pill board using SWD headers.
- Put the blue pill board in programming mode (optional). The Boot0 jumper is set to 0, set it to 1 and reset the device.
- Run the following to flash the board with binary.
make flash
- Done.
Connect the board with a host through a USB to TTL converter (FTDI board in our case). The connections are described as follows.
Pin on Blue Pill | Pin on FTDI |
---|---|
PA9 | Rx |
PA10 | Tx |
Gnd | Gnd |
"Hello, world" messages are visible on the terminal arriving every 2 seconds as seen below.
Click on Run and Debug
option in the VsCode sidebar. Then launch the Cortex Debug
target.