2024-08-08 04:57 AM
I Created a New Project for the Following MCU's
I enabled the USB as Device and Also Selected Virtual Com Port as the Middleware and Generated the Project.
Upon Loading the Respective Projects to the MCU's The USB Ports were Identified as Virtual Com Port(Serial Port) on Windows OS. Thereby Confirming Device is rightly Configured and Identified on the Host System.
On Inspecting the Code in Detail, Neither in any of the Functions mentioned below, Do I see the Pin Assignment of PA11 and PA12 done. i.e. GPIO Mode, GPIO Speed, GPIO Alternating Functions, etc.
So Where Exactly are the Pins Assigned for their roles in the MX Generated Code. or what am I missing in my Understanding?
If the same is generated for lets say UART/SPI, Such Assignments are Done in HAL_UART_MspInit() Fn. respectively.
Solved! Go to Solution.
2024-08-12 02:32 AM
Hi @Pavan_LohiaGroup @Pavel A.
We typically configure AF10 but AF10 programming is not strictly necessary. The GPIO side is not in input/output mode. So, when we put GPIO into analog, this makes the IO work in additional function mode. So, it should not be the issue in your case!
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.
2024-08-08 07:11 AM
It depends on the chip. USB modes are not always alternate function modes.
If they need to be done, such as on the F401, they are done in HAL_PCD_MspInit. Here is what a new F401 project with VCP enabled generates:
/*******************************************************************************
LL Driver Callbacks (PCD -> USB Device Library)
*******************************************************************************/
/* MSP Init */
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(pcdHandle->Instance==USB_OTG_FS)
{
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
/* USER CODE END USB_OTG_FS_MspInit 0 */
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USB_OTG_FS GPIO Configuration
PA11 ------> USB_OTG_FS_DM
PA12 ------> USB_OTG_FS_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_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
/* USER CODE END USB_OTG_FS_MspInit 1 */
}
}
If that's not happening for you, attach your IOC.
2024-08-08 08:34 AM - edited 2024-08-08 08:34 AM
It seems the code generated by MX for STM32L072CZY is not complete, the HAL_PCD_MspInit is missing the GPIO configuration for the USB pins PA11 and PA12. An internal ticket 188390 is submitted to review code generation. By manually adding the GPIO configuration for PA11 and PA12, you can ensure that the USB is properly initialized.
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.
2024-08-09 04:11 AM - edited 2024-08-09 04:22 AM
Thank you @TDK I missed your point ! Indeed, USB data signals are not always used in alternate function modes.
F103 and L072 should be used as Additional function
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.
2024-08-09 05:11 AM
@FBL How Additional functions should be configured? If not as GPIO AFs, then via syscfg registers?
2024-08-12 12:09 AM
Hello @TDK ,
My Bad, I Checked the Code again and Yes You were Correct for F401RE.
Unfortunately The same Doesn't Apply for F103 and L072.
Though Pins are not Initialized or Configured, It Puzzles me how does the USB Port Still work.
I would Humble Request you to Try the same for F103 and L072 and Share me your Thoughts and Opinions too
2024-08-12 12:11 AM
Hi @FBL ,
Can You please Elaborate and Explain me, If Pins aren't Configured/Initialized, How does the VCP Code even Work?
2024-08-12 12:50 AM
@FBL, As It should be Configured or used as Additional Functions, Can You please Help us how should it be done.
2024-08-12 02:32 AM
Hi @Pavan_LohiaGroup @Pavel A.
We typically configure AF10 but AF10 programming is not strictly necessary. The GPIO side is not in input/output mode. So, when we put GPIO into analog, this makes the IO work in additional function mode. So, it should not be the issue in your case!
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.