Skip to content

Commit 225dc96

Browse files
SuGliderewpa
authored andcommitted
Allows spiram malloc with wifi dynamic buffers - better free heap (espressif#5791)
Summary Modifies WiFi lib to allow dynamic buffer allocation along with SPIRAM MALLOC enabled This gives more heap space to the users Related PR in Arduino Lib Builder: espressif/esp32-arduino-lib-builder#47 Impact WiFi will work the same as it was in version 1.0.6, restoring free heap. close espressif#5630 close espressif#5474 close espressif#5699 close espressif#5697
1 parent db066a2 commit 225dc96

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Diff for: libraries/WiFi/src/WiFiGeneric.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,20 @@ bool tcpipInit(){
542542
* */
543543

544544
static bool lowLevelInitDone = false;
545+
bool WiFiGenericClass::_wifiUseStaticBuffers = false;
546+
547+
bool WiFiGenericClass::useStaticBuffers(){
548+
return _wifiUseStaticBuffers;
549+
}
550+
551+
void WiFiGenericClass::useStaticBuffers(bool bufferMode){
552+
if (lowLevelInitDone) {
553+
log_w("WiFi already started. Call WiFi.mode(WIFI_MODE_NULL) before setting Static Buffer Mode.");
554+
}
555+
_wifiUseStaticBuffers = bufferMode;
556+
}
557+
558+
545559
bool wifiLowLevelInit(bool persistent){
546560
if(!lowLevelInitDone){
547561
lowLevelInitDone = true;
@@ -557,6 +571,16 @@ bool wifiLowLevelInit(bool persistent){
557571
}
558572

559573
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
574+
575+
if(!WiFiGenericClass::useStaticBuffers()) {
576+
cfg.static_tx_buf_num = 0;
577+
cfg.dynamic_tx_buf_num = 32;
578+
cfg.tx_buf_type = 1;
579+
cfg.cache_tx_buf_num = 1; // can't be zero!
580+
cfg.static_rx_buf_num = 4;
581+
cfg.dynamic_rx_buf_num = 32;
582+
}
583+
560584
esp_err_t err = esp_wifi_init(&cfg);
561585
if(err){
562586
log_e("esp_wifi_init %d", err);
@@ -644,7 +668,6 @@ wifi_ps_type_t WiFiGenericClass::_sleepEnabled = WIFI_PS_MIN_MODEM;
644668

645669
WiFiGenericClass::WiFiGenericClass()
646670
{
647-
648671
}
649672

650673
const char * WiFiGenericClass::getHostname()

Diff for: libraries/WiFi/src/WiFiGeneric.h

+4
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,16 @@ class WiFiGenericClass
179179
static bool hostname(const String& aHostname) { return setHostname(aHostname.c_str()); }
180180

181181
static esp_err_t _eventCallback(arduino_event_t *event);
182+
183+
static void useStaticBuffers(bool bufferMode);
184+
static bool useStaticBuffers();
182185

183186
protected:
184187
static bool _persistent;
185188
static bool _long_range;
186189
static wifi_mode_t _forceSleepLastMode;
187190
static wifi_ps_type_t _sleepEnabled;
191+
static bool _wifiUseStaticBuffers;
188192

189193
static int setStatusBits(int bits);
190194
static int clearStatusBits(int bits);

0 commit comments

Comments
 (0)