Electronics & Programming


Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » MSPGCC
  • » [Mspgcc-users] Accessing data above 64K [RSS Feed]

#1 June 14, 2010 18:59:08

Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] Accessing data above 64K

There are two ways to access it.
If the compiler supports 20 bit pointers, things are straight. Just use any
normal C reference (variable/array name, pointer etc.).

Unfortunately, the mspgcc3 does not support it at all and the mspgcc4 still
seems to have some problems (it's recommended to only only use data in the
lower 64k).
So you'll need a read function that sets up the registers for 20 bit pointer
usage from a passed 32 bit address and retrieves the data.
Here's a code snippet for word reads:

static inline unsigned int FlashReadWord (unsigned long address){
unsigned int result, sr, flash;
__asm__ __volatile__ ("mov r2,%0":"=r"(sr):);
// save SR before disabling IRQ
__asm__ __volatile__ ("movx.a %1,%0":"=r"(flash):"m"(address));
__asm__ __volatile__ ("movx @%1, %0":"=r"(result):"r"(flash));
__asm__ __volatile__ ("mov %0,r2"::"r"(sr));
// restore previous SR and IRQ state
return result;

It's necessary to block IRQs so a non-X- ISR cannot clobber the 20 bit register
contents by only saving 16 bits. Also, don't push SR ons tack as it might break
the stack frame which might hold the address parameter.
For byte reads use a separate function with "movx.b @%1,%0", since movx(.w)
won't work for an odd address. For long reads add an incda and a second movx
command and as destination the %A and %B modifiers for
a long result. Flash is a dummy variable, just to allow the compiler to chose a
register on its own during the inline function. One could use a fixed register
and mark it as clobbered, but it's better to let the compiler decide
which one to use.

Have Fun!

----- Urspr√ľngliche Nachricht -----
Von: FrancoG
An: mspgcc-us***@*ists.sourceforge.net
Gesendet am: 10 Jun 2010 15:26:36
Betreff: Accessing data above 64K

I have read how to use attribute command to allow placing of data in area
above 64k (fartext). Can someone please show me a C code snippet to access
the data in the FARTEXT section. Thanks. Franco


  • Root
  • » MSPGCC
  • » [Mspgcc-users] Accessing data above 64K [RSS Feed]

Board footer

Moderator control

Enjoy the 21st of March

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support