1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-13 11:29:56 +03:00
inav/docs/development/Converting Betaflight Targets.md
Marcelo Bezerra 3443f268a2
Fix typo
2023-12-11 15:38:18 +01:00

3.5 KiB

If your flight controller does not have an official INAV target, it is possible to use src/utils/bf2inav.py script to generate a good starting point for an unofficial INAV target.

This script can read the config.h from Betaflight's target configuration repository and it currently supports STM32F405, STM32F722, STM32F745, STM32H743 and AT32F435 targets. Locate your Flight Controller target config.h in BetaFlight's repo, eg.: config.h, for BETAFPVF435 target.

It is also advisable to record the output of the timer command from BetaFlight, as it will provide useful information on timer usage that can be used to adjust the generated target later.

# timer
timer B08 AF3
# pin B08: TIM10 CH1 (AF3)
timer C08 AF3
# pin C08: TIM8 CH3 (AF3)
timer B00 AF2
# pin B00: TIM3 CH3 (AF2)
timer B01 AF2
# pin B01: TIM3 CH4 (AF2)
timer A03 AF1
# pin A03: TIM2 CH4 (AF1)
timer A02 AF1
# pin A02: TIM2 CH3 (AF1)
timer B06 AF2
# pin B06: TIM4 CH1 (AF2)
timer A08 AF1
# pin A08: TIM1 CH1 (AF1)
timer A09 AF1
# pin A09: TIM1 CH2 (AF1)
timer A10 AF1
# pin A10: TIM1 CH3 (AF1)

In the above example, pin B08: TIM10 CH1 (AF3) means that pind to CH1. This information can be used to fix the generated timer assigned to match BetaFlight's allocation by editing the target.c file generated by the bf2inav.py script.

Using the BETAFPVF405 target mentioned above, to create the target now we need to:

  1. Download INAV source code and be able to build
  2. Download the config.h from BetaFlight repository
  3. Create a target folder that will be used as the output folder for the bf2inav.py script, eg: inav/src/main/targets/BETAFPVF405
  4. Navigate to the script folder in inav/src/utils/
  5. python3 ./bf2inav.py -i config.h -o ../main/target/BETAFPVF405/
  6. Edit generated target.c and chose the correct timer definitions to match Betaflight's timer definitions.
timerHardware_t timerHardware[] = {
    DEF_TIM(TIM3, CH3, PB0, TIM_USE_OUTPUT_AUTO, 0, 0),
    //DEF_TIM(TIM8, CH2N, PB0, TIM_USE_OUTPUT_AUTO, 0, 0),
    //DEF_TIM(TIM1, CH2N, PB0, TIM_USE_OUTPUT_AUTO, 0, 0),

    DEF_TIM(TIM3, CH4, PB1, TIM_USE_OUTPUT_AUTO, 0, 0),
    //DEF_TIM(TIM8, CH3N, PB1, TIM_USE_OUTPUT_AUTO, 0, 0),
    //DEF_TIM(TIM1, CH3N, PB1, TIM_USE_OUTPUT_AUTO, 0, 0),

    //DEF_TIM(TIM5, CH4, PA3, TIM_USE_OUTPUT_AUTO, 0, 0),
    //DEF_TIM(TIM9, CH2, PA3, TIM_USE_OUTPUT_AUTO, 0, 0),
    DEF_TIM(TIM2, CH4, PA3, TIM_USE_OUTPUT_AUTO, 0, 0),

    //DEF_TIM(TIM5, CH3, PA2, TIM_USE_OUTPUT_AUTO, 0, 0),
    //DEF_TIM(TIM9, CH1, PA2, TIM_USE_OUTPUT_AUTO, 0, 0),
    DEF_TIM(TIM2, CH3, PA2, TIM_USE_OUTPUT_AUTO, 0, 0),

    DEF_TIM(TIM8, CH3, PC8, TIM_USE_OUTPUT_AUTO, 0, 0),
    //DEF_TIM(TIM3, CH3, PC8, TIM_USE_OUTPUT_AUTO, 0, 0),

    DEF_TIM(TIM1, CH1, PA8, TIM_USE_OUTPUT_AUTO, 0, 0),

    //DEF_TIM(TIM3, CH1, PB4, TIM_USE_BEEPER, 0, 0),

    DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0, 0),

};

In this particular example, PA3, PA2 were changed to match Betaflight's mapping, and the timer PB4 was disabled, due to a timer conflict. Normal channels are prefered over N channels (CH1, over CH1N) or C channels in AT32 architectures. 7. Now update yout build scripts by running cmake and build the target you just created. The target name can be checked in the generated CMakeLists.txt, but should match the Betaflight target name.

For information on how to build INAV, check the documents in the docs/development folder.