How to use internal flash ?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Saito
Posts: 4
Joined: Mon Aug 27, 2018 8:03 am

How to use internal flash ?

Post by Saito » Wed Sep 05, 2018 2:03 am

Dear All,

I want to stash few data in internal flash for next power up. I can read/write internal flash by
print(esp.flash_user_start())
>>2097152
so I write data to 2097152:
>>esp.flash_write(2097152, buf)
Then I ruin fat32 table....

How do I know the actual code size, Read-Only(constant) size and R/W size ?
I want to know how much flash size I can use to store some data.

Thank you all for reading this question.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How to use internal flash ?

Post by Roberthh » Wed Sep 05, 2018 5:52 am

The mostz obvious method would writing your data into a file, e.g. using the JSON methods. If you like to use direct write to flash, you have to adapt the driver for that file system, which is in modules/flashbdev.py. In line 6 there is the definition of START_SEC, which defines the fist address of the file system. You may add a few sector (4096 bytes each) to get room for your data.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: How to use internal flash ?

Post by OutoftheBOTS_ » Wed Sep 05, 2018 7:49 am

You can use the standard python file handling in Micro-Python. see bottom of this page https://docs.python.org/3/tutorial/inputoutput.html

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: How to use internal flash ?

Post by jickster » Wed Sep 05, 2018 1:35 pm

OutoftheBOTS_ wrote:You can use the standard python file handling in Micro-Python. see bottom of this page https://docs.python.org/3/tutorial/inputoutput.html
That assumes you’re running on top of an OS.

If you’re running on bare metal, those won’t work


Sent from my iPhone using Tapatalk Pro

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How to use internal flash ?

Post by Roberthh » Wed Sep 05, 2018 1:39 pm

@salto seems to work with an ESP32 or ESP8266, and mentioned, that his first attempts damaged the FAT. So there is a file system.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: How to use internal flash ?

Post by OutoftheBOTS_ » Wed Sep 05, 2018 9:04 pm

jickster wrote:
Wed Sep 05, 2018 1:35 pm
OutoftheBOTS_ wrote:You can use the standard python file handling in Micro-Python. see bottom of this page https://docs.python.org/3/tutorial/inputoutput.html
That assumes you’re running on top of an OS.

If you’re running on bare metal, those won’t work


Sent from my iPhone using Tapatalk Pro
So far I have used MP on ESP8266, ESP32 and STM32F7 and I have just used standard python file handing to create/edit files on both flash and SD and all 3 platforms. As far as I was aware this is some of the special magic performed by MP.

As far as I am aware it works similar to how a SSD (PC flash storage) works on a PC, It creates a boot sector for the MP firmware then creates a FAT with the left over flash.

Saito
Posts: 4
Joined: Mon Aug 27, 2018 8:03 am

Re: How to use internal flash ?

Post by Saito » Fri Sep 07, 2018 6:35 am

Yes, I am using ESP32 board.
@OutoftheBOTS_, thanks for providing this idea, I find an interesting article here:
https://techtutorialsx.com/2017/06/03/e ... ng-a-file/
It demonstrate a way to read/write a file, then I can follow @Roberthh suggestion to create a csv file.

To @Roberthh, I have a question. I downloaded binary file from micropython website, in your suggestion, it need to modify modules/flashbdev.py. It looks I have to install linux then run "make" ?? Am I right ?

Thanks for everyone.

Post Reply