Skip to content

Commit

Permalink
AP_HAL_ChibiOS: explicitly set dshot rate when using iomcu
Browse files Browse the repository at this point in the history
  • Loading branch information
andyp1per authored and tridge committed Aug 14, 2023
1 parent c4cfc5d commit 75c1ad6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions libraries/AP_HAL_ChibiOS/RCOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,16 +513,15 @@ void RCOutput::set_default_rate(uint16_t freq_hz)
*/
void RCOutput::set_dshot_rate(uint8_t dshot_rate, uint16_t loop_rate_hz)
{
#if HAL_WITH_IO_MCU
if (AP_BoardConfig::io_dshot()) {
iomcu.set_dshot_period(1000UL, 0);
}
#endif

// for low loop rates simply output at 1Khz on a timer
if (loop_rate_hz <= 100 || dshot_rate == 0) {
_dshot_period_us = 1000UL;
_dshot_rate = 0;
#if HAL_WITH_IO_MCU
if (AP_BoardConfig::io_dshot()) {
iomcu.set_dshot_period(1000UL, 0);
}
#endif
return;
}
// if there are non-dshot channels then do likewise
Expand All @@ -532,6 +531,13 @@ void RCOutput::set_dshot_rate(uint8_t dshot_rate, uint16_t loop_rate_hz)
group.current_mode == MODE_PWM_BRUSHED) {
_dshot_period_us = 1000UL;
_dshot_rate = 0;
#if HAL_WITH_IO_MCU
// this is not strictly neccessary since the iomcu could run at a different rate,
// but there is only one parameter to control this
if (AP_BoardConfig::io_dshot()) {
iomcu.set_dshot_period(1000UL, 0);
}
#endif
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_HAL_ChibiOS/hwdef/iomcu-dshot/hwdef.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ undef AP_HAL_SHARED_DMA_ENABLED
define STM32_TIM_TIM2_UP_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
define STM32_TIM_TIM2_UP_DMA_CHAN 1

# TIM4_UP (PWM 3/4) cannot be used with sharin as channels used by high speed USART2 RX/TX
# TIM4_UP (PWM 3/4) cannot be used with sharing as channels used by high speed USART2 RX/TX
define AP_HAL_SHARED_DMA_ENABLED 1
define STM32_TIM_TIM4_UP_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
define STM32_TIM_TIM4_UP_DMA_CHAN 1
Expand Down

0 comments on commit 75c1ad6

Please sign in to comment.