ESP32-S2fh2 flashing(configuration?) issues, getting constant resets in bootloader

I’ve created a custom PCB for a purpose-built USB gamepad with the ESP32-S2 specifically the S2fh2 variant. I was unable to find a existing board configuration using this variant built into PlatformIO, so I modified an existing board.json to create a custom board with the appropriate changes. I thought that was all I needed to do to get running, unfortunately, that was not the case. All I’m getting from my chip is repeated RTC_SW_SYS_RST resets before entering my sketch. When the flash is wiped I get invalid header: 0xffffffff over serial. After discussing with Copilot these symptoms don’t seem to indicate a hardware issue(I only trust Copilot so much so would appreciate some input). Also, I can’t halt the CPU immediately at reset over JTAG. In addition, I’m very outa my depth when it comes to configuring boards and would appreciate some help.

my github repo of the project if you want a more in depth look at the project: github.com/mickdassive/drone_sim_controler

contents of bustom board file esp32-s2fh2

{
  "name": "Custom ESP32-S2FH2 Board",
  "url": "https://google.com",
  "vendor": "custom",
  "build": {
    "arduino": {
      "ldscript": "esp32_out.ld"
    },
    "core": "esp32",
    "extra_flags": "-DCUSTOM_BOARD",
    "f_cpu": "240000000L",
    "f_flash": "40000000L",
    "flash_mode": "dio",
    "mcu": "esp32s2",
    "variant": "esp32s2"
  },
  "connectivity": [
    "wifi",
    "bluetooth",
    "ethernet",
    "can"
  ],
  "debug": {
    "openocd_board": "esp32s2.cfg"
  },
  "frameworks": [
    "arduino",
    "espidf"
  ],
  "upload": {
    "flash_size": "2MB",
    "maximum_ram_size": 327680,
    "maximum_size": 2097152,
    "require_upload_port": true,
    "speed": 460800
  }
}

contents of my platformio.ini


; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32-s2]
platform = espressif32
board = esp32-s2fh2
board_upload.flash_size=2MB
framework = arduino
monitor_speed = 115200
upload_speed = 921600
build_flags = 
lib_deps = 
	adafruit/Adafruit TinyUSB Library@^3.5.0
lib_archive = false
debug_tool = jlink
debug_init_break =
debug_server =
    openocd
    -f
    board/esp32s2-kaluga-1.cfg

Never do this you never know which version you are using

can you elaborate on that. what version should I be using what would to corrected like look like?

It depends which Arduino version do you want / need. For actual Arduino core 3.2.1
it is

platform = https://github.com/pioarduino/platform-espressif32/releases/download/54.03.21/platform-espressif32.zip

ive made the suggested changes and now im getting the following error.

ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x3 (RTC_SW_SYS_RST),boot:0xb (SPI_FAST_FLASH_BOOT)
Saved PC:0x4004f8e9
SPIWP:0xee
mode:DIO, clock div:2
load:0x3ffe5110,len:0x115c
load:0x4004a000,len:0x4
load:0x4004a004,len:0x8d8
load:0x4004e000,len:0x32bc
entry 0x4004a13c
E (28) flash_parts: partition 3 invalid - offset 0x150000 size 0x140000 exceeds flash chip size 0x200000
E (29) boot: Failed to verify partition table
E (31) boot: load partition table error!

Your used partitions.csv is wrong