From 331b4cecc2cf5a21ce8de687dddf7d52293be202 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 27 Jul 2022 10:38:11 +0200 Subject: board: st: stm32mp2: add user button support Handle user button 2 to force boot with STM32CubeProgrammer. Signed-off-by: Patrick Delaunay Signed-off-by: Patrice Chotard --- board/st/stm32mp2/stm32mp2.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'board') diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c index 576a958c783..6e4f19b1664 100644 --- a/board/st/stm32mp2/stm32mp2.c +++ b/board/st/stm32mp2/stm32mp2.c @@ -5,6 +5,7 @@ #define LOG_CATEGORY LOGC_BOARD +#include #include #include #include @@ -13,10 +14,12 @@ #include #include #include +#include #include #include #include #include +#include /* * Get a global data pointer @@ -90,10 +93,33 @@ static int setup_led(enum led_state_t cmd) return ret; } +static void check_user_button(void) +{ + struct udevice *button; + int i; + + if (!IS_ENABLED(CONFIG_CMD_STM32PROG) || !IS_ENABLED(CONFIG_BUTTON)) + return; + + if (button_get_by_label("User-2", &button)) + return; + + for (i = 0; i < 21; ++i) { + if (button_get_state(button) != BUTTON_ON) + return; + if (i < 20) + mdelay(50); + } + + log_notice("entering download mode...\n"); + clrsetbits_le32(TAMP_BOOT_CONTEXT, TAMP_BOOT_FORCED_MASK, BOOT_STM32PROG); +} + /* board dependent setup after realloc */ int board_init(void) { setup_led(LEDST_ON); + check_user_button(); return 0; } -- cgit v1.3.1