EmbDev.net

Forum: ARM programming with GCC/GNU tools Writing to Flash in Thumb mode


von Luiz C. (lz-coelho)


Rate this post
useful
not useful
Hello.
I have a Flash Write routine for the AT91SAM7XC256 that works fine
when compiled in ARM mode but, when compiled in THUMB mode, generates
a Data Abort exception when trying to write to the write page buffer.
With this section of code removed, the program works fine in THUMB mode.
The write access is done with 32 bits, as the datasheet states (item
20.1.3 Write Operations): "Writing 8-bit and 16-bit data is not
allowed and may lead to unpredictable data corruption". Maybe the
access to Flash should be done in 16 bits in THUMB mode?
The base address for writing is calculated as:
(pagenum * FLASH_PAGE_SIZE)+0x00100000, with FLASH_PAGE_SIZE = 256.
I would apreciate some help with this problem. Thanks in advance.

Luiz Coelho

von Luiz C. (lz-coelho)


Rate this post
useful
not useful
Hi people.

The problem was solved and had nothing to do with Thumb mode, but with a
subtle caracteristic of the gnu compiler for ARM.
The Data Abort exeception was caused, not by a writing access to the
flash address space, but by an invalid read access from a misaligned
buffer.

The flash writing loop was:

  for(i=0; i<(FLASH_PAGE_SIZE/4); i++)
  {
    *p++ = *buf++;
  }

whith *p and *buf pointers to unsigned ints, as required, but *buf was
initialized with the address of a misaligned structure. The solution was
a declaration of an atribute of alignement:

struct _attribute_ ((packed, aligned (4)))
{
.....
} fine_struct;

and then we make

buf = (unsigned int *)((void *)&fine_struct);

Thanks for everybody.

Luiz Coelho



Luiz Coelho wrote:
> Hello.
> I have a Flash Write routine for the AT91SAM7XC256 that works fine
> when compiled in ARM mode but, when compiled in THUMB mode, generates
> a Data Abort exception when trying to write to the write page buffer.
> With this section of code removed, the program works fine in THUMB mode.
> The write access is done with 32 bits, as the datasheet states (item
> 20.1.3 Write Operations): "Writing 8-bit and 16-bit data is not
> allowed and may lead to unpredictable data corruption". Maybe the
> access to Flash should be done in 16 bits in THUMB mode?
> The base address for writing is calculated as:
> (pagenum * FLASH_PAGE_SIZE)+0x00100000, with FLASH_PAGE_SIZE = 256.
> I would apreciate some help with this problem. Thanks in advance.
>
> Luiz Coelho

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.