Skip to content

Commit 9245bf3

Browse files
committed
💬 update documentation
1 parent 50160b0 commit 9245bf3

File tree

9 files changed

+97
-42
lines changed

9 files changed

+97
-42
lines changed

uart-polling/README.md

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,41 @@ Connect the board with host through USB to TTL converter (FTDI board in our case
2121

2222
![Connection diagram for USART1](https://github.com/csrohit/bluepill-baremetal-projects/blob/main/uart-polling/resources/label.png "Pin connection diagram for usart1")
2323

24+
25+
## Project Structure
26+
27+
* `src` directory contains all source files for the project
28+
* `include` directory contains all header files for the project
29+
30+
### Source file description
31+
32+
* `STM32F103C8TX_FLASH.ld` - linker script for generating elf file.
33+
* `src/main.c` - entry point of application and main code body.
34+
* `src/uart.c` - Contains definition of non-inline functions for uart.
35+
* `src/timer.c` - Contains definition of non-inline functions for SysTick timer.
36+
* `src/startup_stm32f103c8tx.s` - assembly startup script for blue pill board.
37+
* `include/uart.h` - Contains definitions of inline functions and declaration of all functions for uart.
38+
* `include/uart.h` - Contains definitions of inline functions and declarations of all functions for SysTick timer.
39+
* `system_stm32f1xx.c` - clock configuration and system initialization functions.
40+
* `STM32F103.svd` - contains the description of the system contained in Arm Cortex-M processor-based microcontrollers, in particular, the memory mapped registers of peripherals.
41+
42+
2443
## Control flow
2544

2645
The initialisation function accomplishes following tasks
2746

28-
1. Enables clock signal for USART1 peripheral as well as GPIO Port A, both are connected with APB2 bus.\
29-
`RCC->APB2ENR |= RCC_APB2ENR_USART1EN | RCC_APB2ENR_IOPAEN;`
30-
2. Reset mode and configuration for PA9 and PA10.\
31-
`GPIOA->CRH &= ~(GPIO_CRH_MODE10 | GPIO_CRH_MODE9 | GPIO_CRH_CNF10 | GPIO_CRH_CNF9);`
47+
1. Enables clock signal for USART1 peripheral as well as GPIO Port A, both are connected with APB2 bus.
48+
49+
```C
50+
RCC->APB2ENR |= RCC_APB2ENR_USART1EN | RCC_APB2ENR_IOPAEN;
51+
```
52+
53+
2. Reset mode and configuration for PA9 and PA10.
54+
55+
```C
56+
GPIOA->CRH &= ~(GPIO_CRH_MODE10 | GPIO_CRH_MODE9 | GPIO_CRH_CNF10 | GPIO_CRH_CNF9);
57+
```
58+
3259
3. Set appropriate mode and configuration for PA9 and PA10.
3360
* PA9 as push-pull output at 50MHz speed.
3461
* PA10 as floating input.
@@ -45,24 +72,41 @@ uint32_t baud = (uint32_t)(SystemCoreClock / baudrate);
4572
USART1->BRR = baud;
4673
```
4774

48-
5. Enable transmitter, receiver, transmitter interrupt, receiver interrupt and USART1 clock.\
49-
`USART1->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE | USART_CR1_UE;`\
75+
5. Enable transmitter, receiver, transmitter interrupt, receiver interrupt and USART1 clock.
76+
77+
```C
78+
USART1->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE | USART_CR1_UE;
79+
```
80+
5081
6. Enable interrupt for USART1
51-
`NVIC_EnableIRQ(USART1_IRQn);`
82+
83+
```C
84+
NVIC_EnableIRQ(USART1_IRQn);
85+
```
5286
5387
![Control Flow Diagram](https://github.com/csrohit/bluepill-baremetal-projects/blob/main/uart-polling/resources/flow.png "Control flow diagram for usart")
5488
89+
### Function description
90+
91+
1. `USART1_puts()` - prints a string to USART1.
92+
2. `USART1_putc()` - waits for the transmit data register (`TDR`) to be empty and loads new character in it.
93+
3. `USART1_IRQHandler()` - Interrupt service routine for USART1 related interrupts. If `RXNE` is set i.e. receiver not empty interrupt then it echoes the character back to usart.
94+
5595
## Project Working
5696
57-
This project configures SysTick timer and uses it to generate time accurate delay for blinking an LED. The onboard LED connected to pin C13 blinks every second.
97+
The application prints time elapsed since boot in interval of 5 seconds. Configure serial onitor on host for 9600 baudrate to be able to read and write to blue pill using uart.
5898
5999
## Dependencies
60100
61101
* **make**\
62102
Make utility is required for configuring and building this project. You can install make on linux by running command:
63103
64104
```bash
105+
# for debian/ubuntu
65106
sudo apt install build-essential
107+
108+
# for macos
109+
brew install make
66110
```
67111
68112
* **gcc-arm-none-eabi toolchain**\
@@ -71,12 +115,17 @@ This project configures SysTick timer and uses it to generate time accurate dela
71115
```bash
72116
sudo apt install gcc-arm-none-eabi
73117
```
118+
* For mac, visit ![ARM Downloads](https://developer.arm.com/downloads/-/gnu-rm) page to install arm embedded toolchain.
74119
75120
* **openocd**\
76121
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:
77122
78123
```bash
124+
# for debian/ubuntu
79125
sudo apt install openocd -y
126+
127+
# for macos
128+
brew install openocd
80129
```
81130

82131
* **Cortex Debug extension**\
@@ -87,19 +136,6 @@ This project configures SysTick timer and uses it to generate time accurate dela
87136
ext install marus25.cortex-debug
88137
```
89138

90-
## Project Structure
91-
92-
* `src` directory contains all source files for the project
93-
* `include` directory contains all header files for the project
94-
95-
### Source file description
96-
97-
* `STM32F103C8TX_FLASH.ld` - linker script
98-
* `src\main.c` - application code
99-
* `src\startup_stm32f103c8tx.s` - assembly startup script for blue pill board
100-
* `system_stm32f1xx.c` - clock configuration and system initialization functions
101-
* `STM32F103.svd` - contains the description of the system contained in Arm Cortex-M processor-based microcontrollers, in particular, the memory mapped registers of peripherals.
102-
103139
## Run Locally
104140

105141
Running the project is super easy. Just clone, build, and flash.

uart-polling/include/uart.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#pragma once
22

3-
// void uart_init();
4-
5-
3+
/**
4+
* @brief Initialize USART1 peripheral
5+
*
6+
* @param baudrate baudrate to be configurate
7+
*/
68
static inline void USART1_init(uint32_t baudrate)
79
{
810
// enable clock for GPIOA and USART1
9-
RCC->APB2ENR |= RCC_APB2ENR_USART1EN_Msk | RCC_APB2ENR_IOPAEN_Msk;
11+
RCC->APB2ENR |= RCC_APB2ENR_USART1EN | RCC_APB2ENR_IOPAEN;
1012

1113
// reset pin configurations for PA9 and PA10
1214
GPIOA->CRH &= ~(GPIO_CRH_MODE10 | GPIO_CRH_MODE9 | GPIO_CRH_CNF10 | GPIO_CRH_CNF9);
@@ -24,8 +26,26 @@ static inline void USART1_init(uint32_t baudrate)
2426
// transmitter enable, receiver enable, receiver interrupt enable and USART enable
2527
USART1->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE | USART_CR1_UE;
2628

29+
// enable USART1 interrupt
2730
NVIC_EnableIRQ(USART1_IRQn);
2831
}
2932

30-
void putch(char c);
31-
void putstr(const char *str);
33+
/**
34+
* @brief Transmit 1 character
35+
*
36+
* @param c character to be transmitted
37+
*/
38+
void USART1_putch(char c);
39+
40+
/**
41+
* @brief Transmit string
42+
*
43+
* @param str pointer to the string
44+
*/
45+
void USART1_puts(const char *str);
46+
47+
/**
48+
* @brief Interrupt service routine for USART1 related interrupts
49+
*
50+
*/
51+
void USART1_IRQHandler(void);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<mxfile host="Electron" modified="2022-11-11T16:28:17.644Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.3.0 Chrome/104.0.5112.114 Electron/20.1.3 Safari/537.36" etag="R0rUlnk7utbA5kOZ1j_B" version="20.3.0" type="device"><diagram id="eoFRF44f-ROiIzYbxTK2" name="Page-1">7V1bc5s6EP41eUwGIcTlMbf2dOacTidpp0lfOhhkmyk2LsZN0l9/RI1stAIjMLfEdR9ixCKDdr+9i57h68Xz+9hdzf+LfBqe6Zr/fIZvznQdaQSzP+nIy3bE4gOzOPAzov3AffCb8iuz0U3g07VAmERRmAQrcdCLlkvqJcKYG8fRk0g2jULxV1fujEoD954byqNfAz+Zb0dt3dqP/0OD2Zz/MjKd7ZmFy4mzJ1nPXT96yg3h2zN8HUdRsv22eL6mYbp4fF22170rObu7sZguE5ULLvVz5/vPeeJ9e/FfvtKf3vx6dY5Qdru/3HCTPXJ2u8kLX4NZHG1WGRmNE/pctPLuhJNr8p2h3fMyQaHRgibxCyP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rwzeV136Cmsk0Ru9gECumtz9fQdMWc0LJKuGfwcM0hSqKm94l0eL7wXTh9SetlMsWLV3g4BdFybML3edD0OyUX0zrSQZ2A71khADiUETfwvReFtLEHci23+14LhUAeezQm/asOEBtDJN425pIuiSda4M5ND1DSmDw75C+mILnucYMfiR7D+cp3ccMWeO/V0Gix9uLHGMrWIiMkv01pbRkgKXLxtSZ2qROymqmVKmHl/VAFVPC8mOXlFVA3fm5xW8mVfiirg6Fe54gRMtc6uQq0rLfvgFmcBLQQXtfBY3pEJzUoNNA+xw/x/jbHGz/++F8O3/</diagram></mxfile>
1+
<mxfile host="Electron" modified="2022-11-11T16:29:08.090Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.3.0 Chrome/104.0.5112.114 Electron/20.1.3 Safari/537.36" etag="T7QQIA_5njoSDqphC3Nz" version="20.3.0" type="device"><diagram id="eoFRF44f-ROiIzYbxTK2" name="Page-1">7R3Zcps69GvymAxCiOUxW3s7c2+nk7TTpC8dDLLNFBsX4ybp119RIxsdgRGYLXGdBxtxEHD2TcoZvl48v4/d1fy/yKfhma75z2f45kzXkUYw+0pHXrYjFh+YxYGfAe0H7oPflF+ZjW4Cn64FwCSKwiRYiYNetFxSLxHG3DiOnkSwaRSKd125MyoN3HtuKI9+Dfxkvh21dWs//g8NZnN+Z2Q62zMLlwNnb7Keu370lBvCt2f4Oo6iZPtr8XxNwxR5HC/b696VnN09WEyXicoFl/q58/3nPPG+vfgvX+lPb369Okd8nl9uuMleOXvc5IXjYBZHm1UGRuOEPhdh3p1wcE1+MrR7X8YoNFrQJH5hINlEOENZxiKIZDM87RFuoexu8xyyLScDdDMiz3ZT7/HAfmSoqIMW5PSBlkMkKcWWgQRsGTKyTI5AAVlGZ8iSUHV1+YV9ae/pksZuEsUS6hjmlj5NJ0Vn+OppHiT0fuV66dknpkfY2DxZhNnpaRCG11HIpkmvxdPpVPc8Nr5O4ugHzZ3xzYlJ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efKQA5d35AyOOwrpBtb8DzHiIUfyf7DefrEEXPm2PcyWPxwY4liDIuJSCzRW1tGSwpcvmxInahF7qSoZkqJenxVA1Q9LSQ7ekVVDdyZn1ewM69EFRE7Fe54gRMtU6uQqkegvWzfzC7+lQ073P/3oK287P8HE779Hw==</diagram></mxfile>

uart-polling/resources/.$flow.drawio.dtmp

Lines changed: 0 additions & 1 deletion
This file was deleted.

uart-polling/resources/.$uart.drawio.dtmp

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)