update device_info example to work with p4 dcache

This commit is contained in:
hathach 2024-11-27 00:01:37 +07:00
parent 67e92e6688
commit 123f1affb7
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
4 changed files with 104 additions and 92 deletions

View File

@ -63,6 +63,14 @@ enum {
}; };
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED; static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
// Declare for buffer for usb transfer, may need to be in USB/DMA section and
// multiple of dcache line size if dcache is enabled (for some ports).
CFG_TUH_MEM_SECTION struct {
TUH_EPBUF_TYPE_DEF(tusb_desc_device_t, device);
TUH_EPBUF_DEF(serial, 64*sizeof(uint16_t));
TUH_EPBUF_DEF(buf, 128*sizeof(uint16_t));
} desc;
void led_blinking_task(void* param); void led_blinking_task(void* param);
static void print_utf16(uint16_t* temp_buf, size_t buf_len); static void print_utf16(uint16_t* temp_buf, size_t buf_len);
@ -109,60 +117,57 @@ void tuh_mount_cb(uint8_t daddr) {
blink_interval_ms = BLINK_MOUNTED; blink_interval_ms = BLINK_MOUNTED;
// Get Device Descriptor // Get Device Descriptor
tusb_desc_device_t desc_device; uint8_t xfer_result = tuh_descriptor_get_device_sync(daddr, &desc.device, 18);
uint8_t xfer_result = tuh_descriptor_get_device_sync(daddr, &desc_device, 18);
if (XFER_RESULT_SUCCESS != xfer_result) { if (XFER_RESULT_SUCCESS != xfer_result) {
printf("Failed to get device descriptor\r\n"); printf("Failed to get device descriptor\r\n");
return; return;
} }
uint16_t serial[64]; printf("Device %u: ID %04x:%04x SN ", daddr, desc.device.idVendor, desc.device.idProduct);
uint16_t buf[256]; xfer_result = tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, desc.serial, sizeof(desc.serial));
printf("Device %u: ID %04x:%04x SN ", daddr, desc_device.idVendor, desc_device.idProduct);
xfer_result = tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, serial, sizeof(serial));
if (XFER_RESULT_SUCCESS != xfer_result) { if (XFER_RESULT_SUCCESS != xfer_result) {
uint16_t* serial = (uint16_t*)(uintptr_t) desc.serial;
serial[0] = 'n'; serial[0] = 'n';
serial[1] = '/'; serial[1] = '/';
serial[2] = 'a'; serial[2] = 'a';
serial[3] = 0; serial[3] = 0;
} }
print_utf16(serial, TU_ARRAY_SIZE(serial)); print_utf16((uint16_t*)(uintptr_t) desc.serial, sizeof(desc.serial)/2);
printf("\r\n"); printf("\r\n");
printf("Device Descriptor:\r\n"); printf("Device Descriptor:\r\n");
printf(" bLength %u\r\n", desc_device.bLength); printf(" bLength %u\r\n", desc.device.bLength);
printf(" bDescriptorType %u\r\n", desc_device.bDescriptorType); printf(" bDescriptorType %u\r\n", desc.device.bDescriptorType);
printf(" bcdUSB %04x\r\n", desc_device.bcdUSB); printf(" bcdUSB %04x\r\n", desc.device.bcdUSB);
printf(" bDeviceClass %u\r\n", desc_device.bDeviceClass); printf(" bDeviceClass %u\r\n", desc.device.bDeviceClass);
printf(" bDeviceSubClass %u\r\n", desc_device.bDeviceSubClass); printf(" bDeviceSubClass %u\r\n", desc.device.bDeviceSubClass);
printf(" bDeviceProtocol %u\r\n", desc_device.bDeviceProtocol); printf(" bDeviceProtocol %u\r\n", desc.device.bDeviceProtocol);
printf(" bMaxPacketSize0 %u\r\n", desc_device.bMaxPacketSize0); printf(" bMaxPacketSize0 %u\r\n", desc.device.bMaxPacketSize0);
printf(" idVendor 0x%04x\r\n", desc_device.idVendor); printf(" idVendor 0x%04x\r\n", desc.device.idVendor);
printf(" idProduct 0x%04x\r\n", desc_device.idProduct); printf(" idProduct 0x%04x\r\n", desc.device.idProduct);
printf(" bcdDevice %04x\r\n", desc_device.bcdDevice); printf(" bcdDevice %04x\r\n", desc.device.bcdDevice);
// Get String descriptor using Sync API // Get String descriptor using Sync API
printf(" iManufacturer %u ", desc_device.iManufacturer); printf(" iManufacturer %u ", desc.device.iManufacturer);
xfer_result = tuh_descriptor_get_manufacturer_string_sync(daddr, LANGUAGE_ID, buf, sizeof(buf)); xfer_result = tuh_descriptor_get_manufacturer_string_sync(daddr, LANGUAGE_ID, desc.buf, sizeof(desc.buf));
if (XFER_RESULT_SUCCESS == xfer_result) { if (XFER_RESULT_SUCCESS == xfer_result) {
print_utf16(buf, TU_ARRAY_SIZE(buf)); print_utf16((uint16_t*)(uintptr_t) desc.buf, sizeof(desc.buf)/2);
} }
printf("\r\n"); printf("\r\n");
printf(" iProduct %u ", desc_device.iProduct); printf(" iProduct %u ", desc.device.iProduct);
xfer_result = tuh_descriptor_get_product_string_sync(daddr, LANGUAGE_ID, buf, sizeof(buf)); xfer_result = tuh_descriptor_get_product_string_sync(daddr, LANGUAGE_ID, desc.buf, sizeof(desc.buf));
if (XFER_RESULT_SUCCESS == xfer_result) { if (XFER_RESULT_SUCCESS == xfer_result) {
print_utf16(buf, TU_ARRAY_SIZE(buf)); print_utf16((uint16_t*)(uintptr_t) desc.buf, sizeof(desc.buf)/2);
} }
printf("\r\n"); printf("\r\n");
printf(" iSerialNumber %u ", desc_device.iSerialNumber); printf(" iSerialNumber %u ", desc.device.iSerialNumber);
printf((char*)serial); // serial is already to UTF-8 printf((char*)desc.serial); // serial is already to UTF-8
printf("\r\n"); printf("\r\n");
printf(" bNumConfigurations %u\r\n", desc_device.bNumConfigurations); printf(" bNumConfigurations %u\r\n", desc.device.bNumConfigurations);
} }
// Invoked when device is unmounted (bus reset/unplugged) // Invoked when device is unmounted (bus reset/unplugged)

View File

@ -364,16 +364,15 @@
#define TUP_DCD_ENDPOINT_MAX 16 // FS 7 ep, HS 16 ep #define TUP_DCD_ENDPOINT_MAX 16 // FS 7 ep, HS 16 ep
#define CFG_TUSB_OS_INC_PATH_DEFAULT freertos/ #define CFG_TUSB_OS_INC_PATH_DEFAULT freertos/
// #define CFG_TUH_DWC2_DMA_ENABLE_DEFAULT 1
// #define CFG_TUD_DWC2_SLAVE_ENABLE_DEFAULT 0
// Enable host/device dcache if DMA is enabled
#define CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT CFG_TUD_DWC2_DMA_ENABLE
#define CFG_TUH_MEM_DCACHE_ENABLE_DEFAULT CFG_TUH_DWC2_DMA_ENABLE
#define CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT 64 #define CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT 64
#if defined(CFG_TUD_DWC2_DMA_ENABLE) && CFG_TUD_DWC2_DMA_ENABLE == 1
#define CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT 1
#endif
#define CFG_TUH_DWC2_DMA_ENABLE_DEFAULT 0
#define CFG_TUH_MEM_DCACHE_ENABLE_DEFAULT 0
#elif TU_CHECK_MCU(OPT_MCU_ESP32, OPT_MCU_ESP32C2, OPT_MCU_ESP32C3, OPT_MCU_ESP32C6, OPT_MCU_ESP32H2) #elif TU_CHECK_MCU(OPT_MCU_ESP32, OPT_MCU_ESP32C2, OPT_MCU_ESP32C3, OPT_MCU_ESP32C6, OPT_MCU_ESP32H2)
#if (CFG_TUD_ENABLED || !(defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421)) #if (CFG_TUD_ENABLED || !(defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421))
#error "MCUs are only supported with CFG_TUH_MAX3421 enabled" #error "MCUs are only supported with CFG_TUH_MAX3421 enabled"

View File

@ -152,65 +152,65 @@ typedef struct {
#endif #endif
static usbh_class_driver_t const usbh_class_drivers[] = { static usbh_class_driver_t const usbh_class_drivers[] = {
#if CFG_TUH_CDC #if CFG_TUH_CDC
{ {
.name = DRIVER_NAME("CDC"), .name = DRIVER_NAME("CDC"),
.init = cdch_init, .init = cdch_init,
.deinit = cdch_deinit, .deinit = cdch_deinit,
.open = cdch_open, .open = cdch_open,
.set_config = cdch_set_config, .set_config = cdch_set_config,
.xfer_cb = cdch_xfer_cb, .xfer_cb = cdch_xfer_cb,
.close = cdch_close .close = cdch_close
}, },
#endif #endif
#if CFG_TUH_MSC #if CFG_TUH_MSC
{ {
.name = DRIVER_NAME("MSC"), .name = DRIVER_NAME("MSC"),
.init = msch_init, .init = msch_init,
.deinit = msch_deinit, .deinit = msch_deinit,
.open = msch_open, .open = msch_open,
.set_config = msch_set_config, .set_config = msch_set_config,
.xfer_cb = msch_xfer_cb, .xfer_cb = msch_xfer_cb,
.close = msch_close .close = msch_close
}, },
#endif #endif
#if CFG_TUH_HID #if CFG_TUH_HID
{ {
.name = DRIVER_NAME("HID"), .name = DRIVER_NAME("HID"),
.init = hidh_init, .init = hidh_init,
.deinit = hidh_deinit, .deinit = hidh_deinit,
.open = hidh_open, .open = hidh_open,
.set_config = hidh_set_config, .set_config = hidh_set_config,
.xfer_cb = hidh_xfer_cb, .xfer_cb = hidh_xfer_cb,
.close = hidh_close .close = hidh_close
}, },
#endif #endif
#if CFG_TUH_HUB #if CFG_TUH_HUB
{ {
.name = DRIVER_NAME("HUB"), .name = DRIVER_NAME("HUB"),
.init = hub_init, .init = hub_init,
.deinit = hub_deinit, .deinit = hub_deinit,
.open = hub_open, .open = hub_open,
.set_config = hub_set_config, .set_config = hub_set_config,
.xfer_cb = hub_xfer_cb, .xfer_cb = hub_xfer_cb,
.close = hub_close .close = hub_close
}, },
#endif #endif
#if CFG_TUH_VENDOR #if CFG_TUH_VENDOR
{ {
.name = DRIVER_NAME("VENDOR"), .name = DRIVER_NAME("VENDOR"),
.init = cush_init, .init = cush_init,
.deinit = cush_deinit, .deinit = cush_deinit,
.open = cush_open, .open = cush_open,
.set_config = cush_set_config, .set_config = cush_set_config,
.xfer_cb = cush_isr, .xfer_cb = cush_isr,
.close = cush_close .close = cush_close
} }
#endif #endif
}; };
enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(usbh_class_drivers) }; enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(usbh_class_drivers) };

View File

@ -249,12 +249,20 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#ifndef CFG_TUD_DWC2_SLAVE_ENABLE #ifndef CFG_TUD_DWC2_SLAVE_ENABLE
#define CFG_TUD_DWC2_SLAVE_ENABLE 1 #ifndef CFG_TUD_DWC2_SLAVE_ENABLE_DEFAULT
#define CFG_TUD_DWC2_SLAVE_ENABLE_DEFAULT 1
#endif
#define CFG_TUD_DWC2_SLAVE_ENABLE CFG_TUD_DWC2_SLAVE_ENABLE_DEFAULT
#endif #endif
// Enable DWC2 DMA for device // Enable DWC2 DMA for device
#ifndef CFG_TUD_DWC2_DMA_ENABLE #ifndef CFG_TUD_DWC2_DMA_ENABLE
#define CFG_TUD_DWC2_DMA_ENABLE 0 #ifndef CFG_TUD_DWC2_DMA_ENABLE_DEFAULT
#define CFG_TUD_DWC2_DMA_ENABLE_DEFAULT 0
#endif
#define CFG_TUD_DWC2_DMA_ENABLE CFG_TUD_DWC2_DMA_ENABLE_DEFAULT
#endif #endif
// Enable DWC2 Slave mode for host // Enable DWC2 Slave mode for host