Successfully upload code to ESP32-S2 custom board, but code is not running (LED not blinking)

I create a blinking LED code using PIN 15 of ESP32-S2 and the code was running smoothly if I upload the code using Arduino IDE:

void setup() {
    pinMode(15, OUTPUT);
}

void loop() {
    digitalWrite(15, HIGH);
    delay(5000);
    digitalWrite(15, LOW);
    delay(5000);
}

Below is my configuration in Arduino IDE:

I implement the same code using PlatformIO but the code is not running (LED was not blinking) although the code was successfully uploaded.
I build board.json for my custom board:

{
    "build": {
        "arduino": {
            "ldscript": "esp32s2_out.ld"
        },
        "core": "esp32",
        "extra_flags": "-DARDUINO_ESP32S2_DEV",
        "f_cpu": "240000000L",
        "f_flash": "40000000L",
        "flash_mode": "qio",
        "mcu": "esp32s2",
        "variant": "esp32s2"
    },
    "connectivity": [
        "wifi"
    ],
    "debug": {
        "openocd_target": "esp32s2.cfg"
    },
    "frameworks": [
        "arduino",
        "espidf"
    ],
    "name": "Espressif Ferbos-ESP32-S2",
    "upload": {
        "flash_size": "2MB",
        "maximum_ram_size": 327680,
        "maximum_size": 2097152,
        "require_upload_port": true,
        "speed": 460800
    },
    "url": "ferbos",
    "vendor": "Espressif"
}

and my platform.ini file contains this:

[env:ferbos_esp32s2]
platform = espressif32
board = ferbos-esp32-s2
framework = arduino

board_build.mcu = esp32s2
board_build.f_cpu = 240000000L
board_build.f_flash = 40000000L
board_build.flash_mode = qio
board_build.flash_size = 2MB
board_build.partitions = min_spiffs.csv
board_build.psram_type = disabled

upload_protocol = esptool
upload_speed = 921600

monitor_speed = 115200

what is the exact problem that I face? is there any misconfiguration in my platformio?

Additionally add

build_flags = 
	-D ARDUINO_USB_MODE=1
	-D ARDUINO_USB_CDC_ON_BOOT=1    

to the platformio.ini and upload this exact code:

void setup() {
    Serial.begin(9600);
    pinMode(15, OUTPUT);
}

void loop() {
    Serial.println("Blink!!");
    digitalWrite(15, HIGH);
    delay(5000);
    digitalWrite(15, LOW);
    delay(5000);
}

What output is there on the serial monitor?

Adding -D ARDUINO_USB_MODE=1 will result this error:

C:/Users/nazmi/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.cpp:60:8: error: 'Serial' was not declared in this scope
     if(Serial.available()) serialEvent();
        ^~~~~~
C:/Users/nazmi/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.cpp:60:8: note: suggested alternative: 'Serial1'
     if(Serial.available()) serialEvent();
        ^~~~~~
        Serial1
*** [.pio\build\ferbos_esp32s2\FrameworkArduino\HardwareSerial.cpp.o] Error 1

So I change to -D ARDUINO_USB_MODE=0

The code was successfully uploaded:

I need to reset the board manually and running pio device monitor to check the serial output. But nothing appear in my serial monitor @maxgerhardt

P.S.: I’m using ESP32-S2-FH2 with 2MB flash memory

UPDATE

I start to change the framework to espidf by creating new projects and put this code in main.c

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"

#define BLINK_GPIO 15

void app_main(void)
{
    gpio_reset_pin(BLINK_GPIO);
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);

    while (1) {
        gpio_set_level(BLINK_GPIO, 1);
        vTaskDelay(2000 / portTICK_PERIOD_MS);
        gpio_set_level(BLINK_GPIO, 0);
        vTaskDelay(2000 / portTICK_PERIOD_MS);
    }
}

and the LED is blinking!
I use the same board.json files, why is the led not blinking using arduino framework?

I found the problem!

I change the platform.ini to this:

[env:ferbos_esp32s2]
platform = espressif32
board = ferbos-esp32-s2
framework = arduino

board_build.mcu = esp32s2
board_build.flash_size = 2MB
board_build.partitions = minimal.csv

upload_speed = 921600

The previous code not works because of in the partition table, the size of app0 and app1 are bigger than total flash (2MB) of STM32-S2-FH2

I’m glad you found a solution for your problem.

What’s the reason for this?

The include folder should be available by default.

Hi @sivar2311 ,

Sorry I forgot to delete that. It was part of my trial and error process. That’s not necessary in my solution.
Already updated my answer.
Thanks