From: Quentin Schulz Date: Fri, 3 Nov 2023 09:28:12 +0000 (+0100) Subject: rockchip: ringneck-px30: always reset STM32 companion controller on boot X-Git-Url: http://git.dujemihanovic.xyz/%22http:/www.sics.se/static/git-favicon.png?a=commitdiff_plain;h=6acdd63e87714b6b0292788d7f1f39899119527a;p=u-boot.git rockchip: ringneck-px30: always reset STM32 companion controller on boot It's happened that glitches on the STM32_RST and STM32_BOOT lines have put the STM32 companion microcontroller into DFU mode making it not boot its FW, rendering it useless for the user. Considering that the STM32 companion microcontroller is always reset on a reboot or power cycle, resetting it once again in U-Boot SPL isn't going to hurt it any more. For ATtiny companion microcontroller, the situation is a bit different because a reboot or power cycle doesn't reset it. Additionally, since it can only be reset with a UPDI reset on the STM32_RST line, and that is virtually impossible to mistakenly trigger, the ATtiny is unlikely to be in unwanted reset or enter reset because U-Boot toggles STM32_RST line. Cc: Quentin Schulz Signed-off-by: Quentin Schulz Reviewed-by: Heiko Stuebner Reviewed-by: Kever Yang --- diff --git a/board/theobroma-systems/ringneck_px30/ringneck-px30.c b/board/theobroma-systems/ringneck_px30/ringneck-px30.c index bb1bb4acf5..537ce0d1d1 100644 --- a/board/theobroma-systems/ringneck_px30/ringneck-px30.c +++ b/board/theobroma-systems/ringneck_px30/ringneck-px30.c @@ -16,12 +16,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include @@ -169,3 +171,54 @@ int misc_init_r(void) return 0; } + +#define STM32_RST 100 /* GPIO3_A4 */ +#define STM32_BOOT 101 /* GPIO3_A5 */ + +void spl_board_init(void) +{ + /* + * Glitches on STM32_BOOT and STM32_RST lines during poweroff or power + * on may put the STM32 companion microcontroller into DFU mode, let's + * always reset it into normal mode instead. + * Toggling the STM32_RST line is safe to do with the ATtiny companion + * microcontroller variant because it will not trigger an MCU reset + * since only a UPDI reset command will. Since a UPDI reset is difficult + * to mistakenly trigger, glitches to the lines are theoretically also + * incapable of triggering an actual ATtiny reset. + */ + int ret; + + ret = gpio_request(STM32_RST, "STM32_RST"); + if (ret) { + debug("Failed to request STM32_RST\n"); + return; + } + + ret = gpio_request(STM32_BOOT, "STM32_BOOT"); + if (ret) { + debug("Failed to request STM32_BOOT\n"); + return; + } + + /* Rely on HW pull-down for inactive level */ + ret = gpio_direction_input(STM32_BOOT); + if (ret) { + debug("Failed to configure STM32_BOOT as input\n"); + return; + } + + ret = gpio_direction_output(STM32_RST, 0); + if (ret) { + debug("Failed to configure STM32_RST as output low\n"); + return; + } + + mdelay(1); + + ret = gpio_direction_output(STM32_RST, 1); + if (ret) { + debug("Failed to configure STM32_RST as output high\n"); + return; + } +}