Skip to content

zephyr 0.52 - Portenta H7 maybe others - <err> mpu: Failed to allocate new MPU region 27 #283

@KurtE

Description

@KurtE

I have been seeing this with some of my own Zephyr test apps, since I switched over to using
USB_next based USB/CDC-ACM.

As far as I can tell, it only happens when you first start up the board or maybe when there is no
Serial connected up to . If I reboot the processor it usually does not happen again.

In this case I wanted to test my Arduino test sketch that displays how large I can do a malloc...
https://forum.arduino.cc/t/giga-portenta-h7-difficulties-with-malloc-on-zephyr-0-52/1415377/2?u=kurte

I plugged in Portenta H7.

I double clicked on it, selected some programmer and then the flash the bootloader.
I then double clicked again and downloaded the sketch:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  while (!Serial && millis() < 5000) {}
  delay(250);
  Serial.println("Check max malloc");
  Serial.print("Enter max KB to start: ");
  pinMode(LED_BUILTIN, OUTPUT);

  //printk("KB: %u Buffer: %p\n", buffer);
}

void loop() {
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  if (Serial.available()) {
    int kb_max = Serial.parseInt();
    int kb;
    void *buffer;
    Serial.println(kb_max);
    for (kb = kb_max; kb > 0; kb--) {
      buffer = malloc(kb * 1024);
      if (buffer) break;
    }
    Serial.print(kb);
    Serial.print(": ");
    Serial.print((uint32_t)buffer, HEX);
    if (buffer) {
      Serial.print(" - ");
      Serial.print((uint32_t)buffer + kb * 1024, HEX);
    }
    Serial.print(" Stack var: ");
    Serial.println((uint32_t)&buffer, HEX);
    free(buffer);    
    Serial.print("Enter max KB to start: ");
    while (Serial.read() != -1) {}
  }
  delay(500);
}

When it came up I waited a long time before the prompt to enter max KB, which took a long time.
typed 512 took a long time...

So I then started up Serial monitor for the FTDI USB to serial adapter hooked up to the Serial1 port and
was getting an endless stream of these messages

[00:01:32.781,000] <err> mpu: Failed to allocate new MPU region 27

[00:01:32.792,000] <err> mpu: Failed to allocate new MPU region 27

[00:01:32.804,000] <err> mpu: Failed to allocate new MPU region 27

[00:01:32.915,000] <err> mpu: Failed to allocate new MPU region 27

[00:01:32.927,000] <err> mpu: Failed to allocate new MPU region 27

Took forever to print the 45K result.

I reset the H7, and then it ran as normal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions