LPC1788 IAP problem

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

LPC1788 IAP problem

569 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lazar92 on Fri May 08 02:48:46 MST 2015
I'm working on LPC1788, trying to use In Application Programming, and in one project where I implemented this code:

#define IAP_BASE1 0x00030000 
#define IAP_BASE2 0x00038000
#define IAP_BASE3 0x00040000 

    int main(void) {

        BYTE podatak1, podatak2, podatak3;
        DWORD *pointer_podatak1, *pointer_podatak2, *pointer_podatak3;
        uart0();

        NVIC_DisableIRQ(TIMER0_IRQn);   
        NVIC_DisableIRQ(TIMER1_IRQn);
        NVIC_DisableIRQ(UART0_IRQn);

        podatak1 = 0x33;
        podatak2 = 0x63;
        podatak3 = 0x84;

        iap_copy_to_flash(&podatak1, IAP_BASE1, 1);
        delay_1_ms();
        iap_copy_to_flash(&podatak2, IAP_BASE2, 1);
        delay_1_ms();
        iap_copy_to_flash(&podatak3, IAP_BASE3, 1);
        delay_1_ms();

        pointer_podatak1 = (DWORD*) IAP_BASE1;
        pointer_podatak2 = (DWORD*) IAP_BASE2;
        pointer_podatak3 = (DWORD*) IAP_BASE3;

        LPC_UART0->THR = *pointer_podatak1;
        delay_1_ms();
        LPC_UART0->THR = *pointer_podatak2;
        delay_1_ms();
        LPC_UART0->THR = *pointer_podatak3;
        delay_1_ms();

        while(1)
        {
        }

}

It works perfectly, but when I try to utilize it in my main project, I've got nothing written on flash memory locations I indicated. Here is the code in my main project to read and write from flash:

#define   OFFSET_ADDRESS                     0x00030000                                                                                     
#define   OFFSET_VERSION                     0x00038000
#define   OFFSET_SERIAL                      0x00040000

void write_to_flash (void)    {                    
BYTE i;
DWORD *pointer_podatak1, *pointer_podatak2, *pointer_podatak3;

    iap_copy_to_flash(&display_address, OFFSET_ADDRESS, 1);
    delay_1_ms();

    iap_copy_to_flash(&version, OFFSET_VERSION, 1);
    delay_1_ms();

    for (i=0;i<8;i++)     {

        iap_copy_to_flash(&serial_no, OFFSET_SERIAL+i, 1);
        delay_1_ms();

        }  
    }

void read_from_flash (void)   {                    

    BYTE i;
    DWORD *pok_add, *pok_ver, *pok_serial_no;

    pok_add = (DWORD*)OFFSET_ADDRESS;
    display_address = *pok_add;
    delay_1_ms();
    if ((display_address > MAX_OUTDOOR_DISPLAY_ADDRESS) || (display_address < MIN_OUTDOOR_DISPLAY_ADDRESS))  display_address = UNI_ADDRESS;


    pok_ver = (DWORD*)OFFSET_VERSION;
    version = *pok_ver;
    delay_1_ms();
    if (version > MAX_FW_VERSION)        version = 0;                      

    for (i=0;i<8;i++)     {
        pok_serial_no = (DWORD*)OFFSET_SERIAL;
        serial_no = *pok_serial_no++;
        delay_1_ms();
    }
    for (i=0;i<8;i++)         if (serial_no > 9)   serial_no = 0;      

}

display_address, version and serial_no[] are global variables which are forwarded to these two functions write_to_flash and read_from_flash. Anyone knows maybe what can cause the problem, even if the correct and working code is implemented in main project?
Labels (1)
0 Kudos
4 Replies

453 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mho on Mon May 11 09:51:31 MST 2015
Is your LPC1788 running at 120 MHz?
I had similar problems with 120 MHz (CCLK) and IAP calls but my LPC1788 has triggered a hard fault in this issue.

The work-around on the Errata Sheet is to call the IAP with a lower speed than 120 MHz.
0 Kudos

453 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon May 11 01:59:13 MST 2015
A source file, without context is completely pointless. Suggest you look at the differences between your working and non-working application - look at the map file, to see what is running where. For example, do you know that you can't be running from flash and programming it at the same time? Have you reserved the top of RAM as detailed in the IAP calls?
0 Kudos

453 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lazar92 on Mon May 11 01:09:48 MST 2015
I've attached iap library, so take a look, I don't know what's happening with code, in one project it works, but in the second it won't. Please help, thanks.
0 Kudos

453 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mc on Fri May 08 09:18:00 MST 2015
Hi lazar92,
I am not sure in you code what iap_copy_to_flash(...) function does? Could you please look into periph_flashiap project from LPCopen? See below link
http://www.lpcware.com/content/nxpfile/lpcopen-software-development-platform-lpc17xx-packages

LPCopen supports Keil, IAR and LPCXpresso development platforms.
0 Kudos