EmbDev.net

Forum: ARM programming with GCC/GNU tools Error in lpc2129_adc_stdio


von Alexey Shusharin (Guest)


Rate this post
useful
not useful
Hallo all

lpc2129_adc_stdio (in WinARM 20060606 examples) is very useful example
of using newlib stdio, but it holds some errors. I taked it as an
example of my program and it didn't work correctly. A day later I found
a problem: It was stack overflow.

I was using STACK_SIZE = 0x400 as showed in lpc2129_adc_stdio, but only
_vfiprintf_r (it's calling into iprintf) needs 0x523 bytes in stack.

I suppose this correcting can spare time for somebody.

Also I found some small errors:
in ADC.c: PLLCFG = MSEL | (1<<PSEL1) | (0<<PSEL0);
I think it must be: PLLCFG = MSEL | (0<<PSEL1) | (1<<PSEL0);

in makefile: THUMB = -mthumb and #DEBUG = stabs
It must be without thumb or with dwarf-2 debug format

best regards
Alexey

von Martin Thomas (Guest)


Rate this post
useful
not useful
Alexey Shusharin wrote:
> Hallo all
>
> lpc2129_adc_stdio (in WinARM 20060606 examples) is very useful example
> of using newlib stdio, but it holds some errors. I taked it as an
> example of my program and it didn't work correctly. A day later I found
> a problem: It was stack overflow.
>
> I was using STACK_SIZE = 0x400 as showed in lpc2129_adc_stdio, but only
> _vfiprintf_r (it's calling into iprintf) needs 0x523 bytes in stack.
>
> I suppose this correcting can spare time for somebody.
>
> Also I found some small errors:
> in ADC.c: PLLCFG = MSEL | (1<<PSEL1) | (0<<PSEL0);
> I think it must be: PLLCFG = MSEL | (0<<PSEL1) | (1<<PSEL0);
>
> in makefile: THUMB = -mthumb and #DEBUG = stabs
> It must be without thumb or with dwarf-2 debug format
>

Thanks Alexey for the feedback. I will look into the code soon and
modify it according to your suggestions.

I don't get your last point. The # means that the line is commented out.
dwarf-2 should be the default-setting (no # in the DEBUG = dwarf-2
line). Can you please provide some more information on this and why you
think that there is a mistake/error?

Martin Thomas

von Martin Thomas (Guest)


Rate this post
useful
not useful
Updated version available at
http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/index.html#gcc_stdio
- increased stack-size to 0x0800
- PLL divider 2 instead of 4
as suggested by Alexey
I have not yet tested this with real hardware since all LPC2129
prototype-boards are currently "out of town". Feedback welcome.

Martin

von Alexey Shusharin (Guest)


Rate this post
useful
not useful
Martin Thomas wrote:
> Alexey Shusharin wrote:

>
> Thanks Alexey for the feedback. I will look into the code soon and
> modify it according to your suggestions.
>
> I don't get your last point. The # means that the line is commented out.
> dwarf-2 should be the default-setting (no # in the DEBUG = dwarf-2
> line). Can you please provide some more information on this and why you
> think that there is a mistake/error?
>
> Martin Thomas

Hallo Martin

Sorry, It's my mistake. I had copied "#DEBUG = stabs" (with '#') from my
project.

Original makefile of lpc2129_adc_stdio hold this text:

# MCU name and submodel
MCU    = arm7tdmi-s
SUBMDL = LPC2129
THUMB    = -mthumb
THUMB_IW = -mthumb-interwork

...

# Debugging format.
# stabs  or dwarf-2,
DEBUG = stabs
#DEBUG = dwarf-2

best regards
Alexey

von Alexey Shusharin (Guest)


Rate this post
useful
not useful
Hallo again

I have some changes in lpc2129_adc_stdio else.
Stdio function "fgets" doesn't work correctly then I make second call of
it (in ADC.c). For example:

...
iprintf("Type something: ");
fgets(s,20+1,stdin);
iprintf("\nhere it is again: %s\n\n",s);

iprintf("Type something again: ");
fgets(s,20+1,stdin);   // Doesn't work
iprintf("\nhere it is again: %s\n\n",s);
...

For correct work _read_r should be changed from:

_ssize_t _read_r(struct _reent *r, int file, void *ptr, size_t len)
{
  char c;
  int  i;
  unsigned char *p;

  p = (unsigned char*)ptr;

  for (i = 0; i < len; i++)
  {
    c = uart0GetchW();
    if (c == 0x0D)
    {
      *p='\0';
      break;
    }
    *p++ = c;
    uart0Putch(c);
  }
  return len - i;
}

to:

_ssize_t _read_r(struct _reent *r, int file, void *ptr, size_t len)
{
  char c;
  int  i;
  unsigned char *p;

  p = (unsigned char*)ptr;

  for (i = 0; i < len; i++)
  {
    c = uart0GetchW();

    *p++ = c;
    uart0Putch(c);

    if (c == 0x0D && i <= (len - 2))
    {
      *p = 0x0A;
      uart0Putch(0x0A);
      return i + 2;
    }
  }
  return i;
}

best regards
Alexey

von Martin Thomas (Guest)


Rate this post
useful
not useful
Hello,

the debug-setting in the makefile has been already changed in a previous
update. If you have problems with example included in the
WinARM-package: please visit my "ARM-Projects" pages first, maybe there
is already a "better" version.

Alexey Shusharin wrote:

> I have some changes in lpc2129_adc_stdio else.
> Stdio function "fgets" doesn't work correctly then I make second call of
> it (in ADC.c). For example:
>
> ...
> iprintf("Type something: ");
> fgets(s,20+1,stdin);
> iprintf("\nhere it is again: %s\n\n",s);
>
> iprintf("Type something again: ");
> fgets(s,20+1,stdin);   // Doesn't work
> iprintf("\nhere it is again: %s\n\n",s);
> ...
>
> For correct work _read_r should be changed from:
>
> [...]
>
> to:
>
> _ssize_t _read_r(struct _reent *r, int file, void *ptr, size_t len)
> {
>   char c;
>   int  i;
>   unsigned char *p;
>
>   p = (unsigned char*)ptr;
>
>   for (i = 0; i < len; i++)
>   {
>     c = uart0GetchW();
>
>     *p++ = c;
>     uart0Putch(c);
>
>     if (c == 0x0D && i <= (len - 2))
>     {
>       *p = 0x0A;
>       uart0Putch(0x0A);
>       return i + 2;
>     }
>   }
>   return i;
> }


Applied in version 20070313.

http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/index.html#gcc_stdio

Thanks again.
Martin

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.