cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 F4 Hal libraries GPIO PIN alternate function

ismimusyafani
Associate II
Posted on September 21, 2015 at 03:57

how to configure GPIO PIN alternate function in hal driver ?

in std_periph driver i usually used this code:

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_TIM12);   //TIM2_CH1

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_TIM12);    //TIM2_CH2

how to configure in Hal driver, can you help me about this code :

// GPIO TypeDef Initialization

 

  GPIO_TypeDef GPIO_TypeDefStruct;

 /* // No se para que mierda es esto si uso PWM

  GPIO_TypeDefStruct.MODER |= ((31<<1)|(29<<1)|(27<<1)|(25<<1));

  GPIO_TypeDefStruct.OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR15_1 | GPIO_OSPEEDER_OSPEEDR_14_1

                                 GPIO_OSPEEDER_OSPEEDR13_1 | GPIO_OSPEEDER_OSPEEDR_12_1);

  */

  GPIO_TypeDefStruct.AFR[1] |=(28<<GPIO_AF2_TIM4|24<<GPIO_AF2_TIM4|20<<GPIO_AF2_TIM4|16<<GPIO_AF2_TIM4);

  GPIO_TypeDef* GPIO_D = & GPIO_TypeDefStruct;

 

    
2 REPLIES 2
stm32forum
Associate II
Posted on September 21, 2015 at 10:31

Hi,

For example:

Configuring USART3 Tx (PC10, mapped on AF7) as alternate function:

GPIO_InitStruct.Pin = GPIO_PIN_10;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_PULLUP;

GPIO_InitStruct.Speed = GPIO_SPEED_FAST;

GPIO_InitStruct.Alternate = GPIO_AF7_USART3;

HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

 

ismimusyafani
Associate II
Posted on September 29, 2015 at 01:29

thanx Edje, your information is very important for me. I also know it in stm32 cube example project, there are many configuration for all function of stm32. thanx edje hehehe