µTasker Forum

µTasker Forum => Luminary Micro TM LM3SXXXX => Topic started by: aloft on September 06, 2008, 11:50:50 PM

Title: Using the UART in the simulator.
Post by: aloft on September 06, 2008, 11:50:50 PM
Thanks for this great resource.  I've been able to do quite a bit with it so far.  Now I'd like to communicate with the UARTs and I'd like to start with the simulator.

I've tried following the section on UARTS in the Simulator in post http://www.utasker.com/forum/index.php?topic=54.0 but I'm not having any luck.  There is also a reference to a different tutorial in the LM3SXXXX tutorial that I can't seem to find.

My computer only has 1 serial port so I'm setting to port 3 as below then building the Simulator and trying to access the simulator using the serial port of another computer.  Is this correct?

At first, I thought I could open a terminal window on the same computer but after thinking about it, I figured I'd need to use a second computer.  I confirmed that I can talk between the two computers by sending messages back and forth between terminal sessions on each computer.

Any ideas?

Thanks,

TW

 #define SERIAL_PORT_0 '3'                                            // if we open UART channel 0 we simulate using this com port on the PC (0 for no mapping)
    #define SERIAL_PORT_1 '3'                                            // if we open UART channel 1 we simulate using this com port on the PC
    #define SERIAL_PORT_2 '0'                                            // if we open UART channel 2 we simulate using this com port on the PC
Title: Re: Using the UART in the simulator.
Post by: mark on September 07, 2008, 12:30:38 AM
Hi

Which UART are you using in the code?

In your configuration you have mapped UART0 and UART1 to COM3. Do you actually have COM3 on the PC?
If you map 2 UARTs to the same COM port I believe that the first one opened in the code will be mapped and the second one opened will be ignored, therefore ensure that you only map the one that you want - to be sure.

Unfortunately the additional UART tutorial doesn't exist (at least not yet, although the tutorial seems to state that it does...sorry about that). But you are on the right track - testing using two terminal emulators is the correct thing to do and then the simulator should also operate (make sure that you also close the terminal emulator on the PC you are running the simulator on since it will otherwise not allow the simulator to use the COM - the simulator than silently gives up [rather than giving annoying warnings even when the UARTs are of no interest]).

Regards

Mark
Title: Re: Using the UART in the simulator.
Post by: aloft on September 07, 2008, 01:46:59 AM
Thanks, Mark.  Just mapping one port did the trick.
Title: Re: Using the UART in the simulator.
Post by: mhoneywill on September 21, 2008, 04:58:35 AM
I've not tried them with the uTasker simulator but you might want to try these free virtual comm port simulators that create pairs of virtual comm ports on your PC that are connected together by a virtual null modem cable. You could connect UTasker to one port and a terminal emulator to another.

See

http://www.mixw.net/index.php?j=related
http://com0com.sourceforge.net/
http://developer.berlios.de/projects/n8vbvcomdriver/
http://www.hw-group.com/products/hw_vsp/index_en.html

Hope these help

Cheers

Martin
Title: Re: Using the UART in the simulator.
Post by: mark on October 05, 2008, 11:44:06 PM
Hi Martin

I have used com0com (it also works under Vista) and it works well with the uTasker simulator.
The only thing which can't be fully check is the serial physical settings since it will work whatever is set up (even if there is a mismatch in the baud rates). However it is very practical since it avoids having to have real COM ports connected together when working with a single PC.

Thanks!

Regards

Mark
Title: Re: Using the UART in the simulator.
Post by: aloft on December 06, 2008, 11:17:52 PM
Hi Mark,

For some reason, I seem to be having a problem getting UART1 to work in the simulator (I haven't checked on the actual board).  The serial interface works fine on UART0 but if I change to UART1 by just changing the DEMO_UART from 0 to 1, it stops working.  COM3 isn't a valid port, but it seems from the UART thread that it just won't bind to that port, right?

I also change the SERIAL_PORT_0 mapping.  I'm using a LM3S6965 so I should have 3 UARTs.  What am I doing wrong?

Thanks,

TW

This works:

#define SERIAL_PORT_0     '6'                                            // if we open UART channel 0 we simulate using this com port on the PC (0 for no mapping)
#define SERIAL_PORT_1     '3'                                            // if we open UART channel 1 we simulate using this com port on the PC
#define DEMO_UART          0                                           // use UART 0


This doesn't work:
#define SERIAL_PORT_0    '3'                                            // if we open UART channel 0 we simulate using this com port on the PC (0 for no mapping)
#define SERIAL_PORT_1    '6'                                            // if we open UART channel 1 we simulate using this com port on the PC
#define DEMO_UART         1                                           // use UART 1
Title: Re: Using the UART in the simulator.
Post by: mark on December 07, 2008, 12:39:29 AM
Hi TW

You are doing nothing wrong. I didn't realise until you noted it but only UART0 is supported fully in the simulator.
UARTs 1 and 2 have no receiver and UART2 transmitter was not correct.

If you make the following changes in LM3SXXXXSim.c it will work.

1. In fnSimulateSerialIn() add the cases 1 and 2 (for UARTs 1 and 2)
Code: [Select]
    #if CHIP_HAS_UARTS > 1
    case 1:                                                              // {1}
        while (usLen--) {
            UARTRIS_1 |= UART_RXIM;                                      // set interrupt bit
            IRQ0_31_SPR |= (1 << irq_UART1_ID);
            IRQ0_31_CPR = IRQ0_31_SPR;
            UARTDR_1 = *ptrDebugIn++;                                    // put received character into rx holding register
            if (IRQ0_31_SER & (1 << irq_UART1_ID)) {                     // if UART 1 interrupt is not disabled
                if (UARTIM_1 & UART_RXIM) {                              // if receive interrupt is enabled
                    UARTMIS_1 |= UART_RXIM;                              // set masked interrupt status
                    ptrVect->processor_interrupts.irq_UART1();           // call the interrupt handler
                }
            }
        }
        break;
    #endif
    #if CHIP_HAS_UARTS > 2
    case 2:                                                              // {1}
        while (usLen--) {
            UARTRIS_2 |= UART_RXIM;                                      // set interrupt bit
            IRQ32_63_SPR |= (1 << (irq_UART2_ID - 32));
            IRQ32_63_CPR = IRQ32_63_SPR;
            UARTDR_2 = *ptrDebugIn++;                                    // put received character into rx holding register
            if (IRQ32_63_SER & (1 << (irq_UART2_ID - 32))) {             // if UART 2 interrupt is not disabled
                if (UARTIM_2 & UART_RXIM) {                              // if receive interrupt is enabled
                    UARTMIS_2 |= UART_RXIM;                              // set masked interrupt status
                    ptrVect->processor_interrupts.irq_UART2();           // call the interrupt handler
                }
            }
        }
        break;
    }
    #endif

2. In fnSimInts() replace the following block

Code: [Select]
#if CHIP_HAS_UARTS > 2
    if ((iInts & CHANNEL_2_SERIAL_INT) && (argv)) {
        ptrCnt = (int *)argv[2];                                         // {2}
        if (*ptrCnt) {
            if (--(*ptrCnt) == 0) {
                iMasks |= CHANNEL_2_SERIAL_INT;                          // enough serial interupts handled in this tick period
            }
            else {
                iInts &= ~CHANNEL_2_SERIAL_INT;                          // interrupt has been handled
    #ifdef SERIAL_INTERFACE
                fnLogTx2((unsigned char)UARTDR_2);
                ulNewActions |= SEND_COM_2;
                UARTRIS_2 |= (UART_TXIM);                                // simulate Tx int
                UARTFR_2 |= UARTTXFE;                                    // mark that the transmitter is no longer busy
                IRQ32_63_SPR |= (1 << (irq_UART2_ID - 32));
                IRQ32_63_CPR = IRQ32_63_SPR;
                if (IRQ32_63_SER & (1 << (irq_UART2_ID - 32))) {         // if UART 2 interrupt is not disabled
                    if (UARTIM_2 & UART_TXIM) {                          // if transmit interrupt is enabled
                        UARTMIS_2 |= UART_TXIM;                          // set masked interrupt status
                        ptrVect->processor_interrupts.irq_UART2();       // call the interrupt handler
                    }
                } 
    #endif
            }
        }
    }
#endif

I do expect that all UARTs work on the target but I can't be 100% sure since I possibly only ever tested UART0 on the hardware.

Regards

Mark