From ba4be76bcc440a6112410fbb3b35c53a8565ab4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 29 Jan 2020 14:21:32 +0100 Subject: [PATCH] omnibus/f4sd: use hw description methods for timer configuration --- boards/omnibus/f4sd/src/CMakeLists.txt | 2 +- boards/omnibus/f4sd/src/board_config.h | 32 ------ boards/omnibus/f4sd/src/init.c | 11 +- boards/omnibus/f4sd/src/timer_config.c | 137 ----------------------- boards/omnibus/f4sd/src/timer_config.cpp | 49 ++++++++ 5 files changed, 54 insertions(+), 177 deletions(-) delete mode 100644 boards/omnibus/f4sd/src/timer_config.c create mode 100644 boards/omnibus/f4sd/src/timer_config.cpp diff --git a/boards/omnibus/f4sd/src/CMakeLists.txt b/boards/omnibus/f4sd/src/CMakeLists.txt index 63f010ad0e..ef9809a96e 100644 --- a/boards/omnibus/f4sd/src/CMakeLists.txt +++ b/boards/omnibus/f4sd/src/CMakeLists.txt @@ -35,7 +35,7 @@ add_library(drivers_board init.c led.c spi.c - timer_config.c + timer_config.cpp usb.c ) diff --git a/boards/omnibus/f4sd/src/board_config.h b/boards/omnibus/f4sd/src/board_config.h index f2a23988e0..1962168a6a 100644 --- a/boards/omnibus/f4sd/src/board_config.h +++ b/boards/omnibus/f4sd/src/board_config.h @@ -194,42 +194,10 @@ #define PX4_I2C_BUS_LED PX4_I2C_BUS_EXPANSION /* PWM - * - * 6 PWM outputs are configured. * * Alternatively CH3/CH4 could be assigned to UART6_TX/RX - * - * Pins: - * - * INPUTS: - * CH1 : PB8 : TIM10_CH1 // PPM - * CH2 : PB9 : TIM4_CH4 - * CH3 : PC6 : TIM8_CH1 // OR UART6_TX - * CH4 : PC7 : TIM8_CH2 // OR UART6_RX - * CH5 : PC8 : TIM8_CH3 - * CH6 : PC9 : TIM8_CH4 - * - * OUTPUTS: - * M1 : PB0 : TIM3_CH3 - * M2 : PB1 : TIM3_CH4 - * M3 : PA3 : TIM2_CH3 - * M4 : PA2 : TIM2_CH4 - * M5 : PA1 : TIM5_CH2 // UART4_RX - * M6 : PA8 : TIM1_CH1 // USART2_TX */ - -#define GPIO_TIM3_CH3OUT GPIO_TIM3_CH3OUT_1 //PB0 S1_OUT D1_ST7 -#define GPIO_TIM3_CH4OUT GPIO_TIM3_CH4OUT_1 //PB1 S2_OUT D1_ST2 -#define GPIO_TIM2_CH4OUT GPIO_TIM2_CH4OUT_1 //PA3 S3_OUT D1_ST6 -#define GPIO_TIM2_CH3OUT GPIO_TIM2_CH3OUT_1 //PA2 S4_OUT D1_ST1 - #define DIRECT_PWM_OUTPUT_CHANNELS 4 - -#define GPIO_TIM3_CH3IN GPIO_TIM3_CH3IN_1 -#define GPIO_TIM3_CH4IN GPIO_TIM3_CH4IN_1 -#define GPIO_TIM2_CH4IN GPIO_TIM2_CH4IN_1 -#define GPIO_TIM2_CH3IN GPIO_TIM2_CH3IN_1 - #define DIRECT_INPUT_TIMER_CHANNELS 4 // Has pwm outputs diff --git a/boards/omnibus/f4sd/src/init.c b/boards/omnibus/f4sd/src/init.c index aa0162550f..fc27d3a660 100644 --- a/boards/omnibus/f4sd/src/init.c +++ b/boards/omnibus/f4sd/src/init.c @@ -72,6 +72,7 @@ #include +#include #include #include @@ -127,13 +128,9 @@ __EXPORT void board_peripheral_reset(int ms) __EXPORT void board_on_reset(int status) { /* configure the GPIO pins to outputs and keep them low */ - - stm32_configgpio(GPIO_GPIO0_OUTPUT); - stm32_configgpio(GPIO_GPIO1_OUTPUT); - stm32_configgpio(GPIO_GPIO2_OUTPUT); - stm32_configgpio(GPIO_GPIO3_OUTPUT); - //stm32_configgpio(GPIO_GPIO4_OUTPUT); - //stm32_configgpio(GPIO_GPIO5_OUTPUT); + for (int i = 0; i < DIRECT_PWM_OUTPUT_CHANNELS; ++i) { + px4_arch_configgpio(io_timer_channel_get_gpio_output(i)); + } /* On resets invoked from system (not boot) insure we establish a low * output state (discharge the pins) on PWM pins before they become inputs. diff --git a/boards/omnibus/f4sd/src/timer_config.c b/boards/omnibus/f4sd/src/timer_config.c deleted file mode 100644 index a748602e39..0000000000 --- a/boards/omnibus/f4sd/src/timer_config.c +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2018 PX4 Development Team. All rights reserved. - * - * 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 PX4 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. - * - ****************************************************************************/ - -/* - * @file timer_config.c - * - * Configuration data for the stm32 pwm_servo, input capture and pwm input driver. - * - * Note that these arrays must always be fully-sized. - */ - -#include - -#include -#include -#include - -#include -#include - -#include "board_config.h" - -__EXPORT const io_timers_t io_timers[MAX_IO_TIMERS] = { - { - .base = STM32_TIM2_BASE, - .clock_register = STM32_RCC_APB1ENR, - .clock_bit = RCC_APB1ENR_TIM2EN, - .clock_freq = STM32_APB1_TIM2_CLKIN, - .vectorno = STM32_IRQ_TIM2, - .dshot = { - .dma_base = STM32_DMA1_BASE, - .dmamap = DMAMAP_TIM2_UP_1, - } - }, - { - .base = STM32_TIM3_BASE, - .clock_register = STM32_RCC_APB1ENR, - .clock_bit = RCC_APB1ENR_TIM3EN, - .clock_freq = STM32_APB1_TIM3_CLKIN, - .vectorno = STM32_IRQ_TIM3, - .dshot = { - .dma_base = STM32_DMA1_BASE, - .dmamap = DMAMAP_TIM3_UP, - } - } -}; - -__EXPORT const io_timers_channel_mapping_t io_timers_channel_mapping = { - .element = { - { - .first_channel_index = 0, - .channel_count = 2, - }, - { - .first_channel_index = 2, - .channel_count = 2, - } - } -}; - - -/* - * OUTPUTS: - * M3 : PA3 : TIM2_CH3 - * M4 : PA2 : TIM2_CH4 - * M1 : PB0 : TIM3_CH3 - * M2 : PB1 : TIM3_CH4 - */ - -__EXPORT const timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = { - //PB0 S1_OUT D1_ST7 - { - .gpio_out = GPIO_TIM3_CH3OUT, - .gpio_in = GPIO_TIM3_CH3IN, - .timer_index = 1, - .timer_channel = 3, - .ccr_offset = STM32_GTIM_CCR3_OFFSET, - .masks = GTIM_SR_CC3IF | GTIM_SR_CC3OF - }, - //PB1 S2_OUT D1_ST2 - { - .gpio_out = GPIO_TIM3_CH4OUT, - .gpio_in = GPIO_TIM3_CH4IN, - .timer_index = 1, - .timer_channel = 4, - .ccr_offset = STM32_GTIM_CCR4_OFFSET, - .masks = GTIM_SR_CC4IF | GTIM_SR_CC4OF - }, - //PA3 S3_OUT D1_ST6 - { - .gpio_out = GPIO_TIM2_CH4OUT, - .gpio_in = GPIO_TIM2_CH4IN, - .timer_index = 0, - .timer_channel = 4, - .ccr_offset = STM32_GTIM_CCR4_OFFSET, - .masks = GTIM_SR_CC4IF | GTIM_SR_CC4OF - }, - //PA2 S4_OUT D1_ST1 - { - .gpio_out = GPIO_TIM2_CH3OUT, - .gpio_in = GPIO_TIM2_CH3IN, - .timer_index = 0, - .timer_channel = 3, - .ccr_offset = STM32_GTIM_CCR3_OFFSET, - .masks = GTIM_SR_CC3IF | GTIM_SR_CC3OF - } -}; diff --git a/boards/omnibus/f4sd/src/timer_config.cpp b/boards/omnibus/f4sd/src/timer_config.cpp new file mode 100644 index 0000000000..c38c5b161a --- /dev/null +++ b/boards/omnibus/f4sd/src/timer_config.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** + * + * Copyright (C) 2018 PX4 Development Team. All rights reserved. + * + * 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 PX4 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. + * + ****************************************************************************/ + +#include + +constexpr io_timers_t io_timers[MAX_IO_TIMERS] = { + initIOTimer(Timer::Timer2, DMA{DMA::Index1, DMA::Stream1, DMA::Channel3}), + initIOTimer(Timer::Timer3, DMA{DMA::Index1, DMA::Stream2, DMA::Channel5}), +}; + +constexpr timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = { + initIOTimerChannel(io_timers, {Timer::Timer3, Timer::Channel3}, {GPIO::PortB, GPIO::Pin0}), + initIOTimerChannel(io_timers, {Timer::Timer3, Timer::Channel4}, {GPIO::PortB, GPIO::Pin1}), + initIOTimerChannel(io_timers, {Timer::Timer2, Timer::Channel4}, {GPIO::PortA, GPIO::Pin3}), + initIOTimerChannel(io_timers, {Timer::Timer2, Timer::Channel3}, {GPIO::PortA, GPIO::Pin2}), +}; + +constexpr io_timers_channel_mapping_t io_timers_channel_mapping = + initIOTimerChannelMapping(io_timers, timer_io_channels);