Skip to content

Commit

Permalink
nxp/fmurt1062-v1: use hw description methods for timer configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
bkueng committed Jan 31, 2020
1 parent a306925 commit e2f3065
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 194 deletions.
4 changes: 2 additions & 2 deletions boards/nxp/fmurt1062-v1/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ px4_add_library(drivers_board
led.c
sdhc.c
spi.cpp
timer_config.c
timer_config.cpp
usb.c
manifest.c
imxrt_flexspi_nor_boot.c
Expand All @@ -54,4 +54,4 @@ target_link_libraries(drivers_board
nuttx_arch # sdio
nuttx_drivers # sdio
px4_layer
)
)
68 changes: 0 additions & 68 deletions boards/nxp/fmurt1062-v1/src/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,30 +326,7 @@
#define BOARD_INDICATE_ARMED_STATE(on_armed) px4_arch_configgpio((on_armed) ? GPIO_nARMED : GPIO_nARMED_INIT)

/* PWM
*
* 8 PWM outputs are configured.
*
* Pins:
*
* FMU_CH1 : GPIO_B0_06 GPIO2 Pin 6 FLEXPWM2_PWMA0
* FMU_CH2 : GPIO_EMC_08 GPIO4 Pin 8 FLEXPWM2_PWMA1
* FMU_CH3 : GPIO_EMC_10 GPIO4 Pin 10 FLEXPWM2_PWMA2
* FMU_CH4 : GPIO_AD_B0_09 GPIO1 Pin 9 FLEXPWM2_PWMA3
* FMU_CH5 : GPIO_EMC_33 GPIO3 Pin 19 FLEXPWM3_PWMA2
* FMU_CH6 : GPIO_EMC_30 GPIO4 Pin 30 FLEXPWM3_PWMB0
* FMU_CH7 : GPIO_EMC_04 GPIO4 Pin 4 FLEXPWM4_PWMA2
* FMU_CH8 : GPIO_EMC_01 GPIO4 Pin 1 FLEXPWM4_PWMB0
*
*/
#define PWM_IOMUX (IOMUX_CMOS_OUTPUT | IOMUX_PULL_NONE | IOMUX_DRIVE_50OHM | IOMUX_SPEED_MEDIUM | IOMUX_SLEW_FAST)
#define PIN_FLEXPWM2_PWMA00 /* P2:6 GPIO_B0_06 PWM2 A0 FMU1 */ (PWM_IOMUX | GPIO_FLEXPWM2_PWMA00_2)
#define PIN_FLEXPWM2_PWMA01 /* P4:8 GPIO_EMC_08 PWM2 A1 FMU2 */ (PWM_IOMUX | GPIO_FLEXPWM2_PWMA01_1)
#define PIN_FLEXPWM2_PWMA02 /* P4:10 GPIO_EMC_10 PWM2 A2 FMU3 */ (PWM_IOMUX | GPIO_FLEXPWM2_PWMA02_1)
#define PIN_FLEXPWM2_PWMA03 /* P1:9 GPIO_AD_B0_09 PWM2 A3 FMU4 */ (PWM_IOMUX | GPIO_FLEXPWM2_PWMA03_2)
#define PIN_FLEXPWM3_PWMA02 /* P3:19 GPIO_EMC_33 PWM3 A2 FMU5 */ (PWM_IOMUX | GPIO_FLEXPWM3_PWMA02_1)
#define PIN_FLEXPWM3_PWMB00 /* P4:30 GPIO_EMC_30 PWM3 B0 FMU6 */ (PWM_IOMUX | GPIO_FLEXPWM3_PWMB00_1)
#define PIN_FLEXPWM4_PWMA02 /* P4:4 GPIO_EMC_04 PWM4 A2 FMU7 */ (PWM_IOMUX | GPIO_FLEXPWM4_PWMA02_2)
#define PIN_FLEXPWM4_PWMB00 /* P4:1 GPIO_EMC_01 PWM4 B0 FMU8 */ (PWM_IOMUX | GPIO_FLEXPWM4_PWMB00_1)

#define DIRECT_PWM_OUTPUT_CHANNELS 8

Expand All @@ -368,38 +345,6 @@
*/


/* User GPIOs
*
* GPIO-
* Define as GPIO input / GPIO outputs
*/

#define FMU_INPUT_IOMUX (IOMUX_SCHMITT_TRIGGER | IOMUX_PULL_UP_47K | IOMUX_DRIVE_HIZ)

#define _MK_GPIO_INPUT(def) (((def) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_INPUT | FMU_INPUT_IOMUX))

#define GPIO_GPIO0_INPUT /* P2:6 GPIO_B0_06 PWM2 A0 FMU1 */ (GPIO_PORT2 | GPIO_PIN6 | GPIO_INPUT | FMU_INPUT_IOMUX)
#define GPIO_GPIO1_INPUT /* P4:8 GPIO_EMC_08 PWM2 A1 FMU2 */ (GPIO_PORT4 | GPIO_PIN8 | GPIO_INPUT | FMU_INPUT_IOMUX)
#define GPIO_GPIO2_INPUT /* P4:10 GPIO_EMC_10 PWM2 A2 FMU3 */ (GPIO_PORT4 | GPIO_PIN10 | GPIO_INPUT | FMU_INPUT_IOMUX)
#define GPIO_GPIO3_INPUT /* P1:9 GPIO_AD_B0_09 PWM2 A3 FMU4 */ (GPIO_PORT1 | GPIO_PIN9 | GPIO_INPUT | FMU_INPUT_IOMUX)
#define GPIO_GPIO4_INPUT /* P3:19 GPIO_EMC_33 PWM3 A2 FMU5 */ (GPIO_PORT3 | GPIO_PIN19 | GPIO_INPUT | FMU_INPUT_IOMUX)
#define GPIO_GPIO5_INPUT /* P4:30 GPIO_EMC_30 PWM3 B0 FMU6 */ (GPIO_PORT4 | GPIO_PIN30 | GPIO_INPUT | FMU_INPUT_IOMUX)
#define GPIO_GPIO6_INPUT /* P4:4 GPIO_EMC_04 PWM4 A2 FMU7 */ (GPIO_PORT4 | GPIO_PIN4 | GPIO_INPUT | FMU_INPUT_IOMUX)
#define GPIO_GPIO7_INPUT /* P4:1 GPIO_EMC_01 PWM4 B0 FMU8 */ (GPIO_PORT4 | GPIO_PIN1 | GPIO_INPUT | FMU_INPUT_IOMUX)

#define FMU_OUTPUT_IOMUX (IOMUX_CMOS_OUTPUT | IOMUX_PULL_KEEP | IOMUX_DRIVE_33OHM | IOMUX_SPEED_MEDIUM | IOMUX_SLEW_FAST)

#define _MK_GPIO_OUTPUT(def) (((def) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX))

#define GPIO_GPIO0_OUTPUT /* P2:6 GPIO_B0_06 PWM2 A0 FMU1 */ (GPIO_PORT2 | GPIO_PIN6 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX)
#define GPIO_GPIO1_OUTPUT /* P4:8 GPIO_EMC_08 PWM2 A1 FMU2 */ (GPIO_PORT4 | GPIO_PIN8 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX)
#define GPIO_GPIO2_OUTPUT /* P4:10 GPIO_EMC_10 PWM2 A2 FMU3 */ (GPIO_PORT4 | GPIO_PIN10 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX)
#define GPIO_GPIO3_OUTPUT /* P1:9 GPIO_AD_B0_09 PWM2 A3 FMU4 */ (GPIO_PORT1 | GPIO_PIN9 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX)
#define GPIO_GPIO4_OUTPUT /* P3:19 GPIO_EMC_33 PWM3 A2 FMU5 */ (GPIO_PORT3 | GPIO_PIN19 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX)
#define GPIO_GPIO5_OUTPUT /* P4:30 GPIO_EMC_30 PWM3 B0 FMU6 */ (GPIO_PORT4 | GPIO_PIN30 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX)
#define GPIO_GPIO6_OUTPUT /* P4:4 GPIO_EMC_04 PWM4 A2 FMU7 */ (GPIO_PORT4 | GPIO_PIN4 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX)
#define GPIO_GPIO7_OUTPUT /* P4:1 GPIO_EMC_01 PWM4 B0 FMU8 */ (GPIO_PORT4 | GPIO_PIN1 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX)

/* Power supply control and monitoring GPIOs */

#define GENERAL_INPUT_IOMUX (IOMUX_CMOS_INPUT | IOMUX_PULL_UP_47K | IOMUX_DRIVE_HIZ)
Expand Down Expand Up @@ -545,19 +490,6 @@

#define BOARD_HAS_ON_RESET 1

/* The list of GPIO that will be initialized */

#define PX4_GPIO_PWM_INIT_LIST { \
GPIO_GPIO7_INPUT, \
GPIO_GPIO6_INPUT, \
GPIO_GPIO5_INPUT, \
GPIO_GPIO4_INPUT, \
GPIO_GPIO3_INPUT, \
GPIO_GPIO2_INPUT, \
GPIO_GPIO1_INPUT, \
GPIO_GPIO0_INPUT, \
}

#define PX4_GPIO_INIT_LIST { \
GPIO_nARMED_INIT, \
PX4_ADC_GPIO, \
Expand Down
8 changes: 4 additions & 4 deletions boards/nxp/fmurt1062-v1/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include <drivers/drv_hrt.h>
#include <drivers/drv_board_led.h>
#include <systemlib/px4_macros.h>
#include <px4_arch/io_timer.h>
#include <px4_platform_common/init.h>
#include <px4_platform/gpio.h>
#include <px4_platform/board_determine_hw_info.h>
Expand Down Expand Up @@ -135,10 +136,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 */

const uint32_t gpio[] = PX4_GPIO_PWM_INIT_LIST;
px4_gpio_init(gpio, arraySize(gpio));
for (int i = 0; i < DIRECT_PWM_OUTPUT_CHANNELS; ++i) {
px4_arch_configgpio(PX4_MAKE_GPIO_INPUT(io_timer_channel_get_gpio_output(i)));
}

if (status >= 0) {
up_mdelay(6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@
*
****************************************************************************/

/*
* @file timer_config.c
*
* Configuration data for the imxrt pwm_servo, input capture and pwm input driver.
*
* Note that these arrays must always be fully-sized.
*/

// TODO:Stubbed out for now
#include <stdint.h>

Expand All @@ -52,7 +44,7 @@
#include "imxrt_periphclks.h"

#include <drivers/drv_pwm_output.h>
#include <px4_arch/io_timer.h>
#include <px4_arch/io_timer_hw_description.h>

#include "board_config.h"

Expand Down Expand Up @@ -83,127 +75,34 @@
#define rDMA REG(IMXRT_TMR_DMA_OFFSET)
#define rENBL REG(IMXRT_TMR_ENBL_OFFSET)

__EXPORT const io_timers_t io_timers[MAX_IO_TIMERS] = {
{
.base = IMXRT_FLEXPWM2_BASE,
},
{
.base = IMXRT_FLEXPWM3_BASE,
},
{
.base = IMXRT_FLEXPWM4_BASE,
},
constexpr io_timers_t io_timers[MAX_IO_TIMERS] = {
initIOPWM(PWM::FlexPWM2),
initIOPWM(PWM::FlexPWM3),
initIOPWM(PWM::FlexPWM4),
};

__EXPORT const io_timers_channel_mapping_t io_timers_channel_mapping = {
.element = {
{
.first_channel_index = 0,
.channel_count = 4,
},
{
.first_channel_index = 4,
.channel_count = 2,
},
{
.first_channel_index = 6,
.channel_count = 2,
}
}
constexpr timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = {
initIOTimerChannel(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule0}, IOMUX::Pad::GPIO_B0_06),
initIOTimerChannel(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule1}, IOMUX::Pad::GPIO_EMC_08),
initIOTimerChannel(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule2}, IOMUX::Pad::GPIO_EMC_10),
initIOTimerChannel(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule3}, IOMUX::Pad::GPIO_AD_B0_09),
initIOTimerChannel(io_timers, {PWM::PWM3_PWM_A, PWM::Submodule2}, IOMUX::Pad::GPIO_EMC_33),
initIOTimerChannel(io_timers, {PWM::PWM3_PWM_B, PWM::Submodule0}, IOMUX::Pad::GPIO_EMC_30),
initIOTimerChannel(io_timers, {PWM::PWM4_PWM_A, PWM::Submodule2}, IOMUX::Pad::GPIO_EMC_04),
initIOTimerChannel(io_timers, {PWM::PWM4_PWM_B, PWM::Submodule0}, IOMUX::Pad::GPIO_EMC_01),
};

__EXPORT const timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = {
{
/* FMU_CH1 : GPIO_B0_06 GPIO2 Pin 6 FLEXPWM2_PWMA0 */
.gpio_out = PIN_FLEXPWM2_PWMA00,
.gpio_portpin = GPIO_PORT2 | GPIO_PIN6,
.timer_index = 0,
.val_offset = PWMA_VAL,
.sub_module = SM0,
.sub_module_bits = MCTRL_LDOK(1 << SM0),

},
{
/* FMU_CH2 : GPIO_EMC_08 GPIO4 Pin 8 FLEXPWM2_PWMA1 */
.gpio_out = PIN_FLEXPWM2_PWMA01,
.gpio_portpin = GPIO_PORT4 | GPIO_PIN8,
.timer_index = 0,
.val_offset = PWMA_VAL,
.sub_module = SM1,
.sub_module_bits = MCTRL_LDOK(1 << SM1),

},
{
/* FMU_CH3 : GPIO_EMC_10 GPIO4 Pin 10 FLEXPWM2_PWMA2 */
.gpio_out = PIN_FLEXPWM2_PWMA02,
.gpio_portpin = GPIO_PORT4 | GPIO_PIN10,
.timer_index = 0,
.val_offset = PWMA_VAL,
.sub_module = SM2,
.sub_module_bits = MCTRL_LDOK(1 << SM2),

},
{
/* FMU_CH4 : GPIO_AD_B0_09 GPIO1 Pin 9 FLEXPWM2_PWMA3 */
.gpio_out = PIN_FLEXPWM2_PWMA03,
.gpio_portpin = GPIO_PORT1 | GPIO_PIN9,
.timer_index = 0,
.val_offset = PWMA_VAL,
.sub_module = SM3,
.sub_module_bits = MCTRL_LDOK(1 << SM3),
},

{
/* FMU_CH5 : GPIO_EMC_33 GPIO3 Pin 19 FLEXPWM3_PWMA2 */
.gpio_out = PIN_FLEXPWM3_PWMA02,
.gpio_portpin = GPIO_PORT3 | GPIO_PIN19,
.timer_index = 1,
.val_offset = PWMA_VAL,
.sub_module = SM2,
.sub_module_bits = MCTRL_LDOK(1 << SM2),
},
{
/* FMU_CH6 : GPIO_EMC_30 GPIO4 Pin 30 FLEXPWM3_PWMB0 */
.gpio_out = PIN_FLEXPWM3_PWMB00,
.gpio_portpin = GPIO_PORT4 | GPIO_PIN30,
.timer_index = 1,
.val_offset = PWMB_VAL,
.sub_module = SM0,
.sub_module_bits = MCTRL_LDOK(1 << SM0),

},

{
/* FMU_CH7 : GPIO_EMC_04 GPIO4 Pin 4 FLEXPWM4_PWMA2 */
.gpio_out = PIN_FLEXPWM4_PWMA02,
.gpio_portpin = GPIO_PORT4 | GPIO_PIN4,
.timer_index = 2,
.val_offset = PWMA_VAL,
.sub_module = SM2,
.sub_module_bits = MCTRL_LDOK(1 << SM2),

},
{
/* FMU_CH8 : GPIO_EMC_01 GPIO4 Pin 1 FLEXPWM4_PWMB0 */
.gpio_out = PIN_FLEXPWM4_PWMB00,
.gpio_portpin = GPIO_PORT4 | GPIO_PIN1,
.timer_index = 2,
.val_offset = PWMB_VAL,
.sub_module = SM0,
.sub_module_bits = MCTRL_LDOK(1 << SM0),

},

};
constexpr io_timers_channel_mapping_t io_timers_channel_mapping =
initIOTimerChannelMapping(io_timers, timer_io_channels);

__EXPORT const struct io_timers_t led_pwm_timers[MAX_LED_TIMERS] = {
constexpr io_timers_t led_pwm_timers[MAX_LED_TIMERS] = {
};

__EXPORT const struct timer_io_channels_t led_pwm_channels[MAX_TIMER_LED_CHANNELS] = {
constexpr timer_io_channels_t led_pwm_channels[MAX_TIMER_LED_CHANNELS] = {
};


__EXPORT void fmurt1062_timer_initialize(void)
void fmurt1062_timer_initialize(void)
{
/* We must configure Qtimer 3 as the IPG divide by to yield 16 Mhz
* and deliver that clock to the eFlexPWM234 via XBAR
Expand Down

0 comments on commit e2f3065

Please sign in to comment.