Hi,

> But when I started to add some functionality and increased the size
> of my USART communication buffer, it crashes. I sometimes see
> the printfed "Hello" from the program indicating that it starts, but
> the PIC dies.

Just a wild guess: You might want to check for stack overflow:
Try adding (or changing your current pragma stack if any to)
   #pragma stack 0x100 0x100
where the first 0x100 is the lowest address occupied by the stack and
the second 0x100 its size in bytes (256, the whole bank).
You might also check out the linker-generated .map file and see which
data structures lie just below the stack (stack grows downwards).
and see if they become corrupted.
Alternatively you could install a number of "guard bytes" in the lower
stack-bytes and check their integrity in some timer interrupt routine.

> Good, glad to hear that, some web sites, see for example:
>   http://bas.woodpecker.gotdns.org/pic.php
> suggest that to use all available memory tinkering the linker script
> is necessary.

I see. Such approaches may be required if you have, say, 5 buffers of
200 bytes each but only 4 banks to spare.
With the default linker script, the linker will bail out stating that
it could find no memory for some section (i.e., a buffer variable)
because of fragmentation issues as no variable may cross bank boundaries
(to avoid some BANKSELs).

|| 256.. 455| 456.. 511|| 512.. 711| 712.. 767||
      buff1     unused       buff2     unused

|| 768.. 967| 968..1023||1024..1223|1224..1279||
      buff3     unused       buff4     unused

In this case, merging the 4 banks into one of 1024 bytes can allow the
linker to place all buffers into the large "bank":

|| 256.. 455| 456.. 655| 656.. 855| 856..1055|1056..1255|1256..1279||
      buff1      buff2      buff3      buff4      buff5     unused

However, in such cases it is wise to fix the addresses of the buffers to
prevent the linker from placing other multi-byte variables across the
(now "hidden") bank boundaries.

You do not need to do this unless the linker fails to place all sections.

> And if I do not tinker with linker script I get no error messages, just
> the mysterious crash.if I increase markedly the  size of any of the
> arrays in my program.
> For instance I have a ring buffer for USART, it works if the array is
> 10 bytes but crashes if I make it 80 bytes. If I relocate the variable
> with eg " at 0x300" directive then the program does not crash but the
> characters from USART come through as 0.
> If I add a single 100 byte array, that I do not use for anything, the
> program crashes.

Mysterious indeed ...

Good luck,
Raphael

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to