diff --git a/bsp/stm32/stm32f103-blue-pill/README.md b/bsp/stm32/stm32f103-blue-pill/README.md
index 837b725768..77bbfbd657 100644
--- a/bsp/stm32/stm32f103-blue-pill/README.md
+++ b/bsp/stm32/stm32f103-blue-pill/README.md
@@ -2,6 +2,8 @@
[[中文]](README_zh.md)
+[TOC]
+
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.
The document is covered in four parts:
@@ -13,9 +15,11 @@ The document is covered in four parts:
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.
+Video tutorial: https://www.youtube.com/watch?v=0PwBBYXQ08g
-## MCU Resources
+
+## 1 MCU Resources
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.
@@ -70,7 +74,7 @@ KEY FEATURES
-## Onboard Resources
+## 2 Onboard Resources
- MCU:STM32F103C8T6 @72MHz, 64KB FLASH , 20KB RAM
@@ -87,11 +91,11 @@ KEY FEATURES
-## Quickly Get Started
+## 3 Quickly Get Started
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.
-### Use ST-LINK Debugger to connect the Blue Pill Board
+### 3.1 Use ST-LINK Debugger to connect the Blue Pill Board
ST-LINK driver:
@@ -112,7 +116,7 @@ ST-LINK driver:
-### Use FTDI adapter(USB to UART) to connect the Blue Pill Board's PA9(Tx) and PA10(Rx) pins
+### 3.2 Use FTDI adapter(USB to UART) to connect the Blue Pill Board's PA9(Tx) and PA10(Rx) pins
FTDI adapter driver:
@@ -134,7 +138,7 @@ You can use other USB to UART adapters to replace FTDI adapter.
-### Make sure Jumper Position (Both 0 Position)
+### 3.3 Make sure Jumper Position (Both 0 Position)
| BOOTx | High / Low |
| :---: | :--------: |
@@ -145,7 +149,7 @@ You can use other USB to UART adapters to replace FTDI adapter.
-### Compile and Download
+### 3.4 Compile and Download
- Double-click the `project.uvprojx` file to open the MDK-Keil5 project (**NOT** `template.uvprojx` file)
- Click the “option for target” button
@@ -161,7 +165,7 @@ You can also follow this video to configurate *Blue Pill BSP* Keil5 project:
-### Running Results
+### 3.5 Running Results
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.
@@ -177,7 +181,7 @@ msh >
-### Terminal tool - PuTTy
+### 3.6 Terminal tool - PuTTy
If you have no terminal tool software available, you can download *PuTTy*:
@@ -195,7 +199,7 @@ These two videos will show you how to use PuTTy:
-## **Advanced Features**
+## 4 **Advanced Features**
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:
@@ -208,7 +212,52 @@ Learn how to use RT-Thread ENV, click [Here](https://github.com/RT-Thread/rtthre
-## Read more
+### 4.1 How to use USB virtual com as a console device
+
+#### 4.1.1 Step 1
+
+Enable USB device.
+
+
+
+
+
+#### 4.1.2 Step 2
+
+Enable USB Device Driver and enable to use device as CDC device.
+
+
+
+
+
+#### 4.1.3 Step 3
+
+Select VC (virtual console) software package.
+
+
+
+
+
+#### 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);
+```
+
+
+
+
+
+#### 4.1.5 Step 5
+
+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.
+
+
+
+## 5 Read more
- [[STM32 Blue Pill Board Schematic]](https://stm32duinoforum.com/forum/images/c/c1/wiki_subdomain/Vcc-gnd.com-STM32F103C8-schematic.pdf)
- [[STM32 Blue Pill vs Black Pill Microcontroller Boards]](https://www.youtube.com/watch?v=QCdnO43RBK4&t=875s)
@@ -219,7 +268,7 @@ Learn how to use RT-Thread ENV, click [Here](https://github.com/RT-Thread/rtthre
-## Maintained By
+## 6 Maintained By
Meco Man @ RT-Thread Community
diff --git a/bsp/stm32/stm32f103-blue-pill/README.pdf b/bsp/stm32/stm32f103-blue-pill/README.pdf
index 69de85e9d8..cd845f0ef0 100644
Binary files a/bsp/stm32/stm32f103-blue-pill/README.pdf and b/bsp/stm32/stm32f103-blue-pill/README.pdf differ
diff --git a/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/CubeMX_Config.ioc b/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/CubeMX_Config.ioc
index 385f09a9d9..fc82990525 100644
--- a/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/CubeMX_Config.ioc
+++ b/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/CubeMX_Config.ioc
@@ -14,26 +14,29 @@ Mcu.IP2=RCC
Mcu.IP3=SPI1
Mcu.IP4=SYS
Mcu.IP5=USART1
-Mcu.IP6=USB
-Mcu.IPNb=7
+Mcu.IP6=USART2
+Mcu.IP7=USB
+Mcu.IPNb=8
Mcu.Name=STM32F103C(8-B)Tx
Mcu.Package=LQFP48
Mcu.Pin0=PC14-OSC32_IN
Mcu.Pin1=PC15-OSC32_OUT
-Mcu.Pin10=PA11
-Mcu.Pin11=PA12
-Mcu.Pin12=PA13
-Mcu.Pin13=PA14
-Mcu.Pin14=VP_SYS_VS_Systick
+Mcu.Pin10=PA9
+Mcu.Pin11=PA10
+Mcu.Pin12=PA11
+Mcu.Pin13=PA12
+Mcu.Pin14=PA13
+Mcu.Pin15=PA14
+Mcu.Pin16=VP_SYS_VS_Systick
Mcu.Pin2=PD0-OSC_IN
Mcu.Pin3=PD1-OSC_OUT
Mcu.Pin4=PA1
-Mcu.Pin5=PA5
-Mcu.Pin6=PA6
-Mcu.Pin7=PA7
-Mcu.Pin8=PA9
-Mcu.Pin9=PA10
-Mcu.PinsNb=15
+Mcu.Pin5=PA2
+Mcu.Pin6=PA3
+Mcu.Pin7=PA5
+Mcu.Pin8=PA6
+Mcu.Pin9=PA7
+Mcu.PinsNb=17
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F103C8Tx
@@ -61,6 +64,10 @@ PA13.Mode=Serial_Wire
PA13.Signal=SYS_JTMS-SWDIO
PA14.Mode=Serial_Wire
PA14.Signal=SYS_JTCK-SWCLK
+PA2.Mode=Asynchronous
+PA2.Signal=USART2_TX
+PA3.Mode=Asynchronous
+PA3.Signal=USART2_RX
PA5.Mode=Full_Duplex_Master
PA5.Signal=SPI1_SCK
PA6.Mode=Full_Duplex_Master
@@ -105,7 +112,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=MDK-ARM V5
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false
-ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART1_UART_Init-USART1-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_SPI1_Init-SPI1-false-HAL-true
+ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART1_UART_Init-USART1-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_SPI1_Init-SPI1-false-HAL-true,6-MX_USB_PCD_Init-USB-false-HAL-true
RCC.ADCFreqValue=12000000
RCC.ADCPresc=RCC_ADCPCLK2_DIV6
RCC.AHBFreq_Value=72000000
@@ -139,6 +146,8 @@ SPI1.Mode=SPI_MODE_MASTER
SPI1.VirtualType=VM_MASTER
USART1.IPParameters=VirtualMode
USART1.VirtualMode=VM_ASYNC
+USART2.IPParameters=VirtualMode
+USART2.VirtualMode=VM_ASYNC
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
board=custom
diff --git a/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/main.c b/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/main.c
index b611a36e80..ca692ebc61 100644
--- a/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/main.c
+++ b/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/main.c
@@ -46,6 +46,7 @@ ADC_HandleTypeDef hadc1;
SPI_HandleTypeDef hspi1;
UART_HandleTypeDef huart1;
+UART_HandleTypeDef huart2;
PCD_HandleTypeDef hpcd_USB_FS;
@@ -60,6 +61,7 @@ static void MX_USART1_UART_Init(void);
static void MX_ADC1_Init(void);
static void MX_SPI1_Init(void);
static void MX_USB_PCD_Init(void);
+static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
@@ -101,6 +103,7 @@ int main(void)
MX_ADC1_Init();
MX_SPI1_Init();
MX_USB_PCD_Init();
+ MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
@@ -278,6 +281,39 @@ static void MX_USART1_UART_Init(void)
}
+/**
+ * @brief USART2 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_USART2_UART_Init(void)
+{
+
+ /* USER CODE BEGIN USART2_Init 0 */
+
+ /* USER CODE END USART2_Init 0 */
+
+ /* USER CODE BEGIN USART2_Init 1 */
+
+ /* USER CODE END USART2_Init 1 */
+ huart2.Instance = USART2;
+ huart2.Init.BaudRate = 115200;
+ huart2.Init.WordLength = UART_WORDLENGTH_8B;
+ huart2.Init.StopBits = UART_STOPBITS_1;
+ huart2.Init.Parity = UART_PARITY_NONE;
+ huart2.Init.Mode = UART_MODE_TX_RX;
+ huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart2.Init.OverSampling = UART_OVERSAMPLING_16;
+ if (HAL_UART_Init(&huart2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN USART2_Init 2 */
+
+ /* USER CODE END USART2_Init 2 */
+
+}
+
/**
* @brief USB Initialization Function
* @param None
diff --git a/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/stm32f1xx_hal_msp.c b/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/stm32f1xx_hal_msp.c
index 07504f02bb..03911da92a 100644
--- a/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/stm32f1xx_hal_msp.c
+++ b/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/stm32f1xx_hal_msp.c
@@ -242,17 +242,23 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /* USER CODE BEGIN USART1_MspInit 1 */
+
+ /* USER CODE END USART1_MspInit 1 */
}
-
- if(huart->Instance==USART2)
+ else if(huart->Instance==USART2)
{
+ /* USER CODE BEGIN USART2_MspInit 0 */
+
+ /* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
-
+
__HAL_RCC_GPIOA_CLK_ENABLE();
- /**USART1 GPIO Configuration
+ /**USART2 GPIO Configuration
PA2 ------> USART2_TX
- PA3 ------> USART2_RX
+ PA3 ------> USART2_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -263,7 +269,12 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /* USER CODE BEGIN USART2_MspInit 1 */
+
+ /* USER CODE END USART2_MspInit 1 */
}
+
}
/**
@@ -292,6 +303,24 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
/* USER CODE END USART1_MspDeInit 1 */
}
+ else if(huart->Instance==USART2)
+ {
+ /* USER CODE BEGIN USART2_MspDeInit 0 */
+
+ /* USER CODE END USART2_MspDeInit 0 */
+ /* Peripheral clock disable */
+ __HAL_RCC_USART2_CLK_DISABLE();
+
+ /**USART2 GPIO Configuration
+ PA2 ------> USART2_TX
+ PA3 ------> USART2_RX
+ */
+ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
+
+ /* USER CODE BEGIN USART2_MspDeInit 1 */
+
+ /* USER CODE END USART2_MspDeInit 1 */
+ }
}
diff --git a/bsp/stm32/stm32f103-blue-pill/figures/usb_code.png b/bsp/stm32/stm32f103-blue-pill/figures/usb_code.png
new file mode 100644
index 0000000000..aa7d171993
Binary files /dev/null and b/bsp/stm32/stm32f103-blue-pill/figures/usb_code.png differ
diff --git a/bsp/stm32/stm32f103-blue-pill/figures/usb_device1.png b/bsp/stm32/stm32f103-blue-pill/figures/usb_device1.png
new file mode 100644
index 0000000000..85302c7c97
Binary files /dev/null and b/bsp/stm32/stm32f103-blue-pill/figures/usb_device1.png differ
diff --git a/bsp/stm32/stm32f103-blue-pill/figures/usb_device2.png b/bsp/stm32/stm32f103-blue-pill/figures/usb_device2.png
new file mode 100644
index 0000000000..5cba1d8389
Binary files /dev/null and b/bsp/stm32/stm32f103-blue-pill/figures/usb_device2.png differ
diff --git a/bsp/stm32/stm32f103-blue-pill/figures/vconsole.png b/bsp/stm32/stm32f103-blue-pill/figures/vconsole.png
new file mode 100644
index 0000000000..3ff06e36e3
Binary files /dev/null and b/bsp/stm32/stm32f103-blue-pill/figures/vconsole.png differ
diff --git a/bsp/stm32/stm32f103-blue-pill/template.uvoptx b/bsp/stm32/stm32f103-blue-pill/template.uvoptx
index ffa72f632d..45a718e45d 100644
--- a/bsp/stm32/stm32f103-blue-pill/template.uvoptx
+++ b/bsp/stm32/stm32f103-blue-pill/template.uvoptx
@@ -73,7 +73,7 @@
0
- 1
+ 0
0
1
@@ -103,7 +103,7 @@
1
0
0
- 0
+ 6
@@ -114,9 +114,14 @@
- BIN\UL2CM3.DLL
+ STLink\ST-LINKIII-KEIL_SWO.dll
+
+ 0
+ ST-LINKIII-KEIL_SWO
+ -U -O206 -SF4000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P2 -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM)
+
0
JL2CM3
@@ -173,7 +178,6 @@
1
- 0
0
2
10000000
diff --git a/bsp/stm32/stm32f103-blue-pill/template.uvprojx b/bsp/stm32/stm32f103-blue-pill/template.uvprojx
index 90dfc422a0..7e245cdb2e 100644
--- a/bsp/stm32/stm32f103-blue-pill/template.uvprojx
+++ b/bsp/stm32/stm32f103-blue-pill/template.uvprojx
@@ -53,7 +53,7 @@
0
1
1
- 0
+ 1
.\build\keil\List\
1
0
@@ -183,7 +183,6 @@
0
0
0
- 0
0
0
8