From c698df5c6905bd57e492f89c626374da5b51f7aa Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Mon, 31 Jul 2023 18:10:42 +0800 Subject: [PATCH] revised I2C2 and SPI1 Pin and port --- Core/Inc/i2c.h | 11 +------ Core/Inc/spi.h | 21 +------------ Core/Src/i2c.c | 81 ++------------------------------------------------ 3 files changed, 5 insertions(+), 108 deletions(-) diff --git a/Core/Inc/i2c.h b/Core/Inc/i2c.h index 80cc42d..9ecc639 100644 --- a/Core/Inc/i2c.h +++ b/Core/Inc/i2c.h @@ -38,14 +38,6 @@ PB6 ------> I2C1_SCL PB7 ------> I2C1_SDA */ -#if defined(STM32WL55xx) -#define MEMS_I2C_HANDLE hi2c1 -#define MEMS_I2C_SCL_Pin GPIO_PIN_6 -#define MEMS_I2C_SCL_GPIO_Port GPIOB -#define MEMS_I2C_SDA_Pin GPIO_PIN_7 -#define MEMS_I2C_SDA_GPIO_Port GPIOB -#endif - #if defined(STM32WL55xx) #define MEMS_ENABLE_Pin GPIO_PIN_5 #define MEMS_ENABLE_GPIO_Port GPIOB @@ -58,11 +50,10 @@ PB7 ------> I2C1_SDA PA12 ------> I2C2_SCL PA11 ------> I2C2_SDA */ -#if defined(STM32WLE5xx) +#if defined(STM32WLE5xx)|| defined(STM32WL55xx) #define MEMS_I2C_HANDLE hi2c2 #define MEMS_I2C_SCL_Pin GPIO_PIN_12 #define MEMS_I2C_SCL_GPIO_Port GPIOA - #define MEMS_I2C_SDA_Pin GPIO_PIN_11 #define MEMS_I2C_SDA_GPIO_Port GPIOA diff --git a/Core/Inc/spi.h b/Core/Inc/spi.h index eb0f94a..539df92 100644 --- a/Core/Inc/spi.h +++ b/Core/Inc/spi.h @@ -29,23 +29,8 @@ extern "C" { #include "main.h" /* USER CODE BEGIN Includes */ -#if defined(STM32WL55xx) -#define MEMS_SPI_MOSI_Pin GPIO_PIN_12 -#define MEMS_SPI_MOSI_GPIO_Port GPIOA -#define MEMS_CS_N_Pin GPIO_PIN_15 -#define MEMS_CS_N_GPIO_Port GPIOA -#define MEMS_SPI_MISO_Pin GPIO_PIN_11 -#define MEMS_SPI_MISO_GPIO_Port GPIOA -#define MEMS_SPI_SCK_Pin GPIO_PIN_3 -#define MEMS_SPI_SCK_GPIO_Port GPIOB -#define MEMS_ENABLE_Pin GPIO_PIN_5 -#define MEMS_ENABLE_GPIO_Port GPIOB -#define MEMS_SENSOR_INTERRUPT_Pin GPIO_PIN_8 -#define MEMS_SENSOR_INTERRUPT_GPIO_Port GPIOA -#define MEMS_SENSOR_INTERRUPT_EXTI_IRQn EXTI9_5_IRQn -#endif -#if defined(STM32WLE5xx) +#if defined(STM32WLE5xx)||defined(STM32WL55xx) #define MEMS_SPI_SCK_Pin GPIO_PIN_5 //GPIO_PIN_3 #define MEMS_SPI_SCK_GPIO_Port GPIOA //GPIOB #define MEMS_SPI_MISO_Pin GPIO_PIN_6 //GPIO_PIN_11 @@ -61,10 +46,6 @@ extern "C" { #define MEMS_ENABLE_GPIO_Port GPIOB #endif -#define A111_SPI_HANDLE hspi1 -#ifndef A111_USE_SPI_DMA -#define A111_USE_SPI_DMA -#endif /* USER CODE END Includes */ diff --git a/Core/Src/i2c.c b/Core/Src/i2c.c index 2fbe467..b4de628 100644 --- a/Core/Src/i2c.c +++ b/Core/Src/i2c.c @@ -24,38 +24,8 @@ /* USER CODE END 0 */ -I2C_HandleTypeDef hi2c1, hi2c2; +I2C_HandleTypeDef hi2c2; -/* I2C1 init function */ -void MX_I2C1_Init(void) -{ - - hi2c1.Instance = I2C1; - hi2c1.Init.Timing = 0x2010091A; //0x2010091A = 400K Fast Mode, 0x20303E5D, 100K Standard mode, 0x20000209 Fast Mode Plus, 1Mbps - hi2c1.Init.OwnAddress1 = 0; - hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; - hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; - hi2c1.Init.OwnAddress2 = 0; - hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; - hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; - if (HAL_I2C_Init(&hi2c1) != HAL_OK) - { - Error_Handler(); - } - /** Configure Analogue filter - */ - if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK) - { - Error_Handler(); - } - /** Configure Digital filter - */ - if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK) - { - Error_Handler(); - } - -} /* I2C2 init function */ void MX_I2C2_Init(void) @@ -93,30 +63,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(i2cHandle->Instance==I2C1) - { - /* USER CODE BEGIN I2C2_MspInit 0 */ - - /* USER CODE END I2C2_MspInit 0 */ - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**I2C1 GPIO Configuration - PB6 ------> I2C1_SCL - PB7 ------> I2C1_SDA - */ - GPIO_InitStruct.Pin = MEMS_I2C_SCL_Pin|MEMS_I2C_SDA_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF4_I2C2; - HAL_GPIO_Init(MEMS_I2C_SDA_GPIO_Port, &GPIO_InitStruct); - - /* I2C1 clock enable */ - __HAL_RCC_I2C1_CLK_ENABLE(); - /* USER CODE BEGIN I2C1_MspInit 1 */ - - /* USER CODE END I2C1_MspInit 1 */ - } else if(i2cHandle->Instance==I2C2) + if(i2cHandle->Instance==I2C2) { /* USER CODE BEGIN I2C2_MspInit 0 */ @@ -145,29 +92,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle) { - if(i2cHandle->Instance==I2C1) - { - /* USER CODE BEGIN I2C1_MspDeInit 0 */ - - /* USER CODE END I2C1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_I2C1_CLK_DISABLE(); - - /**I2C2 GPIO Configuration - PB6 ------> I2C1_SCL - PB7 ------> I2C1_SDA - */ - HAL_GPIO_DeInit(MEMS_I2C_SCL_GPIO_Port, MEMS_I2C_SCL_Pin); - - HAL_GPIO_DeInit(MEMS_I2C_SDA_GPIO_Port, MEMS_I2C_SDA_Pin); - - /* USER CODE BEGIN I2C2_MspDeInit 1 */ - /* I2C1 DMA DeInit */ - HAL_DMA_DeInit(i2cHandle->hdmarx); - HAL_DMA_DeInit(i2cHandle->hdmatx); - - /* USER CODE END I2C2_MspDeInit 1 */ - } else if(i2cHandle->Instance==I2C2) + if(i2cHandle->Instance==I2C2) { /* USER CODE BEGIN I2C2_MspDeInit 0 */