3.11 Read and Write Operation in Flash

Driver supports reading from and writing to flash region in the address range 0 to 63487.

The SAMD51 function for writing to flash region is DSCSAM_FLASHWrite and for reading from flash region is DSCSAM_FLASHRead.

Step-By-Step Instructions

For writing in to flash region, user need to provide the address to which the data has to be written as well as the BYTE data to be written in to flash region.

For reading from flash region, user need to provide the address from where the BYTE data has to be read as well as the address of the buffer to store the BYTE value read from the provided address.

...

ERRPARAMS errparams;  // structure for returning error code and error string
int Address;
BYTE data;

...

// To write a data 24 at address 46

data = 24;
Address = 46;

if( DSCSAM_FLASHWrite(Address,data) != DE_NONE )
{
    DSCGetLastError ( &errparams );
    printf ( "DSCSAM_FLASHWrite error: %s %s\n", DSCGetErrorString ( errparams.ErrCode ), errparams.errstring );
    return 0;
}

// To read a BYTE value from address 46

Address = 46;

if( DSCSAM_FLASHRead(Address,&data) != DE_NONE )
{
    DSCGetLastError ( &errparams );
    printf ( "DSCSAM_FLASHRead error: %s %s\n", DSCGetErrorString ( errparams.ErrCode ), errparams.errstring );
    return 0;
}
		
...

Last updated