Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is ESP32 S2/S3 support realistic? #15

Open
tobozo opened this issue Aug 2, 2022 · 1 comment
Open

Is ESP32 S2/S3 support realistic? #15

tobozo opened this issue Aug 2, 2022 · 1 comment

Comments

@tobozo
Copy link

tobozo commented Aug 2, 2022

Hi and million thanks for your awesome library 馃憤

An idea came up while I was playing with an ESP32-C3 and esp32-arduino-lib-builder to produce a package with memory protection disabled, and accidentally built for ESP32 S2/S3 too.

Although S2/S3 already have builtin USB support, this support is limited to either host or device role, but what if esp32_usb_soft_host is used along with tinyUSB acting as a device?

I chose to focus on ESP32S2/esp32_usb_soft_host alone, I don't have a broken out ESP32-S3 and tinyUSB considerations can wait.

Adapting the code was mostly adding || defined CONFIG_IDF_TARGET_ESP32S2 to #if CONFIG_IDF_TARGET_* conditional blocks and assigning pins.

However checkPins() detection fails, and now the doubt is there 馃

Some thoughts:

  • not sure what value to assign to BLINK_GPIO, tried the builtin led pin, scl pin, random pins and got not change
  • not sure if cpu_ll_enable_cycle_count(); is needed in function usb_process(), enabling/disabling produces no change
  • using the makeOpcodes() from ESP32 works fine, maybe ESP32S2 wants different opcodes

(In the event the situation is realistic)
Possible use cases of an ESP32S2 using esp32_usb_soft_host/tinyUSB and acting both as host+device:

  • Gaming: DIY dongle for joypad/joystick auto fire + programming
  • Security research: HID MITM keylogger, mouselogger, injector, etc
  • ...

So here's my question:

Is it a xxx limitation prevents yyy feature situation or is it worth researching further?

Thanks again for creating this project, it brought hours of fun 鉂わ笍

@tobozo
Copy link
Author

tobozo commented Aug 9, 2022

well this implementation is really dirty and probably wrong on many levels but after some fiddling I had a keyboard successfully detected on an ESP32-S2

https://github.com/tobozo/ESP32-USB-Soft-Host/releases/tag/v0.1.2

I didn't succeed at using opcodes with the S2, memory management is different and disabling memory protection wasn't enough to prevent it from crashing.

The ugly fix for the ESP32-S2 is to use a substitute for cpuDelay():

    #define NOP() asm volatile ("nop")
    void IRAM_ATTR cpuDelay(uint32_t cycles_count )
    {
      if( cycles_count > 0 ) {
        while( cycles_count-->1 ) NOP();
      }
    }

I'm quite sure the maths don't add up though, maybe this works on a misunderstanding?

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

1 participant