mirror of
https://github.com/apache/nuttx.git
synced 2026-05-09 23:12:17 +08:00
boards/nucleo-c0XX: add qencoder support
add qencoder support for nucleo-c0 boards Signed-off-by: raiden00pl <raiden00@railab.me>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32f0l0g0/common/include/board_qencoder.h
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __BOARDS_ARM_STM32F0L0G0_COMMON_INCLUDE_BOARD_QENCODER_H
|
||||
#define __BOARDS_ARM_STM32F0L0G0_COMMON_INCLUDE_BOARD_QENCODER_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the quadrature encoder driver for the given timer
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_qencoder_initialize(int devno, int timerno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __BOARDS_ARM_STM32F0L0G0_COMMON_INCLUDE_BOARD_QENCODER_H */
|
||||
@@ -26,5 +26,9 @@ if(CONFIG_ARCH_BOARD_COMMON)
|
||||
list(APPEND SRCS stm32_ssd1306.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_SENSORS_QENCODER)
|
||||
list(APPEND SRCS stm32_qencoder.c)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
target_sources(board PRIVATE ${SRCS})
|
||||
|
||||
@@ -26,6 +26,10 @@ ifeq ($(CONFIG_LCD_SSD1306),y)
|
||||
CSRCS += stm32_ssd1306.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_QENCODER),y)
|
||||
CSRCS += board_qencoder.c
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path src
|
||||
VPATH += :src
|
||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32f0l0g0/common/src/board_qencoder.c
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/sensors/qencoder.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "chip.h"
|
||||
#include "arm_internal.h"
|
||||
#include "stm32_qencoder.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_qencoder_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the quadrature encoder driver for the given timer
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_qencoder_initialize(int devno, int timerno)
|
||||
{
|
||||
int ret;
|
||||
char devpath[12];
|
||||
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
sninfo("Initializing the quadrature encoder using TIM%d\n", timerno);
|
||||
snprintf(devpath, sizeof(devpath), "/dev/qe%d", devno);
|
||||
ret = stm32_qeinitialize(devpath, timerno);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -12,6 +12,7 @@ CONFIG_ADC=y
|
||||
CONFIG_ANALOG=y
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="nucleo-c071rb"
|
||||
CONFIG_ARCH_BOARD_COMMON=y
|
||||
CONFIG_ARCH_BOARD_NUCLEO_C071RB=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP="stm32f0l0g0"
|
||||
@@ -38,6 +39,7 @@ CONFIG_EXAMPLES_ADC_GROUPSIZE=2
|
||||
CONFIG_EXAMPLES_ADC_SWTRIG=y
|
||||
CONFIG_EXAMPLES_BUTTONS=y
|
||||
CONFIG_EXAMPLES_HELLO=y
|
||||
CONFIG_EXAMPLES_QENCODER=y
|
||||
CONFIG_EXAMPLES_WATCHDOG=y
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_INIT_STACKSIZE=1536
|
||||
@@ -60,6 +62,8 @@ CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SENSORS=y
|
||||
CONFIG_SENSORS_QENCODER=y
|
||||
CONFIG_START_DAY=19
|
||||
CONFIG_START_MONTH=5
|
||||
CONFIG_START_YEAR=2013
|
||||
@@ -68,6 +72,8 @@ CONFIG_STM32F0L0G0_ADC1=y
|
||||
CONFIG_STM32F0L0G0_ADC_MAX_SAMPLES=6
|
||||
CONFIG_STM32F0L0G0_DMA1=y
|
||||
CONFIG_STM32F0L0G0_IWDG=y
|
||||
CONFIG_STM32F0L0G0_TIM3=y
|
||||
CONFIG_STM32F0L0G0_TIM3_QE=y
|
||||
CONFIG_STM32F0L0G0_USART2=y
|
||||
CONFIG_STM32F0L0G0_WWDG=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
|
||||
@@ -162,6 +162,14 @@
|
||||
#define GPIO_USART2_RX (GPIO_USART2_RX_1|GPIO_SPEED_HIGH) /* PA3 */
|
||||
#define GPIO_USART2_TX (GPIO_USART2_TX_1|GPIO_SPEED_HIGH) /* PA2 */
|
||||
|
||||
/* Qencoder on TIM3:
|
||||
* TIM3_CH1IN - PB4 (D5)
|
||||
* TIM3_CH2IN - PC7 (D3)
|
||||
*/
|
||||
|
||||
#define GPIO_TIM3_CH1IN (GPIO_TIM3_CH1IN_2|GPIO_SPEED_HIGH)
|
||||
#define GPIO_TIM3_CH2IN (GPIO_TIM3_CH2IN_6|GPIO_SPEED_HIGH)
|
||||
|
||||
/* DMA channels *************************************************************/
|
||||
|
||||
/* ADC */
|
||||
|
||||
@@ -42,6 +42,10 @@
|
||||
# include <stm32_wdg.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSORS_QENCODER
|
||||
# include "board_qencoder.h"
|
||||
#endif
|
||||
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "nucleo-c071rb.h"
|
||||
@@ -109,6 +113,19 @@ int stm32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSORS_QENCODER
|
||||
/* Initialize and register the qencoder driver - TIM3 */
|
||||
|
||||
ret = board_qencoder_initialize(0, 3);
|
||||
if (ret != OK)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to register the qencoder: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
UNUSED(ret);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ CONFIG_ADC=y
|
||||
CONFIG_ANALOG=y
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="nucleo-c092rc"
|
||||
CONFIG_ARCH_BOARD_COMMON=y
|
||||
CONFIG_ARCH_BOARD_NUCLEO_C092RC=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP="stm32f0l0g0"
|
||||
@@ -38,6 +39,7 @@ CONFIG_EXAMPLES_ADC_GROUPSIZE=2
|
||||
CONFIG_EXAMPLES_ADC_SWTRIG=y
|
||||
CONFIG_EXAMPLES_BUTTONS=y
|
||||
CONFIG_EXAMPLES_HELLO=y
|
||||
CONFIG_EXAMPLES_QENCODER=y
|
||||
CONFIG_EXAMPLES_WATCHDOG=y
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_INIT_STACKSIZE=1536
|
||||
@@ -60,6 +62,8 @@ CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SENSORS=y
|
||||
CONFIG_SENSORS_QENCODER=y
|
||||
CONFIG_START_DAY=19
|
||||
CONFIG_START_MONTH=5
|
||||
CONFIG_START_YEAR=2013
|
||||
@@ -68,6 +72,8 @@ CONFIG_STM32F0L0G0_ADC1=y
|
||||
CONFIG_STM32F0L0G0_ADC_MAX_SAMPLES=2
|
||||
CONFIG_STM32F0L0G0_DMA1=y
|
||||
CONFIG_STM32F0L0G0_IWDG=y
|
||||
CONFIG_STM32F0L0G0_TIM3=y
|
||||
CONFIG_STM32F0L0G0_TIM3_QE=y
|
||||
CONFIG_STM32F0L0G0_USART2=y
|
||||
CONFIG_STM32F0L0G0_WWDG=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
|
||||
@@ -172,6 +172,14 @@
|
||||
#define GPIO_FDCAN1_RX (GPIO_FDCAN1_RX_8|GPIO_SPEED_HIGH) /* PD0 */
|
||||
#define GPIO_FDCAN1_TX (GPIO_FDCAN1_TX_9|GPIO_SPEED_HIGH) /* PD1 */
|
||||
|
||||
/* Qencoder on TIM3:
|
||||
* TIM3_CH1IN - PB4 (D5)
|
||||
* TIM3_CH2IN - PC7 (D3)
|
||||
*/
|
||||
|
||||
#define GPIO_TIM3_CH1IN (GPIO_TIM3_CH1IN_2|GPIO_SPEED_HIGH)
|
||||
#define GPIO_TIM3_CH2IN (GPIO_TIM3_CH2IN_6|GPIO_SPEED_HIGH)
|
||||
|
||||
/* DMA channels *************************************************************/
|
||||
|
||||
/* ADC */
|
||||
|
||||
@@ -42,6 +42,10 @@
|
||||
# include <stm32_wdg.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSORS_QENCODER
|
||||
# include "board_qencoder.h"
|
||||
#endif
|
||||
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "nucleo-c092rc.h"
|
||||
@@ -129,6 +133,19 @@ int stm32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSORS_QENCODER
|
||||
/* Initialize and register the qencoder driver - TIM3 */
|
||||
|
||||
ret = board_qencoder_initialize(0, 3);
|
||||
if (ret != OK)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to register the qencoder: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
UNUSED(ret);
|
||||
return OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user