AnsweredAssumed Answered

UART0 initialization problem in KSDK V2.0

Question asked by Daniel Truong on Dec 20, 2016
Latest reply on Dec 27, 2016 by Daniel Truong

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

Outcomes