This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 738a30a421 stm32h7/linum-stm32h753bi: add support to qencoder
738a30a421 is described below
commit 738a30a4213a38158d3f8136faa6f563a054e424
Author: Jorge Guzman <[email protected]>
AuthorDate: Sat Jul 6 09:11:02 2024 -0300
stm32h7/linum-stm32h753bi: add support to qencoder
Signed-off-by: Jorge Guzman <[email protected]>
---
.../arm/stm32h7/boards/linum-stm32h753bi/index.rst | 16 +++++-
.../linum-stm32h753bi/configs/qencoder/defconfig | 60 ++++++++++++++++++++
.../arm/stm32h7/linum-stm32h753bi/include/board.h | 4 ++
.../stm32h7/linum-stm32h753bi/src/CMakeLists.txt | 4 ++
boards/arm/stm32h7/linum-stm32h753bi/src/Makefile | 4 ++
.../linum-stm32h753bi/src/linum-stm32h753bi.h | 17 ++++++
.../stm32h7/linum-stm32h753bi/src/stm32_bringup.c | 13 +++++
.../stm32h7/linum-stm32h753bi/src/stm32_qencoder.c | 66 ++++++++++++++++++++++
8 files changed, 183 insertions(+), 1 deletion(-)
diff --git
a/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst
b/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst
index 7a2c3d5ac7..55fd0f249f 100644
--- a/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst
+++ b/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst
@@ -754,4 +754,18 @@ This configuration is focused on network testing using the
ethernet periferal::
56 bytes from 142.251.129.110: icmp_seq=8 time=0.0 ms
56 bytes from 142.251.129.110: icmp_seq=9 time=0.0 ms
10 packets transmitted, 10 received, 0% packet loss, time 10100 ms
- rtt min/avg/max/mdev = 0.000/1.000/10.000/3.000 ms
\ No newline at end of file
+ rtt min/avg/max/mdev = 0.000/1.000/10.000/3.000 ms
+
+qencoder
+--------
+
+Configures and enables TIM5 on CH1(PA0) and CH2(PH11) to handle Quadrature
Encoder:
+
+ nsh> qe
+ qe_main: Hardware initialized. Opening the encoder device: /dev/qe0
+ qe_main: Number of samples: 0
+ qe_main: 1. 1
+ qe_main: 2. 2
+ qe_main: 3. 3
+ qe_main: 4. 2
+ qe_main: 5. 1
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/configs/qencoder/defconfig
b/boards/arm/stm32h7/linum-stm32h753bi/configs/qencoder/defconfig
new file mode 100644
index 0000000000..745971d558
--- /dev/null
+++ b/boards/arm/stm32h7/linum-stm32h753bi/configs/qencoder/defconfig
@@ -0,0 +1,60 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed
.config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that
includes your
+# modifications.
+#
+# CONFIG_NSH_DISABLE_IFCONFIG is not set
+# CONFIG_NSH_DISABLE_PS is not set
+# CONFIG_STANDARD_SERIAL is not set
+# CONFIG_STM32H7_USE_LEGACY_PINMAP is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="linum-stm32h753bi"
+CONFIG_ARCH_BOARD_LINUM_STM32H753BI=y
+CONFIG_ARCH_CHIP="stm32h7"
+CONFIG_ARCH_CHIP_STM32H753BI=y
+CONFIG_ARCH_CHIP_STM32H7=y
+CONFIG_ARCH_CHIP_STM32H7_CORTEXM7=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y
+CONFIG_ARMV7M_DTCM=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_BOARD_LOOPSPERMSEC=43103
+CONFIG_BUILTIN=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_EXAMPLES_ALARM=y
+CONFIG_EXAMPLES_QENCODER=y
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INTELHEX_BINARY=y
+CONFIG_LIBM=y
+CONFIG_MM_REGIONS=4
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=245760
+CONFIG_RAM_START=0x20010000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_RTC_ALARM=y
+CONFIG_RTC_DATETIME=y
+CONFIG_RTC_DRIVER=y
+CONFIG_SCHED_WAITPID=y
+CONFIG_SENSORS=y
+CONFIG_SENSORS_QENCODER=y
+CONFIG_START_DAY=6
+CONFIG_START_MONTH=12
+CONFIG_START_YEAR=2011
+CONFIG_STM32H7_PWR=y
+CONFIG_STM32H7_RTC=y
+CONFIG_STM32H7_TIM5=y
+CONFIG_STM32H7_TIM5_QE=y
+CONFIG_STM32H7_USART1=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_USART1_SERIAL_CONSOLE=y
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/include/board.h
b/boards/arm/stm32h7/linum-stm32h753bi/include/board.h
index 1568e8ff31..594ed09015 100644
--- a/boards/arm/stm32h7/linum-stm32h753bi/include/board.h
+++ b/boards/arm/stm32h7/linum-stm32h753bi/include/board.h
@@ -439,6 +439,10 @@
#define GPIO_ETH_RMII_TXD1 (GPIO_ETH_RMII_TXD1_3|GPIO_SPEED_100MHz) /*
PG14 */
#define GPIO_ETH_RMII_TX_EN (GPIO_ETH_RMII_TX_EN_2|GPIO_SPEED_100MHz) /*
PG11 */
+/* QEncoder - TIM5: CH1 and CH2 */
+#define GPIO_TIM5_CH1IN GPIO_TIM5_CH1IN_1 /* PA0 */
+#define GPIO_TIM5_CH2IN GPIO_TIM5_CH2IN_2 /* PH11 */
+
/****************************************************************************
* Public Data
****************************************************************************/
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt
b/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt
index 89d40328ad..69027401bf 100644
--- a/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt
+++ b/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt
@@ -60,6 +60,10 @@ if(CONFIG_USBMSC)
list(APPEND SRCS stm32_usbmsc.c)
endif()
+if(CONFIG_SENSORS_QENCODER)
+ list(APPEND SRCS stm32_qencoder.c)
+endif()
+
target_sources(board PRIVATE ${SRCS})
set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile
b/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile
index 3ba420bd68..38a08c9bd3 100644
--- a/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile
+++ b/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile
@@ -58,6 +58,10 @@ ifeq ($(CONFIG_USBMSC),y)
CSRCS += stm32_usbmsc.c
endif
+ifeq ($(CONFIG_SENSORS_QENCODER),y)
+CSRCS += stm32_qencoder.c
+endif
+
ifeq ($(CONFIG_BOARDCTL),y)
CSRCS += stm32_appinitialize.c
endif
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h
b/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h
index 72a6a9284e..19942b0ca2 100644
--- a/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h
+++ b/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h
@@ -111,6 +111,13 @@
#define GPIO_ETH_RESET (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_100MHz |\
GPIO_OUTPUT_CLEAR | GPIO_PORTI | GPIO_PIN4) /* PI4
*/
+/* Quadrature Encoder
+ *
+ * Use Timer 5 (TIM3) on channels 2 and 2 for QEncoder, using PB4 and PA7.
+ */
+
+#define LINUMSTM32H753BI_QETIMER 5
+
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@@ -207,4 +214,14 @@ int stm32_pwm_setup(void);
int stm32_w25qxxx_setup(void);
#endif
+/****************************************************************************
+ * Name: board_qencoder_initialize
+ *
+ * Description:
+ * Initialize the quadrature encoder driver for the given timer
+ *
+ ****************************************************************************/
+
+int board_qencoder_initialize(int devno, int timerno);
+
#endif /* __BOARDS_ARM_STM32H7_LINUM_STM32H753BI_SRC_LINUM_STM32H753BI_H */
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c
b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c
index c093ca3d4e..c50094ca8e 100644
--- a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c
+++ b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c
@@ -266,5 +266,18 @@ int stm32_bringup(void)
usbdev_rndis_initialize(mac);
#endif
+#if defined(CONFIG_SENSORS_QENCODER)
+ /* Initialize and register the qencoder driver */
+
+ ret = board_qencoder_initialize(0, LINUMSTM32H753BI_QETIMER);
+ if (ret != OK)
+ {
+ syslog(LOG_ERR,
+ "ERROR: Failed to register the qencoder: %d\n",
+ ret);
+ return ret;
+ }
+#endif
+
return OK;
}
diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_qencoder.c
b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_qencoder.c
new file mode 100644
index 0000000000..308adfc861
--- /dev/null
+++ b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_qencoder.c
@@ -0,0 +1,66 @@
+/****************************************************************************
+ * boards/arm/stm32h7/linum-stm32h753bi/src/stm32_qencoder.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <debug.h>
+#include <stdio.h>
+
+#include <nuttx/sensors/qencoder.h>
+#include <arch/board/board.h>
+
+#include "chip.h"
+#include "arm_internal.h"
+#include "stm32_qencoder.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_qencoder_initialize
+ *
+ * Description:
+ * Initialize the quadrature encoder driver for the given timer
+ *
+ ****************************************************************************/
+
+int board_qencoder_initialize(int devno, int timerno)
+{
+ int ret;
+ char devpath[12];
+
+ /* Initialize a quadrature encoder interface. */
+
+ sninfo("Initializing the quadrature encoder using TIM%d\n", timerno);
+ snprintf(devpath, 12, "/dev/qe%d", devno);
+ ret = stm32_qeinitialize(devpath, timerno);
+ if (ret < 0)
+ {
+ snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
+ }
+
+ return ret;
+}