UART Device Driver Issue on MCUXpresso 10.3.X and SDK 2.5

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

UART Device Driver Issue on MCUXpresso 10.3.X and SDK 2.5

1,166 Views
zhiqunhu
Contributor III

Hello,

I am trying to port a KDS3.X/SDK2.X K64 project to MCUXpresso 10.3.X and SDK 2.5.

I noticed the device drivers have been changed on many peripherals, quite a few device driver APIs used in my project's APP need to be updated to the latest device drivers, mainly API naming.

I have done all that, then find out UART related APIs are not working properly. I am using an UART port for a terminal interface application.

I can use a UART directly with UART_Init(_UART, &config, CLOCK_GetFreq(_UART_CLK_SRC)), and

UART_WriteBlocking(_UART, txbuff, sizeof(txbuff) - 1)

But I cannot use:

DbgConsole_Init((uint8_t )_UART, 115200, DEBUG_CONSOLE_DEVICE_TYPE_UART, CLOCK_GetBusClkFreq());

and printf().

pastedImage_7.png

Shown in above screenshot, if I un-define DEBUG_CONSOLE_UART, the code can be stepped to API function

UART_WriteBlocking(_UART, txbuff, sizeof(txbuff) - 1) without any issue, but I do not want to do that since I have to create my only printf/scanf.

If I define DEBUG_CONSOLE_UART as shown in the above screenshot, when I stepped into line 96:

UART_EnableInterrupts(_UART, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable);

pastedImage_4.png

it will generate a hard fault. I have used BDM to check both base and mask information is correctly pass to the function, and I have no clue why a hard fault will be generated right at the cursor highlight line.

pastedImage_5.png

   

I was thinking that may be related to how the project was created with different configurations, library files. After tried to create a few test projects with different configurations I still have the same issue.

Here is one of my project settings:

1. Project created.

pastedImage_2.png

2. Configuration (I almost tried all of the library files)

pastedImage_1.png

I am wondering if somebody else has seen this problem as well.

0 Kudos
Reply
4 Replies

861 Views
zhiqunhu
Contributor III

Just confirmed with a test code, the first passing parameter is the index number of the UART. 

pastedImage_2.png

But I have to use PRINTF not printf, will work on that.

0 Kudos
Reply

861 Views
zhiqunhu
Contributor III

Hi Daniel,

I just noticed that the first passing parameter in the function DbgConsole_Init() has been changed as Daniel pointed out. I am wondering what is the parameter "instance", and wondering if it is the UART #, but I cannot find any example in SDK_2.5.0_TWR-K64F120M\boards\twrk64f120m\driver_examples\uart, using the function.

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

status_t DbgConsole_Init(uint8_t instance, uint32_t baudRate, serial_port_type_t device, uint32_t clkSrcFreq)

It is kind of inconsistent to update the device driver with the same name but change to different parameters.

Thanks,

Zhiqun

0 Kudos
Reply

861 Views
danielchen
NXP TechSupport
NXP TechSupport

Please also refer to the uart demo.

SDK_2.5.0_TWR-K64F120M\boards\twrk64f120m\driver_examples\uart

Regards

Daniel

0 Kudos
Reply

861 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Zhiqun:

The  reason of the hard fault maybe because the uart clock is not enabled, could you please check with it?

I would suggest you step into the DbgConsole_Init. The implementation of DbgConsole_Init  in SDK2.5 is  totally different from your old sdk. I am assuming you are using SDK 2.2 or 2.3.

The old implementation is :

/* 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)) || \
    (defined(FSL_FEATURE_SOC_IUART_COUNT) && (FSL_FEATURE_SOC_IUART_COUNT > 0))
        case DEBUG_CONSOLE_DEVICE_TYPE_UART:
        case DEBUG_CONSOLE_DEVICE_TYPE_IUART:

........

In SDK 2.5,

/* See fsl_debug_console.h for documentation of this function. */
status_t DbgConsole_Init(uint8_t instance, uint32_t baudRate, serial_port_type_t device, uint32_t clkSrcFreq)
{
    serial_manager_config_t serialConfig;
    status_t status = kStatus_SerialManager_Error;

#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
    serial_port_uart_config_t uartConfig = {
        .instance = instance,
        .clockRate = clkSrcFreq,
        .baudRate = baudRate,
        .parityMode = kSerialManager_UartParityDisabled,
        .stopBitCount = kSerialManager_UartOneStopBit,
        .enableRx = 1,
        .enableTx = 1,
    };
#endif

#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
    serial_port_usb_cdc_config_t usbCdcConfig = {
        .controllerIndex = (serial_port_usb_cdc_controller_index_t)instance,
    };
#endif

.......

The input parameter  is different,

In sdk2.2

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

In sdk 2.5

/* See fsl_debug_console.h for documentation of this function. */
status_t DbgConsole_Init(uint8_t instance, uint32_t baudRate, serial_port_type_t device, uint32_t clkSrcFreq)

I hope it helps

Regards

Daniel

0 Kudos
Reply