Ardunio and HAL library function programming

1. Complete the serial communication program of the STM32 board in Ardunio

1. Install Ardunio software

1. We find the installation compressed package and
Insert picture description here
decompress it. After decompression is complete, double-click arduino-1.8.12-windows.exe to install it normally, and install it by default. And copy the entire folder of Arduino_STM32 in the package file to hareware in the Arduino IDE installation directory/
Insert picture description here
Insert picture description here
2. Open Ardunio as shown in the figure:
Insert picture description here
3. Install the compile support file in Arduion
menu bar\tools\development board...\of the first column Development Board Manager
Enter ARM keyword search, select the compilation support file of Cortex-M3 series and install it. After the installation is complete, exit the development board manager.
Insert picture description here
4. Install the STM32 firmware burning software, double-click the flash_loader_demo_v2.8.0.exe in the package file to install, this is the official ST burning software.
Insert picture description here

2. Compile and burn

1. After the installation is complete, configure the chip type in the menu bar\tools\development board. Since I am using the stm32f103 guide, I choose Generic STM32F103V series.
Variant: STM32F103VE
Upload mode: serial
CPUSpeed: 72Mhz (Normal)
Optimize: Smallest (default)
Insert picture description here
2. Enter the code

int flag=1;   
char Stop[]="stop\n";
void setup() {
    
    
//初始化
pinMode(PB0, OUTPUT);//PB0为绿色,PB1为蓝色,PB5为红色,可根据需要改动
Serial.begin(115200);
}
void loop() {
    
    
int i=0,flag_s=0;
char inByte[50];
digitalWrite(PB0, HIGH); //小灯亮
delay(500); // 延迟
digitalWrite(PB0, LOW); //小灯灭
delay(500); // 延迟
while (Serial.available()> 0)     //当发送缓冲区有数据时
{
    
    
        inByte[i] = Serial.read();    //从串口的缓冲区取出并读取一个Byte的数据
        delay(10); 
        i++ ;                              
}
if(Stop[i]=inByte[i])
{
    
    
  if(Stop[i-1]==inByte[i-1]&&Stop[i-2]==inByte[i-2]&&Stop[i-3]==inByte[i-3])
  {
    
    
  flag=0;
  Serial.println("收到!");
  }
}
if(flag==1)
{
    
      
Serial.println("Hello World!");//向串口发送数据
delay(100); // 延迟
}
}

5. Open the serial monitor to observe the serial output, and set the baud rate to "115200".
The result is as follows: the
Insert picture description here
development board burning is completed:
Insert picture description here
Insert picture description here

Second, the stm32 programming mode difference between standard library functions and HAL library functions

The code output from the standard library to the serial port:

for(t=0;t<len;t++)
{
    
    
	USART_SendData(USART1, USART_RX_BUF[t]);
	//向串口1发送数据	
	while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);
	//等待发送结束
}

The code output by the HAL library to the serial port:

HAL_UART_Transmit(&UART1_Handler,(uint8_t*)USART_RX_BUF,len,1000);	
//发送接收到的数据

The Standard Peripherals
Library is a complete package of the STM32 chip, including device drivers for all standard device peripherals. The standard library is based on register operations.
The HAL library is the hardware abstraction layer, and the HAL library project generally uses Cube software to generate the project. The HAL library is the latest abstraction layer embedded software released by ST for STM32 MCUs, which makes it easier to achieve maximum portability across STM32 products. Compared with the standard peripheral library, the STM32Cube HAL library shows a higher level of abstraction and integration, and the HAL API focuses on the common function functions of each peripheral.
The advantage of the HAL library is that the amount of code is small, and it is easy to define a set of universal user-friendly API function interfaces, so that it can be easily transplanted from one STM32 product to another different STM32 series product.
Compared with the standard library, STM32's HAL library is more abstract. The ultimate goal of ST is to achieve seamless migration between STM32 series MCUs, and even rapid migration among other MCUs.

Three, stduino IDE demo

Stduino IDE is an integrated development platform for 32-bit processors to quickly start learning, official website: http://www.stduino.com/pindex.php
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_47357131/article/details/111151528