2023-10-01 01:26 PM
as a somewhat naive fool i was thinking, CubeMX and ..IDE is a great tool to create a working basic program, running a chip/soc and its peripherals in short time. And the problems or errors in this tools will be removed sooner or later, leading to an almost perfect tool.
So i tried the "new" H563 , on NUCLEO-H563ZI , using SD-card and USB-stick as storage and driving USB-audio-host. ok, it has only one usb-port, so i tried just make an audio-host at first.
but surprise, i cannot use FATFS, because no more there in Cube, only Azure rtos and Filex from M**bleep** to choose...
ok, so i tried this. Nothing working - what a surprise.
And the only existing example is made only for IAR , not easy to get it to stm-IDE in any useful way.
So i tried now a new simple project: just use USB-MSC , to connect a USB-stick -- to see, whats missing , to get it activated in my usb-audio-host.
But surprise, not working...out of the box. :)
see: this its usb handling:
yes, really doing nothing. perfect tool.
in old times, with fatfs and "simple" usb lib, on H743 i did usb-msc-host, working really:
in my simple understanding of such complex thing, as connecting an usb-stick , this old MX generated code did something useful, the new "improvement" with Azure/rtos i just dont understand - for my small brain it just looks like people with no brain at all working here to do the best they can.
Solved! Go to Solution.
2024-02-06 07:14 AM
@xyzzy , maybe , if i remember all the things, i tried...
+ USB host -> for ? I did msc here, but more audio host i want to run - and got it running.
USB MSC host "did nothing" (as on first post shown), usb stick insertion empty;
here i had to put in this :
/* USER CODE BEGIN UX_DEVICE_INSERTION */
/* Get current Storage Class */
if (current_class -> ux_host_class_entry_function == ux_host_class_storage_entry)
{
for (idx = 0; idx < MSC_INSTANCE; )
{
if (storage_instance[idx] != NULL)
{
/* Move to next storage instance */
idx ++;
}
else
{
/* Get current Storage Instance */
storage_instance[idx] = (UX_HOST_CLASS_STORAGE *)current_instance;
msc_index = idx;
break;
}
}
printf("\nUSB Mass Storage Device Plugged");
printf("PID: %#x ", (UINT)storage_instance[msc_index] -> ux_host_class_storage_device -> ux_device_descriptor.idProduct);
printf("VID: %#x ", (UINT)storage_instance[msc_index] -> ux_host_class_storage_device -> ux_device_descriptor.idVendor);
/* Get the storage media */
storage_media = (UX_HOST_CLASS_STORAGE_MEDIA *)current_class -> ux_host_class_media;
if (storage_media[msc_index].ux_host_class_storage_media_lun != 0)
{
storage_media = UX_NULL;
}
else
{
/* Get the media file */
media[msc_index] = &storage_media[msc_index].ux_host_class_storage_media;
/* Check the storage class state */
if (storage_instance[msc_index] -> ux_host_class_storage_state == UX_HOST_CLASS_INSTANCE_LIVE)
{
/* Set STORAGE_MEDIA flag */
if (tx_event_flags_set(&ux_app_EventFlag, STORAGE_MEDIA, TX_OR) != TX_SUCCESS)
{
Error_Handler();
}
}
}
}
/* USER CODE END UX_DEVICE_INSERTION */
+ maybe if you use the newest "examples" from STM on github, its already there.
+
for audio host : unbelievable , but the basic problem was: the USB port was not powered at all !!!
in xxx_hal_msp.c i had to add:
void HAL_HCD_MspInit(HCD_HandleTypeDef* hhcd)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hhcd->Instance==USB_DRD_FS)
{
/* USER CODE BEGIN USB_DRD_FS_MspInit 0 */
/* USER CODE END USB_DRD_FS_MspInit 0 */
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USB GPIO Configuration
PA11 ------> USB_DM
PA12 ------> USB_DP
*/
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_USB;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_USB_CLK_ENABLE();
/* USB_DRD_FS interrupt Init */
HAL_NVIC_SetPriority(USB_DRD_FS_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(USB_DRD_FS_IRQn);
/* USER CODE BEGIN USB_DRD_FS_MspInit 1 */
HAL_PWREx_EnableVddUSB(); // this was missing !!!! so no power at all...
/* USER CODE END USB_DRD_FS_MspInit 1 */
}
}
+ then, with power enabled, surprise, surprise -- it begins to work !
2023-10-01 01:51 PM
2023-10-01 02:39 PM
so...is the state machine (usb_connect /..disconect etc) populated there ? or empty frame like i see on H563 ?
and where is activation/setting of usb peripheral (hardware) ?
in all these files with very informative and creative names i cannot find, where the hardware is set to useful state:
the usb registers just stay at this state without any change :
2023-10-05 08:54 AM
3 days later....
:unamused_face:
2024-02-06 06:49 AM
@AScha.3 can you share what you needed to change to get the USB host working?
2024-02-06 07:14 AM
@xyzzy , maybe , if i remember all the things, i tried...
+ USB host -> for ? I did msc here, but more audio host i want to run - and got it running.
USB MSC host "did nothing" (as on first post shown), usb stick insertion empty;
here i had to put in this :
/* USER CODE BEGIN UX_DEVICE_INSERTION */
/* Get current Storage Class */
if (current_class -> ux_host_class_entry_function == ux_host_class_storage_entry)
{
for (idx = 0; idx < MSC_INSTANCE; )
{
if (storage_instance[idx] != NULL)
{
/* Move to next storage instance */
idx ++;
}
else
{
/* Get current Storage Instance */
storage_instance[idx] = (UX_HOST_CLASS_STORAGE *)current_instance;
msc_index = idx;
break;
}
}
printf("\nUSB Mass Storage Device Plugged");
printf("PID: %#x ", (UINT)storage_instance[msc_index] -> ux_host_class_storage_device -> ux_device_descriptor.idProduct);
printf("VID: %#x ", (UINT)storage_instance[msc_index] -> ux_host_class_storage_device -> ux_device_descriptor.idVendor);
/* Get the storage media */
storage_media = (UX_HOST_CLASS_STORAGE_MEDIA *)current_class -> ux_host_class_media;
if (storage_media[msc_index].ux_host_class_storage_media_lun != 0)
{
storage_media = UX_NULL;
}
else
{
/* Get the media file */
media[msc_index] = &storage_media[msc_index].ux_host_class_storage_media;
/* Check the storage class state */
if (storage_instance[msc_index] -> ux_host_class_storage_state == UX_HOST_CLASS_INSTANCE_LIVE)
{
/* Set STORAGE_MEDIA flag */
if (tx_event_flags_set(&ux_app_EventFlag, STORAGE_MEDIA, TX_OR) != TX_SUCCESS)
{
Error_Handler();
}
}
}
}
/* USER CODE END UX_DEVICE_INSERTION */
+ maybe if you use the newest "examples" from STM on github, its already there.
+
for audio host : unbelievable , but the basic problem was: the USB port was not powered at all !!!
in xxx_hal_msp.c i had to add:
void HAL_HCD_MspInit(HCD_HandleTypeDef* hhcd)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hhcd->Instance==USB_DRD_FS)
{
/* USER CODE BEGIN USB_DRD_FS_MspInit 0 */
/* USER CODE END USB_DRD_FS_MspInit 0 */
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USB GPIO Configuration
PA11 ------> USB_DM
PA12 ------> USB_DP
*/
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_USB;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_USB_CLK_ENABLE();
/* USB_DRD_FS interrupt Init */
HAL_NVIC_SetPriority(USB_DRD_FS_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(USB_DRD_FS_IRQn);
/* USER CODE BEGIN USB_DRD_FS_MspInit 1 */
HAL_PWREx_EnableVddUSB(); // this was missing !!!! so no power at all...
/* USER CODE END USB_DRD_FS_MspInit 1 */
}
}
+ then, with power enabled, surprise, surprise -- it begins to work !
2024-02-06 07:18 AM - edited 2024-02-08 10:28 PM
@AScha.3 The trap here is that ST marketing does way better job that software development does while USB is an animal particularly difficult to deal with - but you already know that. It is what it is. After listening some nice high-level presentation starting with "Hello and welcome to this presentation on..." for the most part you are on your own.
I think ST is still hoping to have low-cost self-supporting engineers community inspired by several likely compensated individuals.
It is not going to work for one fundamental reason I recently realized: people offering their precious time to help others usually do it to fulfill their own needs, to feel good about themselves earning kudos and virtual badges while usually well-paid top engineers just do not have such needs to fulfill.
I do not know if it helps, but I have a working example for USB MSC and STM32U5 I shared here to get ST's help.
It took me weeks to get it working. Probably you want to use FileX (exFAT support) and USBX, thus ThreadX.
2024-02-06 07:25 AM
@AScha.3 brilliant, thank you! I was missing the call to HAL_PWREx_EnableVddUSB() so the USB registers were just sat there not signalling any device attached.