mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-12 19:10:32 +03:00
## Commit Summary: Fix incorrect TIMUP DMA configuration dump on H743 **Problem**: H743 platform had incorrect TIMUP DMA configuration dumping and parsing, causing errors when restoring dumped configurations. **Solution**: This PR implements a comprehensive fix for TIMUP DMA handling across multiple areas: ### CLI DMA Option Handling (`src/main/cli/cli.c`) - Added `getDmaOptDisplayNumber()` and `displayNumberToDmaOptIndex()` helper functions - Properly translates between internal DMA option indices and user-facing display numbers - Integrates presence mask validation for `DMA_PERIPH_TIMUP` peripheral - Ensures only valid/present timer options are displayed and accepted ### Timer Definition Refactoring (Multiple Platforms) - Replaced hardcoded `HARDWARE_TIMER_DEFINITION_COUNT` with dynamic `BITCOUNT(USED_TIMERS)` - Updated STM32H7/G4 `TIMUP_TIMERS` macros to use `TIM_N(x)` instead of `BIT(x)` - Expanded AT32 `USED_TIMERS` to include timers 6 and 7 - Added static assertion to verify `TIMUP_TIMERS` bits are included in `USED_TIMERS` ### Timer Index Management (`src/main/drivers/timer.h` + platform implementations) - Added `TIM_N(n)` macro for timer bitmask generation - Added `TIMER_INDEX(i)` macro for proper index calculation - Implemented `timerGetIndexByNumber()` function across all platforms (STM32, AT32, APM32) - Provides bidirectional timer number ↔ index conversion ### DMA Request Mapping Updates - Modified `REQMAP_TIMUP` macros to use `TIMER_INDEX(timno)` instead of `timno - 1` - Ensures correct DMA request mapping for non-contiguous timer numbering ### Timer Configuration (`src/main/pg/timerup.c`) - Replaced hardware timer count checks with `TIMUP_TIMERS` bitmask validation - Added support for timers 6 and 7 that were previously omitted - Uses computed `TIMER_INDEX()` for proper array indexing
77 lines
2.6 KiB
C
77 lines
2.6 KiB
C
/*
|
|
* This file is part of Cleanflight and Betaflight.
|
|
*
|
|
* Cleanflight and Betaflight are free software. You can redistribute
|
|
* this software and/or modify this software under the terms of the
|
|
* GNU General Public License as published by the Free Software
|
|
* Foundation, either version 3 of the License, or (at your option)
|
|
* any later version.
|
|
*
|
|
* Cleanflight and Betaflight are distributed in the hope that they
|
|
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this software.
|
|
*
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
#include "platform.h"
|
|
|
|
#if defined(USE_TIMER_MGMT) && defined(USE_TIMER_UP_CONFIG)
|
|
|
|
#include "drivers/dma_reqmap.h"
|
|
#include "drivers/timer.h"
|
|
|
|
#include "timerup.h"
|
|
|
|
PG_REGISTER_ARRAY_WITH_RESET_FN(timerUpConfig_t, HARDWARE_TIMER_DEFINITION_COUNT, timerUpConfig, PG_TIMER_UP_CONFIG, 0);
|
|
|
|
void pgResetFn_timerUpConfig(timerUpConfig_t *config)
|
|
{
|
|
for (unsigned timno = 0; timno < HARDWARE_TIMER_DEFINITION_COUNT; timno++) {
|
|
config[timno].dmaopt = DMA_OPT_UNUSED;
|
|
}
|
|
|
|
#if defined(TIMUP1_DMA_OPT) && (TIMUP_TIMERS & TIM_N(1))
|
|
config[TIMER_INDEX(1)].dmaopt = TIMUP1_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP2_DMA_OPT) && (TIMUP_TIMERS & TIM_N(2))
|
|
config[TIMER_INDEX(2)].dmaopt = TIMUP2_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP3_DMA_OPT) && (TIMUP_TIMERS & TIM_N(3))
|
|
config[TIMER_INDEX(3)].dmaopt = TIMUP3_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP4_DMA_OPT) && (TIMUP_TIMERS & TIM_N(4))
|
|
config[TIMER_INDEX(4)].dmaopt = TIMUP4_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP5_DMA_OPT) && (TIMUP_TIMERS & TIM_N(5))
|
|
config[TIMER_INDEX(5)].dmaopt = TIMUP5_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP6_DMA_OPT) && (TIMUP_TIMERS & TIM_N(6))
|
|
config[TIMER_INDEX(6)].dmaopt = TIMUP6_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP7_DMA_OPT) && (TIMUP_TIMERS & TIM_N(7))
|
|
config[TIMER_INDEX(7)].dmaopt = TIMUP7_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP8_DMA_OPT) && (TIMUP_TIMERS & TIM_N(8))
|
|
config[TIMER_INDEX(8)].dmaopt = TIMUP8_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP15_DMA_OPT) && (TIMUP_TIMERS & TIM_N(15))
|
|
config[TIMER_INDEX(15)].dmaopt = TIMUP15_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP16_DMA_OPT) && (TIMUP_TIMERS & TIM_N(16))
|
|
config[TIMER_INDEX(16)].dmaopt = TIMUP16_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP17_DMA_OPT) && (TIMUP_TIMERS & TIM_N(17))
|
|
config[TIMER_INDEX(17)].dmaopt = TIMUP17_DMA_OPT;
|
|
#endif
|
|
#if defined(TIMUP20_DMA_OPT) && (TIMUP_TIMERS & TIM_N(20))
|
|
config[TIMER_INDEX(20)].dmaopt = TIMUP20_DMA_OPT;
|
|
#endif
|
|
}
|
|
#endif
|