cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use the alternate function mapping?

Carter Lee
Associate III
Posted on September 11, 2017 at 06:17

Hi.

Now I'm trying to understand the alternate function mapping with simple example of  'STM32F4xx_StdPeriph_Examples\USART\USART_HyperTerminal'

But there is nowhere the setting of alternate function mapping to use PA9 as USART1_TX (AF7)

I think it should be in there about the setting of alternate function mapping 

Could you please let me know how can I understand this?

Even I can find the same function USART1_TX and USART1_TX PA9 PA10 and PB6 and PB7.

So If I want to use PB6 to USART1_TX not PA9 then what am I supposed to ?

Could you please with any example snippet code?

2 REPLIES 2
Nesrine M_O
Lead II
Posted on September 11, 2017 at 11:33

Hi

,

I recommend you to have a look to thePinouts and pin description (Alternate function mapping table) section in your related datasheet , and alsoGeneral-purpose I/Os (GPIO) chapter in your reference manual.

Even I can find the same function USART1_TX and USART1_TX PA9 PA10 and PB6 and PB7.

So If I want to use PB6 to USART1_TX not PA9 then what am I supposed to ?

Could you please with any example snippet cod

in the main.c file the STM_EVAL_COMInit function Configures the COM port

0690X000006081MQAQ.png

in thestm324x9i_eval.h for example you find the definitions of theCOM port0690X00000608BuQAI.png

you can use thiefunction below to Change the mapping of the specified pin

 /* GPIO Alternate functions configuration function ****************************/void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);�?�?

example TIM1:

GPIO_InitTypeDef GPIO_InitStructure;/* GPIOA, GPIOB and GPIOC clocks enable */RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC, ENABLE);/* TIM1 clock enable */RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);/* GPIOA Configuration: TIM1 Channel1 as alternate function push-pull */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;GPIO_Init(GPIOA, &GPIO_InitStructure);/* Connect TIM pins to AF1 */GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1);�?�?�?�?�?�?�?�?�?�?�?�?�?�?

-Nesrine-

Posted on September 11, 2017 at 12:49

/**

  * @brief  Configures COM port.

  * @param  COM: Specifies the COM port to be configured.

  *   This parameter can be one of following parameters:

  *     @arg COM1

  *     @arg COM2

  * @param  USART_InitStruct: pointer to a USART_InitTypeDef structure that

  *   contains the configuration information for the specified USART peripheral.

  * @retval None

  */

void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)

{

  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enable GPIO clock */

  RCC_AHB1PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM], ENABLE);

  if (COM == COM1)

  {

    /* Enable UART clock */

    RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);

  }

  /* Connect PXx to USARTx_Tx*/

  GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_PIN_SOURCE[COM], COM_TX_AF[COM]);

  /* Connect PXx to USARTx_Rx*/

  GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_PIN_SOURCE[COM], COM_RX_AF[COM]);

  /* Configure USART Tx as alternate function  */

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);

  /* Configure USART Rx as alternate function  */

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];

  GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);

  /* USART configuration */

  USART_Init(COM_USART[COM], USART_InitStruct);

  /* Enable USART */

  USART_Cmd(COM_USART[COM], ENABLE);

}
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..