diff options
Diffstat (limited to 'stm32cubemx/Src')
-rw-r--r-- | stm32cubemx/Src/main.c | 38 | ||||
-rw-r--r-- | stm32cubemx/Src/stm32f1xx_hal_msp.c | 64 | ||||
-rw-r--r-- | stm32cubemx/Src/stm32f1xx_it.c | 14 |
3 files changed, 102 insertions, 14 deletions
diff --git a/stm32cubemx/Src/main.c b/stm32cubemx/Src/main.c index 7c5f9d3..f57b555 100644 --- a/stm32cubemx/Src/main.c +++ b/stm32cubemx/Src/main.c @@ -53,6 +53,8 @@ TIM_HandleTypeDef htim1; DMA_HandleTypeDef hdma_tim1_ch1; +UART_HandleTypeDef huart2; + /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ @@ -64,7 +66,7 @@ void Error_Handler(void); static void MX_GPIO_Init(void); static void MX_DMA_Init(void); static void MX_TIM1_Init(void); -static void MX_NVIC_Init(void); +static void MX_USART2_UART_Init(void); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ @@ -95,9 +97,7 @@ int main(void) MX_DMA_Init(); MX_TIM1_Init(); MX_USB_DEVICE_Init(); - - /* Initialize interrupts */ - MX_NVIC_Init(); + MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ main_post_init(); @@ -172,15 +172,6 @@ void SystemClock_Config(void) HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); } -/** NVIC Configuration -*/ -static void MX_NVIC_Init(void) -{ - /* TIM1_TRG_COM_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(TIM1_TRG_COM_IRQn, 1, 0); - HAL_NVIC_EnableIRQ(TIM1_TRG_COM_IRQn); -} - /* TIM1 init function */ static void MX_TIM1_Init(void) { @@ -191,7 +182,7 @@ static void MX_TIM1_Init(void) htim1.Instance = TIM1; htim1.Init.Prescaler = RX_TIMER_PRESCALER; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; - htim1.Init.Period = 0; + htim1.Init.Period = 65535; htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim1.Init.RepetitionCounter = 0; if (HAL_TIM_IC_Init(&htim1) != HAL_OK) @@ -217,6 +208,25 @@ static void MX_TIM1_Init(void) } +/* USART2 init function */ +static void MX_USART2_UART_Init(void) +{ + + huart2.Instance = USART2; + huart2.Init.BaudRate = 115200; + huart2.Init.WordLength = UART_WORDLENGTH_8B; + huart2.Init.StopBits = UART_STOPBITS_1; + huart2.Init.Parity = UART_PARITY_NONE; + huart2.Init.Mode = UART_MODE_TX_RX; + huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart2.Init.OverSampling = UART_OVERSAMPLING_16; + if (HAL_UART_Init(&huart2) != HAL_OK) + { + Error_Handler(); + } + +} + /** * Enable DMA controller clock */ diff --git a/stm32cubemx/Src/stm32f1xx_hal_msp.c b/stm32cubemx/Src/stm32f1xx_hal_msp.c index eefddb9..b90d153 100644 --- a/stm32cubemx/Src/stm32f1xx_hal_msp.c +++ b/stm32cubemx/Src/stm32f1xx_hal_msp.c @@ -125,6 +125,11 @@ void HAL_TIM_IC_MspInit(TIM_HandleTypeDef* htim_ic) __HAL_LINKDMA(htim_ic,hdma[TIM_DMA_ID_CC1],hdma_tim1_ch1); + /* Peripheral interrupt init */ + HAL_NVIC_SetPriority(TIM1_TRG_COM_IRQn, 1, 0); + HAL_NVIC_EnableIRQ(TIM1_TRG_COM_IRQn); + HAL_NVIC_SetPriority(TIM1_CC_IRQn, 1, 0); + HAL_NVIC_EnableIRQ(TIM1_CC_IRQn); /* USER CODE BEGIN TIM1_MspInit 1 */ /* USER CODE END TIM1_MspInit 1 */ @@ -154,6 +159,8 @@ void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef* htim_ic) /* Peripheral interrupt DeInit*/ HAL_NVIC_DisableIRQ(TIM1_TRG_COM_IRQn); + HAL_NVIC_DisableIRQ(TIM1_CC_IRQn); + } /* USER CODE BEGIN TIM1_MspDeInit 1 */ @@ -161,6 +168,63 @@ void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef* htim_ic) } +void HAL_UART_MspInit(UART_HandleTypeDef* huart) +{ + + GPIO_InitTypeDef GPIO_InitStruct; + if(huart->Instance==USART2) + { + /* USER CODE BEGIN USART2_MspInit 0 */ + + /* USER CODE END USART2_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_USART2_CLK_ENABLE(); + + /**USART2 GPIO Configuration + PA2 ------> USART2_TX + PA3 ------> USART2_RX + */ + GPIO_InitStruct.Pin = GPIO_PIN_2; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = GPIO_PIN_3; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN USART2_MspInit 1 */ + + /* USER CODE END USART2_MspInit 1 */ + } + +} + +void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) +{ + + if(huart->Instance==USART2) + { + /* USER CODE BEGIN USART2_MspDeInit 0 */ + + /* USER CODE END USART2_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART2_CLK_DISABLE(); + + /**USART2 GPIO Configuration + PA2 ------> USART2_TX + PA3 ------> USART2_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); + + } + /* USER CODE BEGIN USART2_MspDeInit 1 */ + + /* USER CODE END USART2_MspDeInit 1 */ + +} + /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ diff --git a/stm32cubemx/Src/stm32f1xx_it.c b/stm32cubemx/Src/stm32f1xx_it.c index 83f5436..ac5d604 100644 --- a/stm32cubemx/Src/stm32f1xx_it.c +++ b/stm32cubemx/Src/stm32f1xx_it.c @@ -242,6 +242,20 @@ void TIM1_TRG_COM_IRQHandler(void) /* USER CODE END TIM1_TRG_COM_IRQn 1 */ } +/** +* @brief This function handles TIM1 capture compare interrupt. +*/ +void TIM1_CC_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_CC_IRQn 0 */ + it_tim1(); + /* USER CODE END TIM1_CC_IRQn 0 */ + HAL_TIM_IRQHandler(&htim1); + /* USER CODE BEGIN TIM1_CC_IRQn 1 */ + + /* USER CODE END TIM1_CC_IRQn 1 */ +} + /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ |