uTasker + Code warrior : How to enable UART_2?

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

uTasker + Code warrior : How to enable UART_2?

3,915 Views
SKumar
Contributor I
Hi.
 
                 I am using MCF52235EVB and using utasker os under codewarrior enviornment.
                 I am currently using UART_0 and UART_1.
 
               Now UART_2 is multiplexed with CAN port.
               I want to use it as UART_2.
 
                Please help me out. how to change the jumper settings.
                I tried with different combinations but didnt worked.
 
               Do i need to do some changes in uTasker code as well.
 
               Thanks...
 
Regards,
kumar
Labels (1)
0 Kudos
14 Replies

1,051 Views
mjbcswitzerland
Specialist V
Hi Kumar

First of all it is correct that the jumpers on the EVB must be set up correctly since the DSUB connector is used also for the CAN bus.

UART2_EN must be set with 1-2 and 3-4 on
UART2/CAN must be set with COM_SELA, COM_SELB and COM_SELC all at 1-2

In the uTasker project you can define which UART is used when opening the serial interface:

Eg:
SerialHandle = fnOpen( TYPE_TTY, ucDriverMode, &tInterfaceParameters );

In TTYTABLE tInterfaceParameters you can define the mode of the interface (stop bits, speed etc., whether it used flow control, high/low water markers and whether is uses DMA, plus a few other things too)
The actual physical interface is selected by the value of tInterfaceParameters.Channel
- 0 will use UART0
- 1 will use UART1
- 2 will use UART2

In your hardware setup file (app_hw_m5223x.h) make sure also that resources for 3 UARTs are defined
#define NUMBER_SERIAL (3)
to ensure that the operating system reserves resources for using all 3 interfaces.

Regards

Mark




P.S. Note that CAN is also supported in the project and its use is very similar.

CAN_handle = fnOpen( TYPE_CAN, FOR_I_O, &tCANParameters );
Details are give in the CAN documention: http://www.utasker.com/docs/uTasker/uTaskerCAN.PDF
0 Kudos

1,051 Views
SKumar
Contributor I
Hi mark,
 
                  Thanks a lot for helping me out.
                   I did the way you told me.
                  Now i can use UART_2 as well.
 
 
                  But there is small problem. When i am outuputting any buffer to UART_2 then buffer is filled 
                  with some Junk and i am getting oput as Junk+buffer.
                  i.e if i am output "Welcome to World" it printed as  "xxxxxxxWelcome to world" .
                   What could be reason for that? Any Idea..
                 
 
                  Anyways, You are helping me out a lot.
                  Thanks a lot.
                  Take care.
 
Regards,
Kumar
0 Kudos

1,051 Views
mjbcswitzerland
Specialist V
Hi Kumar

I haven't heard of any problem with UART2. The driver code is the same for all UARTs apart from the register accesses.

Here are some ideas and how to debug.

1. If you use the uTasker simulator your can simulate the UARTs and do the same test on your PC - conect the COM port of the PC to the terminal(emulator). You can map the COM port to the UART in app_hw_m5223x.h
#define SERIAL_PORT_2 '1' will map UART2 to COM1
If the result is identical it is a code problem but if it isn't it may be a low level driver problem. In the simulator code problems can be easily tracked down and corrections simply tested.

2. Try in Interrupt and DMA modes (DMA support can be removed globally by removing #define SERIAL_SUPPORT_DMA or on a per channel basis by removing the DMA flag when opening the interface.
tInterfaceParameters.ucDMAConfig = 0; // remove UART_TX_DMA;

3. Which write method do you use? fnWrite(serial_handle, buffer, length); or
fnDebugMsg("Hello World\r\n" );
The result in both cases is that a certain length of data is copied into the output buffer. What you are seeing with "xxxxxxHello World" is that the start pointer is before the start of the string and also the length corresponds to the start of the pointer up to the end of the string which you want to send. This means that it is not that a counter of a pointer are off but these at least match up to the end of the string.
Can you show your write code?

4. With the simulator or BDM you can quite easily follow the write to where the characters are placed into the output buffer. After the copy you can expand the structure to see its state. I have attached a screen shot in the uTasker simulator showing this after writing the message to UART 2.

- fnWrite() calls entry_tty(), which takes the switch CALL_WRITE
- pointer ptTTYQue is set to the output TTYQUE structure.
- fnFillBuf() will be called to place the data into the output circular buffer
- Once this has been performed, compare your structure with mine.

A. check that your input buffer (ptBuffer) is really pointing to the string expected and the length of copied data (Counter) is identical to the length of the string.
B. check that the structure is correct. In my screen shot you can see that the string is 0x0a characters in length (variable chars) and that the string has been set to the beginning of the buffer (circular buffer 0x100 in length with get pointer pointing to it).

Regards

Mark

0 Kudos

1,051 Views
SKumar
Contributor I
Hi Mark,
 
               Thanks a lot. UART_2 is working fine now.
 
              But still not gone away with the socket timeout issue which we had discussed in earlier forum. (TCP_STATE_LASK_ACK & TCP_STATE_WAIT).
               Even if we specify usIdealTiimeout to 0xffff. Connection goes in no activity state.
              I am sending TCP ping frame every 20 sec.so that there will be some activity on active connection.
              I am using comman hub between connections.Hub connected on network and i am drawing two connection from it that goes to each of the ethernet port. Does it really matters? i dont think so.
               All the sudden i lost the link between connection and server goes into listen state or stop reponding.
             I observed very few times it is working fine. 
                
Regards,
Kumar
0 Kudos

1,051 Views
mjbcswitzerland
Specialist V
Kumar

I think that you should verify that the connection is not closing for another reason - such as it is receiving a RST from the other side.

1. Put a break point in fnPollTCP() (line 1411) where the idle timer times out
fnNewTCPState(ptr_TCP, TCP_STATE_FIN_WAIT_1);
This will verify whether there is an idle timer really timing out or not.

2. More generally put a break point in fnNewTCPState()
in the case for
case TCP_STATE_CLOSE_WAIT:
case TCP_STATE_LAST_ACK:
case TCP_STATE_FIN_WAIT_1:
case TCP_STATE_CLOSING:

This will break when a TCP connection is closed. You will be able to see the calling function and then be able to see the cause of the connection close.

Regards

Mark
0 Kudos

1,051 Views
SKumar
Contributor I
Hi Mark,
                
                I was debugging fnNewTCPState() function few days before.
                It is closing the connection due to follwing reasons
                
1.
                case TCP_STATE_CLOSE_WAIT:  (2*TCP_MSL_TIMEOUT)
                 It will put socket into TCP_EVENT_CLOSED state. 
2.
                 TCP polls every second for state change.fnPollTCP()
                 It is setting "iReset" flag and put connection in TCP_EVENT_ABORT state.
 
Now first cause will get elimitate as we are using MAX timeout period.
What about second cause?
 
One more thing. You saying it must be receiving RST from other side.That is correct.Some times it receives RST from other side.But without pressing reset switch how it is possible to receive RST from other side.Or what are the circumstances of receiving RST from Other side.
 
Does that mean it is closing the connection because of some network issues or unknown errors?
 
Regards,
kumar
0 Kudos

1,051 Views
mjbcswitzerland
Specialist V
Hi Kumar

A TCP connection will also be closed if the other side is not responding and a transmission TCP frame is repeated too often. The iReset flag is set either when this happens or when the application (your interface) decides that it doesn't want to regenerate data.

[Check how your application is responding to the TCP_EVENT_REGENERATE event. It should resent any non-acked data. If your application would prefer to work with buffered TCP you can alternatively use a TELNET based connection (in RAW mode) which will buffer data and perform windowing, flow control and all retransmissions autonomously.]

I think that it would be useful if you could record the connection close/reset using Ethereal and send this to me. If your board is sending TCP frames which are not acknowledged this will be visible and about 20s later, after a few repetitions, the board will close the connection, sending a RST rather than the FIN because the connection is already dead.

From the data it should be possible to verify this and identify the root cause.

Regards

Mark

0 Kudos

1,051 Views
SKumar
Contributor I
Mark,
 
        That means i have to enable the constant #define USE_TELNET in config.h file 
         put follwing case in TCPListener in order to handle regenerate unacknowledged TCP frame.
 
        case TCP_EVENT_REGENERATE:
       if (fnSendBufTCP(Socket, 0, 0, TCP_BUF_REP)) {                   // repeat send buffered
           return APP_SENT_DATA;
       }
 
       I will also send you the etherial file soon.
 
      Thanks a lot.
       Have a nice weekend.
 
Regards,
Kumar
0 Kudos

1,051 Views
mjbcswitzerland
Specialist V
Hi Kumar

The use of direct TCP socket can not be mixed with the TELNET solution so it is best to remain with your present solution until you have understood the problem that you have.

The TELNET solution requires opening a TELNET based socket rather that a TCP socket. The TELNET based socket includes all TELNET stuff between the actual TCP socket and the application and it is this which handles much of what your application will presently be handling. A TELNET based socket makes application programming much easier since it handles windowing, retransmission, flow control etc. in a transparent manor. The down side is that it is not so stream-lined as a direct TCP socket since it requires a buffer to be allocated for the tranmitted data. However the user has the choice to obtain the most comfortable, and efficient mix for the project in hand. To learn more about the TELNET support simply activate TELNET support in the uTasker demo project. You can then connect to the board using TELNET and all debug messages are then sent over the TELNET connection. The debug output function fnDebugMsg("Hello World" ); is automatically diverted from the UART handle to the TELNET socket handle when the connection is established and back to the UART when the connection is disconnected. See how the TELNET based socket is configured in debug.c.

Since you are presently using a direct TCP socket, your application must handle the regenerate case by regenerating the last TCP frame data. This is often easy to do if the data is fixed (for example data in FLASH) but is more complicated when the data is volatile since it means a copy needs to be kept until its transmission has been acknowledged. Web server sockets for example don't need to back up transmitted data because it is in the file system and can be simply regenerated (it doesn't have to make a backup in case of frame loss). Other data such as debug data is generated in a more random manor and so can not be simple regenerated without making a backup of it in RAM. For such cases the TENLET based method is the simplest to use. A direct socket is possible but the application is then responsibe for the detailed work, which can be quite complicated if high speed bulk transfer is a criteria.

Therefore check how you are handling the regenerate case. If the applicatioin doesn't regenerate, the TCP connection will in fact understand this as a request to close the connection (which will also be visible in the Ethereal recording). Note that you can not use fnSendBufTCP() if using a direct TCP socket since it has no buffered support. The normal fnSendTCP() must be used. There is then another question - assuming that the cause of the closed connections can be explained by packet loss - why do you have possibly a high level of packet loss in your test network? In a LAN, TCP packet loss is normally so low that you will almost never encounter it.

Regards

Mark

P.S. You can read about the TCP window management performed by the TELNET based socket in the uTasker documentation directory in the file uTaskerTELNET.doc

0 Kudos

1,051 Views
SKumar
Contributor I
Hi mark,
 
                As you said we can use Maxidealtimeout period for sockets ie(0xffff).
               But what if client abort its operation by switching off the board?
               In our case timeout period is max...how server will know that client has disconnected and need
               reconnect. we will have to wait till timeout period (approx.. 18 hrs ) to let server know client has 
               disconnected.Meanwhile after client close the connection,another client want the service,how
               server will handle this situation.                              
 
Regards,
Kumar
0 Kudos

1,051 Views
mjbcswitzerland
Specialist V
Hi Kumar
 
By setting 0xffff you will in fact have an infinite timeout (not 18 hours), However this scenario is a normal situation for any TCP socket. If it is connected and the client is turned off, the connection remains established - this situation will remain until the server side sends a frame which can not be delivered and then it will reset since the connection obviously no longer exists. Once again - this is absolutely normal and is the reason why often an timeout is also active (2 minutes is typical).
 
If now another client tries to connect to the port the TCP service is on, what happens depends on the configuration. If you have only one port listening then this port is blocked and the TCP code will send a RST back to the client indicating that no connection is possible. However, if you have multiple sockets listening on the port then the next available one can handle the connection request - whether there is a single socket or multiple ones depends on your application and its requirements.
 
Take a look at the web server (http.c) where the number of listening sockets can be defined in config.h as #define NO_OF_HTTP_SESSIONS 8 // for example
 
This allows 8 clients to be connected to the HTTP service at the same time. If there are 8 established connections, the 9th connection attempt will be RST as there are no more free sockets to handle it.
The compromise is simply memory - a socket requires about 46 bytes of SRAM for its working structure (exact size depending on various settings) and if you need to ensure that a large(ish) number of connections can be handled at the same time (or when some sockets are unavailable due to being in a connection state with no more client...) then the number of sockets will needs to be defined correspondingly. [Note that it is also possible for the application using the socket to actively send a periodic keep-alive type frame to free such a dead connection].
 
Regards
 
Mark
0 Kudos

1,051 Views
SKumar
Contributor I
Hi Mark,
 
    For time being we forget about MAX timeout ( ie 0xffff ) .Let is be TCP_DEFAULT_TIMEOUT ie ( 2 sec ).
   Now if i planned to send TCP frame from/to Client/Server to keep some activity on connection.
   After every 20 sec application will send this frame.
   Will this senario help us from preventing socket getting time out?
    
     One more thing.
     I am reading 16 chars buffer from UARTs contineously. This buffers will send over client/server
    communication as they get filled. Sometime it happens that i  write 16 or more chars on
    Hyperterminal but application not able read it from specified UART.After few seconds if i again try it
    works fine.So previous data that i have already written to Hyperterminal is get lost.
 
    To double check this i also monitored TCP frames in Ethereal.But lost data was not there on Ethereal.
     I also checked serial drivers but it seems to working fine.
    
 
 
Regards,
kumar.
0 Kudos

1,051 Views
mjbcswitzerland
Specialist V
Hi Kumar

Any activity at the socket (either direction) should retrigger the timeout timer.
In case of a timeout it shouldn't be a major problem for an application since both sides know that the connection has timed out and it will be automatically re-established when data is to be sent (sockets can be defined to works as both listener and client if required so that any side can establish the connection when needed).

At the moment I don't understand exactly the problem with the UART and where in the chain data is getting lost.

It may be an idea to start a new thread if this topic is to be analysed so that the subject is clear for any other uses's wishing to follow it. Otherwise you can also send more details (and code is necessary) to the uTasker support email address.

Regards

0 Kudos

1,051 Views
SKumar
Contributor I
Hi mark.
 
                 I am sending you ethereal files.
                 Please look at the same and see if you can get anything from it.
 
                 192.168.1.171 is server and 192.168.1.170 is client.
 
                 Client is sending RST after some time.
                
 
                 Please remove the extention of attached files before opening it using ethereal.
 
 
                 Thanks a lot.   
 
 
Regards,
Kumar
0 Kudos