LPC1549 read/write EEPROM with IAP commands

cancel
Showing results for 
Search instead for 
Did you mean: 

LPC1549 read/write EEPROM with IAP commands

1,392 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gmatarrubia on Thu Mar 05 14:18:10 MST 2015
Hi,

I need to write/read some variables in EEPROM memory. I'm using mbed libraries that It doesn't have any API for that purpose. So I'm trying to use IAP commands. This is my code:

#include "mbed.h"

enum command_code
        {
            IAPCommand_EEPROM_Write = 61,
            IAPCommand_EEPROM_Read,
        };

#define     IAP_LOCATION    0x03000200
typedef     void (*IAP_call)(unsigned int [], unsigned int []);

IAP_call        iap_entry = reinterpret_cast<IAP_call>(IAP_LOCATION);
unsigned int    IAP_command[ 5 ];
unsigned int    IAP_result[ 5 ];
int             cclk_kHz = SystemCoreClock / 1000;

int write_eeprom( uint32_t source_addr, uint32_t target_addr, int size ) {
    IAP_command[ 0 ]    = IAPCommand_EEPROM_Write;
    IAP_command[ 1 ]    = target_addr;                           //  Destination EEPROM address where data bytes are to be written.
    IAP_command[ 2 ]    = (unsigned int)source_addr;    //  Source RAM address from which data bytes are to be read. This address should be a word boundary.
    IAP_command[ 3 ]    = size;                                        //  Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
    IAP_command[ 4 ]    = cclk_kHz;                                 //  CPU Clock Frequency (CCLK) in kHz.

    iap_entry( IAP_command, IAP_result );

    return ( (int)IAP_result[ 0 ] );
}

int main () {
    int num=15;
    int addrEEPROM = 0x100;
    while (1) {
        write_eeprom((uint32_t)&num,add,256);
    }
}


The code, IAP_LOCATION and so on is based on the datasheet. But I always get an "hardfault"

Someone knows how to read/write in the EEPROM?
regards.
Labels (1)
4 Replies

312 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gmatarrubia on Fri Mar 06 05:38:33 MST 2015
I had seen this example but I cannot use #include "chip.h" because I'm using #include "mbed.h" and I cannot use both at the same time.

I've just get a successful write/read in the EEPROM. I've added in mbed libraries the code necessary to use IAP commands.

regards.
0 Kudos

312 Views
athmesh_n
Contributor IV

is add the address of EEPROM? should we enter 0x03000100 or simply 0x100 is passed as EEPROM address?

write_eeprom((uint32_t)&num,add,256);
0 Kudos

312 Views
juanabelaira
Contributor III

... and no one can do a better thing than pointing to a useless example

312 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Mar 05 14:32:50 MST 2015
LPCOpen http://www.lpcware.com/content/nxpfile/lpcopen-software-development-platform-lpc15xx-packages

is including a sample: periph_eeprom, which should show you how to init / read and write  :) 

0 Kudos