cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 use PB4 and PB5 as USART TX-RX?

Luis Martinez
Associate
Posted on June 01, 2017 at 18:53

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

2 REPLIES 2
Posted on June 02, 2017 at 02:23

The silicon provides a finite set of connections, so what you want to happen, can't.

You'd perhaps look at implementing a Software USART, but this isn't something I'd recommend.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Luis Martinez
Associate
Posted on June 02, 2017 at 09:56

Thank you, this is what I was expecting, having read the reference manual about remaping uarts seemed to have this hardwired. I just was hoping to have missed anything.

Thank you again.