116 lines
3.6 KiB
C
116 lines
3.6 KiB
C
|
/* USER CODE BEGIN Header */
|
||
|
/**
|
||
|
******************************************************************************
|
||
|
* @file tim.c
|
||
|
* @brief This file provides code for the configuration
|
||
|
* of the TIM instances.
|
||
|
******************************************************************************
|
||
|
* @attention
|
||
|
*
|
||
|
* Copyright (c) 2023 STMicroelectronics.
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||
|
* in the root directory of this software component.
|
||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||
|
*
|
||
|
******************************************************************************
|
||
|
*/
|
||
|
/* USER CODE END Header */
|
||
|
/* Includes ------------------------------------------------------------------*/
|
||
|
#include "tim.h"
|
||
|
|
||
|
/* USER CODE BEGIN 0 */
|
||
|
|
||
|
/* USER CODE END 0 */
|
||
|
|
||
|
/* TIM3 init function */
|
||
|
void MX_TIM3_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN TIM3_Init 0 */
|
||
|
|
||
|
/* USER CODE END TIM3_Init 0 */
|
||
|
|
||
|
LL_TIM_InitTypeDef TIM_InitStruct = {0};
|
||
|
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
|
||
|
|
||
|
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||
|
/* Peripheral clock enable */
|
||
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
|
||
|
|
||
|
/* USER CODE BEGIN TIM3_Init 1 */
|
||
|
|
||
|
/* USER CODE END TIM3_Init 1 */
|
||
|
TIM_InitStruct.Prescaler = 0;
|
||
|
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
||
|
TIM_InitStruct.Autoreload = 65535;
|
||
|
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
|
||
|
LL_TIM_Init(TIM3, &TIM_InitStruct);
|
||
|
LL_TIM_DisableARRPreload(TIM3);
|
||
|
LL_TIM_SetClockSource(TIM3, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||
|
LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH1);
|
||
|
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
|
||
|
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
|
||
|
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
|
||
|
TIM_OC_InitStruct.CompareValue = 0;
|
||
|
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
|
||
|
LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
|
||
|
LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH1);
|
||
|
LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH2);
|
||
|
LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct);
|
||
|
LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH2);
|
||
|
LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
|
||
|
LL_TIM_DisableMasterSlaveMode(TIM3);
|
||
|
/* USER CODE BEGIN TIM3_Init 2 */
|
||
|
|
||
|
/* USER CODE END TIM3_Init 2 */
|
||
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
|
||
|
/**TIM3 GPIO Configuration
|
||
|
PB4 ------> TIM3_CH1
|
||
|
PB5 ------> TIM3_CH2
|
||
|
*/
|
||
|
GPIO_InitStruct.Pin = PWM2_Pin|PWM1_Pin;
|
||
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||
|
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||
|
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||
|
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||
|
|
||
|
LL_GPIO_AF_RemapPartial_TIM3();
|
||
|
|
||
|
}
|
||
|
/* TIM4 init function */
|
||
|
void MX_TIM4_Init(void)
|
||
|
{
|
||
|
|
||
|
/* USER CODE BEGIN TIM4_Init 0 */
|
||
|
|
||
|
/* USER CODE END TIM4_Init 0 */
|
||
|
|
||
|
LL_TIM_InitTypeDef TIM_InitStruct = {0};
|
||
|
|
||
|
/* Peripheral clock enable */
|
||
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
||
|
|
||
|
/* USER CODE BEGIN TIM4_Init 1 */
|
||
|
|
||
|
/* USER CODE END TIM4_Init 1 */
|
||
|
TIM_InitStruct.Prescaler = 0;
|
||
|
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
||
|
TIM_InitStruct.Autoreload = 65535;
|
||
|
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
|
||
|
LL_TIM_Init(TIM4, &TIM_InitStruct);
|
||
|
LL_TIM_DisableARRPreload(TIM4);
|
||
|
LL_TIM_SetClockSource(TIM4, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||
|
LL_TIM_SetTriggerOutput(TIM4, LL_TIM_TRGO_RESET);
|
||
|
LL_TIM_DisableMasterSlaveMode(TIM4);
|
||
|
/* USER CODE BEGIN TIM4_Init 2 */
|
||
|
|
||
|
/* USER CODE END TIM4_Init 2 */
|
||
|
|
||
|
}
|
||
|
|
||
|
/* USER CODE BEGIN 1 */
|
||
|
|
||
|
/* USER CODE END 1 */
|