From b9490b85416db60faf3f995fbf6271fa73b000d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Fri, 24 May 2019 11:56:23 +0200 Subject: [PATCH] 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. --- .../USBHost/targets/TARGET_STM/USBHALHost_STM.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/features/unsupported/USBHost/targets/TARGET_STM/USBHALHost_STM.h b/features/unsupported/USBHost/targets/TARGET_STM/USBHALHost_STM.h index dd741ecd03..59d3e61f56 100644 --- a/features/unsupported/USBHost/targets/TARGET_STM/USBHALHost_STM.h +++ b/features/unsupported/USBHost/targets/TARGET_STM/USBHALHost_STM.h @@ -122,10 +122,17 @@ static gpio_t gpio_powerpin; void usb_vbus(uint8_t state) { - if (state == 0) { - gpio_write(&gpio_powerpin, USB_POWER_OFF); - } else { - gpio_write(&gpio_powerpin, USB_POWER_ON); + if (gpio_powerpin.reg_set && gpio_powerpin.reg_clr) + { + if (state == 0) { + gpio_write(&gpio_powerpin, USB_POWER_OFF); + } else { + gpio_write(&gpio_powerpin, USB_POWER_ON); + } + } + else + { + /* The board does not have GPIO pin to control usb supply */ } wait(0.2); }