https://toitlang.org/ logo
Out of memory following the OLED display example
# help
t
Here is the message:
Copy code
text
[jaguar] INFO: program 8358aee2-45c6-0193-6318-b75de00f59f3 stopped
[jaguar] INFO: program c6925192-2d45-548f-7f78-726e3c457cad started
Heap report @ out of memory in primitive 6:2:
  ┌───────────┬──────────┬─────────────────────────────────────────────────────┐
  │   Bytes   │  Count   │  Type                                               │
  ├───────────┼──────────┼─────────────────────────────────────────────────────┤
  │   40960   │     12   │  toit processes                                     │
  │     16384 │        4 │    system    0 0ff85ae2-63d2-e530-c9fe-c844785c0276 │
  │     20480 │        5 │    other     1 31709de1-906c-ce7d-8698-87e163711ebb │
  │      4096 │        1 │    current   7 c6925192-2d45-548f-7f78-726e3c457cad │
  │  667648   │      1   │  heap metadata                                      │
  │    4096   │      1   │  spare new-space                                    │
  │   16808   │      7   │  heap overhead                                      │
  │     192   │      4   │  thread/other                                       │
  └───────────┴──────────┴─────────────────────────────────────────────────────┘
  Total: 729704 bytes in 16 allocations (8%), largest free 7452k, total free 7471k

******************************************************************************
Decoding by `jag`, device has version <2.0.0-alpha.159>
******************************************************************************
MALLOC_FAILED error.
  0: Bus.test                  <sdk>/i2c.toit:65:5
  1: Bus.scan                  <sdk>/i2c.toit:60:10
  2: main                      display.toit:23:18
******************************************************************************

[jaguar] ERROR: program c6925192-2d45-548f-7f78-726e3c457cad stopped - exit code 1
I am trying to upload the OLED example with only the I2C pins changed. At first I thought it was genuinely out of memory, but it doesn't appear so looking at the table.
It seems unlikely that a single allocation asked for the remaining 7.5 MB of memory. Could it have something to do with the chip configuration
--chip esp32s3-spiram-octo
?
f
Interesting... I will try to figure out what primitive 6:2 is and what it does. I think there is a possibility that it needs internal ram and we only have external. But that's a wild guess... Did you run any other programs first?
Primite 6:2 is
i2c-write
.
I wonder if we are hitting this:
Copy code
// NOTE:
  // 'i2c_master_X' functions allocate data, but return `ESP_FAIL` if that allocation
  // fails. There is no way to differentiate the kind of error.

  // Initiate the sequence by issuing a `start`. That will notify slaves to
  // listen (if possible) and promote self to current master, in case of
  // multi-master setup.
  if (i2c_master_start(cmd) != ESP_OK) FAIL(MALLOC_FAILED);
Unfortunately not much I can do right now: I don't have any ESP32 with me to try to reproduce. That will have to wait until next week. Do you know if the OLED example worked without spiram? With the standard envelope?
t
Yes. I ran hello-world and blink programs without issue.
I don't know. I will try!
f
So two things to try: Run the OLED program after a reset. (Best chance that memory is still available). Run on the other (non spiram) envelope. That could give us some hints.
Maybe @kasperl has other ideas, when he catches up on this thread.
t
Thank you for your suggestion. The program DOES run with
--chip esp32s3
. Does that effectively mean programs do not have access to the 8 MB SPRAM if I need to run all programs in this way?
f
Some low level operations need to have their memory in specific regions. We might allocate something in the I2C functions incorrectly. At least that's what I think
One more request: could you make us a repro? Basically instructions that consistently create the error. We should be able to find a device with external memory and then debug it. (When I come back next week).
t
Yes. I should be able to do that later today.
Thank you!
f
Thanks
t
I've been mostly in the application-level-programming for a while, but I'd be happy to help too.
f
If I can reproduce it should be relatively straightforward to figure out what's going wrong. If not, getting your help would be very valuable.
t
f
So flash the spiram envelope and then run this program and there is always a memory error?
t
Yes. That is correct.
f
Ok. Good to know.
@Tyrone Smith I have uploaded an
esp32s3-debug
envelope. If you could try to reproduce the error with that one and report back the debug output it produces that would be helpful. You should be able to just run
jag flash --chip=esp32s3-debug
.
t
I'll be able to try it in about a hour 👍
I'm sorry, forgot about this, I'll provide u the debug output today!
f
Any update?
t
It's what we talked about in dms
A problem on my side, the i2c was not properly powered
f
Right. It's still a bug on our side that we report it as OOM, but we will have to rewrite the i2c driver anyway (since espressif deprecated the API we are currently using).
2 Views