[En-Nut-Discussion] CR + LF or LF + CR

Ulrich Prinz uprinz2 at netscape.net
Sat Sep 5 22:52:11 CEST 2009


Sorry to fast...
But by the way: I stumbled accross that on another project: Windows has 
a big problem with string recognition with exchaned CR/LF. We searched 
for hours to find that on a test enviroment in a production line...

Ok, here are fixes for the different platforms. Tell me what you tested 
and what worked, so I test the others.

static void DebugPut(CONST NUTDEVICE * dev, char ch)
{
     if (ch == '\n') {
        while ((inr(dev->dev_base + US_CSR_OFF) & US_TXRDY) == 0);
         outr(dev->dev_base + US_THR_OFF, '\r');
     }
     while ((inr(dev->dev_base + US_CSR_OFF) & US_TXRDY) == 0);
     outr(dev->dev_base + US_THR_OFF, ch);
}

The wait for the THR getting empty has to follow after sending the CR 
out. Sorry again.

Ok, here the fix for AVR: arch/avr/dev/debug1.c
Find / replace DebugPut(char ch)

static void DebugPut(char ch)
{
     if(ch == '\n') {
        while((UCSR1A & BV(UDRE)) == 0);
        UDR1 = '\r';
     }
     while((UCSR1A & BV(UDRE)) == 0);
     UDR1 = ch;
}

And for AVR debugging via UART 0: arch/avr/dev/debug0.c
Find / replace DebugPut(..)

/*!
  * \brief Send a single character to debug device 0.
  *
  * A carriage return character will be automatically appended
  * to any linefeed.
  */
static void DebugPut(char ch)
{
     if(ch == '\n') {
        while((USR & BV(UDRE)) == 0);
        UDR = '\r';
     }
     while((USR & BV(UDRE)) == 0);
     UDR = ch;
}

And now for the LPC2xxx: arch/arm/dev/debug_lpc2xxx.c

/*!
  * \brief Send a single character to debug device 0.
  *
  * A carriage return character will be automatically appended
  * to any linefeed.
  */
void DebugPut0(char ch)
{
   if(ch == '\n') {
      while ((U0LSR & U0LSR_THRE) == 0);
      U0THR = '\r';
   }
   while ((U0LSR & U0LSR_THRE) == 0);
   U0THR = ch;
}

/*!
  * \brief Send a single character to debug device 1.
  *
  * A carriage return character will be automatically appended
  * to any linefeed.
  */
void DebugPut1(char ch)
{
   if(ch == '\n') {
      while ((U1LSR & U1LSR_THRE) == 0);
      U1THR = '\r';
   }
   while ((U1LSR & U1LSR_THRE) == 0);
   U1THR = ch;
}

Andre Riesberg schrieb:
> Hi all,
> 
> I use the debug output via serial interface. In the output every LF will 
> be replaced by LF CR.
> This surprised me a little bit, many other system (I know) use CR LF.
> 
> I know this is really an unimportant detail but my favorite terminal 
> program can suppress CR LF but not LF CR on the screen.
> 
> Greetings
> Andre
> 
> PS: I forward this mail to the developer of HTerm. Maybe in the next 
> version he can also suppress LF CR :-)
> 
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion



More information about the En-Nut-Discussion mailing list