Debug console on USBCDC

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

Debug console on USBCDC

1,445 Views
biafra
Senior Contributor I


Hi everyone,

 

I'm using KDS v 3.2.0 with all updates, KSDK v 2.0 and TWRK65F180M.

I'm trying to use USC CDC as debug console, but I'm in the dark.

 

It seems that I have to call DbgConsole_Init with DEBUG_CONSOLE_DEVICE_TYPE_USBCDC value as device parameter, but I cannot find which value the other parameters have to be. Moreover in the DbgConsole_Init function there is not the case statement belonging to DEBUG_CONSOLE_DEVICE_TYPE_USBCDC device parameter value and therefore the kStatus_InvalidArgument value is returned.

 

I've found a tutorial on this argument but it is referred to KSDK 1.3. Is there any examples for KSDK 2.0?

 

Many thanks

Biafra

Labels (1)
8 Replies

828 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Francesco,

If you use the DEBUG_CONSOLE_DEVICE_TYPE_USBCDC option, have you checked the api function DbgConsole_Init(), does it include the code to initialize USB?

We have the code to use the USB port as USB CDC function so that the data can be transmitted/received from USB of K66 directly instead of via K20 .

There is example code of USBCDC, pls refer to the example:

C:\Freescale\SDK2.0_K64F\boards\frdmk64f\usb_examples\usb_device_cdc_vcom

you have to port the code yourself.

BR

Xiangjun Rong

828 Views
biafra
Senior Contributor I

Hi Xiangjun,

Many thanks for your answer.

I've checked the DbgConsole_Init() function, it does not include the code to initialize USB.

I'm just porting the code to my application.

Many thanks

Biafra

828 Views
therealfreegeek
Contributor IV

Debug console on USBCDC - Is a really common request, it would be great to see NXP have this as a standard example for all devices.

Please add this to the to do list for the team that develops the examples.

828 Views
biafra
Senior Contributor I

Hi everyone,

No one can help?

Many thanks

Biafra

828 Views
biafra
Senior Contributor I

Many thanks Xiangjun for your answer,

The debug console mechanism  for TWR-K65F180M was clear for me. I forgot to mention that now I'm working on TWR-K65F180M, but soon I will work on a custom board based on the same MK65FN2M0VMI18 device. On my custom board there is not available any serial port for debug console, it's planned to use the USBCDC as debug console. Now I'm trying to test this mechanism on TWR-K65F180M witing for my custom board.

Any other suggestion?

Many thanks

Biafra

828 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Regarding your question that you want to communicate with PC, I think there sre several methods.

1)If your PC has RS232 port, it is okay, on your PCB, you can use a UART transceiver such as Max3245 and RS232 connector.

2)If your PC does not have RS232 port, and your PCB has Rs232 port, you can order a USB/RS232 converter.

3)The K65 has USB module, we have the software in SDK to use the USB as USB CDC.

Hope it can help you.

BR

Xiangjun Rong

828 Views
biafra
Senior Contributor I

Hi Xiangjun,

The solution 3 is the one I'm trying to implement, but I'm having trouble in this task.

I don't know if I have to modify the DbgConsole_Init function to handle the DEBUG_CONSOLE_DEVICE_TYPE_USBCDC value as device parameter or some different mechanism.

Many thanks

Biafra

828 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Francesco,

I think you misunderstand the Debug console mechanism, for TWR-K65F10M board, there are two processor, one is the K65F, another is K20, the USB port of K20 communicates with PC so that you can debug and print, and K20 communicates with K65 via JTAG so that you can debug K65, while the K20 communicate with K65 via UART so taht the K65 can printf() to PC.

In conclusion, the K65 use UART to communicate with K20, K20 use USB to communicate with PC so that the K65 can print something. The USB CDC protocl is implemented on K20 instead of K65, K65 just uses UART driver to communicate with K20, so there is not application code about USB CDC protocol on K65 side.

Hope it can help you.

BR

Xiangjun Rong

/* See fsl_debug_console.h for documentation of this function. */

status_t DbgConsole_Init(uint32_t baseAddr, uint32_t baudRate, uint8_t device, uint32_t clkSrcFreq)

{

    if (s_debugConsole.type != DEBUG_CONSOLE_DEVICE_TYPE_NONE)

    {

        return kStatus_Fail;

    }

    /* Set debug console to initialized to avoid duplicated initialized operation. */

    s_debugConsole.type = device;

    /* Switch between different device. */

    switch (device)

    {

#if defined(FSL_FEATURE_SOC_UART_COUNT) && (FSL_FEATURE_SOC_UART_COUNT > 0)

        case DEBUG_CONSOLE_DEVICE_TYPE_UART:

        {

            uart_config_t uart_config;

            s_debugConsole.base = (UART_Type *)baseAddr;

            UART_GetDefaultConfig(&uart_config);

            uart_config.baudRate_Bps = baudRate;

            /* Enable clock and initial UART module follow user configure structure. */

            UART_Init(s_debugConsole.base, &uart_config, clkSrcFreq);

            UART_EnableTx(s_debugConsole.base, true);

            UART_EnableRx(s_debugConsole.base, true);

            /* Set the function pointer for send and receive for this kind of device. */

            s_debugConsole.ops.tx_union.UART_PutChar = UART_WriteBlocking;

            s_debugConsole.ops.rx_union.UART_GetChar = UART_ReadBlocking;

        }

        break;

#endif /* FSL_FEATURE_SOC_UART_COUNT */

#if defined(FSL_FEATURE_SOC_LPSCI_COUNT) && (FSL_FEATURE_SOC_LPSCI_COUNT > 0)

        case DEBUG_CONSOLE_DEVICE_TYPE_LPSCI:

        {

            lpsci_config_t lpsci_config;

            s_debugConsole.base = (UART0_Type *)baseAddr;

            LPSCI_GetDefaultConfig(&lpsci_config);

            lpsci_config.baudRate_Bps = baudRate;

            /* Enable clock and initial UART module follow user configure structure. */

            LPSCI_Init(s_debugConsole.base, &lpsci_config, clkSrcFreq);

            LPSCI_EnableTx(s_debugConsole.base, true);

            LPSCI_EnableRx(s_debugConsole.base, true);

            /* Set the function pointer for send and receive for this kind of device. */

            s_debugConsole.ops.tx_union.LPSCI_PutChar = LPSCI_WriteBlocking;

            s_debugConsole.ops.rx_union.LPSCI_GetChar = LPSCI_ReadBlocking;

        }

        break;

#endif /* FSL_FEATURE_SOC_LPSCI_COUNT */

#if defined(FSL_FEATURE_SOC_LPUART_COUNT) && (FSL_FEATURE_SOC_LPUART_COUNT > 0)

        case DEBUG_CONSOLE_DEVICE_TYPE_LPUART:

        {

            lpuart_config_t lpuart_config;

            s_debugConsole.base = (LPUART_Type *)baseAddr;

            LPUART_GetDefaultConfig(&lpuart_config);

            lpuart_config.baudRate_Bps = baudRate;

            /* Enable clock and initial UART module follow user configure structure. */

            LPUART_Init(s_debugConsole.base, &lpuart_config, clkSrcFreq);

            LPUART_EnableTx(s_debugConsole.base, true);

            LPUART_EnableRx(s_debugConsole.base, true);

            /* Set the function pointer for send and receive for this kind of device. */

            s_debugConsole.ops.tx_union.LPUART_PutChar = LPUART_WriteBlocking;

            s_debugConsole.ops.rx_union.LPUART_GetChar = LPUART_ReadBlocking;

        }

        break;

#endif  /* FSL_FEATURE_SOC_LPUART_COUNT */

        /* If new device is required as the low level device for debug console,

         * Add the case branch and add the preprocessor macro to judge whether

         * this kind of device exist in this SOC. */

        default:

            /* Device identified is invalid, return invalid device error code. */

            return kStatus_InvalidArgument;

    }

    return kStatus_Success;

}