Failed to allocate TFLite arena (error code 1) on Portenta

The FOMO model runs perfectly fine on the Portenta, but when I try to light up the LED_BUILTIN, it gives the Failed to allocate TFLite arena error.

The example code gives the following solution:

 ** NOTE: If you run into TFLite arena allocation issue.
 ** This may be due to may dynamic memory fragmentation.
 ** Try defining "-DEI_CLASSIFIER_ALLOCATION_STATIC" in boards.local.txt (create
 ** if it doesn't exist) and copy this file to
 ** `<ARDUINO_CORE_INSTALL_PATH>/arduino/hardware/<mbed_core>/<core_version>/`.
 ** See
 ** (
 ** to find where Arduino installs cores on your machine.

I was successful in finding where it is located (even though the link does not work), but I am not sure how to edit the file, because the file expects a key=value format.

Hello @ElectricDragon,

The Failed to allocate TFLite arena is a memory issue, you can try to use a smaller EI model (reduce your window size or your image size is usually a good start).

For the option Try defining "-DEI_CLASSIFIER_ALLOCATION_STATIC" in boards.local.txt. I’ll check with our Embedded team if they have a deeper explanation. I’ll add it to our documentation too.



Okay thanks a lot! Let me know where to exactly add the flag in the boards.local.txt file


Hi the URL looks to no longer be working. I’ve find the newer URL. You’d want to navigate to Board platforms and core and find the right path depending on your OS.

E.g. on Linux for the Portenta H7 using mbed core 2.8.0 and for the M7 you’d want to create boards.local.txt with the following path ~/.arduino15/packages/arduino/hardware/mbed_portenta/2.8.0/boards.local.txt.


(Optional) For an example on how you can further expand boards.local.txt take a look at our example for our firmware repo. for our firmware repo.


The behavior you describe may be a memory fragmentation issue. Allocating the tensor arena may or may not solve the issue. It all depends on whether after allocating the tensor arena statically they’ll have enough memory for the rest of your application. Can you share the serial output when it fails and also the (led control) code snippet that causes the issue? And what’s the size of your model?


This is the serial output

Starting inferencing in 2 seconds...
Taking photo...
Failed to allocate TFLite arena (error code 1)
ERR: Failed to run classifier (-6)

Following is the code for the led control:

if (bb.label == "bottle" && bb.value >= 0.90) {
   Serial.println("Bottle found!!!! with " + String(bb.value*100) + "% accuracy");
   digitalWrite(LED_BUILTIN, LOW); // further predictions failed after this line

I am not sure how to get the size of the model…can you tell me how to go about that?


you can get the size of the model from within the Deployment page of the Studio. A similar output:


Here is my model size


Thank you. The model fits nicely in the Portenta. So I suspect your issue was due to memory fragmentation.
The combination of allocation/deallocation of the tensor arena (large area) with the alllocation/deallocation in your Serial.println("Bottle found!...") (small area) causses this. Did allocating the tensor arena statically solve your issue?

1 Like


Yes it did…thanks a lot

1 Like