Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HeapSelectDram for pvPortMalloc, ... #7790

Merged

Conversation

mhightower83
Copy link
Contributor

The goal here is to guarantee that the SDK gets DRAM for the heap requests that are made during SDK API calls. To accomplish this I rely on the SDK to only use the portable heap functions: pvPortMalloc, pvPortCalloc, pvPortRealloc, and pvPortZalloc. I add a thin wrapper to these functions to switch to DRAM.

I am not sure about the lwIP library, it appears to use both malloc and the pvPort... APIs.

@mhightower83 mhightower83 changed the title Pr heap select pv port malloc HeapSelectDram for pvPortMalloc, ... Dec 23, 2020
@d-a-v
Copy link
Collaborator

d-a-v commented Dec 23, 2020

lwIP can be updated to only use pvPortMalloc.
The pure lwIP malloc macro is in cc.h and the glue should be changed to use this macro.

They also could be changed for lwIPMalloc.

Would you like me to make the change ?

@mhightower83
Copy link
Contributor Author

@d-a-v, Yes, that would be great!

@d-a-v
Copy link
Collaborator

d-a-v commented Dec 24, 2020

@mhightower83 You may try with #7793

@mhightower83
Copy link
Contributor Author

@d-a-v Thanks!

I tested with liblwip2-1460-feat.a and liblwip2-1460.a. Both worked with this bad example, using a HeapSelectIram across all of setup(). WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)) was the call at this level that would lead to a HWDT.

#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <umm_malloc/umm_heap_select.h>

const byte DNS_PORT = 53;
IPAddress apIP(172, 217, 28, 1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);

String responseHTML = ""
                      "<!DOCTYPE html><html lang='en'><head>"
                      "<meta name='viewport' content='width=device-width'>"
                      "<title>CaptivePortal</title></head><body>"
                      "<h1>Hello World!</h1><p>This is a captive portal example."
                      " All requests will be redirected here.</p></body></html>";

void setup() {
  HeapSelectIram x;

  WiFi.persistent(false);
  WiFi.mode(WIFI_OFF);
  Serial.begin(115200);
  delay(15);
  Serial.println();
  Serial.println();

  WiFi.mode(WIFI_AP);
  // { // This is the WiFi call that leads to HWDT
  //   HeapSelectIram x;
    WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
  // }
  WiFi.softAP("DNSServer CaptivePortal example");

  // if DNSServer is started with "*" for domain name, it will reply with
  // provided IP to all DNS request
  dnsServer.start(DNS_PORT, "*", apIP);

  Serial.println("DNSServer CaptivePortal example running");

  // replay to all requests with same HTML
  webServer.onNotFound([]() {
    webServer.send(200, "text/html", responseHTML);
  });
  webServer.begin();
}

void loop() {
  HeapSelectIram x;
  dnsServer.processNextRequest();
  webServer.handleClient();
}

@earlephilhower
Copy link
Collaborator

@d-a-v, is this good to merge?

Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks !

@earlephilhower earlephilhower merged commit df5e113 into esp8266:master Jan 12, 2021
@mhightower83 mhightower83 deleted the pr-heap-select-pvPortMalloc branch January 13, 2021 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants