board/stm32f401rc-rs485: Add support to Quadrature Encoder

Signed-off-by: Rodrigo Sim <rcsim10@gmail.com>
This commit is contained in:
Rodrigo Sim 2024-03-16 16:32:17 -03:00 committed by Alan Carvalho de Assis
parent b4407b529a
commit a7ba822389
5 changed files with 129 additions and 0 deletions

View file

@ -465,3 +465,32 @@ NSH commands::
nsh> pwm -d 50 -t 3
pwm_main: starting output with frequency: 50 duty: 00007fff
pwm_main: stopping output
qencoder
--------
Configures the NuttShell (nsh) over USB Serial (check usbserial configuration) and enables Timer 3 on channels 1 and
2 to handle Quadrature Encoder.
NSH commands::
nsh> qe -help
Usage: qe [OPTIONS]
OPTIONS include:
[-p devpath] QE device path
[-n samples] Number of samples
[-t msec] Delay between samples (msec)
[-r] Reset the position to zero
[-h] Shows this message and exits
nsh> qe -p /dev/qe0 -n 5 -t 100 -r
nsh: qe: too many arguments
qe_main: Hardware initialized. Opening the encoder device: /dev/qe0
qe_main: Resetting the count...
qe_main: Number of samples: 5
qe_main: 1. 0
qe_main: 2. 0
qe_main: 3. 4
qe_main: 4. 2
qe_main: 5. 2
Terminating!

View file

@ -0,0 +1,68 @@
#
# 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_FPU is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32f401rc-rs485"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_STM32F401RC_RS485=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F401RC=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_IRQBUTTONS=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_USBDEVCTRL=y
CONFIG_BOARD_LOOPSPERMSEC=8499
CONFIG_BUILTIN=y
CONFIG_CDCACM=y
CONFIG_CDCACM_CONSOLE=y
CONFIG_EXAMPLES_BUTTONS=y
CONFIG_EXAMPLES_BUTTONS_NAME0="SW3"
CONFIG_EXAMPLES_BUTTONS_NAME1="SW4"
CONFIG_EXAMPLES_BUTTONS_NAME2="SW5"
CONFIG_EXAMPLES_BUTTONS_NAMES=y
CONFIG_EXAMPLES_BUTTONS_QTD=3
CONFIG_EXAMPLES_QENCODER=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INPUT=y
CONFIG_INPUT_BUTTONS=y
CONFIG_INPUT_BUTTONS_LOWER=y
CONFIG_INTELHEX_BINARY=y
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=98304
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_SENSORS=y
CONFIG_SENSORS_QENCODER=y
CONFIG_SPI=y
CONFIG_START_DAY=5
CONFIG_START_MONTH=5
CONFIG_START_YEAR=2014
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_OTGFS=y
CONFIG_STM32_PWR=y
CONFIG_STM32_TIM3=y
CONFIG_STM32_TIM3_QE=y
CONFIG_STM32_USART6=y
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_USBDEV=y

View file

@ -290,6 +290,14 @@ extern "C"
#define GPIO_TIM3_CH1OUT GPIO_TIM3_CH1OUT_1
/* Quadrature Encoder
*
* Use Timer 3 (TIM3) on channels 1 and 2 for QEncoder, using PB4 and PA7.
*/
#define GPIO_TIM3_CH1IN GPIO_TIM3_CH1IN_2
#define GPIO_TIM3_CH2IN GPIO_TIM3_CH2IN_1
/* I2C
*
* The optional _GPIO configurations allow the I2C driver to manually

View file

@ -51,6 +51,10 @@
#include "stm32_lm75.h"
#endif
#ifdef CONFIG_SENSORS_QENCODER
#include "board_qencoder.h"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -201,5 +205,18 @@ int stm32_bringup(void)
}
#endif
#ifdef CONFIG_SENSORS_QENCODER
/* Initialize and register the qencoder driver */
ret = board_qencoder_initialize(0, STM32F401RCRS485_QETIMER);
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to register the qencoder: %d\n",
ret);
return ret;
}
#endif
return ret;
}

View file

@ -122,6 +122,13 @@
#define STM32F401RCRS485_PWMTIMER 3
#define STM32F401RCRS485_PWMCHANNEL 1
/* Quadrature Encoder
*
* Use Timer 3 (TIM3) on channels 1 and 2 for QEncoder, using PB4 and PA7.
*/
#define STM32F401RCRS485_QETIMER 3
/****************************************************************************
* Public Data
****************************************************************************/