Flashing error? (memory allocation failed)

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Tillmario
Posts: 18
Joined: Mon Nov 19, 2018 2:06 pm

Flashing error? (memory allocation failed)

Post by Tillmario » Thu Nov 29, 2018 9:05 pm

Hello, I'm running ssd1306.py to work my i2c-display. via writer.py I want to visualize a bigger font. I'm encountering some problems and was wondering if i did something wrong while flashing.

Allthough there should be enough RAM(?) I'm getting this error.

Code: Select all

from writer import Writer
import courier20
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating 4033 bytes
because i read it online I did this:

Code: Select all

import gc
gc.mem_free()
15232

import micropython
micropython.mem_info(1)
stack: 2128 out of 8192
GC: total: 35968, used: 21200, free: 14768
No. of 1-blocks: 122, 2-blocks: 43, max blk sz: 264, max free sz: 135
GC memory layout; from 3ffef550:
00000: MDShhSMMDDhThDMB=BBBh===h====hDBhh==h===========================
00400: ================================================================
00800: ================================================================
00c00: ================================================================
01000: ============================================hhBhDhBh=h===BDh==hB
01400: hDhDBMDDBBBBhB=h=h===B=MDhh=======h=============================
01800: ================================================================
01c00: ================================================================
02000: ====================================================BBB=hBMShSh=
02400: h========B=BSh=Dh=hSMDhh=DDhhSh======hhB=BBTh===h==BDhB=B==BhBhB
02800: =B=BBB=BhB=BBh===h=BBBh=======h========h=..h=h=h=M.Dh====h=B=B=B
02c00: h===h==Sh==h========hh.B=h=======hh===B=.B=h==B=h===h=Bh=h...SSh
03000: =h==hh=h====h=====h=.Sh=....Sh=======================h=======h==
03400: ===========h=h======h====...........h=..........................
03800: .....................................................Sh==.......
03c00: ....h===..................................hh.........h=.........
04000: .......h=======.................................................
04400: ................................................................
04800: ................h=======........................................
04c00: ................................................................
05000: ...............................h=======.........................
05400: ...................................h============================
05800: ================================================================
05c00: ================================================================
06000: ================================================================
06400: ================================...............h============....
       (2 lines all free)
07000: .h=...h=........................................................
07400: ...........hh..................h=...hh........hh................
07800: ................................................................
07c00: .h===.....................h==h===========h==================h===
08000: =========h====h=====h==========h==h===hh====================hh==
08400: ========hh==hh=hh====hh====h=h=====hh=====================h.....
08800: ................................................................
08c00: ........
Does this help? Maybe a mistake flashing the firmware. I did it at 00000 I guess.

Another example:

Code: Select all

import courier20
from writer import Writer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating 80 bytes
Loading other fonts give me the same mistake. I also tried gc.collect() which I read online, didn't work.

Any clues?
Tom

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

Re: Flashing error? (memory allocation failed)

Post by jickster » Thu Nov 29, 2018 9:53 pm

What happens if you allocate an equally big array of numbers?

Tillmario
Posts: 18
Joined: Mon Nov 19, 2018 2:06 pm

Re: Flashing error? (memory allocation failed)

Post by Tillmario » Thu Nov 29, 2018 10:20 pm

You're talking to a beginner :lol: First I will look up allocate and array, since I'm not a native english speaker but I'm afraid after that I won't know how to do what you are asking :oops:

rpr
Posts: 60
Joined: Sat Oct 27, 2018 5:17 pm

Re: Flashing error? (memory allocation failed)

Post by rpr » Thu Nov 29, 2018 10:55 pm

I have the same issue. I don't think that there is enough memory on the ESP8266.

viewtopic.php?t=1747

The font file is quite big for me. ~18 K. while the available memory is only about 22-25 K. Maybe that is the reason that this module cannot run.

User avatar
devnull
Posts: 353
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: Flashing error? (memory allocation failed)

Post by devnull » Thu Nov 29, 2018 11:01 pm

You need to include the font files (and as many other files as you can) as frozen files.

rpr
Posts: 60
Joined: Sat Oct 27, 2018 5:17 pm

Re: Flashing error? (memory allocation failed)

Post by rpr » Thu Nov 29, 2018 11:06 pm

Thanks. I figured something like that was needed. I will look up how to build.

As an aside, the demo code for the writer.py (writer_demo.py) worked just fine on my esp32 (which of course has lots more memory).

rpr
Posts: 60
Joined: Sat Oct 27, 2018 5:17 pm

Re: Flashing error? (memory allocation failed)

Post by rpr » Fri Nov 30, 2018 7:22 am

It worked with the frozen files. Thanks for the help.

Tillmario
Posts: 18
Joined: Mon Nov 19, 2018 2:06 pm

Re: Flashing error? (memory allocation failed)

Post by Tillmario » Fri Nov 30, 2018 8:34 pm

devnull wrote:
Thu Nov 29, 2018 11:01 pm
You need to include the font files (and as many other files as you can) as frozen files.
Thanks from me as well. I have some reading up to do and then hopefully it'll work for me too.

I have a "wifi_connect.py" which is importet in the boot.py. I should freeze that too? Anything else? Since you said as many files as you can.

Tom

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

Font files and RAM

Post by pythoncoder » Sat Dec 01, 2018 6:03 pm

The utility font-to-py converts fonts to Python code. There are two reasons for doing this. One is to simplify rendering. font-to-py.py converts the complex font file to a fixed size bitmap, thereby saving the MicroPython device a great deal of work.

The other reason is that if the Python code is frozen, RAM usage is very small: the data is accessed directly from flash. A font of 20KB in size might use an incremental 200 bytes of RAM.

If you load the Python files in the normal way the data is stored in RAM. What else can the compiler do?

Perhaps I didn't make this sufficiently clear in the docs.
Peter Hinch

Post Reply