Adding GPS back to Cleanflight for F3 flight controllers 🚁

vs code adding gps to cleanflight
Share:

About

Some time ago I bought a NAZE32 F3 flight controller for less than 10$ thinking I could use it for a cheap quadcopter build. But when I tried configuring the GPS it didn’t work. At first, I thought I did something wrong or there was a bug, but as it turns out the GPS feature was removed for F3 flight controllers. The frustrating thing is that this isn’t mentioned anywhere. As a result, I spent hours trying to figure out what the problem was until I found out that the feature was removed. Anyway, the solution is to manualy add in the GPS feature yourself and compile your own version of the firmware.

What we will be doing

In this post, we’ll take a look at how to add/remove features from Cleanflight/Beatflight. In this instance, I will be adding the GPS feature back and remove some of the other features to free up enough resources for the GPS. Using the same process you can add/remove any features you want.

Prerequsites

Before we get started I will assume that you already have the development environment set up and know how to compile the firmware. If you don’t you can check out this tutorial on how to compile the firmware and this tutorial on how to set up Ubuntu on Windows.

Hardware used

How to do it

If you followed my tutorial on compiling the firmware your Cleanfilght folder is in Ubuntu. If you want you can keep it there and edit the files using the command line with an editor like nano or vim.
I will first move the Cleanflight folder from Linux to Windows so I can more easily edit the code. Also, you can just download the source code from Github and then unzip the files to your desktop.
Using the mv command to move the folder to the Windows desktop.
  1. mv -r /home/DTPCLX/cleanflight/ /mnt/c/Users/DTPC/Desktop/
Now that the cleanflight folder is on the desktop, let’s navigate to src\main\target and open up the common_fc_pre.h file in a text editor.
In this file, we can define which features get used. In the following code, you can see that some features will only be available if your controller has more than a specified amount of memory. For example, the GPS feature that I am interested in is only available for the controllers with more than 256 KB of memory. But my F3 controller only has 128KB of memory. So I ‘ll have to move the #define USE_GPS line of code from this if statement #if (FLASH_SIZE > 256) to this if statement #if (FLASH_SIZE > 128).

Before:

  1. #if (FLASH_SIZE > 128)
  2. #define USE_CAMERA_CONTROL
  3. #define USE_CMS
  4. #define USE_EXTENDED_CMS_MENUS
  5. #define USE_DSHOT_DMAR
  6. #define USE_GYRO_OVERFLOW_CHECK
  7. #define USE_YAW_SPIN_RECOVERY
  8. #define USE_HUFFMAN
  9. #define USE_MSP_DISPLAYPORT
  10. #define USE_MSP_OVER_TELEMETRY
  11. #define USE_PINIO
  12. #define USE_PINIOBOX
  13. #define USE_RCDEVICE
  14. #define USE_RTC_TIME
  15. #define USE_RX_MSP
  16. #define USE_SERIALRX_FPORT // FrSky FPort
  17. #define USE_TELEMETRY_CRSF
  18. #define USE_TELEMETRY_SRXL
  19. #define USE_VIRTUAL_CURRENT_METER
  20. #define USE_OSD_ITEM_POSITIONS
  21. #define USE_VTX_COMMON
  22. #define USE_VTX_CONTROL
  23. #define USE_VTX_SMARTAUDIO
  24. #define USE_VTX_TRAMP
  25. #define USE_GYRO_LPF2
  26. #define USE_ESC_SENSOR
  27. #define USE_ESC_SENSOR_INFO
  28. #define USE_CRSF_CMS_TELEMETRY
  29. #define USE_BOARD_INFO
  30. #define USE_SMART_FEEDFORWARD
  31. #define USE_THROTTLE_BOOST
  32. #define USE_RC_SMOOTHING_FILTER
  33. #define USE_ITERM_RELAX
  34.  
  35. #ifdef USE_SERIALRX_SPEKTRUM
  36. #define USE_SPEKTRUM_BIND
  37. #define USE_SPEKTRUM_BIND_PLUG
  38. #define USE_SPEKTRUM_REAL_RSSI
  39. #define USE_SPEKTRUM_FAKE_RSSI
  40. #define USE_SPEKTRUM_RSSI_PERCENT_CONVERSION
  41. #define USE_SPEKTRUM_VTX_CONTROL
  42. #define USE_SPEKTRUM_VTX_TELEMETRY
  43. #define USE_SPEKTRUM_CMS_TELEMETRY
  44. #endif
  45. #endif
  46.  
  47. #if (FLASH_SIZE > 256)
  48. #define USE_DASHBOARD
  49. #define USE_GPS
  50. #define USE_GPS_NMEA
  51. #define USE_GPS_UBLOX
  52. #define USE_GPS_RESCUE
  53. #define USE_OSD
  54. #define USE_OSD_OVER_MSP_DISPLAYPORT
  55. #define USE_OSD_ADJUSTMENTS
  56. #define USE_SENSOR_NAMES
  57. #define USE_SERIALRX_JETIEXBUS
  58. #define USE_TELEMETRY_IBUS
  59. #define USE_TELEMETRY_IBUS_EXTENDED
  60. #define USE_TELEMETRY_JETIEXBUS
  61. #define USE_TELEMETRY_MAVLINK
  62. #define USE_UNCOMMON_MIXERS
  63. #define USE_SIGNATURE
  64. #define USE_ABSOLUTE_CONTROL
  65. #endif
  66.  
  67. #define USE_RCSPLIT

After:

  1. #if (FLASH_SIZE > 128)
  2. #define USE_CAMERA_CONTROL
  3. #define USE_CMS
  4. #define USE_EXTENDED_CMS_MENUS
  5. #define USE_DSHOT_DMAR
  6. #define USE_GYRO_OVERFLOW_CHECK
  7. #define USE_YAW_SPIN_RECOVERY
  8. #define USE_HUFFMAN
  9. #define USE_MSP_DISPLAYPORT
  10. #define USE_MSP_OVER_TELEMETRY
  11. #define USE_PINIO
  12. #define USE_PINIOBOX
  13. #define USE_RCDEVICE
  14. #define USE_RTC_TIME
  15. #define USE_RX_MSP
  16. #define USE_SERIALRX_FPORT // FrSky FPort
  17. #define USE_TELEMETRY_CRSF
  18. #define USE_TELEMETRY_SRXL
  19. #define USE_VIRTUAL_CURRENT_METER
  20. #define USE_OSD_ITEM_POSITIONS
  21. #define USE_VTX_COMMON
  22. #define USE_VTX_CONTROL
  23. #define USE_VTX_SMARTAUDIO
  24. #define USE_VTX_TRAMP
  25. #define USE_GYRO_LPF2
  26. #define USE_ESC_SENSOR
  27. #define USE_ESC_SENSOR_INFO
  28. #define USE_CRSF_CMS_TELEMETRY
  29. #define USE_BOARD_INFO
  30. #define USE_SMART_FEEDFORWARD
  31. #define USE_THROTTLE_BOOST
  32. #define USE_RC_SMOOTHING_FILTER
  33. #define USE_ITERM_RELAX
  34.  
  35. #define USE_GPS
  36. #define USE_GPS_NMEA
  37. #define USE_GPS_UBLOX
  38. #define USE_GPS_RESCUE
  39.  
  40. #ifdef USE_SERIALRX_SPEKTRUM
  41. #define USE_SPEKTRUM_BIND
  42. #define USE_SPEKTRUM_BIND_PLUG
  43. #define USE_SPEKTRUM_REAL_RSSI
  44. #define USE_SPEKTRUM_FAKE_RSSI
  45. #define USE_SPEKTRUM_RSSI_PERCENT_CONVERSION
  46. #define USE_SPEKTRUM_VTX_CONTROL
  47. #define USE_SPEKTRUM_VTX_TELEMETRY
  48. #define USE_SPEKTRUM_CMS_TELEMETRY
  49. #endif
  50. #endif
  51.  
  52. #if (FLASH_SIZE > 256)
  53. #define USE_DASHBOARD
  54.  
  55. #define USE_OSD
  56. #define USE_OSD_OVER_MSP_DISPLAYPORT
  57. #define USE_OSD_ADJUSTMENTS
  58. #define USE_SENSOR_NAMES
  59. #define USE_SERIALRX_JETIEXBUS
  60. #define USE_TELEMETRY_IBUS
  61. #define USE_TELEMETRY_IBUS_EXTENDED
  62. #define USE_TELEMETRY_JETIEXBUS
  63. #define USE_TELEMETRY_MAVLINK
  64. #define USE_UNCOMMON_MIXERS
  65. #define USE_SIGNATURE
  66. #define USE_ABSOLUTE_CONTROL
  67. #endif
  68.  
  69. #define USE_RCSPLIT
Now we have the problem of not having enough memory. To fix this we will just remove some unneeded features.
You can set all the features that you don’t use to #undef. I use the Frsky receiver so everything except  USE_SERIALRX_SBUS  can be set to  #undef.
  1. #define USE_BRUSHED_ESC_AUTODETECT // Detect if brushed motors are connected and set defaults appropriately to avoid motors spinning on boot
  2. #define USE_CLI
  3. #define USE_GYRO_REGISTER_DUMP // Adds gyroregisters command to cli to dump configured register values
  4. #define USE_PPM
  5. #define USE_PWM
  6. #define USE_SERIAL_RX
  7. #define USE_SERIALRX_CRSF // Team Black Sheep Crossfire protocol
  8. #define USE_SERIALRX_IBUS // FlySky and Turnigy receivers
  9. #define USE_SERIALRX_SBUS // Frsky and Futaba receivers
  10. #define USE_SERIALRX_SPEKTRUM // SRXL, DSM2 and DSMX protocol
  11. #define USE_SERIALRX_SUMD // Graupner Hott protocol
  12. #define USE_SERIALRX_SUMH // Graupner legacy protocol
  13. #define USE_SERIALRX_XBUS // JR
Code after removing unused features.
  1. #define USE_BRUSHED_ESC_AUTODETECT // Detect if brushed motors are connected and set defaults appropriately to avoid motors spinning on boot
  2. #define USE_CLI
  3. #define USE_GYRO_REGISTER_DUMP // Adds gyroregisters command to cli to dump configured register values
  4. #define USE_PPM
  5. #define USE_PWM
  6. #define USE_SERIAL_RX
  7. #undefine USE_SERIALRX_CRSF // Team Black Sheep Crossfire protocol
  8. #undefine USE_SERIALRX_IBUS // FlySky and Turnigy receivers
  9. #define USE_SERIALRX_SBUS // Frsky and Futaba receivers
  10. #undefine USE_SERIALRX_SPEKTRUM // SRXL, DSM2 and DSMX protocol
  11. #undefine USE_SERIALRX_SUMD // Graupner Hott protocol
  12. #undefine USE_SERIALRX_SUMH // Graupner legacy protocol
  13. #undefine USE_SERIALRX_XBUS // JR
You can keep going through the code removing things that you don’t need(in my case that was not necessary.). If you don’t know what a particular line of code does google it. And if you still don’t know what it does then leave it alone. After you are done compile the firmware.
Open up the Ubuntu terminal, navigate to the Cleanflight folder and compile.
  1. cd /mnt/c/Users/DTPC/Desktop/cleanflight/
  2. make TARGET=NAZE

Firmware after adding/removing features.

Original firmware without modifications.

As you can see the modified firmware now uses fewer resources than the original one so we are all good(You must make sure that all the numbers are the same or lower than in the original firmware).
And this is it. You can find your .hex file in Cleanflight\obj. All that’s left to do now is to flash the firmware.
Share:

Comments

  1. Hi! Because of your awesome instructions here on this blog I was able to successfully make it work to have Cleanflight with GPS for SPF3 Deluxe. Thank you very much for your effort invested into these articles and thank you for keeping them online! Best regards, Jo

  2. Thanks for the heads up, Interesting thing though, most of the F103 chips actually have 128KB flash and make TARGET=CC3D still works on the current source, removing the unused RX stuff produces a HEX that uses 99.something% of 128KB so it’d fit but would need to be flashed with STLink I think?

    I’m kinda almost tempted to try and fly it but I’m a n00b quad pilot (Starting out with a really cheap 450 frame, motors etc. to get some experience, seriously impressed with the value from the FlySky TX/iA6B combo) and it’s proving hard enough to get a grip on flying with the stock LibrePilot/CC3D stuff before I star throwing randoms like a modded version of Clean/Betaflight in there.

    Wondering if you think there’s significant advantage to buying a couple of F4 controllers as they’re not much more expensive than the CC3Ds I have or if it’s worth jumping straight to F7?

    1. Hi, you should be able to flash your flight controller through the Betaflight/Cleanflight software on your PC. You can load your .hex file by clicking the “Load Firmware[local]” button. See the last part of this post I made: https://eecs.blog/compiling-betaflight-cleanflight-firmware-for-your-multirotor/

      You can mod the firmware to include the GPS but keep in mind that if you ever want to update the firmware to the latest version you will always have go through this process of compiling your custom version. If GPS is an important feature to you I suggest you take a look at INav which is a Cleanflight clone with GPS in mind.

      I would say that flight controllers like F1s, F2s, and F3s can still be used you just have to make a choice: Do you want a racing oriented quadcopter or not. If so use Beat/Cleanflight if you want GPS use INav. If you want both then consider F4s and F7s.

      I don’t know how much difference there is between an F4 and F7 as I currently only own a quad with an F4. But I would recommend getting at least an F4 flight controller as the F3s are kind of outdated.

  3. Hello Tsla

    Great tutorial Congratulations. I will try to ask for help to do it, because it exceeds my knowledge.
    I would like to use an old FC Flip32 + F1 (naze 32 6dof F1) with GPS and PPM Receiver, as a flight controller in a flying wing
    with Cleanflight. I try to navigate waypoints, RTH, hold, etc
    Would you be so kind to compile a trial version for me, I thank you in advance

    regards
    Thanks a lot
    Sergio
    my FC is flip32 + F1 https://www.dronetrest.com/t/flip-32-naze-32-flight-controller-guide/634

    1. I don’t think this would be possible for F1 flight controllers as they don’t have enough memory. I would recommend you to look at INav which is a “clone” of Celanflight but with GPS navigation in mind. All INav versions have GPS as that is the main focus of INav.

      INav: https://github.com/iNavFlight/inav/wiki

  4. Hi Tsla,
    I spent 3 hours today trying to get this to work. I did all the prerequisites which was a true learning expierence and I was able to successfully get to the last step and got an error when trying “navigate to the cleanflight folder and compile”.
    I don’t know what went wrong but if you could assist or create the file for me It would be greatley appreciated.
    I am running a Naze32 on PWM with Turnigy.
    Thanks!

      1. Whatever I try, I cannot get cleanflight to connect to the board after flashing that file. I believe it may be because of how new v2.5. Could you do v2.2 instead? Maybe its something entirely different? Thank you for your help so far!

  5. That is too bad I was really hoping for this. Thanks a lot for trying for me. I do really appreciate it and I like how the quad community tries to help each other.

  6. Can you compile a GPS version for the SPRACINGF3. With PWM connection. I tried but GPS won’t enable. Can you post it here?

      1. hello, i have a cuestion, i have flashed my card with your firmware, now i can enable the gps but now, the gps doesn´t apears enabled in cleanflight, also in te gps notch, the gps doesnt seems to be working or capting gps signal, i´ve done all i have to do to enable it, go to uart2, gps, then configurations and enable the gps notch.

        y use the ublox op gps

      2. Thank you updating the firmware. When I install this firmware I can enable the GPS, however, once the GPS is enabled my FRSKY X9D Plus stops working; I can only use switches but joysticks stops working all together. I’m using PWM RX Input (one wire per channel). Also, I noticed when the GPS is enabled the icon on the cleanflight doesn’t appear as Green though. Can you please provide some assistance?

        1. Hi. Did you upload the firmware from the link I posted above? If so what flight controller are you using?

  7. i have this exact same FC and cant get gps to work, I am also unable to follow this guide very well, is there anyway you can send me the file and instructions how to flash without all the editing and coding you did please?

    1. To add in the GPS feature we first have to remove some other features to make enough “space”. In my case, I disabled the support for all the receivers except for the Fr Sky which I use. If you tell me what receiver/protocol (PPM, CPPM, SBUS, …) you are using I can leave that one in and disable all the others. This now leaves us with enough space for the GPS. I could then compile the firmware and send you the file which you have to flash(upload) to your flight controller. See how to do that at end of this post:

      https://eecs.blog/compiling-betaflight-cleanflight-firmware-for-your-multirotor/

      Open Cleanflight => connect to the board => click “Load Firmware[Local]” => select the firmware file => click the “Flash Firmware” button.

      1. Hi, got same GPS problems:)
        Awesome help! – done everything… but have no idea what to undefine – using simple FS-R6B connection by PPM -> SPRACINGF3 V1:)

            1. Hi Tsla
              I saw this post today and I am trying to load a GPS version of firmware to my F3 board. I do not know how to code and is there a file to just flash the firmware to my existing board that eliminates the unneeded things and makes room for the new firmware. I use crossfire so i am not sure if that matters.

              If you already have a file that I could just upload that would be awesome.
              thanks

              1. For the connection between your flight controller and receiver do you use PPM, CPPM or the actual crossfire protocol?

                    1. Sorry but I am having trouble compiling the betaflight firmware. I was only able to do it for cleanflight.

                1. That is too bad I was really hoping for this. Thanks a lot for trying for me. I do really appreciate it and I like how the quad community tries to help each other.

Leave a Reply

Your email address will not be published. Required fields are marked *

The following GDPR rules must be read and accepted:
This form collects your name, email and content so that we can keep track of the comments placed on the website. For more info check our privacy policy where you will get more info on where, how and why we store your data.

Advertisment ad adsense adlogger