IMX RT1024 UART Loopback Pins

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IMX RT1024 UART Loopback Pins

Jump to solution
3,907 Views
Lukas_Frank
Senior Contributor I

Hi all,

I'm trying to test UART loopback mode on a IMXRT1024 EVK board. So I want to send data from TX and getting these data from RX in the same board without need one more hardware. So just testing functionality of my UART. Reference manual indicates there are a few relevant fields in the UART control register 1 to enable this functionality:

LOOPS Loop Mode Select
Selects between loop back modes and normal 2-pin full-duplex modes. When LOOPS is set, the transmitter output is internally connected to the receiver input.
0 = Normal operation - UART_RX and UART_TX use separate pins.
1 = Loop mode or single-wire mode where transmitter outputs are internally connected to receiver input. (See RSRC bit.) UART_RX pin is not used by UART.

RSRC Receiver Source Select
This bit has no meaning or effect unless the LOOPS bit is set to 1. When LOOPS is set, the receiver input is internally connected to the UART_TX pin and RSRC determines whether this connection is also
connected to the transmitter output.
0 = Provided LOOPS is set, RSRC is cleared, selects internal loop back mode and the UART does not use the UART_RX pins.
1 = Single-wire UART mode where the UART_TX pin is connected to the transmitter output and receiver input.

44.3.6.3 Loop mode

When CTRL[LOOPS] is set, the CTRL[RSRC] bit chooses between loop mode (CTRL[RSRC] = 0) or single-wire mode (CTRL[RSRC] = 1). Loop mode is sometimes used to check software, independent of connections in the external system, to help isolate system problems. In this mode, the transmitter output is internally connected to the receiver input and the RXD pin is not used by the LPUART.

Which pin configuration should I set to do my work?

Are the CTRL[LOOPS] = 1 and CTRL[RSRC] = 1 pins correct configuration for my question? What are the correct ones if it is false?

0 Kudos
Reply
1 Solution
3,770 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank 

   Loopback will connect the RX to the TX in the chip internal side, which don't need to add external TTL-USB tool, that's why I confusing why you use the external TTL-USB, but you still use the internal loop back mode, you totally can use the SDK directly without the loopback, and if you want to use UART2, just change pins, and the UART number to UART2 and the interrupt service handler to UART2 is ok.

   BTW, do you test the function for your company? If yes, you'd better use the company email to create the case, that will have higher priority than the 3rd part email, eg gmail.

 

Best Regards,

kerry

View solution in original post

18 Replies
3,893 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank 

 Please check this information at first:

49.3.5.3 Loop mode
When CTRL[LOOPS] is set, the CTRL[RSRC] bit chooses between loop mode
(CTRL[RSRC] = 0) or single-wire mode (CTRL[RSRC] = 1). Loop mode is sometimes
used to check software, independent of connections in the external system, to help isolate
system problems. In this mode, the transmitter output is internally connected to the
receiver input and the RXD pin is not used by the LPUART.

 

kerryzhou_0-1624437234082.png

So you need:CTRL[LOOPS] = 1 and CTRL[RSRC] = 0 to select the loop back mode.

 

Wish it helps you!

Best Regards,

kerry

 

3,894 Views
Lukas_Frank
Senior Contributor I

Hi again I realized that there is also "TXDIR". Are the correct ping assignment like below?

TXDIR = LOOPS = Rsrc=1

I am just trying to do something like below

Lukas_Frank_0-1624437192770.jpeg

Could you please share me a uart loopback code example for IMXRT1024?

0 Kudos
Reply
3,891 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank 

You configration is wrong, CTRL[RSRC] = 0.

 

Wish it helps you!

Best Regards,

kerry

3,889 Views
Lukas_Frank
Senior Contributor I

I tried it but that is not working. I tried it on LPUART_EDMA_TRANSFER example in the SDK. Is there any example that can direct me to correct solution?

Could you please share me a code example?

Best regards..

0 Kudos
Reply
3,881 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank 

What's the result you are printing now?

Do you try other polling code with this configuration?

BTW, post your configuration code, I need to check whether it is correct or not.

Or you also can debug the code, and check the related register, whether you modify it correctly.

 

Best Regards,

Kerry

3,874 Views
Lukas_Frank
Senior Contributor I

Hi Dear @kerryzhou,

I just firstly tried loopback example in LPUART_EDMA_TRANSFER. But there are no output when I activate the loop mode with the LPUART_Loopback_Mode_Enable method. Then, I tried it with polling code with your directives. Here are the following lines in my source code:

 

#include "ping_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_lpuart.h"

#define DEMO_LPUART				LPUART1
#define DEMO_LPUART_CLK_FREQ 	BOARD_DebugConsoleSrcFreq()

uint8_t txbuff[] 	= "Lpuart polling example\r\nBoard will send back received characters\r\n";
uint8_t rxbuff[20]  = {0};

void LPUART_Loopback_Mode_Enable(LPUART_Type *base, bool enable)
{
	if(enable)
	{
		base->CTRL |= LPUART_CTRL_LOOPS_MASK;
		//base->CTRL |= LPUART_CTRL_RSRC_MASK;
	}
	else
	{
		base->CTRL &= ~LPUART_CTRL_LOOPS_MASK;
		base->CTRL &= ~LPUART_CTRL_RSRC_MASK;
	}
}

int main(void)
{
	uint8_t ch;
	lpuart_config_t config;
	
	BOARD_ConfigMPU();
	BOARD_InitPins();
	BOARD_BootClockRUN();
	
	LPUART_GetDefaultConfig(&config);
	
	config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
	
	config.enableTx		= true;
	config.enableRx		= true;
	
	LPUART_Init(DEMO_LPUART, &config, DEMO_LPUART_CLK_FREQ);
	
	LPUART_Loopback_Mode_Enable(DEMO_LPUART,true);
	
	LPUART_WriteBlocking(DEMO_LPUART,txbuff,sizeof(txbuff)-1);
	
	while(true)
	{
		LPUART_ReadBlocking(DEMO_LPUART, &ch, 1);
		LPUART_WriteBlocking(DEMO_LPUART, &ch, 1);
	}
	
}

 

Scenario 1 : When I enable Loopback mode here is the following Terminal output:

Lpuart polling example
Board will send back received characters
Lpuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.....(keep going on like this)

Scenario 2 : When I do not enable Loopback mode example code wait for input from me and prints what I write.

Note:

In Scenario 1 : J17 Pin UART RX and TX pins are connected each other

In Scenario 2 : J17 Pin UART RX and TX pins are not connected each other

I have two question:

First:

Where exactly come from "Lpuaaaaa....." characters in Scenario 1 ? And why it is ending with 'a' and keep going like "aaaaaaaaaaaa..."

Second:

I just want to send data from TX and read it from RX. How does it true even I do not connect RX and TX pins each other in Scenario 2. So, When I input from keyboard it prints to terminal screen syncly but I am not able to trace it what I am reading (I know there are IRQs but how does it occuring). From below line 

LPUART_ReadBlocking(DEMO_LPUART, &ch, 1);

So how does loopback is occur in default polling example code.

 

I am new on UART. Thanks for your interests with patience.

 

Best Regards,

0 Kudos
Reply
3,869 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank  

   Welcome to the RT world.

   Your test result is totally correct, as you are new to the UART, let me tell you some of my experience.

  1. LPUART receive is the 4 datawords in the receive FIFO Buffer depth in default

   You receive: lpuaaaaaaaaa...

   It because you have send: Lpuart polling example Board will send back received characters

   So, the receive will remember your first lpua, then when you receive call it, and your code is:

while (1)
{
LPUART_ReadBlocking(DEMO_LPUART, &ch, 1);

 LPUART_WriteBlocking(DEMO_LPUART, &ch, 1);
}

Now, your receive will sendout the received data again, send means receive, so you will always get a, as your loopback send a.

2. About the LPUART testing, normally, we don't use the loopback function, we will use the external UART directly to test it. So you totally can use your MIMXRT1024-EVK on board Virtual COM port to test the SDK project, then you will find it works OK.

3. to your loop back, you also can write the code like this:

uint8_t txbuff[]   = "1234";
uint8_t rxbuff[20] = {0};

/*******************************************************************************
 * Code
 ******************************************************************************/
void LPUART_Loopback_Mode_Enable(LPUART_Type *base, bool enable)
{
	if(enable)
	{
		base->CTRL |= LPUART_CTRL_LOOPS_MASK;
		//base->CTRL |= LPUART_CTRL_RSRC_MASK;
	}
	else
	{
		base->CTRL &= ~LPUART_CTRL_LOOPS_MASK;
		base->CTRL &= ~LPUART_CTRL_RSRC_MASK;
	}
}
/*!
 * @brief Main function
 */
int main(void)
{
    uint8_t ch;
    lpuart_config_t config;

    uint16_t delay_cnt=0;

    BOARD_ConfigMPU();
    BOARD_InitPins();
    BOARD_BootClockRUN();

    /*
     * config.baudRate_Bps = 115200U;
     * config.parityMode = kLPUART_ParityDisabled;
     * config.stopBitCount = kLPUART_OneStopBit;
     * config.txFifoWatermark = 0;
     * config.rxFifoWatermark = 0;
     * config.enableTx = false;
     * config.enableRx = false;
     */
    LPUART_GetDefaultConfig(&config);
    config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
    config.enableTx     = true;
    config.enableRx     = true;

    LPUART_Init(DEMO_LPUART, &config, DEMO_LPUART_CLK_FREQ);
    LPUART_Loopback_Mode_Enable(DEMO_LPUART,true);

    LPUART_WriteBlocking(DEMO_LPUART, txbuff, sizeof(txbuff) - 1);
    while (1)
    {
        for(delay_cnt=0; delay_cnt<60000;delay_cnt++);

         LPUART_ReadBlocking(DEMO_LPUART, &ch, 1);
         LPUART_WriteBlocking(DEMO_LPUART, &ch, 1);

    }
}

Then you will receive the result like this:

kerryzhou_0-1624515836386.png

 

Wish it helps you!

Best Regards,

kerry

 

3,861 Views
Lukas_Frank
Senior Contributor I

Hi Dear @kerryzhou,

 

I tried the below code yesterday.

Code:

#include "ping_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_lpuart.h"

#define DEMO_LPUART				LPUART1
#define DEMO_LPUART_CLK_FREQ 	BOARD_DebugConsoleSrcFreq()

uint8_t txbuff[] 	= "Lpuart polling example\r\nBoard will send back received characters\r\n";
uint8_t rxbuff[20]  = {0};

uint8_t LP_txbuff[] = "This message will send via TX and catch by RX\n";
uint8_t LP_rxbuff[sizeof(LP_txbuff)]  = {0};

void LPUART_Loopback_Mode_Enable(LPUART_Type *base, bool enable)
{
	AS THE SAME..
}

int main(void)
{
	uint64_t total_transfer_u64;
	uint8_t ch;
	lpuart_config_t config;
	
	BOARD_ConfigMPU();
	BOARD_InitPins();
	BOARD_BootClockRUN();
	
	LPUART_GetDefaultConfig(&config);
	
	config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
	
	config.enableTx		= true;
	config.enableRx		= true;
	
	LPUART_Init(DEMO_LPUART, &config, DEMO_LPUART_CLK_FREQ);
	
	LPUART_Loopback_Mode_Enable(DEMO_LPUART,true);
	
	LPUART_WriteBlocking(DEMO_LPUART,txbuff,sizeof(txbuff)-1);
	
	while(true)
	{
		for(uint8_t transfer_counter = 0; transfer_counter < sizeof(LP_txbuff); transfer_counter++)
		{
			LPUART_ReadBlocking (DEMO_LPUART,&LP_rxbuff[transfer_counter], 1);
			LPUART_WriteBlocking(DEMO_LPUART,&LP_txbuff[transfer_counter], 1);
		}
		total_transfer_u64++;
	}
}

 

I set the EVK Board Pin Configuration as below.

Configuration:

UART1_TXD = GPIO_AD_BO_06 (Arduino Interface J17 : Pinout 12)

UART1_RXD = GPIO_AD_BO_07 (Arduino Interface J17 : Pinout

I connected these pins with two-sided male jumper.

 

After your last message, I just wonder if it is not possible to test loopback example in EVK. Like Virtual COM Port, I can see the outputs in MCUXpresso Terminal screen too. But I want to test my system physically. But, It is still working even if the pins output are not connected with the two-sided male jumper. I am waiting to corrupt data flow when I plug-out RX-side of male jumper. Is not it possible?

 

By the way, are datawords 8 bit in IMXRT1024 or configurable?

0 Kudos
Reply
3,860 Views
Lukas_Frank
Senior Contributor I

I think, data flow continues because of the demo app writing and reading from registers not pins. Is that so? Is not it possible to do physical test like I mention?

 

Thanks and Regards,

0 Kudos
Reply
3,856 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank 

  If you need physical test, why you add the internal loop back?

1. external TTL-USB tool test, you need to disconnect the on board COM port.

J45, J46, disconnect, then you can connect your external TTL-USB to the J45_2, and J46_2 pin.

Please note, external TX connect to J45_2, external RX connect to J46_2.

kerryzhou_0-1624586155519.png

 

 

2. to the internal loopback test, modify your code

 

 

	LPUART_Init(DEMO_LPUART, &config, DEMO_LPUART_CLK_FREQ);
	
	
	
	LPUART_WriteBlocking(DEMO_LPUART,txbuff,sizeof(txbuff)-1);
LPUART_Loopback_Mode_Enable(DEMO_LPUART,true);

 

 

Your test result is not corrupt, it is the normal working loop internal situation.

It is your code issues.

You can do it like my previous reply code.

Best Regards,

Kerry

 

 

 

3,849 Views
Lukas_Frank
Senior Contributor I

Hi Dear @kerryzhou,

I will try your directives. I have new questions.

First:

Why I am not able to send my datas to Arduino Interface UART1 pins. I listen the target pins for UART1 with oscilloscope. Although I send my datas to UART1 there is no data flow that seen in oscilloscope. Are not Arduino Interface pins physical?

Second:

How can I disconnect J32,J31 COM ports? 

Third:

Where are J32,J31 on board? Is there a way to quickly find my targets on board? I have J45,J46.

Lukas_Frank_1-1624526836605.png

 

Thanks and Regards,

0 Kudos
Reply
3,837 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank 

First:

Why I am not able to send my datas to Arduino Interface UART1 pins. I listen the target pins for UART1 with oscilloscope. Although I send my datas to UART1 there is no data flow that seen in oscilloscope. Are not Arduino Interface pins physical?

Answer: Which pin you have connected?

You mentioned :

Configuration:

UART1_TXD = GPIO_AD_BO_06 (Arduino Interface J17 : Pinout 12)

UART1_RXD = GPIO_AD_BO_07 (Arduino Interface J17 : Pinout

But your code is using:

kerryzhou_0-1624586307305.png

 

Second:

How can I disconnect J32,J31 COM ports? 

Answer: Not J32,J31, it is J45,J46, I post the wrong picture in the last email, already modify it.

  So you can't use your mentioned J17, that is connected to the LPUART2, but your code is using LPUART1.

So you need to use J45_2, J46_2.

Third:

Where are J32,J31 on board? Is there a way to quickly find my targets on board? I have J45,J46.

Answer: you are right, your board is  J45,J46.

 

 

Best Regards,

Kerry

3,828 Views
Lukas_Frank
Senior Contributor I

Hi Dear @kerryzhou ,

 

I have also tried UART2, UART3 in my code before. But it did not even work when I set configurations below. Then I continue with UART1. I think some configurations are missing that rooted by my mistakes.

I set DEMO_LPUART = LPUART2 (also LPUART3) as below:

 

#define DEMO_LPUART LPUART2 //LPUART1
#define DEMO_LPUART_CLK_FREQ BOARD_DebugConsoleSrcFreq()

 

In addition change configurations in BOARD_InitPins in pin_mux.c as below:

 

void BOARD_InitPins(void)
{
CLOCK_EnableClock(kCLOCK_Iomuxc);

IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_08_LPUART2_TX,0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_09_LPUART2_RX,0U);

IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B1_08_LPUART2_TX,0x10B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B1_09_LPUART2_RX,0x10B0U);
}

 

Also change configurations is board.h as below:

 

#define BOARD_DEBUG_UART_TYPE kSerialPort_Uart
#define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART2
#define BOARD_DEBUG_UART_INSTANCE 1U
...
#define BOARD_UART_IRQ LPUART2_IRQn
#define BOARD_UART_IRQ_HANDLER LPUART2_IRQHandler

 

Also I connect my jumpers like below for UART1:

Lukas_Frank_0-1624606832160.png

I think is it possible to use Arduino Interface for physical test. I am happy for this. I have three questions more:

First:

What are the missing points for LPUART2 correct configuration? Is there tool that configure automatically for IMXRT1024 like Code Genaration Tools like IMX CONFIG TOOLS (i.MX-RT1050). If it is not which points should I focus for the correct configuration?

Second:

You said that "you need to disconnect the on board COM port. disconnect J45, J46". I did not exactly understand it. Is there a specific need for this? Is not it possible to do loopback without TTL-USB?

Third:

Will I be able to do loopback just with one jumper cable in Arduino Interface if I configure UART2 correctly in code side?

 

I am a software engineer and I have no background on electronic. So, I am missing some points. Thanks for your patience.

Thanks and Regards,

0 Kudos
Reply
3,826 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank 

   If you use the directly LPUART SDK project, you need to use  J45,J46, it is LPUART1.

   But if you want to use the J17, you need to modify the code, pinmux, you already modified, then the main code, Lpuart 2 interface, just use the polling code at first.

   Now, please check your board, R153,R154 is connected or not?

   Which IDE you are using now?

  Best Regards, 

Kerry

3,816 Views
Lukas_Frank
Senior Contributor I

Hi Dear @kerryzhou,

I am using MCUXpresso v11.3.0.

Q1:What type of check is that ? Should they connected each other? 

Q2:I do not understand why am I checking these pins? Are not they belong to UART2? 

Q3:Should data transmission countinue when I disconnect them? (in register level or any thing else) I am so curious about it. The thing I want to be happen is not continuation of data transmission when I disconnect that pin in loop back mode. But I test it with ossilator it seem like continue data transmission in code side. My receive buffer still is not be empty. 

Q4:Are my configurations for UART2 true?  

Q5:UART1 has pins on J17 (R156 and R162), Why do not we use them?

Lukas_Frank_3-1624618328068.png

Q6: Should my UART loopback example be successful if my UART2 configurations in pooling example be like that and I connect jumpers J17 R153 and R154 to each other?

Thanks and Regards, @kerryzhou 

0 Kudos
Reply
3,774 Views
Lukas_Frank
Senior Contributor I

Hi Dear @kerryzhou,

 

I think I am aware more about UART Loopback anymore. As I understood, Loopback Mode is not a physicall mode it connects rx and tx in the logic gate level. It is like virtual or internally connected mode. I will now try the communicate my UART1 and UART2. So I need true configuration in the same code. I will open an issue now.

 

Thanks and Regards. 

0 Kudos
Reply
3,771 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank 

   Loopback will connect the RX to the TX in the chip internal side, which don't need to add external TTL-USB tool, that's why I confusing why you use the external TTL-USB, but you still use the internal loop back mode, you totally can use the SDK directly without the loopback, and if you want to use UART2, just change pins, and the UART number to UART2 and the interrupt service handler to UART2 is ok.

   BTW, do you test the function for your company? If yes, you'd better use the company email to create the case, that will have higher priority than the 3rd part email, eg gmail.

 

Best Regards,

kerry

3,763 Views
Lukas_Frank
Senior Contributor I

Hi Dear @kerryzhou,

I just learned this. Then, I rethought over the whole process. There was not an explenation in Reference Manual about it and I am new in Embedded World as Software Engineer. Thanks for all your patience

I have two more question:

Q1: UART Write and Read operations prints data to terminal screen (serial port configuration) successfully in SDK Pooling Example. But, there is not printing data to terminal screen when I create a project from scratch despite data communication is successfully occur. Why could be my example is not printing to terminal?

Q2: I am not able to make sense one parameter in IOMUXC_SetPinConfig method in the BOARD_InitPins. It is configValue parameter of IOMUXC_SetPinConfig (sixth-one). I see it assigned as 0x10B0U in the SDK Pooling example. Why? What is the meaning of 0x10B0U. Is there a sheet that explain different combination of this parameter for spesific cases or Is that value constant for all cases?

 

We are core entrepreneurial group for the now and we have no company host mail. I will change my mail address as soon as have a company host.

 

Thanks and Regards,

0 Kudos
Reply