Skip to content

Commit

Permalink
imxrt dshot timing fix (#23365)
Browse files Browse the repository at this point in the history
* imxrt: Change PLL settings for more accurate dshot timing
* Update NuttX submodule
  • Loading branch information
PetervdPerk-NXP authored Jul 8, 2024
1 parent 77709c2 commit 6bd81f3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions boards/px4/fmu-v6xrt/nuttx-config/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define IMXRT_IPG_PODF_DIVIDER 5
#define BOARD_GPT_FREQUENCY 24000000
#define BOARD_XTAL_FREQUENCY 24000000
#define BOARD_FLEXIO_PREQ 108000000

/* SDIO *********************************************************************/

Expand Down
12 changes: 6 additions & 6 deletions boards/px4/fmu-v6xrt/src/imxrt_clockconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ const struct clock_configuration_s g_initial_clkconfig = {
.div = 1,
.mux = ACMP_CLK_ROOT_OSC_RC_48M_DIV2,
},
.flexio1_clk_root = /* 240 / 2 = 120Mhz */
.flexio1_clk_root = /* 432 / 4 = 108Mhz */
{
.enable = 1,
.div = 2,
.mux = FLEXIO1_CLK_ROOT_SYS_PLL3_DIV2,
.div = 4,
.mux = FLEXIO1_CLK_ROOT_SYS_PLL2_PFD3,
},
.flexio2_clk_root =
{
Expand Down Expand Up @@ -492,9 +492,9 @@ const struct clock_configuration_s g_initial_clkconfig = {
.mfd = 268435455,
.ss_enable = 0,
.pfd0 = 27, /* (528 * 18) / 27 = 352 MHz */
.pfd1 = 16, /* (528 * 16) / 16 = 594 MHz */
.pfd2 = 24, /* (528 * 24) / 27 = 396 MHz */
.pfd3 = 32, /* (528 * 32) / 27 = 297 MHz */
.pfd1 = 16, /* (528 * 18) / 16 = 594 MHz */
.pfd2 = 24, /* (528 * 18) / 24 = 396 MHz */
.pfd3 = 22, /* (528 * 18) / 22 = 216 MHz */
},
.sys_pll3 =
{
Expand Down
2 changes: 1 addition & 1 deletion platforms/nuttx/NuttX/nuttx
5 changes: 2 additions & 3 deletions platforms/nuttx/src/px4/nxp/imxrt/dshot/dshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include "arm_internal.h"

#define FLEXIO_BASE IMXRT_FLEXIO1_BASE
#define FLEXIO_PREQ 120000000
#define DSHOT_TIMERS FLEXIO_SHIFTBUFNIS_COUNT
#define DSHOT_THROTTLE_POSITION 5u
#define DSHOT_TELEMETRY_POSITION 4u
Expand Down Expand Up @@ -305,8 +304,8 @@ static int flexio_irq_handler(int irq, void *context, void *arg)
int up_dshot_init(uint32_t channel_mask, unsigned dshot_pwm_freq, bool enable_bidirectional_dshot)
{
/* Calculate dshot timings based on dshot_pwm_freq */
dshot_tcmp = 0x2F00 | (((FLEXIO_PREQ / (dshot_pwm_freq * 3) / 2)) & 0xFF);
bdshot_tcmp = 0x2900 | (((FLEXIO_PREQ / (dshot_pwm_freq * 5 / 4) / 2) - 1) & 0xFF);
dshot_tcmp = 0x2F00 | (((BOARD_FLEXIO_PREQ / (dshot_pwm_freq * 3) / 2) - 1) & 0xFF);
bdshot_tcmp = 0x2900 | (((BOARD_FLEXIO_PREQ / (dshot_pwm_freq * 5 / 4) / 2) - 3) & 0xFF);

/* Clock FlexIO peripheral */
imxrt_clockall_flexio1();
Expand Down

0 comments on commit 6bd81f3

Please sign in to comment.