custom section address

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

Hey, I made a new Section for loading configuration.

 

When the section is: 

-Wl,--section-start=.configSec=0xa000

and the loading code is:

#define CONFIG_SECTION_ADDRESS 0xa000

	memcpy_P(&config_block,(void *) CONFIG_SECTION_ADDRESS, sizeof(struct cnf_blk));

everything works good.

 

but if I change the address of the .configSec over 0xffff, it doesn't work, why?

 

I have a Xmega256a3u device, how can I set it to (0x00019000) in the flash memory?

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

but if I change the address of the .configSec over 0xffff, it doesn't work, why?

int's in AVR compilers are 16 bit, so are the pointers. So they can address 0..64K of memory. Beyond 64K you need some form of additional addressing information like RAMPZ, RAMPD, etc. That (usually 8 bits) is amalgamated with the 16bit pointer to extend its range to 24 bits. 24 bit pointers can address 16MB.

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

Can you give me example, how to copy address from 0x00019000 ?

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

Not really as I have no experience of using >64K AVR and PROGMEM myself but I would point out that it is memcpy_PF() and not just memcpy_P() you should be using and for the "far" versions the second parameter is a "uint_farptr_t" which is effectively a "32 bit pointer" and you would generally use pgm_get_far_address() to build such a 32 bit pointer. So something like:

__attribute__((section(".configSec"))) int data[] = { 1,2,3,4 };

    memcpy_PF(&config_block, pgm_get_far_address(data), sizeof(data));

Obviously your data is a struct not just an array of int[] but you can presumably build on this?

 

As I say I have never actually done this so have no idea if I got the syntax of this correct but I bet if you google "memcpy_PF" you will find other people's working code examples.