Error when running function from RAM (MCF51QE mcu)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error when running function from RAM (MCF51QE mcu)

1,383 Views
Florijan
Contributor III

Hi,

 

i am trying to run function from ram. When i try to compile the program I receive the error saying: "MyFunction in file main.c is referenced but has not been written. Check your linker command file."

the .lcf file looks like this:

# Sample Linker Command File for CodeWarrior for ColdFire MCF51QE32

# Memory ranges

MEMORY {
   code        (RX)  : ORIGIN = 0x00000410, LENGTH = 0x00007BF0
   userram     (RWX) : ORIGIN = 0x00800000, LENGTH = 0x00002000
}

SECTIONS {

# Heap and Stack sizes definition
  ___heap_size     = 0x0400;
  ___stack_size    = 0x0400;

# MCF51QE32 Derivative Memory map definitions from linker command files:
# ___RAM_ADDRESS, ___RAM_SIZE, ___FLASH_ADDRESS, ___FLASH_SIZE linker
# symbols must be defined in the linker command file.

# 8 Kbytes Internal SRAM
   ___RAM_ADDRESS = 0x00800000;
   ___RAM_SIZE    = 0x00002000;

# 32 KByte Internal Flash Memory
   ___FLASH_ADDRESS  = 0x00000000;
   ___FLASH_SIZE     = 0x00008000;

  .userram        : {} > userram
  .code     : {} > code

  .text :
  {
    *(.text)
    . = ALIGN (0x4);
    *(.rodata)
    . = ALIGN (0x4);
    ___ROM_AT = .;
    ___DATA_ROM = .;
  } >> code

  .data : AT(___ROM_AT)
  {
    ___DATA_RAM = .;
    . = ALIGN(0x4);
    *(.exception)
    . = ALIGN(0x4);
    __exception_table_start__ = .;
    EXCEPTION
    __exception_table_end__ = .;

    ___sinit__ = .;
      STATICINIT
    __START_DATA = .;

    *(.data)
    . = ALIGN (0x4);
    __END_DATA = .;

    __START_SDATA = .;
    *(.sdata)
    . = ALIGN (0x4);
    __END_SDATA = .;

    ___DATA_END = .;
    __SDA_BASE = .;
    . = ALIGN (0x4);
  } >> userram
 
  .copyToRAM: AT(___DATA_ROM + SIZEOF(.data))
    {
    . = ALIGN (0x4);
    __START_COPYTORAM = .;
    *(CopyToRAM)
    __END_COPYTORAM = .;

    } >> userram
   
  .bss :
  {
    ___BSS_START = .;
    __START_SBSS = .;
    *(.sbss)
    . = ALIGN (0x4);
    *(SCOMMON)
    __END_SBSS = .;

    __START_BSS = .;
    *(.bss)
    . = ALIGN (0x4);
    *(COMMON)
    __END_BSS = .;
    ___BSS_END = .;

    . = ALIGN(0x4);
  } >> userram

  .custom :
  {
    ___HEAP_START       = .;
    ___heap_addr        = ___HEAP_START;
    ___HEAP_END         = ___HEAP_START + ___heap_size;
    ___SP_END             = ___HEAP_END;
    ___SP_INIT          = ___SP_END + ___stack_size;

    . = ALIGN (0x4);
  } >> userram

  __SP_INIT             = ___SP_INIT;

  ___SP_AFTER_RESET     = __SP_INIT;

  _romp_at = ___ROM_AT + SIZEOF(.data);
  .romp : AT(_romp_at)
  {
    __S_romp = _romp_at;
    WRITEW(___ROM_AT);
    WRITEW(ADDR(.data));
    WRITEW(SIZEOF(.data)+SIZEOF(.copyToRAM)); #size
    WRITEW(0);
    WRITEW(0);
    WRITEW(0);
  }
}


main.c file looks something like this:

 

#pragma CODE_SEG __FAR_SEG CopyToRAM
unsigned int MyFunction(unsigned int n) {
return n*3;
}
#pragma CODE_SEG DEFAULT

 

Then i call function from main.c like:

 

unsigned int reslt;

reslt=MyFunction(5);

 

 

 

 

 

 

 

 

 

 

Thanks.

Florijan

Labels (1)
0 Kudos
2 Replies

414 Views
kef
Specialist I

this pragma seems to not work:

#pragma CODE_SEG __FAR_SEG CopyToRAM

 

I managed to make it working with CF2 method: 

 

#pragma define_section CopyToRAM "CopyToRAM" far_code
__declspec (CopyToRAM) unsigned int Fibonacci(unsigned int n) {
/*Code here*/
     return n*n;
}

And here's my lcf file:

 

# Sample Linker Command File for CodeWarrior for ColdFire MCF51QE128

# Memory ranges

MEMORY {
   code        (RX)  : ORIGIN = 0x00000410, LENGTH = 0x0001FBF0
   userram     (RWX) : ORIGIN = 0x00800000, LENGTH = 0x00002000
}

SECTIONS {

# Heap and Stack sizes definition
  ___heap_size     = 0x0400;
  ___stack_size    = 0x0400;

# MCF51QE128 Derivative Memory map definitions from linker command files:
# ___RAM_ADDRESS, ___RAM_SIZE, ___FLASH_ADDRESS, ___FLASH_SIZE linker
# symbols must be defined in the linker command file.

# 8 Kbytes Internal SRAM
   ___RAM_ADDRESS = 0x00800000;
   ___RAM_SIZE    = 0x00002000;

# 128 KByte Internal Flash Memory
   ___FLASH_ADDRESS  = 0x00000000;
   ___FLASH_SIZE     = 0x00020000;

  .userram        : {} > userram
  .code     : {} > code

  .text :
  {
    *(.text)
    . = ALIGN (0x4);
    *(.rodata)
    . = ALIGN (0x4);
    ___ROM_AT = .;
    ___DATA_ROM = .;
  } >> code

  .data : AT(___ROM_AT)
  {
    ___DATA_RAM = .;
    . = ALIGN(0x4);
    *(.exception)
    . = ALIGN(0x4);
    __exception_table_start__ = .;
    EXCEPTION
    __exception_table_end__ = .;

    ___sinit__ = .;
      STATICINIT
    __START_DATA = .;

    *(.data)
    . = ALIGN (0x4);
    __END_DATA = .;

    __START_SDATA = .;
    *(.sdata)
    . = ALIGN (0x4);
    __END_SDATA = .;

    ___DATA_END = .;
    __SDA_BASE = .;
    . = ALIGN (0x4);
  } >> userram

### copyToRAM mod
  .copyToRAM: AT(___DATA_ROM + SIZEOF(.data))
  {
    __START_COPYTORAM = .;
    *(CopyToRAM)
    __END_COPYTORAM = .;
    . = ALIGN (0x4);
  } >> userram
### /copyToRAM mod

  .bss :
  {
    ___BSS_START = .;
    __START_SBSS = .;
    *(.sbss)
    . = ALIGN (0x4);
    *(SCOMMON)
    __END_SBSS = .;

    __START_BSS = .;
    *(.bss)
    . = ALIGN (0x4);
    *(COMMON)
    __END_BSS = .;
    ___BSS_END = .;

    . = ALIGN(0x4);
  } >> userram

  .custom :
  {
    ___HEAP_START       = .;
    ___heap_addr        = ___HEAP_START;
    ___HEAP_END         = ___HEAP_START + ___heap_size;
    ___SP_END             = ___HEAP_END;
    ___SP_INIT          = ___SP_END + ___stack_size;

    . = ALIGN (0x4);
  } >> userram

  __SP_INIT             = ___SP_INIT;

  ___SP_AFTER_RESET     = __SP_INIT;


### copyToRAM mod ----------------------\
  _romp_at = ___ROM_AT + SIZEOF(.data) + SIZEOF(.copyToRAM);
  .romp : AT(_romp_at)
  {
    __S_romp = _romp_at;
    WRITEW(___ROM_AT);
    WRITEW(ADDR(.data));
### copyToRAM mod --------\
    WRITEW(SIZEOF(.data)+ SIZEOF(.copyToRAM)); #size
    WRITEW(0);
    WRITEW(0);
    WRITEW(0);
  }

}

0 Kudos

414 Views
Florijan
Contributor III

Thank you for the response. I will study this response. It will take a few days.

 

Have a nice day!

Florijan

0 Kudos