rfLPC
A low level library for using NXP's LPC17xx SoC. Config is given for MBED prototyping board
Flash memory In-Application Programming (IAP)

Functions

int rflpc_iap_get_serial_number (unsigned long result[4])
 Gets the flash serial number. More...
 
void * rflpc_iap_get_address_from_sector (int sector)
 Flash memory sector-address mapping. More...
 
int rflpc_iap_get_sector_from_address (const void *address)
 Flash memory address-sector mapping. More...
 
int rflpc_iap_prepare_sectors_for_writing (int start_sector, int end_sector)
 Prepare sectors for a writing operation (write/erase). More...
 
int rflpc_iap_erase_sectors (int start_sector, int end_sector)
 Erase Flash sectors. More...
 
int rflpc_iap_copy_ram_to_flash (const void *destination, const void *source, int length)
 Copy RAM to Flash. More...
 
int rflpc_iap_write_buffer_to_sector (const void *buffer, int sector_number)
 Copy a 4k buffer to Flash. More...
 
int rflpc_iap_write_to_sector (const void *destination, const void *buffer, int length)
 Copy a buffer <= 4K to Flash. More...
 
int rflpc_iap_write_buffer (const void *destination, const void *buffer, int length)
 Copy a buffer to Flash. More...
 
int rflpc_iap_transfert_4ks_to_32k (const void *destination32k, const void *source4ks, int length)
 Transfer memory from the 4k sectors to one 32k sector. More...
 

Detailed Description

Function Documentation

int rflpc_iap_copy_ram_to_flash ( const void *  destination,
const void *  source,
int  length 
)

Copy RAM to Flash.

After preparing the sectors, call this function to write RAM contents to flash

Parameters
[out]destinationdestination Flash address where bytes are to be written. Should be a 256 bytes boundary.
[in]sourcesource RAM address from which bytes are to be read. Should be a word boundary.
[in]lengththe number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
Returns
0 if successful, -1 otherwise
int rflpc_iap_erase_sectors ( int  start_sector,
int  end_sector 
)

Erase Flash sectors.

After preparing the sectors, call this function to erase Flash sectors contents.

void* rflpc_iap_get_address_from_sector ( int  sector)

Flash memory sector-address mapping.

Use this function when an address is needed for a given sector.

Parameters
[in]sectora sector identifier
Returns
the start address of the sector
int rflpc_iap_get_sector_from_address ( const void *  address)

Flash memory address-sector mapping.

For a given address, returns the sector it belongs to.

Parameters
[in]address
Returns
the sector.
int rflpc_iap_get_serial_number ( unsigned long  result[4])

Gets the flash serial number.

This can be used to uniquely identify the LPC17xx running the program.

Parameters
[out]resultthe serial number as four 32 bits word
Returns
0 if successful, -1 otherwise
int rflpc_iap_prepare_sectors_for_writing ( int  start_sector,
int  end_sector 
)

Prepare sectors for a writing operation (write/erase).

Needed to unprotect the sectors for the writing operation.

Parameters
[in]start_sectora valid sector to start with.
[in]end_sectorshould be greater than or equal to start_sector.
Returns
0 if successful, -1 otherwise
int rflpc_iap_transfert_4ks_to_32k ( const void *  destination32k,
const void *  source4ks,
int  length 
)

Transfer memory from the 4k sectors to one 32k sector.

Parameters
[in]destination32k
[in]source4ksmemory lying into 4ks sectors.
[in]lengthlength of the destination <= 32k.
Returns
0 if successful, negative otherwise
int rflpc_iap_write_buffer ( const void *  destination,
const void *  buffer,
int  length 
)

Copy a buffer to Flash.

This function handles multiple sectors overlap.

Parameters
[in]destination
[in]buffera buffer.
[in]length
Returns
0 if successful, -1 otherwise
int rflpc_iap_write_buffer_to_sector ( const void *  buffer,
int  sector_number 
)

Copy a 4k buffer to Flash.

Parameters
[in]buffera 4K buffer.
[in]sector_numbersee nxp user's manual.
Returns
0 if successful, -1 otherwise
int rflpc_iap_write_to_sector ( const void *  destination,
const void *  buffer,
int  length 
)

Copy a buffer <= 4K to Flash.

If the buffer is over multiple sectors the function returns -1.

Parameters
[in]destination
[in]buffera buffer less than or equal to 4K, inside the same sector.
[in]lengthlength of the buffer (<= 4k).
Returns
0 if successful, -1 otherwise