Internal Flash or EFC
Dear all,
HW: AT91SAM7x
Compiler: CrossWork GCC
OS: FreeRTOS 4.7
Any one has experience using the internal flash memory as an EEPROM data storage?
It is call Embedded Flash Controller (EFC) for AT91SAM7 family.
Any help on read and write on the last page of flash memory area in FreeRTOS will be much appreciate.
Thanks for ur attention
Regards
Hudson
Internal Flash or EFC
#define FLASH_PAGE_SIZE 256
#define FLASH_BASE_ADDRESS 0x00100000
#define SETTINGS_PAGE_NUMBER 1023
#define SETTINGS_PAGE ((int *)0x0013FF00)
/*
* I think this is not the best way to go but we need to
* put flash routines into the sram
*/
char flash_write(int *data, short data_length, short pagen) __attribute__ ((section (".data")));
inline int perform_command( char command, short pagen ) __attribute__ ((section (".data")));
void efc_test()
{
SETTINGS_PAGE[0] = 1; /* write sth to the beginning */
SETTINGS_PAGE[32] = 1;
SETTINGS_PAGE[64] = 1; /* write sth to the end */
flash_write(NULL, 0, SETTINGS_PAGE_NUMBER);
}
/*
* Flash programming
*/
inline int perform_command( char command, short pagen )
{
int i;
DISABLE_INTERRUPTS();
i = AT91C_BASE_MC->MC_FSR;
while( ( i & AT91C_MC_FRDY ) != AT91C_MC_FRDY )
i = AT91C_BASE_MC->MC_FSR;
AT91C_BASE_MC->MC_FCR = ( 0x5A << 24 ) | command | ( pagen << 8 );
i = AT91C_BASE_MC->MC_FSR;
while( ( i & AT91C_MC_FRDY ) != AT91C_MC_FRDY )
i = AT91C_BASE_MC->MC_FSR;
ENABLE_INTERRUPTS();
return i;
}
char flash_write(int *data, short data_length, short pagen)
{
int *addr_ptr = (int *)(FLASH_BASE_ADDRESS + pagen * FLASH_PAGE_SIZE);
int i;
if(data != NULL) {
for(i = 0; i < data_length; i++)
addr_ptr[i] = data[i];
}
i = perform_command( AT91C_MC_FCMD_START_PROG , pagen );
if( ( i & AT91C_MC_LOCKE ) == AT91C_MC_LOCKE )
return 1;
if( ( i & AT91C_MC_PROGE ) == AT91C_MC_PROGE )
return 2;
return 0;
}
Internal Flash or EFC
Thanks for your Help chaalar.
I am using "__attribute__ ((section (".fast")" instead of .data. but i guess they both put flash routines into the sram.
:)