diff --git a/boards/arm/stm32/b-g431b-esc1/README.txt b/boards/arm/stm32/b-g431b-esc1/README.txt index 4b846366bc1..6dc45e77650 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 67946a45992..872c00c658c 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 450ba85a38b..46e139efb84 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 166e3e3ed2c..044e5355e93 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 +#include + #ifdef CONFIG_USERLED # include #endif @@ -37,6 +39,14 @@ # include #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 4d1c8bd5157..0dc8d1532d8 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");