Skip to content

Commit 59e39a2

Browse files
committed
✨ add dma project
1 parent 1b710b0 commit 59e39a2

22 files changed

+49079
-0
lines changed

dma/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build
2+
*.bkp
3+
*.dtmp
4+
.DS_Store

dma/.vscode/c_cpp_properties.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "STM32",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [
9+
"STM32F103xB"
10+
],
11+
"compilerPath": "/usr/bin/arm-none-eabi-gcc",
12+
"cStandard": "gnu17",
13+
"cppStandard": "gnu++17",
14+
"intelliSenseMode": "gcc-arm"
15+
}
16+
],
17+
"version": 4
18+
}

dma/.vscode/launch.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Cortex Debug",
9+
"cwd": "${workspaceFolder}",
10+
"executable": "./build/blink.elf",
11+
"request": "launch",
12+
"type": "cortex-debug",
13+
"runToEntryPoint": "main",
14+
"servertype": "openocd",
15+
"configFiles": [
16+
"interface/stlink.cfg",
17+
"target/stm32f1x.cfg"
18+
],
19+
"svdFile": "${workspaceFolder}/STM32F103.svd"
20+
}
21+
]
22+
}

dma/LICENSE.md

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

dma/Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
TARGET = dma-usart
2+
3+
4+
# Configure micro-controller
5+
MCU_FAMILY = STM32F103xB
6+
LDSCRIPT = stm32f1.ld
7+
CPU = cortex-m3
8+
INSTR_SET = thumb
9+
FLOAT_ABI = soft
10+
11+
# compiler option
12+
OPT := -Os
13+
CSTD ?= c11
14+
CXXSTD := c++17
15+
16+
# Project specific configuration
17+
BUILD_DIR := build
18+
BUILD_TYPE ?= Debug
19+
SRC_DIR := src
20+
INC_DIRS = include
21+
22+
23+
PREFIX ?= arm-none-eabi
24+
CC := $(PREFIX)-gcc
25+
CXX := $(PREFIX)-g++
26+
LD := $(PREFIX)-gcc
27+
AR := $(PREFIX)-ar
28+
AS := $(PREFIX)-as
29+
SIZE := $(PREFIX)-size
30+
OBJCOPY := $(PREFIX)-objcopy
31+
OBJDUMP := $(PREFIX)-objdump
32+
GDB := $(PREFIX)-gdb
33+
34+
# collect source files and generate object files
35+
SRCS := $(shell find $(SRC_DIR) -name '*.cpp' -or -name '*.c')
36+
OBJS := $(addsuffix .o,$(basename $(SRCS))) # replace .c with .o
37+
OBJS := $(addprefix $(BUILD_DIR)/,$(OBJS)) # replace .c with .o
38+
39+
40+
# Define stm32 family macro
41+
DEFS += -D$(MCU_FAMILY)
42+
43+
# header library include flsgs
44+
INC_FLAGS = $(addprefix -I,$(INC_DIRS))
45+
46+
47+
# Target-specific flags
48+
CPU_FLAGS ?= -mfloat-abi=$(FLOAT_ABI) -m$(INSTR_SET) -mcpu=$(CPU)
49+
50+
CPPFLAGS ?=$(DEFS) $(INC_FLAGS)
51+
CFLAGS ?=$(CPU_FLAGS) $(OPT)
52+
CXXFLAGS :=$(CFLAGS) -fno-exceptions -fno-rtti
53+
LDFLAGS ?=$(CPU_FLAGS)
54+
55+
ifeq ($(BUILD_TYPE), Debug)
56+
CFLAGS += -g -gdwarf-2
57+
endif
58+
59+
# Do not link stdlib with executable
60+
CFLAGS += -nostdlib -fno-tree-loop-distribute-patterns -fdata-sections -ffunction-sections
61+
CXXFLAGS += -nostdlib -fno-tree-loop-distribute-patterns -fdata-sections -ffunction-sections
62+
LDFLAGS += -nostdlib
63+
64+
65+
# Warning options for C and CXX compiler
66+
CFLAGS += -Wall -Wextra -Wundef -Wshadow -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
67+
CXXFLAGS += -Wall -Wextra -Wundef -Wshadow -Wredundant-decls -Weffc++ -Werror
68+
69+
70+
LDFLAGS += -T $(LDSCRIPT)
71+
LDFLAGS += -Wl,-Map=$(basename $@).map,--gc-sections,-cref,--print-memory-usage
72+
73+
all: bin size
74+
size: $(BUILD_DIR)/$(TARGET).size
75+
elf: $(BUILD_DIR)/$(TARGET).elf
76+
bin: $(BUILD_DIR)/$(TARGET).bin
77+
hex: $(BUILD_DIR)/$(TARGET).hex
78+
srec: $(BUILD_DIR)/$(TARGET).srec
79+
list: $(BUILD_DIR)/$(TARGET).list
80+
81+
82+
%.size: %.elf
83+
@$(SIZE) $<
84+
85+
%.bin: %.elf
86+
@echo "COPY " $< " => " $@
87+
@$(OBJCOPY) -Obinary $(*).elf $(*).bin
88+
89+
$(BUILD_DIR)/%.o:%.c
90+
@mkdir -p $(dir $@)
91+
@echo "CC" $< " ==> " $@
92+
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
93+
94+
$(BUILD_DIR)/%.o:%.cpp
95+
@mkdir -p $(dir $@)
96+
@echo "CXX" $< " ==> " $@
97+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
98+
99+
$(BUILD_DIR)/$(TARGET).elf: $(OBJS)
100+
@echo "Linking sources into "$@
101+
@$(CC) $(LDFLAGS) -o $@ $^
102+
103+
104+
flash: bin
105+
st-flash write $(BUILD_DIR)/$(TARGET).bin 0x8000000
106+
107+
debug: CFLAGS += -g -gdwarf-2
108+
debug: CXXFLAGS += -g -gdwarf-2
109+
debug: all
110+
111+
clean:
112+
rm -rf build

dma/README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# USART communication using DMA
2+
3+
A boilerplate for generating projects for stm32 blue pill board using makefile. The projects does not use any tools provided by ST Microelectronics.
4+
Everything from development, flashing to debugging can be done in Visual Studio Code only.
5+
6+
![Build Passing](https://img.shields.io/badge/build-passing-brightgreen) [![GPLv3 License](https://img.shields.io/badge/License-GPL%20v3-yellow.svg)](https://opensource.org/licenses/)
7+
8+
9+
## Dependencies
10+
11+
* make
12+
Make utility is required for configuring and building this project. You can install make on linux by running command:
13+
14+
```bash
15+
sudo apt install build-essential
16+
```
17+
18+
* gcc-arm-none-eabi toolchain
19+
ARM cross-platform toolchain is required to build applications for arm mcus. Toolchain can be installed by running following command:
20+
21+
```bash
22+
sudo apt install gcc-arm-none-eabi
23+
```
24+
25+
* openocd
26+
It is an Open On Circuit Debugging tool used to flash and debug arm micro controllers. You can install openocd on linux by running command:
27+
28+
```bash
29+
sudo apt install openocd -y
30+
```
31+
32+
* Cortex Debug extension
33+
x`
34+
35+
36+
## Project Structure
37+
38+
* `src` directory contains all source files for the project
39+
* `include` directory contains all header files for the project
40+
41+
### Source file description
42+
43+
* `STM32F103C8TX_FLASH.ld` - linker script
44+
* `src\main.c` - application code
45+
* `src\startup_stm32f103c8tx.s` - assembly startup script for blue pill board
46+
* `system_stm32f1xx.c` - clock configuration and system initialization functions
47+
48+
## Run Locally
49+
50+
Running the project is super easy. Just clone, build, and flash.
51+
52+
### Clone the project
53+
54+
1. Using https
55+
56+
```bash
57+
git clone https://github.com/csrohit/bluepill-template-project.git
58+
cd bluepill-template-project
59+
```
60+
61+
2. Using ssh
62+
63+
```bash
64+
git clone git@github.com:csrohit/bluepill-template-project.git
65+
cd bluepill-template-project
66+
```
67+
## Configuration
68+
69+
All the configuration required for building this project is given below.
70+
71+
1. Build output directory
72+
In `Makefile`, output directory can be configured using variable `BUILD_DIR`.
73+
74+
2. Build type
75+
In `Makefile`, build type can be configured using variable`DEBUG`. Possible values are `Debug` and `Release`.
76+
77+
3. Binary name
78+
In `CMakeLists.txt`, output binary name can be configured using `project(<binary-name>)` macro.
79+
** update above info in `.vscode/launch.json` as well for debugging to work.
80+
81+
## Build
82+
83+
Run following command in terminal to generate flashable binaries for blue pill board. Build files will be written to **Build Output Directory** as configured.
84+
85+
```bash
86+
make all
87+
```
88+
89+
## Flash
90+
91+
1. Connect Stlink to PC and blue pill board using swd headers.
92+
2. Put blue pill board in programming mode.
93+
3. Run following to flash board with binary.
94+
95+
```bash
96+
make flash
97+
```
98+
99+
## Output
100+
101+
Onboard led connected to Pin C13 can be observed to be blinking after 500ms.
102+
103+
## Debug
104+
105+
Click in `Run and Debug` option in VsCode sidebar. Then launch `Cortex Debug` target.
106+
107+
Happy debugging....

0 commit comments

Comments
 (0)