Merge pull request #4238 from mysterywolf/master

[stm32][bsp][bluepill] update readme and update cubemx project
This commit is contained in:
Bernard Xiong 2021-01-17 15:54:53 +08:00 committed by GitHub
commit 2d71a33248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 163 additions and 37 deletions

View File

@ -2,6 +2,8 @@
[[中文]](README_zh.md) [[中文]](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. 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: 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. 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. 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
- MCUSTM32F103C8T6 @72MHz, 64KB FLASH , 20KB RAM - MCUSTM32F103C8T6 @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. 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: 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: 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 | | 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) - Double-click the `project.uvprojx` file to open the MDK-Keil5 project (**NOT** `template.uvprojx` file)
- Click the “option for target” button - 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. 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*: 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: 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.
![putty](figures/usb_device1.png)
#### 4.1.2 Step 2
Enable USB Device Driver and enable to use device as CDC device.
![putty](figures/usb_device2.png)
#### 4.1.3 Step 3
Select VC (virtual console) software package.
![putty](figures/vconsole.png)
#### 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);
```
![putty](figures/usb_code.png)
#### 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 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) - [[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 Meco Man @ RT-Thread Community

View File

@ -14,26 +14,29 @@ Mcu.IP2=RCC
Mcu.IP3=SPI1 Mcu.IP3=SPI1
Mcu.IP4=SYS Mcu.IP4=SYS
Mcu.IP5=USART1 Mcu.IP5=USART1
Mcu.IP6=USB Mcu.IP6=USART2
Mcu.IPNb=7 Mcu.IP7=USB
Mcu.IPNb=8
Mcu.Name=STM32F103C(8-B)Tx Mcu.Name=STM32F103C(8-B)Tx
Mcu.Package=LQFP48 Mcu.Package=LQFP48
Mcu.Pin0=PC14-OSC32_IN Mcu.Pin0=PC14-OSC32_IN
Mcu.Pin1=PC15-OSC32_OUT Mcu.Pin1=PC15-OSC32_OUT
Mcu.Pin10=PA11 Mcu.Pin10=PA9
Mcu.Pin11=PA12 Mcu.Pin11=PA10
Mcu.Pin12=PA13 Mcu.Pin12=PA11
Mcu.Pin13=PA14 Mcu.Pin13=PA12
Mcu.Pin14=VP_SYS_VS_Systick Mcu.Pin14=PA13
Mcu.Pin15=PA14
Mcu.Pin16=VP_SYS_VS_Systick
Mcu.Pin2=PD0-OSC_IN Mcu.Pin2=PD0-OSC_IN
Mcu.Pin3=PD1-OSC_OUT Mcu.Pin3=PD1-OSC_OUT
Mcu.Pin4=PA1 Mcu.Pin4=PA1
Mcu.Pin5=PA5 Mcu.Pin5=PA2
Mcu.Pin6=PA6 Mcu.Pin6=PA3
Mcu.Pin7=PA7 Mcu.Pin7=PA5
Mcu.Pin8=PA9 Mcu.Pin8=PA6
Mcu.Pin9=PA10 Mcu.Pin9=PA7
Mcu.PinsNb=15 Mcu.PinsNb=17
Mcu.ThirdPartyNb=0 Mcu.ThirdPartyNb=0
Mcu.UserConstants= Mcu.UserConstants=
Mcu.UserName=STM32F103C8Tx Mcu.UserName=STM32F103C8Tx
@ -61,6 +64,10 @@ PA13.Mode=Serial_Wire
PA13.Signal=SYS_JTMS-SWDIO PA13.Signal=SYS_JTMS-SWDIO
PA14.Mode=Serial_Wire PA14.Mode=Serial_Wire
PA14.Signal=SYS_JTCK-SWCLK 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.Mode=Full_Duplex_Master
PA5.Signal=SPI1_SCK PA5.Signal=SPI1_SCK
PA6.Mode=Full_Duplex_Master PA6.Mode=Full_Duplex_Master
@ -105,7 +112,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=MDK-ARM V5 ProjectManager.TargetToolchain=MDK-ARM V5
ProjectManager.ToolChainLocation= ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false 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.ADCFreqValue=12000000
RCC.ADCPresc=RCC_ADCPCLK2_DIV6 RCC.ADCPresc=RCC_ADCPCLK2_DIV6
RCC.AHBFreq_Value=72000000 RCC.AHBFreq_Value=72000000
@ -139,6 +146,8 @@ SPI1.Mode=SPI_MODE_MASTER
SPI1.VirtualType=VM_MASTER SPI1.VirtualType=VM_MASTER
USART1.IPParameters=VirtualMode USART1.IPParameters=VirtualMode
USART1.VirtualMode=VM_ASYNC USART1.VirtualMode=VM_ASYNC
USART2.IPParameters=VirtualMode
USART2.VirtualMode=VM_ASYNC
VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick VP_SYS_VS_Systick.Signal=SYS_VS_Systick
board=custom board=custom

View File

@ -46,6 +46,7 @@ ADC_HandleTypeDef hadc1;
SPI_HandleTypeDef hspi1; SPI_HandleTypeDef hspi1;
UART_HandleTypeDef huart1; UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
PCD_HandleTypeDef hpcd_USB_FS; 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_ADC1_Init(void);
static void MX_SPI1_Init(void); static void MX_SPI1_Init(void);
static void MX_USB_PCD_Init(void); static void MX_USB_PCD_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */ /* USER CODE BEGIN PFP */
/* USER CODE END PFP */ /* USER CODE END PFP */
@ -101,6 +103,7 @@ int main(void)
MX_ADC1_Init(); MX_ADC1_Init();
MX_SPI1_Init(); MX_SPI1_Init();
MX_USB_PCD_Init(); MX_USB_PCD_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
/* USER CODE END 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 * @brief USB Initialization Function
* @param None * @param None

View File

@ -242,17 +242,23 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE BEGIN USART1_MspInit 1 */
/* USER CODE END USART1_MspInit 1 */
} }
else if(huart->Instance==USART2)
if(huart->Instance==USART2)
{ {
/* USER CODE BEGIN USART2_MspInit 0 */
/* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */ /* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE(); __HAL_RCC_USART2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE();
/**USART1 GPIO Configuration /**USART2 GPIO Configuration
PA2 ------> USART2_TX PA2 ------> USART2_TX
PA3 ------> USART2_RX PA3 ------> USART2_RX
*/ */
GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 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.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 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 */ /* 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 */
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -73,7 +73,7 @@
<LExpSel>0</LExpSel> <LExpSel>0</LExpSel>
</OPTXL> </OPTXL>
<OPTFL> <OPTFL>
<tvExp>1</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>1</IsCurrentTarget> <IsCurrentTarget>1</IsCurrentTarget>
</OPTFL> </OPTFL>
@ -103,7 +103,7 @@
<bEvRecOn>1</bEvRecOn> <bEvRecOn>1</bEvRecOn>
<bSchkAxf>0</bSchkAxf> <bSchkAxf>0</bSchkAxf>
<bTchkAxf>0</bTchkAxf> <bTchkAxf>0</bTchkAxf>
<nTsel>0</nTsel> <nTsel>6</nTsel>
<sDll></sDll> <sDll></sDll>
<sDllPa></sDllPa> <sDllPa></sDllPa>
<sDlgDll></sDlgDll> <sDlgDll></sDlgDll>
@ -114,9 +114,14 @@
<tDlgDll></tDlgDll> <tDlgDll></tDlgDll>
<tDlgPa></tDlgPa> <tDlgPa></tDlgPa>
<tIfile></tIfile> <tIfile></tIfile>
<pMon>BIN\UL2CM3.DLL</pMon> <pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
</DebugOpt> </DebugOpt>
<TargetDriverDllRegistry> <TargetDriverDllRegistry>
<SetRegEntry>
<Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key>
<Name>-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)</Name>
</SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>JL2CM3</Key> <Key>JL2CM3</Key>
@ -173,7 +178,6 @@
<pMultCmdsp></pMultCmdsp> <pMultCmdsp></pMultCmdsp>
<DebugDescription> <DebugDescription>
<Enable>1</Enable> <Enable>1</Enable>
<EnableFlashSeq>0</EnableFlashSeq>
<EnableLog>0</EnableLog> <EnableLog>0</EnableLog>
<Protocol>2</Protocol> <Protocol>2</Protocol>
<DbgClock>10000000</DbgClock> <DbgClock>10000000</DbgClock>

View File

@ -53,7 +53,7 @@
<CreateLib>0</CreateLib> <CreateLib>0</CreateLib>
<CreateHexFile>1</CreateHexFile> <CreateHexFile>1</CreateHexFile>
<DebugInformation>1</DebugInformation> <DebugInformation>1</DebugInformation>
<BrowseInformation>0</BrowseInformation> <BrowseInformation>1</BrowseInformation>
<ListingPath>.\build\keil\List\</ListingPath> <ListingPath>.\build\keil\List\</ListingPath>
<HexFormatSelection>1</HexFormatSelection> <HexFormatSelection>1</HexFormatSelection>
<Merge32K>0</Merge32K> <Merge32K>0</Merge32K>
@ -183,7 +183,6 @@
<hadXRAM>0</hadXRAM> <hadXRAM>0</hadXRAM>
<uocXRam>0</uocXRam> <uocXRam>0</uocXRam>
<RvdsVP>0</RvdsVP> <RvdsVP>0</RvdsVP>
<RvdsMve>0</RvdsMve>
<hadIRAM2>0</hadIRAM2> <hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2> <hadIROM2>0</hadIROM2>
<StupSel>8</StupSel> <StupSel>8</StupSel>