Skip to main content
eeeeee
Associate III
June 8, 2021
Solved

Can't swap TX/RX pins of UART in project 'Zigbee_SE_Msg_Server_Router' on STM32WB50CG.

  • June 8, 2021
  • 5 replies
  • 3348 views

Hi,

I'm trying to swap the TX/RX pins of UART but I can't make it happen without the project configuration file that is not present in the Zigbee_SE_Msg_Server_Router project.

I tried to change the pins in the 'hw_conf.h' file but that doesn't seem to change anything. Am I missing something?

Thanks in advance!

This topic has been closed for replies.
Best answer by eeeeee

I believe I've found the problem. There was another adjustment to be made in the file 'stm32wbxx_hal_msp.c'.

There is a GPIO_InitStruct in this file that also needs to be modified to the right pins. After that it worked for me.

Thanks for your time!

5 replies

Mike_ST
ST Technical Moderator
June 8, 2021

Try to activate the "SWAP" feature:

/**

 * @brief USART1 Initialization Function

 * @param None

 * @retval None

 */

void MX_USART1_UART_Init(void)

{

   huart1.Instance = USART1;

   huart1.Init.BaudRate = 115200;

   huart1.Init.WordLength = UART_WORDLENGTH_8B;

   huart1.Init.StopBits = UART_STOPBITS_1;

   huart1.Init.Parity = UART_PARITY_NONE;

   huart1.Init.Mode = UART_MODE_TX_RX;

   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;

   huart1.Init.OverSampling = UART_OVERSAMPLING_8;

   huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

   huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;

   huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT; //UART_ADVFEATURE_NO_INIT;

   if (HAL_UART_Init(&huart1) != HAL_OK) {

       Error_Handler();

   }

   if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) {

       Error_Handler();

   }

   if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) {

       Error_Handler();

   }

   if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) {

       Error_Handler();

   }

}

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
eeeeee
eeeeeeAuthor
Associate III
June 8, 2021

Yes I also did that, sorry for not mentioning.

Mike_ST
ST Technical Moderator
June 8, 2021

It should be as simple as that.

Do you see some signal on UART pins even when not swapped ?

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
eeeeee
eeeeeeAuthor
Associate III
June 8, 2021

Yes I have a LED on RX and TX each. When I run another project and I initialize the UART, the LEDs on each signal goes on. When I initialize this project, I only see the TX signal go on.

I figured it would maybe be because it is a protected project or something?

eeeeee
eeeeeeAuthorBest answer
Associate III
June 8, 2021

I believe I've found the problem. There was another adjustment to be made in the file 'stm32wbxx_hal_msp.c'.

There is a GPIO_InitStruct in this file that also needs to be modified to the right pins. After that it worked for me.

Thanks for your time!