BackupGGCode / propgcc

GCC for the Parallax Propeller Microcontroller
Other
0 stars 0 forks source link

Off-by-one Error in FDSerial Driver Prevents Useful Initialization Via freopen() #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1. Create a simple program (test.c):

#include <stdio.h>
#include <driver.h>

extern _Driver _SimpleSerialDriver;
extern _Driver _FullDuplexSerialDriver;
_Driver *_driverlist[] = {
  &_SimpleSerialDriver,
  &_FullDuplexSerialDriver,
  NULL
};
void main()
{
    freopen("FDS:115200,31,30", "w", stdout);
    while (1) printf("Hello World\n");
}

2. Compile and load to a propeller thus:

propeller-elf-gcc -O2 -mfcache  -mlmm -o test.o -c test.c
propeller-elf-gcc -mlmm -fno-exceptions -fno-rtti -o test.elf test.o -s
propeller-load -b <yourboard> test.elf -r -t

What is the expected output? What do you see instead?

I expect to see lots and lots of "Hello Worlds".  Instead, I see nothing.  An 
astute observer with an oscilloscope or an LED on P0 will see that P0 is being 
used as the TX pin instead of P30.

What version of the product are you using? On what operating system?

propgcc-0.2.2

Please provide any additional information below.

The problem is at line 153 of lib/drivers/FdSerial.c; we need to increment name 
before doing the atoi.   lib/drivers/SimpleSerial.c (at around line 123) does 
the exact same parsing of the driver parameters, and it gets it right.

The exact fix is:

Change lines 152 and 153 of FdSerial.c from:

      if (*name)
        txpin = atoi(name);

To:

      if (*name)
        {
          name++;
          txpin = atoi(name);
        }

Original issue reported on code.google.com by tjstefan...@charter.net on 28 Jan 2012 at 9:34

GoogleCodeExporter commented 9 years ago
Thank you very much for catching this. I've checked the fix in.

Eric

Original comment by ersm...@hfx.eastlink.ca on 4 Feb 2012 at 9:30