From 0f4f89eae4ad3742d39ddb436e8dbafb419458ec Mon Sep 17 00:00:00 2001 From: xiao Date: Tue, 31 Mar 2026 16:34:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=8C=E6=AD=A5CubeMX=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Src/gpio.c | 14 ++++++++++++++ Core/Src/spi.c | 12 ++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index f897b09..4337773 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -56,6 +56,9 @@ void MX_GPIO_Init(void) /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); + /*Configure GPIO pin : PC13 */ GPIO_InitStruct.Pin = GPIO_PIN_13; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; @@ -76,6 +79,17 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /*Configure GPIO pin : PA4 */ + GPIO_InitStruct.Pin = GPIO_PIN_4; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* EXTI interrupt init*/ + HAL_NVIC_SetPriority(EXTI0_IRQn, 6, 0); + HAL_NVIC_EnableIRQ(EXTI0_IRQn); + } /* USER CODE BEGIN 2 */ diff --git a/Core/Src/spi.c b/Core/Src/spi.c index 5a72083..e3184b9 100644 --- a/Core/Src/spi.c +++ b/Core/Src/spi.c @@ -73,7 +73,7 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) __HAL_RCC_GPIOA_CLK_ENABLE(); /**SPI1 GPIO Configuration - PA4 ------> CH390 CS (GPIO Output, controlled by CH390_Interface.c) + PA4 ------> GPIO_Output PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI @@ -90,7 +90,11 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /* PA4 (CS) is configured as GPIO output in CH390_Interface.c */ + GPIO_InitStruct.Pin = GPIO_PIN_4; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* SPI1 interrupt Init */ HAL_NVIC_SetPriority(SPI1_IRQn, 5, 0); @@ -113,12 +117,12 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) __HAL_RCC_SPI1_CLK_DISABLE(); /**SPI1 GPIO Configuration - PA4 ------> CH390 CS (handled by CH390_Interface.c) + PA4 ------> GPIO_Output PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); /* SPI1 interrupt Deinit */ HAL_NVIC_DisableIRQ(SPI1_IRQn);