From: Vikas Manocha Date: Mon, 10 Apr 2017 22:03:00 +0000 (-0700) Subject: stm32f746: to switch on user LED1 & read user button X-Git-Tag: v2017.07-rc1~439 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2f80a9f72ecf4cfee68279a45e3c155f6516faa1;p=u-boot stm32f746: to switch on user LED1 & read user button All discovery boards have one user button & one user LED. Here we are just reading the button status & switching ON the user LED. Signed-off-by: Vikas Manocha cc: Christophe KERELLO --- diff --git a/arch/arm/dts/stm32f746-disco.dts b/arch/arm/dts/stm32f746-disco.dts index f830aa90ef..8e4576bdc1 100644 --- a/arch/arm/dts/stm32f746-disco.dts +++ b/arch/arm/dts/stm32f746-disco.dts @@ -78,6 +78,16 @@ gpio9 = &gpioj; gpio10 = &gpiok; }; + + led1 { + compatible = "st,led1"; + led-gpio = <&gpioi 1 0>; + }; + + button1 { + compatible = "st,button1"; + button-gpio = <&gpioi 11 0>; + }; }; &clk_hse { diff --git a/board/st/stm32f746-disco/stm32f746-disco.c b/board/st/stm32f746-disco/stm32f746-disco.c index 45a2c47aa2..52c1900ee3 100644 --- a/board/st/stm32f746-disco/stm32f746-disco.c +++ b/board/st/stm32f746-disco/stm32f746-disco.c @@ -17,6 +17,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -72,6 +73,42 @@ u32 get_board_rev(void) return 0; } +int board_late_init(void) +{ + struct gpio_desc gpio = {}; + int node; + + node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1"); + if (node < 0) + return -1; + + gpio_request_by_name_nodev(gd->fdt_blob, node, "led-gpio", 0, &gpio, + GPIOD_IS_OUT); + + if (dm_gpio_is_valid(&gpio)) { + dm_gpio_set_value(&gpio, 0); + mdelay(10); + dm_gpio_set_value(&gpio, 1); + } + + /* read button 1*/ + node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1"); + if (node < 0) + return -1; + + gpio_request_by_name_nodev(gd->fdt_blob, node, "button-gpio", 0, &gpio, + GPIOD_IS_IN); + + if (dm_gpio_is_valid(&gpio)) { + if (dm_gpio_get_value(&gpio)) + puts("usr button is at HIGH LEVEL\n"); + else + puts("usr button is at LOW LEVEL\n"); + } + + return 0; +} + int board_init(void) { gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; diff --git a/include/configs/stm32f746-disco.h b/include/configs/stm32f746-disco.h index e917ba9162..48ac4413e0 100644 --- a/include/configs/stm32f746-disco.h +++ b/include/configs/stm32f746-disco.h @@ -75,4 +75,5 @@ #define CONFIG_CMD_MEM #define CONFIG_CMD_CACHE +#define CONFIG_BOARD_LATE_INIT #endif /* __CONFIG_H */