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
commit f2405ccc57ba1c259984fc27b69398a79146104b Author: raiden00pl <[email protected]> AuthorDate: Sat Nov 6 19:14:32 2021 +0100 boards/b-g431b-esc1: register Qenco index pin --- boards/arm/stm32/b-g431b-esc1/src/b-g431b-esc1.h | 7 ++++++ boards/arm/stm32/b-g431b-esc1/src/stm32_foc.c | 28 +++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) 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 46e139e..afa2052 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,13 @@ #define GPIO_BTN_USER (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTC|GPIO_PIN10) +#ifdef CONFIG_SENSORS_QENCODER +/* Qenco index pin */ + +# define QENCODER_TIM4_INDEX_GPIO (GPIO_INPUT | GPIO_FLOAT |\ + GPIO_EXTI | GPIO_PORTB | GPIO_PIN8) +#endif + #ifdef CONFIG_SENSORS_HALL3PHASE /* GPIO pins used by the 3-phase Hall effect sensor */ 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 0dc8d15..291a590 100644 --- a/boards/arm/stm32/b-g431b-esc1/src/stm32_foc.c +++ b/boards/arm/stm32/b-g431b-esc1/src/stm32_foc.c @@ -40,6 +40,10 @@ #include "stm32_foc.h" +#ifdef CONFIG_SENSORS_QENCODER +# include "stm32_qencoder.h" +#endif + #include "arm_arch.h" #include "b-g431b-esc1.h" @@ -535,6 +539,24 @@ int stm32_foc_setup(void) if (g_foc_dev == NULL) { +#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 defined(CONFIG_SENSORS_QENCODER) && defined(CONFIG_STM32_QENCODER_INDEX_PIN) + /* Configure encoder index GPIO */ + + ret = stm32_qe_index_init(4, QENCODER_TIM4_INDEX_GPIO); + if (ret < 0) + { + mtrerr("Failed to register encoder index pin %d\n", ret); + ret = -EACCES; + goto errout; + } +#endif + /* Initialize arch specific FOC lower-half */ foc = stm32_foc_initialize(0, &g_stm32_foc_board); @@ -584,12 +606,6 @@ 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");
