Esp_core_dump_flash and spi_flash errors

I developed my project using platformIO with Arduino framework in VS code, The program builds and uploads well but I get these errors in the serial monitor.

E (137) spi_flash: Detected size(2k) smaller than the size in the binary image header(4096k). Probe failed. assert failed: do_core_init startup.c:328 (flash_ret == ESP_OK) E (159) esp_core_dump_flash: Core dump flash config is corrupted! CRC=0x7bd5c66f instead of 0x0 Rebooting...

I decided to try out the simple projects in the examples (blink and hello_world), I still get the same issue. I have now uninstalled and re-installed PlatformIO but its still the same.

I tried using the Arduino IDE and esp-idf in VS code, hello world and blink run very well. Is there a solution to this or I have to learn esp-idf. Any help will be greatly appreciated

my platformio.ini currently looks like this

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino

build_flags = -DCORE_DEBUG_LEVEL=5

#targets = upload, monitor
upload_speed = 230400
monitor_speed = 115200
board_upload.flash_size = 4MB

board_build.partitions = partition.csv
lib_deps =
  https://github.com/Savjee/EmonLib-esp32.git
  ArduinoJson
  Adafruit GFX Library
  Adafruit SSD1306
  adafruit/Adafruit BusIO @ ^1.7.2
  MQTT
  NTPClient

For a simple “Hello World” sketch, your platformio.ini is way to complex.

This should be enough:

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200

Already declared in esp32doit-devkit-v1.json - See

I guess this is the root cause for your problems. Unfortunately, you did not show the content of your custom partition.csv.

These libs are not needed for a simple “Hello World” sketch.

Please try erasing the entire flash first, then upload your hello world sketch with the platformio.ini from above.

Erasing flash:

PIO-Icon → PROJECT TASKS → esp32doit-devkit-v1 → Platform → Erase Flash

thank you, It was the relay board I connected to the esp32 that caused me all this trouble. I connected gpio12 and 13 to two relays. After isolating them, my project is now working fine