[FL-933] API HAL I2C: initialize bus on start (#360)
* API HAL I2C: initialize bus on start * API HAL I2C: move timing register to resources, explain its value. Update cube project.
This commit is contained in:
		| @@ -31,8 +31,6 @@ extern "C" { | ||||
|  | ||||
| /* USER CODE END Includes */ | ||||
|  | ||||
| extern I2C_HandleTypeDef hi2c1; | ||||
|  | ||||
| /* USER CODE BEGIN Private defines */ | ||||
|  | ||||
| /* USER CODE END Private defines */ | ||||
|   | ||||
| @@ -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 */ | ||||
|   | ||||
							
								
								
									
										53
									
								
								firmware/targets/f5/cube/Inc/stm32_assert.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								firmware/targets/f5/cube/Inc/stm32_assert.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    stm32_assert.h | ||||
|   * @brief   STM32 assert file. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2019 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * 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****/ | ||||
| @@ -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   */ | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 */ | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user