-
Notifications
You must be signed in to change notification settings - Fork 7.7k
waveshare esp32s3 crashing after connecting to wifi. #9919
-
Hello everyone.
I've recently started a project where I'm trying to make my own smart watch using a custom esp32 board from waveshare ( https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-1.28#esp32-s3-touch-lcd-1.28-demo ).
The thing is that, as soon as I connect the board to wifi and want to display anything on the screen at the same time, the board reboots and the debug log gives me this message:
load:0x403c9704,len:0xad0
load:0x403cc700,len:0x29e4
entry 0x403c9880
Connecting to WiFi...
Connecting...
Connected to WiFi
PSRAM is correctly initialized
Memory allocated successfully for BlackImage
DEV_Module_Init OK
GPIO Init successful!
Debug : Set image Rotate 90
assert failed: block_locate_free tlsf.c:566 (block_size(block) >= size)
Backtrace: 0x40377336:0x3fca0ba0 0x4037db41:0x3fca0bc0 0x40383885:0x3fca0be0 0x40382f99:0x3fca0d10 0x40382951:0x3fca0d30 0x40382a80:0x3fca0d50 0x40377f6a:0x3fca0d70 0x4037803a:0x3fca0da0 0x40379605:0x3fca0df0 0x4209bcf9:0x3fca0e10 0x4209dda4:0x3fca0e40 0x4209e828:0x3fca0e70 0x4209ec9d:0x3fca0eb0 0x40041502:0x3fca0ef0 0x4209b54d:0x3fca0f20
ELF file SHA256: d7e68d302420fd69
Rebooting...
The code technically works, and displays the correct time, but only for about a second, before the board reboots.
However, connecting to wifi and displaying the time in serial works fine, as well as displaying text on the screen. the code even works if I remove the "connectToWiFi();" line from the code.
I'm kinda new to esp32 coding and don't know what could cause this?
Here is the code, and all the custom libraries that the code is using:
I am using arduino IDE 2.3.2
CODE:
#include <Arduino.h>
#include "LCD_Test.h"
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include "time.h"
UWORD Imagesize = LCD_1IN28_HEIGHT * LCD_1IN28_WIDTH * 2;
UWORD *BlackImage;
const char *ssid = "SSID";
const char *password = "PASSWORD";
const char *ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 3600;
const int daylightOffset_sec = 0;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, ntpServer, gmtOffset_sec);
#define RETRY_BUTTON_PIN 33
const unsigned long debounceDelay = 50;
bool buttonState = HIGH;
bool lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long lastWiFiConnectTime = 0;
// Interval for automatic WiFi reconnection (48 hours)
const unsigned long wifiReconnectInterval = 48 * 60 * 60 * 1000;
void setup()
{
Serial.begin(115200);
Serial.setDebugOutput(true);
pinMode(RETRY_BUTTON_PIN, INPUT_PULLUP);
connectToWiFi();
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
setLocalTime();
timeClient.begin();
if(psramInit()){
Serial.println("\nPSRAM is correctly initialized");
}
else{
Serial.println("PSRAM not available");
}
if ((BlackImage = (UWORD *)ps_malloc(Imagesize)) == NULL){
Serial.println("Failed to apply for black memory...");
exit(0);
}
if (DEV_Module_Init() != 0){
Serial.println("GPIO Init Fail!");
}
else{
Serial.println("GPIO Init successful!");
LCD_1IN28_Init(HORIZONTAL);
LCD_1IN28_Clear(WHITE);
Paint_NewImage((UBYTE *)BlackImage, LCD_1IN28.WIDTH, LCD_1IN28.HEIGHT, 0, WHITE);
Paint_SetScale(65);
Paint_SetRotate(ROTATE_90);
}
}
void connectToWiFi() {
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting...");
}
Serial.println("Connected to WiFi");
}
void setLocalTime() {
while (!timeClient.update()) {
timeClient.forceUpdate();
delay(100);
}
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
void displayCurrentTime() {
timeClient.update();
String formattedTime = timeClient.getFormattedTime();
Paint_Clear(WHITE);
Paint_DrawString_EN(45, 50, formattedTime.c_str(), &Font16, WHITE, BLACK);
LCD_1IN28_Display(BlackImage);
}
bool isButtonPressed() {
bool reading = digitalRead(RETRY_BUTTON_PIN);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
return true; // Button is pressed
}
}
}
lastButtonState = reading;
return false; // Button is not pressed
}
void loop() {
if (WiFi.status() != WL_CONNECTED && millis() - lastWiFiConnectTime > wifiReconnectInterval) {
connectToWiFi();
lastWiFiConnectTime = millis();
}
if (isButtonPressed()) {
Serial.println("Manual reconnecting...");
WiFi.begin(ssid, password);
}
// Automatic WiFi reconnection every 48 hours
unsigned long currentMillis = millis();
if (currentMillis - lastWiFiConnectTime >= wifiReconnectInterval) {
Serial.println("Auto reconnecting...");
WiFi.begin(ssid, password);
lastWiFiConnectTime = currentMillis;
}
displayCurrentTime();
delay(1000);
}
The libraries and a copy of the code are in this zip file:
If you need any other files or informations, tell me.
thanks for your time.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 1 reply
-
Same thing here. Hope that's not your real password?
Beta Was this translation helpful? Give feedback.
All reactions
-
The issue you're encountering with your ESP32-S3 board likely relates to a memory allocation problem. The error message indicates that an assertion failed when trying to locate a free memory block, suggesting that there isn't enough memory available to complete the requested operation. This can happen when combining WiFi connectivity with display operations, both of which can be memory-intensive.
Here are some steps you can take to troubleshoot and potentially resolve the issue:
-
Free Up Memory
Ensure that you are using memory efficiently and freeing up any resources that are no longer needed. For example, check that you are not allocating more memory than necessary or that you are not leaking memory by failing to free up resources. -
Reduce WiFi Memory Usage
The ESP32 has configurable memory settings for its WiFi stack. Reducing the memory allocated for WiFi might help. You can configure these settings in your code. Here's an example of how to do that:
cpp
Copier le code
WiFi.setSleep(true); // Enable WiFi sleep to reduce memory usage
3. Optimize Display Operations
Ensure that your display operations are as efficient as possible. For instance, avoid repeatedly allocating and deallocating memory for the display buffer. Instead, allocate the buffer once and reuse it.
-
Check PSRAM Usage
If your board has PSRAM, make sure it is being used effectively. Sometimes the default configuration might not utilize PSRAM for certain operations. You can configure your code to use PSRAM for display buffers or other large memory allocations. -
Increase Task Stack Size
If the issue is related to stack size, you can try increasing the stack size for the tasks that handle WiFi and display operations. -
Debugging Memory Allocation
Use the ESP32's built-in functions to monitor memory usage and identify where the problem might be occurring. For example:
cpp
Copier le code
#include <esp_heap_caps.h>
void printMemoryInfo() {
Serial.print("Free heap: ");
Serial.println(esp_get_free_heap_size());
Serial.print("Largest free block: ");
Serial.println(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT));
Serial.print("Free PSRAM: ");
Serial.println(esp_psram_get_free_size());
}
Call this function before and after significant operations to see how memory usage changes.
This is my account on upwork for help! : https://www.upwork.com/freelancers/~01ac78ccc04e3d71ba?viewMode=1
Beta Was this translation helpful? Give feedback.
All reactions
-
cpp Copier le code #include <esp_heap_caps.h>
void printMemoryInfo() { Serial.print("Tas libre : "); Serial.println(esp_get_free_heap_size()); Serial.print("Plus grand bloc libre : "); Serial.println(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT)); Serial.print("PSRAM libre : "); Serial.println(esp_psram_get_free_size()); } Appelez cette fonction avant et après des opérations importantes pour voir comment l'utilisation de la mémoire change.
oups, esp_psram_get_free_size not exist
Beta Was this translation helpful? Give feedback.