External Flash usage

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

External Flash usage

Postby imtiaz » Thu Nov 10, 2016 6:36 pm

Hi,

I would like to use the external flash to store a binary image for a connected processor. Can someone give me some example code on how I can do that. The maximum size I need is 1 MByte.

Thanks
Imtiaz

bowen11
Posts: 1
Joined: Tue Nov 29, 2016 9:49 am

Re: External Flash usage

Postby bowen11 » Tue Nov 29, 2016 9:51 am


ESP_Sprite
Posts: 9046
Joined: Thu Nov 26, 2015 4:08 am

Re: External Flash usage

Postby ESP_Sprite » Tue Nov 29, 2016 1:25 pm

But seriously, you can do this multiple ways nowadays. The most elegant way probably is to use a custom partition table and declare an 1MB partition there. Then use the partition API to map that partition into memory and do what you want with the data in it.

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

Re: External Flash usage

Postby imtiaz » Mon Feb 27, 2017 10:34 pm

But seriously, you can do this multiple ways nowadays. The most elegant way probably is to use a custom partition table and declare an 1MB partition there. Then use the partition API to map that partition into memory and do what you want with the data in it.
Hi @ ESP_Sprite,@ESP_Angus

I am trying to memory map a region of external flash into a data region . It finds my partition and maps the region succesfully. However program crashes if I write data to it. Can you check this code .. I couldnt find any examples so Im probably doing something wrong. How are you supposed to read/write data to the mapped partition?

Code: Select all

const esp_partition_t *p = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, 0x80, NULL);
	if(p != NULL)
	{
		TRACE_D("MMap partition found\n");
	}
	else
	{
		TRACE_D("MMap partition NOT found\n");
	}

	 uint32_t *mmap_data;

	 spi_flash_mmap_handle_t mmap_handle;


	 if( esp_partition_mmap(p, 0, 2048000, SPI_FLASH_MMAP_DATA,
	                      (const void **)&mmap_data, &mmap_handle) == ESP_OK)
	 {
		 TRACE_D("Memory mappped\n");
	 }
	 else
	 {
		 TRACE_D("Memory map fail\n");
	 }

	 mmap_data[0] = 12345678; //This line causes crash
	 
	 if(mmap_data[0] == 12345678)
	 {
		 TRACE_D("test Pass\n");
	 }

ESP_Sprite
Posts: 9046
Joined: Thu Nov 26, 2015 4:08 am

Re: External Flash usage

Postby ESP_Sprite » Tue Feb 28, 2017 6:46 am

Memory-mapped flash is read-only because flashing doesn't happen transparently. (If anything because doing that would either make the hardware horrenduously complicated and/or non-power-fail-safe because of the way flash works.) Please use the normal SPI calls (esp_partition_erase_range/esp_partition_write) if you need to modify flash. See http://esp-idf.readthedocs.io/en/latest ... table-apis for the API reference for those, if you need it.

Who is online

Users browsing this forum: No registered users and 219 guests