Skip to content

Commit c4d6b72

Browse files
pbaradaraiden00pl
authored andcommitted
boards/stm32h7: Add button support to nucleo-h743zi2
This patch adds support for the user button on nuclo-h743zi2 board (and nucleo-h753zi2 which is also a MB1364 board design) and enables button support and example in nucleo-h743zi2:jumbo configuration selector. Signed-off-by: Peter Barada <peter.barada@gmail.com>
1 parent 966be68 commit c4d6b72

8 files changed

Lines changed: 391 additions & 78 deletions

File tree

Documentation/platforms/arm/stm32h7/boards/nucleo-h743zi2/index.rst

Lines changed: 239 additions & 76 deletions
Large diffs are not rendered by default.

boards/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,7 @@ config ARCH_BOARD_NUCLEO_H743ZI2
19211921
depends on ARCH_CHIP_STM32H743ZI
19221922
select ARCH_HAVE_LEDS
19231923
select ARCH_HAVE_BUTTONS
1924+
select ARCH_HAVE_IRQBUTTONS
19241925
---help---
19251926
STMicro Nucleo H743ZI2 board based on the STMicro STM32H743ZI MCU.
19261927

boards/arm/stm32h7/nucleo-h743zi2/configs/jumbo/defconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
CONFIG_ARCH="arm"
1212
CONFIG_ARCH_BOARD="nucleo-h743zi2"
1313
CONFIG_ARCH_BOARD_NUCLEO_H743ZI2=y
14+
CONFIG_ARCH_BUTTONS=y
1415
CONFIG_ARCH_CHIP="stm32h7"
1516
CONFIG_ARCH_CHIP_STM32H743ZI=y
1617
CONFIG_ARCH_CHIP_STM32H7=y
1718
CONFIG_ARCH_CHIP_STM32H7_CORTEXM7=y
19+
CONFIG_ARCH_IRQBUTTONS=y
1820
CONFIG_ARCH_STACKDUMP=y
1921
CONFIG_ARMV7M_DCACHE=y
2022
CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y
@@ -32,6 +34,10 @@ CONFIG_DEBUG_USB_WARN=y
3234
CONFIG_DEFAULT_TASK_STACKSIZE=4096
3335
CONFIG_DHCPC_RENEW_STACKSIZE=2048
3436
CONFIG_ETH0_PHY_LAN8742A=y
37+
CONFIG_EXAMPLES_BUTTONS=y
38+
CONFIG_EXAMPLES_BUTTONS_NAME0="B1"
39+
CONFIG_EXAMPLES_BUTTONS_NAMES=y
40+
CONFIG_EXAMPLES_BUTTONS_QTD=1
3541
CONFIG_EXAMPLES_HIDKBD=y
3642
CONFIG_EXAMPLES_TOUCHSCREEN=y
3743
CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH="/dev/mouse0"
@@ -44,6 +50,8 @@ CONFIG_FS_PROCFS_REGISTER=y
4450
CONFIG_HAVE_CXX=y
4551
CONFIG_HAVE_CXXINITIALIZE=y
4652
CONFIG_INIT_ENTRYPOINT="nsh_main"
53+
CONFIG_INPUT_BUTTONS=y
54+
CONFIG_INPUT_BUTTONS_LOWER=y
4755
CONFIG_INTELHEX_BINARY=y
4856
CONFIG_LIBM=y
4957
CONFIG_LINE_MAX=64

boards/arm/stm32h7/nucleo-h743zi2/src/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ if(CONFIG_BOARDCTL_RESET)
5656
list(APPEND SRCS stm32_reset.c)
5757
endif()
5858

59+
if(CONFIG_ARCH_BUTTONS)
60+
list(APPEND SRCS stm32_buttons.c)
61+
endif()
62+
5963
target_sources(board PRIVATE ${SRCS})
6064

6165
set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")
@@ -64,6 +68,5 @@ if(NOT CONFIG_BUILD_FLAT)
6468
add_subdirectory(${NUTTX_BOARD_DIR}/kernel)
6569
set_property(
6670
GLOBAL PROPERTY LD_SCRIPT_USER ${NUTTX_BOARD_DIR}/scripts/memory.ld
67-
${NUTTX_BOARD_DIR}/scripts/user-space.ld)
71+
${NUTTX_BOARD_DIR}/scripts/user-space.ld)
6872
endif()
69-

boards/arm/stm32h7/nucleo-h743zi2/src/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ else
3434
CSRCS += stm32_userleds.c
3535
endif
3636

37+
ifeq ($(CONFIG_ARCH_BUTTONS),y)
38+
CSRCS += stm32_buttons.c
39+
endif
40+
3741
ifeq ($(CONFIG_STM32H7_OTGFS),y)
3842
CSRCS += stm32_usb.c
3943
endif

boards/arm/stm32h7/nucleo-h743zi2/src/nucleo-h743zi2.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@
8888
#define GPIO_LED_ORANGE GPIO_LD2
8989
#define GPIO_LED_RED GPIO_LD3
9090

91+
/* BUTTONS
92+
*
93+
* The Blue pushbutton B1, labeled "User", is connected to GPIO PC13.
94+
* A high value will be sensed when the button is depressed.
95+
* Note:
96+
* 1) That the EXTI is included in the definition to enable an interrupt
97+
* on this IO.
98+
* 2) The following definitions assume the default Solder Bridges are
99+
* installed.
100+
*/
101+
102+
#define GPIO_BTN_USER (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | GPIO_PORTC | GPIO_PIN13)
103+
91104
#define GPIO_OTGFS_VBUS (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz| \
92105
GPIO_OPENDRAIN|GPIO_PORTA|GPIO_PIN9)
93106

boards/arm/stm32h7/nucleo-h743zi2/src/stm32_bringup.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949

5050
#include "nucleo-h743zi2.h"
5151

52+
#ifdef CONFIG_INPUT_BUTTONS
53+
# include <nuttx/input/buttons.h>
54+
#endif
55+
5256
/****************************************************************************
5357
* Private Functions
5458
****************************************************************************/
@@ -157,6 +161,16 @@ int stm32_bringup(void)
157161
}
158162
#endif
159163

164+
#if defined(CONFIG_INPUT_BUTTONS_LOWER)
165+
/* Register the BUTTON driver */
166+
167+
ret = btn_lower_initialize("/dev/buttons");
168+
if (ret < 0)
169+
{
170+
syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret);
171+
}
172+
#endif /* CONFIG_INPUT_BUTTONS */
173+
160174
#ifdef HAVE_USBHOST
161175
/* Initialize USB host operation. stm32_usbhost_initialize()
162176
* starts a thread will monitor for USB connection and
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/****************************************************************************
2+
* boards/arm/stm32h7/nucleo-h743zi2/src/stm32_buttons.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <stddef.h>
30+
#include <errno.h>
31+
32+
#include <nuttx/irq.h>
33+
#include <nuttx/board.h>
34+
35+
#include "stm32_gpio.h"
36+
#include "nucleo-h743zi2.h"
37+
#include <arch/board/board.h>
38+
39+
#ifdef CONFIG_ARCH_BUTTONS
40+
41+
/****************************************************************************
42+
* Public Functions
43+
****************************************************************************/
44+
45+
/****************************************************************************
46+
* Name: board_button_initialize
47+
*
48+
* Description:
49+
* board_button_initialize() must be called to initialize button resources.
50+
* After that, board_buttons() may be called to collect the current state
51+
* of all buttons or board_button_irq() may be called to register button
52+
* interrupt handlers.
53+
*
54+
****************************************************************************/
55+
56+
uint32_t board_button_initialize(void)
57+
{
58+
stm32_configgpio(GPIO_BTN_USER);
59+
return NUM_BUTTONS;
60+
}
61+
62+
/****************************************************************************
63+
* Name: board_buttons
64+
****************************************************************************/
65+
66+
uint32_t board_buttons(void)
67+
{
68+
return stm32_gpioread(GPIO_BTN_USER) ? 1 : 0;
69+
}
70+
71+
/****************************************************************************
72+
* Button support.
73+
*
74+
* Description:
75+
* board_button_initialize() must be called to initialize button resources.
76+
* After that, board_buttons() may be called to collect the current state
77+
* of all buttons or board_button_irq() may be called to register button
78+
* interrupt handlers.
79+
*
80+
* After board_button_initialize() has been called, board_buttons() may be
81+
* called to collect the state of all buttons. board_buttons() returns a
82+
* 32-bit bit set with each bit associated with a button. See the
83+
* BUTTON_*_BIT definitions in board.h for the meaning of each bit.
84+
*
85+
* board_button_irq() may be called to register an interrupt handler that
86+
* will be called when a button is depressed or released. The ID value is
87+
* a button enumeration value that uniquely identifies a button resource.
88+
* See the BUTTON_* definitions in board.h for the meaning of enumeration
89+
* value.
90+
*
91+
****************************************************************************/
92+
93+
#ifdef CONFIG_ARCH_IRQBUTTONS
94+
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
95+
{
96+
int ret = -EINVAL;
97+
98+
if (id == BUTTON_USER)
99+
{
100+
ret = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true,
101+
irqhandler, arg);
102+
}
103+
104+
return ret;
105+
}
106+
#endif
107+
#endif /* CONFIG_ARCH_BUTTONS */

0 commit comments

Comments
 (0)