当前位置:网站首页>1. Hezhou air32f103 debugging GPIO

1. Hezhou air32f103 debugging GPIO

2022-07-17 18:43:21WuZJJJ

One 、 brief introduction

Hezhou Air32F103 Development board on board Air32F103CBT6, compatible STM32F103C8T6, The price is too sweet , First episode 9.9 Free shipping . Bring their own DAPLink The firmware , Can directly be DAPLink Use .

Official details ( With information ):Air32F103 Wiki, Development board development board PinOUT chart :

  In this column, we will briefly introduce the debugging based on this development board , Alibaba cloud debugging oriented , Complete the debugging of each part , Expected updates include :GPIO、USART、LCD、KEY、DHT11、 Alibaba cloud .

All programs will be replanted with official routines , And rewrite the project , Reference the style of punctual atom to establish a project directory .

Two 、 Debug routine

Use the official routine , It can quickly verify the development environment 、 Download methods and other issues .

2.1 Download routines

stay Air32F103Gitee Download and use the official SDK routine .

AIR_Jlink_Keil The folder contains the downloaded software package ,Libraries The folder contains library files ,ModuleDemo The folder contains routines for each module .

2.2 Install package

double-click AIR_Jlink_Keil\Keil.AIR32F103_DFP.1.0.4.pack You can install the software package .

2.3 open GPIO routine

open GPIO Routine engineering :ModuleDemo\GPIO\GPIO_IOOut\USER\GPIO.uvprojx

2.4 Connect to the downloader

Because this development board comes with DAPLink The firmware , So use 2 Block development board for debugging . A development board , One when DAPLink.

The connection is as follows :

2.5 Download program

Before downloading , First the Debug The downloader model in is CMSIS-DAP Debugger.

because Air32F103 The development board has DAPLink The firmware , When downloading for the first time, you need to press and hold the reset key and then click download . official Wiki Detailed instructions :

If the download goes well , Press the reset key , On board 3 individual LED The running water light starts flashing , The download is successful , So far, the debugging of the development environment and program download wiring has been completed .

( Detailed description of the download program , In the official Wiki There is a more detailed introduction )

3、 ... and 、 Packaging Engineering

Because the official engineering example is not suitable for expansion , Use the style of punctual atom to build a new project .

3.1 encapsulation led The underlying file

Create a new one led.c and led.h. Encapsulate the following functions :

led.c

#include "led.h"

void LED_GPIO_Init(void)

{

       GPIO_InitTypeDef GPIO_InitStructure;

       RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // Can make GPIOB The clock

       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_10 | GPIO_Pin_11;

       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Speed 50MHz

       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;    // The output mode

       GPIO_Init(GPIOB, &GPIO_InitStructure); // initialization GPIOB.2,10,11        

}                                                         

void LED_Set(u8 led)

{

       if(led&0x01)LEDR_ON;else LEDR_OFF;

       if(led&0x02)LEDG_ON;else LEDG_OFF;

       if(led&0x04)LEDB_ON;else LEDB_OFF;

}

leh.h

#ifndef __LED_H__

#define __LED_H__                        

#include "air32f10x.h"

#include "sys.h"

#define LEDR PBout(11)

#define LEDG PBout(10)

#define LEDB PBout(2)

#define LEDR_ON (LEDR=1)

#define LEDG_ON (LEDG=1)

#define LEDB_ON (LEDB=1)

#define LEDR_OFF (LEDR=0)

#define LEDG_OFF (LEDG=0)

#define LEDB_OFF (LEDB=0)

#define LEDR_TOGGLE (LEDR=~LEDR)

#define LEDG_TOGGLE (LEDG=~LEDG)

#define LEDB_TOGGLE (LEDB=~LEDB)

void LED_GPIO_Init(void);

void LED_Set(u8 led);

#endif

3.2 Use

stay main In the function, you only need to do LED_GPIO After initialization of , Proceed again LED Control is enough .

main.c

#include <stdlib.h>

#include <string.h>

#include <stdio.h>

#include "delay.h"

#include "led.h"

int main(void)

{

       RCC_ClocksTypeDef clocks;

       delay_init();                       // Delay initialization

       RCC_GetClocksFreq(&clocks); // Get the system clock frequency

      

       LED_GPIO_Init();

      

       while (1)

       {

              LEDR_TOGGLE;

              delay_ms(200);// Time delay 200ms

             

              LEDG_TOGGLE;

              delay_ms(200);// Time delay 200ms

             

              LEDB_TOGGLE;

              delay_ms(200);// Time delay 200ms

       }

}

3.3 Engineering structure

  The engineering structure is similar to the engineering of punctual atoms , But not exactly , It is convenient for you to use the classification .

Here we are , compile , Download project , Just like the official routine , notice LED Just flash .

原网站

版权声明
本文为[WuZJJJ]所创,转载请带上原文链接,感谢
https://chowdera.com/2022/198/202207150601183101.html

随机推荐