shaoxiongduan / sci-calc

software and firmware for a esp32-based scientific calculator
MIT License
169 stars 10 forks source link

Attempt to play with the WiFi module #3

Open Jayatubi opened 1 month ago

Jayatubi commented 1 month ago

Hi,

I'm very new to the embedded development and I was going to make some practice on this project so I tried some code to make the WiFi module work as:

#include <WiFi.h>

void setup() {
    ...
    WiFi.mode(WIFI_STA); 
    WiFi.begin(ssid, pwd);

    Serial.print("WiFi connecting");

    while (WiFi.status() != WL_CONNECTED)
    {
        Serial.print(".");
        delay(500);
    }

    Serial.println("");
    Serial.print("IP:");
    Serial.println(WiFi.localIP()); 
    Serial.print("WiFi RSSI:");
    Serial.println(WiFi.RSSI());
}

However, when I was going to compile this project I got some errors like:

ld: .pio/build/sci_calc_firmware/firmware.elf section `.dram0.bss' will not fit in region `dram0_0_seg'
ld: DRAM segment data does not fit.
ld: DRAM segment data does not fit.
ld: region `dram0_0_seg' overflowed by 2544 bytes

How can I address what the issue is? Does that mean the executable is too large?

shaoxiongduan commented 1 month ago

Would you mind sharing more of your code? I tested the SCI-CALC with the esp32 wifi connection example that comes with the arduino IDE and it works fine. I would recommend testing that first. You can find the example located at File/examples/WiFi/WifiClientConnect.

Jayatubi commented 1 month ago

Actually I didn't do any thing special. I just clone this repo and add one line at the end of the init function in the main.cpp:

#include <WiFi.h>

void init() {
    u8g2.begin();
    u8g2.setFontMode(0);
    Serial.begin(115200);
    u8g2.setFont(u8g2_font_profont10_mf);
    u8g2.setFontPosCenter();
    u8g2.setFontMode(1);
    u8g2.enableUTF8Print();

    Serial.begin(115200);
   //first init and check SD card
    if (!SD.begin(4)) {
        rebootEspWithReason("Card Mount Failed");
    }

    uint8_t cardType;
    cardType = SD.cardType();
    if (cardType == CARD_NONE) {
        rebootEspWithReason("No SD_MMC card attached");
    }
    pinMode(36, INPUT);
    initFromFile();
    WiFi.mode(WIFI_STA);  // Just add this
}

Then I got the issue while linking: ld: region dram0_0_seg overflowed by 2544 bytes.

If I remove all the original code and only keep the WiFi related stuffs it would be fine then but I want to make them to work together.

yangnuozhen commented 3 weeks ago

Actually I didn't do any thing special. I just clone this repo and add one line at the end of the init function in the main.cpp:


#include <WiFi.h>

void init() {

    u8g2.begin();

    u8g2.setFontMode(0);

    Serial.begin(115200);

    u8g2.setFont(u8g2_font_profont10_mf);

    u8g2.setFontPosCenter();

    u8g2.setFontMode(1);

    u8g2.enableUTF8Print();

    Serial.begin(115200);

   //first init and check SD card

    if (!SD.begin(4)) {

        rebootEspWithReason("Card Mount Failed");

    }

    uint8_t cardType;

    cardType = SD.cardType();

    if (cardType == CARD_NONE) {

        rebootEspWithReason("No SD_MMC card attached");

    }

    pinMode(36, INPUT);

    initFromFile();

    WiFi.mode(WIFI_STA);  // Just add this

}

Then I got the issue while linking: ld: region dram0_0_seg overflowed by 2544 bytes.

If I remove all the original code and only keep the WiFi related stuffs it would be fine then but I want to make them to work together.

I occurred the same problem...

It seems that due to the characteristics of ESP32, the WiFi library always reduces the data memory (DRAM) in ESP32 by a certain size, making it impossible for the heap to allocate the required space on the DRAM of ESP32, causing the problem you encounter.

Similar problems often occur when you use both the Bluetooth library and the WiFi library.

The only way to solve this problem is to replace a lighter WiFi library, or reduce the DRAM usage of other parts of the code (for example, remove the Bluetooth module and its related functions, Bluetooth will also occupy a large amount of memory space on DRAM. However, if you have experience, you can also adjust the memory allocation strategy of ESP32.

For more information of the heap memory allocation, read this: https://docs.espressif.com/projects/esp-idf/en/v5.3/esp32/api-reference/system/mem_alloc.html