USBHID and MSC drive on internal Flash simultaneously
Posted: Wed Feb 08, 2023 1:36 pm
I am trying to make a HID USB program for ESP32-S2 and to have an MSC on the internal Flash mounted as device towards PC, First part is super easy using the demo programs from C:\.platformio\packages\framework-arduinoespressif32\libraries\USB\examples. My problem is that there is no example for MSC using Flash, only for a RamDisk and a FirmwareMSC .
I have found a nice example in chegewara's TinyUSB packet, but trying to combine this library with the internal lib of arduino-espressif looks very hard to me, while only simply creating the FlashUSB dev object ruins the demo program.
I am using Platformio arduino espressif for developement and here is the code:
#include <Arduino.h>
#include "FS.h"
#include "SD.h"
#include "USB.h"
#include "USBHIDMouse.h"
#include "USBHIDKeyboard.h"
USBHIDMouse Mouse;
USBHIDKeyboard Keyboard;
/**
* Simple MSC device, use fat partition
* author: chegewara
*/
#include "flashdisk.h"
#if 0
FlashUSB dev;
char *l1 = "ffat";
void setupFlash()
{
if (dev.init("/fat1", "ffat"))
{
if (dev.begin())
{
Serial.println("MSC lun 1 begin");
}
else
log_e("LUN 1 failed");
}
}
#endif
void setup()
{ // initialize the buttons' inputs:
Serial.begin(115200);
delay(100);
// initialize mouse control:
Mouse.begin();
Keyboard.begin();
USB.begin();
}
void loop()
{
// use serial input to control the mouse:
if (Serial.available() > 0)
{
char inChar = Serial.read();
Serial.printf(" > %c ", inChar);
switch (inChar)
{
case 'u':
// move mouse up
Mouse.move(0, -40);
Serial.println(" up ");
break;
case 'd':
// move mouse down
Mouse.move(0, 40);
Serial.println(" down ");
break;
}
}
delay(5);
}
This is the GOOD version and the output with debuglevel 5:
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x524
load:0x4004c000,len:0xa70
load:0x40050000,len:0x2914
entry 0x4004c18c
[ 497][D][esp32-hal-tinyusb.c:673] tinyusb_enable_interface(): Interface HID enabled
[ 497][D][USBHID.cpp:61] tinyusb_enable_hid_device(): Device[0] len: 79
[ 500][D][USBHID.cpp:61] tinyusb_enable_hid_device(): Device[1] len: 67
E (96) esp_core_dump_flash:[ 620][D][esp32-hal-tinyusb.c:562] tinyusb_load_enabled_interfaces(): Load Done: if_num: 1, descr_len: 41, if_mask: 0x4
[ 1073][V][USBHID.cpp:245] tud_hid_set_idle_cb(): instance: 0, idle_rate:0
[ 1074][V][USBHID.cpp:224] tud_hid_descriptor_report_cb(): instance: 0
[ 1076][D][USBHID.cpp:176] tinyusb_load_enabled_hid_devices(): Loaded HID Desriptor with the following reports:
[ 1085][D][USBHID.cpp:184] tinyusb_load_enabled_hid_devices(): ID: 2, Type: INPUT, Size: 5, Usage: MOUSE
[ 1095][D][USBHID.cpp:184] tinyusb_load_enabled_hid_devices(): ID: 1, Type: INPUT, Size: 8, Usage: KEYBOARD
[ 1106][D][USBHID.cpp:184] tinyusb_load_enabled_hid_devices(): ID: 1, Type: OUTPUT, Size: 1, Usage: KEYBOARD
Simply moving the
FlashUSB dev;
line above the #if 0 - gives output with missing loaded HID descriptors.
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x524
load:0x4004c000,len:0xa70
load:0x40050000,len:0x2914
entry 0x4004c18c
[ 498][D][esp32-hal-tinyusb.c:673] tinyusb_enable_interface(): Interface HID enabled
[ 498][D][USBHID.cpp:61] tinyusb_enable_hid_device(): Device[0] len: 79
[ 501][D][USBHID.cpp:61] tinyusb_enable_hid_device(): Device[1] len: 67
E (97) esp_core_dump_flash:[ 621][D][esp32-hal-tinyusb.c:562] tinyusb_load_enabled_interfaces(): Load Done: if_num: 1, descr_len: 41, if_mask: 0x4
Unfortunately I am newbie concerning USBs, and descriptors on a level needed to get past this obstacle. The best solution would be probably to have a simple internal Flash demo program with the ESP32-S2 own internal library. I feel that the solution is really easy - but only for someone familiar with USB.
Can someone help me a little bit here?
I have found a nice example in chegewara's TinyUSB packet, but trying to combine this library with the internal lib of arduino-espressif looks very hard to me, while only simply creating the FlashUSB dev object ruins the demo program.
I am using Platformio arduino espressif for developement and here is the code:
#include <Arduino.h>
#include "FS.h"
#include "SD.h"
#include "USB.h"
#include "USBHIDMouse.h"
#include "USBHIDKeyboard.h"
USBHIDMouse Mouse;
USBHIDKeyboard Keyboard;
/**
* Simple MSC device, use fat partition
* author: chegewara
*/
#include "flashdisk.h"
#if 0
FlashUSB dev;
char *l1 = "ffat";
void setupFlash()
{
if (dev.init("/fat1", "ffat"))
{
if (dev.begin())
{
Serial.println("MSC lun 1 begin");
}
else
log_e("LUN 1 failed");
}
}
#endif
void setup()
{ // initialize the buttons' inputs:
Serial.begin(115200);
delay(100);
// initialize mouse control:
Mouse.begin();
Keyboard.begin();
USB.begin();
}
void loop()
{
// use serial input to control the mouse:
if (Serial.available() > 0)
{
char inChar = Serial.read();
Serial.printf(" > %c ", inChar);
switch (inChar)
{
case 'u':
// move mouse up
Mouse.move(0, -40);
Serial.println(" up ");
break;
case 'd':
// move mouse down
Mouse.move(0, 40);
Serial.println(" down ");
break;
}
}
delay(5);
}
This is the GOOD version and the output with debuglevel 5:
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x524
load:0x4004c000,len:0xa70
load:0x40050000,len:0x2914
entry 0x4004c18c
[ 497][D][esp32-hal-tinyusb.c:673] tinyusb_enable_interface(): Interface HID enabled
[ 497][D][USBHID.cpp:61] tinyusb_enable_hid_device(): Device[0] len: 79
[ 500][D][USBHID.cpp:61] tinyusb_enable_hid_device(): Device[1] len: 67
E (96) esp_core_dump_flash:[ 620][D][esp32-hal-tinyusb.c:562] tinyusb_load_enabled_interfaces(): Load Done: if_num: 1, descr_len: 41, if_mask: 0x4
[ 1073][V][USBHID.cpp:245] tud_hid_set_idle_cb(): instance: 0, idle_rate:0
[ 1074][V][USBHID.cpp:224] tud_hid_descriptor_report_cb(): instance: 0
[ 1076][D][USBHID.cpp:176] tinyusb_load_enabled_hid_devices(): Loaded HID Desriptor with the following reports:
[ 1085][D][USBHID.cpp:184] tinyusb_load_enabled_hid_devices(): ID: 2, Type: INPUT, Size: 5, Usage: MOUSE
[ 1095][D][USBHID.cpp:184] tinyusb_load_enabled_hid_devices(): ID: 1, Type: INPUT, Size: 8, Usage: KEYBOARD
[ 1106][D][USBHID.cpp:184] tinyusb_load_enabled_hid_devices(): ID: 1, Type: OUTPUT, Size: 1, Usage: KEYBOARD
Simply moving the
FlashUSB dev;
line above the #if 0 - gives output with missing loaded HID descriptors.
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x524
load:0x4004c000,len:0xa70
load:0x40050000,len:0x2914
entry 0x4004c18c
[ 498][D][esp32-hal-tinyusb.c:673] tinyusb_enable_interface(): Interface HID enabled
[ 498][D][USBHID.cpp:61] tinyusb_enable_hid_device(): Device[0] len: 79
[ 501][D][USBHID.cpp:61] tinyusb_enable_hid_device(): Device[1] len: 67
E (97) esp_core_dump_flash:[ 621][D][esp32-hal-tinyusb.c:562] tinyusb_load_enabled_interfaces(): Load Done: if_num: 1, descr_len: 41, if_mask: 0x4
Unfortunately I am newbie concerning USBs, and descriptors on a level needed to get past this obstacle. The best solution would be probably to have a simple internal Flash demo program with the ESP32-S2 own internal library. I feel that the solution is really easy - but only for someone familiar with USB.
Can someone help me a little bit here?