Skip to main content
bluscape
Associate III
April 12, 2012
Question

GPIO_PinAFConfig does not configure alternate function register

  • April 12, 2012
  • 1 reply
  • 643 views
Posted on April 12, 2012 at 23:01

I'm using a STM32L151C8 with ARM RealView and ST peripheral libraries.

When I try and configure an I/O pin as an alternate function it does not write the alternate function selection to the GPIOx_AFR register. After calling the GPIO_PinAFConfig function the GPIOA_AFRH register should contain a value of 0x07 (AF7) in AFRH10 and AFRH9 but they remain zero.

#define USART_TXD_PIN                         GPIO_Pin_9

#define USART_RXD_PIN                         GPIO_Pin_10

#define USART_TXD                             GPIOA

#define USART_RXD                             GPIOA

GPIO_InitStructure.GPIO_Pin = GSM_TXD_PIN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;  

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_PinAFConfig(GSM_TXD, GSM_TXD_PIN, GPIO_AF_USART1);        

GPIO_InitStructure.GPIO_Pin = GSM_RXD_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 

GPIO_Init(GPIOA, &GPIO_InitStructure);        

GPIO_PinAFConfig(GSM_RXD, GSM_RXD_PIN, GPIO_AF_USART1);
    This topic has been closed for replies.

    1 reply

    bluscape
    bluscapeAuthor
    Associate III
    April 12, 2012
    Posted on April 12, 2012 at 23:09

    Ok, realized my problem.

    It should be: GPIO_PinAFConfig(GSM_TXD,

    GPIO_PinSource9

    , GPIO_AF_USART1);

    and not: GPIO_PinAFConfig(GSM_TXD,

    GPIO_Pin9

    , GPIO_AF_USART1);