Error in lpc2129_adc_stdio

Guest #1172213
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
Guest #1172214
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
Guest #1172216
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
Guest #1172217
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
Guest #1172218
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

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.