guild icon
Toit
#out of memory on PCB
Thread channel in help
diego.ar
diego.ar 02/17/2025 07:17 PM
Hi, when running a Toit code on a PCB, i am getting an "allocation failed" error... see pls attached the error message

-----------------------------------
this is the function where i get the error, is a simple post thru http to a web server:

persist_data client data:
e := catch --trace:
response := client.post_json --host=URL --path=PATH {
"data": data
}

data_response := json.decode_stream response.body
print data_response
response = null
data_response = null
if e:
print "Error en POST: $e.stringify"

any tip to free memory resources?

thanks
floitsch
floitsch 02/17/2025 07:20 PM
It does look like an actual OOM
floitsch
floitsch 02/17/2025 07:20 PM
It's basically running out of memory when establishing the TLS connection.
floitsch
floitsch 02/17/2025 07:21 PM
Is there anything else running?
floitsch
floitsch 02/17/2025 07:22 PM
Independently, you could try to establish the connection earlier, when less memory is used. The really expensive part is establishing the connection. Once it exists you shouldn't need as much anymore.
floitsch
floitsch 02/17/2025 07:24 PM
Also, if you don't use BLE use the esp32-no-ble envelope. Just having BLE support reduces the amount of free memory.
diego.ar
diego.ar 02/17/2025 08:11 PM
after flashing the device with no-ble, as per your suggestiion... jag flash esp32-no-ble --name device1 im getting a different out of memory error...

Heap report @ out of memory in primitive 6:2:
┌───────────┬──────────┬─────────────────────────────────────────────────────┐
│ Bytes │ Count │ Type │
├───────────┼──────────┼─────────────────────────────────────────────────────┤
│ 45056 │ 13 │ toit processes │
│ 16384 │ 4 │ system 0 601fdfa0-55bf-adc8-1620-cf4dba25ce57 │
│ 20480 │ 5 │ other 1 af3508f3-fd45-adf5-a3d6-b140bf7705bd │
│ 8192 │ 2 │ current 4 42e2be1a-805a-b594-6e2a-f7a6f4a75a7d │
│ 335872 │ 1 │ heap metadata │
│ 4096 │ 1 │ spare new-space │
│ 8608 │ 6 │ heap overhead │
│ 216 │ 3 │ event source │
└───────────┴──────────┴─────────────────────────────────────────────────────┘
Total: 393848 bytes in 16 allocations (9%), largest free 3692k, total free 3707k


Decoding by jag, device has version <2.0.0-alpha.174>

MALLOC_FAILED error.
0: Bus.test <sdk>\i2c.toit:84:5
1: Bus.scan <sdk>\i2c.toit:79:10
2: get-display get_display.toit:23:18
3: main lora_receive.toit:79:28
**
with the esp32-no-ble ... i get a malloc even before..
floitsch
floitsch 02/17/2025 08:12 PM
Are you sure this is the same program? The get-display call was in comments in the code you showed me.(edited)
diego.arOPdiego.ar
after flashing the device with no-ble, as per your suggestiion... jag flash esp32-no-ble --name device1 im getting a different out of memory error... Heap report @ out of memory i...
floitsch
floitsch 02/17/2025 08:13 PM
@bitphlipphar what is the heap metadata?
diego.ar
diego.ar 02/17/2025 08:13 PM
it is yes the same program, i commented the display lines to make it run.. sorry ive sent the code commented to you
floitschfloitsch
@bitphlipphar what is the heap metadata?
bitphlipphar
bitphlipphar 02/17/2025 08:14 PM
Heap metadata is the extra bits we use to keep track of pointers in the heap. It is a percentage of the heap size.
bitphlipphar
bitphlipphar 02/17/2025 08:15 PM
Here the heap is pretty big, so we need a lot of space for the metadata.
floitsch
floitsch 02/17/2025 08:15 PM
Unless I'm misreading the data, the heap metadata is reported as 335872 bytes which is much more than the actual heap
bitphlipphar
bitphlipphar 02/17/2025 08:16 PM
What do you mean?
bitphlipphar
bitphlipphar 02/17/2025 08:16 PM
There is almost 4MB free in the heap?
bitphlipphar
bitphlipphar 02/17/2025 08:16 PM
Largest free block is 3692k.
floitsch
floitsch 02/17/2025 08:16 PM
Aah. I missed the k.
bitphlipphar
bitphlipphar 02/17/2025 08:16 PM
Important that one.
bitphlipphar
bitphlipphar 02/17/2025 08:16 PM
:🙂:
bitphlipphar
bitphlipphar 02/17/2025 08:16 PM
So we are very, very far from being out of memory for real.
bitphlipphar
bitphlipphar 02/17/2025 08:17 PM
Bus.test is a write operation, no?
floitsch
floitsch 02/17/2025 08:17 PM
Ok. So switching to no-ble apparently also enabled spiram
bitphlippharbitphlipphar
Bus.test is a write operation, no?
floitsch
floitsch 02/17/2025 08:18 PM
It does small writes. Yes
bitphlipphar
bitphlipphar 02/17/2025 08:18 PM
If we fail for other reasons with the i2c writes, we still report out of memory which is kinda annoying.
bitphlipphar
bitphlipphar 02/17/2025 08:18 PM
Is that what we're hitting here?
floitsch
floitsch 02/17/2025 08:18 PM
Probably
bitphlipphar
bitphlipphar 02/17/2025 08:18 PM
So this is unlikely to actually be memory related.
floitsch
floitsch 02/17/2025 08:19 PM
I think we haven't released since we fixed it in the SDK ?
Or was that just for the S3?
bitphlipphar
bitphlipphar 02/17/2025 08:19 PM
Like if i2c_master_start fails, we report out-of-memory.
floitsch
floitsch 02/17/2025 08:20 PM
@diego.ar try to remove the scan function in the get-display function
diego.ar
diego.ar 02/17/2025 08:20 PM
sure(edited)
floitschfloitsch
I think we haven't released since we fixed it in the SDK ? Or was that just for the S3?
bitphlipphar
bitphlipphar 02/17/2025 08:21 PM
When did we fix anything related to this?
diego.ar
diego.ar 02/17/2025 08:21 PM
by the way.. i made a small tweak on the get-display function.. since i was getting an error when using the gps and the screen on the same code..
floitsch
floitsch 02/17/2025 08:21 PM
And apparently you are using a wrover module, so is either esp32-spiram or no-ble, ...
One that has external memory enabled
floitsch
floitsch 02/17/2025 08:22 PM
That's the one. I2C and external memory.(edited)
floitsch
floitsch 02/17/2025 08:22 PM
Exactly what's happening here.(edited)
bitphlipphar
bitphlipphar 02/17/2025 08:23 PM
Cool!
floitsch
floitsch 02/17/2025 08:23 PM
Removing the scan call should fix things
bitphlipphar
bitphlipphar 02/17/2025 08:23 PM
So we just need to build a test release and take it for a spin :🙂:
diego.ar
diego.ar 02/17/2025 08:23 PM
just commented the code...

//devices := bus.scan
//if not devices.contains Ssd1306.I2C_ADDRESS: throw "No SSD1306 display found"
diego.ar
diego.ar 02/17/2025 08:23 PM
ill retry now
👍1
diego.ar
diego.ar 02/17/2025 08:24 PM
let me flash again on no-ble.. just a sec
diego.ar
diego.ar 02/17/2025 08:27 PM
running like a charm now...
diego.ar
diego.ar 02/17/2025 08:27 PM
error is gone
🥳1
👏1
diego.ar
diego.ar 02/17/2025 09:14 PM
thank you very much for the support
👍1
47 messages in total