How to move heap start after user defined memory segment.

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I interfaced external SRAM memory to ATMega128. Works fine. I wish to have stack, .bss and .data segments in internal SRAM and heap in external. Easy to do, well explained in AVR-libc manual. But at the same time I wish to have an additional memory segment for storing not time-critical global variables defined in external memory. It would be ideal if my additional segment will start at beginning of external memory (0x1100), and the heap will be just behind it. I know that I have to define __malloc_heap_start variable or __heap_start symbol, but how to feed it with end address of my defined section?
Or I can set the segment at the end of external memory, but how to automatically set the start address to RAMEND-size of segment?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I would choose an approximately correct size for , assign that location as RAMEND-sizeof(), then set __heapend (that exists, or something like it) to the location before your .

Your first map will show the size of so you can adjust the beginning of and __heapend.

I am unaware of an automatic way of doing this. If someone else clues us in, we'll both know! :wink:

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Stu, I’ve already solved the problem by modifying linker script:

.noinit  :
  {
     PROVIDE (__noinit_start = .) ;
    *(.noinit*)
     PROVIDE (__noinit_end = .) ;
     _end = . ;
     /*PROVIDE (__heap_start = .) ;*/
  }  > data
.XMEM	 0x801100:
  {
	*(.XMEM*)
	PROVIDE (__heap_start = .);
  } > data

I was just curious if somebody knows an easy way of doing it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, the linker-provided symbol would have been my recommendation
as well.

p.s.: Make sure to use avr-libc 1.7.0 (or higher once a newer version
exists), as several bugs with malloc() have been fixed there.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Jörg for response. I wonder if I can do it simpler. I cannot modify __malloc_heap_start variable, as my segment is on the beginning of external RAM, and I want to move the heap to the first byte after the segment. And here is the problem – in C I can’t or at least I don’t know how to obtain the segment end address. So my solution was to modify linker script, so my own segment defines __heap_start label.
BTW, I wish to use avr-libc 1.7.0, but I think it is now only available with Atmel provided avr-gcc? But unfortunately I have problems with it :
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=98723

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

in C I can’t or at least I don’t know how to obtain the segment end address.

Use PROVIDE in the linker script to make a symbol available. Just as happens at present:

C:\WinAVR-20100110\avr\lib\ldscripts>grep PROVIDE avr5.x
     PROVIDE (__data_start = .) ;
     PROVIDE (__data_end = .) ;
     PROVIDE (__bss_start = .) ;
     PROVIDE (__bss_end = .) ;
     PROVIDE (__noinit_start = .) ;
     PROVIDE (__noinit_end = .) ;
     PROVIDE (__heap_start = .) ;

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As I already did. Sorry, I misunderstood Jörg’s post.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> BTW, I wish to use avr-libc 1.7.0, but I think it is now only available
> with Atmel provided avr-gcc?

Well, compiling your own version of avr-libc isn't rocket science.
No fancy patches needed (unlike for binutils and GCC itself), all
you need is a compiler, make etc., which you do have already.
If you really have unresolvable troubles compiling it, I could also upload
a binary version to savannah.nongnu.org. I used to do that in the past,
but discontinued this service since I got the impression nobody were
using those binary versions anyway.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Jörg. You are right; it is not a rocket science  I was just lazy because with WinAVR I’ve got all the tools ready to use. Yesterday I checked once again the newest avr-gcc provided by Atmel with a newly created project and surprise – all my troubles were gone. I have to check it with g++, because I mainly write my programs in C++. In previous version I notice a problem with initialization of instances of global objects.