KSDK example "hello world" for MK22FX512VLH12

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

KSDK example "hello world" for MK22FX512VLH12

Jump to solution
1,518 Views
nakulyadur
Contributor III

Hello,

 

I am using KSDK 2.0, SDK_2.0_MK22FX512xxx12 for my µC MK22FX512VLH12. I am using the demo example "hello world" provided and trying to display the "hello world" on the Console (PuTTY) but all I am getting are some junk values on the console.
The example is from TWR-K21F120M but I was told it is compatible with MK22FX512VLH12. I have changed the UART port in the code to use that from MK22FX512VLH12. I am using PORT E with PCR0 and PCR1. I have set both the Baudrates to 115200 and no parity, 1 stop bit. I am using P&E Multilink Universal for debugging. Since I am getting junk values on the console, I think there is a UART connection between the µC and the console. Can someone please help me with this? thanks,

Nakul

Labels (1)
1 Solution
974 Views
DavidS
NXP Employee
NXP Employee

Hi Nakul,

In the hello_world_twrk21f120m project the hello_world.c has following in main():

    /* Init board hardware. */

    BOARD_InitPins();

    BOARD_BootClockRUN();

    BOARD_InitDebugConsole();

In the BOARD_InitPins() in pin_mux.c you need to change the UART pin configuration from default UART5 (PTD8/9) to UART1 (PTE0/1):

void BOARD_InitPins(void)

{

#if 1 //DES 1=test changing default UART, 0=default code

    /* Initialize UART1 pins below */

    /* Ungate the port clock */

    CLOCK_EnableClock(kCLOCK_PortE);

    /* Affects PORTD_PCR8 register */

    PORT_SetPinMux(PORTE, 0u, kPORT_MuxAlt3);

    /* Affects PORTD_PCR9 register */

    PORT_SetPinMux(PORTE, 1u, kPORT_MuxAlt3);

#else

    /* Initialize UART1 pins below */

    /* Ungate the port clock */

    CLOCK_EnableClock(kCLOCK_PortD);

    /* Affects PORTD_PCR8 register */

    PORT_SetPinMux(PORTD, 8u, kPORT_MuxAlt3);

    /* Affects PORTD_PCR9 register */

    PORT_SetPinMux(PORTD, 9u, kPORT_MuxAlt3);

#endif   

}

Then in board.h you need to changes the clock source as follows:

#define BOARD_USE_UART

#if 1 //DES 1=test changing default UART, 0=default code

#define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_UART

#define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART1

#define BOARD_DEBUG_UART_CLKSRC kCLOCK_CoreSysClk //DES this MARCO not used but update to not confuse user

#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

#else

#define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_UART

#define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART5

#define BOARD_DEBUG_UART_CLKSRC kCLOCK_BusClk

#define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetBusClkFreq()

#define BOARD_UART_IRQ UART5_RX_TX_IRQn

#define BOARD_UART_IRQ_HANDLER UART5_RX_TX_IRQHandler

#endif

I do not have a TWR-K21F120M to test this with but I believe the above should work.

Hope this helps.

Regards,

David

View solution in original post

5 Replies
975 Views
DavidS
NXP Employee
NXP Employee

Hi Nakul,

In the hello_world_twrk21f120m project the hello_world.c has following in main():

    /* Init board hardware. */

    BOARD_InitPins();

    BOARD_BootClockRUN();

    BOARD_InitDebugConsole();

In the BOARD_InitPins() in pin_mux.c you need to change the UART pin configuration from default UART5 (PTD8/9) to UART1 (PTE0/1):

void BOARD_InitPins(void)

{

#if 1 //DES 1=test changing default UART, 0=default code

    /* Initialize UART1 pins below */

    /* Ungate the port clock */

    CLOCK_EnableClock(kCLOCK_PortE);

    /* Affects PORTD_PCR8 register */

    PORT_SetPinMux(PORTE, 0u, kPORT_MuxAlt3);

    /* Affects PORTD_PCR9 register */

    PORT_SetPinMux(PORTE, 1u, kPORT_MuxAlt3);

#else

    /* Initialize UART1 pins below */

    /* Ungate the port clock */

    CLOCK_EnableClock(kCLOCK_PortD);

    /* Affects PORTD_PCR8 register */

    PORT_SetPinMux(PORTD, 8u, kPORT_MuxAlt3);

    /* Affects PORTD_PCR9 register */

    PORT_SetPinMux(PORTD, 9u, kPORT_MuxAlt3);

#endif   

}

Then in board.h you need to changes the clock source as follows:

#define BOARD_USE_UART

#if 1 //DES 1=test changing default UART, 0=default code

#define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_UART

#define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART1

#define BOARD_DEBUG_UART_CLKSRC kCLOCK_CoreSysClk //DES this MARCO not used but update to not confuse user

#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

#else

#define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_UART

#define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART5

#define BOARD_DEBUG_UART_CLKSRC kCLOCK_BusClk

#define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetBusClkFreq()

#define BOARD_UART_IRQ UART5_RX_TX_IRQn

#define BOARD_UART_IRQ_HANDLER UART5_RX_TX_IRQHandler

#endif

I do not have a TWR-K21F120M to test this with but I believe the above should work.

Hope this helps.

Regards,

David

974 Views
nakulyadur
Contributor III

Hi David,

This works perfect. Thanks a lot.

regards,
Nakul

0 Kudos
Reply
974 Views
DavidS
NXP Employee
NXP Employee

Hi Nakul,

I believe you are seeing correct results for the following reason.

The TWR-K21F120M tower board is setup to use UART5 for the hello_world example.

For your device you have setup to use UART1.

If you look at the reference manual chapter 5 Clock Distribution in Table 5-2 (near bottom of table) the UART0 and UART1 use the System clock as it clock source and all remaining UART's use the Bus clock (which typically is 1/2 the System/Core clock).

When configuring the UART baud this fact must be taken into consideration.

Regards,

David

0 Kudos
Reply
974 Views
nakulyadur
Contributor III

Hi David,

Thank you so much.

Can you please tell me how do I change the UART1 setting of the MK22FX512VLH12 so that I can use the correct baud rate? Thanks.

regards,

Nakul

0 Kudos
Reply
974 Views
nakulyadur
Contributor III

I was able to display on the console when I set the console baudrate at double the baudrate of the µC (

MK22FX512VLH12)

. Maybe I need to change the system clock on the µC. Can someone help me with setting the system clock as I am not able to find it on KSDK 2.0. When I am using the Processor Expert, it's easier to set the processor clock. Thanks,
Nakul

0 Kudos
Reply