From df54caba1e2dac4925b5af7c2c398af567f7d267 Mon Sep 17 00:00:00 2001 From: Peter van der Perk Date: Sun, 10 Mar 2024 15:40:22 +0100 Subject: [PATCH] tropic: enable dshot --- boards/nxp/tropic/default.px4board | 5 ++- .../nxp/tropic/nuttx-config/include/board.h | 8 ++++ .../scripts/itcm_functions_includes.ld | 1 + boards/nxp/tropic/src/init.c | 38 +++++++++++++++++-- boards/nxp/tropic/src/timer_config.cpp | 21 +++++----- 5 files changed, 56 insertions(+), 17 deletions(-) diff --git a/boards/nxp/tropic/default.px4board b/boards/nxp/tropic/default.px4board index 27b856f0a6..4262ca34cb 100644 --- a/boards/nxp/tropic/default.px4board +++ b/boards/nxp/tropic/default.px4board @@ -9,6 +9,7 @@ CONFIG_DRIVERS_BAROMETER_DPS310=y CONFIG_DRIVERS_CAMERA_CAPTURE=y CONFIG_DRIVERS_CAMERA_TRIGGER=y CONFIG_DRIVERS_DISTANCE_SENSOR_LIGHTWARE_LASER_I2C=y +CONFIG_DRIVERS_DSHOT=y CONFIG_DRIVERS_GPS=y CONFIG_DRIVERS_IMU_BOSCH_BMI088=y CONFIG_DRIVERS_IMU_INVENSENSE_ICM20948=y @@ -22,10 +23,10 @@ CONFIG_DRIVERS_POWER_MONITOR_INA238=y CONFIG_DRIVERS_PWM_OUT=y CONFIG_DRIVERS_RC_INPUT=y CONFIG_DRIVERS_SAFETY_BUTTON=y -CONFIG_DRIVERS_UAVCAN=y -CONFIG_BOARD_UAVCAN_INTERFACES=1 CONFIG_COMMON_TELEMETRY=y CONFIG_DRIVERS_TONE_ALARM=y +CONFIG_DRIVERS_UAVCAN=y +CONFIG_BOARD_UAVCAN_INTERFACES=1 CONFIG_MODULES_BATTERY_STATUS=y CONFIG_MODULES_CAMERA_FEEDBACK=y CONFIG_MODULES_COMMANDER=y diff --git a/boards/nxp/tropic/nuttx-config/include/board.h b/boards/nxp/tropic/nuttx-config/include/board.h index f074c719df..c8af099bcf 100644 --- a/boards/nxp/tropic/nuttx-config/include/board.h +++ b/boards/nxp/tropic/nuttx-config/include/board.h @@ -133,6 +133,14 @@ #define BOARD_GPT_FREQUENCY \ (BOARD_CPU_FREQUENCY / IMXRT_IPG_PODF_DIVIDER) / IMXRT_PERCLK_PODF_DIVIDER + +/* 108Mhz clock for FlexIO using PLL3 PFD2 @ 520 */ +#define CONFIG_FLEXIO1_CLK 1 +#define CONFIG_FLEXIO1_PRED_DIVIDER 5 +#define CONFIG_FLEXIO1_PODF_DIVIDER 1 +#define CONFIG_PLL3_PFD2_FRAC 16 +#define BOARD_FLEXIO_PREQ 108000000 + /* Define this to enable tracing */ #if CONFIG_USE_TRACE # define IMXRT_TRACE_PODF_DIVIDER 1 diff --git a/boards/nxp/tropic/nuttx-config/scripts/itcm_functions_includes.ld b/boards/nxp/tropic/nuttx-config/scripts/itcm_functions_includes.ld index b134bc1116..d5c804a72b 100644 --- a/boards/nxp/tropic/nuttx-config/scripts/itcm_functions_includes.ld +++ b/boards/nxp/tropic/nuttx-config/scripts/itcm_functions_includes.ld @@ -101,6 +101,7 @@ *(.text.imxrt_dispatch) *(.text.arp_arpin) *(.text.ipv4_input) +*(.text.flexio_irq_handler) *(.text.work_thread) diff --git a/boards/nxp/tropic/src/init.c b/boards/nxp/tropic/src/init.c index 5569f08f95..f3b43fc4d5 100644 --- a/boards/nxp/tropic/src/init.c +++ b/boards/nxp/tropic/src/init.c @@ -76,6 +76,7 @@ #include #undef FLEXSPI_LUT_COUNT #include +#include #include @@ -87,10 +88,6 @@ #include #include -/**************************************************************************** - * Pre-Processor Definitions - ****************************************************************************/ - /* Configuration ************************************************************/ /* @@ -318,6 +315,38 @@ int imxrt_phy_boardinitialize(int intf) return OK; } +void imxrt_flexio_clocking(void) +{ + uint32_t reg; + + /* Init USB PLL3 PFD2 */ + + reg = getreg32(IMXRT_CCM_ANALOG_PFD_480); + + while ((getreg32(IMXRT_CCM_ANALOG_PLL_USB1) & + CCM_ANALOG_PLL_USB1_LOCK) == 0) { + } + + reg &= ~CCM_ANALOG_PFD_480_PFD2_FRAC_MASK; + + /* Set PLL3 PFD2 to 480 * 18 / CONFIG_PLL3_PFD2_FRAC */ + + reg |= ((uint32_t)(CONFIG_PLL3_PFD2_FRAC) << CCM_ANALOG_PFD_480_PFD3_FRAC_SHIFT); + + putreg32(reg, IMXRT_CCM_ANALOG_PFD_480); + + reg = getreg32(IMXRT_CCM_CDCDR); + reg &= ~(CCM_CDCDR_FLEXIO1_CLK_SEL_MASK | + CCM_CDCDR_FLEXIO1_CLK_PODF_MASK | + CCM_CDCDR_FLEXIO1_CLK_PRED_MASK); + reg |= CCM_CDCDR_FLEXIO1_CLK_SEL(CONFIG_FLEXIO1_CLK); + reg |= CCM_CDCDR_FLEXIO1_CLK_PODF + (CCM_PODF_FROM_DIVISOR(CONFIG_FLEXIO1_PODF_DIVIDER)); + reg |= CCM_CDCDR_FLEXIO1_CLK_PRED + (CCM_PRED_FROM_DIVISOR(CONFIG_FLEXIO1_PRED_DIVIDER)); + putreg32(reg, IMXRT_CCM_CDCDR); +} + /**************************************************************************** * Name: board_app_initialize @@ -345,6 +374,7 @@ int imxrt_phy_boardinitialize(int intf) ****************************************************************************/ __EXPORT int board_app_initialize(uintptr_t arg) { + imxrt_flexio_clocking(); /* Power on Interfaces */ diff --git a/boards/nxp/tropic/src/timer_config.cpp b/boards/nxp/tropic/src/timer_config.cpp index ea5669af0d..1955fcc26d 100644 --- a/boards/nxp/tropic/src/timer_config.cpp +++ b/boards/nxp/tropic/src/timer_config.cpp @@ -75,27 +75,26 @@ constexpr io_timers_t io_timers[MAX_IO_TIMERS] = { - initIOPWM(PWM::FlexPWM2, PWM::Submodule0), // PWM_1, PMW_5 - initIOPWM(PWM::FlexPWM2, PWM::Submodule1), // PWM_0 + initIOPWMDshot(PWM::FlexPWM2, PWM::Submodule0), // PWM_1, PMW_5 + initIOPWMDshot(PWM::FlexPWM2, PWM::Submodule1), // PWM_0 initIOPWM(PWM::FlexPWM2, PWM::Submodule2), // PWM_4 - initIOPWM(PWM::FlexPWM4, PWM::Submodule2), // PWM_2, PWM_3 + initIOPWMDshot(PWM::FlexPWM4, PWM::Submodule2), // PWM_2, PWM_3 }; -/* Using PWM_4 and PWM_5 breaks PWM needs driver fixup */ +#define FXIO_IOMUX (IOMUX_SLEW_FAST | IOMUX_DRIVE_130OHM | IOMUX_PULL_UP_47K | IOMUX_SCHMITT_TRIGGER) + constexpr timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = { - initIOTimerChannel(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule0}, IOMUX::Pad::GPIO_EMC_06), /* RevA. PWM_1 RevB. PWM1 */ - initIOTimerChannel(io_timers, {PWM::PWM2_PWM_B, PWM::Submodule0}, IOMUX::Pad::GPIO_EMC_07), /* RevA. PWM_5 RevB. PWM2 */ - initIOTimerChannel(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule1}, IOMUX::Pad::GPIO_EMC_08), /* RevA. PWM_0 RevB. PWM3 */ + initIOTimerChannelDshot(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule0}, IOMUX::Pad::GPIO_EMC_06, GPIO_FLEXIO1_FLEXIO06_1 | FXIO_IOMUX, 6), /* RevA. PWM_1 RevB. PWM1 */ + initIOTimerChannelDshot(io_timers, {PWM::PWM2_PWM_B, PWM::Submodule0}, IOMUX::Pad::GPIO_EMC_07, GPIO_FLEXIO1_FLEXIO07_1 | FXIO_IOMUX, 7), /* RevA. PWM_5 RevB. PWM2 */ + initIOTimerChannelDshot(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule1}, IOMUX::Pad::GPIO_EMC_08, GPIO_FLEXIO1_FLEXIO08_1 | FXIO_IOMUX, 8), /* RevA. PWM_0 RevB. PWM3 */ initIOTimerChannel(io_timers, {PWM::PWM2_PWM_B, PWM::Submodule2}, IOMUX::Pad::GPIO_B0_11), /* RevA. PWM_4 RevB. PWM4 */ - initIOTimerChannel(io_timers, {PWM::PWM4_PWM_A, PWM::Submodule2}, IOMUX::Pad::GPIO_EMC_04), /* RevA. PWM_3 RevB. PWM5 */ - initIOTimerChannel(io_timers, {PWM::PWM4_PWM_B, PWM::Submodule2}, IOMUX::Pad::GPIO_EMC_05), /* RevA. PWM_2 RevB. PWM6 */ + initIOTimerChannelDshot(io_timers, {PWM::PWM4_PWM_A, PWM::Submodule2}, IOMUX::Pad::GPIO_EMC_04, GPIO_FLEXIO1_FLEXIO04_1 | FXIO_IOMUX, 4), /* RevA. PWM_3 RevB. PWM5 */ + initIOTimerChannelDshot(io_timers, {PWM::PWM4_PWM_B, PWM::Submodule2}, IOMUX::Pad::GPIO_EMC_05, GPIO_FLEXIO1_FLEXIO05_1 | FXIO_IOMUX, 5), /* RevA. PWM_2 RevB. PWM6 */ }; - constexpr io_timers_channel_mapping_t io_timers_channel_mapping = initIOTimerChannelMapping(io_timers, timer_io_channels); - constexpr io_timers_t led_pwm_timers[MAX_LED_TIMERS] = { };