# FLASH

The flash memory software module allows the user code to read memory in the flash program space. Reading the flash is portable across all supported MCU’s. However, writing the flash is dependent on the MCU page size.

This interface is typically only used with the bootloader. The preferred way to access the flash is using the Memory (RAM/Flash) interface.

## Details

##### define FLASH_MIN_WRITE_SIZE

This defines the MCU specific value for the minimum write size. This is also the minimum step and alignment size for writing the flash.

##### define FLASH_MAX_WRITE_SIZE

This defines the MCU specific value for the maximum write size for a flash operation.

##### define I_FLASH_SETACTION

This request erases the page containing the specified address. The address is specified as the ctl argument.

ioctl(flash_fd, I_FLASH_ERASEADDR, (void*)0x00001000 );


##### define I_FLASH_ERASEPAGE

This request erases the page number specified by the ctl argument.

Example:

ioctl(flash_fd, I_FLASH_ERASEPAGE, 3); //erase page 3


##### define I_FLASH_GETPAGE

This request gets the page number for the specified address. The ctl argument is the address and the return value is the page.

Example:

int page;
page = ioctl(flash_fd, I_FLASH_GETPAGE, (void*)0x00001000 );


##### define I_FLASH_GETSIZE

This request gets the page number for the specified address. The ctl argument is the address and the return value is the page.

Example:

int page;
size = ioctl(flash_fd, I_FLASH_GET_PAGE);


##### define I_FLASH_GETPAGEINFO

This request gets the page number for the specified address. The ctl argument is the address and the return value is the page.

Example:

flash_pageinfo_t pageinfo;
page = ioctl(flash_fd, I_FLASH_GETPAGEINFO, &pageinfo );


##### define I_FLASH_WRITEPAGE

This request is used to write a page to the flash memory.

flash_writepage_t pwrite;
pwrite.addr = 0x1000; //this should be on a boundary for the minimum page size
pwrite.nbyte = 256;  //This has to be a valid page write value for the architecture
memcpy(pwrite.buf, my_data, pwrite.nbyte);
ioctl(flash_fd, I_FLASH_WRITEPAGE, &pwrite);


#### struct::flash_pageinfo_t

This data structure holds the details of a flash page.

#### struct::flash_writepage_t

This structure is used to write data to the flash using I_FLASH_WRITEPAGE.