arch/xtensa: add support for brushed DC motor control

arch/xtensa: add support for capture driver on ESP32 and ESP32|S3|

Squashed:
Initial settings for MCPWM Capture on board level
Created lower half files - compilation ok
Using capture debug features. Simple example on fops works
Successful duty and freq calculation
Documentation update
Fixed and added interupt capabilities for all 3 capture channels
Cleaned defconfig
Renamed macros, added S3 options and moved arch source to common dir
Added support for ESP32S3
Added capture example to defconfig and renamed

Basic bring up ready. New Kconfig options for motor.

Good motor registration

Working on enabling pwm generators

Working on enabling pwm generators

Added fops functions

Success on PWM 50%

stable pwm operation for bdc

Added loopback option for testing

Improved rules on fsm

Working motor direction control

Testing new ISR for fault handling

Issues on fault ISR

Removed fault implementation (not working)

Added support for esp32s3

Documentation improvements

Added default motor spin direction

Added parameter change while running

Review fixes

arch/xtensa: add support for fault signal on motor control

Squashed:
Initial settings for MCPWM Capture on board level
Created lower half files - compilation ok
Using capture debug features. Simple example on fops works
Successful duty and freq calculation
Documentation update
Fixed and added interupt capabilities for all 3 capture channels
Cleaned defconfig
Renamed macros, added S3 options and moved arch source to common dir
Added support for ESP32S3
Added capture example to defconfig and renamed

Basic bring up ready. New Kconfig options for motor.

Good motor registration

Working on enabling pwm generators

Working on enabling pwm generators

Added fops functions

Success on PWM 50%

stable pwm operation for bdc

Added loopback option for testing

Improved rules on fsm

Working motor direction control

Testing new ISR for fault handling

Issues on fault ISR

Removed fault implementation (not working)

Added support for esp32s3

Documentation improvements

Added default motor spin direction

Added parameter change while running

Got responsive fault indicator

Working brakes - still need to work on starting isr

Fixed single-time ISR initializiation

Working soft brake on fault

Improved KConfig for BDC and BLDC

Kconfig fixed at board level
This commit is contained in:
Filipe Cavalcanti
2024-07-03 09:49:11 -03:00
committed by Xiang Xiao
parent b57079e88e
commit 91dfd20eaf
17 changed files with 1897 additions and 72 deletions
@@ -43,6 +43,25 @@ extern "C"
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32_motor_initialize
*
* Description:
* Initialize MCPWM peripheral for motor control and register the motor
* driver.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ESP_MCPWM_MOTOR_BDC
int board_motor_initialize(void);
#endif
#ifdef CONFIG_ESP_MCPWM_CAPTURE
/****************************************************************************
@@ -29,6 +29,7 @@
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/motor/motor.h>
#include <nuttx/timers/capture.h>
#include <arch/board/board.h>
@@ -39,10 +40,59 @@
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_ESP_MCPMW_MOTOR_CH0_FAULT
# define MCPWM_FAULT_GPIO CONFIG_ESP_MCPMW_MOTOR_CH0_FAULT_GPIO
#else
# define MCPWM_FAULT_GPIO 0
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_motor_initialize
*
* Description:
* Initialize MCPWM peripheral for motor control and register the motor
* driver.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ESP_MCPWM_MOTOR_BDC
int board_motor_initialize(void)
{
int ret;
struct motor_lowerhalf_s *motor;
motor = esp_motor_bdc_initialize(0,
CONFIG_ESP_MCPWM_MOTOR_CH0_PWM_FREQ,
CONFIG_ESP_MCPWM_MOTOR_CH0_PWMA_GPIO,
CONFIG_ESP_MCPWM_MOTOR_CH0_PWMB_GPIO,
MCPWM_FAULT_GPIO);
if (!motor)
{
syslog(LOG_ERR, "ERROR: Failed to start MCPWM BDC Motor: CH0\n");
return -ENODEV;
}
ret = motor_register("/dev/motor0", motor);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: motor_register failed: %d\n", ret);
return ret;
}
return OK;
}
#endif
/****************************************************************************
* Name: board_capture_initialize
*
@@ -23,6 +23,7 @@ CONFIG_ESP32_UART0=y
CONFIG_ESP_MCPWM=y
CONFIG_ESP_MCPWM_CAPTURE=y
CONFIG_ESP_MCPWM_CAPTURE_CH0=y
CONFIG_ESP_MCPWM_CAPTURE_CH0_GPIO=14
CONFIG_EXAMPLES_CAPTURE=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
@@ -0,0 +1,50 @@
#
# 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_ARCH_LEDS is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="xtensa"
CONFIG_ARCH_BOARD="esp32-devkitc"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32_DEVKITC=y
CONFIG_ARCH_CHIP="esp32"
CONFIG_ARCH_CHIP_ESP32=y
CONFIG_ARCH_CHIP_ESP32WROVER=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_XTENSA=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_ESP32_UART0=y
CONFIG_ESP_MCPWM=y
CONFIG_ESP_MCPWM_MOTOR=y
CONFIG_ESP_MCPWM_MOTOR_BDC=y
CONFIG_ESP_MCPWM_MOTOR_CH0=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=3072
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=3072
CONFIG_INTELHEX_BINARY=y
CONFIG_MM_REGIONS=3
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=114688
CONFIG_RAM_START=0x20000000
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_SYSLOG_BUFFER=y
CONFIG_SYSTEM_NSH=y
CONFIG_UART0_SERIAL_CONSOLE=y
@@ -295,6 +295,14 @@ int esp32_bringup(void)
}
#endif
#ifdef CONFIG_ESP_MCPWM_MOTOR_BDC
ret = board_motor_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: board_motor_initialize failed: %d\n", ret);
}
#endif
#ifdef CONFIG_SENSORS_MAX6675
ret = board_max6675_initialize(0, 2);
if (ret < 0)