/* Function for programming data to Flash. 
This function will check whether the data is greater than Flash page size. If it is greater, it splits and writes pagewise. */
static void program_memory(uint32_t address, uint8_t *buffer, uint16_t len)
/* Function for programming data to Flash. 
This function will check whether the data is greater than Flash page size. If it is greater, it splits and writes pagewise. */
static void program_memory(uint32_t address, uint8_t *buffer, uint16_t len)
{
	if (len > NVMCTRL_PAGE_SIZE) {
		uint32_t offset = 0;
		while (len > NVMCTRL_PAGE_SIZE) {
			if ((address & 0xFF) == 0) {
				nvm_erase_row(address);
			}
			nvm_write_buffer(address, buffer + offset, NVMCTRL_PAGE_SIZE);
			address += NVMCTRL_PAGE_SIZE;
			offset += NVMCTRL_PAGE_SIZE;
			len -= NVMCTRL_PAGE_SIZE;
		}
		if (len > 0) {
			nvm_write_buffer(address, buffer + offset, len);
		}
	} else {
		if ((address & 0xFF) == 0) {
			nvm_erase_row(address);
		}
		nvm_write_buffer(address, buffer, len);
	}
}