Skip to content

The Preferences function of ESP32-S3-WROOM-1U-N4R8 in USBHID mode does not work. #11284

Open
@Ccccraz

Description

@Ccccraz

Board

ESP32-S3-WROOM-1U-N4R8

Device Description

Image

For reference, below is my board.json configuration, and I believe the flash configuration here should be correct:

{
  "build": {
    "arduino":{
      "ldscript": "esp32s3_out.ld",
      "memory_type": "qio_opi"
    },
    "core": "esp32",
    "extra_flags": [
      "-DBOARD_HAS_PSRAM",
      "-DARDUINO_ESP32S3_DEV",
      "-DARDUINO_USB_MODE=0",
      "-DARDUINO_RUNNING_CORE=1",
      "-DARDUINO_EVENT_RUNNING_CORE=1"
    ],
    "f_cpu": "240000000L",
    "f_flash": "80000000L",
    "flash_mode": "qio",
    "hwids": [
      [
        "0x303A",
        "0x1001"
      ]
    ],
    "mcu": "esp32s3",
    "variant": "esp32s3"
  },
}

I don't know where this problem comes from? Maybe it's the USB? Or I made some stupid mistakes in the code that I didn't notice.

Hardware Configuration

GPIO19, GPIO20 directly used as USB signal lines

Version

latest stable Release (if not listed below)

IDE Name

VScode

Operating System

Windows 11

Flash frequency

80Mhz

PSRAM enabled

yes

Upload speed

460800

Description

I am developing a HID project based on the ESP32S3 using platformIO. Everything is going smoothly. However, today when I tried to use Preferences.h to persist some data, I found that I couldn’t do it.

I found a similar issue at #8429, and later I confirmed that the flash of the ESP32-S3-WROOM-1U-N4R8 I am using is operating in qio mode, so the solution in this issue does not work to me.

Sketch

AT8236HID::AT8236HID(uint8_t in1_pin, uint8_t in2_pin, float speed)
    : _in1_pin(in1_pin), _in2_pin(in2_pin), _speed(constrain(speed, 0.0f, 1.0f))
{
    pump_prefs.begin(pref_namespace, true);

    if (!pump_prefs.isKey(pref_device_id))
    {
        pump_prefs.end();
        pump_prefs.begin(pref_namespace, false);
        pump_prefs.putUInt(pref_device_id, 2);
        pump_prefs.end();
        pump_prefs.begin(pref_namespace, true);
    }

    _device_id = pump_prefs.getUInt(pref_device_id);
    pump_prefs.end();
}

auto AT8236HID::_onSetFeature(uint8_t report_id, const uint8_t *buffer, uint16_t len) -> void
{
    feature_t feature{};
    memcpy(&feature, buffer, sizeof(feature));

    if (feature.device_id != _device_id)
        return;

    _device_id = feature.new_device_id;

    pump_prefs.begin(pref_namespace, false);
    pump_prefs.putUInt(pref_device_id, _device_id);
    pump_prefs.end();
}


I initialize them here:

    const char *pref_namespace{"app-name"};
    const char *pref_device_id{"device_id"};
    Preferences pump_prefs{};

Debug Message

In USBHID mode, I don't know how to obtain the debug output.

Other Steps to Reproduce

I'm trying to build a minimal example to reproduce this problem.

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions