Skip to content

HelloServer example doesn't work with ESP32C3 #6004

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

Closed
sh-user opened this issue Dec 10, 2021 · 17 comments
Closed

HelloServer example doesn't work with ESP32C3 #6004

sh-user opened this issue Dec 10, 2021 · 17 comments

Comments

@sh-user
Copy link

sh-user commented Dec 10, 2021

Hardware:

Board: ESP32C3 Dev Module
Core Installation version: 2.0.1
IDE name: Arduino IDE 1.8.13

Description:

HelloServer example doesn't work with ESP32C3

ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x4038195a
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x484
load:0x403ce000,len:0x90c
load:0x403d0000,len:0x2398
SHA-256 comparison failed:
Calculated: e0c357829f601add6a50d6ea19f89687ec5acf531610506a38b33d09b4a71c7e
Expected: 77332826ec7bc491df854452f675071e3a094e80858dd7d91dd7e27940204216
Attempting to boot anyway...
entry 0x403ce000 

Sketch:

#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>

const char* ssid = "........";
const char* password = "........";

WebServer server(80);

const int led = 13;

void handleRoot() {
  digitalWrite(led, 1);
  server.send(200, "text/plain", "hello from esp32!");
  digitalWrite(led, 0);
}

void handleNotFound() {
  digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}

void setup(void) {
  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp32")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

  server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void) {
  server.handleClient();
  delay(2);//allow the cpu to switch to other tasks
}
@felmue
Copy link

felmue commented Dec 10, 2021

Hello @sh-user

hmm, the code you posted runs fine on my ESP32C3 - two thoughts:

  • from your log mode:DIO, clock div:1 and assuming I am understanding the documentation correctly this means the flash frequency is 80 MHz. The default however seems to be 40 MHz (e.g. mode:DIO, clock div:2). Maybe try to change the flash frequency to 40 MHz for a test?
  • I've seen ESP32 boards reset while using WiFi due to the power source being too weak. Have you tried a different power source / different USB cable?

Thanks
Felix

@sh-user
Copy link
Author

sh-user commented Dec 10, 2021

GetChipID example works fine

@sh-user
Copy link
Author

sh-user commented Dec 10, 2021

@felmue the reason was in the RESET button, I caught interference with a wire 10 cm long and the ESP32C3-12F module was cyclically reset

@sh-user sh-user closed this as completed Dec 10, 2021
@felmue
Copy link

felmue commented Dec 11, 2021

Hello @sh-user

glad to hear you figured it out. And thank you for letting me know.

Thanks
Felix

@adumont
Copy link

adumont commented Dec 12, 2021

Could you explain how to fix the issue? I am having the same issue here... (with an empty sketch)

Flashing from Arduino IDE seems to work fine:

python /home/adumont/.arduino15/packages/esp32/tools/esptool_py/3.1.0/esptool.py --chip esp32c3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0xe000 /home/adumont/.arduino15/packages/esp32/hardware/esp32/2.0.1/tools/partitions/boot_app0.bin 0x0 /tmp/arduino_build_577568/sketch_dec12b.ino.bootloader.bin 0x10000 /tmp/arduino_build_577568/sketch_dec12b.ino.bin 0x8000 /tmp/arduino_build_577568/sketch_dec12b.ino.partitions.bin 

esptool.py v3.1
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-C3 (revision 2)
Features: Wi-Fi
Crystal is 40MHz
MAC: 7c:df:a1:43:03:54
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00000000 to 0x00003fff...
Flash will be erased from 0x00010000 to 0x00038fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 567.8 kbit/s)...
Hash of data verified.
Flash params set to 0x022f
Compressed 12672 bytes to 9035...
Writing at 0x00000000... (100 %)
Wrote 12672 bytes (9035 compressed) at 0x00000000 in 0.3 seconds (effective 292.8 kbit/s)...
Hash of data verified.
Compressed 166928 bytes to 93052...
Writing at 0x00010000... (16 %)
Writing at 0x00019a89... (33 %)
Writing at 0x0001f8ea... (50 %)
Writing at 0x0002592a... (66 %)
Writing at 0x0002bdf9... (83 %)
Writing at 0x000338cc... (100 %)
Wrote 166928 bytes (93052 compressed) at 0x00010000 in 2.8 seconds (effective 476.5 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 128...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (128 compressed) at 0x00008000 in 0.1 seconds (effective 444.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

but then in the Serial Monitor I see:

Attempting to boot anyway...
entry 0x403ce000
ESP-ROM:esp32c3-20200918
Build:Sep 18 2020
rst:0x3 (RTC_SW_SYS_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x403d0f8a
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x484
load:0x403ce000,len:0x90c
load:0x403d0000,len:0x2398
SHA-256 comparison failed:
Calculated: e0c357829f601add6a50d6ea19f89687ec5acf531610506a38b33d09b4a71c7e
Expected: 77332826ec7bc491df854452f675071e3a094e80858dd7d91dd7e27940204216
Attempting to boot anyway...

@sh-user
Copy link
Author

sh-user commented Dec 12, 2021

@adumont check pullup resistor CHIP_EN and supply voltage

@adumont
Copy link

adumont commented Dec 12, 2021 via email

@sh-user
Copy link
Author

sh-user commented Dec 12, 2021

No need to supply external power, usually USB is enough, check that the voltage on the RST pin 3.3V.
https://docs.espressif.com/projects/esp-idf/en/v4.3-beta1/esp32c3/hw-reference/esp32c3/user-guide-devkitm-1.html
I assembled my board using the ESP32C3-12F module and soldered the button to the RST pin, when connected to the router, the module reset

@adumont
Copy link

adumont commented Dec 13, 2021 via email

@sh-user
Copy link
Author

sh-user commented Dec 13, 2021

Write your sketch here, I will check it on my module
Found a cyclic restart if the mode: DIO, clock div: 1 (80MHz)
Only mode: DIO, clock div: 2 (40MHz) working normally

The problem was not in the wire connected to RESET, the button was re-soldered and everything works. I probably switched to 40MHz and removed the reset wire. So I thought it was a hindrance.

@sh-user sh-user reopened this Dec 13, 2021
@adumont
Copy link

adumont commented Dec 13, 2021 via email

@sh-user
Copy link
Author

sh-user commented Dec 13, 2021

@adumont try flash frequency: 40 MHz

@adumont
Copy link

adumont commented Dec 13, 2021 via email

@atanisoft
Copy link
Collaborator

@adumont Your issue does not appear to be related to this but instead the chip revision is not supported by the current arduino-esp32 build.

@sh-user sh-user closed this as completed Dec 14, 2021
@git67frederick
Copy link

comment out all lines with digitalWrite and try again...works now for me M5StampC3
//digitalWrite(led,

@alexceltare2
Copy link
Contributor

Try changing const int led = 13; to 8 or whatever LED you have in your devboard. Worked for me.

@short-cheese-the-3rd
Copy link

Try changing const int led = 13; to 8 or whatever LED you have in your devboard. Worked for me.

This worked for me too. Thank you so much @alexceltare2

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

No branches or pull requests

7 participants