Skip to content

Commit 6092ef1

Browse files
committed
boards/nucleo-c0XX: add qencoder support
add qencoder support for nucleo-c0 boards Signed-off-by: raiden00pl <[email protected]>
1 parent 7cb0822 commit 6092ef1

10 files changed

Lines changed: 201 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/****************************************************************************
2+
* boards/arm/stm32f0l0g0/common/include/stm32_qencoder.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef __BOARDS_ARM_STM32F0L0G0_COMMON_INCLUDE_STM32_QENCODER_H
24+
#define __BOARDS_ARM_STM32F0L0G0_COMMON_INCLUDE_STM32_QENCODER_H
25+
26+
/****************************************************************************
27+
* Included Files
28+
****************************************************************************/
29+
30+
#include <nuttx/config.h>
31+
32+
/****************************************************************************
33+
* Public Data
34+
****************************************************************************/
35+
36+
#ifdef __cplusplus
37+
#define EXTERN extern "C"
38+
extern "C"
39+
{
40+
#else
41+
#define EXTERN extern
42+
#endif
43+
44+
/****************************************************************************
45+
* Public Function Prototypes
46+
****************************************************************************/
47+
48+
/****************************************************************************
49+
* Name: board_qencoder_initialize
50+
*
51+
* Description:
52+
* Initialize the quadrature encoder driver for the given timer
53+
*
54+
****************************************************************************/
55+
56+
int board_qencoder_initialize(int devno, int timerno);
57+
58+
#undef EXTERN
59+
#ifdef __cplusplus
60+
}
61+
#endif
62+
63+
#endif /* __BOARDS_ARM_STM32F0L0G0_COMMON_INCLUDE_STM32_QENCODER_H */

boards/arm/stm32f0l0g0/common/src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ if(CONFIG_ARCH_BOARD_COMMON)
2626
list(APPEND SRCS stm32_ssd1306.c)
2727
endif()
2828

29+
if(CONFIG_SENSORS_QENCODER)
30+
list(APPEND SRCS stm32_qencoder.c)
31+
endif()
32+
2933
endif()
3034
target_sources(board PRIVATE ${SRCS})

boards/arm/stm32f0l0g0/common/src/Make.defs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ ifeq ($(CONFIG_LCD_SSD1306),y)
2626
CSRCS += stm32_ssd1306.c
2727
endif
2828

29+
ifeq ($(CONFIG_SENSORS_QENCODER),y)
30+
CSRCS += board_qencoder.c
31+
endif
32+
2933
DEPPATH += --dep-path src
3034
VPATH += :src
3135
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/****************************************************************************
2+
* boards/arm/stm32f0l0g0/common/src/stm32_qencoder.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <errno.h>
30+
#include <debug.h>
31+
#include <stdio.h>
32+
33+
#include <nuttx/sensors/qencoder.h>
34+
#include <arch/board/board.h>
35+
36+
#include "chip.h"
37+
#include "arm_internal.h"
38+
#include "stm32_qencoder.h"
39+
40+
/****************************************************************************
41+
* Public Functions
42+
****************************************************************************/
43+
44+
/****************************************************************************
45+
* Name: board_qencoder_initialize
46+
*
47+
* Description:
48+
* Initialize the quadrature encoder driver for the given timer
49+
*
50+
****************************************************************************/
51+
52+
int board_qencoder_initialize(int devno, int timerno)
53+
{
54+
int ret;
55+
char devpath[12];
56+
57+
/* Initialize a quadrature encoder interface. */
58+
59+
sninfo("Initializing the quadrature encoder using TIM%d\n", timerno);
60+
snprintf(devpath, sizeof(devpath), "/dev/qe%d", devno);
61+
ret = stm32_qeinitialize(devpath, timerno);
62+
if (ret < 0)
63+
{
64+
snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
65+
}
66+
67+
return ret;
68+
}

boards/arm/stm32f0l0g0/nucleo-c071rb/configs/jumbo/defconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CONFIG_ADC=y
1212
CONFIG_ANALOG=y
1313
CONFIG_ARCH="arm"
1414
CONFIG_ARCH_BOARD="nucleo-c071rb"
15+
CONFIG_ARCH_BOARD_COMMON=y
1516
CONFIG_ARCH_BOARD_NUCLEO_C071RB=y
1617
CONFIG_ARCH_BUTTONS=y
1718
CONFIG_ARCH_CHIP="stm32f0l0g0"
@@ -38,6 +39,7 @@ CONFIG_EXAMPLES_ADC_GROUPSIZE=2
3839
CONFIG_EXAMPLES_ADC_SWTRIG=y
3940
CONFIG_EXAMPLES_BUTTONS=y
4041
CONFIG_EXAMPLES_HELLO=y
42+
CONFIG_EXAMPLES_QENCODER=y
4143
CONFIG_EXAMPLES_WATCHDOG=y
4244
CONFIG_INIT_ENTRYPOINT="nsh_main"
4345
CONFIG_INIT_STACKSIZE=1536
@@ -51,6 +53,8 @@ CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
5153
CONFIG_NSH_BUILTIN_APPS=y
5254
CONFIG_NSH_FILEIOSIZE=64
5355
CONFIG_NSH_READLINE=y
56+
CONFIG_SENSORS=y
57+
CONFIG_SENSORS_QENCODER=y
5458
CONFIG_NUNGET_CHARS=0
5559
CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=1536
5660
CONFIG_PTHREAD_MUTEX_UNSAFE=y
@@ -67,6 +71,8 @@ CONFIG_STDIO_DISABLE_BUFFERING=y
6771
CONFIG_STM32F0L0G0_ADC1=y
6872
CONFIG_STM32F0L0G0_DMA1=y
6973
CONFIG_STM32F0L0G0_IWDG=y
74+
CONFIG_STM32F0L0G0_TIM3=y
75+
CONFIG_STM32F0L0G0_TIM3_QE=y
7076
CONFIG_STM32F0L0G0_USART2=y
7177
CONFIG_STM32F0L0G0_WWDG=y
7278
CONFIG_SYSTEM_NSH=y

boards/arm/stm32f0l0g0/nucleo-c071rb/include/board.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@
162162
#define GPIO_USART2_RX (GPIO_USART2_RX_1|GPIO_SPEED_HIGH) /* PA3 */
163163
#define GPIO_USART2_TX (GPIO_USART2_TX_1|GPIO_SPEED_HIGH) /* PA2 */
164164

165+
/* Qencoder on TIM3:
166+
* TIM3_CH1IN - PB4 (D5)
167+
* TIM3_CH2IN - PC7 (D3)
168+
*/
169+
170+
#define GPIO_TIM3_CH1IN (GPIO_TIM3_CH1IN_2|GPIO_SPEED_HIGH)
171+
#define GPIO_TIM3_CH2IN (GPIO_TIM3_CH2IN_6|GPIO_SPEED_HIGH)
172+
165173
/* DMA channels *************************************************************/
166174

167175
/* ADC */

boards/arm/stm32f0l0g0/nucleo-c071rb/src/stm32_bringup.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
# include <stm32_wdg.h>
4343
#endif
4444

45+
#ifdef CONFIG_SENSORS_QENCODER
46+
# include "board_qencoder.h"
47+
#endif
48+
4549
#include <arch/board/board.h>
4650

4751
#include "nucleo-c071rb.h"
@@ -109,6 +113,19 @@ int stm32_bringup(void)
109113
}
110114
#endif
111115

116+
#ifdef CONFIG_SENSORS_QENCODER
117+
/* Initialize and register the qencoder driver - TIM3 */
118+
119+
ret = board_qencoder_initialize(0, 3);
120+
if (ret != OK)
121+
{
122+
syslog(LOG_ERR,
123+
"ERROR: Failed to register the qencoder: %d\n",
124+
ret);
125+
return ret;
126+
}
127+
#endif
128+
112129
UNUSED(ret);
113130
return OK;
114131
}

boards/arm/stm32f0l0g0/nucleo-c092rc/configs/jumbo/defconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CONFIG_ADC=y
1212
CONFIG_ANALOG=y
1313
CONFIG_ARCH="arm"
1414
CONFIG_ARCH_BOARD="nucleo-c092rc"
15+
CONFIG_ARCH_BOARD_COMMON=y
1516
CONFIG_ARCH_BOARD_NUCLEO_C092RC=y
1617
CONFIG_ARCH_BUTTONS=y
1718
CONFIG_ARCH_CHIP="stm32f0l0g0"
@@ -38,6 +39,7 @@ CONFIG_EXAMPLES_ADC_GROUPSIZE=2
3839
CONFIG_EXAMPLES_ADC_SWTRIG=y
3940
CONFIG_EXAMPLES_BUTTONS=y
4041
CONFIG_EXAMPLES_HELLO=y
42+
CONFIG_EXAMPLES_QENCODER=y
4143
CONFIG_EXAMPLES_WATCHDOG=y
4244
CONFIG_INIT_ENTRYPOINT="nsh_main"
4345
CONFIG_INIT_STACKSIZE=1536
@@ -51,6 +53,8 @@ CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
5153
CONFIG_NSH_BUILTIN_APPS=y
5254
CONFIG_NSH_FILEIOSIZE=64
5355
CONFIG_NSH_READLINE=y
56+
CONFIG_SENSORS=y
57+
CONFIG_SENSORS_QENCODER=y
5458
CONFIG_NUNGET_CHARS=0
5559
CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=1536
5660
CONFIG_PTHREAD_MUTEX_UNSAFE=y
@@ -67,6 +71,8 @@ CONFIG_STDIO_DISABLE_BUFFERING=y
6771
CONFIG_STM32F0L0G0_ADC1=y
6872
CONFIG_STM32F0L0G0_DMA1=y
6973
CONFIG_STM32F0L0G0_IWDG=y
74+
CONFIG_STM32F0L0G0_TIM3=y
75+
CONFIG_STM32F0L0G0_TIM3_QE=y
7076
CONFIG_STM32F0L0G0_USART2=y
7177
CONFIG_STM32F0L0G0_WWDG=y
7278
CONFIG_SYSTEM_NSH=y

boards/arm/stm32f0l0g0/nucleo-c092rc/include/board.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@
172172
#define GPIO_FDCAN1_RX (GPIO_FDCAN1_RX_8|GPIO_SPEED_HIGH) /* PD0 */
173173
#define GPIO_FDCAN1_TX (GPIO_FDCAN1_TX_9|GPIO_SPEED_HIGH) /* PD1 */
174174

175+
/* Qencoder on TIM3:
176+
* TIM3_CH1IN - PB4 (D5)
177+
* TIM3_CH2IN - PC7 (D3)
178+
*/
179+
180+
#define GPIO_TIM3_CH1IN (GPIO_TIM3_CH1IN_2|GPIO_SPEED_HIGH)
181+
#define GPIO_TIM3_CH2IN (GPIO_TIM3_CH2IN_6|GPIO_SPEED_HIGH)
182+
175183
/* DMA channels *************************************************************/
176184

177185
/* ADC */

boards/arm/stm32f0l0g0/nucleo-c092rc/src/stm32_bringup.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
# include <stm32_wdg.h>
4343
#endif
4444

45+
#ifdef CONFIG_SENSORS_QENCODER
46+
# include "board_qencoder.h"
47+
#endif
48+
4549
#include <arch/board/board.h>
4650

4751
#include "nucleo-c092rc.h"
@@ -129,6 +133,19 @@ int stm32_bringup(void)
129133
}
130134
#endif
131135

136+
#ifdef CONFIG_SENSORS_QENCODER
137+
/* Initialize and register the qencoder driver - TIM3 */
138+
139+
ret = board_qencoder_initialize(0, 3);
140+
if (ret != OK)
141+
{
142+
syslog(LOG_ERR,
143+
"ERROR: Failed to register the qencoder: %d\n",
144+
ret);
145+
return ret;
146+
}
147+
#endif
148+
132149
UNUSED(ret);
133150
return OK;
134151
}

0 commit comments

Comments
 (0)