earlephilhower / newlib-xtensa

newlib-xtensa fork intended for esp8266
GNU General Public License v2.0
5 stars 7 forks source link

memmove_P does not support IRAM #10

Closed mhightower83 closed 4 years ago

mhightower83 commented 4 years ago

Copied over from https://github.com/esp8266/Arduino/pull/7060#issuecomment-669317101

memmove_P does not support IRAM

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <umm_malloc/umm_malloc.h>
#include <umm_malloc/umm_heap_select.h>

//#define memmove_P ets_memmove

char str[] = "Move over";

void setup() {
  WiFi.persistent(false);
  WiFi.mode(WIFI_OFF);
  Serial.begin(115200);
  delay(10);
  Serial.printf_P(PSTR("\r\nBegin ...\r\n"));

  {
    HeapSelectIram ephemeral;
    size_t sz = strlen(str) + 1;
    char *newstr = (char *)malloc(sz + 8);
    memcpy(newstr, str, sz);
    Serial.println(newstr);
    memmove_P(&newstr[1], newstr, sz);
    newstr[0] = ' ';
    Serial.println(newstr);
    free(newstr);
  }
}

void loop() {}

Prints:

Begin ...
Move over
 MMMMMMMMMM

Works when not using IRAM or using ets_memmove with a non32-bit access handler.

Your comment about the issue: https://github.com/esp8266/Arduino/pull/7060#issuecomment-669437477