| | |
| | | * @retval None |
| | | */ |
| | | |
| | | void SystemClock_Config(void) |
| | | void SystemClock_Config_New(void) |
| | | { |
| | | LL_FLASH_SetLatency(LL_FLASH_LATENCY_1); |
| | | |
| | | if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_1) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | LL_RCC_HSE_Enable(); |
| | | |
| | | /* Wait till HSE is ready */ |
| | | while(LL_RCC_HSE_IsReady() != 1) |
| | | { |
| | | |
| | | } |
| | | LL_RCC_LSI_Enable(); |
| | | |
| | | /* Wait till LSI is ready */ |
| | | while(LL_RCC_LSI_IsReady() != 1) |
| | | { |
| | | |
| | | } |
| | | #if (XLAT_FREQ == 12) |
| | | LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_3, LL_RCC_PLL_MUL_12); |
| | | #else |
| | | LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_2, LL_RCC_PLL_MUL_12); |
| | | #endif |
| | | LL_RCC_PLL_Enable(); |
| | | |
| | | /* Wait till PLL is ready */ |
| | | while(LL_RCC_PLL_IsReady() != 1) |
| | | { |
| | | |
| | | } |
| | | LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); |
| | | LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); |
| | | LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); |
| | | |
| | | /* Wait till System clock is ready */ |
| | | while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) |
| | | { |
| | | |
| | | } |
| | | |
| | | LL_InitTick(48000000,10000); |
| | | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
| | | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
| | | |
| | | SysTick->CTRL = SysTick_CTRL_ENABLE_Msk |
| | | | SysTick_CTRL_TICKINT_Msk; |
| | | |
| | | LL_SetSystemCoreClock(48000000); |
| | | LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK1); |
| | | |
| | | } |
| | | |
| | | |
| | | void SystemClock_Config(void) |
| | | { |
| | | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
| | | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
| | | |
| | |
| | | // GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | // LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_15; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**SPI1 GPIO Configuration |
| | | PB3 ------> SPI1_SCK |
| | | PB4 ------> SPI1_MISO |
| | | PB5 ------> SPI1_MOSI |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3; |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | /* |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_4; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | */ |
| | | /* SPI1 interrupt Init */ |
| | | NVIC_SetPriority(SPI1_IRQn, 0); |
| | | // NVIC_EnableIRQ(SPI1_IRQn); |
| | |
| | | /* USER CODE END SPI2_Init 2 */ |
| | | } |
| | | |
| | | void Soft_I2C1_Init(void) |
| | | { |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**I2C1 GPIO Configuration |
| | | PB6 ------> I2C1_SCL |
| | | PB7 ------> I2C1_SDA |
| | | */ |
| | | LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_6|LL_GPIO_PIN_7); |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_6 | LL_GPIO_PIN_7; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_6 | LL_GPIO_PIN_7); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @brief I2C1 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_I2C1_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN I2C1_Init 0 */ |
| | | |
| | | /* USER CODE END I2C1_Init 0 */ |
| | | |
| | | LL_I2C_InitTypeDef I2C_InitStruct = {0}; |
| | | |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**I2C1 GPIO Configuration |
| | | PB8 ------> I2C1_SCL |
| | | PB9 ------> I2C1_SDA |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_8; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_9; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); |
| | | |
| | | /* USER CODE BEGIN I2C1_Init 1 */ |
| | | |
| | | /* USER CODE END I2C1_Init 1 */ |
| | | /** I2C Initialization |
| | | */ |
| | | LL_I2C_DisableOwnAddress2(I2C1); |
| | | LL_I2C_DisableGeneralCall(I2C1); |
| | | LL_I2C_EnableClockStretching(I2C1); |
| | | I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; |
| | | I2C_InitStruct.Timing = 0x20303E5D; |
| | | 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); |
| | | /* USER CODE BEGIN I2C1_Init 2 */ |
| | | |
| | | /* USER CODE END I2C1_Init 2 */ |
| | | |
| | | } |
| | | |
| | | /* USART1 init function */ |
| | | void MX_USART1_UART_Init(void) |
| | |
| | | // LL_USART_SetDEAssertionTime(USART1, 1); |
| | | // LL_USART_SetDEDeassertionTime(USART1, 1); |
| | | // LL_USART_EnableOneBitSamp(USART1); |
| | | |
| | | #if (USART1_AUTO_BAUDRATE == 1) |
| | | LL_USART_EnableAutoBaudRate(USART1); |
| | | LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
| | | LL_USART_DisableOverrunDetect(USART1); |
| | | #endif |
| | | |
| | | LL_USART_DisableOverrunDetect(USART1); |
| | | LL_USART_ConfigAsyncMode(USART1); |
| | | LL_USART_Enable(USART1); |
| | | } |
| | |
| | | LL_USART_EnableDEMode(USART2); |
| | | LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_LOW); |
| | | // LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_HIGH); |
| | | LL_USART_SetDEAssertionTime(USART2, 31); |
| | | LL_USART_SetDEDeassertionTime(USART2, 31); |
| | | LL_USART_SetDEAssertionTime(USART2, 15); |
| | | LL_USART_SetDEDeassertionTime(USART2, 15); |
| | | #else |
| | | |
| | | #endif |
| | |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | if (GetBoardType()==2) |
| | | { |
| | | #if (BOARD_TYPE==2) |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
| | | |
| | | } |
| | | else if (GetBoardType()==9 || GetBoardType()==10 || GetBoardType()==15 || BOARD_TYPE == 16 ) |
| | | { |
| | | |
| | | #elif (BOARD_TYPE==9 || BOARD_TYPE==10) |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| |
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
| | | |
| | | #elif (BOARD_TYPE==15 || BOARD_TYPE == 16 ) |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
| | | LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| |
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
| | | } |
| | | else if ( GetBoardType() == 11 ) |
| | | { |
| | | #elif ( BOARD_TYPE == 11 ) |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
| | | LL_GPIO_PIN_2|LL_GPIO_PIN_10|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
| | | } else if (BOARD_TYPE == 14) |
| | | { |
| | | #elif (BOARD_TYPE == 14) |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
| | | LL_GPIO_PIN_10|LL_GPIO_PIN_11|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_14|LL_GPIO_PIN_15; |
| | | } else |
| | | { |
| | | #else |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
| | | LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| |
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
| | | } |
| | | |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
| | | |
| | | #endif |
| | | |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |