EmbDev.net

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


Author: Luiz Coelho (lz-coelho)
Posted on:

Rate this post
0 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

Author: Luiz Coelho (lz-coelho)
Posted on:

Rate this post
0 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

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.