cancel
Showing results for 
Search instead for 
Did you mean: 

Change the Alternate functions default pin for USART1 on STM32F103

JLEE.61
Associate II

Hi,

I want to change TX/PB6 to RX/PB6 for USART1 on STM32F103.

Please let me know if you have a solution.

Thanks.

12 REPLIES 12

Remap the I2C1 off the PB6/PB7 and then remap USART1 on. For the remap to function the AFIO clock needs to be enabled.

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

Hi Clive

Thanks for quickly response.

You mean that below?

================================================

__HAL_AFIO_REMAP_I2C1_DISABLE();

 __HAL_RCC_USART1_CLK_ENABLE();

 GPIO_InitStruct.Pin = GPIO_PIN_6;

 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = GPIO_PIN_7;

 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 __HAL_AFIO_REMAP_USART1_ENABLE();

 __HAL_RCC_AFIO_CLK_ENABLE();  

================================================

Could you let me know the more detail information?

Thanks.

You need to enable the AFIO clock BEFORE you use things dependent on it, not after.

Try a more rational ordering..

__HAL_RCC_AFIO_CLK_ENABLE();

__HAL_RCC_USART1_CLK_ENABLE();

__HAL_AFIO_REMAP_I2C1_DISABLE();

__HAL_AFIO_REMAP_USART1_ENABLE();

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

I tried it in the way you told me, but it did not work

In my pins configuration,

1. I2C1 = not use

2. I2C2(PB10-SCL, PB11-SDA) is work well.

3. UART3(PC11-RX, PC10-TX) is work well too.

4. UART1(PB6-TX, PB7-RX) is work well too.

5. UART1(PB6-RX, PB7-TX) dose not work.

Is there any other way?

Piranha
Chief II

"5. UART1(PB6-RX, PB7-TX) dose not work."

Read the datasheet - there is no such mode in it! You can't set any pin to any function.

JLEE.61
Associate II

Hi Piranha

I know that default USART1 are PB6-TX, PB​7-RX as the datasheet.

Our HW team has opposite designed the PIN.

Is it really impossible?

Thanks.

What is the complete/specific part number of the chip you are using? ST has a range of parts with assorted capabilities and dies.

https://www.st.com/resource/en/datasheet/cd00161566.pdf

The USART1 remapping to PB6/PB7 should be viable, but we're talking 10 year old parts, and I've moved on from them. The F1 family had peripheral level remapping, newer families have a richer pin muxing fabric which affords more/different opportunities.

>>Our HW team has opposite designed the PIN.

They swapped the TX and RX usage?

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

I'm using the STM32F103RBT7.

let me know if you have detail instructions or related doc to remapping.

Thanks.

The Data Sheet, Reference Manual, and SPL library source proved sufficient for me.

But per the docs, you're not going to be able to switch RX and TX functionality around, that is beyond the scope of remapping. PB6 is the OUTPUT, PB7 is the INPUT

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