Skip to content

Commit b7a22c3

Browse files
committed
📝💡 update documentation comments
1 parent de3e527 commit b7a22c3

File tree

10 files changed

+347
-128
lines changed

10 files changed

+347
-128
lines changed

dma/1shot.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# USART communication using DMA in one shot mode
2+
3+
Communication between PC and STM32 using USART and DMA peripherals.
4+
5+
Transmit data using USART1 and DMA in one shot mode without interruption of CPU. The DMA is restarted adter every 2 seconds. This project does not require any IDE like CubeIde, any text editor will work including notepad, vim. For better debugging experience, VSCode is preferred.
6+
7+
![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/)
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+
# for debian based linux distros
16+
sudo apt install build-essential
17+
18+
# for macos
19+
xcode-select --install
20+
21+
# for macos using brew formulae
22+
brew install make
23+
```
24+
25+
* gcc-arm-none-eabi toolchain
26+
ARM cross-platform toolchain is required to build applications for arm mcus. Toolchain can be installed by running following command:
27+
28+
```bash
29+
# for debian based linux distros
30+
sudo apt install gcc-arm-none-eabi
31+
32+
# for macos
33+
brew install --cask gcc-arm-embedded
34+
```
35+
36+
* openocd
37+
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:
38+
39+
```bash
40+
# for debian based linux distros
41+
sudo apt install openocd -y
42+
43+
# for macos
44+
brew install openocd
45+
```
46+
47+
* stlink-tools
48+
This program is required for uploading binaries to the STM32 boards. You can install stlink tools by running the command:
49+
50+
```bash
51+
# for debian based linux distros
52+
sudo apt install stlink-tools
53+
54+
# for macos
55+
brew install stlink
56+
```
57+
58+
* Cortex Debug extension
59+
This extension for VSCode is helpful for debugging 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.
60+
61+
```bash
62+
ext install marus25.cortex-debug
63+
```
64+
65+
## Project Structure
66+
67+
* `src` directory contains all source files for the project
68+
* `include` directory contains all header files for the project
69+
70+
### Source file description
71+
72+
* `stm32f1.ld` - linker script for stm32f103
73+
* `src/main.c` - main application code
74+
* `src/startup_stm32f1.c` - boot sequence for arm cortex-m3 processors
75+
* `src/system_stm32f1xx.c` - clock configuration and system initialization functions
76+
77+
## Run Locally
78+
79+
Running the project is super easy. Just clone, build, and flash. Clone this project using **Code** button above.
80+
81+
### Configuration
82+
83+
All the configuration required for building this project is given below.
84+
85+
1. Build output directory
86+
In `Makefile`, output directory can be configured using variable `BUILD_DIR`.
87+
88+
2. Build type
89+
In `Makefile`, build type can be configured using variable`BUILD_TYPE`. Possible values are `Debug` and `Release`.
90+
91+
3. Binary name
92+
In `Makefile`, output binary name can be configured using `TARGET` variable.
93+
** update the target name in the `executable` property `.vscode/launch.json` for the debugger to work.
94+
95+
### Build
96+
97+
Run following command in terminal to generate flashable binaries for blue pill board. Build files will be written to **Build Output Directory** as configured.
98+
99+
```bash
100+
make
101+
```
102+
103+
## Flash
104+
105+
1. Connect Stlink to PC and blue pill board using swd headers.
106+
2. Put blue pill board in programming mode *(optional)*.
107+
The *Boot0* jumper is set to *0*, set it to *1* and reset the device.
108+
3. Run following to flash board with binary.
109+
110+
```bash
111+
make flash
112+
```
113+
114+
4. Done.
115+
116+
## Hardware Setup
117+
118+
Connect the board with host through USB to TTL converter (FTDI board in our case). The connections are described as follows.
119+
120+
| Pin on Blue Pill | Pin on FTDI |
121+
|------------------ |------------- |
122+
| PA9 | Rx |
123+
| PA10 | Tx |
124+
| Gnd | Gnd |
125+
126+
![Connection diagram for USART1](../docs/label.png "Pin connection diagram for usart1")
127+
128+
## Output
129+
130+
"Hello world" messages are visible on the terminal arriving every 2 seconds as seen below.
131+
![Serial prompt at 115200 baudrate](docs/out_one_shot.png "Output on terminal")
132+
133+
## Debug
134+
135+
Click in `Run and Debug` option in VsCode sidebar. Then launch `Cortex Debug` target.
136+

dma/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# USART communication using DMA in one shot mode
1+
# USART communication using DMA in echo mode
22

33
Communication between PC and STM32 using USART and DMA peripherals.
44

5-
Transmit data using USART1 and DMA in one shot mode without interruption of CPU. The DMA is restarted adter every 2 seconds. This project does not require any IDE like CubeIde, any text editor will work including notepad, vim. For better debugging experience, VSCode is preferred.
5+
Transmit data using USART1 and DMA in echo mode without interruption of CPU. DMA will accept 10 bytes from UART and echo back the same along with a carriage return and newline character. This project does not require any IDE like CubeIde, any text editor will work including notepad, vim. For better debugging experience, VSCode is preferred.
66

77
![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/)
88

@@ -107,9 +107,9 @@ make
107107
The *Boot0* jumper is set to *0*, set it to *1* and reset the device.
108108
3. Run following to flash board with binary.
109109

110-
```bash
111-
make flash
112-
```
110+
```bash
111+
make flash
112+
```
113113

114114
4. Done.
115115

@@ -127,10 +127,9 @@ Connect the board with host through USB to TTL converter (FTDI board in our case
127127

128128
## Output
129129

130-
"Hello world" messages are visible on the terminal arriving every 2 seconds as seen below.
131-
![Serial prompt at 115200 baudrate](docs/out_one_shot.png "Output on terminal")
130+
Enter 10 bytes on the serial prompt, the controller will echo the same characters and place the cursor on the new line.
131+
![Serial prompt at 115200 baudrate](docs/out_echo.png "Output on terminal")
132132

133133
## Debug
134134

135135
Click in `Run and Debug` option in VsCode sidebar. Then launch `Cortex Debug` target.
136-

dma/docs/out_echo.png

391 KB
Loading

dma/include/dma.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* @file dma.h
3+
* @author Rohit Nimkar (nehalnimkar@gmail.com)
4+
* @brief Function declarations and inline function definitions for DMA peripheral
5+
* @version 1.2
6+
* @date 2022-12-07
7+
*
8+
* @copyright Copyright (c) 2022
9+
* @attention
10+
*
11+
* This software component is licensed by Rohit Nimkar under BSD 3-Clause license,
12+
* the "License"; You may not use this file except in compliance with the
13+
* License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause
14+
*
15+
*/
16+
117
#include <stm32f1xx.h>
218

319
#ifndef __DMA_H__

dma/include/main.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* @file main.h
3+
* @author Rohit Nimkar (nehalnimkar@gmail.com)
4+
* @brief Header file for the functions used in the main.c source file
5+
* @version 1.2
6+
* @date 2022-12-07
7+
*
8+
* @copyright Copyright (c) 2022
9+
* @attention
10+
*
11+
* This software component is licensed by Rohit Nimkar under BSD 3-Clause license,
12+
* the "License"; You may not use this file except in compliance with the
13+
* License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause
14+
*
15+
*/
16+
117
#ifndef __MAIN_H__
218

319
#define __MAIN_H__
@@ -35,6 +51,12 @@ void dma_usart_tx_disable(void);
3551
*/
3652
void dma_usart_rx_enable(void);
3753

54+
/**
55+
* @brief Disable DMA to accept request for Channel 5
56+
*
57+
*/
58+
void dma_usart_rx_disable(void);
59+
3860
/**
3961
* @brief Configure USART1 on PA9 and PA10
4062
* Enable Transmitter with DMA
@@ -46,11 +68,16 @@ void usart1_init(void);
4668
*/
4769
void usart1_enable(void);
4870

49-
5071
/**
5172
* @brief Interrupt handler for DMA channel 4
5273
*
5374
*/
5475
void DMA1_Channel4_IRQHandler(void);
5576

77+
/**
78+
* @brief Interrupt handler for DMA channel 4
79+
*
80+
*/
81+
void DMA1_Channel5_IRQHandler(void);
82+
5683
#endif

dma/include/timer.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* @file dma.h
3+
* @author Rohit Nimkar (nehalnimkar@gmail.com)
4+
* @brief Function declarations and inline function definitions for timing related functions
5+
* @version 1.2
6+
* @date 2022-12-07
7+
*
8+
* @copyright Copyright (c) 2022
9+
* @attention
10+
*
11+
* This software component is licensed by Rohit Nimkar under BSD 3-Clause license,
12+
* the "License"; You may not use this file except in compliance with the
13+
* License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause
14+
*
15+
*/
116

217
#include<stdint.h>
318

dma/main.txt

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)