Wildfire STM32 motor series (1) Cubemx configuration GPIO

tip: The first project is the main file, and the subsequent functions are mainly to use Cubemx to generate code and then transplant it to the motor control project.

1 project establishment

You can directly browse the wildfire information, here is the configuration to match the hot sun board

1.1 Create a project as shown below

2438ecbb317a4a0b9fc389d836d5b502.png311442bebdd94cce90ecd5b4222b9a0b.png

 76efd47f32b441fa9d2145b265a6a52d.png

ff5aef940cb74eee8c424626e9025a1a.png

 1.2 GPIO port

The button (GPIO input press is high level) pin is

SW7/RESET

KEY1/SW2=PA0

KEY2/SW3=PG2

KEY3/SW3=PC13

KEY4/SW4=PG3

KEY5/SW5=PG4

29a3f44619d74aba94ecfc9d43657d13.png

The lamp (GPIO output active high) pin is

LED1=PA15

LED2=PE2

LED3=PG15

LED4=PB8

25e77fe8f00e4da085bb2cca1dbcd6e9.png

 Configure the GPIO one by one, press the button to select output, led to select input

0203dc87868849839aa7e7c65ce53a68.png

Below, the LED needs to be changed (high-level push-pull pull-up high-speed mode)

7570d10f181b4449836267bb29809321.png

 

1.3 Clock and other configurations 

0249d5587f0f4ee09510022795a1357c.png

 

241cf49671104cfe8116dcf02bd486db.png

 Configured here as a personal habitb731901ac5624645a262205c881f123c.png

 e79e5f2f17a1486986453b8f54639999.png

 Click to generate code

2 Engineering Verification

Simply configure the emulator and try to see if it can be burned into it

a6d7a0894ce64c46815a1298bbbfe914.png

 8bde6c3275b844d5bb9541647fde122d.png

3 function function added

1. Add a function to determine whether the button is pressed and turn on and off the LED light

2. The main function uses the button to light up the LED light to test the configuration and function

3. Finally tidy up the code

The specific code is as follows

//根据输入数字点亮对应LED灯
void LED_ON(unsigned char c)
{
	if(c==1)
	{
		HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_RESET);
	}
	if(c==2)
	{
		HAL_GPIO_WritePin(LED_2_GPIO_Port, LED_2_Pin, GPIO_PIN_RESET);
	}
	if(c==3)
	{
		HAL_GPIO_WritePin(LED_3_GPIO_Port, LED_3_Pin, GPIO_PIN_RESET);
	}
	if(c==4)
	{
		HAL_GPIO_WritePin(LED_4_GPIO_Port, LED_4_Pin, GPIO_PIN_RESET);
	}
}
//根据输入数字关闭对应LED灯
void LED_OFF(unsigned char c)
{
	if(c==1)
	{
		HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_SET);
	}
	if(c==2)
	{
		HAL_GPIO_WritePin(LED_2_GPIO_Port, LED_2_Pin, GPIO_PIN_SET);
	}
	if(c==3)
	{
		HAL_GPIO_WritePin(LED_3_GPIO_Port, LED_3_Pin, GPIO_PIN_SET);
	}
	if(c==4)
	{
		HAL_GPIO_WritePin(LED_4_GPIO_Port, LED_4_Pin, GPIO_PIN_SET);
	}
}
//按键检测
unsigned char Key_scan(void)
{
	unsigned char unKey_Val = 0;
	
	if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)==GPIO_PIN_SET)
			unKey_Val = 1;
	if(HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_2)==GPIO_PIN_SET)
			unKey_Val = 2;
	if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)==GPIO_PIN_SET)
			unKey_Val = 3;	
	if(HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_3)==GPIO_PIN_SET)
			unKey_Val = 4;
	
	return unKey_Val;
}

The main function test code is as follows

72f7e15477e54ea786c8700195616ebf.png

 4 Effect display

6842edbabc484edda234752348b68175.gif

 

 

Guess you like

Origin blog.csdn.net/qq_49552487/article/details/127396555