新手入门
- 积分
- 8
- 金钱
- 8
- 注册时间
- 2022-12-15
- 在线时间
- 1 小时
|
楼主 |
发表于 2022-12-21 16:22:21
|
显示全部楼层
- int main(void)
- {
- uint32_t system_clock_freq = 0;
- /* USER CODE BEGIN 1 */
- /* USER CODE END 1 */
- /* MCU Configuration--------------------------------------------------------*/
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
- /* USER CODE BEGIN Init */
- /* USER CODE END Init */
- /* Configure the system clock */
- SystemClock_Config();
- /* USER CODE BEGIN SysInit */
-
- /* USER CODE END SysInit */
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_USART1_UART_Init();
- MX_TIM2_Init();
- MX_TIM3_Init();
- MX_TIM4_Init();
- MX_TIM1_Init();
- MX_USART3_UART_Init();
- printf("11111111!\r\n");
- /* Initialize interrupts */
- MX_NVIC_Init();
- printf("222222222!\r\n");
- /* USER CODE BEGIN 2 */
- tuya_task_init();
- // HAL_TIM_Base_Start_IT(&htim1);
- HAL_TIM_Base_Start_IT(&htim2);
- HAL_TIM_Base_Start_IT(&htim3);
- HAL_TIM_Base_Start_IT(&htim4);
- printf("333333333!\r\n");
-
- /* USER CODE END 2 */
复制代码
- /**
- * @brief NVIC Configuration.
- * @retval None
- */
- static void MX_NVIC_Init(void)
- {
- /* FLASH_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(FLASH_IRQn, 1, 0);
- HAL_NVIC_EnableIRQ(FLASH_IRQn);
- /* RCC_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(RCC_IRQn, 1, 0);
- HAL_NVIC_EnableIRQ(RCC_IRQn);
- /* EXTI3_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(EXTI3_IRQn);
- /* EXTI4_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(EXTI4_IRQn);
- /* EXTI9_5_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
- /* EXTI15_10_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
- /* USART1_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(USART1_IRQn, 3, 0);
- HAL_NVIC_EnableIRQ(USART1_IRQn);
- /* USART3_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(USART3_IRQn, 3, 0);
- HAL_NVIC_EnableIRQ(USART3_IRQn);
- /* TIM1_UP_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(TIM1_UP_IRQn, 1, 0);
- HAL_NVIC_EnableIRQ(TIM1_UP_IRQn);
- /* TIM4_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(TIM4_IRQn, 2, 0);
- HAL_NVIC_EnableIRQ(TIM4_IRQn);
- }
复制代码
/* TIM4 init function */
void MX_TIM4_Init(void)
{
/* USER CODE BEGIN TIM4_Init 0 */
/* USER CODE END TIM4_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM4_Init 1 */
/* USER CODE END TIM4_Init 1 */
htim4.Instance = TIM4;
htim4.Init.Prescaler = 64-1;
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
htim4.Init.Period = 500-1;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
// htim4.Init.RepetitionCounter = 0;
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM4_Init 2 */
/* USER CODE END TIM4_Init 2 */
} |
|