From d0a749022243c07e9ba240f514fe8eee043cd4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sun, 8 Sep 2019 11:42:04 +0200 Subject: [PATCH] dshot: update timer generation before DMA request This reloads the timer configuration before triggering DMA. Without that, in rare cases, there were 17 bits sent instead of 16. The 1. bit (1. pulse) was always wrong (too much), the rest of the bits were the correct DShot packet that was meant to be sent. --- platforms/nuttx/src/px4/stm/stm32_common/dshot/dshot.c | 1 + .../src/px4/stm/stm32_common/include/px4_arch/io_timer.h | 1 + platforms/nuttx/src/px4/stm/stm32_common/io_pins/io_timer.c | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/platforms/nuttx/src/px4/stm/stm32_common/dshot/dshot.c b/platforms/nuttx/src/px4/stm/stm32_common/dshot/dshot.c index 8fb67dfd5d..b3ee564f7e 100644 --- a/platforms/nuttx/src/px4/stm/stm32_common/dshot/dshot.c +++ b/platforms/nuttx/src/px4/stm/stm32_common/dshot/dshot.c @@ -383,6 +383,7 @@ void up_dshot_trigger(void) uint32_t dshot_data_size = motors_number * ONE_MOTOR_BUFF_SIZE; *rxIFCR |= dma_int_streamx_mask; //clear interrupt flags *rSxNDTR = dshot_data_size; + io_timer_update_generation(timer); *rSxCR |= DMA_SCR_EN; // Trigger DMA } } diff --git a/platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/io_timer.h b/platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/io_timer.h index c2164a9812..a8a319a4a7 100644 --- a/platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/io_timer.h +++ b/platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/io_timer.h @@ -143,6 +143,7 @@ __EXPORT int io_timer_free_channel(unsigned channel); __EXPORT int io_timer_get_channel_mode(unsigned channel); __EXPORT int io_timer_get_mode_channels(io_timer_channel_mode_t mode); __EXPORT extern void io_timer_trigger(void); +__EXPORT void io_timer_update_generation(uint8_t timer); __EXPORT extern int io_timer_set_dshot_mode(uint8_t timer, unsigned dshot_pwm_rate, uint8_t dma_burst_length); diff --git a/platforms/nuttx/src/px4/stm/stm32_common/io_pins/io_timer.c b/platforms/nuttx/src/px4/stm/stm32_common/io_pins/io_timer.c index b309a3e5e1..d977e4dd48 100644 --- a/platforms/nuttx/src/px4/stm/stm32_common/io_pins/io_timer.c +++ b/platforms/nuttx/src/px4/stm/stm32_common/io_pins/io_timer.c @@ -492,6 +492,12 @@ static inline void io_timer_set_oneshot_mode(unsigned timer) rEGR(timer) = GTIM_EGR_UG; } +void io_timer_update_generation(uint8_t timer) +{ + // Re-initialize the counter and generate an update of the registers + rEGR(timer) = ATIM_EGR_UG; +} + int io_timer_set_dshot_mode(uint8_t timer, unsigned dshot_pwm_freq, uint8_t dma_burst_length) { int ret_val = OK;