AnsweredAssumed Answered

STM32F103 use PB4 and PB5 as USART TX-RX?

Question asked by Luis Martinez on Jun 1, 2017
Latest reply on Jun 2, 2017 by Luis Martinez

Hello to the community,

 

Due to an error on a board routing I have ended with a bunch of boards with the RX and TX pins of USART1 incorrectly routed to PB4 and PB5 pins of STM32F103.

I wonder if there is any human way of remaping this pins to be used with USART1,2 or 3.

 

I have tried the following code without success:

#define USARTy USART2
#define USARTy_GPIO GPIOB
#define USARTy_CLK RCC_APB1Periph_USART2
#define USARTy_GPIO_CLK RCC_APB2Periph_GPIOA
#define USARTy_RxPin GPIO_Pin_4
#define USARTy_TxPin GPIO_Pin_5

 

RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);

RCC_APB1PeriphClockCmd(USARTy_CLK, ENABLE);

 

/* Enable the USART2 Pins Software Remapping */

GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);

 

/* Configure USARTy Rx as input floating */
GPIO_InitStructure.GPIO_Pin = USARTy_RxPin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);

 

/* Configure USARTy Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = USARTy_TxPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);

 

Thanks in advance,

 

Luis

Outcomes