Reading and Writing FLASH at run time

OP #1174357
Environment details:

binutils:            2.18
arm-elf-gcc:     4.2.2
newlib:              1.16.0
Device:              AT91SAM7X256
Compiler:        IAR and GCC (for ARM)

Problem statement:
-- I am trying to port a code written for an AVR 8 bit controller
compiled for both IAR and GCC (for AVR). This code had an function which
basically writes and reads from FLASH using the keywords provided by IAR
and GCC for FLASH operations.

/*********************************USEFUL
CODE***************************************/
#if defined(_ICCAVR_)
    #define FLASH_DECLARE(x) __flash x
    #define FLASH_STRING(x) ((__flash const char *)(x))
    #define FLASH_STRING_T  char const __flash *
#endif

#if defined(_GNUC_)
   #define FLASH_DECLARE(x) x __attribute__((_progmem_))
   #define FLASH_STRING(x) PSTR(x)
   #define FLASH_STRING_T  PGM_P
#endif

void assert_test(bool expression, FLASH_STRING_T message,  int8_t *file,
                               uint16_t line)
{
    /* This function prints the provided assert message on serial using
UART */
}

#define ASSERT(expr)   assert_test(expr, FLASH_STRING( #expr ),
(int8_t*)__FILE__, _LINE_)

void main(void)
{
        ASSERT("Some string" == 0);
}

/*********************************USEFUL
CODE***************************************/

-- I am porting the above mentioned code for AT91SAM7X256 for IAR and
GCC both.

Question: Does GCC/IAR provide any way by which i can read and write the
FLASH at run time.
Moderator #1174358
Vinit Bidkar wrote:
>...
> Question: Does GCC/IAR provide any way by which i can read and write the
> FLASH at run time.

There is no special handling needed for "flash read" since there is only
one address-space in the used controller so there is no need for
something like LPM of the AVR. Just make sure the "variables"/constants
in flash are defined with const. Location can be verified with map- and
symbol-files.

Writing to flash similar to the self-programming-support on AVR can be
done with the EFC (see manual/datasheet). For an example-implementation
see the "basic-internalflash" project in Atmel's softpack for the
AT91SAM7X-EK.
#1174359
Hi,

I m not an expert of Atmel,
But i did it on a ARM9 STR912 from ST,

To do it, you need to load in RAM,
and execute from the RAM the piece
of code which will update the sector.

Doing it from flash will crash your
software (verified on STR912, at least)

Regards.

Damien.

Reply

A question of your own? This thread is over 18 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.