From 7a0aec00efad374586a641d1c391dac9b48717e4 Mon Sep 17 00:00:00 2001 From: Michael Ossmann Date: Tue, 27 Sep 2022 14:45:58 -0400 Subject: [PATCH] h1r9: fix usb_vendor_request_reset() The bootloader is configured by pin straps on certain pins. We use some of those for other purposes in r9 which causes the bootloader to misbehave if the device is reset from software. By switching these pins from outputs to inputs just before reset this problem is avoided. --- firmware/hackrf_usb/usb_api_board_info.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/firmware/hackrf_usb/usb_api_board_info.c b/firmware/hackrf_usb/usb_api_board_info.c index e6a2b8f2..97f92a99 100644 --- a/firmware/hackrf_usb/usb_api_board_info.c +++ b/firmware/hackrf_usb/usb_api_board_info.c @@ -33,6 +33,13 @@ #include #include +#ifdef HACKRF_ONE + #include "gpio_lpc.h" +static struct gpio_t gpio_h1r9_clkout_en = GPIO(0, 9); +static struct gpio_t gpio_h1r9_mcu_clk_en = GPIO(0, 8); +static struct gpio_t gpio_h1r9_rx = GPIO(0, 7); +#endif + usb_request_status_t usb_vendor_request_read_board_id( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) @@ -123,7 +130,19 @@ usb_request_status_t usb_vendor_request_reset( const usb_transfer_stage_t stage) { if (stage == USB_TRANSFER_STAGE_SETUP) { +#ifdef HACKRF_ONE + /* + * Set boot pins as inputs so that the bootloader reads them + * correctly after the reset. + */ + if (detected_platform() == BOARD_ID_HACKRF1_R9) { + gpio_input(&gpio_h1r9_mcu_clk_en); + gpio_input(&gpio_h1r9_clkout_en); + gpio_input(&gpio_h1r9_rx); + } +#endif wwdt_reset(100000); + usb_transfer_schedule_ack(endpoint->in); } return USB_REQUEST_STATUS_OK;