EmbDev.net

Forum: ARM programming with GCC/GNU tools Reading and Writing FLASH at run time


Author: Vinit Bidkar (vinitbidkar)
Posted on:

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

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

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

Author: Damien Hoyen (damien)
Posted on:

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

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.