README.md 9.4 KB
Newer Older
mysterywolf's avatar
mysterywolf 已提交
1 2
# STM32F103C8 Blue Pill Board BSP Introduction

mysterywolf's avatar
mysterywolf 已提交
3
 [[中文]](README_zh.md)
mysterywolf's avatar
mysterywolf 已提交
4

mysterywolf's avatar
mysterywolf 已提交
5 6
[TOC]

mysterywolf's avatar
mysterywolf 已提交
7
This document records the introduction of the BSP (board support package) provided by the RT-Thread development team for the STM32F103C8 Blue Pill development board.
mysterywolf's avatar
mysterywolf 已提交
8 9 10 11 12 13

The document is covered in four parts:

- Onboard Resources
- Quickly Get Started
- Advanced Features
14
- Read more
mysterywolf's avatar
mysterywolf 已提交
15 16 17

By reading the ***Quickly Get Started*** section developers can quickly get their hands on this BSP and run RT-Thread on the board. More advanced features will be introduced in the Advanced Features section to help developers take advantage of RT-Thread to drive more on-board resources.

mysterywolf's avatar
mysterywolf 已提交
18 19
Video tutorial: https://www.youtube.com/watch?v=0PwBBYXQ08g

mysterywolf's avatar
mysterywolf 已提交
20 21


mysterywolf's avatar
mysterywolf 已提交
22
## 1 MCU Resources
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

The STM32F103xx medium-density performance line family incorporates the high-performance ARM®Cortex®-M3 32-bit RISC core operating at a 72 MHz frequency, high-speed embedded memories (Flash memory up to 128 Kbytes and SRAM up to 20 Kbytes), and an extensive range of enhanced I/Os and peripherals connected to two APB buses. All devices offer two 12-bit ADCs, three general purpose 16-bit timers plus one PWM timer, as well as standard and advanced communication interfaces: up to two I2Cs and SPIs, three USARTs, an USB and a CAN.

The devices operate from a 2.0 to 3.6 V power supply. They are available in both the –40 to +85 °C temperature range and the –40 to +105 °C extended temperature range. A comprehensive set of power-saving mode allows the design of low-power applications.
The STM32F103xx medium-density performance line family includes devices in six different package types: from 36 pins to 100 pins. Depending on the device chosen, different sets of peripherals are included, the description below gives an overview of the complete range of peripherals proposed in this family.
These features make the STM32F103xx medium-density performance line microcontroller family suitable for a wide range of applications such as motor drives, application control, medical and handheld equipment, PC and gaming peripherals, GPS platforms, industrial applications, PLCs, inverters, printers, scanners, alarm systems, video intercoms, and HVACs.

KEY FEATURES

- ARM® 32-bit Cortex®-M3 CPU Core
  - 72 MHz maximum frequency,1.25 DMIPS/MHz (Dhrystone 2.1) performance at 0 wait state memory access
  - Single-cycle multiplication and hardware division
- Memories
  - 64 or 128 Kbytes of Flash memory
  - 20 Kbytes of SRAM
- Clock, reset and supply management
  - 2.0 to 3.6 V application supply and I/Os
  - POR, PDR, and programmable voltage detector (PVD)
  - 4-to-16 MHz crystal oscillator
  - Internal 8 MHz factory-trimmed RC
  - Internal 40 kHz RC
  - PLL for CPU clock
  - 32 kHz oscillator for RTC with calibration
- Low-power
  - Sleep, Stop and Standby modes
  - VBAT supply for RTC and backup registers
- 2 x 12-bit, 1 μs A/D converters (up to 16 channels)
  - Conversion range: 0 to 3.6 V
  - Dual-sample and hold capability
  - Temperature sensor
- DMA
  - 7-channel DMA controller
mysterywolf's avatar
mysterywolf 已提交
55
  - Peripherals supported: Timers, ADC, SPIs, I2Cs and USARTs
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

- Up to 80 fast I/O ports
  - 26/37/51/80 I/Os, all mappable on 16 external interrupt vectors and almost all 5 V-tolerant
- Debug mode
  - Serial wire debug (SWD) & JTAG interfaces
- 7 timers
  - Three 16-bit timers, each with up to 4 IC/OC/PWM or pulse counter and quadrature (incremental) encoder input
  - 16-bit, motor control PWM timer with dead-time generation and emergency stop
  - 2 watchdog timers (Independent and Window)
  - SysTick timer 24-bit downcounter
- Up to 9 communication interfaces
  - Up to 2 x I2C interfaces (SMBus/PMBus)
  - Up to 3 USARTs (ISO 7816 interface, LIN, IrDA capability, modem control)
  - Up to 2 SPIs (18 Mbit/s)
  - CAN interface (2.0B Active)
  - USB 2.0 full-speed interface
- CRC calculation unit, 96-bit unique ID
- Packages are ECOPACK®

mysterywolf's avatar
mysterywolf 已提交
75

76

mysterywolf's avatar
mysterywolf 已提交
77
## 2 Onboard Resources
mysterywolf's avatar
mysterywolf 已提交
78

mysterywolf's avatar
mysterywolf 已提交
79
- MCU:STM32F103C8T6 @72MHz, 64KB FLASH , 20KB RAM
mysterywolf's avatar
mysterywolf 已提交
80 81 82 83 84

- Peripherals
  
  - LED:PC13
  
85
- Debug IO interface type: ST-LINK V2 (SWD)
mysterywolf's avatar
mysterywolf 已提交
86 87


mysterywolf's avatar
mysterywolf 已提交
88
![board](figures/Bluepill_pinout.png)
mysterywolf's avatar
mysterywolf 已提交
89 90 91 92 93





mysterywolf's avatar
mysterywolf 已提交
94
## 3 Quickly Get Started
mysterywolf's avatar
mysterywolf 已提交
95 96 97

This BSP provides MDK4, MDK5, and IAR projects for developers and it supports the GCC development environment. Here's an example of the MDK5 development environment, to introduce how to run the system.

mysterywolf's avatar
mysterywolf 已提交
98
### 3.1 Use ST-LINK Debugger to connect the Blue Pill Board
99

100 101 102
ST-LINK driver: 

> https://www.st.com/en/development-tools/stsw-link009.html
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

| ST-LINK Debugger | Blue Pill 4-Pin SWD |
| :--------------: | :-----------------: |
|      SWDIO       |         IO          |
|      SWDCLK      |         CLK         |
|      VCC3.3      |       VCC3.3        |
|       GND        |         GND         |

![connection](figures/connecter1.jpeg)

![connection](figures/connecter2.png)

![connection](figures/connecter3.jpeg)



mysterywolf's avatar
mysterywolf 已提交
119
### 3.2 Use FTDI adapter(USB to UART) to connect the Blue Pill Board's PA9(Tx) and PA10(Rx) pins
120

121 122 123
FTDI adapter driver:

> https://www.ftdichip.com/FTDrivers.htm
124 125 126 127 128 129 130 131 132 133

You can use other USB to UART adapters to replace FTDI adapter.

| FTDI adapter(USB to UART) |            Blue Pill Board            |
| :-----------------------: | :-----------------------------------: |
|            Tx             |                PA10 Rx                |
|            Rx             |                PA9 Tx                 |
|            GND            |                  GND                  |
|          VCC 3.3          | **Don't need to connect VCC 3.3 pin** |
|           VCC 5           |  **Don't need to connect VCC 5 pin**  |
mysterywolf's avatar
mysterywolf 已提交
134 135 136



mysterywolf's avatar
mysterywolf 已提交
137
![connection](figures/connection.jpg)
mysterywolf's avatar
mysterywolf 已提交
138

139 140


mysterywolf's avatar
mysterywolf 已提交
141
### 3.3 Make sure Jumper Position (Both 0 Position)
142 143 144 145 146 147 148 149 150 151

| BOOTx | High / Low |
| :---: | :--------: |
| BOOT0 |     0      |
| BOOT1 |     0      |

![connection](figures/jumper.jpg)



mysterywolf's avatar
mysterywolf 已提交
152
### 3.4 Compile and Download
mysterywolf's avatar
mysterywolf 已提交
153

154
- Double-click the `project.uvprojx` file to open the MDK-Keil5 project  (**NOT** `template.uvprojx` file)
155 156 157 158 159 160 161
- Click the “option for target” button
  - Debug: Choose "ST-LINK Debugger" and Click "Setting" button:
    - Port: choose "SW (Serial Wire)"
    - Flash Download: check "Reset and Run"

- Compile and download the program to the board

162 163 164 165
You can also follow this video to configurate *Blue Pill BSP* Keil5 project: 

> https://www.youtube.com/watch?v=0PwBBYXQ08g&t

166

mysterywolf's avatar
mysterywolf 已提交
167

mysterywolf's avatar
mysterywolf 已提交
168
### 3.5 Running Results
mysterywolf's avatar
mysterywolf 已提交
169

mysterywolf's avatar
mysterywolf 已提交
170
After the program is successfully downloaded, the system runs automatically. Observe the running results of the LED on the development board, and you will see the LED is flashing periodically.
mysterywolf's avatar
mysterywolf 已提交
171

172
The COM port connects to **USART1 (PA9-Tx, PA10-Rx) by default**, and when the corresponding serial port (**115200**-8-1-N) is opened in the terminal tool, the output information of RT-Thread can be seen when the device is reset:
mysterywolf's avatar
mysterywolf 已提交
173 174 175 176 177 178 179 180 181

```shell
 \ | /
- RT -     Thread Operating System
 / | \     4.0.0 build Dec 21 2018
 2006 - 2018 Copyright by rt-thread team
msh >
```

182 183


mysterywolf's avatar
mysterywolf 已提交
184
### 3.6 Terminal tool - PuTTy 
185 186 187 188 189 190 191 192 193 194 195 196 197 198

If you have no terminal tool software available, you can download *PuTTy*:

>  https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

![putty](figures/putty.png)



These two videos will show you how to use PuTTy:

> https://www.youtube.com/watch?v=ab4ilbsteWU
>
> https://www.youtube.com/watch?v=dO-BMOzNKcI
199

mysterywolf's avatar
mysterywolf 已提交
200 201


mysterywolf's avatar
mysterywolf 已提交
202
## 4 **Advanced Features**
mysterywolf's avatar
mysterywolf 已提交
203

204
This BSP only enables GPIO and USART1 by default. If you need more advanced features such as SPI, ADC, or to add software packages, you need to configure the BSP with RT-Thread [ENV tool](https://www.rt-thread.io/download.html?download=Env), as follows:
mysterywolf's avatar
mysterywolf 已提交
205

mysterywolf's avatar
mysterywolf 已提交
206
1. Open the ENV tool under the specific BSP folder, eg: *bsp/stm32/stm32f103-blue-pill* ;
mysterywolf's avatar
mysterywolf 已提交
207 208 209 210 211 212 213 214
2. Enter `menuconfig` command to configure the project, then save and exit;
3. Enter `pkgs --update` command to update the package;
4. Enter `scons --target=mdk4/mdk5/iar` command to regenerate the project.

Learn how to use RT-Thread ENV, click [Here](https://github.com/RT-Thread/rtthread-manual-doc/blob/master/env/env.md).



mysterywolf's avatar
update  
mysterywolf 已提交
215
### 4.1 How to use USB virtual com as a console device
mysterywolf's avatar
mysterywolf 已提交
216 217 218 219 220

#### 4.1.1 Step 1

Enable USB device.

221
![usb_device1](figures/usb_device1.png)
mysterywolf's avatar
mysterywolf 已提交
222 223 224 225 226 227 228



#### 4.1.2 Step 2

Enable USB Device Driver and enable to use device as CDC device.

229
![usb_device2](figures/usb_device2.png)
mysterywolf's avatar
mysterywolf 已提交
230 231 232 233 234 235 236



#### 4.1.3 Step 3

Select VC (virtual console) software package.

237
![vconsole](figures/vconsole.png)
mysterywolf's avatar
mysterywolf 已提交
238 239 240 241 242 243 244 245 246 247 248 249



#### 4.1.4 Step 4

Add these codes in main function which is located in 'Applications' folder, and don't forget to include `vconsole.h`.

```c
rt_device_t dev = rt_device_find("vcom");
vconsole_switch(dev);
```

250
![usb_code](figures/usb_code.png)
mysterywolf's avatar
mysterywolf 已提交
251 252 253 254 255



#### 4.1.5 Step 5

mysterywolf's avatar
update  
mysterywolf 已提交
256
Download the new program to your blue pill board. Re-plug the USB cable and you will find a new serial (virtual com, 115200, 8-N-1) device in your computer. Then, you can use the USB instead of the UART-USB adapter as a console and send commands through USB cable. If you reset or reboot the blue pill board, you'll still need to re-plug the USB cable. 
mysterywolf's avatar
mysterywolf 已提交
257 258 259 260



## 5 Read more
mysterywolf's avatar
mysterywolf 已提交
261

262
- [[STM32 Blue Pill Board Schematic]](https://stm32duinoforum.com/forum/images/c/c1/wiki_subdomain/Vcc-gnd.com-STM32F103C8-schematic.pdf)
mysterywolf's avatar
mysterywolf 已提交
263 264
- [[STM32 Blue Pill vs Black Pill Microcontroller Boards]](https://www.youtube.com/watch?v=QCdnO43RBK4&t=875s)
- [[STM32F103C8 datasheet]]( https://www.st.com/resource/en/datasheet/stm32f103c8.pdf)
265 266
- [[STM32F103C8 More Information (ST official)]](https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html#overview)
- [[RT-Thread document center]](https://www.rt-thread.io/document/site/introduction/introduction/)
mysterywolf's avatar
mysterywolf 已提交
267 268 269 270




mysterywolf's avatar
mysterywolf 已提交
271
## 6 Maintained By
mysterywolf's avatar
mysterywolf 已提交
272

273
Meco Man @ RT-Thread Community
mysterywolf's avatar
mysterywolf 已提交
274 275 276

jiantingman@foxmail.com 

mysterywolf's avatar
mysterywolf 已提交
277
https://github.com/mysterywolf