/*
 * stm32f4xx_hal_msp.c
 *
 *  Created on: 9. 2. 2017
 *      Author: Steave
 */
/**
  ******************************************************************************
  * @file    stm32f4xx_hal_msp_template.c
  * @author  MCD Application Team
  * @version V1.6.0
  * @date    04-November-2016
  * @brief   This file contains the HAL System and Peripheral (PPP) MSP initialization
  *          and de-initialization functions.
  *          It should be copied to the application folder and renamed into 'stm32f4xx_hal_msp.c'.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
#include "main.h"

/** @addtogroup STM32F4xx_HAL_Driver
  * @{
  */

/** @defgroup HAL_MSP HAL MSP
  * @brief HAL MSP module.
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/** @defgroup HAL_MSP_Private_Functions HAL MSP Private Functions
  * @{
  */

/**
  * @brief  Initializes the Global MSP.
  * @note   This function is called from HAL_Init() function to perform system
  *         level initialization (GPIOs, clock, DMA, interrupt).
  * @retval None
  */
void HAL_MspInit(void)
{

}

/**
  * @brief  DeInitializes the Global MSP.
  * @note   This functiona is called from HAL_DeInit() function to perform system
  *         level de-initialization (GPIOs, clock, DMA, interrupt).
  * @retval None
  */
void HAL_MspDeInit(void)
{

}

/**
  * @brief  Initializes the PPP MSP.
  * @note   This functiona is called from HAL_PPP_Init() function to perform
  *         peripheral(PPP) system level initialization (GPIOs, clock, DMA, interrupt)
  * @retval None
  */
void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
{
	GPIO_InitTypeDef   GPIO_InitStruct;

	__TIM2_CLK_ENABLE();
	__TIM5_CLK_ENABLE();
	__GPIOA_CLK_ENABLE();
	__GPIOB_CLK_ENABLE();

	/* Configure  (TIM2_Channel_1) in Alternate function, push-pull and 100MHz speed */
	  GPIO_InitStruct.Pin = GPIO_PIN_15;
	  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
	  GPIO_InitStruct.Pull = GPIO_PULLUP;
	  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
	  GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
	  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
	/* Configure  (TIM2_Channel_2) in Alternate function, push-pull and 100MHz speed */
	  GPIO_InitStruct.Pin = GPIO_PIN_3;
	  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
	  GPIO_InitStruct.Pull = GPIO_PULLUP;
	  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
	  GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
	  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);



	  /* Configure  (TIM5_Channel_1) in Alternate function, push-pull and 100MHz speed */
	  GPIO_InitStruct.Pin = GPIO_PIN_0;
  	  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  	  GPIO_InitStruct.Pull = GPIO_PULLUP;
  	  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  	  GPIO_InitStruct.Alternate = GPIO_AF2_TIM5;
  	  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  	  /* Configure  (TIM5_Channel_2) in Alternate function, push-pull and 100MHz speed */
  	  GPIO_InitStruct.Pin = GPIO_PIN_1;
  	  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  	  GPIO_InitStruct.Pull = GPIO_PULLUP;
  	  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  	  GPIO_InitStruct.Alternate = GPIO_AF2_TIM5;
  	  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  	 /*##-2- Configure the NVIC for TIMx ########################################*/
  	  /* Set Interrupt Group Priority */
  	  /*HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
  	  HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0);
*/

  	  /* Enable the TIMx global Interrupt */
  /*	  HAL_NVIC_EnableIRQ(TIM2_IRQn);
  	  HAL_NVIC_EnableIRQ(TIM5_IRQn);
*/
}

/**
  * @brief  DeInitializes the Encoder MSP.
  * @note   This functiona is called from HAL_PPP_DeInit() function to perform
  *         peripheral(PPP) system level de-initialization (GPIOs, clock, DMA, interrupt)
  * @retval None
  */
void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
{

}

/**
  * @brief  Initializes the UART MSP.
  * @note   This functiona is called from HAL_UART_Init() function to perform
  *         peripheral(UART) system level initialization (GPIOs, clock, DMA, interrupt)
  * @retval None
  */
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
	  GPIO_InitTypeDef  GPIO_InitStruct;


	/*##-1- Enable peripherals and GPIO Clocks #################################*/
	  /* Enable GPIO TX/RX clock */
	__HAL_RCC_GPIOC_CLK_ENABLE();
	  /* Enable USART4 clock */
	__HAL_RCC_UART4_CLK_ENABLE();

	/*##-2- Configure peripheral GPIO ##########################################*/
	  /* UART TX GPIO pin configuration  */
	  GPIO_InitStruct.Pin       = GPIO_PIN_10;
	  GPIO_InitStruct.Mode      = GPIO_MODE_AF_PP;
	  GPIO_InitStruct.Pull      = GPIO_NOPULL;
	  GPIO_InitStruct.Speed     = GPIO_SPEED_FAST;
	  GPIO_InitStruct.Alternate = GPIO_AF8_UART4;

	  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

	  /* UART RX GPIO pin configuration  */
	  GPIO_InitStruct.Pin = GPIO_PIN_11;
	  GPIO_InitStruct.Alternate = GPIO_AF8_UART4;

	  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);



	    /* NVIC configuration for USART TC interrupt */
	    HAL_NVIC_SetPriority(UART4_IRQn, 0, 1);
	    HAL_NVIC_EnableIRQ(UART4_IRQn);



}

/**
  * @brief  DeInitializes the UART MSP.
  * @note   This functiona is called from HAL_UART_DeInit() function to perform
  *         peripheral(UART) system level de-initialization (GPIOs, clock, DMA, interrupt)
  * @retval None
  */
void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
{
	/*##-1- Reset peripherals ##################################################*/
	__HAL_RCC_UART4_FORCE_RESET();
	__HAL_RCC_UART4_RELEASE_RESET();

	  /*##-2- Disable peripherals and GPIO Clocks #################################*/
	  /* Configure UART Tx as alternate function  */
	  HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10);
	  /* Configure UART Rx as alternate function  */
	  HAL_GPIO_DeInit(GPIOC, GPIO_PIN_11);

	  HAL_NVIC_DisableIRQ(UART4_IRQn);

}




/**
  * @}
  */
/*void HAL_RTC_MspInit(RTC_HandleTypeDef * hrtc)
{
	if(hrtc->Instance==RTC)
	  {


	    __HAL_RCC_RTC_ENABLE();

	  }


}*/
/**
  * @}
  */
/*void HAL_RTC_MspDeInit(RTC_HandleTypeDef * hrtc)
{

	if(hrtc->Instance==RTC)
	  {
	  	    __HAL_RCC_RTC_DISABLE();
	  }
 }
*/
/**
  * @}
  */
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
{
  /*##-1- Enable peripherals and GPIO Clocks #################################*/
  /* TIMx Peripheral clock enable */
  __HAL_RCC_TIM7_CLK_ENABLE();

  /*##-2- Configure the NVIC for TIMx ########################################*/
  /* Set Interrupt Group Priority */
  HAL_NVIC_SetPriority(TIM7_IRQn, 0, 0);

  /* Enable the TIMx global Interrupt */
  HAL_NVIC_EnableIRQ(TIM7_IRQn);
}


/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/




