What configuration needs to change to use a LPUART for the debug console?

cancel
Showing results for 
Search instead for 
Did you mean: 

What configuration needs to change to use a LPUART for the debug console?

Jump to solution
619 Views
gorakk
Contributor IV

We have a custom board but I'm using the FRDM-K22F to figure out this issue.

I import the SDK led_blinky sample project and I select "UART" for the SDK Debug Console:

pastedImage_1.png

And I select "Redirect printf/scanf to UART":

pastedImage_3.png

The default configuration uses UART1 but for various reasons we need to use LPUART0 on our custom board.

The imported board.c file has the call to DbgConsole_Init():

/* Initialize debug console. */
void BOARD_InitDebugConsole(void)
{
 uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ;
 DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);
}‍‍‍‍‍‍

The defines used in board.c are in board.h:

/*! @brief The UART to use for debug messages. */
#define BOARD_USE_UART
#define BOARD_DEBUG_UART_TYPE kSerialPort_Uart
#define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART1
#define BOARD_DEBUG_UART_INSTANCE 1U
#define BOARD_DEBUG_UART_CLKSRC SYS_CLK
#define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetCoreSysClkFreq()
#define BOARD_UART_IRQ UART1_RX_TX_IRQn
#define BOARD_UART_IRQ_HANDLER UART1_RX_TX_IRQHandler

#ifndef BOARD_DEBUG_UART_BAUDRATE
#define BOARD_DEBUG_UART_BAUDRATE 115200
#endif /* BOARD_DEBUG_UART_BAUDRATE */‍‍‍‍‍‍‍‍‍‍‍‍

I'm not seeing a way to specify LPUART0 instead of UART1.

The BOARD_DEBUG_UART_BASEADDR define looks likely but it's not actually used in the code.

Has anyone used an LPUART instead of a UART for the debug console?

MCUXpresso IDE v11.0.0

SDK 2.6.0

0 Kudos
1 Solution
427 Views
gorakk
Contributor IV

Jing,

Here is what I found:

It looks like the debug console is using the serial manager.  I dug around and found that there is a "uart_adapter.c".  There is an option in the SDK Component Manager for uart_adapter but nothing that I could find for an lpuart adapter.

pastedImage_2.png

So I googled "lpuart_adapter.c" and found a copy on the internet.  I copied it as shown and excluded uart_adapter.c from the project:

pastedImage_1.png

I modified the defines and removed the ones that are not being used:

/*! @brief The UART to use for debug messages. */
#define BOARD_DEBUG_UART_TYPE kSerialPort_Uart
#define BOARD_DEBUG_UART_INSTANCE 0U
#define BOARD_DEBUG_UART_CLK_FREQ 8000000UL

#ifndef BOARD_DEBUG_UART_BAUDRATE
#define BOARD_DEBUG_UART_BAUDRATE 115200
#endif /* BOARD_DEBUG_UART_BAUDRATE */

I then used the pin configuration tool to set the LPUART0 TX and RX pins.

Rebuilt the project, loaded it into the FRDM board and it works - debug information is being output on LPUART0  Smiley Happy 

Allen

p.s. - I searched the SDK files manually and there was no copy of the lpuart_adapter.c file.

View solution in original post

0 Kudos
3 Replies
427 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi,

It seems there isn't such an example. But it's not a hard work. UART and LPUART has almost same function name.

1. change pin config

2. copy lpuart driver to project.

3. modify the define

4. change the function name in fsl_debug_console.c

...

Regards,

Jing

0 Kudos
428 Views
gorakk
Contributor IV

Jing,

Here is what I found:

It looks like the debug console is using the serial manager.  I dug around and found that there is a "uart_adapter.c".  There is an option in the SDK Component Manager for uart_adapter but nothing that I could find for an lpuart adapter.

pastedImage_2.png

So I googled "lpuart_adapter.c" and found a copy on the internet.  I copied it as shown and excluded uart_adapter.c from the project:

pastedImage_1.png

I modified the defines and removed the ones that are not being used:

/*! @brief The UART to use for debug messages. */
#define BOARD_DEBUG_UART_TYPE kSerialPort_Uart
#define BOARD_DEBUG_UART_INSTANCE 0U
#define BOARD_DEBUG_UART_CLK_FREQ 8000000UL

#ifndef BOARD_DEBUG_UART_BAUDRATE
#define BOARD_DEBUG_UART_BAUDRATE 115200
#endif /* BOARD_DEBUG_UART_BAUDRATE */

I then used the pin configuration tool to set the LPUART0 TX and RX pins.

Rebuilt the project, loaded it into the FRDM board and it works - debug information is being output on LPUART0  Smiley Happy 

Allen

p.s. - I searched the SDK files manually and there was no copy of the lpuart_adapter.c file.

View solution in original post

0 Kudos
427 Views
gorakk
Contributor IV

Jing,

Thanks for the reply!  I'll give this a try and respond with the results.

Allen

0 Kudos