From f5527eaf0ec8c984775c066470c484fabbe9eb84 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 1/2] 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); } From 5d33fe1dfaca5715e04993a8b99d281366240abb Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Mon, 3 Jun 2019 08:44:41 +0100 Subject: [PATCH 2/2] unsupported USBHAL: fix coding style --- .../USBHost/targets/TARGET_STM/USBHALHost_STM.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/features/unsupported/USBHost/targets/TARGET_STM/USBHALHost_STM.h b/features/unsupported/USBHost/targets/TARGET_STM/USBHALHost_STM.h index 59d3e61f56..4233490eca 100644 --- a/features/unsupported/USBHost/targets/TARGET_STM/USBHALHost_STM.h +++ b/features/unsupported/USBHost/targets/TARGET_STM/USBHALHost_STM.h @@ -122,16 +122,13 @@ static gpio_t gpio_powerpin; void usb_vbus(uint8_t state) { - if (gpio_powerpin.reg_set && gpio_powerpin.reg_clr) - { + 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 - { + } else { /* The board does not have GPIO pin to control usb supply */ } wait(0.2);