2021-08-24 12:50 AM
I set stm32f401 to use USB and deinit USB to dP/dN to use normal GPIO.
But I can not control dP/dN for GPIO.
How can I switch GPIO function from USB to normal GPIO?
Solved! Go to Solution.
2021-08-24 03:34 AM
What is this, SPL?
I don't use SPL nor Cube. As I've said, make sure OTG_GCCFG.PWRDWN gets cleared. Read the post I've linked to above, and the posts linked from there.
JW
2021-08-24 01:28 AM
HAL_GPIO_Init can be used to set the target mode, same as any other GPIO pin. Ensure the clock is enabled. CubeMX will generate the code for you.
USB pins are not set up in USB mode by default.
2021-08-24 02:27 AM
I don't know what is "deinit USB", but in 'F407 - and most probably also in 'F401 - USB PHY overrides the GPIO settings, so you have to switch it off by clearing OTG_GCCFG.PWRDWN.
This is not documented by ST.
JW
2021-08-24 03:00 AM
I set the following process to switch USB DP/DN port to normal GPIO.
But it still in DP/DN mode and can not control as normal GPIO.
// USB Device Off (DP/DN Port Off ???)
if (USBH_Stop(&hUsbHostFS) != USBH_OK)
{
Error_Handler();
}
if (USBH_DeInit(&hUsbHostFS) != USBH_OK)
{
Error_Handler();
}
// DP/DN Port GPIO Input Mode
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = USB_DN_Pin|USB_DP_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2021-08-24 03:24 AM
I set the following process to switch USB DP/DN port to normal GPIO.
But it still in DP/DN mode and can not control as normal GPIO.
// USB Device Off (DP/DN Port Off ???)
if (USBH_Stop(&hUsbHostFS) != USBH_OK)
{
Error_Handler();
}
if (USBH_DeInit(&hUsbHostFS) != USBH_OK)
{
Error_Handler();
}
// DP/DN Port GPIO Input Mode
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = USB_DN_Pin|USB_DP_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2021-08-24 03:25 AM
I set the following process to switch USB DP/DN port to normal GPIO.
But it still in DP/DN mode and can not control as normal GPIO.
// USB Device Off (DP/DN Port Off ???)
if (USBH_Stop(&hUsbHostFS) != USBH_OK)
{
Error_Handler();
}
if (USBH_DeInit(&hUsbHostFS) != USBH_OK)
{
Error_Handler();
}
// DP/DN Port GPIO Input Mode
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = USB_DN_Pin|USB_DP_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2021-08-24 03:34 AM
What is this, SPL?
I don't use SPL nor Cube. As I've said, make sure OTG_GCCFG.PWRDWN gets cleared. Read the post I've linked to above, and the posts linked from there.
JW
2021-08-24 08:22 PM
Thanks!
Works well.