Skip to content

Commit f5527ea

Browse files
committed
STM USBHALHost: Fix NULL pointer dereference
On STM32F746G Discovery boards, the USB OTG HS port does not have a dedicated GPIO for controlling the USB VBUS. This change fixes HardFault (NULL pointer dereference) that triggered when such USB host port was used.
1 parent c4cc9c4 commit f5527ea

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

features/unsupported/USBHost/targets/TARGET_STM/USBHALHost_STM.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,17 @@ static gpio_t gpio_powerpin;
122122

123123
void usb_vbus(uint8_t state)
124124
{
125-
if (state == 0) {
126-
gpio_write(&gpio_powerpin, USB_POWER_OFF);
127-
} else {
128-
gpio_write(&gpio_powerpin, USB_POWER_ON);
125+
if (gpio_powerpin.reg_set && gpio_powerpin.reg_clr)
126+
{
127+
if (state == 0) {
128+
gpio_write(&gpio_powerpin, USB_POWER_OFF);
129+
} else {
130+
gpio_write(&gpio_powerpin, USB_POWER_ON);
131+
}
132+
}
133+
else
134+
{
135+
/* The board does not have GPIO pin to control usb supply */
129136
}
130137
wait(0.2);
131138
}

0 commit comments

Comments
 (0)