Configuring ESP32 to execute from SPI RAM

User avatar
Vader_Mester
Posts: 300
Joined: Tue Dec 05, 2017 8:28 pm
Location: Hungary
Contact:

Configuring ESP32 to execute from SPI RAM

Postby Vader_Mester » Sun Jul 01, 2018 7:15 pm

I did ask something similar in another post, but I was not quite exact.

So, my question: is it possible to reconfigure the ESP to load execute from external RAM?
I guess that the secnd stage bootloader can be modified to achieve this, and I guess the MMU mapping must be modified.

Is technically possible, and did anyone try this yet?

Code: Select all

task_t coffeeTask()
{
	while(atWork){
		if(!xStreamBufferIsEmpty(mug)){
			coffeeDrink(mug);
		} else {
			xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
			xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
		}
	}
	vTaskDelete(NULL);
}

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Configuring ESP32 to execute from SPI RAM

Postby kolban » Mon Jul 02, 2018 12:00 am

I'm curious on the back story. What does loading an app into external RAM for execution buy you? Can you paint the picture of what your thinking is behind the question? How would you see it used? What advantages over the current story of loading from flash are present?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
Vader_Mester
Posts: 300
Joined: Tue Dec 05, 2017 8:28 pm
Location: Hungary
Contact:

Re: Configuring ESP32 to execute from SPI RAM

Postby Vader_Mester » Mon Jul 02, 2018 6:13 am

kolban wrote:I'm curious on the back story. What does loading an app into external RAM for execution buy you? Can you paint the picture of what your thinking is behind the question? How would you see it used? What advantages over the current story of loading from flash are present?
I was thinking about some home automation stuff, that what if I could stream my applications to the ESP device?
Since it's not a very file size heavy, basically within a second, you can have an different app running on your ESP.
This thing would be a UI heavy, and the users would select the running app from the screen, and ppl don't like waiting for an app to load, otherwise they will already keep wanting faster stuff :D
So I can have all the applications available for a user for checking on their home, without the need to largely pre-customize the system. (I can have a RPi on the network to store the applications, and stream from it.)
I stream down the app into the PSRAM, and do a reboot, with the app loading from PSRAM.

I also came here from the analogy, that essentially all computers load apps from a non volatile storage into a RAM.
If I want to load a completely different app, I have to reflash at the moment, which is quickly going to reduce my flash life, and it is very slow to write to.
This could be used also with an SD card as a source of applications.
If you combine it with 5-10years of usage, you may end up killing that flash sooner than you would think.
So it would be better to use the P-SRAM in this case.
I would have a flash here of course, for running the 2nd stage bootloader.
What I do get from the code is that the 2nd stage bootloader has things to do with to make this possible, which is read from flash obviously. So far it seems that the flash-interface is deeply hard coded into the ESP, so dunno how to do it realisticly.

But a man has to dream :)

Code: Select all

task_t coffeeTask()
{
	while(atWork){
		if(!xStreamBufferIsEmpty(mug)){
			coffeeDrink(mug);
		} else {
			xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
			xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
		}
	}
	vTaskDelete(NULL);
}

mikemoy
Posts: 627
Joined: Fri Jan 12, 2018 9:10 pm

Re: Configuring ESP32 to execute from SPI RAM

Postby mikemoy » Mon Jul 02, 2018 7:47 am

Vader_Mester, are you saying that even if you put all your apps onto flash, it would not fit into the ESP-WROOM-32 (16MB) version ?

User avatar
Vader_Mester
Posts: 300
Joined: Tue Dec 05, 2017 8:28 pm
Location: Hungary
Contact:

Re: Configuring ESP32 to execute from SPI RAM

Postby Vader_Mester » Mon Jul 02, 2018 8:51 am

That's not the point realy.

This idea was originally came into my mind when I was thinking about building a proper SBC using the ESP32 as it's base processor,
and use it like a Raspberry Pi, drop an SD card in to run your stuff from, and boom, or rather stream it through the web, and run it instantly, skipping the whole OTA process.
Primarily for makers, pushing the boundaries of what an ESP32 system can do with a couple of supporting circuitry, but not too expensive and big.
(you would have an ESP32, with it's stuff, flash, RAM, STM32 uC, FT813, power supply circuits, ethernet circuit, etc).

As said, this will have a UI, to control everything, in the form of a 5" 800x480 screen, a separate System Management Controller (SMC), which is just an ARM Cortex uC, which will just houskeep the board, control the display via an FT813 - independently from the ESP, handle USB OTG, for keyboard and mouse support later on (and have tons of GPIO pins).
I want to have an android-like UI, which is very possible with the FT813.

Imagine if you can run micropython scripts on your ESP based unit, without needing to touch your PC (type it on screen and run it). ;)
(I know I know, it's possible with just the flash but... well...)

The concept is a bit complex, but it would be awsome to have the capability to execute from RAM.
I just can't ignore the fact that flash has limited life time, and slow to write and read.

I just though, that it would be nice to have the capability developing an app without touching the flash, and just run stuff from an SD card for example, just pop an SD card in, or stream it from the Web or network, and run it from RAM.

I don't say it is a must, but a "What if". If the ESP is capable of this, then why not try? ... if it is capable.
... or mybe I am not fully capable to understand the ESP32 as it is now.

Code: Select all

task_t coffeeTask()
{
	while(atWork){
		if(!xStreamBufferIsEmpty(mug)){
			coffeeDrink(mug);
		} else {
			xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
			xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
		}
	}
	vTaskDelete(NULL);
}

mikemoy
Posts: 627
Joined: Fri Jan 12, 2018 9:10 pm

Re: Configuring ESP32 to execute from SPI RAM

Postby mikemoy » Mon Jul 02, 2018 12:45 pm

ok, I get it now.

RetroDISTORT
Posts: 4
Joined: Fri Oct 13, 2017 5:44 am

Re: Configuring ESP32 to execute from SPI RAM

Postby RetroDISTORT » Sun Jan 20, 2019 4:33 pm

I've been trying to do this for a while too. My attempt was to make a text file interpreter, which works perfectly. The one problem with this method was "slow" for time sensitive functions due to interpretation time.

Regardless, I also want to have the option to upload code in pSRAM. I bet we can work together to make it happen.
Some information I collected from my research may help us to start moving forward.

Currently I was looking ant information about partitions for the esp32. If it's possible to map the external ram to the partition table, then the next step would be to write the code into ram.
Here's a link to the partition section for the esp32:
https://docs.espressif.com/projects/esp ... partitions
Apparently pSRAM is allocated in a specific addressable location. According to the ESP32 Datasheet (Page 14 on paper), The address for external SRAM should be from 0x3F80_0000 to 0x3FBF_FFFF https://www.espressif.com/sites/default ... eet_en.pdf

Apparently, Python on ESP32 reads code directly from ram which should be a ggod sign that we are going in the right direction. Might it be possible to get some assistance from their team? :?:

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Configuring ESP32 to execute from SPI RAM

Postby WiFive » Mon Jan 21, 2019 2:15 pm

Psram is mapped into dram and the CPU cannot execute instructions from dram

RetroDISTORT
Posts: 4
Joined: Fri Oct 13, 2017 5:44 am

Re: Configuring ESP32 to execute from SPI RAM

Postby RetroDISTORT » Wed Jan 30, 2019 7:52 am

WiFive wrote:
Mon Jan 21, 2019 2:15 pm
Psram is mapped into dram and the CPU cannot execute instructions from dram
Thanks for the reply!

Would you happen to know if it is possible to move code from dram to IRAM on demand?

Probably my moving chunks of code at a time? Or at the very least short codes?

I really want to be able to load apps from an sd card or an external device on the go without having to re-write every time on (and shortening the life of) flash memory.
(I'm not sure if the IRAM_ATTR function may be used for this purpose)

Who is online

Users browsing this forum: No registered users and 81 guests