Forums

Using flash mem for data-storrage

Started by "r.jensenm" April 17, 2008
Hi,

Im trying to use a flash mem section for data storrage and have
tried to implement the libmem example included in Crossstudio. I
have tried the code below but it gives me an error message?

Does anyone have an example on how to use the flash for data
storrage og might can tell me what is wrong wth the code below?

Regards Michael

************Std code from cross studio******************

int libmem_example_1(void)
{
const int flash1_max_geometry_regions = 4;
libmem_driver_handle_t flash1_handle;
libmem_geometry_t flash1_geometry[flash1_max_geometry_regions];
libmem_flash_info_t flash1_info;
uint8_t *flash1_start = (uint8_t *)0x10000000;
uint8_t *write_dest = flash1_start + 16;
const uint8_t write_data[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
int res;

// Register the FLASH LIBMEM driver
res = libmem_register_cfi_driver(&flash1_handle,
flash1_start,
flash1_geometry,
flash1_max_geometry_regions,
&flash1_info);
if (res != LIBMEM_STATUS_SUCCESS)
return 0;

// Unlock the destination memory area.
res = libmem_unlock(write_dest, sizeof(write_data));
if (res != LIBMEM_STATUS_SUCCESS)
return 0;

// Erase the destination memory area.
res = libmem_erase(write_dest, sizeof(write_data), 0, 0);
if (res != LIBMEM_STATUS_SUCCESS)
return 0;

// Copy write_data to the destination memory area.
res = libmem_write(write_dest, write_data, sizeof(write_data));
if (res != LIBMEM_STATUS_SUCCESS)
return 0;

// Complete any outstanding transactions and put FLASH memory
back into read mode.
res = libmem_flush();
if (res != LIBMEM_STATUS_SUCCESS)
return 0;

return 1;
}

error message: C:/MRJ/source/ARM/YCS_server/main.c:69: undefined
reference to `libmem_register_cfi_driver'

An Engineer's Guide to the LPC2100 Series

> Im trying to use a flash mem section for data storrage and have
> tried to implement the libmem example included in Crossstudio. I
> have tried the code below but it gives me an error message?
>
> Does anyone have an example on how to use the flash for data
> storrage og might can tell me what is wrong wth the code below?

If you're trying to program an external flash you can indeed use a CFI
driver if the external flash is CFI and you will need to add the libmem CFI
library to the linker inputs.

If you want to program internal flash, the is an LPC2000 libmem driver for
that, look in liblpc2000.h, IIRC.

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

Ive had a look at the header file liblpc2000.h but im still not
sure how to implement a flash storrage area and how to read/write to
it?

Do you know where to find an example?

Regards Michael

--- In l..., "Paul Curtis" wrote:
>
> > Im trying to use a flash mem section for data storrage and have
> > tried to implement the libmem example included in Crossstudio. I
> > have tried the code below but it gives me an error message?
> >
> > Does anyone have an example on how to use the flash for data
> > storrage og might can tell me what is wrong wth the code below?
>
> If you're trying to program an external flash you can indeed use a
CFI
> driver if the external flash is CFI and you will need to add the
libmem CFI
> library to the linker inputs.
>
> If you want to program internal flash, the is an LPC2000 libmem
driver for
> that, look in liblpc2000.h, IIRC.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
>

Hi,

> -----Original Message-----
> From: l... [mailto:l...] On
> Behalf Of r.jensenm
> Sent: 17 April 2008 15:24
> To: l...
> Subject: [lpc2000] Re: Using flash mem for data-storrage
>
> Thanks Paul,
>
> Ive had a look at the header file liblpc2000.h but im still not
> sure how to implement a flash storrage area and how to read/write to
> it?
>
> Do you know where to find an example?

The libmem flash library will allow you to erase and flash parts of chips.
It will also allow you to specify, register, or detect the geometry of the
target device (depends upon device though).

Libmem is completely documented--you can call the documented libmem
functions to erase and program sectors as long as you have registered a
driver for the region you're going to erase/program.

There's an example in the docs (which you seem to have found), or you can
just load the LPC2000 loader project and make some changes to see what
happens. Note that this will nuke your flash loader, so you might want to
back the changes out after you've fiddled.

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

Hi again,

I have tried to use some of the code from the loader_lpc2300.c but
cannot build it. my stripped down code looks like this:

#include
#include
#include
#include
#include

init_flash_mem()
{
libmem_driver_handle_t flash1_handle;

/* Initialise FLASH drivers */
liblpc2000_register_libmem_driver(&flash1_handle);

/* Run the loader - use the unused RAM */
libmem_rpc_loader_start(&__SRAM_segment_used_end__,
&__SRAM_segment_start__ + liblpc2000_get_ram_size());

}

I get the following errors:

undefined reference to `libmem_rpc_loader_start'
undefined reference to ibmem_register_driver'
:-) Michael

--- In l..., "Paul Curtis" wrote:
>
> > Im trying to use a flash mem section for data storrage and have
> > tried to implement the libmem example included in Crossstudio. I
> > have tried the code below but it gives me an error message?
> >
> > Does anyone have an example on how to use the flash for data
> > storrage og might can tell me what is wrong wth the code below?
>
> If you're trying to program an external flash you can indeed use a
CFI
> driver if the external flash is CFI and you will need to add the
libmem CFI
> library to the linker inputs.
>
> If you want to program internal flash, the is an LPC2000 libmem
driver for
> that, look in liblpc2000.h, IIRC.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
>

Hi,

> Hi again,
>
> I have tried to use some of the code from the loader_lpc2300.c but
> cannot build it. my stripped down code looks like this:
>
> #include
> #include
> #include
> #include
> #include init_flash_mem()
> {
> libmem_driver_handle_t flash1_handle;
>
> /* Initialise FLASH drivers */
> liblpc2000_register_libmem_driver(&flash1_handle);
>
> /* Run the loader - use the unused RAM */
> libmem_rpc_loader_start(&__SRAM_segment_used_end__,
> &__SRAM_segment_start__ + liblpc2000_get_ram_size());
>
> }
>
> I get the following errors:
>
> undefined reference to `libmem_rpc_loader_start'
> undefined reference to ibmem_register_driver'

You don't need to link in the RPC loader and you do need to link in the
libmem libraries.

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

So I just initialize a flash section for storring data by including
the header files without calling any functions - and then what?

how do I read and write to a ceratain section?

Regards Michael
--- In l..., "Paul Curtis" wrote:
>
> Hi,
>
> > Hi again,
> >
> > I have tried to use some of the code from the loader_lpc2300.c
but
> > cannot build it. my stripped down code looks like this:
> >
> > #include
> > #include
> > #include
> > #include
> > #include
> >
> > init_flash_mem()
> > {
> > libmem_driver_handle_t flash1_handle;
> >
> > /* Initialise FLASH drivers */
> > liblpc2000_register_libmem_driver(&flash1_handle);
> >
> > /* Run the loader - use the unused RAM */
> > libmem_rpc_loader_start(&__SRAM_segment_used_end__,
> > &__SRAM_segment_start__ + liblpc2000_get_ram_size());
> >
> > }
> >
> > I get the following errors:
> >
> > undefined reference to `libmem_rpc_loader_start'
> > undefined reference to ibmem_register_driver'
>
> You don't need to link in the RPC loader and you do need to link
in the
> libmem libraries.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
>

Michael,

You need to reserve some space to store data by editing the memory map--or
just don't use part of memory. To write to that memory you call the libmem
functions, after registering a driver for the memory area. The driver
doesn't allow you to rewrite arbitrary parts of memory, just erase and
program them using IAP. If you need to rewrite parts of memory, you need to
do a read-modify-erase-write.

-- Paul.
> -----Original Message-----
> From: l... [mailto:l...] On
> Behalf Of r.jensenm
> Sent: 21 April 2008 10:16
> To: l...
> Subject: [lpc2000] Re: Using flash mem for data-storrage
>
> Sorry for being such a newbie,
>
> So I just initialize a flash section for storring data by including
> the header files without calling any functions - and then what?
>
> how do I read and write to a ceratain section?
>
> Regards Michael
> --- In l..., "Paul Curtis" wrote:
> >
> > Hi,
> >
> > > Hi again,
> > >
> > > I have tried to use some of the code from the loader_lpc2300.c
> but
> > > cannot build it. my stripped down code looks like this:
> > >
> > > #include
> > > #include
> > > #include
> > > #include
> > > #include
> > >
> > > init_flash_mem()
> > > {
> > > libmem_driver_handle_t flash1_handle;
> > >
> > > /* Initialise FLASH drivers */
> > > liblpc2000_register_libmem_driver(&flash1_handle);
> > >
> > > /* Run the loader - use the unused RAM */
> > > libmem_rpc_loader_start(&__SRAM_segment_used_end__,
> > > &__SRAM_segment_start__ + liblpc2000_get_ram_size());
> > >
> > > }
> > >
> > > I get the following errors:
> > >
> > > undefined reference to `libmem_rpc_loader_start'
> > > undefined reference to ibmem_register_driver'
> >
> > You don't need to link in the RPC loader and you do need to link
> in the
> > libmem libraries.
> >
> > --
> > Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> > CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
> >
Paul,

I think we misunderstand each other - its probably because of my
lack of english scills etc.

Anyway Im getting a bit frustrated because Im still not able to
compile my project when including some of the libmem features.

If I open the loader.hzp project in the Philips_LPC210X folder and
activate the LPC2300 loader I can build it with no problems

If I include the same header files and add the same code in my main
I get errors like this: liblpc2000_flash.c:(.text.liblpc2000+0x2c8):
undefined reference to `libmem_get_sector_info'

I surpose it might has something to do with the project setup and
the *.s files???

I think I do understad how to read and write to a flash section but
need to be able to build the project. I have tried to compare the
setup of loader.hzp project and my project but dont know exactly
where to look for the error?

--- In l..., "Paul Curtis" wrote:
>
> Michael,
>
> You need to reserve some space to store data by editing the memory
map--or
> just don't use part of memory. To write to that memory you call
the libmem
> functions, after registering a driver for the memory area. The
driver
> doesn't allow you to rewrite arbitrary parts of memory, just erase
and
> program them using IAP. If you need to rewrite parts of memory,
you need to
> do a read-modify-erase-write.
>
> -- Paul.
>
>
> > -----Original Message-----
> > From: l... [mailto:l...] On
> > Behalf Of r.jensenm
> > Sent: 21 April 2008 10:16
> > To: l...
> > Subject: [lpc2000] Re: Using flash mem for data-storrage
> >
> > Sorry for being such a newbie,
> >
> > So I just initialize a flash section for storring data by
including
> > the header files without calling any functions - and then what?
> >
> > how do I read and write to a ceratain section?
> >
> > Regards Michael
> >
> >
> > --- In l..., "Paul Curtis" wrote:
> > >
> > > Hi,
> > >
> > > > Hi again,
> > > >
> > > > I have tried to use some of the code from the
loader_lpc2300.c
> > but
> > > > cannot build it. my stripped down code looks like this:
> > > >
> > > > #include
> > > > #include
> > > > #include
> > > > #include
> > > > #include
> > > >
> > > > init_flash_mem()
> > > > {
> > > > libmem_driver_handle_t flash1_handle;
> > > >
> > > > /* Initialise FLASH drivers */
> > > > liblpc2000_register_libmem_driver(&flash1_handle);
> > > >
> > > > /* Run the loader - use the unused RAM */
> > > > libmem_rpc_loader_start(&__SRAM_segment_used_end__,
> > > > &__SRAM_segment_start__ + liblpc2000_get_ram_size());
> > > >
> > > > }
> > > >
> > > > I get the following errors:
> > > >
> > > > undefined reference to `libmem_rpc_loader_start'
> > > > undefined reference to ibmem_register_driver'
> > >
> > > You don't need to link in the RPC loader and you do need to
link
> > in the
> > > libmem libraries.
> > >
> > > --
> > > Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> > > CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3
processors
> > >
> >
> >
> >
> >
> >
> >
Hi,

> I think we misunderstand each other - its probably because of my
> lack of english scills etc.
>
> Anyway Im getting a bit frustrated because Im still not able to
> compile my project when including some of the libmem features.
>
> If I open the loader.hzp project in the Philips_LPC210X folder and
> activate the LPC2300 loader I can build it with no problems
>
> If I include the same header files and add the same code in my main
> I get errors like this: liblpc2000_flash.c:(.text.liblpc2000+0x2c8):
> undefined reference to `libmem_get_sector_info'
>
> I surpose it might has something to do with the project setup and
> the *.s files???

No, you need to link in the library files that you need.

> I think I do understad how to read and write to a flash section but
> need to be able to build the project. I have tried to compare the
> setup of loader.hzp project and my project but dont know exactly
> where to look for the error?

Have a look at the Linker Additional Input Files which will link in the
libmem and liblpc2000 libraries.

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