UART0 initialization problem in KSDK V2.0

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

UART0 initialization problem in KSDK V2.0

956 Views
danieltruong
Contributor IV

Hi,

I'm using KDS 3.2.0 along with KSDK v2.0 and I'm having a trouble with programming the UART0 channel. The microcontroller is MKL26Z256VLL4.

 

Unlike the UART1 and UART2 channels which I don't have any problem accessing them via API library functions (KSDK 2.0), I just can't use the same library with UART0 because the base address is defined at 0 instead of 0x4006A000. As a result, I got a crash when the following API function was called:

 

static UART_Type *const s_uartBases[] = UART_BASE_PTRS;

uint32_t UART_GetInstance(UART_Type *base)
{
   uint32_t instance;
   uint32_t uartArrayCount = (sizeof(s_uartBases) / sizeof(s_uartBases[0]));

   /* Find the instance index from base address mappings. */
   for (instance = 0; instance < uartArrayCount; instance++)
   {
      if (s_uartBases[instance] == base)
      {
         break;
      }
   }

assert(instance < uartArrayCount);

return instance;
}

 

When called, "base" was passed in as 0x4006A000. In the for loop, the if statement expects a match at the 1st "instance" value . However, when instance=0, s_uartBases[0] = 0 instead of 0x4006A000 (see UART_BASE_PTRS definition below). So there was no match.

 

Here is an excerpt from the MKL26Z4.h file:

 

#define UART0_BASE (0x4006A000u)
#define UART0 ((UART0_Type *)UART0_BASE)

#define UART1_BASE (0x4006B000u)
#define UART1 ((UART_Type *)UART1_BASE)
#define UART2_BASE (0x4006C000u)
#define UART2 ((UART_Type *)UART2_BASE)

 

#define UART_BASE_ADDRS { 0u, UART1_BASE, UART2_BASE }
#define UART_BASE_PTRS { (UART_Type *)0u, UART1, UART2 }

 

 

I guess my project was still somehow set up with a FRDM-XXX board in mind (which reserves UART0 for a dedicated OpenSDA channel as a debug console). Thus the base address was re-routed to 0, but I'm not so sure if this is the case. 

 

Can someone please help me shed some lights on this problem? 

 

Thanks,

Daniel

Labels (1)
0 Kudos
Reply
4 Replies

655 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

The KL26 has three UART modules:LPUART0, LPUART1 and UART2, in SDK2.0, there is lpuart example and uart example and correspondind drivers. So the SDK2.0 see lpuart and uart as two modules.

Hope it can help you

BR

XiangJun Rong

0 Kudos
Reply

655 Views
danieltruong
Contributor IV

Hi Xiangjun,

I found there are no "lpuart" drivers in the driver directory of my project (fsl_xxx.c, fsl_xxx.h). There are fsl_uart.c and fsl_uart.h as far as uart-related names. Is it possible that I don't have the right SDK ? 

I'm pretty sure I downloaded SDK2.0 with the configuration set for the microcontroller MKL26Z256xxx as follows:

Capture.PNG

I followed this link to downloaded and configured my SDK:

Software Development Kit for Kinetis MCUs|NXP 

and downloaded the 2nd item (Kinetis SDK Builder REV 2 & 1.3) in the Software Development Kit section. 

If this is not the right one or there is something wrong in my setup, can you help me to correct it?

Thanks so much.

--Daniel

0 Kudos
Reply

655 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I attach the SDK driver for KL27, you can see the fsl_lpuart.c, hope it can help you

BR

XiangJun Rong

pastedImage_1.png

0 Kudos
Reply

655 Views
danieltruong
Contributor IV

Hi Xiangjun,

The KL27 may have the "lpuart" function, but it's not the same name in KL26. In KL26 family, it's named "lpsci".

Anyway, thank you for your effort of trying to help me in this issue.

Have a nice day!

-Daniel

0 Kudos
Reply