Failed to allocate TFLite arena (error code 1)

I am running a vision impulse on the Arduino Portenta with LoRa Vision Shield to control an RC hacked car (detects a track using pop cans, water bottles or cones etc). Things are great until I include servo commands. Then I get

Failed to allocate TFLite arena (error code 1)
ERR: Failed to run classifier, error number: -6

I was thinking I was running out of memory, as I was also was running a grayscale OLED and raw LoRa emergency stop and I am getting close to maximum memory usage ~98%, but when I got rid of those extras I am still having issues. I am thinking the servo motor is perhaps taking longer to activate than the code is happy with, or I have some memory leak going on.

My code is taken from my Library here with this slightly different sketch having the Servo driver here

Does anyone have any suggestions?

Hmmmm, it’s not the servo code, could it possibly be analogWrite PWM code killing the sketch? Maybe that makes sense since PWM needs constant microcontroller assistance to operate.

…

Yup, just confirmed, PWM is killing the sketch on any of the pins I tried: D0, D6 and D4. So my options are: Put the PWM code in it’s own thread, not sure if I have enough room to activate a thread (97% memory full). The other option is to use the inner M4 core, communicating using the UART. Kind of want to try that, unless anyone has other suggestions?

Threads are easy:

#include "mbed.h"
#include "rtos.h"

//using namespace mbed;  // sometimes needed
using namespace rtos;

Thread thread;

void myLedBlue_thread(){
   while (true) {
      digitalWrite(LEDB, !digitalRead(LEDB));   //switch on / off
      ThisThread::sleep_for(1000);
   }
}

void setup() {
   pinMode(LEDB, OUTPUT);   // LEDB = blue, LEDG or LED_BUILTIN = green, LEDR = red 
   thread.start(myLedBlue_thread);
}

void loop() {
  // put your main code here, to run repeatedly:

}

Looks like the issue might be solved using a thread. I will have to test it with a motor but it is compiling and running inference.

2 Likes

Good to know, thanks for the update! That’s interesting you’re forced to use threads…I would have thought that PWM/servo code used counter/timers outside of the TFLite inference engine. Maybe there’s something else causing a conflict.

1 Like

You might be right. My raw LoRa emergency stop seems to conflict with D4 pin PWM for the drive motor (Possibly SerialLoRa interacts on D4,perhaps part of UART6 not sure). But switching the PWM to D1 or D0 seems to mess up the TFLite engine. Switching to D6 doesn’t even seem to be PWM, motor either off or on full. I was very lucky that switching the PWM to D5 and the D5 pin to D6 worked. So everything is now working. I just have to improve my Edge Impulse model. I have a few tricks to help with that. There is so much going on with the Portenta, someone needs to summarize all the possible conflicts. The main pinout pdf is much to complex.

1 Like