arch/arm/src/stm32h7: Ported the QEncoder from F7 to H7.

This commit is contained in:
Eduard Niesner 2019-06-27 07:00:50 -06:00 committed by Gregory Nutt
parent b922c2748e
commit 056eebd9da
6 changed files with 1503 additions and 2 deletions

View File

@ -4229,4 +4229,181 @@ config STM32H7_ETHMAC_REGDEBUG
endmenu # Ethernet MAC configuration
menu "QEncoder Driver"
depends on SENSORS_QENCODER
depends on STM32H7_TIM1 || STM32H7_TIM2 || STM32H7_TIM3 || STM32H7_TIM4 || STM32H7_TIM5 || STM32H7_TIM8
config STM32H7_TIM1_QE
bool "TIM1"
default n
depends on STM32H7_TIM1
---help---
Reserve TIM1 for use by QEncoder.
if STM32H7_TIM1_QE
config STM32H7_TIM1_QEPSC
int "TIM1 pulse prescaler"
default 1
---help---
This prescaler divides the number of recorded encoder pulses,
limiting the count rate at the expense of resolution.
endif
config STM32H7_TIM2_QE
bool "TIM2"
default n
depends on STM32H7_TIM2
---help---
Reserve TIM2 for use by QEncoder.
if STM32H7_TIM2_QE
config STM32H7_TIM2_QEPSC
int "TIM2 pulse prescaler"
default 1
---help---
This prescaler divides the number of recorded encoder pulses,
limiting the count rate at the expense of resolution.
endif
config STM32H7_TIM3_QE
bool "TIM3"
default n
depends on STM32H7_TIM3
---help---
Reserve TIM3 for use by QEncoder.
if STM32H7_TIM3_QE
config STM32H7_TIM3_QEPSC
int "TIM3 pulse prescaler"
default 1
---help---
This prescaler divides the number of recorded encoder pulses,
limiting the count rate at the expense of resolution.
endif
config STM32H7_TIM4_QE
bool "TIM4"
default n
depends on STM32H7_TIM4
---help---
Reserve TIM4 for use by QEncoder.
if STM32H7_TIM4_QE
config STM32H7_TIM4_QEPSC
int "TIM4 pulse prescaler"
default 1
---help---
This prescaler divides the number of recorded encoder pulses,
limiting the count rate at the expense of resolution.
endif
config STM32H7_TIM5_QE
bool "TIM5"
default n
depends on STM32H7_TIM5
---help---
Reserve TIM5 for use by QEncoder.
if STM32H7_TIM5_QE
config STM32H7_TIM5_QEPSC
int "TIM5 pulse prescaler"
default 1
---help---
This prescaler divides the number of recorded encoder pulses,
limiting the count rate at the expense of resolution.
endif
config STM32H7_TIM8_QE
bool "TIM8"
default n
depends on STM32H7_TIM8
---help---
Reserve TIM8 for use by QEncoder.
if STM32H7_TIM8_QE
config STM32H7_TIM8_QEPSC
int "TIM8 pulse prescaler"
default 1
---help---
This prescaler divides the number of recorded encoder pulses,
limiting the count rate at the expense of resolution.
endif
config STM32H7_QENCODER_FILTER
bool "Enable filtering on STM32 QEncoder input"
default y
choice
depends on STM32H7_QENCODER_FILTER
prompt "Input channel sampling frequency"
default STM32H7_QENCODER_SAMPLE_FDTS_4
config STM32H7_QENCODER_SAMPLE_FDTS
bool "fDTS"
config STM32H7_QENCODER_SAMPLE_CKINT
bool "fCK_INT"
config STM32H7_QENCODER_SAMPLE_FDTS_2
bool "fDTS/2"
config STM32H7_QENCODER_SAMPLE_FDTS_4
bool "fDTS/4"
config STM32H7_QENCODER_SAMPLE_FDTS_8
bool "fDTS/8"
config STM32H7_QENCODER_SAMPLE_FDTS_16
bool "fDTS/16"
config STM32H7_QENCODER_SAMPLE_FDTS_32
bool "fDTS/32"
endchoice
choice
depends on STM32H7_QENCODER_FILTER
prompt "Input channel event count"
default STM32H7_QENCODER_SAMPLE_EVENT_6
config STM32H7_QENCODER_SAMPLE_EVENT_1
depends on STM32H7_QENCODER_SAMPLE_FDTS
bool "1"
config STM32H7_QENCODER_SAMPLE_EVENT_2
depends on STM32H7_QENCODER_SAMPLE_CKINT
bool "2"
config STM32H7_QENCODER_SAMPLE_EVENT_4
depends on STM32H7_QENCODER_SAMPLE_CKINT
bool "4"
config STM32H7_QENCODER_SAMPLE_EVENT_5
depends on STM32H7_QENCODER_SAMPLE_FDTS_16 || STM32H7_QENCODER_SAMPLE_FDTS_32
bool "5"
config STM32H7_QENCODER_SAMPLE_EVENT_6
depends on !STM32H7_QENCODER_SAMPLE_FDTS && !STM32H7_QENCODER_SAMPLE_CKINT
bool "6"
config STM32H7_QENCODER_SAMPLE_EVENT_8
depends on !STM32H7_QENCODER_SAMPLE_FDTS
bool "8"
endchoice
endmenu
endif # ARCH_CHIP_STM32H7

View File

@ -141,3 +141,7 @@ endif
ifeq ($(CONFIG_STM32H7_ETHMAC),y)
CHIP_CSRCS += stm32_ethernet.c
endif
ifeq ($(CONFIG_SENSORS_QENCODER),y)
CHIP_CSRCS += stm32_qencoder.c
endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,143 @@
/************************************************************************************
* arch/arm/src/stm32h7/stm32_qencoder.h
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************************/
#ifndef __ARCH_ARM_SRC_STM32H7_STM32_QENCODER_H
#define __ARCH_ARM_SRC_STM32H7_STM32_QENCODER_H
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#include "chip.h"
#ifdef CONFIG_SENSORS_QENCODER
/************************************************************************************
* Included Files
************************************************************************************/
/* Timer devices may be used for different purposes. One special purpose is as
* a quadrature encoder input device. If CONFIG_STM32H7_TIMn is defined then the
* CONFIG_STM32H7_TIMn_QE must also be defined to indicate that timer "n" is intended
* to be used for as a quadrature encoder.
*/
#ifndef CONFIG_STM32H7_TIM1
# undef CONFIG_STM32H7_TIM1_QE
#endif
#ifndef CONFIG_STM32H7_TIM2
# undef CONFIG_STM32H7_TIM2_QE
#endif
#ifndef CONFIG_STM32H7_TIM3
# undef CONFIG_STM32H7_TIM3_QE
#endif
#ifndef CONFIG_STM32H7_TIM4
# undef CONFIG_STM32H7_TIM4_QE
#endif
#ifndef CONFIG_STM32H7_TIM5
# undef CONFIG_STM32H7_TIM5_QE
#endif
#ifndef CONFIG_STM32H7_TIM8
# undef CONFIG_STM32H7_TIM8_QE
#endif
/* Only timers 2-5, and 1 & 8 can be used as a quadrature encoder (at least for the
* STM32 H7)
*/
#undef CONFIG_STM32H7_TIM6_QE
#undef CONFIG_STM32H7_TIM7_QE
#undef CONFIG_STM32H7_TIM9_QE
#undef CONFIG_STM32H7_TIM10_QE
#undef CONFIG_STM32H7_TIM11_QE
#undef CONFIG_STM32H7_TIM12_QE
#undef CONFIG_STM32H7_TIM13_QE
#undef CONFIG_STM32H7_TIM14_QE
/* Clock out frequency. This value is used to calculation the timer CLKIN in
* prescaler value.
*/
#ifndef CONFIG_STM32H7_TIM1_QECLKOUT
# define CONFIG_STM32H7_TIM1_QECLKOUT 28000000
#endif
#ifndef CONFIG_STM32H7_TIM2_QECLKOUT
# define CONFIG_STM32H7_TIM2_QECLKOUT 28000000
#endif
#ifndef CONFIG_STM32H7_TIM3_QECLKOUT
# define CONFIG_STM32H7_TIM3_QECLKOUT 28000000
#endif
#ifndef CONFIG_STM32H7_TIM4_QECLKOUT
# define CONFIG_STM32H7_TIM4_QECLKOUT 28000000
#endif
#ifndef CONFIG_STM32H7_TIM5_QECLKOUT
# define CONFIG_STM32H7_TIM5_QECLKOUT 28000000
#endif
#ifndef CONFIG_STM32H7_TIM8_QECLKOUT
# define CONFIG_STM32H7_TIM8_QECLKOUT 28000000
#endif
/************************************************************************************
* Included Files
************************************************************************************/
/************************************************************************************
* Name: stm32_qeinitialize
*
* Description:
* Initialize a quadrature encoder interface. This function must be called from
* board-specific logic..
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/qe0"
* tim - The timer number to used. 'tim' must be an element of {1,2,3,4,5,8}
*
* Returned Value:
* Zero on success; A negated errno value is returned on failure.
*
************************************************************************************/
int stm32_qeinitialize(FAR const char *devpath, int tim);
#endif /* CONFIG_SENSORS_QENCODER */
#endif /* __ARCH_ARM_SRC_STM32H7_STM32_QENCODER_H */

View File

@ -395,7 +395,7 @@ Configuration Subdirectories
2019-06-18: The RTC now appears to be fully functional.
2019-06-26: Renamed nsh configuration to nsh_flash. Added nsh_ram
configuration.
configuration. Not yet verified.
sdboot

View File

@ -52,7 +52,7 @@
****************************************************************************/
/****************************************************************************
* Name: alert, err, warn, and info
* Name: _alert, _err, _warn, and _info
*
* Description:
* If the cross-compiler's pre-processor does not support variable