Linker problem placing variables in extra memory region

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

I'm trying to place variables in a non-cacheable memory region (with the intention to define extra MPU attributes for this).

 

To do so I added this section to the linker file:

MEMORY
{
  rom (rx)  : ORIGIN = 0x00420000, LENGTH = 0x001d0000
  ram (rwx) : ORIGIN = 0x20400000, LENGTH = 0x00050000
  ram_nocache (rwx): ORIGIN = 0x20450000, LENGTH = 0x10000
}

 

    /* region excluded from cache for unmanged DMA */
	.ram_nocache (NOLOAD):
    {
        . = ALIGN(8);
        _sram_nocache = .;
    } > ram_nocache

 

If I place only one variable into the section like this

 

__attribute__ ((section(".ram_nocache")))
COMPILER_ALIGNED(32) static struct gmac_device gs_gmac_dev;

then the result looks fine like this in .map file

.ram_nocache    0x20450000     0x1900
                0x20450000                . = ALIGN (0x8)
                0x20450000                _sram_nocache = .
 .ram_nocache   0x20450000     0x1900 src/ASF/thirdparty/lwip/lwip-port-1.4.1/sam/netif/same70_gmac.o

 

Same if I only place another variable like this

__attribute__ ((section(".ram_nocache")))
COMPILER_ALIGNED(32) static u8_t memp_memory[MEM_ALIGNMENT - 1
static u8_t memp_memory[MEM_ALIGNMENT - 1
#define LWIP_MEMPOOL(name,num,size,desc) + ( (num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size) ) )
#include "lwip/memp_std.h"
];

then the result looks also fine for me:

.ram_nocache    0x20450000     0xb4af
                0x20450000                . = ALIGN (0x8)
                0x20450000                _sram_nocache = .
 .ram_nocache   0x20450000     0xb4af src/ASF/thirdparty/lwip/lwip-1.4.1/src/core/memp.o

A problem arise if I place both variables to this memory region. The first variable is now located in flash instead of sram:

.ram_nocache    0x004f0b80     0x1900
 .ram_nocache   0x004f0b80     0x1900 src/ASF/thirdparty/lwip/lwip-port-1.4.1/sam/netif/same70_gmac.o
                0x004f2480                . = ALIGN (0x4)
                0x004f2480                _etext = .

.ram_nocache    0x20450000     0xb4af
                0x20450000                . = ALIGN (0x8)
                0x20450000                _sram_nocache = .
 .ram_nocache   0x20450000     0xb4af src/ASF/thirdparty/lwip/lwip-1.4.1/src/core/memp.o

Both variables should fit into the 64kByte memory region. I guess this is a problem in my linker file ?

I've attached the linker script and map file.

 

Thanks,

Jochen

Attachment(s): 

This topic has a solution.

SAME newbie

Last Edited: Sat. Dec 2, 2017 - 07:03 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guess I can answer it myself. I missed the linker statement to "collect" all variables with the same attribute in the appropriate section. This works for me:

/* Section Definitions */
SECTIONS
{
    /* other sections */
    /* ...... */

    /* region excluded from cache for unmanaged DMA */
	.ram_nocache (NOLOAD):
    {
        . = ALIGN(8);
        _sram_nocache = .;
	*(.ram_nocache)
    } > ram_nocache

    . = ALIGN(4);
    _end = . ;
    _ram_end_ = ORIGIN(ram) + LENGTH(ram) + LENGTH(ram_nocache) -1 ;
}

 

SAME newbie

Last Edited: Sat. Dec 2, 2017 - 07:06 PM