Serial write from RLP

I have seen the suggestion to write debugging info to a serial port from RLP. Does anyone have an example for this? There isn’t a serialport class in RLP as far as I know.

Open serial port from C# to initialize everything then you can simply write to the TX register directly on RLP. Look at LPC code in PK or in the code bundle from NXP for details.

I didn’t find anying in the porting kit that seemed helpful, but uart.c in the lpc sample seems correct, so I’ll try that this evening, thanks.

@ Paul Please do post if you get serial from RLP working - I’m going to be wanting to do that sooner or later.

Andrew

Complete drivers are here C:\MicroFrameworkPK_v4_1\DeviceCode\Targets\Native\LPC24XX\DeviceCode\USART

but all you need really is the UART TX register. you can look at NXP example code or just look it up in datasheet.

I found the CPP pretty incomprehensible (and no reference to U0THR) but the below from uart.c appears to be a fairly simple way of doing it so I’ll try that and report back how it goes:


    while ( Length != 0 )
    {
	  /* THRE status, contain valid data */
	  while ( !(UART0TxEmpty & 0x01) );	
	  U0THR = *BufferPtr;
	  UART0TxEmpty = 0;	/* not empty in the THR until it shifts out */
	  BufferPtr++;
	  Length--;
	}


This works, if you do U0THR = ‘a’ in a loop you will get that many a’s when you read from the port since it is clearing and using that register before each instruction executes in C.

Here’s the catch though, you can’t read straight from the port registers in .NET. So you have to setup two COM ports in code, run a wire from the out of one to the in of the next and then you can read it and do a Debug.Print on it. I tried just reading directly from the single port I was writing to the register of and I tried writing to both the read and write register but I couldn’t get any data until I ran a wire to another port on the board and used two ports.

Alternatively you could read it through a terminal program and a USB to serial converter but this seemed easier than that. Probably setting up an event that calls into managed code and you then call a method to get your debug data is a better way to do it, but this does work.

Sounds very complicated.
Why don’t you just connect the COM port to the PC and use a terminal program. You don’t need Debug.Print.

It is and I mentioned that as a possibility. But then I would have to involve a) a serial to USB converter and b) a terminal program. This way involves nothing extra since I’m already debugging the Fez device. If I weren’t then the terminal program would be the way to go.

You want debugging feedback from rlp to .Net, right? each rlp function returns an int. Define a list of possible errors and return the correct error when a function fails. Or send an event from rlp to .net with a predefined status number…

Yeah, I was looking more for print statements as it hits each section so I know where it is going as it calls multiple other methods to get work done. Plus if it bombs at any point you just get nothing instead of an exception you can catch, etc. like good ol’ .NET. I think posting an event and accumulating and clearing the string messages and then viewing them would work though. Anyway, I kept seeing “use the COM port” as a tip for debugging so I wanted to see how it would work.

I’ve just made use of serial comms from RLP - see this post [url]http://www.tinyclr.com/forum/2/3106/#/1/msg31906[/url]

I’ll be posting the code up shortly.

Andrew

Nice work!

I added a little library of functions that you can call to send messages to a com port:
You can print signed/unsigned numerics with optional base, and of course strings.

[url]http://code.tinyclr.com/project/329/rlp-serial-debugging/[/url]

Useful, thanks

@ Felix: nice work.

You can wait until the transmit register is empty instead of using a guessed delay value :slight_smile:


while (!(U1LSR & LSR_TEMT)) ;

Wouter, that works great - much faster now, thanks!

I updated the sample code.