mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 05:42:05 +08:00
boards/b-g431b-esc1: add Hall and Qenco support
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
****************************************************************************/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user