You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/11/02 16:54:13 UTC
[incubator-nuttx] branch master updated: boards/b-g431b-esc1: add
Hall and Qenco support
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 1c28126 boards/b-g431b-esc1: add Hall and Qenco support
1c28126 is described below
commit 1c28126670d25816f49e1e4d4ab279d23e205331
Author: raiden00pl <ra...@railab.me>
AuthorDate: Tue Nov 2 10:46:10 2021 +0100
boards/b-g431b-esc1: add Hall and Qenco support
---
boards/arm/stm32/b-g431b-esc1/README.txt | 6 ++--
boards/arm/stm32/b-g431b-esc1/include/board.h | 5 +++
boards/arm/stm32/b-g431b-esc1/src/b-g431b-esc1.h | 11 +++++++
boards/arm/stm32/b-g431b-esc1/src/stm32_bringup.c | 37 +++++++++++++++++++++++
boards/arm/stm32/b-g431b-esc1/src/stm32_foc.c | 21 +++++++++++++
5 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/boards/arm/stm32/b-g431b-esc1/README.txt b/boards/arm/stm32/b-g431b-esc1/README.txt
index 4b84636..6dc45e7 100644
--- a/boards/arm/stm32/b-g431b-esc1/README.txt
+++ b/boards/arm/stm32/b-g431b-esc1/README.txt
@@ -43,9 +43,9 @@ Configuration Sub-directories
VBUS ADC1_IN1 PA0
POT ADC1_IN11 PB12
LED GPIO_PC6 PC6
- ENCO_A/HALL_H1 PB6
- ENCO_B/HALL_H2 PB7
- ENCO_Z/HALL_H3 PB8
+ ENCO_A/HALL_H1 TIM4_CH1 PB6
+ ENCO_B/HALL_H2 TIM4_CH2 PB7
+ ENCO_Z/HALL_H3 TIM4_CH3 PB8
BUTTON GPIO_PC10 PC10
PWM PA15
diff --git a/boards/arm/stm32/b-g431b-esc1/include/board.h b/boards/arm/stm32/b-g431b-esc1/include/board.h
index 67946a4..872c00c 100644
--- a/boards/arm/stm32/b-g431b-esc1/include/board.h
+++ b/boards/arm/stm32/b-g431b-esc1/include/board.h
@@ -229,6 +229,11 @@
#define GPIO_TIM1_CH2NOUT GPIO_TIM1_CH2NOUT_1 /* TIM1 CH2N - PA12 - V low */
#define GPIO_TIM1_CH3NOUT GPIO_TIM1_CH3NOUT_3 /* TIM1 CH3N - PB15 - W low */
+/* TIM4 QE configuration ****************************************************/
+
+#define GPIO_TIM4_CH1IN GPIO_TIM4_CH1IN_2 /* TIM4 CH1 - PB6 */
+#define GPIO_TIM4_CH2IN GPIO_TIM4_CH2IN_2 /* TIM4 CH2 - PB7 */
+
/* DMA channels *************************************************************/
/* ADC */
diff --git a/boards/arm/stm32/b-g431b-esc1/src/b-g431b-esc1.h b/boards/arm/stm32/b-g431b-esc1/src/b-g431b-esc1.h
index 450ba85..46e139e 100644
--- a/boards/arm/stm32/b-g431b-esc1/src/b-g431b-esc1.h
+++ b/boards/arm/stm32/b-g431b-esc1/src/b-g431b-esc1.h
@@ -70,6 +70,17 @@
#define GPIO_BTN_USER (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTC|GPIO_PIN10)
+#ifdef CONFIG_SENSORS_HALL3PHASE
+/* GPIO pins used by the 3-phase Hall effect sensor */
+
+# define GPIO_HALL_PHA (GPIO_INPUT | GPIO_SPEED_5MHz | \
+ GPIO_PORTB | GPIO_PIN6)
+# define GPIO_HALL_PHB (GPIO_INPUT | GPIO_SPEED_5MHz | \
+ GPIO_PORTB | GPIO_PIN7)
+# define GPIO_HALL_PHC (GPIO_INPUT | GPIO_SPEED_5MHz | \
+ GPIO_PORTB | GPIO_PIN8)
+#endif
+
/****************************************************************************
* Public Data
****************************************************************************/
diff --git a/boards/arm/stm32/b-g431b-esc1/src/stm32_bringup.c b/boards/arm/stm32/b-g431b-esc1/src/stm32_bringup.c
index 166e3e3..044e535 100644
--- a/boards/arm/stm32/b-g431b-esc1/src/stm32_bringup.c
+++ b/boards/arm/stm32/b-g431b-esc1/src/stm32_bringup.c
@@ -29,6 +29,8 @@
#include <nuttx/board.h>
+#include <stm32.h>
+
#ifdef CONFIG_USERLED
# include <nuttx/leds/userled.h>
#endif
@@ -37,6 +39,14 @@
# include <nuttx/input/buttons.h>
#endif
+#ifdef CONFIG_SENSORS_QENCODER
+# include "board_qencoder.h"
+#endif
+
+#ifdef CONFIG_SENSORS_HALL3PHASE
+# include "board_hall3ph.h"
+#endif
+
#include "b-g431b-esc1.h"
/****************************************************************************
@@ -112,6 +122,33 @@ int stm32_bringup(void)
}
#endif
+#ifdef CONFIG_SENSORS_QENCODER
+ /* Initialize and register the qencoder driver - TIM4 */
+
+ ret = board_qencoder_initialize(0, 4);
+ if (ret != OK)
+ {
+ syslog(LOG_ERR,
+ "ERROR: Failed to register the qencoder: %d\n",
+ ret);
+ return ret;
+ }
+#endif
+
+#ifdef CONFIG_SENSORS_HALL3PHASE
+ /* Initialize and register the 3-phase Hall effect sensor driver */
+
+ ret = board_hall3ph_initialize(0, GPIO_HALL_PHA, GPIO_HALL_PHB,
+ GPIO_HALL_PHC);
+ if (ret != OK)
+ {
+ syslog(LOG_ERR,
+ "ERROR: Failed to register the hall : %d\n",
+ ret);
+ return ret;
+ }
+#endif
+
UNUSED(ret);
return OK;
}
diff --git a/boards/arm/stm32/b-g431b-esc1/src/stm32_foc.c b/boards/arm/stm32/b-g431b-esc1/src/stm32_foc.c
index 4d1c8bd..0dc8d15 100644
--- a/boards/arm/stm32/b-g431b-esc1/src/stm32_foc.c
+++ b/boards/arm/stm32/b-g431b-esc1/src/stm32_foc.c
@@ -34,6 +34,10 @@
#include "hardware/stm32g4xxxx_opamp.h"
+#if defined(CONFIG_SENSORS_QENCODER) || defined(CONFIG_SENSORS_HALL3PHASE)
+# include "hardware/stm32g4xxxx_pwr.h"
+#endif
+
#include "stm32_foc.h"
#include "arm_arch.h"
@@ -169,6 +173,17 @@
# error
#endif
+/* Qenco configuration - only TIM4 */
+
+#ifdef CONFIG_SENSORS_QENCODER
+# ifndef CONFIG_STM32_TIM4_QE
+# error
+# endif
+# if CONFIG_STM32_TIM4_QEPSC != 0
+# error
+# endif
+#endif
+
/****************************************************************************
* Private Types
****************************************************************************/
@@ -569,6 +584,12 @@ int stm32_adc_setup(void)
if (initialized == false)
{
+#if defined(CONFIG_SENSORS_QENCODER) || defined(CONFIG_SENSORS_HALL3PHASE)
+ /* Disable USB Type-C and Power Delivery Dead Battery */
+
+ modifyreg32(STM32_PWR_CR3, 0, PWR_CR3_UCPD1_DBDIS);
+#endif
+
if (g_foc_dev == NULL)
{
mtrerr("Failed to get g_foc_dev device\n");