Writing to Flash in Thumb mode

OP #1172149
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
OP #1172150
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

A question of your own? This thread is over 19 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.