Cannot get any input using UART with MQX

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

Cannot get any input using UART with MQX

2,439 Views
freewill
Contributor II

I'm trying to get some charaters from PC using UART but I couldn't. instead I just can see same repeated strings on the serial terminal that I sent out just before. I have tried all the ways that I can but I couldn't find out any solutions.

Tx and  opening ttyb: is working fine because I can see the strings "ttyb opend" from  write(serial_fd,"ttyb opend", 10);

using MQX 3.8.1, Kinetis K10 CPU on 96Mhz core clock.

 

Please help.

settings and code are as below.

 

in user_config.h

#define BSPCFG_ENABLE_TTYB              1

 

in main.c

 if((serial_fd =  fopen("ttyb:",(pointer) ( IO_SERIAL_TRANSLATION)))==NULL){
  printf("ttyb open failed!\n");
 }else{
    write(serial_fd,"ttyb opend", 10);
 }

 while(1)  
 {
  _time_delay(100); 
  if (fstatus( serial_fd )) {
       tmp = fgetc(serial_fd);
       fputc((char)tmp,serial_fd);
  }
 }

 

terminal output

petttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opettty

 

thanks

 

 

 

10 Replies

776 Views
c0170
Senior Contributor III

Hello freewill,

 

Just add my 5 cents here, I tested your code on TWR K40 and it's working. Unfortunately, I do not have any K10 at the moment.

 

Regards,

MartinK

776 Views
DavidS
NXP Employee
NXP Employee

Hi freewill,

Have you updated your equivalent twrk60n512.h (BSP device header file) to have ttyb the default IO Channel?

Reference the "<-- CHANGE to" comments below:

/*
 * Other Serial console options:smileysad:do not forget to enable BSPCFG_ENABLE_TTY define if changed)
 *      "ittyf:"     OSJTAG-COM  interrupt mode
 *      "ttyd:"      TWR-SER     polled mode
 *      "ittyd:"     TWR-SER     interrupt mode
 *      "iodebug:"   IDE debug console
 ** MGCT: <option type="string" maxsize="256" quoted="false" allowempty="false"/>
 */
#ifndef BSP_DEFAULT_IO_CHANNEL
    #if BSPCFG_ENABLE_TTYD     <-- CHANGE to TTYB
        #define BSP_DEFAULT_IO_CHANNEL                    "ttyd:"   <-- CHANGE to ttyb: 
        #define BSP_DEFAULT_IO_CHANNEL_DEFINED
    #else
        #define BSP_DEFAULT_IO_CHANNEL                      NULL
    #endif
#else
    /* undef is for backward compatibility with user_configh.h files which have already had it defined */
    #undef  BSP_DEFAULT_IO_CHANNEL_DEFINED
    #define BSP_DEFAULT_IO_CHANNEL_DEFINED
#endif

 

Regards,

David

776 Views
freewill
Contributor II

Thanks David,

 

yes I already changed that you mentioned but not working.

here is my setting.

 

#ifndef BSP_DEFAULT_IO_CHANNEL
    #if BSPCFG_ENABLE_TTYB
//        #define BSP_DEFAULT_IO_CHANNEL                      "ttya:"    /* OSJTAG-COM   polled mode   */
        #define BSP_DEFAULT_IO_CHANNEL                      "ttyb:"    /* OSJTAG-COM   polled mode   */
        #define BSP_DEFAULT_IO_CHANNEL_DEFINED
    #else
        #define BSP_DEFAULT_IO_CHANNEL                      NULL
    #endif
#endif

 

the UART Tx is working fine but Rx is always not working.

have you any experiece like this problem?

I don't have any ideas to try more.

 

thanks.

0 Kudos

776 Views
DavidS
NXP Employee
NXP Employee

Hi freewill,

Try added following code after your fopen and use your file pointer...not mine :smileywink: :

           _io_set_handle(IO_STDIN, fh_ptr);
           _io_set_handle(IO_STDOUT, fh_ptr);

 

Regards,

David

0 Kudos

776 Views
freewill
Contributor II

Hi David,

 

thank you for your quick reply.

I applied that you provide, but Rx is still not working.

If I remove the write as below, there was no input and output. even if I press keyboard.

//  write(serial_fd,"ttyb opend", 10);

once I add the write setence, it is always  spit out same strings.

 

BR,

freewill

0 Kudos

776 Views
DavidS
NXP Employee
NXP Employee
Hi freewill, Please try using "BSP_DEFAULT_IO_OPEN_MODE" in fopen like I have below: fh_ptr = (pointer)fopen("ttyb:", BSP_DEFAULT_IO_OPEN_MODE); Regards, David
0 Kudos

776 Views
MarkP_
Contributor V

Hi freewill,

have you checked that correct IO-pins are activated in function init_gpio.c:_bsp_serial_io_init.

/* Setup GPIO for UART devices */
switch (dev_num)
{
case 1: << This is for TTYB
            pctl = (PORT_MemMapPtr)PORTC_BASE_PTR;
            if (flags & IO_PERIPHERAL_PIN_MUX_ENABLE)
            {
                /* PTC3 as RX function (Alt.3) + drive strength */
                pctl->PCR[3] = 0 | PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK;
                /* PTC4 as TX function (Alt.3) + drive strength */
                pctl->PCR[4] = 0 | PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK;
            }

...

~Mark

0 Kudos

776 Views
freewill
Contributor II

thanks everybody

 

as I have tried all the ways you suggested, but still I have same problem.

so I am going to write my own UART driver. because I don't have much time.

support from you guys was great and really helpful.

 

thank you very much.

 

Kevin. P

 

 

0 Kudos

776 Views
MarkP_
Contributor V

One more thing: it is better to use interrupt based mode ITTYB:

#define BSPCFG_ENABLE_ITTYB  1

~Mark

0 Kudos

776 Views
Ed_EmbeddedAcce
Contributor II

In general interrupt mode is better as you don't waste time polling in your application.  However if you are primarily transporting data over serial and you have very high throughput polling can be more efficient as you don't have the over head of interrupt processing.