Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BF config to INAV target converter #9556

Merged
merged 38 commits into from
Nov 16, 2024
Merged

Conversation

mmosca
Copy link
Collaborator

@mmosca mmosca commented Dec 10, 2023

Add a script that can generate a workable INAV target, from a config.h from https://github.com/betaflight/config.

The generated target, while not perfect, often works.

User may need to fine tune the timer selection to be able to use DSHOT or to get an optimal distribution of outputs and timers.

Example usage:

./bf2inav.py -i ~/dev/bf/config/configs/BETAFPVF405/config.h -o ../main/target/BETAFPVF405/

TODO:

  • STM32F405 timer info
  • STM32F722 timer info
  • STM32F7x5 timer info
  • STM32H743 timer info
  • AT32F435 timer info
  • Infer timer definition from BF config.h

mmosca added 24 commits January 29, 2023 17:30
The target can be used as a starting point for a full featured INAV
target, but won't include any fixed wing functionality.
- Leds
- Beeper
- WS2811
- UART
- SOFTSERIAL
- SPI
- I2C
Works for BEFH-BETAFPVF411.config
Fails for HAMO-CRAZYBEEF4SX1280.config

Still need to add ADC definition
+ unofficial target for betafpvf411 5a aio
Currently only cover AT32F435
Target files generated, probably needs reviewing pin mappings
@mmosca mmosca marked this pull request as draft December 10, 2023 19:24
@mmosca mmosca marked this pull request as ready for review December 11, 2023 14:27
@mmosca mmosca changed the title Add BF config to INAV target convereter Add BF config to INAV target converter Dec 12, 2023
@YI-BOYANG
Copy link
Contributor

Great!

@mbainrot
Copy link

Quick and dirty test before I got to bed, doesn't seem to like the betaflight/AIKONF7 config

~/Git/inav/src/utils$ ./bf2inav.py -i ~/Git/betaflight-config/configs/AIKONF7/config.h ../main/target/AIKONF7/ { "defines": { "FC_TARGET_MCU": "STM32F7X2", "BOARD_NAME": "AIKONF7", "MANUFACTURER_ID": "AIKO", "BEEPER_PIN": "PC15", "MOTOR1_PIN": "PC6", "MOTOR2_PIN": "PC7", "MOTOR3_PIN": "PC8", "MOTOR4_PIN": "PC9", "MOTOR5_PIN": "PB6", "MOTOR6_PIN": "PB8", "MOTOR7_PIN": "PB7", "MOTOR8_PIN": "PB1", "RX_PPM_PIN": "PB9", "LED_STRIP_PIN": "PA15", "UART1_TX_PIN": "PA9", "UART2_TX_PIN": "PA2", "UART3_TX_PIN": "PC10", "UART4_TX_PIN": "PA0", "UART5_TX_PIN": "PC12", "UART1_RX_PIN": "PA10", "UART2_RX_PIN": "PA3", "UART3_RX_PIN": "PC11", "UART4_RX_PIN": "PA1", "UART5_RX_PIN": "PD2", "I2C2_SCL_PIN": "PB10", "I2C2_SDA_PIN": "PB11", "LED0_PIN": "PC13", "SPI1_SCK_PIN": "PA5", "SPI2_SCK_PIN": "PB13", "SPI3_SCK_PIN": "PB3", "SPI1_SDI_PIN": "PA6", "SPI2_SDI_PIN": "PC2", "SPI3_SDI_PIN": "PB4", "SPI1_SDO_PIN": "PA7", "SPI2_SDO_PIN": "PB15", "SPI3_SDO_PIN": "PB5", "CAMERA_CONTROL_PIN": "PB14", "ADC_VBAT_PIN": "PC0", "ADC_RSSI_PIN": "PC3", "ADC_CURR_PIN": "PC1", "BARO_CS_PIN": "PB2", "FLASH_CS_PIN": "PB0", "MAX7456_SPI_CS_PIN": "PB12", "GYRO_1_EXTI_PIN": "PC4", "GYRO_1_CS_PIN": "PA4", "PINIO1_PIN": "PC14", "TIMER_PIN_MAPPING": "\\", "ADC1_DMA_OPT": "0", "BARO_SPI_INSTANCE": "SPI3", "DEFAULT_BLACKBOX_DEVICE": "BLACKBOX_DEVICE_FLASH", "DEFAULT_DSHOT_BURST": "DSHOT_DMAR_ON", "DEFAULT_CURRENT_METER_SOURCE": "CURRENT_METER_ADC", "DEFAULT_VOLTAGE_METER_SOURCE": "VOLTAGE_METER_ADC", "MAX7456_SPI_INSTANCE": "SPI2", "FLASH_SPI_INSTANCE": "SPI3", "GYRO_1_SPI_INSTANCE": "SPI1", "PINIO1_BOX": "40", "PINIO2_BOX": "0", "PINIO3_BOX": "0", "PINIO4_BOX": "0" }, "empty_defines": [ "USE_ACC", "USE_ACC_SPI_MPU6000", "USE_ACCGYRO_BMI270", "USE_ACC_SPI_ICM42688P", "USE_GYRO", "USE_GYRO_SPI_MPU6000", "USE_GYRO_SPI_ICM42688P", "USE_BARO", "USE_BARO_SPI_BMP280", "USE_BARO_SPI_DPS310", "USE_FLASH", "USE_FLASH_M25P16", "USE_MAX7456", "BEEPER_INVERTED", "USE_SPI_GYRO" ], "features": [ "FEATURE_OSD", "FEATURE_TELEMETRY", "FEATURE_CURRENT_METER", "FEATURE_VBAT", "FEATURE_TX_PROF_SEL", "FEATURE_BLACKBOX" ], "pins": { "PC15": "BEEPER", "PC6": "MOTOR1", "PC7": "MOTOR2", "PC8": "MOTOR3", "PC9": "MOTOR4", "PB6": "MOTOR5", "PB8": "MOTOR6", "PB7": "MOTOR7", "PB1": "MOTOR8", "PB9": "RX_PPM", "PA15": "LED_STRIP", "PA9": "UART1_TX", "PA2": "UART2_TX", "PC10": "UART3_TX", "PA0": "UART4_TX", "PC12": "UART5_TX", "PA10": "UART1_RX", "PA3": "UART2_RX", "PC11": "UART3_RX", "PA1": "UART4_RX", "PD2": "UART5_RX", "PB10": "I2C2_SCL", "PB11": "I2C2_SDA", "PC13": "LED0", "PA5": "SPI1_SCK", "PB13": "SPI2_SCK", "PB3": "SPI3_SCK", "PA6": "SPI1_SDI", "PC2": "SPI2_SDI", "PB4": "SPI3_SDI", "PA7": "SPI1_SDO", "PB15": "SPI2_SDO", "PB5": "SPI3_SDO", "PB14": "CAMERA_CONTROL", "PC0": "ADC_VBAT", "PC3": "ADC_RSSI", "PC1": "ADC_CURR", "PB2": "BARO_CS", "PB0": "FLASH_CS", "PB12": "MAX7456_SPI_CS", "PC4": "GYRO_1_EXTI", "PA4": "GYRO_1_CS", "PC14": "PINIO1" }, "funcs": { "BEEPER": "PC15", "MOTOR1": "PC6", "MOTOR2": "PC7", "MOTOR3": "PC8", "MOTOR4": "PC9", "MOTOR5": "PB6", "MOTOR6": "PB8", "MOTOR7": "PB7", "MOTOR8": "PB1", "RX_PPM": "PB9", "LED_STRIP": "PA15", "UART1_TX": "PA9", "UART2_TX": "PA2", "UART3_TX": "PC10", "UART4_TX": "PA0", "UART5_TX": "PC12", "UART1_RX": "PA10", "UART2_RX": "PA3", "UART3_RX": "PC11", "UART4_RX": "PA1", "UART5_RX": "PD2", "I2C2_SCL": "PB10", "I2C2_SDA": "PB11", "LED0": "PC13", "SPI1_SCK": "PA5", "SPI2_SCK": "PB13", "SPI3_SCK": "PB3", "SPI1_SDI": "PA6", "SPI2_SDI": "PC2", "SPI3_SDI": "PB4", "SPI1_SDO": "PA7", "SPI2_SDO": "PB15", "SPI3_SDO": "PB5", "CAMERA_CONTROL": "PB14", "ADC_VBAT": "PC0", "ADC_RSSI": "PC3", "ADC_CURR": "PC1", "BARO_CS": "PB2", "FLASH_CS": "PB0", "MAX7456_SPI_CS": "PB12", "GYRO_1_EXTI": "PC4", "GYRO_1_CS": "PA4", "PINIO1": "PC14" }, "timer_pin_map": { "0": { "i": "0", "p": "PC6", "o": "2", "d": "1" }, "1": { "i": "1", "p": "PC7", "o": "2", "d": "1" }, "2": { "i": "2", "p": "PC8", "o": "2", "d": "1" }, "3": { "i": "3", "p": "PC9", "o": "2", "d": "0" }, "4": { "i": "4", "p": "PB6", "o": "1", "d": "0" }, "5": { "i": "5", "p": "PB8", "o": "1", "d": "0" }, "6": { "i": "6", "p": "PB7", "o": "1", "d": "0" }, "7": { "i": "7", "p": "PB1", "o": "2", "d": "0" }, "8": { "i": "8", "p": "PB9", "o": "2", "d": "-1" }, "9": { "i": "9", "p": "PA15", "o": "1", "d": "0" } }, "mcu": { "type": "STM32F7X2" }, "board_name": "AIKONF7", "manufacturer_id": "AIKO" } Traceback (most recent call last): File "/home/max/Git/inav/src/utils/./bf2inav.py", line 978, in <module> main(sys.argv[1:]) File "/home/max/Git/inav/src/utils/./bf2inav.py", line 972, in main writeTarget(outputdir, map) File "/home/max/Git/inav/src/utils/./bf2inav.py", line 740, in writeTarget writeTargetH(outputFolder, map) File "/home/max/Git/inav/src/utils/./bf2inav.py", line 431, in writeTargetH file.write("#define IMU_%s_ALIGN %s\n" % (supportedgyro, getGyroAlign(map))) ^^^^^^^^^^^^^^^^^ File "/home/max/Git/inav/src/utils/./bf2inav.py", line 181, in getGyroAlign bfalign = map['defines']['GYRO_1_ALIGN'] ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^ KeyError: 'GYRO_1_ALIGN'

I'll look into it more tomorrow when I have some more braincells dancing together so I can give more useful feedback.

Git status
`On branch mosca-target-converter
Your branch is up to date with 'origin/mosca-target-converter'.

Untracked files:
(use "git add ..." to include in what will be committed)
CMakeLists.txt
target.h`

Git log
commit 7c532cd028d9ccce5f4d3a452fef1878f213a734 (HEAD -> mosca-target-converter, origin/mosca-target-converter) Author: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Tue Dec 12 12:26:18 2023 +0100

@mbainrot
Copy link

OK testing it more (now that I am much more awake :) ) neither AIKONF4 or AIKONF7 work but when I do the one that you have in your example it works fine.

~/Git/inav/src/utils$ ./bf2inav.py -i ~/Git/betaflight-config/configs/BETAFPVF405/config.h ../main/target/TEST69/ { "defines": { "FC_TARGET_MCU": "STM32F405", "BOARD_NAME": "BETAFPVF405", "MANUFACTURER_ID": "BEFH", "BEEPER_PIN": "PB4", "MOTOR1_PIN": "PB0", "MOTOR2_PIN": "PB1", "MOTOR3_PIN": "PA3", "MOTOR4_PIN": "PA2", "MOTOR5_PIN": "PC8", "MOTOR6_PIN": "PA8", "RX_PPM_PIN": "PB8", "SONAR_TRIGGER_PIN": "PC9", "SONAR_ECHO_PIN": "PA8", "LED_STRIP_PIN": "PB6", "UART1_TX_PIN": "PA9", "UART3_TX_PIN": "PB10", "UART4_TX_PIN": "PA0", "UART6_TX_PIN": "PC6", "UART1_RX_PIN": "PA10", "UART3_RX_PIN": "PB11", "UART4_RX_PIN": "PA1", "UART5_RX_PIN": "PD2", "UART6_RX_PIN": "PC7", "INVERTER_PIN_UART3": "PC9", "INVERTER_PIN_UART6": "PC8", "LED0_PIN": "PB5", "SPI1_SCK_PIN": "PA5", "SPI2_SCK_PIN": "PB13", "SPI3_SCK_PIN": "PC10", "SPI1_SDI_PIN": "PA6", "SPI2_SDI_PIN": "PB14", "SPI3_SDI_PIN": "PC11", "SPI1_SDO_PIN": "PA7", "SPI2_SDO_PIN": "PB15", "SPI3_SDO_PIN": "PC12", "ESCSERIAL_PIN": "PB8", "ADC_VBAT_PIN": "PC2", "ADC_RSSI_PIN": "PC0", "ADC_CURR_PIN": "PC1", "BARO_CS_PIN": "PB3", "SDCARD_SPI_CS_PIN": "PB12", "SDCARD_DETECT_PIN": "PB7", "FLASH_CS_PIN": "PB12", "MAX7456_SPI_CS_PIN": "PA15", "GYRO_1_EXTI_PIN": "PC4", "GYRO_1_CS_PIN": "PA4", "USB_DETECT_PIN": "PC5", "TIMER_PIN_MAPPING": "\\", "SPI2_TX_DMA_OPT": "0", "ADC2_DMA_OPT": "1", "MAG_I2C_INSTANCE": "(I2CDEV_2)", "BARO_SPI_INSTANCE": "SPI3", "DEFAULT_BARO_DEVICE": "BARO_NONE", "ADC_INSTANCE": "ADC2", "DEFAULT_BLACKBOX_DEVICE": "BLACKBOX_DEVICE_FLASH", "DEFAULT_DSHOT_BURST": "DSHOT_DMAR_ON", "DEFAULT_CURRENT_METER_SOURCE": "CURRENT_METER_ADC", "DEFAULT_VOLTAGE_METER_SOURCE": "VOLTAGE_METER_ADC", "SDCARD_SPI_INSTANCE": "SPI2", "SYSTEM_HSE_MHZ": "8", "MAX7456_SPI_INSTANCE": "SPI3", "DASHBOARD_I2C_INSTANCE": "(I2CDEV_2)", "FLASH_SPI_INSTANCE": "SPI2", "GYRO_1_SPI_INSTANCE": "SPI1", "GYRO_1_ALIGN": "CW270_DEG", "GYRO_1_ALIGN_YAW": "2700", "GYRO_2_SPI_INSTANCE": "SPI1" }, "empty_defines": [ "USE_ACC", "USE_ACC_SPI_MPU6000", "USE_GYRO", "USE_GYRO_SPI_MPU6000", "USE_GYRO_SPI_ICM42688P", "USE_ACC_SPI_ICM42688P", "USE_ACCGYRO_BMI270", "USE_BARO", "USE_BARO_SPI_BMP280", "USE_FLASH", "USE_FLASH_W25Q128FV", "USE_MAX7456", "USE_ADC", "BEEPER_INVERTED", "SDCARD_DETECT_INVERTED", "USE_SDCARD_SPI", "USE_SPI_GYRO" ], "features": [ "FEATURE_OSD", "FEATURE_TELEMETRY", "FEATURE_CURRENT_METER", "FEATURE_VBAT", "FEATURE_TX_PROF_SEL", "FEATURE_BLACKBOX" ], "pins": { "PB4": "BEEPER", "PB0": "MOTOR1", "PB1": "MOTOR2", "PA3": "MOTOR3", "PA2": "MOTOR4", "PC8": "MOTOR5", "PA8": "SONAR_ECHO", "PB8": "ESCSERIAL", "PC9": "SONAR_TRIGGER", "PB6": "LED_STRIP", "PA9": "UART1_TX", "PB10": "UART3_TX", "PA0": "UART4_TX", "PC6": "UART6_TX", "PA10": "UART1_RX", "PB11": "UART3_RX", "PA1": "UART4_RX", "PD2": "UART5_RX", "PC7": "UART6_RX", "PB5": "LED0", "PA5": "SPI1_SCK", "PB13": "SPI2_SCK", "PC10": "SPI3_SCK", "PA6": "SPI1_SDI", "PB14": "SPI2_SDI", "PC11": "SPI3_SDI", "PA7": "SPI1_SDO", "PB15": "SPI2_SDO", "PC12": "SPI3_SDO", "PC2": "ADC_VBAT", "PC0": "ADC_RSSI", "PC1": "ADC_CURR", "PB3": "BARO_CS", "PB12": "FLASH_CS", "PB7": "SDCARD_DETECT", "PA15": "MAX7456_SPI_CS", "PC4": "GYRO_1_EXTI", "PA4": "GYRO_1_CS", "PC5": "USB_DETECT" }, "funcs": { "BEEPER": "PB4", "MOTOR1": "PB0", "MOTOR2": "PB1", "MOTOR3": "PA3", "MOTOR4": "PA2", "MOTOR5": "PC8", "MOTOR6": "PA8", "RX_PPM": "PB8", "SONAR_TRIGGER": "PC9", "SONAR_ECHO": "PA8", "LED_STRIP": "PB6", "UART1_TX": "PA9", "UART3_TX": "PB10", "UART4_TX": "PA0", "UART6_TX": "PC6", "UART1_RX": "PA10", "UART3_RX": "PB11", "UART4_RX": "PA1", "UART5_RX": "PD2", "UART6_RX": "PC7", "LED0": "PB5", "SPI1_SCK": "PA5", "SPI2_SCK": "PB13", "SPI3_SCK": "PC10", "SPI1_SDI": "PA6", "SPI2_SDI": "PB14", "SPI3_SDI": "PC11", "SPI1_SDO": "PA7", "SPI2_SDO": "PB15", "SPI3_SDO": "PC12", "ESCSERIAL": "PB8", "ADC_VBAT": "PC2", "ADC_RSSI": "PC0", "ADC_CURR": "PC1", "BARO_CS": "PB3", "SDCARD_SPI_CS": "PB12", "SDCARD_DETECT": "PB7", "FLASH_CS": "PB12", "MAX7456_SPI_CS": "PA15", "GYRO_1_EXTI": "PC4", "GYRO_1_CS": "PA4", "USB_DETECT": "PC5" }, "timer_pin_map": { "0": { "i": "0", "p": "PB8", "o": "2", "d": "-1" }, "1": { "i": "1", "p": "PC8", "o": "2", "d": "-1" }, "2": { "i": "2", "p": "PB0", "o": "2", "d": "0" }, "3": { "i": "3", "p": "PB1", "o": "2", "d": "0" }, "4": { "i": "4", "p": "PA3", "o": "1", "d": "1" }, "5": { "i": "5", "p": "PA2", "o": "1", "d": "0" }, "6": { "i": "6", "p": "PB6", "o": "1", "d": "0" }, "7": { "i": "7", "p": "PA8", "o": "1", "d": "-1" }, "8": { "i": "8", "p": "PA9", "o": "1", "d": "0" } }, "mcu": { "type": "STM32F405" }, "board_name": "BETAFPVF405", "manufacturer_id": "BEFH" }

And doing a diff of the BETAFPVF405 vs AIKONF7 I see that as per the error message #define GYRO_1_ALIGN CW270_DEG is present in the BETAFPVF405 and absent in AIKONF7.

Looking at the gyro code (https://github.com/betaflight/betaflight/blob/master/src/main/pg/gyrodev.c#L62), it seems that the absence of the GYRO_1_ALIGN should not impact the validity of the config as there is a ifndef (if not defined) which sets it to CW0_DEG

Adding #define GYRO_1_ALIGN CW0_DEG to the ~/Git/betaflight-config/configs/AIKONF7/config.h fixes the issue so I reckon if you bang in a null check and just recreate the behavior of the gyrodev.c then it should be golden. Once I have a bit more time I will set up my multi rotor and give 'er a whirl to see if the generated config is valid or not :)

@mbainrot
Copy link

OK finally got it compiled and it worked OK. There was some minor gremlins.

It miscalculated? the number of serial ports for my target, not sure why but it said 4 serial ports when it should have said 5 (I think it didn't count the USB MCP), This caused UART_5 to be AWOL, was an easy fix thou.

GRYO_1_ALIGN gremlin as mentioned above.

File dropping was a bit buggy for me, running it the same way as I did in previous examples I had hit and miss behavior and it also dropped the target.c target.h and CMakeTarget.txt in the wrong directory (it dropped it into the PWD, which has to be src/utils otherwise it fails due to YAML error) instead of the third parameter directory. Not sure if that is a PEBKAC error on my part or bug in the code.

I have a ton of hardware testing to do which I am not sure if I am going to get time to do it before I go back to work. I also have a lot of other priorities (like getting my target contribution completed, tested and PR submitted before I go back to work so I have time to answer any questions & apply any feedback)

Overall the script is a beauty, definitely made my life getting to the point I am at waaaay easier. Nicely done mate :)

@mmosca
Copy link
Collaborator Author

mmosca commented Dec 29, 2023

@mbainrot Should be fixed now.

Thanks for testing it.

Let me know if this gets you in the air :)

@mbainrot
Copy link

@mbainrot Should be fixed now.

Thanks for testing it.

Let me know if this gets you in the air :)

Thanks @mmosca I manually fixed the issues so I could get a PR moving (PR# 9603). But will retest and diff to see.

There were problems in compilation with the baro which I had to fix too, I will reproduce them for you and also include the changes I did to get the baro bit to compile. In my late night post I forgot to mention those, sorry!

But will do let you know once I get airborne on iNAV, just have to work out motor mixes (I built my quad up on betaflight so I hardware configured it for QUAD-X 1234, but iNAV doesn't seem to support that config) and finish testing the peripherals.

The script was a huge help thou nonetheless, did all the hard stuff like figuring out the timers for me which was super helpful.

@mbainrot
Copy link

mbainrot commented Dec 29, 2023

Ok as promised here is the error I now get after generating the target, this is the baro related error that I forgot to talk about in my post last night 😅

In file included from /home/max/Git/inav/src/main/target/common_hardware.c:20:
/home/max/Git/inav/src/main/target/common_hardware.c:92:32: error: 'BARO_I2C_BUS' undeclared here (not in a function); did you mean 'BMP085_I2C_BUS'?
   92 |         #define BMP085_I2C_BUS BARO_I2C_BUS
      |                                ^~~~~~~~~~~~
/home/max/Git/inav/src/main/drivers/bus.h:260:23: note: in definition of macro 'BUSDEV_REGISTER_I2C_F'
  260 |             .i2cBus = _i2cBus,                                                                  \
      |                       ^~~~~~~
/home/max/Git/inav/src/main/target/common_hardware.c:94:5: note: in expansion of macro 'BUSDEV_REGISTER_I2C'
   94 |     BUSDEV_REGISTER_I2C(busdev_bmp085,      DEVHW_BMP085,       BMP085_I2C_BUS,     0x77,               NONE,           DEVFLAGS_NONE,      0);
      |     ^~~~~~~~~~~~~~~~~~~
/home/max/Git/inav/src/main/target/common_hardware.c:94:65: note: in expansion of macro 'BMP085_I2C_BUS'
   94 | BUSDEV_REGISTER_I2C(busdev_bmp085,      DEVHW_BMP085,       BMP085_I2C_BUS,     0x77,               NONE,           DEVFLAGS_NONE,      0);
      |                                                             ^~~~~~~~~~~~~~

make[3]: *** [src/main/target/AIKONF7/CMakeFiles/AIKONF7.elf.dir/build.make:1244: src/main/target/AIKONF7/CMakeFiles/AIKONF7.elf.dir/__/common_hardware.c.obj] Error 1
make[2]: *** [CMakeFiles/Makefile2:8598: src/main/target/AIKONF7/CMakeFiles/AIKONF7.elf.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:8631: src/main/target/AIKONF7/CMakeFiles/AIKONF7.dir/rule] Error 2
make: *** [Makefile:358: AIKONF7] Error 2

This is the code generated before me going in and tweaking with it

#define MPU6000_CS_PIN       PA4
#define MPU6000_SPI_BUS BUS_SPI1
#define IMU_MPU6000_ALIGN    CW0_DEG
// BARO
#define USE_BARO
#define USE_BARO_ALL
#define USE_BARO_SPI_BMP280
#define BMP280_SPI_BUS BUS_SPI3
#define BMP280_CS_PIN PB2
// OSD
#define USE_MAX7456
#define MAX7456_CS_PIN PB12

This is the code after

#define MPU6000_SPI_BUS BUS_SPI1
#define IMU_MPU6000_ALIGN    CW0_DEG
// BARO
#define USE_BARO
#define USE_BARO_BMP280
#define USE_BARO_SPI_BMP280
#define BMP280_SPI_BUS BUS_SPI3
#define BMP280_CS_PIN PB2
// OSD
#define USE_MAX7456
#define MAX7456_CS_PIN PB12

Doing some digging it's to do with the USE_BARO_ALL, when that is set it, well, adds all the baro which is cool. But when it goes to bang in BMP085_I2C_BUS that then sets off another ifdef in common_hardware.c

#if defined(USE_BARO_BMP085)
    #if !defined(BMP085_I2C_BUS)
        #define BMP085_I2C_BUS BARO_I2C_BUS
    #endif
    BUSDEV_REGISTER_I2C(busdev_bmp085,      DEVHW_BMP085,       BMP085_I2C_BUS,     0x77,               NONE,           DEVFLAGS_NONE,      0);
#endif

But we haven't set BARO_I2C_BUS because it's a SPI baro, not a i2c baro.

I am not sure of what the best fix would be for you, whether you can do some logic to only add the specific baro based on what it detects when it adds the USE_BARO_SPI_BMP280 or whether it's a wider bug that's outside the scope of this script.

The risk with the logic is it creates a massive rabbit hole for you to figure out the mapping for USE_BARO_SPI_BMP280 to USE_BARO_BMP280 which has to be maintained as new baros are added.

But nonetheless, hopefully this info helps 😄

edit: Forgot to add, the changes worked a treat! it still dumps the files in the present working directory but everything else works a treat

@mmosca
Copy link
Collaborator Author

mmosca commented Dec 30, 2023

Seems to be ok now.

Memory region         Used Size  Region Size  %age Used
        ITCM_RAM:        9176 B        16 KB     56.01%
      ITCM_FLASH:          0 GB        16 KB      0.00%
ITCM_FLASH_CONFIG:          0 GB        16 KB      0.00%
     ITCM_FLASH1:          0 GB       480 KB      0.00%
           FLASH:         584 B        16 KB      3.56%
    FLASH_CONFIG:          0 GB        16 KB      0.00%
          FLASH1:      441371 B       480 KB     89.80%
             TCM:       18228 B        64 KB     27.81%
             RAM:       83800 B       192 KB     42.62%
       MEMORY_B1:          0 GB         0 GB
Built target AIKONF7.elf
Built target AIKONF7

@mbainrot
Copy link

Yup works a treat for me, thanks!

Building C object src/main/target/AIKONF7/CMakeFiles/AIKONF7.elf.dir/__/__/telemetry/telemetry.c.obj
Linking C executable ../../../../bin/AIKONF7.elf
Memory region         Used Size  Region Size  %age Used
        ITCM_RAM:        9176 B        16 KB     56.01%
      ITCM_FLASH:          0 GB        16 KB      0.00%
ITCM_FLASH_CONFIG:          0 GB        16 KB      0.00%
     ITCM_FLASH1:          0 GB       480 KB      0.00%
           FLASH:         584 B        16 KB      3.56%
    FLASH_CONFIG:          0 GB        16 KB      0.00%
          FLASH1:      441371 B       480 KB     89.80%
             TCM:       18228 B        64 KB     27.81%
             RAM:       83800 B       192 KB     42.62%
       MEMORY_B1:          0 GB         0 GB
Built target AIKONF7.elf
Built target AIKONF7
max@max-framework:~/Git/inav/build$ 

@sensei-hacker
Copy link
Collaborator

I did some testing on this as well, and added a couple things. I note it doesn't change anything in the INAV code and so can't break anything, as I mash the merge button.

@sensei-hacker sensei-hacker merged commit 7c0fe51 into master Nov 16, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants