cancel
Showing results for 
Search instead for 
Did you mean: 

loopback with UART Tx pin configured as AF_OD and Rx pin as GPIO_Input

Meghana
Visitor

I'm trying uart loopback and checking if I'm receiving the transmitted data on the receive buffer, I'm using nucleo-u575zi board , uart2 I'm using , baudrate is 57600 , the tx pin & rx pin are configured as shown below

 

   GPIO_InitStruct.Pin = GPIO_PIN_2;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_3;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 

  I'm using receive in interrupt mode and in ISR function I'm trying to receive byte by byte, And also, before going to receive callback it goes error callback function where the error-code is 4 and then it goes rxcallback where byte by byte reception happens, but buffer value is zero.
If the tx & rx modes AF_PP it works fine where in buffer I can see the data in buffer Whatever I'm transmitting but in the above-mentioned mode, receive buffer nothing is coming.
I have attached the main.c , msp.c and it.c files below, kindly ignore the commented lines I was trying to work on something else too.

16 REPLIES 16
Imen.D
ST Employee

Hello @Meghana ,

I'm editing your post to comply with the ST Community guidelines. In next time, please use </> button for your code.
Please review our recommendation on this link on how to post a thread in this community:
https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Imen.D
ST Employee

Hi @Meghana ,

The error code indicates a framing error, which might be caused by incorrect baud rate or UART settings.

You can refer to the UART examples available in the STM32CubeU5 firmware package for your Nucleo-U575 board:

STM32CubeU5/Projects/NUCLEO-U575ZI-Q/Examples at main · STMicroelectronics/STM32CubeU5 · GitHub

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
AScha.3
Chief III

Is this setting generated by Cube - or you playing around yourself ?

 

+

it should be like this:

    /**UART7 GPIO Configuration
    PE7     ------> UART7_RX
    PE8     ------> UART7_TX
    */
    GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF7_UART7;
    HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
If you feel a post has answered your question, please click "Accept as Solution".
gbm
Lead III

It cannot work this way - the pin configuration is incorrect. First, it's not F1 series - Rx must be configured as AF, not as GPIO input. Then, it MUST be pulled up. Additionally, you may enable pullup on TX to make it slightly stronger.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

Thank you for correcting me from now on I'll adhere to the ST Community guidelines.

Hi 

Thank you for the response. The code is generated as you mentioned only but for my testing purpose, I need it in the mentioned configuration where Tx pin is open-drain and Rx pin is input mode. 
The loopback works fine for the default configuration but when I change it to mentioned configurations and do receive in interrupt mode, it calls error callback function where it shows error code as 4 which indicates frame error after clearing that flag then it goes rxcallback function. 

I attached an external pullup resistor of 10kohms to the Tx line as it is in open drain mode.

Kindly, check the files I have attached.


Hi 

Thank you for the response. So, to be specific you are saying that using u5 series board I cannot do this but why? Transmission works fine, but why doesn't receive work? Also should I enable internal pullup for Tx and Rx pin configurations?

GPIO_InitStruct.Pull = GPIO_PULLUP;

 

Hi,

see in rm U5xx :

port registers :

AScha3_0-1737968529755.png

For uart rx/tx you need AF setting. But you cannot choose more than ONE mode for a pin.

You haveto  set it to AF , uart working then.

...and try, to read the input state from input register - should be still connected, if this pic is correct:

AScha3_1-1737968728950.png

 

Just try... (i never tried and have no U5...) .If there is an input mux , not shown in pic, then its not possible.

If you feel a post has answered your question, please click "Accept as Solution".

@Meghana wrote:

Transmission works fine


How have you verified that?

Any open-drain (or open-collector) output will always require a pullup to work - it's basic electronics.

An open-drain output acts as just a switch to ground: it can pull down, but it can never drive high - hence a pullup is always essential.

Internal pullups have a fairly high resistance - around 40k ? - so are not going to be suitable for high-speed comms.

This post shows the effect of pullup value on the communication:

AndrewNeil_3-1737969789848.png

So use an oscilloscope to check what's happening in your case ...