summaryrefslogtreecommitdiff
path: root/bsp/radio-controller-1/Src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-06-03 20:47:37 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-06-03 20:47:37 +0200
commit0bc2a81c0aab3c89b534415d6f07d07e392260ce (patch)
tree5995a09ea9212df38490b330fc878060b6bb9294 /bsp/radio-controller-1/Src
parentdcfb42c972f904482514ef194003018a02c8c260 (diff)
downloadradio-controller-0bc2a81c0aab3c89b534415d6f07d07e392260ce.tar.gz
radio-controller-0bc2a81c0aab3c89b534415d6f07d07e392260ce.tar.bz2
radio-controller-0bc2a81c0aab3c89b534415d6f07d07e392260ce.tar.xz
radio-controller-0bc2a81c0aab3c89b534415d6f07d07e392260ce.zip
o Adding support for reading IR codes.
Diffstat (limited to 'bsp/radio-controller-1/Src')
-rw-r--r--bsp/radio-controller-1/Src/main.c73
-rw-r--r--bsp/radio-controller-1/Src/stm32f1xx_hal_msp.c51
-rw-r--r--bsp/radio-controller-1/Src/stm32f1xx_it.c15
-rw-r--r--bsp/radio-controller-1/Src/usbd_conf.c4
4 files changed, 136 insertions, 7 deletions
diff --git a/bsp/radio-controller-1/Src/main.c b/bsp/radio-controller-1/Src/main.c
index d7e4c04..dbcf975 100644
--- a/bsp/radio-controller-1/Src/main.c
+++ b/bsp/radio-controller-1/Src/main.c
@@ -54,6 +54,7 @@
IWDG_HandleTypeDef hiwdg;
TIM_HandleTypeDef htim1;
+TIM_HandleTypeDef htim2;
UART_HandleTypeDef huart2;
@@ -68,6 +69,7 @@ void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_IWDG_Init(void);
static void MX_TIM1_Init(void);
+static void MX_TIM2_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
@@ -98,6 +100,7 @@ int main(void)
MX_GPIO_Init();
MX_IWDG_Init();
MX_TIM1_Init();
+ MX_TIM2_Init();
MX_USART2_UART_Init();
MX_USB_DEVICE_Init();
@@ -172,7 +175,7 @@ void SystemClock_Config(void)
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
+ HAL_NVIC_SetPriority(SysTick_IRQn, 1, 0);
}
/* IWDG init function */
@@ -240,6 +243,63 @@ static void MX_TIM1_Init(void)
}
+/* TIM2 init function */
+static void MX_TIM2_Init(void)
+{
+
+ TIM_SlaveConfigTypeDef sSlaveConfig;
+ TIM_MasterConfigTypeDef sMasterConfig;
+ TIM_IC_InitTypeDef sConfigIC;
+
+ htim2.Instance = TIM2;
+ htim2.Init.Prescaler = RADIO_RX_TIMER_PRESCALER;
+ htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
+ htim2.Init.Period = 0xffff;
+ htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+ if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ if (HAL_TIM_IC_Init(&htim2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;
+ sSlaveConfig.InputTrigger = TIM_TS_TI1FP1;
+ sSlaveConfig.TriggerPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
+ sSlaveConfig.TriggerFilter = 0;
+ if (HAL_TIM_SlaveConfigSynchronization(&htim2, &sSlaveConfig) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
+ sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
+ if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
+ sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
+ sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
+ sConfigIC.ICFilter = 0;
+ if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
+ sConfigIC.ICSelection = TIM_ICSELECTION_INDIRECTTI;
+ if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+}
+
/* USART2 init function */
static void MX_USART2_UART_Init(void)
{
@@ -269,11 +329,22 @@ static void MX_USART2_UART_Init(void)
static void MX_GPIO_Init(void)
{
+ GPIO_InitTypeDef GPIO_InitStruct;
+
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(DEBUG_PIN_GPIO_Port, DEBUG_PIN_Pin, GPIO_PIN_RESET);
+
+ /*Configure GPIO pin : DEBUG_PIN_Pin */
+ GPIO_InitStruct.Pin = DEBUG_PIN_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(DEBUG_PIN_GPIO_Port, &GPIO_InitStruct);
+
}
/* USER CODE BEGIN 4 */
diff --git a/bsp/radio-controller-1/Src/stm32f1xx_hal_msp.c b/bsp/radio-controller-1/Src/stm32f1xx_hal_msp.c
index 5ee7f9a..49e9623 100644
--- a/bsp/radio-controller-1/Src/stm32f1xx_hal_msp.c
+++ b/bsp/radio-controller-1/Src/stm32f1xx_hal_msp.c
@@ -75,7 +75,7 @@ void HAL_MspInit(void)
/* PendSV_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0);
/* SysTick_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
+ HAL_NVIC_SetPriority(SysTick_IRQn, 1, 0);
/**NOJTAG: JTAG-DP Disabled and SW-DP Enabled
*/
@@ -107,14 +107,37 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
HAL_GPIO_Init(RADIO_RX_GPIO_Port, &GPIO_InitStruct);
/* Peripheral interrupt init */
- HAL_NVIC_SetPriority(TIM1_TRG_COM_IRQn, 1, 0);
+ HAL_NVIC_SetPriority(TIM1_TRG_COM_IRQn, 10, 0);
HAL_NVIC_EnableIRQ(TIM1_TRG_COM_IRQn);
- HAL_NVIC_SetPriority(TIM1_CC_IRQn, 1, 0);
+ HAL_NVIC_SetPriority(TIM1_CC_IRQn, 10, 0);
HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);
/* USER CODE BEGIN TIM1_MspInit 1 */
/* USER CODE END TIM1_MspInit 1 */
}
+ else if(htim_base->Instance==TIM2)
+ {
+ /* USER CODE BEGIN TIM2_MspInit 0 */
+
+ /* USER CODE END TIM2_MspInit 0 */
+ /* Peripheral clock enable */
+ __HAL_RCC_TIM2_CLK_ENABLE();
+
+ /**TIM2 GPIO Configuration
+ PA0-WKUP ------> TIM2_CH1
+ */
+ GPIO_InitStruct.Pin = IR_RX_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(IR_RX_GPIO_Port, &GPIO_InitStruct);
+
+ /* Peripheral interrupt init */
+ HAL_NVIC_SetPriority(TIM2_IRQn, 10, 0);
+ HAL_NVIC_EnableIRQ(TIM2_IRQn);
+ /* USER CODE BEGIN TIM2_MspInit 1 */
+
+ /* USER CODE END TIM2_MspInit 1 */
+ }
}
@@ -139,10 +162,30 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
HAL_NVIC_DisableIRQ(TIM1_CC_IRQn);
- }
/* USER CODE BEGIN TIM1_MspDeInit 1 */
/* USER CODE END TIM1_MspDeInit 1 */
+ }
+ else if(htim_base->Instance==TIM2)
+ {
+ /* USER CODE BEGIN TIM2_MspDeInit 0 */
+
+ /* USER CODE END TIM2_MspDeInit 0 */
+ /* Peripheral clock disable */
+ __HAL_RCC_TIM2_CLK_DISABLE();
+
+ /**TIM2 GPIO Configuration
+ PA0-WKUP ------> TIM2_CH1
+ */
+ HAL_GPIO_DeInit(IR_RX_GPIO_Port, IR_RX_Pin);
+
+ /* Peripheral interrupt DeInit*/
+ HAL_NVIC_DisableIRQ(TIM2_IRQn);
+
+ /* USER CODE BEGIN TIM2_MspDeInit 1 */
+
+ /* USER CODE END TIM2_MspDeInit 1 */
+ }
}
diff --git a/bsp/radio-controller-1/Src/stm32f1xx_it.c b/bsp/radio-controller-1/Src/stm32f1xx_it.c
index 67cbc69..2edc0a7 100644
--- a/bsp/radio-controller-1/Src/stm32f1xx_it.c
+++ b/bsp/radio-controller-1/Src/stm32f1xx_it.c
@@ -42,6 +42,7 @@
/* External variables --------------------------------------------------------*/
extern PCD_HandleTypeDef hpcd_USB_FS;
extern TIM_HandleTypeDef htim1;
+extern TIM_HandleTypeDef htim2;
/******************************************************************************/
/* Cortex-M3 Processor Interruption and Exception Handlers */
@@ -241,6 +242,20 @@ void TIM1_CC_IRQHandler(void)
/* USER CODE END TIM1_CC_IRQn 1 */
}
+/**
+* @brief This function handles TIM2 global interrupt.
+*/
+void TIM2_IRQHandler(void)
+{
+ /* USER CODE BEGIN TIM2_IRQn 0 */
+
+ /* USER CODE END TIM2_IRQn 0 */
+ HAL_TIM_IRQHandler(&htim2);
+ /* USER CODE BEGIN TIM2_IRQn 1 */
+
+ /* USER CODE END TIM2_IRQn 1 */
+}
+
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
diff --git a/bsp/radio-controller-1/Src/usbd_conf.c b/bsp/radio-controller-1/Src/usbd_conf.c
index 858fb0c..ea64758 100644
--- a/bsp/radio-controller-1/Src/usbd_conf.c
+++ b/bsp/radio-controller-1/Src/usbd_conf.c
@@ -79,9 +79,9 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
__HAL_RCC_USB_CLK_ENABLE();
/* Peripheral interrupt init */
- HAL_NVIC_SetPriority(USB_HP_CAN1_TX_IRQn, 0, 0);
+ HAL_NVIC_SetPriority(USB_HP_CAN1_TX_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(USB_HP_CAN1_TX_IRQn);
- HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 0, 0);
+ HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
/* USER CODE BEGIN USB_MspInit 1 */