diff --git a/bootloader/targets/f5/api-hal/api-hal-i2c.c b/bootloader/targets/f5/api-hal/api-hal-i2c.c index 999a200d..d9aca753 100644 --- a/bootloader/targets/f5/api-hal/api-hal-i2c.c +++ b/bootloader/targets/f5/api-hal/api-hal-i2c.c @@ -12,7 +12,7 @@ void api_hal_i2c_init() { LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1); LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - GPIO_InitStruct.Pin = I2C_SCL_Pin | I2C_SDA_Pin; + GPIO_InitStruct.Pin = POWER_I2C_SCL_Pin | POWER_I2C_SDA_Pin; GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; @@ -23,7 +23,7 @@ void api_hal_i2c_init() { LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; - I2C_InitStruct.Timing = 0x10707DBC; + I2C_InitStruct.Timing = POWER_I2C_TIMINGS; I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; I2C_InitStruct.DigitalFilter = 0; I2C_InitStruct.OwnAddress1 = 0; diff --git a/bootloader/targets/f5/api-hal/api-hal-resources.h b/bootloader/targets/f5/api-hal/api-hal-resources.h index 78ebaa9c..8bf55562 100644 --- a/bootloader/targets/f5/api-hal/api-hal-resources.h +++ b/bootloader/targets/f5/api-hal/api-hal-resources.h @@ -7,12 +7,17 @@ extern "C" { #endif -#define I2C_SCL_Pin LL_GPIO_PIN_9 -#define I2C_SCL_GPIO_Port GPIOA -#define I2C_SDA_Pin LL_GPIO_PIN_10 -#define I2C_SDA_GPIO_Port GPIOA +#define POWER_I2C_SCL_Pin LL_GPIO_PIN_9 +#define POWER_I2C_SCL_GPIO_Port GPIOA +#define POWER_I2C_SDA_Pin LL_GPIO_PIN_10 +#define POWER_I2C_SDA_GPIO_Port GPIOA #define POWER_I2C I2C1 +/* Timing register value is computed with the STM32CubeMX Tool, + * Fast Mode @100kHz with I2CCLK = 64 MHz, + * rise time = 0ns, fall time = 0ns + */ +#define POWER_I2C_TIMINGS 0x10707DBC /* Input Keys */ typedef enum { diff --git a/firmware/targets/f4/api-hal/api-hal-i2c.c b/firmware/targets/f4/api-hal/api-hal-i2c.c index 087af97e..b56895a1 100644 --- a/firmware/targets/f4/api-hal/api-hal-i2c.c +++ b/firmware/targets/f4/api-hal/api-hal-i2c.c @@ -1,5 +1,6 @@ #include #include +#include #include osMutexId_t api_hal_i2c_mutex = NULL; @@ -7,6 +8,36 @@ osMutexId_t api_hal_i2c_mutex = NULL; void api_hal_i2c_init() { api_hal_i2c_mutex = osMutexNew(NULL); furi_check(api_hal_i2c_mutex); + + LL_I2C_InitTypeDef I2C_InitStruct = {0}; + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1); + + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + GPIO_InitStruct.Pin = POWER_I2C_SCL_Pin | POWER_I2C_SDA_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + GPIO_InitStruct.Alternate = LL_GPIO_AF_4; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); + + I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; + I2C_InitStruct.Timing = POWER_I2C_TIMINGS; + I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; + I2C_InitStruct.DigitalFilter = 0; + I2C_InitStruct.OwnAddress1 = 0; + I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; + I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; + LL_I2C_Init(I2C1, &I2C_InitStruct); + LL_I2C_EnableAutoEndMode(I2C1); + LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK); + LL_I2C_DisableOwnAddress2(I2C1); + LL_I2C_DisableGeneralCall(I2C1); + LL_I2C_EnableClockStretching(I2C1); } void api_hal_i2c_tx(I2C_TypeDef* instance, uint8_t address, const uint8_t *data, uint8_t size) { diff --git a/firmware/targets/f4/api-hal/api-hal-resources.h b/firmware/targets/f4/api-hal/api-hal-resources.h index e5081e43..d7a1493a 100644 --- a/firmware/targets/f4/api-hal/api-hal-resources.h +++ b/firmware/targets/f4/api-hal/api-hal-resources.h @@ -10,12 +10,17 @@ extern "C" { #endif -#define I2C_SCL_Pin LL_GPIO_PIN_9 -#define I2C_SCL_GPIO_Port GPIOA -#define I2C_SDA_Pin LL_GPIO_PIN_10 -#define I2C_SDA_GPIO_Port GPIOA +#define POWER_I2C_SCL_Pin LL_GPIO_PIN_9 +#define POWER_I2C_SCL_GPIO_Port GPIOA +#define POWER_I2C_SDA_Pin LL_GPIO_PIN_10 +#define POWER_I2C_SDA_GPIO_Port GPIOA #define POWER_I2C I2C1 +/* Timing register value is computed with the STM32CubeMX Tool, + * Fast Mode @100kHz with I2CCLK = 64 MHz, + * rise time = 0ns, fall time = 0ns + */ +#define POWER_I2C_TIMINGS 0x10707DBC /* Input Related Constants */ #define INPUT_DEBOUNCE_TICKS 20 diff --git a/firmware/targets/f4/target.mk b/firmware/targets/f4/target.mk index 7c8b4bb6..7c063807 100644 --- a/firmware/targets/f4/target.mk +++ b/firmware/targets/f4/target.mk @@ -53,8 +53,6 @@ C_SOURCES += \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_flash_ex.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_gpio.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_hsem.c \ - $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_i2c.c \ - $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_i2c_ex.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_ipcc.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \ @@ -74,6 +72,8 @@ C_SOURCES += \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_uart_ex.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_lptim.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_adc.c \ + $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_gpio.c \ + $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_i2c.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_usb.c \ $(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/croutine.c \ $(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \ @@ -97,6 +97,7 @@ ASM_SOURCES += $(MXPROJECT_DIR)/startup_stm32wb55xx_cm4.s # Common CFLAGS += \ + -DUSE_FULL_LL_DRIVER \ -DUSE_HAL_DRIVER \ -DHAVE_FREERTOS \ -DDEBUG_UART=huart1 diff --git a/firmware/targets/f5/api-hal/api-hal-i2c.c b/firmware/targets/f5/api-hal/api-hal-i2c.c index 087af97e..b56895a1 100644 --- a/firmware/targets/f5/api-hal/api-hal-i2c.c +++ b/firmware/targets/f5/api-hal/api-hal-i2c.c @@ -1,5 +1,6 @@ #include #include +#include #include osMutexId_t api_hal_i2c_mutex = NULL; @@ -7,6 +8,36 @@ osMutexId_t api_hal_i2c_mutex = NULL; void api_hal_i2c_init() { api_hal_i2c_mutex = osMutexNew(NULL); furi_check(api_hal_i2c_mutex); + + LL_I2C_InitTypeDef I2C_InitStruct = {0}; + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1); + + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + GPIO_InitStruct.Pin = POWER_I2C_SCL_Pin | POWER_I2C_SDA_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + GPIO_InitStruct.Alternate = LL_GPIO_AF_4; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); + + I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; + I2C_InitStruct.Timing = POWER_I2C_TIMINGS; + I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; + I2C_InitStruct.DigitalFilter = 0; + I2C_InitStruct.OwnAddress1 = 0; + I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; + I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; + LL_I2C_Init(I2C1, &I2C_InitStruct); + LL_I2C_EnableAutoEndMode(I2C1); + LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK); + LL_I2C_DisableOwnAddress2(I2C1); + LL_I2C_DisableGeneralCall(I2C1); + LL_I2C_EnableClockStretching(I2C1); } void api_hal_i2c_tx(I2C_TypeDef* instance, uint8_t address, const uint8_t *data, uint8_t size) { diff --git a/firmware/targets/f5/api-hal/api-hal-resources.h b/firmware/targets/f5/api-hal/api-hal-resources.h index e5081e43..d7a1493a 100644 --- a/firmware/targets/f5/api-hal/api-hal-resources.h +++ b/firmware/targets/f5/api-hal/api-hal-resources.h @@ -10,12 +10,17 @@ extern "C" { #endif -#define I2C_SCL_Pin LL_GPIO_PIN_9 -#define I2C_SCL_GPIO_Port GPIOA -#define I2C_SDA_Pin LL_GPIO_PIN_10 -#define I2C_SDA_GPIO_Port GPIOA +#define POWER_I2C_SCL_Pin LL_GPIO_PIN_9 +#define POWER_I2C_SCL_GPIO_Port GPIOA +#define POWER_I2C_SDA_Pin LL_GPIO_PIN_10 +#define POWER_I2C_SDA_GPIO_Port GPIOA #define POWER_I2C I2C1 +/* Timing register value is computed with the STM32CubeMX Tool, + * Fast Mode @100kHz with I2CCLK = 64 MHz, + * rise time = 0ns, fall time = 0ns + */ +#define POWER_I2C_TIMINGS 0x10707DBC /* Input Related Constants */ #define INPUT_DEBOUNCE_TICKS 20 diff --git a/firmware/targets/f5/cube/Inc/i2c.h b/firmware/targets/f5/cube/Inc/i2c.h index 48a76906..d5a09031 100644 --- a/firmware/targets/f5/cube/Inc/i2c.h +++ b/firmware/targets/f5/cube/Inc/i2c.h @@ -31,8 +31,6 @@ extern "C" { /* USER CODE END Includes */ -extern I2C_HandleTypeDef hi2c1; - /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ diff --git a/firmware/targets/f5/cube/Inc/main.h b/firmware/targets/f5/cube/Inc/main.h index eb24cd42..90c08db8 100644 --- a/firmware/targets/f5/cube/Inc/main.h +++ b/firmware/targets/f5/cube/Inc/main.h @@ -29,6 +29,18 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32wbxx_hal.h" +#include "stm32wbxx.h" +#include "stm32wbxx_ll_i2c.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" +#include "stm32wbxx_ll_gpio.h" +#include "stm32wbxx_ll_dma.h" + +#include "stm32wbxx_ll_exti.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/firmware/targets/f5/cube/Inc/stm32_assert.h b/firmware/targets/f5/cube/Inc/stm32_assert.h new file mode 100644 index 00000000..734c6558 --- /dev/null +++ b/firmware/targets/f5/cube/Inc/stm32_assert.h @@ -0,0 +1,53 @@ +/** + ****************************************************************************** + * @file stm32_assert.h + * @brief STM32 assert file. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32_ASSERT_H +#define __STM32_ASSERT_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Includes ------------------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0U) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32_ASSERT_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f5/cube/Inc/stm32wbxx_hal_conf.h b/firmware/targets/f5/cube/Inc/stm32wbxx_hal_conf.h index d6d1e73f..c58d051d 100644 --- a/firmware/targets/f5/cube/Inc/stm32wbxx_hal_conf.h +++ b/firmware/targets/f5/cube/Inc/stm32wbxx_hal_conf.h @@ -38,7 +38,7 @@ #define HAL_COMP_MODULE_ENABLED #define HAL_CRC_MODULE_ENABLED #define HAL_HSEM_MODULE_ENABLED -#define HAL_I2C_MODULE_ENABLED +/*#define HAL_I2C_MODULE_ENABLED */ /*#define HAL_IPCC_MODULE_ENABLED */ /*#define HAL_IRDA_MODULE_ENABLED */ /*#define HAL_IWDG_MODULE_ENABLED */ diff --git a/firmware/targets/f5/cube/Makefile b/firmware/targets/f5/cube/Makefile index f437f041..f3ee2eba 100644 --- a/firmware/targets/f5/cube/Makefile +++ b/firmware/targets/f5/cube/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.11.0-B13] date: [Mon Mar 01 14:14:38 MSK 2021] +# File automatically-generated by tool: [projectgenerator] version: [3.11.0-B13] date: [Wed Mar 03 12:02:50 MSK 2021] ########################################################################################################################## # ------------------------------------------------ @@ -157,7 +157,12 @@ Src/system_stm32wbxx.c \ /home/aanper/STM32Cube/Repository/STM32Cube_FW_WB_V1.10.0/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c \ /home/aanper/STM32Cube/Repository/STM32Cube_FW_WB_V1.10.0/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \ /home/aanper/STM32Cube/Repository/STM32Cube_FW_WB_V1.10.0/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \ -/home/aanper/STM32Cube/Repository/STM32Cube_FW_WB_V1.10.0/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c +/home/aanper/STM32Cube/Repository/STM32Cube_FW_WB_V1.10.0/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c \ +/Users/aku/STM32Cube/Repository/STM32Cube_FW_WB_V1.10.0/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_utils.c \ +/Users/aku/STM32Cube/Repository/STM32Cube_FW_WB_V1.10.0/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_exti.c \ +/Users/aku/STM32Cube/Repository/STM32Cube_FW_WB_V1.10.0/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_i2c.c \ +/Users/aku/STM32Cube/Repository/STM32Cube_FW_WB_V1.10.0/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_gpio.c \ +/Users/aku/STM32Cube/Repository/STM32Cube_FW_WB_V1.10.0/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_dma.c # ASM sources ASM_SOURCES = \ @@ -206,7 +211,8 @@ AS_DEFS = # C defines C_DEFS = \ -DUSE_HAL_DRIVER \ --DSTM32WB55xx +-DSTM32WB55xx \ +-DUSE_FULL_LL_DRIVER # AS includes diff --git a/firmware/targets/f5/cube/Src/i2c.c b/firmware/targets/f5/cube/Src/i2c.c index 3f2b619e..c41b35d5 100644 --- a/firmware/targets/f5/cube/Src/i2c.c +++ b/firmware/targets/f5/cube/Src/i2c.c @@ -24,95 +24,47 @@ /* USER CODE END 0 */ -I2C_HandleTypeDef hi2c1; - /* I2C1 init function */ void MX_I2C1_Init(void) { + LL_I2C_InitTypeDef I2C_InitStruct = {0}; - hi2c1.Instance = I2C1; - hi2c1.Init.Timing = 0x10707DBC; - hi2c1.Init.OwnAddress1 = 0; - hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; - hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; - hi2c1.Init.OwnAddress2 = 0; - hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK; - hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; - hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; - if (HAL_I2C_Init(&hi2c1) != HAL_OK) - { - Error_Handler(); - } - /** Configure Analogue filter + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + /**I2C1 GPIO Configuration + PA9 ------> I2C1_SCL + PA10 ------> I2C1_SDA */ - if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK) - { - Error_Handler(); - } - /** Configure Digital filter + GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; + GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; + GPIO_InitStruct.Alternate = LL_GPIO_AF_4; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* Peripheral clock enable */ + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); + + /** I2C Initialization */ - if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK) - { - Error_Handler(); - } + I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; + I2C_InitStruct.Timing = 0x10707DBC; + I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; + I2C_InitStruct.DigitalFilter = 0; + I2C_InitStruct.OwnAddress1 = 0; + I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; + I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; + LL_I2C_Init(I2C1, &I2C_InitStruct); + LL_I2C_EnableAutoEndMode(I2C1); + LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK); + LL_I2C_DisableOwnAddress2(I2C1); + LL_I2C_DisableGeneralCall(I2C1); + LL_I2C_EnableClockStretching(I2C1); } -void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(i2cHandle->Instance==I2C1) - { - /* USER CODE BEGIN I2C1_MspInit 0 */ - - /* USER CODE END I2C1_MspInit 0 */ - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**I2C1 GPIO Configuration - PA9 ------> I2C1_SCL - PA10 ------> I2C1_SDA - */ - GPIO_InitStruct.Pin = I2C_SCL_Pin|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_I2C1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* I2C1 clock enable */ - __HAL_RCC_I2C1_CLK_ENABLE(); - /* USER CODE BEGIN I2C1_MspInit 1 */ - - /* USER CODE END I2C1_MspInit 1 */ - } -} - -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(); - - /**I2C1 GPIO Configuration - PA9 ------> I2C1_SCL - PA10 ------> I2C1_SDA - */ - HAL_GPIO_DeInit(I2C_SCL_GPIO_Port, I2C_SCL_Pin); - - HAL_GPIO_DeInit(I2C_SDA_GPIO_Port, I2C_SDA_Pin); - - /* USER CODE BEGIN I2C1_MspDeInit 1 */ - - /* USER CODE END I2C1_MspDeInit 1 */ - } -} - /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ diff --git a/firmware/targets/f5/cube/f5.ioc b/firmware/targets/f5/cube/f5.ioc index 40ba686a..429d620c 100644 --- a/firmware/targets/f5/cube/f5.ioc +++ b/firmware/targets/f5/cube/f5.ioc @@ -13,6 +13,7 @@ PC12.Locked=true TIM1.IPParameters=Channel-Output Compare1 CH1N,Channel-PWM Generation3 CH3N PC12.Signal=GPIO_Output PB14.GPIO_Label=iBTN +I2C1.I2C_Rise_Time=0 PC6.GPIO_Label=DISPLAY_DI VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled RCC.RTCFreq_Value=32768 @@ -142,6 +143,7 @@ ADC1.Rank-0\#ChannelRegularConversion=1 PA15.GPIOParameters=GPIO_Label Mcu.PinsNb=69 PC11.Locked=true +I2C1.I2C_Fall_Time=0 ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,OffsetNumber-0\#ChannelRegularConversion,NbrOfConversionFlag,master,EnableAnalogWatchDog1,ContinuousConvMode PC13.Locked=true ADC1.OffsetNumber-0\#ChannelRegularConversion=ADC_OFFSET_NONE @@ -321,7 +323,7 @@ RCC.PLLSAI1RoutputFreq_Value=48000000 PC5.Locked=true PA0.GPIO_Label=IR_RX PA12.GPIOParameters=GPIO_Speed -ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true,5-MX_RTC_Init-RTC-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_SPI2_Init-SPI2-false-HAL-true,8-MX_USART1_UART_Init-USART1-false-HAL-true,9-MX_USB_Device_Init-USB_DEVICE-false-HAL-false,10-MX_TIM1_Init-TIM1-false-HAL-true,11-MX_TIM2_Init-TIM2-false-HAL-true,12-MX_TIM16_Init-TIM16-false-HAL-true,13-MX_COMP1_Init-COMP1-false-HAL-true,14-MX_RF_Init-RF-false-HAL-true,15-MX_PKA_Init-PKA-false-HAL-true,16-MX_RNG_Init-RNG-false-HAL-true,17-MX_AES1_Init-AES1-false-HAL-true,18-MX_AES2_Init-AES2-false-HAL-true,19-MX_CRC_Init-CRC-false-HAL-true,0-MX_HSEM_Init-HSEM-false-HAL-true +ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_I2C1_Init-I2C1-false-LL-true,5-MX_RTC_Init-RTC-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_SPI2_Init-SPI2-false-HAL-true,8-MX_USART1_UART_Init-USART1-false-HAL-true,9-MX_USB_Device_Init-USB_DEVICE-false-HAL-false,10-MX_TIM1_Init-TIM1-false-HAL-true,11-MX_TIM2_Init-TIM2-false-HAL-true,12-MX_TIM16_Init-TIM16-false-HAL-true,13-MX_COMP1_Init-COMP1-false-HAL-true,14-MX_RF_Init-RF-false-HAL-true,15-MX_PKA_Init-PKA-false-HAL-true,16-MX_RNG_Init-RNG-false-HAL-true,17-MX_AES1_Init-AES1-false-HAL-true,18-MX_AES2_Init-AES2-false-HAL-true,19-MX_CRC_Init-CRC-false-HAL-true,0-MX_HSEM_Init-HSEM-false-HAL-true PC0.GPIOParameters=GPIO_Label PA9.GPIOParameters=GPIO_Speed,GPIO_Label PA2.GPIO_Speed=GPIO_SPEED_FREQ_LOW @@ -349,7 +351,7 @@ Mcu.IP5=FREERTOS RCC.FCLKCortexFreq_Value=64000000 USB_DEVICE.MANUFACTURER_STRING=Flipper Mcu.IP2=AES2 -I2C1.IPParameters=Timing,CustomTiming +I2C1.IPParameters=Timing,CustomTiming,I2C_Rise_Time,I2C_Fall_Time Mcu.IP3=COMP1 PA15.GPIO_Label=SD_CD PB4.GPIOParameters=GPIO_Label diff --git a/firmware/targets/f5/target.mk b/firmware/targets/f5/target.mk index 7c8b4bb6..7c063807 100644 --- a/firmware/targets/f5/target.mk +++ b/firmware/targets/f5/target.mk @@ -53,8 +53,6 @@ C_SOURCES += \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_flash_ex.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_gpio.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_hsem.c \ - $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_i2c.c \ - $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_i2c_ex.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_ipcc.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \ @@ -74,6 +72,8 @@ C_SOURCES += \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_uart_ex.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_lptim.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_adc.c \ + $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_gpio.c \ + $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_i2c.c \ $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_usb.c \ $(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/croutine.c \ $(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \ @@ -97,6 +97,7 @@ ASM_SOURCES += $(MXPROJECT_DIR)/startup_stm32wb55xx_cm4.s # Common CFLAGS += \ + -DUSE_FULL_LL_DRIVER \ -DUSE_HAL_DRIVER \ -DHAVE_FREERTOS \ -DDEBUG_UART=huart1