IAP How to know where to save a data

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IAP How to know where to save a data

4,406 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Sun Jul 26 22:56:01 MST 2015
Hello,

How to know where to save a data when using IAP. I would like saving data from array. User who have a system, will fill a data array and when data array is full, save into a EEPROM -(IAP) - other options. And when user turn on system, data available.

But I don't know on which location must saving data. I read AN10995 and in this is drawing table Figure 4 (sect. 3.1). I don't understand where saving a my program when programming and where save a data.

I see on LPCXpresso in the right click on project -> Properties -> In the section C/C++ build - MCU settings. I have options edit memory in LPC. My idea is: add Flash or Add RAM (I don't know which) who reserved just for my data. And then get  addresses and size of memory. I must have a 336 bits of memory for my data.  It's OK?

Please help me.


Labels (1)
0 Kudos
Reply
32 Replies

3,456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Thu Aug 13 00:58:49 MST 2015
OK, but I don't understand why is this:
(now code snippets if you cannot look in up attach project)

void eefill(uint8_t fillPattern)
{
uint32_t i, j, z;
z = (fillPattern << 24 | 
fillPattern << 16 |
fillPattern << 8|
fillPattern << 0 );

for (i = 0; i < EE_SIZE; i+=16)
{
for (j = 0; j < 16; j+=4)
{
writeEEPROM( (uint8_t*) i + j, 
 (uint8_t*) &z, sizeof(z));
}
}
}


Why I cannot set direct EEPROM address? Example
i = 0x00006000;
writeEEPROM( (uint8_t*) i,   (uint8_t*) &z, sizeof(z));



If i save:
case 4:
{
uint8_t* adr = 12;
writeEEPROM((uint8_t *) adr, &z, sizeof(z));
}


get warning Initialization makes pointer from integer without a cast
0 Kudos
Reply

3,456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Aug 12 23:50:42 MST 2015

Quote: drvrh
I testing my program with store in EEPROM on LPC11A14 now.



Modern LPC chips with EEPROM can access this EEPROM with IAP. So you just need to look in your user manual and use the IAP command to read / write EEPROM...
0 Kudos
Reply

3,456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Wed Aug 12 23:27:20 MST 2015
Yes for LPC1114 I create 256 B union and then first change bit by bit in union then store over IAP when timer interrupts flag ON. (every minute if union be change)

Sorry I forgot write before. I testing my program with store in EEPROM on LPC11A14 now. And I find example with EEPROM here.


I have a question it is possible save into EEPROM without this for statement, I don't understand why with for. It is possible save with address?
Program example in the zip file from up link. (zip -> EEPROM -> SRC -> EEPROMtEST)

0 Kudos
Reply

3,456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Aug 12 08:04:00 MST 2015

Quote: drvrh
...is it possible to store union in EEPROM. I have data in union. If yes, how?



:quest:

Are we talking about storing data in Flash via IAP?

If you are storing a 256 byte buffer via IAP just copy the union in that buffer before...

Or more elegant: create a 256 byte union (with all data you want to store) and store that union  ;-)

0 Kudos
Reply

3,456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Aug 12 08:03:59 MST 2015

Quote: drvrh
...is it possible to store union in EEPROM. I have data in union. If yes, how?



:quest:

Are we talking about storing data in Flash via IAP?

If you are storing a 256 byte buffer via IAP just copy the union in that buffer before...

Or more elegant: create a 256 byte union (with all data you want to store) and store that union  ;-)

0 Kudos
Reply

3,456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Wed Aug 12 05:53:21 MST 2015
Ok,
One questions, is it possible to store union in EEPROM. I have data in union. If yes, how?

for example this

union{
struct{
unsigned int  AM :24;
}dayAM;
struct{
unsigned int PM :24;
}dayPM;
}tDay[7];

0 Kudos
Reply

3,456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Jul 29 01:23:02 MST 2015

Quote: drvrh
Why not snippets?



Because it's incomplete. If you should describe a 'real' problem it's difficult to see what you are doing in detail...

We don't know which library you are using, which MCU we are talking about  :((

So it's useful to export and post a simple project (or at least a file) that is including everything and is debuggable  :)

At the moment it looks like your '250k peace' project is a 250k questions project...
0 Kudos
Reply

3,457 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Wed Jul 29 01:01:32 MST 2015
OK sorry, If  I debug I saw this mistake.

Why not snippets?
0 Kudos
Reply

3,457 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Jul 29 00:47:15 MST 2015

Quote: drvrh
First data save with this:

SaveIntoFlashINT(F_DRZAVA, 0);


Second data save with this:
uint16_t count = F_MOON;
SaveIntoFlashINT(count, 0);


On the top I have
#define F_DRZAVA 0x00006000
#define F_MOON                0x00006800

This's my function for save data:
void SaveIntoFlashINT(void* naslov, void* input_data){
unsigned int cfs = ((unsigned int)naslov >> 12);
unsigned int cfss = 1;
static uint32_t prestavljen_data = 0;
//#define CONFIG_FLASH_SECTOR_SIZE    1

   // Prepare the sector for erase
    iap_status = (__e_iap_status) iap_prepare_sector(cfs,
            (cfs + cfss));
    if (iap_status != CMD_SUCCESS) while(1);

    // Erase the sector
    iap_status = (__e_iap_status) iap_erase_sector(cfs,
            (cfs + cfss));
    if (iap_status != CMD_SUCCESS) while(1);

    // Prepare the sector for writing
    iap_status = (__e_iap_status) iap_prepare_sector(cfs,
            (cfs + cfss));
    if (iap_status != CMD_SUCCESS) while(1);
    prestavljen_data = input_data;
    // write data to flash
    iap_status = (__e_iap_status) iap_copy_ram_to_flash(&prestavljen_data,
            (void *)naslov, 256);
    if (iap_status != CMD_SUCCESS) while(1);
}


IAP class I don't change, and is the same as on the link in top post.



And again, code snippets  |(

You are deleting the complete sector  :quest:  And then you are surprised that it is deleted  :~
0 Kudos
Reply

3,457 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Wed Jul 29 00:36:42 MST 2015
First data save with this:

SaveIntoFlashINT(F_DRZAVA, 0);


Second data save with this:
uint16_t count = F_MOON;
SaveIntoFlashINT(count, 0);


On the top I have
#define F_DRZAVA 0x00006000
#define F_MOON                0x00006800

This's my function for save data:
void SaveIntoFlashINT(void* naslov, void* input_data){
unsigned int cfs = ((unsigned int)naslov >> 12);
unsigned int cfss = 1;
static uint32_t prestavljen_data = 0;
//#define CONFIG_FLASH_SECTOR_SIZE    1

   // Prepare the sector for erase
    iap_status = (__e_iap_status) iap_prepare_sector(cfs,
            (cfs + cfss));
    if (iap_status != CMD_SUCCESS) while(1);

    // Erase the sector
    iap_status = (__e_iap_status) iap_erase_sector(cfs,
            (cfs + cfss));
    if (iap_status != CMD_SUCCESS) while(1);

    // Prepare the sector for writing
    iap_status = (__e_iap_status) iap_prepare_sector(cfs,
            (cfs + cfss));
    if (iap_status != CMD_SUCCESS) while(1);
    prestavljen_data = input_data;
    // write data to flash
    iap_status = (__e_iap_status) iap_copy_ram_to_flash(&prestavljen_data,
            (void *)naslov, 256);
    if (iap_status != CMD_SUCCESS) while(1);
}


IAP class I don't change, and is the same as on the link in top post.



0 Kudos
Reply

3,457 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Wed Jul 29 00:18:53 MST 2015

Quote: drvrh
Hello,

I save data on 0x00006000 location, and next data save on location 0x00006100.
When I save second data get first data new value 255, I don't know why?



We don't know what you are doing because you don't post you code  :p

Probably you are deleting the sector? Or it is an Alien attack...
0 Kudos
Reply

3,457 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Wed Jul 29 00:10:15 MST 2015
Hello,

I save data on 0x00006000 location, and next data save on location 0x00006100.
When I save second data get first data new value 255, I don't know why?

0 Kudos
Reply

3,458 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Mon Jul 27 06:27:38 MST 2015

Quote: drvrh
I have a function
...
but now working.

When I move input_data from function and define variable in the start of program
static uint8_t input_data;


now working.

And very important is the variable must be static.




Please stop posting code snippets  |(

Post complete files or projects and describe the problem...


Quote:

but now working.

...
now working.



:quest:

And please read a C book, you probably don't know how parameter passing is working 

http://www.c4learn.com/c-programming/c-function-parameter-passing/
0 Kudos
Reply

3,458 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Mon Jul 27 06:11:14 MST 2015
I have a function

void SaveIntoFlashINT(uint8_t input_data){

.....
.....
    iap_status = (__e_iap_status) iap_copy_ram_to_flash(&input_data,
            (void *)CONFIG_FLASH_OFFSET, 256);
    if (iap_status != CMD_SUCCESS) while(1);
}

but now working.

When I move input_data from function and define variable in the start of program
static uint8_t input_data;


now working.

And very important is the variable must be static.
0 Kudos
Reply

3,457 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Mon Jul 27 06:02:55 MST 2015
Now I transfer function for write and read on the other clas, but here not working .

From prepare to write goes program without problem. When wrtie data into flash I get error:
 SRC_ADDR_ERROR,


why, when debuggin addres for flash is ( 24576) for ram addres is bigger number (268443575).

Why?
0 Kudos
Reply

3,458 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Mon Jul 27 04:55:29 MST 2015

Quote: TheFallGuy
So what about my comment

Quote:
Also, don't forget that when writing to flash, you need to be running from RAM...





That's not necessary for a simple IAP sector write with 'unused' sectors ;-)
0 Kudos
Reply

3,458 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Mon Jul 27 04:35:43 MST 2015
st = * ((uint8_t *) 0x00006000);


this is my pointer who call my value from storage. In storage I have

static uint8_t demo_messg = 123;


And I get beautiful 123 ....

Thank's for all, now I go programming for write and read array.

0 Kudos
Reply

3,458 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by drvrh on Mon Jul 27 04:16:28 MST 2015
Sorry. Yes my mistake. I'm not read this chapter.
Now I'm settings
#define CONFIG_FLASH_OFFSET            0x00006000


on this location. Now I must read.

I read from storage with pointer it's OK?
I post when I successful.


0 Kudos
Reply

3,458 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Mon Jul 27 04:07:11 MST 2015

Quote: drvrh
Now I'm set this, for location 25k because I don't have program here, my program is end with 21k size.
#define CONFIG_FLASH_OFFSET            0x61A8




Are you kidding us?

Which sector are you trying to use?

Read User manual Chapter 26.3.6 Flash configuration for LPC1100XL series...

0 Kudos
Reply

3,458 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Mon Jul 27 04:02:50 MST 2015

Quote: drvrh
...stopped when is Hard Fault Handler.



As R2D2 already posted, the usual Hard Fault error (no reserved IAP RAM) is described here:

https://www.lpcware.com/content/forum/storing-settings



0 Kudos
Reply