Skip to content

Commit 50160b0

Browse files
committed
📝 update readme
1 parent 8eb3d72 commit 50160b0

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

uart-polling/README.md

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,38 @@ Connect the board with host through USB to TTL converter (FTDI board in our case
1919
| PA10 | Tx |
2020
| Gnd | Gnd |
2121

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

2424
## Control flow
2525

26-
![Control Flow Diagram](https://github.com/csrohit/bluepill-baremetal-projects/blob/main/uart-polling/resources/flow.png "USART: Control folow diagram")
27-
28-
1. Program the reload value:\
29-
The reload value can be loaded by setting `LOAD` register. This value is set to 1 less that the number of clock cycles needed for the interrupt as the timer counts both reload value as well as zero. e.g. If the SysTick interrupt is required every 100 clock pulses, set RELOAD to 99.
30-
2. Clear current value:\
31-
This register can be accessed using `VAL` variable. Bits *24:31* are reserved and 24 bit value can be read from bits *23:0*. Writing any value this register sets it to zero along with setting `COUNT_FLAG` to zero.
32-
3. Configure SysTick and start:
33-
1. Select clock source-\
34-
Clock source can be set using `CLKSOURCE` bit (2) of `CTRL` register.\
35-
0 - AHB/8\
36-
1 - Processor Clock (AHB)
37-
2. Enable Tick interrupt-\
38-
To enable Tick interrupt set `TICKINT` bit (2) of `CTRL` register.
39-
3. Start SysTick timer-\
40-
`ENABLE` bit (0) of `CTRL` register enables the counter. When `ENABLE` is set to 1, the counter loads the `RELOAD` value from the `LOAD` register and then counts down. On reaching 0, it sets the `COUNTFLAG` to 1 and optionally asserts the `SysTick` depending on the value of `TICKINT`. It then loads the `RELOAD` value again, and begins counting.
26+
The initialisation function accomplishes following tasks
27+
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);`
32+
3. Set appropriate mode and configuration for PA9 and PA10.
33+
* PA9 as push-pull output at 50MHz speed.
34+
* PA10 as floating input.
35+
36+
```C
37+
GPIOA->CRH |= GPIO_CRH_MODE9_0 | GPIO_CRH_MODE9_1 | GPIO_CRH_CNF9_1;
38+
GPIOA->CRH |= GPIO_CRH_CNF10_0;
39+
```
40+
41+
4. Calculate and set baud rate values in register.
42+
43+
```C
44+
uint32_t baud = (uint32_t)(SystemCoreClock / baudrate);
45+
USART1->BRR = baud;
46+
```
47+
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;`\
50+
6. Enable interrupt for USART1
51+
`NVIC_EnableIRQ(USART1_IRQn);`
52+
53+
![Control Flow Diagram](https://github.com/csrohit/bluepill-baremetal-projects/blob/main/uart-polling/resources/flow.png "Control flow diagram for usart")
4154

4255
## Project Working
4356

@@ -96,15 +109,15 @@ Running the project is super easy. Just clone, build, and flash.
96109
1. Using https
97110

98111
```bash
99-
git clone https://github.com/csrohit/bluepill-systick.git
100-
cd bluepill-systick
112+
git clone git@github.com:csrohit/bluepill-baremetal-projects.git
113+
cd bluepill-baremetal-projects/uart-polling
101114
```
102115

103116
2. Using ssh
104117

105118
```bash
106-
git clone git@github.com:csrohit/bluepill-systick.git
107-
cd bluepill-systick
119+
git clone git@github.com:csrohit/bluepill-baremetal-projects.git
120+
cd bluepill-baremetal-projects/uart-polling
108121
```
109122

110123
## Configuration

0 commit comments

Comments
 (0)