lpcware

LPC1549  read/write EEPROM with IAP commands

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jul 20, 2017 by Juan Abelaira
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.

Outcomes