2024-04-13 03:02 AM - edited 2024-04-13 03:02 AM
I think there is a bug with code generation when USB_OTG_HS_Dx is selected for PA11 and PA12 pins and USB_OTG_HS peripheral is not active:
then there is this code generated in MX_GPIO_Init() function:
/*Configure GPIO pins : PA11 PA12 */
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_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
.Mode is set to alternate function but there is missing setting of GPIO_InitTypeDef.Alternate field. In this case, USB is not Alternate function but Additonal function, which means that no configuration is needed here and the USB peripheral manages it itself when it is configured. Indeed, when USB_OTG_HS peripheral is initialized from the GUI, this code disappears. I think this is a bug because in our case, code like this was generated:
/*Configure GPIO pins : PB14 PB15 */
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_SDMMC2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
...
/*Configure GPIO pins : USB_N_Pin USB_P_Pin */
GPIO_InitStruct.Pin = USB_N_Pin|USB_P_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
so PA11 and PA12 got mapped to FDCAN (alternate function 9 is FDCAN in this case) which collided with the 'real' FDCAN pins and CAN1 did not work at all.
IDE version: 1.15.0
STM32CubeMX version: 6.11.0
MCU: STM32H723ZG
Similar to this thread: https://community.st.com/t5/stm32cubemx-mcus/missing-alternate-function-on-spi-pins-in-cubemx-generated-code/m-p/76662/highlight/true#M1342
Solved! Go to Solution.
2024-04-19 03:07 AM
Hello @heveskar
After sharing this with the concerned team. So, it is not required to add the code to configure the USB DP/DM as those pins are directly connected to USB IP as soon as this IP is enabled.
Best Regards.
STTwo-32
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-04-13 06:22 AM - edited 2024-04-17 08:54 AM
Hello @heveskar
Thank you for reporting this. I've escalated to the concerned team for more investigation and correction (under internal ticket number 179279)
Best Regards.
STTwo-32
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-04-19 03:07 AM
Hello @heveskar
After sharing this with the concerned team. So, it is not required to add the code to configure the USB DP/DM as those pins are directly connected to USB IP as soon as this IP is enabled.
Best Regards.
STTwo-32
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-04-22 10:45 PM
@STTwo-32 As you don't state it explicitly, hope that it is clear that it is a bug in the code generator as it shouldn't do the initialization at all.
2024-04-22 11:21 PM
If you set the Pins as alternate function USB DP/DM but you don't activate the IP, The Code will be generated to set both pins to this alternate function. But when you activate the USB IP, the USB DP/DM pins are directly connected to USB IP. So, it is not required to add the code to configure them.
Best Regards.
STTwo-32
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-04-22 11:33 PM
If you set the Pins as alternate function USB DP/DM but you don't activate the IP, The Code will be generated to set both pins to this alternate function.
OK but this is the problem I am trying to report, I have selected alternate function without IP activation, then there was generated code that configures GPIO to alternate function, but this member of the GPIO structure was left unitialized:
GPIO_InitStruct.Alternate
This meant that there was left previous value from the code, which in this case was 9 which in this case corresponds to FDCAN1 and therefore FDCAN1 stopped working. My point was that the code shouldn't be there at all regardless if USB IP is enabled or not.
In other words, in the GUI, when PA11 and PA12 was set to USB alternate function without USB IP enabled, FDCAN1 stopped working. Don't you see that as a bug?
2024-04-22 11:36 PM
Can you give a more details about how we can reproduce this.
Best Regards.
STTwo-32
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-04-23 12:17 AM
So now I noticed that there is another factor for that issue to happen, SDMMC pins must also be used with alternate function without SDMMC peripheral enabled. Here is what's needed:
MCU STM32H723ZGT
In the GUI - Pins PD0 and PD1 mapped to FDCAN1 (RX, TX) with the peripheral enabled.
Pins PB14, PB15, PD6, PD7, PG11, PG12 mapped to SDMMC (D0, D1, CK, CMD, D2, D3) without the peripheral enabled.
PA11, PA12 to USB DM and DP without the peripheral enabled.
This code is generated in MX_GPIO_Init() which sets PA11 and PA12 to incorrect alternate function.
...
/*Configure GPIO pins : PB14 PB15 */
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_SDMMC2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : PA11 PA12 */
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_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2024-04-23 01:50 AM
Thank you so Much for this description. Can you please create a new post using this description to give it more visibility on the Community. I will reply immediately if you mention me on the new post.
Best Regards.
STTwo-32
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.