MQX RTOS UART Communication

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

MQX RTOS UART Communication

Jump to solution
8,564 Views
Lakshmi
Contributor II

Hi,

 

I am trying UART communication with MQX RTOS.

 

There is a structure in mcf52x.h

 

 

/*
** MCF52XX_UART_STRUCT
** This structure defines what one uart register look like
*/
typedef union mcf52xx_uart_struct
{
   struct  {
      uchar UMR;             // UART mode register
      uchar filler1[3];
      uchar USR;             // UART status register
      uchar filler2[3];
      uchar filler4a;            
      uchar filler4[3];
      uchar URB;             // (Read) UART Receive Buffer
      uchar filler5[3];
      uchar UIPCR;           // (Read) UART Input Port Change Register
      uchar filler6[3];
      uchar UISR;            // (Read) UART Interrupt Status Register
      uchar filler7[3];
      uchar filler9a;           
      uchar filler9[3];
      uchar filler10a;           
      uchar filler10[3];
      uchar filler11[0x0234 - 0x021C - 3 - 1];
      uchar UIP;             // (Read) UART Input Port Register
      uchar filler12[3];
      uchar filler13a;           
      uchar filler13[3];
      uchar filler14a;     // (Write) UART Output Port Bit Reset Command Register
      uchar filler14[3];
   } READ;
   struct  {
      uchar UMR;             // UART mode register
      uchar filler1[3];
      uchar UCSR;             // UART status register
      uchar filler2[3];
      uchar UCR;             // (Write) UART Command Register
      uchar filler4[3];
      uchar UTB;             //  (Write) UART Transmit Buffer
      uchar filler5[3];
      uchar UACR;            //  (Write) UART Auxiliary Control Register
      uchar filler6[3];
      uchar UIMR;            // (Write) UART Interrupt Mask Register
      uchar filler7[3];
      uchar UBG1;            // (Write) UART Baud Rate Generator Register 1
      uchar filler9[3];
      uchar UBG2;            // (Write) UART Baud Rate Generator Register 2
      uchar filler10[3];
      uchar filler11[0x0234 - 0x021C - 3 - 1];
      uchar filler12a;            
      uchar filler12[3];
      uchar UOP1;            // (Write) UART Output Port Bit Set Command Register 0
      uchar filler13[3];
      uchar UIP0;             // (Write) UART Output Port Bit Reset Command Register
   } WRITE;
} MCF52XX_UART_STRUCT, _PTR_ MCF52XX_UART_STRUCT_PTR;

 

 

For the above structure, I created the following instance,

 

 

volatile MCF52XX_UART_STRUCT _PTR_ uart_ptr = (MCF52XX_UART_STRUCT _PTR_)BSP_IPSBAR;

 

 

Is the above LOC correct? is this the way to access UART registers?

 

But I am NOT getting the correct value of registers with the above address. For example, if I have to see the value of USR,

usr = uart_ptr->READ.USR;

 this isn't giving me the correct value.

 

Can anyone please correct me?

 

I am currently working on MCF52233 Demo board.

 

Thanks

 

1 Solution
2,899 Views
DavidS
NXP Employee
NXP Employee

Hi Lakshmi,

I found a couple of coding errors.  Look for //DES in the code for the updates.  I think you'll now be running OK.

Also not that the M52233DEMO board had serveral Revisions (C/D/F) that had slightly different pins used for switches (and maybe LEDs....cannot totally recall).  So if switch or button not working as expected, check respective schematic.

I tested this on REV C M52233DEMO.  Marking on the bottom of board.

Regards,

David

View solution in original post

0 Kudos
Reply
14 Replies
2,899 Views
DavidS
NXP Employee
NXP Employee

Hi Lakshmi,

Two ways that I tried on my M52259EVB to read the UART status register.

 

#if 0
   VMCF5225_STRUCT_PTR vuart;  //DES-test
   MCF52XX_UART_STRUCT_PTR uart_ptr;

   vuart = (&((VMCF5225_STRUCT_PTR)_PSP_GET_IPSBAR())->UART[dev_num]);
   uart_ptr = (MCF52XX_UART_STRUCT_PTR)vuart;
   UART_USR = uart_ptr->READ.USR;
#else  
   MCF52XX_UART_STRUCT_PTR vuart;
  
   vuart = (MCF52XX_UART_STRUCT_PTR)(&((VMCF5225_STRUCT_PTR)_PSP_GET_IPSBAR())->UART[dev_num]);
   UART_USR = vuart->READ.USR;
#endif

 

Regards,

David

0 Kudos
Reply
2,899 Views
Lakshmi
Contributor II

Hi DavidS

 

Please find the source code attached, where I am trying UART0 interrupt.

 

I believe that using below definitions, all the interrupt settings related to UART0 are enabled

 

 

#define BSPCFG_ENABLE_TTYA   0#define BSPCFG_ENABLE_ITTYA      1

 

But still I am unable to see the interrupt getting triggered on UART0.

 

I am currently using MCF52233 demo board.

 

Please chack the code attached & correct me if I am wrong

 

Thanks

 

 

 

0 Kudos
Reply
2,899 Views
DavidS
NXP Employee
NXP Employee

Hi Lakshmi,

Looking at your code it appears that you are trying to setup the UART with your own ISR.  Is that correct?  If yes, then you do not want to enable the BSP to initialize the UART.  In essence you are causing contention with your code base and FSLMQX.

 

I'd recommend letting the RTOS configure and setup the UART for ISR mode.  I just ran a test on M52233DEMO using the Freescale MQX 3.5\mqx\examples\io\cwcf71\io_m52233demo.mcp project.  I've attached the modified main.c and user_config.h files.  Make sure to re-compile the respective build_libs.mcp for this project.

 

Instructions I buried in the main.c printfs are:

   printf("This is printed to the default UART device in interrupt mode.\n");
   printf("Please set a breakpoint in the UART ISR to see it happen\n");
   printf("Assuming breakpoint in UART ISR then you can also look at the IPRL0 to see interrupt flag set\n");
   printf("Function _mcf52xx_uart_serial_int_isr() in file serl_int_mcf52xx.c in following path:\n");
   printf("Freescale\\Freescale MQX3.5\\mqx\\source\\io\\serial\\int\n");

Regards,

David

0 Kudos
Reply
2,899 Views
Lakshmi
Contributor II

Hi David,

 

Thank you for your inputs.

 

A. I am unable to insert break point in the ISR you mentioned "_mcf52xx_uart_serial_int_isr()"

 

B. This is NOT what I am looking for, I need an interrupt to be triggered when a character is ready to receive in UART receive register.

 

C. And I want to insert breakpoint in UART ISR routine within my main() function & check for character received.

 

 

void uart0_isr(pointer dummy){ /* Wait until character has been received */    while (uart_ptr->READ.USR & MCF52XX_UART_USR_RXRDY)    {     uart0_char = uart_ptr->READ.URB;    }}

 

Is the following line required to install or enable UART0 ISR?

 

 

 

if(_int_install_isr(MCF5223_INT_UART0, uart0_isr,NULL) == NULL) {  printf("Could NOT install MQX UART0 ISR\n"); }

 

 

 

0 Kudos
Reply
2,899 Views
DavidS
NXP Employee
NXP Employee

Hi Lakshmi,

Ok...you are trying to create your own UART ISR routine and I believe that it is conflicting with the RTOS/BSP configuration.

If you really want to create your own code, disable the UARTs in the user_config.h by setting the #define BSPCFG_ENABLE_TTYA 0.

But I would strongly suggest trying to use the RTOS and its features to do the work for you.

The attahced code (Copy of main_fstatus.c) is demonstrating the RTOS approach.  It also uses fstatus() to see if a character is waiting.

Let me backup a bit.....when the UARTs are configured into Interrupt mode, there is a 64 byte recieve and transmit queue generated.  What this allows to happen very efficiently is for the UART ISR to grab a received character and place it in the UART receive queue.  This way if you code is off doing other stuff, it get interrupted, character gets stored (or multiple characters).

When you want to get a charater, you can use the fstatus() to see if one is waiting.  Or you can do a read() and if character is present, you get it back right away.  If no character present, the read() will block until one comes available.

I hope this helps.

Regards,

David

0 Kudos
Reply
2,899 Views
Lakshmi
Contributor II

Hi David,

 

I tried the code that you have attached "Copy of main_fstatus.c 5 KB",

 

I am getting the error "cannot open file: ittya" in my Hyper Terminal

 

I have configured in user_config.h as follows

 

#define BSPCFG_ENABLE_TTYA  0
#define BSPCFG_ENABLE_ITTYA  1
#define BSP_DEFAULT_IO_CHANNEL "ittya:"
#define BSP_DEFAULT_IO_CHANNEL_DEFINED

 

Could you please tell me where I am going wrong.

 

Thanks,

Lakshmi

 

0 Kudos
Reply
2,901 Views
DavidS
NXP Employee
NXP Employee

When you update the user_config.h, did you re-compile the build_m52259evb_libs.mcp, then re-build your application?

If that still is not working then try setting the UARTs for the ttya mode (drop the "i").

Regards,

David

0 Kudos
Reply
2,901 Views
Lakshmi
Contributor II

Thanks David

 

I will get back to you on this

0 Kudos
Reply
2,901 Views
Lakshmi
Contributor II

Hi David,

 

Please find my code attached. What I am basically trying to do here is, I have enabled UART0 in INTERRUPT mode. I have also configured for LED2 of my MCF52233 demo board.

 

When there is any character input in the HyperTerminal, I want to toggle the LED2 of my demo board.

 

I am able to output a character on HyperTerminal in interrupt mode,  but unable to input a character on Hyperterminal.

 

In the while(TRUE) loop mentioned in my code attached, I am in infinite loop reading a character on UART0 & trying to toggle the LED. It is NOT working as expected.

 

Also I noticed that, if UART0 write() works then read() does not work, vice versa is also true.

 

Also when I debug, I can notice that the control freezes at line

read(fh_ptr,bptr,1);  

 

When I press F10 at this line, the control does not overcome to next line of code.

 

 

Can you please look into my code & tell me where I am going wrong?

 

Thank you in advance

0 Kudos
Reply
2,900 Views
DavidS
NXP Employee
NXP Employee

Hi Lakshmi,

I found a couple of coding errors.  Look for //DES in the code for the updates.  I think you'll now be running OK.

Also not that the M52233DEMO board had serveral Revisions (C/D/F) that had slightly different pins used for switches (and maybe LEDs....cannot totally recall).  So if switch or button not working as expected, check respective schematic.

I tested this on REV C M52233DEMO.  Marking on the bottom of board.

Regards,

David

0 Kudos
Reply
2,901 Views
Lakshmi
Contributor II

Hi David,

 

I am tring with REV F.. I am able to toggle the LED2 after typing a character on Hyperterminal

 

Thanks,

Lakshmi

0 Kudos
Reply
2,901 Views
niravj
Contributor I

Hi David,

 

I am also having the similar problem as Lakshmi is haivng, I need to have an interrupt (An ISR which I can define and add my logic in it to handle the rceived character) when the uart receiver buffer is full or some specific number of characters are being received in the uart receive buffer.

 

Probably I can do it using the lower level programming - i.e. accessing UART program/status registers (though the exact syntax/program I have not tried for the same) and checking it in my program, but I wan to do the same using the BSP provided by mqx for UART. 

 

Beside this I also tried the same i.e. installing user defined isr instead of default isr for UART by the function call _int_install_isr() and using the example code at \mqx\examples\isr.

 

In this experiment it seems to me that in either of the case i.e. transmitting/receiving in both of the cases the interrupt is getting generated. So  how can I differentiate it or is it the correct way to do it ?

 

Any help in this direction will be greatly helpful to this thread readers/creator, because it seems to me there is no single example or documentation available for this.

 

Thanks for the help in advance :smileyhappy:

 

 

 

 

 

 

 

 

 

 

0 Kudos
Reply
2,901 Views
DavidS
NXP Employee
NXP Employee

Hi Niravj,

Please look at the latest reply and code I sent Lakshmi above.

I'm trying to make use of the inherent FSLMQX RTOS capabilities without having to reinvent the wheel.  Hopefully that will help you too.

Regards,

David

0 Kudos
Reply
2,901 Views
MQXuser
Contributor III

I would refer to the   \mqx\examples\io   example in the source directory. That should explain you the basics of UART management. Although there is no example for the MCU you mention, it should be helpful.

 

0 Kudos
Reply