EmbeddedRelated.com
Forums

AT91SAM7X256 internal flash read write with Rowley's CrossStudio

Started by ckchan_4 September 5, 2008
Hi guys,

Anybody have done the internal flash read & write from CrossStudio
project ? I've downloaded Atmel's internal flash project, but those
are for gcc and IAR compiler..

i tried to port over to CrossStudio, but i'm stuck at setting the
function to run in RAM

for IAR, it's __ramfunc

for gcc, it's __attribute__ ((section (".ramfunc")))

what is for CrossStudio ?

Thanks for your time !

Hi,

To run in ram, put it in the .fast section.

Note that there is already a libmem driver for the SAM7X (which the flash
loader uses) so you can, if you wish, register the flash driver with libmem.

e.g. the loader uses this:

/* Register FLASH driver */
libat91sam7_register_libmem_driver(&flash1_handle, 48000000);

The first parameter is a handle, the second is the CPU frequency (48MHz, in
this case).

Once done, you can just write to flash as you wish.

Rgds,

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors

> -----Original Message-----
> From: A... [mailto:A...] On Behalf
Of
> ckchan_4
> Sent: 05 September 2008 10:59
> To: A...
> Subject: [AT91SAM] AT91SAM7X256 internal flash read write with Rowley's
> CrossStudio
>
> Hi guys,
>
> Anybody have done the internal flash read & write from CrossStudio
> project ? I've downloaded Atmel's internal flash project, but those
> are for gcc and IAR compiler..
>
> i tried to port over to CrossStudio, but i'm stuck at setting the
> function to run in RAM
>
> for IAR, it's __ramfunc
>
> for gcc, it's __attribute__ ((section (".ramfunc")))
>
> what is for CrossStudio ?
>
> Thanks for your time !
>
Thank you very much Paul.. shall try it out first thing coming monday :)

--- In A..., "Paul Curtis" wrote:
>
> Hi,
>
> To run in ram, put it in the .fast section.
>
> Note that there is already a libmem driver for the SAM7X (which the
flash
> loader uses) so you can, if you wish, register the flash driver with
libmem.
>
> e.g. the loader uses this:
>
> /* Register FLASH driver */
> libat91sam7_register_libmem_driver(&flash1_handle, 48000000);
>
> The first parameter is a handle, the second is the CPU frequency
(48MHz, in
> this case).
>
> Once done, you can just write to flash as you wish.
>
> Rgds,
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
> > -----Original Message-----
> > From: A... [mailto:A...] On
Behalf
> Of
> > ckchan_4
> > Sent: 05 September 2008 10:59
> > To: A...
> > Subject: [AT91SAM] AT91SAM7X256 internal flash read write with
Rowley's
> > CrossStudio
> >
> > Hi guys,
> >
> > Anybody have done the internal flash read & write from CrossStudio
> > project ? I've downloaded Atmel's internal flash project, but those
> > are for gcc and IAR compiler..
> >
> > i tried to port over to CrossStudio, but i'm stuck at setting the
> > function to run in RAM
> >
> > for IAR, it's __ramfunc
> >
> > for gcc, it's __attribute__ ((section (".ramfunc")))
> >
> > what is for CrossStudio ?
> >
> > Thanks for your time !
> >
> >
> >
> >
> >
> >
> >
i've tried using libmem library, manage to link the lib and register
the driver.

however, when i tried to unlock the page, it returns -5 which is
LIBMEM_STATUS_NO_DRIVER

what went wrong ? thanks
following is the codes i used, most of it is sample provided..

/************** begin *******************/
void TestFlash( void )
{
libmem_driver_handle_t flash_handle;
uint8_t buffer[64];
const uint8_t write_data[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
int res;

// last page of internal flash
uint8_t *nvm_dest = (uint8_t *)0x0013F00;

/* Register FLASH driver */
libat91sam7_register_libmem_driver(&flash_handle, 48000000);

/* read initial data */
res = libmem_read(buffer, nvm_dest , sizeof(buffer));
if (res == LIBMEM_STATUS_SUCCESS)
{
printf("d1 : (%d)\n", buffer[0]);
}

/* Unlock the destination memory area */
res = libmem_unlock(nvm_dest, sizeof(write_data));
if (res != LIBMEM_STATUS_SUCCESS)
{
printf("unlock:(%d)\n", res);
}

/* Erase the destination memory area */
res = libmem_erase(nvm_dest, sizeof(write_data), 0, 0);
if (res != LIBMEM_STATUS_SUCCESS)
{
printf("erase:(%d)\n", res);
}

/* Copy write_data to the destination memory area */
res = libmem_write(nvm_dest, write_data, sizeof(write_data));
if (res != LIBMEM_STATUS_SUCCESS)
{
printf("write:(%d)\n", res);
}

/* Complete any outstanding transactions and */
/* put FLASH memory back into read mode */
res = libmem_flush();
if (res != LIBMEM_STATUS_SUCCESS)
{
printf("flush:(%d)\n", res);
}

// read again to confirm
res = libmem_read(buffer, nvm_dest , sizeof(buffer));
if (res == LIBMEM_STATUS_SUCCESS)
{
printf("d2 : (%d)\n", buffer[0]);
}
}

/************** end *******************/
--- In A..., "ckchan_4" wrote:
>
> Thank you very much Paul.. shall try it out first thing coming monday :)
>
> --- In A..., "Paul Curtis" wrote:
> >
> > Hi,
> >
> > To run in ram, put it in the .fast section.
> >
> > Note that there is already a libmem driver for the SAM7X (which the
> flash
> > loader uses) so you can, if you wish, register the flash driver with
> libmem.
> >
> > e.g. the loader uses this:
> >
> > /* Register FLASH driver */
> > libat91sam7_register_libmem_driver(&flash1_handle, 48000000);
> >
> > The first parameter is a handle, the second is the CPU frequency
> (48MHz, in
> > this case).
> >
> > Once done, you can just write to flash as you wish.
> >
> > Rgds,
> >
> > --
> > Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> > CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: A... [mailto:A...] On
> Behalf
> > Of
> > > ckchan_4
> > > Sent: 05 September 2008 10:59
> > > To: A...
> > > Subject: [AT91SAM] AT91SAM7X256 internal flash read write with
> Rowley's
> > > CrossStudio
> > >
> > > Hi guys,
> > >
> > > Anybody have done the internal flash read & write from CrossStudio
> > > project ? I've downloaded Atmel's internal flash project, but those
> > > are for gcc and IAR compiler..
> > >
> > > i tried to port over to CrossStudio, but i'm stuck at setting the
> > > function to run in RAM
> > >
> > > for IAR, it's __ramfunc
> > >
> > > for gcc, it's __attribute__ ((section (".ramfunc")))
> > >
> > > what is for CrossStudio ?
> > >
> > > Thanks for your time !
> > >
> > >
> > >
> > >
> > >
> > >
> > >
what went wrong is this

// last page of internal flash
uint8_t *nvm_dest = (uint8_t *)0x0013F00; <-- wrong typo

uint8_t *nvm_dest = (uint8_t *)0x0013FF00; <-- correct address
--- In A..., "ckchan_4" wrote:
>
> i've tried using libmem library, manage to link the lib and register
> the driver.
>
> however, when i tried to unlock the page, it returns -5 which is
> LIBMEM_STATUS_NO_DRIVER
>
> what went wrong ? thanks
> following is the codes i used, most of it is sample provided..
>
> /************** begin *******************/
> void TestFlash( void )
> {
> libmem_driver_handle_t flash_handle;
> uint8_t buffer[64];
> const uint8_t write_data[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
> int res;
>
> // last page of internal flash
> uint8_t *nvm_dest = (uint8_t *)0x0013F00;
>

Paul,

do i need to unlock, erase, write, lock and flush in the sequence ?
if i do that, i only get to run up to "read1: (2)". registration
returns 1, "reg: (1)" which is ok.

it didnt get to print "unlock: .. and just hung there and i have to
power cycle it/reset the board

thanks for your time Paul

/***********************************************************/
void NewTestFlash( void )
{
libmem_driver_handle_t flash_handle;
uint8_t buffer[64];
int res;

// last page of internal flash
uint8_t *nvm_dest = (uint8_t *)0x0013FF00;

/* Register FLASH driver */
res = libat91sam7_register_libmem_driver(&flash_handle, 48000000);
printf("reg : (%d)\n", res);

///* read initial data
res = libmem_read(buffer, nvm_dest , 1);
printf("read1 : (%d)\n", buffer[0]);

buffer[0] = buffer[0] + 1;

//* Unlock the destination memory area
res = libmem_unlock(nvm_dest, 256);
printf("unlock:(%d)\n", res);

// * Erase the destination memory area
res = libmem_erase(nvm_dest, 256, 0, 0);
printf("erase:(%d)\n", res);

//* Copy write_data to the destination memory area
res = libmem_write(nvm_dest, buffer, 1);
printf("write:(%d)\n", res);

//* Complete any outstanding transactions and
//* put FLASH memory back into read mode
res = libmem_flush();
printf("flush:(%d)\n", res);

// read again to confirm
res = libmem_read(buffer, nvm_dest , 1);
printf("read2 : (%d)\n", buffer[0]);
}

Hello,
I know what you are talking about when you say that the downloaded projects can only be run by GCC or IAR. However, I also do't think it is a very easy job to go ahead and use CrossStudio. I assume you mean to use the debug features? I have not exactly had complete success with debug on my home built JTAG. But I want to say this, that the best solution is the ECLIPSE and GCC solution, together with OPENOCD as the JTAG solution. I know it sounds crazy because most of these tools are real problem to work with, but I am saying if you are putting in so much effort, put it into that, since it can be tested by everyone.
Thank you and to success.

----- Original Message ----
From: ckchan_4
To: A...
Sent: Monday, September 8, 2008 12:13:38 PM
Subject: [AT91SAM] Re: AT91SAM7X256 internal flash read write with Rowley's CrossStudio
i've tried using libmem library, manage to link the lib and register
the driver.

however, when i tried to unlock the page, it returns -5 which is
LIBMEM_STATUS_ NO_DRIVER

what went wrong ? thanks

following is the codes i used, most of it is sample provided..

/*********** *** begin ************ *******/
void TestFlash( void )
{
libmem_driver_ handle_t flash_handle;
uint8_t buffer[64];
const uint8_t write_data[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
int res;

// last page of internal flash
uint8_t *nvm_dest = (uint8_t *)0x0013F00;

/* Register FLASH driver */
libat91sam7_ register_ libmem_driver( &flash_handle, 48000000);

/* read initial data */
res = libmem_read( buffer, nvm_dest , sizeof(buffer) );
if (res == LIBMEM_STATUS_ SUCCESS)
{
printf("d1 : (%d)\n", buffer[0]);
}

/* Unlock the destination memory area */
res = libmem_unlock( nvm_dest, sizeof(write_ data));
if (res != LIBMEM_STATUS_ SUCCESS)
{
printf("unlock: (%d)\n", res);
}

/* Erase the destination memory area */
res = libmem_erase( nvm_dest, sizeof(write_ data), 0, 0);
if (res != LIBMEM_STATUS_ SUCCESS)
{
printf("erase: (%d)\n", res);
}

/* Copy write_data to the destination memory area */
res = libmem_write( nvm_dest, write_data, sizeof(write_ data));
if (res != LIBMEM_STATUS_ SUCCESS)
{
printf("write: (%d)\n", res);
}

/* Complete any outstanding transactions and */
/* put FLASH memory back into read mode */
res = libmem_flush( );
if (res != LIBMEM_STATUS_ SUCCESS)
{
printf("flush: (%d)\n", res);
}

// read again to confirm
res = libmem_read( buffer, nvm_dest , sizeof(buffer) );
if (res == LIBMEM_STATUS_ SUCCESS)
{
printf("d2 : (%d)\n", buffer[0]);
}
}

/*********** *** end ************ *******/

--- In AT91SAM@yahoogroups .com, "ckchan_4" wrote:
>
> Thank you very much Paul.. shall try it out first thing coming monday :)
>
> --- In AT91SAM@yahoogroups .com, "Paul Curtis" wrote:
> >
> > Hi,
> >
> > To run in ram, put it in the .fast section.
> >
> > Note that there is already a libmem driver for the SAM7X (which the
> flash
> > loader uses) so you can, if you wish, register the flash driver with
> libmem.
> >
> > e.g. the loader uses this:
> >
> > /* Register FLASH driver */
> > libat91sam7_ register_ libmem_driver( &flash1_handle, 48000000);
> >
> > The first parameter is a handle, the second is the CPU frequency
> (48MHz, in
> > this case).
> >
> > Once done, you can just write to flash as you wish.
> >
> > Rgds,
> >
> > --
> > Paul Curtis, Rowley Associates Ltd http://www.rowley. co.uk
> > CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: AT91SAM@yahoogroups .com [mailto:AT91SAM@yahoogroups .com] On
> Behalf
> > Of
> > > ckchan_4
> > > Sent: 05 September 2008 10:59
> > > To: AT91SAM@yahoogroups .com
> > > Subject: [AT91SAM] AT91SAM7X256 internal flash read write with
> Rowley's
> > > CrossStudio
> > >
> > > Hi guys,
> > >
> > > Anybody have done the internal flash read & write from CrossStudio
> > > project ? I've downloaded Atmel's internal flash project, but those
> > > are for gcc and IAR compiler..
> > >
> > > i tried to port over to CrossStudio, but i'm stuck at setting the
> > > function to run in RAM
> > >
> > > for IAR, it's __ramfunc
> > >
> > > for gcc, it's __attribute_ _ ((section (".ramfunc") ))
> > >
> > > what is for CrossStudio ?
> > >
> > > Thanks for your time !
> > >
> > >
> > >
> > >
> > > ------------ --------- --------- ------
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
>
hi Maziar,

i actually wanted to use internal flash as NVM storage for some
setting parameters. but i did have problem with connecting the JTAG
(JLink connected but when start debug, it says "cannot stop CPU") :)
but that is another problem (and another thread) to worry about..

anyway, here is the latest update.. i manage to write into the flash !

void TestFlashOK( void )
{
/* Register FLASH driver */
res = libat91sam7_register_libmem_driver(&flash_handle, 48000000);

// read initial data
res = libmem_read(buffer, nvm_dest , 256);
// update data
buffer[0] = buffer[0] + 1;

// Copy write_data to the destination memory area
res = libmem_write(nvm_dest, buffer, 256);

/* board will hang after executing the above !! */
/* reset the board to run, updated data is in flash */
}

but i have to reset the board as it will hang after flash writing.. is
this the way it suppose to work ?

--- In A..., Maziar Tasbihi wrote:
>
> Hello,
> I know what you are talking about when you say that the downloaded
projects can only be run by GCC or IAR. However, I also do't think it
is a very easy job to go ahead and use CrossStudio. I assume you mean
to use the debug features? I have not exactly had complete success
with debug on my home built JTAG. But I want to say this, that the
best solution is the ECLIPSE and GCC solution, together with OPENOCD
as the JTAG solution. I know it sounds crazy because most of these
tools are real problem to work with, but I am saying if you are
putting in so much effort, put it into that, since it can be tested by
everyone.
> Thank you and to success.

Hi,

are you executing FLASH erase/write operations from RAM? Check your map
file to see if libmem functions are mapped to
RAM.

Foltos

ckchan_4 wrote:
>
> hi Maziar,
>
> i actually wanted to use internal flash as NVM storage for some
> setting parameters. but i did have problem with connecting the JTAG
> (JLink connected but when start debug, it says "cannot stop CPU") :)
> but that is another problem (and another thread) to worry about..
>
> anyway, here is the latest update.. i manage to write into the flash !
>
> void TestFlashOK( void )
> {
> /* Register FLASH driver */
> res = libat91sam7_register_libmem_driver(&flash_handle, 48000000);
>
> // read initial data
> res = libmem_read(buffer, nvm_dest , 256);
> // update data
> buffer[0] = buffer[0] + 1;
>
> // Copy write_data to the destination memory area
> res = libmem_write(nvm_dest, buffer, 256);
>
> /* board will hang after executing the above !! */
> /* reset the board to run, updated data is in flash */
> }
>
> but i have to reset the board as it will hang after flash writing.. is
> this the way it suppose to work ?
>
> --- In A... ,
> Maziar Tasbihi wrote:
> >
> > Hello,
> > I know what you are talking about when you say that the downloaded
> projects can only be run by GCC or IAR. However, I also do't think it
> is a very easy job to go ahead and use CrossStudio. I assume you mean
> to use the debug features? I have not exactly had complete success
> with debug on my home built JTAG. But I want to say this, that the
> best solution is the ECLIPSE and GCC solution, together with OPENOCD
> as the JTAG solution. I know it sounds crazy because most of these
> tools are real problem to work with, but I am saying if you are
> putting in so much effort, put it into that, since it can be tested by
> everyone.
> > Thank you and to success.
>
>
Hi there, about the problem that you say it becomes necessary to reset the board; it is true that I also have experienced this. I am sorry that I cannot at the moment provide better answer in terms of code sequence to use to test this, but I know this that it is necessary to perform reset after you have loaded flash with the new program, and the reset controller handles this, both via hardware or software.
So, I believe what has to be looked at, is what do the program samples which ATMEL provide have in common which donot require the reset performed manually, to look at linker script for example, etc. Thank you and regards.

----- Original Message ----
From: ckchan_4
To: A...
Sent: Tuesday, September 9, 2008 7:46:56 AM
Subject: [AT91SAM] Re: AT91SAM7X256 internal flash read write with Rowley's CrossStudio - solved ?
hi Maziar,

i actually wanted to use internal flash as NVM storage for some
setting parameters. but i did have problem with connecting the JTAG
(JLink connected but when start debug, it says "cannot stop CPU") :)
but that is another problem (and another thread) to worry about..

anyway, here is the latest update.. i manage to write into the flash !

void TestFlashOK( void )
{
/* Register FLASH driver */
res = libat91sam7_ register_ libmem_driver( &flash_handle, 48000000);

// read initial data
res = libmem_read( buffer, nvm_dest , 256);
// update data
buffer[0] = buffer[0] + 1;

// Copy write_data to the destination memory area
res = libmem_write( nvm_dest, buffer, 256);

/* board will hang after executing the above !! */
/* reset the board to run, updated data is in flash */
}

but i have to reset the board as it will hang after flash writing.. is
this the way it suppose to work ?

--- In AT91SAM@yahoogroups .com, Maziar Tasbihi wrote:
>
> Hello,
> I know what you are talking about when you say that the downloaded
projects can only be run by GCC or IAR. However, I also do't think it
is a very easy job to go ahead and use CrossStudio. I assume you mean
to use the debug features? I have not exactly had complete success
with debug on my home built JTAG. But I want to say this, that the
best solution is the ECLIPSE and GCC solution, together with OPENOCD
as the JTAG solution. I know it sounds crazy because most of these
tools are real problem to work with, but I am saying if you are
putting in so much effort, put it into that, since it can be tested by
everyone.
> Thank you and to success.