Hello Lucas,
Indeed, the right way to handle this is to call a "get_speed" function once a USB_DEV_EVENT_BUS_RESET is received in the USB App Device callback, after this, you have to set this speed value by using USB_Desc_Set_Speed.
Look at these two examples, one is dev_msd_disk_bm_twrk65f180m (compatible with MK26):
void USB_App_Device_Callback(uint8_t event_type, void* val, void* arg)
{
if (event_type == USB_DEV_EVENT_BUS_RESET)
{
g_disk.start_app = FALSE;
if (USB_OK == USB_Class_MSC_Get_Speed(g_disk.app_handle, &g_disk.speed))
{
USB_Desc_Set_Speed(g_disk.app_handle, g_disk.speed);
}
}
And for example, in PEx I created a MSD example with dual speed and this also has to be handled the same:
void msd1_application_callback(uint8_t event_type, void * val, void * arg)
{
switch (event_type) {
case USB_DEV_EVENT_BUS_RESET: /* BUS reset received */
if (USB_OK == USB_Class_MSC_Get_Speed(msd1_MsdHandle, &g_device_speed)) {
usbDsc1_USB_Desc_Set_Speed(msd1_MsdHandle, g_device_speed);
}
break;
In CDC project, this is also handled:
if (event_type == USB_DEV_EVENT_BUS_RESET)
{
start_app = FALSE;
if (USB_OK == USB_Class_CDC_Get_Speed(handle, &g_cdc_device_speed))
{
USB_Desc_Set_Speed(handle, g_cdc_device_speed);
if (USB_SPEED_HIGH == g_cdc_device_speed)
{
g_bulk_out_max_packet_size = HS_DIC_BULK_OUT_ENDP_PACKET_SIZE;
g_bulk_in_max_packet_size = HS_DIC_BULK_IN_ENDP_PACKET_SIZE;
}
else
{
g_bulk_out_max_packet_size = FS_DIC_BULK_OUT_ENDP_PACKET_SIZE;
g_bulk_in_max_packet_size = FS_DIC_BULK_IN_ENDP_PACKET_SIZE;
}
}
}
So, this must be handled in USB_App_Device_Callback once the RESET event has been received, also, pay attention that Get speed functions is specific for used class and it will return the speed that is used according to the CONTROLLER_ID (KHCI or EHCI) that was used when USB_Class_Init was called.
Regards,
Isaac Avila