1# STM32F103C8 Blue Pill Board BSP Introduction 2 3 [[中文]](README_zh.md) 4 5[TOC] 6 7This document records the introduction of the BSP (board support package) provided by the RT-Thread development team for the STM32F103C8 Blue Pill development board. 8 9The document is covered in four parts: 10 11- Onboard Resources 12- Quickly Get Started 13- Advanced Features 14- Read more 15 16By 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. 17 18Video tutorial: https://www.youtube.com/watch?v=0PwBBYXQ08g 19 20 21 22## 1 MCU Resources 23 24The STM32F103Cx 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. 25 26The 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. 27The STM32F103Cx 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. 28These 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. 29 30KEY FEATURES 31 32- ARM® 32-bit Cortex®-M3 CPU Core 33 - 72 MHz maximum frequency,1.25 DMIPS/MHz (Dhrystone 2.1) performance at 0 wait state memory access 34 - Single-cycle multiplication and hardware division 35- Memories 36 - 64 or 128 Kbytes of Flash memory 37 - 20 Kbytes of SRAM 38- Clock, reset and supply management 39 - 2.0 to 3.6 V application supply and I/Os 40 - POR, PDR, and programmable voltage detector (PVD) 41 - 4-to-16 MHz crystal oscillator 42 - Internal 8 MHz factory-trimmed RC 43 - Internal 40 kHz RC 44 - PLL for CPU clock 45 - 32 kHz oscillator for RTC with calibration 46- Low-power 47 - Sleep, Stop and Standby modes 48 - VBAT supply for RTC and backup registers 49- 2 x 12-bit, 1 μs A/D converters (up to 16 channels) 50 - Conversion range: 0 to 3.6 V 51 - Dual-sample and hold capability 52 - Temperature sensor 53- DMA 54 - 7-channel DMA controller 55 - Peripherals supported: Timers, ADC, SPIs, I2Cs and USARTs 56 57- Up to 80 fast I/O ports 58 - 26/37/51/80 I/Os, all mappable on 16 external interrupt vectors and almost all 5 V-tolerant 59- Debug mode 60 - Serial wire debug (SWD) & JTAG interfaces 61- 7 timers 62 - Three 16-bit timers, each with up to 4 IC/OC/PWM or pulse counter and quadrature (incremental) encoder input 63 - 16-bit, motor control PWM timer with dead-time generation and emergency stop 64 - 2 watchdog timers (Independent and Window) 65 - SysTick timer 24-bit downcounter 66- Up to 9 communication interfaces 67 - Up to 2 x I2C interfaces (SMBus/PMBus) 68 - Up to 3 USARTs (ISO 7816 interface, LIN, IrDA capability, modem control) 69 - Up to 2 SPIs (18 Mbit/s) 70 - CAN interface (2.0B Active) 71 - USB 2.0 full-speed interface 72- CRC calculation unit, 96-bit unique ID 73- Packages are ECOPACK® 74 75 76 77## 2 Onboard Resources 78 79- MCU:STM32F103C8T6 @72MHz, 64KB FLASH (can be extended to 128KB) , 20KB RAM 80 81- Peripherals 82 83 - LED:PB2 84 85- Debug IO interface type: ST-LINK V2 (SWD) 86 87 88 89 90 91 92 93 94## 3 Quickly Get Started 95 96This 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. 97 98**Attention please!!!** 99 100Before the compilation work, please open ENV and execute the following command (this command is used to pull the necessary HAL library and CMSIS library, otherwise it cannot be compiled): 101 102```bash 103pkgs --update 104``` 105 106### 3.1 Use ST-LINK Debugger to connect the Blue Pill Board 107 108ST-LINK driver: 109 110> https://www.st.com/en/development-tools/stsw-link009.html 111 112| ST-LINK Debugger | Blue Pill 4-Pin SWD | 113| :--------------: | :-----------------: | 114| SWDIO | IO | 115| SWDCLK | CLK | 116| VCC3.3 | VCC3.3 | 117| GND | GND | 118 119 120 121 122 123 124 125 126 127### 3.2 Use FTDI adapter(USB to UART) to connect the Blue Pill Board's PA9(Tx) and PA10(Rx) pins 128 129FTDI adapter driver: 130 131> https://www.ftdichip.com/FTDrivers.htm 132 133You can use other USB to UART adapters to replace FTDI adapter. 134 135| FTDI adapter(USB to UART) | Blue Pill Board | 136| :-----------------------: | :-----------------------------------: | 137| Tx | PA10 Rx | 138| Rx | PA9 Tx | 139| GND | GND | 140| VCC 3.3 | **Don't need to connect VCC 3.3 pin** | 141| VCC 5 | **Don't need to connect VCC 5 pin** | 142 143 144 145 146 147 148 149### 3.3 Make sure Jumper Position (Both 0 Position) 150 151| BOOTx | High / Low | 152| :---: | :--------: | 153| BOOT0 | 0 | 154| BOOT1 | 0 | 155 156 157 158 159 160### 3.4 Compile and Download 161 162#### 3.4.1 Using RT-Studio to create and compile the project 163 164***Please watch this tutorial video:*** 165 166- [RT-Thread RTOS Tutorial #3 | Advanced Skills - YouTube](https://www.youtube.com/watch?v=k4-ArvvIiR8) 167 168#### 3.4.2 Using Keil-MDK or IAR to compile the project 169 170- Double-click the `project.uvprojx` file to open the MDK-Keil5 project (**NOT** `template.uvprojx` file) 171- Click the “option for target” button 172 - Debug: Choose "ST-LINK Debugger" and Click "Setting" button: 173 - Port: choose "SW (Serial Wire)" 174 - Flash Download: check "Reset and Run" 175 176- Compile and download the program to the board 177 178 179 180### 3.5 Running Results 181 182After 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. 183 184The 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: 185 186```shell 187 \ | / 188- RT - Thread Operating System 189 / | \ 4.0.0 build Dec 21 2018 190 2006 - 2018 Copyright by rt-thread team 191msh > 192``` 193 194 195 196### 3.6 Terminal tool - PuTTy 197 198If you have no terminal tool software available, you can download ***PuTTy***: 199 200> https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html 201 202 203 204 205 206These two videos will show you how to use PuTTy: 207 208> https://www.youtube.com/watch?v=ab4ilbsteWU 209> 210> https://www.youtube.com/watch?v=dO-BMOzNKcI 211 212 213 214### 3.7 Peripheral Condition 215 216Each peripheral supporting condition for this BSP is as follows: 217 218| **On-board Peripherals** | **Support** | **Remark** | 219| ------------------------ | ----------- | ------------------------------------------------------------ | 220| LED | √ | PC13 | 221| USB Virtual Serial Port | √ | USB CDC | 222| **On-chip Peripherals** | **Support** | **Remark** | 223| GPIO | √ | | 224| UART | √ | USART1 / USART2 | 225| SPI | √ | SPI1 | 226| I2C | √ | software simulate | 227| USB | √ | USB Device | 228| ADC | √ | ADC1 IN1 | 229| RTC | √ | Support for external crystal oscillator and internal low-speed clocks | 230| PWM | | | 231| FLASH | | | 232| IWG | | | 233| UID | √ | STM32 Unique Device Identifier | 234 235 236 237### 3.8 MDK-Keil5 Simulator 238 239 If you haven't had a real Blue Pill Board yet, you may use MDK-Keil5 simulator to simulate to run RT-Thread on Blue Pill Board. Please Double-click the `project.uvprojx` file to open the MDK-Keil5 project (**NOT** `template.uvprojx` file). 240 241 242 243 244 245 246 247 248 249 250 251 252 253## 4 **Advanced Features** 254 255This 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: 256 2571. Open the ENV tool under the specific BSP folder, eg: *bsp/stm32/stm32f103-blue-pill* ; 2582. Enter `menuconfig` command to configure the project, then save and exit; 2593. Enter `pkgs --update` command to update the package; 2604. Enter `scons --target=mdk4/mdk5/iar` command to regenerate the project. 261 262Learn how to use RT-Thread ENV, click [Here](https://github.com/RT-Thread/rt-thread/blob/master/documentation/env/env.md). 263 264 265 266### 4.1 How to use USB virtual com as a console device 267 268**Step 1: Enable USB device.** 269 270 271 272 273 274**Step 2: Enable USB Device Driver and enable to use device as CDC device.** 275 276 277 278 279 280**Step 3: Select vconsole (virtual console) software package.** 281 282 283 284 285 286**Step 4: Add these codes in main function which is located in 'Applications' folder.** 287 288```c 289#include <vconsole.h> 290 291rt_device_t dev = rt_device_find("vcom"); 292vconsole_switch(dev); 293``` 294 295 296 297 298 299**Step 5: Download the new program to your blue pill board.** 300 301Re-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. 302 303 304 305### 4.2 How to extend Blue Pill board’s Flash space 306 307According to ST official datasheet, STM32F103C8 has 64KB of Flash. However, STM32F103C8 and STM32F103CB use the same type of silicon die, which means STM32F103C8 also has 128KB ROM in theory, but ST locked the high 64KB. Basically, to force the debugger to download program can unlock the high 64KB. There is a good news that **Keil5 / IAR / RT-Studio will help you to unlock the Blue Pill Board high 64KB block** if you use this Blue Pill Board BSP as a template to create your project. You just need to press the "Flash Download" button as usual. What you only need to remember is that Blue Pill board has 128KB of Flash rather than 64KB. 308 309 310 311## 5 Read more 312 313- [[STM32 Blue Pill Board Schematic]](https://stm32duinoforum.com/forum/images/c/c1/wiki_subdomain/Vcc-gnd.com-STM32F103C8-schematic.pdf) 314- [[STM32 Blue Pill vs Black Pill Microcontroller Boards]](https://www.youtube.com/watch?v=QCdnO43RBK4&t=875s) 315- [[STM32F103C8 datasheet]]( https://www.st.com/resource/en/datasheet/stm32f103c8.pdf) 316- [[STM32F103C8 More Information (ST official)]](https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html#overview) 317- [[RT-Thread document center]](https://www.rt-thread.io/document/site/introduction/introduction/) 318 319 320 321 322## 6 Maintained By 323 324[Meco Man](https://github.com/mysterywolf) @ RT-Thread Community 325 326jiantingman@foxmail.com 327 328