Skip to main content
JLEE.61
Associate II
November 14, 2018
Question

Change the Alternate functions default pin for USART1 on STM32F103

  • November 14, 2018
  • 5 replies
  • 3033 views

Hi,

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

Please let me know if you have a solution.

Thanks.

    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    November 14, 2018

    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    JLEE.61
    JLEE.61Author
    Associate II
    November 14, 2018

    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.

    Tesla DeLorean
    Guru
    November 14, 2018

    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    JLEE.61
    JLEE.61Author
    Associate II
    November 14, 2018

    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
    Principal III
    November 16, 2018

    "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
    JLEE.61Author
    Associate II
    November 19, 2018

    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.

    Tesla DeLorean
    Guru
    November 19, 2018

    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    JLEE.61
    JLEE.61Author
    Associate II
    November 19, 2018

    I'm using the STM32F103RBT7.

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

    Thanks.