K60 UART1 Port

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

K60 UART1 Port

1,786 Views
SGraessle
Contributor I

Hello all, I am currently working on a small proof-of-concept project involving the Kinetis K60 + TWR System. I am working on routing UART1 (or any UART port's) RX/TX to the RS 232 port on the TWR-SER board. I have identified several of the control registers that need to be set to correctly communicate using the UART port but I am not sure where in the code would I look to connect it to the RS 232 port.

 

I am only slightly modifying the ADC_Demo code that is provided with the Codewarrior IDE. Any help would be greatly appreciated. I have attached a copy of the code for your viewing. 

 

Thanks!

 

-Stephen

 

 

0 Kudos
4 Replies

674 Views
leslieyang0509
Contributor II

Platrform: TWR-K60N512

Example: enable UART0

set port B 16 as UART0 Rx (demo board, J3 pin 13)

set port B 17 as UART0 Tx (demo board, J3 pin 14)

 

Step 1, Change port setting 

Code Warrior Porjects\bsp_twrk60n512\twrk60n512 BSP Files\init_gpio.c

modify function _bsp_serial_io_init()

 

 

 

    switch (dev_num)    {        case 0:#if 1          pctl = (PORT_MemMapPtr)PORTB_BASE_PTR;          if (flags & IO_PERIPHERAL_PIN_MUX_ENABLE)          {              /* PTB16 as RX function (Alt.3) + drive strength */              pctl->PCR[16] = 0 | PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK;              /* PTB17 as TX function (Alt.3) + drive strength */              pctl->PCR[17] = 0 | PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK;          }          if (flags & IO_PERIPHERAL_PIN_MUX_DISABLE)          {              /* PTB16 default */              pctl->PCR[16] = 0;              /* PTB17 default */              pctl->PCR[17] = 0;          }#else            pctl = (PORT_MemMapPtr)PORTD_BASE_PTR;            if (flags & IO_PERIPHERAL_PIN_MUX_ENABLE)            {                /* PTD6 as RX function (Alt.3) + drive strength */                pctl->PCR[6] = 0 | PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK;                /* PTD7 as TX function (Alt.3) + drive strength */                pctl->PCR[7] = 0 | PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK;            }            if (flags & IO_PERIPHERAL_PIN_MUX_DISABLE)            {                /* PTD6 default */                pctl->PCR[6] = 0;                /* PTD7 default */                pctl->PCR[7] = 0;            }#endif

Step 2

change BSPCFG_ENABLE_TTYA from 0 to 1

Code Warrior Porjects\bsp_twrk60n512\twrk60n512 User Config\user_config.h

 

#ifndef __user_config_h__#define __user_config_h__/* mandatory CPU identification */#define MQX_CPU                 PSP_CPU_MK60DN512Z/* Silicon version number */#define MK60_REV_1_0             1/*** BSP settings - for defaults see mqx\source\bsp\<board_name>\<board_name>.h*/#define BSPCFG_ENABLE_TTYA       1  // change from 0 to 1#define BSPCFG_ENABLE_ITTYA      0

 

UART0 setting are set at _bsp_sci0_init variable

default baudrate is 115200

const KUART_INIT_STRUCT _bsp_sci0_init ( @ init_sci.c)

 

Step 3

rebuild BSP and PSP

 

Step 4

Implement your own UART module

UART_Module.h

#ifndef __UART_MODULE_H__#define __UART_MODULE_H__#define UART_COUNT 5//******************************************************************************////******************************************************************************void UART_Module_init(void);void UART0_printf(char *);#endif /* __UART_MODULE_H__ */

 

 

UART_Module.c

#include "UART_Module.h"#include <mqx.h>#include <bsp.h>#define DEV_UART0 "ttya:" #define UART0_IDX 0#define UART1_IDX 1#define UART2_IDX 2#define UART3_IDX 3#define UART4_IDX 4MQX_FILE_PTR UART_fp[UART_COUNT] = {0, 0, 0, 0, 0};//******************************************************************************////******************************************************************************void UART_Module_init(void){  //----------------------------------------------------------------  // open UART0  //----------------------------------------------------------------  printf("Opening UART device ...");  UART_fp[UART0_IDX] = fopen(DEV_UART0, NULL);  if(UART_fp[UART0_IDX] != NULL)  {        printf("fopen "DEV_UART0" done\r\n");  }  else  {        printf("fopen "DEV_UART0" failed\r\n");    _task_block();  }}//******************************************************************************////******************************************************************************void UART_printf(char *mData, uint_32 mIndex){  MQX_FILE_PTR fp = 0;  uint32_t len;      if(UART_COUNT <= mIndex)  {    return;  }    fp = UART_fp[mIndex];  len = strlen(mData);  if (write(fp, mData, len))  {      }  }//******************************************************************************////******************************************************************************void UART0_printf(char *mData){  UART_printf(mData, UART0_IDX);}

 

Step 5

call UART_Module_init();

call UART0_printf("UART0 test\r\n");

 

Step 6

build project

 

Step 7

Download code and debug

 

Good lock!

 

Leslie

0 Kudos

674 Views
Abhitechmania
Contributor IV

I didnt look at the code but I suggest you to look at KINETIS512_SC (Kinetis family example projects). Look into the folder  KINETIS512_SC\src\drivers\uart. The two files concerned are uart.c and uart.h. 

0 Kudos

674 Views
SGraessle
Contributor I

Thank you for that suggestions. However, I could not find the answers I am looking for.

 

Essentially, the following code is from the K60_tower.h file

/*
* Serial Port Info
*/

/*
* Select the serial port that is being used below. Only one of the
* options should be uncommented at any time.
*/
//#define SERIAL_CARD // this is the default option, so it is uncommented
#define OSJTAG // use this option for serial port over the OS-JTAG circuit

#if (defined(SERIAL_CARD))
#define TERM_PORT UART3_BASE_PTR
#define TERMINAL_BAUD 115200
#undef HW_FLOW_CONTROL
#elif (defined(OSJTAG))
#define TERM_PORT UART5_BASE_PTR
#define TERMINAL_BAUD 115200
#undef HW_FLOW_CONTROL
#else
#error "No valid serial port defined"
#endif

 

UART5 is connected to the USB cable on the K60 (when I am using OSJTAG), I want to connect a UART instead to the RS-232 port on the TWR-SER card. I can't find how/where UART5 is connected to the USB to figure out how to route a different UART to the serial port I want.

 

Help/Thoughts?

0 Kudos

674 Views
masahiroNZ
Contributor I

Hello. The setup is done in "void start(void)" in start.c and sysinit() is the actual function to set UART up for OSJTAG. start is the start up routine, which is done before main().

 

I am using TWR-K53N but I think K60 is the same. This kind of setup is written in "Kinetis Peripheral Module Quick Reference". I am pretty new to Kinetis so currently studying about Kinetis with this document. :smileyhappy:

0 Kudos