board/stm32f401rc-rs485: Add support to ultrasonic sensor HC-SR04

Signed-off-by: Rodrigo Sim rcsim10@gmail.com
This commit is contained in:
Rodrigo Sim 2024-05-18 12:20:46 -03:00 committed by Alan Carvalho de Assis
parent e6ed8c6782
commit 8fb458b7fe
4 changed files with 109 additions and 0 deletions

View File

@ -539,3 +539,19 @@ NSH commands::
mcsonn_main: Connected
nsh> msdis
hcs04
-----
Configures the NuttShell (nsh) over USB Serial (check usbserial configuration) and enables ultrasonic sensor HC-SR04::
nsh> cat /dev/dist0
6241 --> value
6227
6241
6255
You can convert the value using following::
Convert to cm: value/58
Converto to inches: value/148

View File

@ -0,0 +1,67 @@
#
# 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_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_HCSR04=y
CONFIG_SPI=y
CONFIG_START_DAY=5
CONFIG_START_MONTH=5
CONFIG_START_YEAR=2014
CONFIG_STM32_FREERUN=y
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_OTGFS=y
CONFIG_STM32_PWR=y
CONFIG_STM32_TIM1=y
CONFIG_STM32_USART6=y
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_USBDEV=y

View File

@ -298,6 +298,17 @@ extern "C"
#define GPIO_TIM3_CH1IN GPIO_TIM3_CH1IN_2
#define GPIO_TIM3_CH2IN GPIO_TIM3_CH2IN_1
/* HCSR04 driver */
/* Pins config to use with HC-SR04 sensor */
#define GPIO_HCSR04_INT (GPIO_INPUT |GPIO_FLOAT |GPIO_EXTI | GPIO_PORTB | GPIO_PIN1)
#define GPIO_HCSR04_TRIG (GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_SPEED_50MHz | GPIO_PORTB | GPIO_PIN0)
#define BOARD_HCSR04_GPIO_INT GPIO_HCSR04_INT
#define BOARD_HCSR04_GPIO_TRIG GPIO_HCSR04_TRIG
#define BOARD_HCSR04_FRTIMER 1 /* TIM1 as free running timer */
/* I2C
*
* The optional _GPIO configurations allow the I2C driver to manually

View File

@ -59,6 +59,11 @@
# include <nuttx/usb/rndis.h>
#endif
#ifdef CONFIG_SENSORS_HCSR04
#include "stm32_hcsr04.h"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -233,5 +238,15 @@ int stm32_bringup(void)
usbdev_rndis_initialize(mac);
#endif
#ifdef CONFIG_SENSORS_HCSR04
/* Configure and initialize the HC-SR04 distance sensor */
ret = board_hcsr04_initialize(0);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: board_hcsr04_initialize() failed: %d\n", ret);
}
#endif
return ret;
}