/trunk/ZHONX_III/ZHONX_III/Src/stm32f4xx_hal_msp.c
C | 503 lines | 249 code | 91 blank | 163 comment | 28 complexity | 6c0c4698a6e7cfe869117d8fb8f045c2 MD5 | raw file
- /**
- ******************************************************************************
- * File Name : stm32f4xx_hal_msp.c
- * Date : 19/10/2014 22:24:43
- * Description : This file provides code for the MSP Initialization
- * and de-Initialization codes.
- ******************************************************************************
- *
- * COPYRIGHT(c) 2014 STMicroelectronics
- *
- * 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"
-
- extern DMA_HandleTypeDef hdma_adc1;
-
- extern DMA_HandleTypeDef hdma_i2c1_tx;
-
- extern DMA_HandleTypeDef hdma_i2c1_rx;
-
- /* USER CODE BEGIN 0 */
-
- /* USER CODE END 0 */
-
- void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
- {
-
- GPIO_InitTypeDef GPIO_InitStruct;
- if(hadc->Instance==ADC1)
- {
- /* Peripheral clock enable */
- __ADC1_CLK_ENABLE();
-
- /**ADC1 GPIO Configuration
- PC0 ------> ADC1_IN10
- PC1 ------> ADC1_IN11
- PC2 ------> ADC1_IN12
- PC3 ------> ADC1_IN13
- PA1 ------> ADC1_IN1
- PA3 ------> ADC1_IN3
- PA4 ------> ADC1_IN4
- PA5 ------> ADC1_IN5
- PA6 ------> ADC1_IN6
- PA7 ------> ADC1_IN7
- PC4 ------> ADC1_IN14
- PC5 ------> ADC1_IN15
- */
- GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
- |GPIO_PIN_4|GPIO_PIN_5;
- GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
- |GPIO_PIN_6|GPIO_PIN_7;
- GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- /* Peripheral DMA init*/
-
- hdma_adc1.Instance = DMA2_Stream0;
- hdma_adc1.Init.Channel = DMA_CHANNEL_0;
- hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
- hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
- hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
- hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
- hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
- hdma_adc1.Init.Mode = DMA_CIRCULAR;
- hdma_adc1.Init.Priority = DMA_PRIORITY_HIGH;
- hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
- HAL_DMA_Init(&hdma_adc1);
-
- __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
-
- }
-
- }
-
- void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
- {
-
- if(hadc->Instance==ADC1)
- {
- /* Peripheral clock disable */
- __ADC1_CLK_DISABLE();
-
- /**ADC1 GPIO Configuration
- PC0 ------> ADC1_IN10
- PC1 ------> ADC1_IN11
- PC2 ------> ADC1_IN12
- PC3 ------> ADC1_IN13
- PA1 ------> ADC1_IN1
- PA3 ------> ADC1_IN3
- PA4 ------> ADC1_IN4
- PA5 ------> ADC1_IN5
- PA6 ------> ADC1_IN6
- PA7 ------> ADC1_IN7
- PC4 ------> ADC1_IN14
- PC5 ------> ADC1_IN15
- */
- HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
- |GPIO_PIN_4|GPIO_PIN_5);
-
- HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
- |GPIO_PIN_6|GPIO_PIN_7);
-
- /* Peripheral DMA DeInit*/
- HAL_DMA_DeInit(hadc->DMA_Handle);
- }
-
- }
-
- void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
- {
-
- GPIO_InitTypeDef GPIO_InitStruct;
- if(hi2c->Instance==I2C1)
- {
- /* Peripheral clock enable */
- __I2C1_CLK_ENABLE();
-
- /**I2C1 GPIO Configuration
- PB6 ------> I2C1_SCL
- PB7 ------> I2C1_SDA
- */
- GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
- GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- /* Peripheral DMA init*/
-
- hdma_i2c1_tx.Instance = DMA1_Stream6;
- hdma_i2c1_tx.Init.Channel = DMA_CHANNEL_1;
- hdma_i2c1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
- hdma_i2c1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
- hdma_i2c1_tx.Init.MemInc = DMA_MINC_ENABLE;
- hdma_i2c1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
- hdma_i2c1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
- hdma_i2c1_tx.Init.Mode = DMA_NORMAL;
- hdma_i2c1_tx.Init.Priority = DMA_PRIORITY_LOW;
- hdma_i2c1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
- HAL_DMA_Init(&hdma_i2c1_tx);
-
- __HAL_LINKDMA(hi2c,hdmatx,hdma_i2c1_tx);
-
- hdma_i2c1_rx.Instance = DMA1_Stream5;
- hdma_i2c1_rx.Init.Channel = DMA_CHANNEL_1;
- hdma_i2c1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
- hdma_i2c1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
- hdma_i2c1_rx.Init.MemInc = DMA_MINC_ENABLE;
- hdma_i2c1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
- hdma_i2c1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
- hdma_i2c1_rx.Init.Mode = DMA_NORMAL;
- hdma_i2c1_rx.Init.Priority = DMA_PRIORITY_HIGH;
- hdma_i2c1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
- HAL_DMA_Init(&hdma_i2c1_rx);
-
- __HAL_LINKDMA(hi2c,hdmarx,hdma_i2c1_rx);
-
- /* Peripheral interrupt init*/
- /* Sets the priority grouping field */
- HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1);
- HAL_NVIC_SetPriority(I2C1_ER_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(I2C1_ER_IRQn);
- /* Sets the priority grouping field */
- HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1);
- HAL_NVIC_SetPriority(I2C1_EV_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(I2C1_EV_IRQn);
- }
-
- }
-
- void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
- {
-
- if(hi2c->Instance==I2C1)
- {
- /* Peripheral clock disable */
- __I2C1_CLK_DISABLE();
-
- /**I2C1 GPIO Configuration
- PB6 ------> I2C1_SCL
- PB7 ------> I2C1_SDA
- */
- HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
-
- /* Peripheral DMA DeInit*/
- HAL_DMA_DeInit(hi2c->hdmatx);
- HAL_DMA_DeInit(hi2c->hdmarx);
-
- /* Peripheral interrupt Deinit*/
- HAL_NVIC_DisableIRQ(I2C1_ER_IRQn);
- HAL_NVIC_DisableIRQ(I2C1_EV_IRQn);
- }
-
- }
-
- void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* htim_encoder)
- {
-
- GPIO_InitTypeDef GPIO_InitStruct;
- if(htim_encoder->Instance==TIM1)
- {
- /* Peripheral clock enable */
- __TIM1_CLK_ENABLE();
-
- /**TIM1 GPIO Configuration
- PA8 ------> TIM1_CH1
- PA9 ------> TIM1_CH2
- */
- GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- /* Peripheral interrupt init*/
- /* Sets the priority grouping field */
- HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1);
- HAL_NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn);
- }
- else if(htim_encoder->Instance==TIM3)
- {
- /* Peripheral clock enable */
- __TIM3_CLK_ENABLE();
-
- /**TIM3 GPIO Configuration
- PB4 ------> TIM3_CH1
- PB5 ------> TIM3_CH2
- */
- GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- /* Peripheral interrupt init*/
- /* Sets the priority grouping field */
- HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1);
- HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(TIM3_IRQn);
- }
-
- }
-
- void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
- {
-
- GPIO_InitTypeDef GPIO_InitStruct;
- if(htim_pwm->Instance==TIM4)
- {
- /* Peripheral clock enable */
- __TIM4_CLK_ENABLE();
-
- /**TIM4 GPIO Configuration
- PB9 ------> TIM4_CH4
- */
- GPIO_InitStruct.Pin = GPIO_PIN_9;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- }
-
- }
-
- void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
- {
-
- GPIO_InitTypeDef GPIO_InitStruct;
- if(htim_base->Instance==TIM6)
- {
- /* Peripheral clock enable */
- __TIM6_CLK_ENABLE();
-
- /* Peripheral interrupt init*/
- /* Sets the priority grouping field */
- HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1);
- HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 1, 2);
- HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
- }
- else if(htim_base->Instance==TIM7)
- {
- /* Peripheral clock enable */
- __TIM7_CLK_ENABLE();
-
- /* Peripheral interrupt init*/
- /* Sets the priority grouping field */
- HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1);
- HAL_NVIC_SetPriority(TIM7_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(TIM7_IRQn);
- }
- else if(htim_base->Instance==TIM8)
- {
- /* Peripheral clock enable */
- __TIM8_CLK_ENABLE();
-
- /**TIM8 GPIO Configuration
- PC6 ------> TIM8_CH1
- PC9 ------> TIM8_CH4
- */
- GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_9;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
- GPIO_InitStruct.Alternate = GPIO_AF3_TIM8;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-
- }
- else if(htim_base->Instance==TIM10)
- {
- /* Peripheral clock enable */
- __TIM10_CLK_ENABLE();
-
- /* Peripheral interrupt init*/
- /* Sets the priority grouping field */
- HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1);
- HAL_NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn);
- }
-
- }
-
- void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef* htim_encoder)
- {
-
- if(htim_encoder->Instance==TIM1)
- {
- /* Peripheral clock disable */
- __TIM1_CLK_DISABLE();
-
- /**TIM1 GPIO Configuration
- PA8 ------> TIM1_CH1
- PA9 ------> TIM1_CH2
- */
- HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_9);
-
- /* Peripheral interrupt Deinit*/
- HAL_NVIC_DisableIRQ(TIM1_UP_TIM10_IRQn);
- }
- else if(htim_encoder->Instance==TIM3)
- {
- /* Peripheral clock disable */
- __TIM3_CLK_DISABLE();
-
- /**TIM3 GPIO Configuration
- PB4 ------> TIM3_CH1
- PB5 ------> TIM3_CH2
- */
- HAL_GPIO_DeInit(GPIOB, GPIO_PIN_4|GPIO_PIN_5);
-
- /* Peripheral interrupt Deinit*/
- HAL_NVIC_DisableIRQ(TIM3_IRQn);
- }
-
- }
-
- void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
- {
-
- if(htim_pwm->Instance==TIM4)
- {
- /* Peripheral clock disable */
- __TIM4_CLK_DISABLE();
-
- /**TIM4 GPIO Configuration
- PB9 ------> TIM4_CH4
- */
- HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9);
-
- }
-
- }
-
- void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
- {
-
- if(htim_base->Instance==TIM6)
- {
- /* Peripheral clock disable */
- __TIM6_CLK_DISABLE();
-
- /* Peripheral interrupt Deinit*/
- HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn);
- }
- else if(htim_base->Instance==TIM7)
- {
- /* Peripheral clock disable */
- __TIM7_CLK_DISABLE();
-
- /* Peripheral interrupt Deinit*/
- HAL_NVIC_DisableIRQ(TIM7_IRQn);
- }
- else if(htim_base->Instance==TIM8)
- {
- /* Peripheral clock disable */
- __TIM8_CLK_DISABLE();
-
- /**TIM8 GPIO Configuration
- PC6 ------> TIM8_CH1
- PC9 ------> TIM8_CH4
- */
- HAL_GPIO_DeInit(GPIOC, GPIO_PIN_6|GPIO_PIN_9);
-
- }
- else if(htim_base->Instance==TIM10)
- {
- /* Peripheral clock disable */
- __TIM10_CLK_DISABLE();
-
- /* Peripheral interrupt Deinit*/
- HAL_NVIC_DisableIRQ(TIM1_UP_TIM10_IRQn);
- }
-
- }
-
- void HAL_UART_MspInit(UART_HandleTypeDef* huart)
- {
-
- GPIO_InitTypeDef GPIO_InitStruct;
- if(huart->Instance==USART3)
- {
- /* Peripheral clock enable */
- __USART3_CLK_ENABLE();
-
- /**USART3 GPIO Configuration
- PC10 ------> USART3_TX
- PC11 ------> USART3_RX
- */
- GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-
- }
-
- }
-
- void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
- {
-
- if(huart->Instance==USART3)
- {
- /* Peripheral clock disable */
- __USART3_CLK_DISABLE();
-
- /**USART3 GPIO Configuration
- PC10 ------> USART3_TX
- PC11 ------> USART3_RX
- */
- HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11);
-
- }
-
- }
-
- /* USER CODE BEGIN 1 */
-
- /* USER CODE END 1 */
-
- /**
- * @}
- */
-
- /**
- * @}
- */
-
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/