From 5363d0619ae16ad3637cc62141dec8d5cffcbaa8 Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Fri, 18 Nov 2016 15:26:08 +0100 Subject: [PATCH 1/2] Fix warnings --- drivers/timers/timer.c | 5 ++--- include/nuttx/timers/timer.h | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/timers/timer.c b/drivers/timers/timer.c index 80c76a1b62..667be5276d 100644 --- a/drivers/timers/timer.c +++ b/drivers/timers/timer.c @@ -131,7 +131,6 @@ static bool timer_notifier(FAR uint32_t *next_interval_us, FAR void *arg) #ifdef CONFIG_CAN_PASS_STRUCTS union sigval value; #endif - int ret; DEBUGASSERT(upper != NULL); @@ -139,9 +138,9 @@ static bool timer_notifier(FAR uint32_t *next_interval_us, FAR void *arg) #ifdef CONFIG_CAN_PASS_STRUCTS value.sival_ptr = upper->arg; - ret = sigqueue(upper->pid, upper->signo, value); + (void)sigqueue(upper->pid, upper->signo, value); #else - ret = sigqueue(upper->pid, upper->signo, upper->arg); + (void)sigqueue(upper->pid, upper->signo, upper->arg); #endif return true; diff --git a/include/nuttx/timers/timer.h b/include/nuttx/timers/timer.h index a89369d5df..ab78f5ea97 100644 --- a/include/nuttx/timers/timer.h +++ b/include/nuttx/timers/timer.h @@ -46,6 +46,7 @@ #include #include #include +#include #ifdef CONFIG_TIMER From ddba6de8bcd10dc04f5fa1252d36f08d879d20a1 Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Fri, 18 Nov 2016 15:26:31 +0100 Subject: [PATCH 2/2] Add support for timers to nucleo l476 --- configs/nucleo-l476rg/include/board.h | 9 ++- configs/nucleo-l476rg/src/Makefile | 4 ++ configs/nucleo-l476rg/src/nucleo-l476rg.h | 12 ++++ configs/nucleo-l476rg/src/stm32_appinit.c | 13 ++++ configs/nucleo-l476rg/src/stm32_timer.c | 82 +++++++++++++++++++++++ 5 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 configs/nucleo-l476rg/src/stm32_timer.c diff --git a/configs/nucleo-l476rg/include/board.h b/configs/nucleo-l476rg/include/board.h index 986844bf33..103f5a2e00 100644 --- a/configs/nucleo-l476rg/include/board.h +++ b/configs/nucleo-l476rg/include/board.h @@ -206,12 +206,15 @@ * Default is to use timer 5 (32-bit) and encoder on PA0/PA1 */ -#define GPIO_TIM5_CH1IN GPIO_TIM5_CH1IN_1 -#define GPIO_TIM5_CH2IN GPIO_TIM5_CH2IN_1 - #define GPIO_TIM2_CH1IN GPIO_TIM2_CH1IN_1 #define GPIO_TIM2_CH2IN GPIO_TIM2_CH2IN_1 +#define GPIO_TIM3_CH1IN GPIO_TIM3_CH1IN_3 +#define GPIO_TIM3_CH2IN GPIO_TIM3_CH2IN_3 + +#define GPIO_TIM5_CH1IN GPIO_TIM5_CH1IN_1 +#define GPIO_TIM5_CH2IN GPIO_TIM5_CH2IN_1 + /* PWM output for full bridge, uses config 1, because port E is N/A on QFP64 * CH1 | 1(A8) 2(E9) * CH2 | 1(A9) 2(E11) diff --git a/configs/nucleo-l476rg/src/Makefile b/configs/nucleo-l476rg/src/Makefile index c47701ba2c..a27b0f3b84 100644 --- a/configs/nucleo-l476rg/src/Makefile +++ b/configs/nucleo-l476rg/src/Makefile @@ -70,6 +70,10 @@ ifeq ($(CONFIG_PWM),y) CSRCS += stm32_pwm.c endif +ifeq ($(CONFIG_TIMER),y) +CSRCS += stm32_timer.c +endif + ifeq ($(CONFIG_LIB_BOARDCTL),y) CSRCS += stm32_appinit.c endif diff --git a/configs/nucleo-l476rg/src/nucleo-l476rg.h b/configs/nucleo-l476rg/src/nucleo-l476rg.h index d35d247349..50151a3fe5 100644 --- a/configs/nucleo-l476rg/src/nucleo-l476rg.h +++ b/configs/nucleo-l476rg/src/nucleo-l476rg.h @@ -351,4 +351,16 @@ int board_adc_initialize(void); int board_ajoy_initialize(void); #endif +/**************************************************************************** + * Name: board_timer_driver_initialize + * + * Description: + * Initialize and register a timer + * + ****************************************************************************/ + +#ifdef CONFIG_TIMER +int board_timer_driver_initialize(FAR const char *devpath, int timer); +#endif + #endif /* __CONFIGS_NUCLEO_L476RG_SRC_NUCLEO_L476RG_H */ diff --git a/configs/nucleo-l476rg/src/stm32_appinit.c b/configs/nucleo-l476rg/src/stm32_appinit.c index 4f805ff147..bb134ee6aa 100644 --- a/configs/nucleo-l476rg/src/stm32_appinit.c +++ b/configs/nucleo-l476rg/src/stm32_appinit.c @@ -205,6 +205,19 @@ int board_app_initialize(uintptr_t arg) } #endif +#ifdef CONFIG_TIMER + /* Initialize and register the timer driver */ + + ret = board_timer_driver_initialize("/dev/timer0", 2); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the timer driver: %d\n", + ret); + return ret; + } +#endif + return OK; } diff --git a/configs/nucleo-l476rg/src/stm32_timer.c b/configs/nucleo-l476rg/src/stm32_timer.c new file mode 100644 index 0000000000..2d6f83835e --- /dev/null +++ b/configs/nucleo-l476rg/src/stm32_timer.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * config/nucleo-l476rg/src/stm32_timer.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Copied from nucleo-f303 by Sebastien Lorquet + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +#include "stm32l4_tim.h" +#include "nucleo-l476rg.h" + +#ifdef CONFIG_TIMER + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_timer_driver_initialize + * + * Description: + * Configure the timer driver. + * + * Input Parameters: + * devpath - The full path to the timer device. This should be of the + * form /dev/timer0 + * timer - The timer's number. + * + * Returned Values: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +int board_timer_driver_initialize(FAR const char *devpath, int timer) +{ + return stm32l4_timer_initialize(devpath, timer); +} + +#endif