cancel
Showing results for 
Search instead for 
Did you mean: 

H563/H573 - How to use the CC1,CC2 pins for GPIO and still get USB-MSC working

VT_Jim
Associate III

Folks,

 

I started off with the H573i discovery board demo as reference for the MSC + SD card (with ThreadX). 

I don't have the Discovery board since in my application I needed those CC1, CC2 USBPD pins for something else.  So I ran a board of my own (using the H563ZIT6).  I'm using just micro-USB B connector, not USB-C.

I set up the project in Cube and pulled in all the segments from the demo for H573I.

But in CubeMX I have to disable the UCPD in order to get access the two pins I need.

I just left the USB enabled.

But it seems that there is no USB library setup properly if the UCPD is disabled.

Can someone tell me how to get the demo from the H573 to work if the CC1, CC2 pins are disabled in Cube and assigned as GPIO? 

I don't have to have the ThreadX but figured it might be helpful as my product develops.  

Thanks!

J

 

1 ACCEPTED SOLUTION

Accepted Solutions
VT_Jim
Associate III

@Nicolas P. @FBL I found the issue - one step further.  CubeMX defaults the IO Speed setting for the MCO1 pin to low speed when it is enabled within the pin config (chip map).  This is done in the MX_GPIO_Init.  But the setting for the SystemClock is done BEFORE this MX_GPIO_Init.  

So the fast IO pin type setting of the SystemClock_Config gets overwritten with a Slow output setting for the pin.

I just put into the user code space another call to set the GPIO very fast again after.  

But this is worth a look by ST that you may want the tool to determine for the user which IO speed mode the pin assignment should be in based on what clocking speed they have configured in the Clock setup tool, or the MCO should be left alone when you get to your MX_GPIO_Init. 

 

View solution in original post

23 REPLIES 23
AScha.3
Chief II

Hi,

so you want access SD-card , and then USB as MSC device ? (Its like a sd-card reader on USB ? )

If you feel a post has answered your question, please click "Accept as Solution".
VT_Jim
Associate III

@AScha.3  I need to have this look like a microSD card reader to the user, but it is a memory controller device for a musical instrument.  Files get put into the SD via the USB.  

I have tested the SD (SDMMC1) is working fine.  It reads my cards.  I have also gotten the USB to show up on my PC as MSC device but with failure.  The event logs for Windows show that the USB has the correct Vendor ID, etc.  

But ThreadX crashes on me the moment I connect the USB cable.  

I selected to not use VBUS sensing.  My device is self powered and doesn't use the power from USB.

I had to manually add the line of code to initialize the RPU (pull up) on D+

So far, after more than a day of debugging, I know that drivers and event handlers are not working if the UCPD is not enabled.  But if I enable it, i lose the pins I need.

 

Can these H563/573 chips be used with the older USB ports without the UCPD (power delivery) and work within the CubeMX setup framework?

The IRQHandler is missing for something I believe.  But not sure how to tell which one?

 

VT_Jim_0-1712258763670.png

 

 

 

 

>The IRQHandler is missing for something I believe.  But not sure how to tell which one?

I dont understand . 🙂

But dont start/use WWDG , its just a funny problem more, until your prog is working fine. THEN use watchdog.

+

Yes, you can use "old" library without Azure - if you prefer. But it should work with rtos also.

+

I have never tried MSC device on my H563-nucleo , but MSC host and Audio host . 🙂 (much more problems...)

So i just can tell you : 

1. have a lot of ram space for threads... (otherwise crash)

2. maybe still the crazy error in Cube: it not enables power to USB !

If still the problem, add in stm32xxxx_hal_msp.c , at HAL_HCD_MspInit :

 

    /* Peripheral clock enable */
    __HAL_RCC_USB_CLK_ENABLE();
    /* USB_DRD_FS interrupt Init */
  /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */
    HAL_PWREx_EnableVddUSB();  // enable power !!!!
  /* USB_OTG_HS interrupt Init */
  HAL_NVIC_SetPriority(USB_DRD_FS_IRQn, 6, 0);
  HAL_NVIC_EnableIRQ(USB_DRD_FS_IRQn);
  /* USER CODE END USB_DRD_FS_MspInit 1 */
  }

 

 

If you feel a post has answered your question, please click "Accept as Solution".
VT_Jim
Associate III

@AScha.3 I checked and confirmed no watch dog is active.  It is not enabled in the CubeMX and doesn't appear in my code that I can find.  I believe that reference in the debug trace was that a RTOS watchdog service had an event that it trapped and when this event (interrupt) happens, it tosses the code into an assembly line forever loop within the TreadX assembly code.  In the code above that line it says this loop is to preserve the debug stack for unexpected Interrupts.  

I tried to enable the HAL_HCD_MspInit with a pre-compiler directive but when I do that, it flags a lot of missing files.  Any way to have Cube auto-generate this configuration with the older HCD enabled? 

Thanks for your help!

J

 

Sorry, what ? 

>enable the HAL_HCD_MspInit with a pre-compiler directive 

I showed you, how to write in xxxhal_msp.c (in your source directory)...so what you doing ???

+ its just the problem, HAL doing it wrong here. (Maybe corrected in later version, that i used.)

+> a lot of missing files --- should never happen, if you keep to what i showed.

If you feel a post has answered your question, please click "Accept as Solution".

Sorry for my confusion on your post above -

My MspInit already has the HAL_PWREx_EnableUSB.

The code you listed above matches what came out of CubeMX for me. 

So they must have fixed that bug you mentioned.

As I said - I do have the PC seeing this as a USB MSC and finds the correct VID/etc.  

I'm fairly confident the USB peripheral is powered. 

It is some interrupt handler that I must be missing somewhere.  

 

Good - error corrected now.

But then still - it should work then.

Whats first error , it shows ?

If you feel a post has answered your question, please click "Accept as Solution".
VT_Jim
Associate III

This is going to sound crazy but - I went into Cube and told it I have the UCPD peripheral and lost my two pins (CC1,CC2) that I wanted for something else.  

I recompiled and it still had the same crash, same problem.  

I tried reverting in CubeMX to compare which files changed.

I then went back to Cube and enabled the UCPD again and then compiled again. 

This time it worked!  I have the SD + the MSC finally working properly.  

There has to be some kind of issue over the order or sequence of setting things up that doesn't configure things correctly.  

I've committed a working copy and will see if I can narrow down what it was that changed in this process.

Such a huge sigh of relief however.  I thought i was going to have to make a new board spin just to switch to USB-C for this chip.  

Thanks for your help along the way in this! 

FBL
ST Employee

Hello @VT_Jim 

Have you tried the example provided in Cube?

STM32CubeH5/Projects/STM32H573I-DK/Applications/USBX/Ux_Host_MSC at main · STMicroelectronics/STM32CubeH5 · GitHub

You can disable UCPD port in IOC and regenerate. Please check again, it should compile and run. MX should import middleware without issues. If not, please provide your IOC file and screenshot crash.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.