IAP flash memory write and read in LPC804

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

IAP flash memory write and read in LPC804

1,203 Views
Sathiya_T
Contributor I

I included in my code to  given IAP_Flash_memory package in LPC804 , if any global variable to assign the ,that was not working properly,  last data is stored the IAP_CopyRamToFlash but soIAP_PrepareSectorForWritemetimes repeated  data i got so, how  i can read the data properly from IAP_CopyRamToFlash and IAP_PrepareSectorForWrite.

0 Kudos
Reply
4 Replies

1,184 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

The LPC804 has 32K Bytes(32KB) flash, the flash can be grouped by page and sector, one page consists of 64 bytes, one sector consists of 1K bytes or 16 oages, so there is 32 sector from sector0~sector 31, there are 512 pages from page0 to page511.

Because the application code is allocated as low address of flash, and the Page 510 and page 511 in sector 31 are not available for user code because of the boot block. so you have to write the flash between the end page of application code and the page 509.

xiangjun_rong_0-1692327050424.png

Secondly, the erase operation is based on sector, but programming operation is based on absolute address.

I suppose that you have referred to iap_flash example in the SDK package.

xiangjun_rong_1-1692327490666.png

The example use sector 14 with the macro:

#define DEMO_IAP_FLASH_SECTOR (14)

static uint32_t s_IapFlashPage =
(FSL_FEATURE_SYSCON_FLASH_SECTOR_SIZE_BYTES / FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES) * DEMO_IAP_FLASH_SECTOR;

so the page the example wrote is

the variable s_IapFlashPage is 14*(1024/64)=14*16=244 page, the absolute address is 244*64=15616 in decimal =0x3D00 with the following parameter:

(s_IapFlashPage + i) * FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES

so first parameter for api IAP_CopyRamToFlash() is the flash address.

If it is not what you expected, pls clarify your question, I am sorry.

This is the flash programming code:

IAP_PrepareSectorForWrite(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
status = IAP_CopyRamToFlash((s_IapFlashPage + i) * FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES, &s_PageBuf[0],
FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES, SystemCoreClock);

 

BR

XiangJun Rong

 

0 Kudos
Reply

987 Views
Loïc
Contributor I

Hi XiangJun Rong,

Per apps I can clarify his request ? (Because I have the same)

With the SDK of the LPC804 or the example for the LPC802, you can find the api IAP_CopyRamToFlash() to copy RAM to Flash as it said. But how can we do the opposite operation ?

I would like to read the Flash. Do I need to just use the address were it is store? Or Is there an api for that?

Maybe an api name "IAP_ReadInFlash" ? Or something similar to "iap_entry" ?

 

BR

Loïc

0 Kudos
Reply

982 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Generally, reading flash is the same as reading internal SRAM.

For example

uint32_t *u32Point=(uint32_t*) 0xxxxxxxxx; //flash address

uint32_t array[10];

uint32_t i;

main()

{

for (i=0; i<10; i++)

{

array[i]=*u32Point;

u32Point++;

}

Pls have a try;

BR

XiangJun Rong

0 Kudos
Reply

974 Views
Loïc
Contributor I

Hi,

I tried to adapt the code of iap_flash (example code of LPC802) with your code but I don't really understand what's happening.

You can tried with the project attach to the message.

But to summurize :

uint32_t *Addresse;

PRINTF("\r\nWriting flash sector %d\r\n", DEMO_IAP_FLASH_SECTOR);
    /* Erase sector before writing */
IAP_PrepareSectorForWrite(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
IAP_EraseSector(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR, SystemCoreClock);
    /* Generate data to be written to flash */
    for (i = 0; i < FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES; i++)
    {
        *(((uint8_t *)(&s_PageBuf[0])) + i) = 5;
        PRINTF("\r\n%d		%d",*(((uint8_t *)(&s_PageBuf[0])) + i),i);
    }
    /* Program sector */
    for (i = 0; i < s_IapFlashPageNum; i++)
    {
        IAP_PrepareSectorForWrite(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
        Addresse = (uint32_t*)(((s_IapFlashPage) + i) * FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES);
        PRINTF("\r\n%x	%d", *Addresse, Addresse);
        status = IAP_CopyRamToFlash(((s_IapFlashPage) + i) * FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES, &s_PageBuf[0], FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES, SystemCoreClock);
        PRINTF("\r\n%d	%d	%x", *(((uint8_t *)(&s_PageBuf[0])) + i),
((s_IapFlashPage + i) * FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES), *Addresse);   //Trying to display the addresse of the data and the data it self
        //Addresse++;
        if (status != kStatus_IAP_Success)
        {
            PRINTF("\r\nWrite to flash page failed\r\n");
            break;
        }
    }

And when I try to watch with the serial port, i have this output :

Writing flash sector 14

5 0

5 1

...

5 62

5 63

0 14336

5 14336 5050505

0 14400

5 14400 5050505

...

0 14464

5 15232 5050505

0 15296

5 15296 5050505

 

I don't really understand how it is store in the flash. Per apps du to the misunderstanding of the "iap_entry" function.

How this function works ? It's called in the "IAP_CopyRamToFlash" function but How does it work's after the "FSL_FEATURE_SYSCON_IAP_ENTRY_LOCATION" gateway ?

/* @brief Pointer to ROM IAP entry functions */
#define FSL_FEATURE_SYSCON_IAP_ENTRY_LOCATION (0x0F001FF1)


/*!
 * @brief IAP_ENTRY API function type.
 *
 * Wrapper for rom iap call.
 *
 * @Param cmd_param IAP command and relevant parameter array.
 * @Param status_result IAP status result array.
 */
static inline void iap_entry(uint32_t *cmd_param, uint32_t *status_result);

static inline void iap_entry(uint32_t *cmd_param, uint32_t *status_result)
{
    __disable_irq();
    ((IAP_ENTRY_T)FSL_FEATURE_SYSCON_IAP_ENTRY_LOCATION)(cmd_param, status_result);
    __enable_irq();
}

 

 

BR,

Loïc

0 Kudos
Reply