From 65b8fb05d5f3e76b29ba91b4e7c72e72e9aa2333 Mon Sep 17 00:00:00 2001 From: Wanderingss <1624155937@qq.com> Date: Sat, 19 Sep 2026 20:32:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20V2=20=E5=BC=95=E8=84=9A?= =?UTF-8?q?=E8=A1=A5=E4=B8=81=EF=BC=9Av2-on-ui=20=E6=B2=BF=E7=94=A8=20v2?= =?UTF-8?q?=20=E7=A1=AC=E4=BB=B6=E5=BC=95=E8=84=9A=EF=BC=88LED2=3DPB0=20?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E8=87=B4=E6=9D=BF=E7=BA=A7=E7=94=B5=E6=BA=90?= =?UTF-8?q?/=E5=A4=8D=E4=BD=8D=E8=B7=8C=E8=90=BD=EF=BC=8C=E5=BC=80?= =?UTF-8?q?=E6=9C=BA=E6=AD=BB=E4=BA=A1=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/main.h | 12 ++++++------ STM32F407-Demo.ioc | 35 +++++++++++++++++++---------------- Src/gpio.c | 32 ++++++++++++-------------------- Src/spi.c | 8 ++++---- 4 files changed, 41 insertions(+), 46 deletions(-) diff --git a/Inc/main.h b/Inc/main.h index 56c8ff7a..efbacc90 100644 --- a/Inc/main.h +++ b/Inc/main.h @@ -59,10 +59,10 @@ void Error_Handler(void); /* Private defines -----------------------------------------------------------*/ #define CH395_INT_Pin GPIO_PIN_5 #define CH395_INT_GPIO_Port GPIOE -#define LED1_Pin GPIO_PIN_5 +#define LED1_Pin GPIO_PIN_4 #define LED1_GPIO_Port GPIOC -#define LED2_Pin GPIO_PIN_0 -#define LED2_GPIO_Port GPIOB +#define LED2_Pin GPIO_PIN_5 +#define LED2_GPIO_Port GPIOC #define LED3_Pin GPIO_PIN_1 #define LED3_GPIO_Port GPIOB #define LED4_Pin GPIO_PIN_2 @@ -89,10 +89,10 @@ void Error_Handler(void); #define CH395_SCS_GPIO_Port GPIOB #define CH395F_SCK_Pin GPIO_PIN_13 #define CH395F_SCK_GPIO_Port GPIOB -#define CH395F_SDI_Pin GPIO_PIN_14 -#define CH395F_SDI_GPIO_Port GPIOB -#define CH395F_SDO_Pin GPIO_PIN_15 +#define CH395F_SDO_Pin GPIO_PIN_14 #define CH395F_SDO_GPIO_Port GPIOB +#define CH395F_SDOB15_Pin GPIO_PIN_15 +#define CH395F_SDOB15_GPIO_Port GPIOB #define DB2_Pin GPIO_PIN_2 #define DB2_GPIO_Port GPIOG #define DB3_Pin GPIO_PIN_3 diff --git a/STM32F407-Demo.ioc b/STM32F407-Demo.ioc index a8472649..7606de09 100644 --- a/STM32F407-Demo.ioc +++ b/STM32F407-Demo.ioc @@ -120,7 +120,7 @@ Mcu.Pin26=PG8 Mcu.Pin27=PA9 Mcu.Pin28=PA10 Mcu.Pin29=PA13 -Mcu.Pin3=PC5 +Mcu.Pin3=PC4 Mcu.Pin30=PA14 Mcu.Pin31=PC10 Mcu.Pin32=PC11 @@ -131,7 +131,7 @@ Mcu.Pin36=PD2 Mcu.Pin37=PD3 Mcu.Pin38=PD4 Mcu.Pin39=PD5 -Mcu.Pin4=PB0 +Mcu.Pin4=PC5 Mcu.Pin40=PD6 Mcu.Pin41=PD7 Mcu.Pin42=PG9 @@ -160,8 +160,8 @@ Mcu.PinsNb=59 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F407ZGTx -MxCube.Version=6.18.1 -MxDb.Version=DB.6.0.181 +MxCube.Version=6.17.0 +MxDb.Version=DB.6.0.170 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false NVIC.DMA1_Stream3_IRQn=true\:7\:0\:true\:false\:true\:true\:false\:true\:true NVIC.DMA1_Stream4_IRQn=true\:7\:0\:true\:false\:true\:true\:false\:true\:true @@ -209,13 +209,10 @@ PA9.GPIO_PuPd=GPIO_NOPULL PA9.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH PA9.Mode=Asynchronous PA9.Signal=USART1_TX -PB0.GPIOParameters=PinState,GPIO_Label -PB0.GPIO_Label=LED2 -PB0.Locked=true -PB0.PinState=GPIO_PIN_SET -PB0.Signal=GPIO_Output -PB1.GPIOParameters=PinState,GPIO_Label +PB1.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label PB1.GPIO_Label=LED3 +PB1.GPIO_PuPd=GPIO_PULLUP +PB1.GPIO_Speed=GPIO_SPEED_FREQ_HIGH PB1.Locked=true PB1.PinState=GPIO_PIN_SET PB1.Signal=GPIO_Output @@ -242,7 +239,7 @@ PB13.Locked=true PB13.Mode=Full_Duplex_Master PB13.Signal=SPI2_SCK PB14.GPIOParameters=GPIO_PuPd,GPIO_Label -PB14.GPIO_Label=CH395F_SDI +PB14.GPIO_Label=CH395F_SDO PB14.GPIO_PuPd=GPIO_PULLUP PB14.Locked=true PB14.Mode=Full_Duplex_Master @@ -309,19 +306,25 @@ PC12.GPIO_Label=ST_TX4 PC12.Locked=true PC12.Mode=Asynchronous PC12.Signal=UART5_TX -PC5.GPIOParameters=PinState,GPIO_Label -PC5.GPIO_Label=LED1 +PC4.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label +PC4.GPIO_Label=LED1 +PC4.GPIO_PuPd=GPIO_PULLUP +PC4.GPIO_Speed=GPIO_SPEED_FREQ_HIGH +PC4.Locked=true +PC4.PinState=GPIO_PIN_SET +PC4.Signal=GPIO_Output +PC5.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label +PC5.GPIO_Label=LED2 +PC5.GPIO_PuPd=GPIO_PULLUP +PC5.GPIO_Speed=GPIO_SPEED_FREQ_HIGH PC5.Locked=true PC5.PinState=GPIO_PIN_SET PC5.Signal=GPIO_Output -PCC.Bar.Display=Horizontal Bar PCC.Checker=false PCC.Display=Plot\: All Steps PCC.Line=STM32F407/417 PCC.MCU=STM32F407Z(E-G)Tx PCC.PartNumber=STM32F407ZGTx -PCC.SequenceTime=1.0 ms -PCC.SequenceTime.Unit=ms PCC.Series=STM32F4 PCC.Temperature=25 PCC.Vdd=3.3 diff --git a/Src/gpio.c b/Src/gpio.c index 7bd24b0b..d62e88e1 100644 --- a/Src/gpio.c +++ b/Src/gpio.c @@ -55,11 +55,10 @@ void MX_GPIO_Init(void) __HAL_RCC_GPIOD_CLK_ENABLE(); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOC, LED1_Pin|LED2_Pin, GPIO_PIN_SET); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, LED2_Pin|LED3_Pin|LED4_Pin|CH395_SCS_Pin - |GD_WP_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOB, LED3_Pin|LED4_Pin|CH395_SCS_Pin|GD_WP_Pin, GPIO_PIN_SET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOF, LED5_Pin|LED6_Pin, GPIO_PIN_SET); @@ -82,26 +81,19 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(CH395_INT_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pin : LED1_Pin */ - GPIO_InitStruct.Pin = LED1_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(LED1_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : LED2_Pin LED3_Pin */ - GPIO_InitStruct.Pin = LED2_Pin|LED3_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pin : LED4_Pin */ - GPIO_InitStruct.Pin = LED4_Pin; + /*Configure GPIO pins : LED1_Pin LED2_Pin */ + GPIO_InitStruct.Pin = LED1_Pin|LED2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(LED4_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /*Configure GPIO pins : LED3_Pin LED4_Pin */ + GPIO_InitStruct.Pin = LED3_Pin|LED4_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /*Configure GPIO pins : LED5_Pin LED6_Pin */ GPIO_InitStruct.Pin = LED5_Pin|LED6_Pin; diff --git a/Src/spi.c b/Src/spi.c index b9b79baa..c875b811 100644 --- a/Src/spi.c +++ b/Src/spi.c @@ -179,19 +179,19 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) PB14 ------> SPI2_MISO PB15 ------> SPI2_MOSI */ - GPIO_InitStruct.Pin = CH395F_SCK_Pin|CH395F_SDO_Pin; + GPIO_InitStruct.Pin = CH395F_SCK_Pin|CH395F_SDOB15_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - GPIO_InitStruct.Pin = CH395F_SDI_Pin; + GPIO_InitStruct.Pin = CH395F_SDO_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; - HAL_GPIO_Init(CH395F_SDI_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(CH395F_SDO_GPIO_Port, &GPIO_InitStruct); /* SPI2 DMA Init */ /* SPI2_RX Init */ @@ -280,7 +280,7 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) PB14 ------> SPI2_MISO PB15 ------> SPI2_MOSI */ - HAL_GPIO_DeInit(GPIOB, CH395F_SCK_Pin|CH395F_SDI_Pin|CH395F_SDO_Pin); + HAL_GPIO_DeInit(GPIOB, CH395F_SCK_Pin|CH395F_SDO_Pin|CH395F_SDOB15_Pin); /* SPI2 DMA DeInit */ HAL_DMA_DeInit(spiHandle->hdmarx);