diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-29 23:10:32 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-29 23:10:32 +0200 |
commit | 89d464c7f38b902e332f082f99df075dee080978 (patch) | |
tree | 603750026d3fa12b2db7fa19abb8cdc079c5d3be /stm32cubemx/Src | |
parent | 4c159924abc0ad027166fe8853d062ed0a46481e (diff) | |
download | radio-controller-89d464c7f38b902e332f082f99df075dee080978.tar.gz radio-controller-89d464c7f38b902e332f082f99df075dee080978.tar.bz2 radio-controller-89d464c7f38b902e332f082f99df075dee080978.tar.xz radio-controller-89d464c7f38b902e332f082f99df075dee080978.zip |
o Setting up for TIM1/Channel 1 as input capture. Enabling IWDG.
Diffstat (limited to 'stm32cubemx/Src')
-rw-r--r-- | stm32cubemx/Src/main.c | 26 | ||||
-rw-r--r-- | stm32cubemx/Src/stm32f1xx_hal_msp.c | 22 | ||||
-rw-r--r-- | stm32cubemx/Src/stm32f1xx_it.c | 15 |
3 files changed, 59 insertions, 4 deletions
diff --git a/stm32cubemx/Src/main.c b/stm32cubemx/Src/main.c index b69bf4f..e9fdb8e 100644 --- a/stm32cubemx/Src/main.c +++ b/stm32cubemx/Src/main.c @@ -42,6 +42,7 @@ IWDG_HandleTypeDef hiwdg; TIM_HandleTypeDef htim1; +DMA_HandleTypeDef hdma_tim1_ch1; /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ @@ -52,6 +53,7 @@ TIM_HandleTypeDef htim1; void SystemClock_Config(void); 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_IWDG_Init(void); static void MX_NVIC_Init(void); @@ -69,7 +71,7 @@ int main(void) { /* USER CODE BEGIN 1 */ - + main_pre_init(); /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ @@ -82,6 +84,7 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); + MX_DMA_Init(); MX_TIM1_Init(); MX_IWDG_Init(); @@ -89,7 +92,7 @@ int main(void) MX_NVIC_Init(); /* USER CODE BEGIN 2 */ - + main_post_init(); /* USER CODE END 2 */ /* Infinite loop */ @@ -99,7 +102,7 @@ int main(void) /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - + main_loop(); } /* USER CODE END 3 */ @@ -185,7 +188,7 @@ static void MX_TIM1_Init(void) TIM_IC_InitTypeDef sConfigIC; htim1.Instance = TIM1; - htim1.Init.Prescaler = 0; + htim1.Init.Prescaler = RX_TIMER_PRESCALER; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; htim1.Init.Period = 0; htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; @@ -213,6 +216,21 @@ static void MX_TIM1_Init(void) } +/** + * Enable DMA controller clock + */ +static void MX_DMA_Init(void) +{ + /* DMA controller clock enable */ + __HAL_RCC_DMA1_CLK_ENABLE(); + + /* DMA interrupt init */ + /* DMA1_Channel2_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn); + +} + /** Configure pins as * Analog * Input diff --git a/stm32cubemx/Src/stm32f1xx_hal_msp.c b/stm32cubemx/Src/stm32f1xx_hal_msp.c index 696dd5d..be02361 100644 --- a/stm32cubemx/Src/stm32f1xx_hal_msp.c +++ b/stm32cubemx/Src/stm32f1xx_hal_msp.c @@ -34,6 +34,8 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_hal.h" +extern DMA_HandleTypeDef hdma_tim1_ch1; + extern void Error_Handler(void); /* USER CODE BEGIN 0 */ @@ -96,6 +98,23 @@ void HAL_TIM_IC_MspInit(TIM_HandleTypeDef* htim_ic) GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /* Peripheral DMA init*/ + + hdma_tim1_ch1.Instance = DMA1_Channel2; + hdma_tim1_ch1.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma_tim1_ch1.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_tim1_ch1.Init.MemInc = DMA_MINC_ENABLE; + hdma_tim1_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; + hdma_tim1_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; + hdma_tim1_ch1.Init.Mode = DMA_NORMAL; + hdma_tim1_ch1.Init.Priority = DMA_PRIORITY_LOW; + if (HAL_DMA_Init(&hdma_tim1_ch1) != HAL_OK) + { + Error_Handler(); + } + + __HAL_LINKDMA(htim_ic,hdma[TIM_DMA_ID_CC1],hdma_tim1_ch1); + /* USER CODE BEGIN TIM1_MspInit 1 */ /* USER CODE END TIM1_MspInit 1 */ @@ -119,6 +138,9 @@ void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef* htim_ic) */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8); + /* Peripheral DMA DeInit*/ + HAL_DMA_DeInit(htim_ic->hdma[TIM_DMA_ID_CC1]); + /* Peripheral interrupt DeInit*/ HAL_NVIC_DisableIRQ(TIM1_TRG_COM_IRQn); diff --git a/stm32cubemx/Src/stm32f1xx_it.c b/stm32cubemx/Src/stm32f1xx_it.c index 40c5612..473a07a 100644 --- a/stm32cubemx/Src/stm32f1xx_it.c +++ b/stm32cubemx/Src/stm32f1xx_it.c @@ -40,6 +40,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern DMA_HandleTypeDef hdma_tim1_ch1; extern TIM_HandleTypeDef htim1; /******************************************************************************/ @@ -185,6 +186,20 @@ void SysTick_Handler(void) /******************************************************************************/ /** +* @brief This function handles DMA1 channel2 global interrupt. +*/ +void DMA1_Channel2_IRQHandler(void) +{ + /* USER CODE BEGIN DMA1_Channel2_IRQn 0 */ + + /* USER CODE END DMA1_Channel2_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_tim1_ch1); + /* USER CODE BEGIN DMA1_Channel2_IRQn 1 */ + + /* USER CODE END DMA1_Channel2_IRQn 1 */ +} + +/** * @brief This function handles TIM1 trigger and commutation interrupts. */ void TIM1_TRG_COM_IRQHandler(void) |