TWR K60N512 uart ISR triggering using mqx 4.0

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

TWR K60N512 uart ISR triggering using mqx 4.0

1,552 Views
shiju_cg
Contributor II

Hi,

I am using TWR K60N512 with mqx 4.0 .I need to create an ISR function for uart3 interrupt that trigger whenever a character is received .I tried to create an ISR  function, but it never gets triggered.

These are my initialization steps

#define RS232CHANNEL "ittyd:"

   rs232_dev = fopen( RS232CHANNEL, BSP_DEFAULT_IO_OPEN_MODE );

  

   _nvic_int_init(INT_UART3_RX_TX, 2, TRUE);  

   

  _nvic_int_enable(INT_UART3_RX_TX);  

   _int_install_isr(INT_UART3_RX_TX, uart3_rx_tx_isr, rs232_dev);

I have enabled the ITTYD in userconfig.h 

The following is the ISR function that i created.

void uart3_rx_tx_isr

   (

      pointer user_isr_ptr

   )

{

   uchar ubUDR;

   if (fstatus( rs232_dev ))

   {

       ubUDR = fgetc( rs232_dev );

   }

  

}

Can anybody provide me a sample code for the same  or help me to create an ISR that trigger whenever a character is received?.

5 Replies

626 Views
shiju_cg
Contributor II

Hi David,

I used  #define CUSTOMER_CODE  0 and print out both "hello" and "world". When i changed #define CUSTOMER_CODE 1 the control goes in to ISR before getting a character . ISR triggering,  without receiving a character, this happens only if printf function is used, else it works very well. Here i attached my source code.In it the printf in the while(1) loop works only once and it can printout only the first letter. ISR is working updating data properly.I have attached the source file.

Thanks and Regards, !

Shiju C G

0 Kudos

626 Views
DavidS
NXP Employee
NXP Employee

Hi CG,

I grabbed your code and added it to the mqx/examples/hello2.

I'm using the PEMicro Universal debugger but have also plugged in the OSBDM (after I had been debugging the project several times to make sure that CW was using the correct debugger interface) to enable a second serial interface (my primary serial interface is on the TWR-SER card (ttyd).  I then modified the BSP user_config.h to #define ittyf 1 which is the OSBDM debugger interface.  Use device manger to look at the "Ports" to determine what COM PORT it is using.  My assumption is you are using the OSBDM debugger interface.  If not that is OK too.

Once you modify the user_config.h always re-compile your RTOS.

I then played around with your code for a bit to get used to it and came up with the following conclusions:

- You are mixing baremetal code with RTOS code.  Usually this doesn't work well and it did not work here for following reasons:

          - The interrupt was triggering OK but the fstaus() and fgetc() function calls are to the RTOS drivers it is expecting to be working.  Your insertion of your uart5_rx_tx_isr did this and therefore was not allowing the received UART character to be processed and placed into a fifo as the interrupt driver for the ittyf device wants to use,  So the fstatus() call would not see a character in the UART interrupt fifo and never call the fgetc().  If commenting out the fstatus() then the fgetc() call also is looking for a character on the fifo, doesn't see one present and then suspends the task (usually not a good thing when calling from a interrupt service routine.

- The hack I did was to use your code to enable the UART to generate an interrupt when a character is received and then baremetal code read UART Status 1 register followed by read of receive buffer of the UART to clear interrupt flag and get the character.

Attached is the code.  To restore it to the hello2 original source change #define .CUSTOMER_CODE 0.

To run modified code to see your baremetal code receive a character change #define CUSTOMER_CODE 1.

Important steps for testing as I didn't use the best mqx/examples project as it only runs through the code/task once.  Set multiple breakpoints after your code initializes the ttyf interface and one in the isr.  Once breakpoint hit, then in your OSBDM terminal window type ONE character, hit Resume/Go Run (whatever you like to call it) and you should hit the breakpoint in the interrupt service routine or see the typed character echoed back to OSBDM terminal.

Summary: Don't mix baremetal code with MQX RTOS code.  Do one or the other.

Hope this helps,

David

0 Kudos

626 Views
shiju_cg
Contributor II

Hi David,

I downloaded the hello.c file and executed the file. Data reception is working properly, but the printf() function used in the ISR function is not printing  out  the received value and the execution control is not exiting from ISR.

void uart5_rx_tx_isr(pointer user_isr_ptr)

//DES should be a global   uchar ubUDR;

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

   if (fstatus( rs232_dev ))

   {

       ubUDR = fgetc( rs232_dev );

   }

#else

   /* Get the device registers */

   UART_MemMapPtr sci_ptr = _bsp_get_serial_base_address (5); //DES get base address for UART5

   ubUDR = sci_ptr->S1; //DES read status register.  Part of two step process to clear the interrupt flag.

   ubUDR = sci_ptr->D; //DES get the character

   printf("\n%c", ubUDR); //DES print character to "other" ttyN device         --------------------------------------------------------------------------------------->not printing out the received value

#endif

}

ISR is working perfectly when commenting out the printf() function used in the ISR function.Also i tried to use the printf () out side the ISR , that also not working properly. It print out only 2 characters.I tried to use     _io_serial_int_write  to print out data, but this also not working properly. 

Thanks and Regards,

Shiju C G

626 Views
DavidS
NXP Employee
NXP Employee

Hi Shiju,

I suspect your board header file or user_config.h isn't setup correctly.

For this example (again I'm using the TWR-K60D100M[newer silicon] but should be same for TWRK60N512[older silicon]).

Please verify that you are getting the "hello" and "world" printf's working first that output via the TWR-SER card.

The OSBDM serial interface is the input and should be able to echo the OSBDM character to the TWR-SER card.

Once you have verified the two headers above have been configured correctly, clean your RTOS and re-build it, then re-build your hello MQX application and test.

user_config.hScreenHunter_48 Dec. 18 07.35.gif

ScreenHunter_47 Dec. 18 07.35.gif

twrk60d100m.h

Regards,

David

626 Views
KJFPE
Contributor III

typedef struct my_isr_struct

{

   pointer               OLD_ISR_DATA;

   void      (_CODE_PTR_ OLD_ISR)(pointer);

   // what else needs to be in this structure

   _mqx_uint             intrCount;   // count the number of interrupts

} MY_ISR_STRUCT, _PTR_ MY_ISR_STRUCT_PTR;

void SetupRS232(void)

{

  MY_ISR_STRUCT_PTR  isr_ptr;

  fh_ptr =(pointer)fopen("ittyd:", (char const*)(IO_SERIAL_RAW_IO | IO_SERIAL_XON_XOFF));

  isr_ptr = (MY_ISR_STRUCT_PTR)(_mem_alloc_zero((_mem_size)sizeof(MY_ISR_STRUCT)));

  isr_ptr->intrCount = 0;

  isr_ptr->OLD_ISR_DATA = _int_get_isr_data(BSP_UART3_INTERRUPT_VECTOR);

  isr_ptr->OLD_ISR = _int_get_isr(BSP_UART3_INTERRUPT_VECTOR);

  _int_install_isr(BSP_UART3_INTERRUPT_VECTOR, new_uart_isr, isr_ptr);

}

void new_uart_isr(pointer user_isr_ptr)

{

  MY_ISR_STRUCT_PTR  isr_ptr = (MY_ISR_STRUCT_PTR)user_isr_ptr;

  (*isr_ptr->OLD_ISR)(isr_ptr->OLD_ISR_DATA);

}

0 Kudos