File write speed

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
pythoncoder
Posts: 2991
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: File write speed

Post by pythoncoder » Tue May 15, 2018 5:13 am

@goatchurch I think you may have misunderstood my above comment. I was suggesting an asynchronous solution along these lines:

Code: Select all

import uasyncio as asyncio

async def sender():
    with open('test.txt', 'w') as f:
        swriter = asyncio.StreamWriter(f, {})
        while True:
            await swriter.awrite('Hello file\n')
            await asyncio.sleep_ms(10)

loop = asyncio.get_event_loop()
loop.create_task(sender())
loop.run_forever()
(The 10ms sleep was merely to keep the file size within bounds on this fast Linux box.)
Peter Hinch

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

Re: File write speed

Post by jickster » Tue May 15, 2018 9:02 pm

pythoncoder wrote:
Tue May 15, 2018 5:13 am
@goatchurch I think you may have misunderstood my above comment. I was suggesting an asynchronous solution along these lines:

Code: Select all

import uasyncio as asyncio

async def sender():
    with open('test.txt', 'w') as f:
        swriter = asyncio.StreamWriter(f, {})
        while True:
            await swriter.awrite('Hello file\n')
            await asyncio.sleep_ms(10)

loop = asyncio.get_event_loop()
loop.create_task(sender())
loop.run_forever()
(The 10ms sleep was merely to keep the file size within bounds on this fast Linux box.)
While this may work in general, his problem is that the ESP OS freezes the entire system when a flash write is performed to the same flash memory where the code is stored.

To overcome this, he needs to store his code in a different location than SPI flash.

User avatar
pythoncoder
Posts: 2991
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: File write speed

Post by pythoncoder » Wed May 16, 2018 5:25 am

OK, I hadn't appreciated that.
Peter Hinch

Post Reply