Skip to content

Instantly share code, notes, and snippets.

@wlgrd
Last active January 27, 2024 22:23
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save wlgrd/17b3f8626fe3bff29a4bcad2622f2177 to your computer and use it in GitHub Desktop.
Save wlgrd/17b3f8626fe3bff29a4bcad2622f2177 to your computer and use it in GitHub Desktop.
How to set up betaflight fc with Ubuntu
1. Create a rule for the DFU
$ (echo '# DFU (Internal bootloader for STM32 MCUs)' echo 'ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE="0664", GROUP="plugdev"') | sudo tee /etc/udev/rules.d/45-stdfu-permissions.rules > /dev/null
2. Monitor connection and find your model (unplug/plug the fc while this cmd is active)
$ udevadm monitor --environment --udev | grep ID_MODEL_ID
3. Update the /etc/udev/rules.d/45-stdfu-permissions.rules file with your model. E.g, my MODEL_ID is 5740, and the .rules file
ends up like this:
# DFU (Internal bootloader for STM32 MCUs)
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE="0664", GROUP="plugdev"
# ix5
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", MODE="0664", GROUP="plugdev"
4. Now reload rules
$ sudo udevadm control --reload-rules && udevadm trigger
5. You can then test the rule using when your FC is plugged in:
$ udevadm test $(udevadm info -q path -n /dev/ttyACM0)
Ensure line "MODE 0664 /etc/udev/rules.d/45-stdfu-permissions.rules" is present
6. Now check the group at which the device belongs to
You can then test the rule using when your FC is plugged in:
$ ls -lah /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 mars 17 21:57 /dev/ttyACM0
Here it is in dialout, obviosuly thinking it is a modem.
7. Stop the modem service
$ sudo systemctl stop ModemManager.service
8. Add yourself to the group plugdev and dialout (don't know which one is the "correct one")
$ sudo usermod -G plugdev -a <username>
$ sudo usermod -G dialout -a <username>
9. I had to reboot for this to work.
@dagitibi
Copy link

Dear Smarter guys then i am! I am a big fan of fpv and ive built 22 racing quads so far...and i cant stop! I recently had enough of windows and ive changed to ubuntu which im loving big time. i wish i understood it better or have the time to figure it out and learn but i have to work and make living. ive tried to install and use my beloved Betaflight but i cant connect trough usb. Im sure it might be an easy fix for most of you guys but ive tried to follow this instruction above but ive failed to be successful. Please hel me out by sending ll the code line by line i have to put in to get this working. I really appreciate your help in advance
many thanks
dagitibi

@AndreiGavrilescu
Copy link

@dagitibi you need to set your own product id in "ATTRS{idProduct}=="df11"
You can find out your particular attributes by typing "lsusb" in the terminal and you get something like this

Controller
Bus 001 Device 003: ID 8087:07da Intel Corp. 
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 024: ID 0483:5740 STMicroelectronics STM32F407
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The line "Bus 003 Device 024: ID 0483:5740 STMicroelectronics STM32F407" indicates in the ID field that the manufacturer attribure is "0483" and the product id is "5740" for my particular device. That means that I need to set idProduct = 5740.

@jobot1984
Copy link

Thanks, this worked for me on 14.04. But the pathway I had to use from step 5 was dev/ttyUSB0

@Jugsy
Copy link

Jugsy commented Apr 13, 2018

Worked for 16.04, thanks! I couldn't see the line "MODE 0664 /etc/udev/rules.d/45-stdfu-permissions.rules" but with no idea how to troubleshoot I proceeded anyway and everything is working fine. Legend.

@xvovx
Copy link

xvovx commented May 1, 2018

So this has helped me be able to finally connect and edit settings on my FC, however I am having issues with DFU for some reason and any help would be wonderful.

I am using Ubuntu 16.04 and the issue is happening with multiple different FCs so the boards are not the issue.

When I connect the board without holding down the boot button everything connects just fine and the boards are recognized under /dev/ttyACM0. However, when I hold down the boot button and connect Betaflight recognizes the board has having connected in DFU mode but whenever I try to flash a newer version of Betaflight to the board I receive the error message "Failed to open USB Device! Are udev rules installed correctly?"

This is after following the above instructions to a T.

@Zappelphilipp
Copy link

Zappelphilipp commented Sep 5, 2018

thank you for the procedure, i am using linux since the beginning but i still have one problem i cant solve: i just cannot flash. I am able to configure betaflight via the configurator but no flashing. when i start to flash the board just beeps and the configurator does not show any loading bar.

udevadm monitor --environment --udev | grep ID_MODEL_ID
shows me 5740 so i added the line as mentioned above.

testing the rule with
udevadm test $(udevadm info -q path -n /dev/ttyACM0)
doesnt show me the line "MODE 0664..."

ls -lah /dev/ttyACM0
shows me that it uses the dialout group which i added my user to.

Still not working :(
i am using the newest version of deepinOS (which is based on debian)

@ChrisKiggins
Copy link

I believe there is a permissions issue that is not getting resolved with either the 'official' instruction set or the above posted steps.

I have spent a surprisingly long time on this seemingly simple instruction set trying to flash a board from cleanflight to betaflight.

I was about to post one of my longer typed tirades when I gave up, got a drink, came back and tried again as 'root'. Worked like a champ.

I do not know as of this time what exactly happened to make it work, but after executing all of the recommended commands and tests (repeatedly) as a user, I got to the point where the board was recognized by betaflight as a valid target, and where betaflight recognized the board as a DFU target when I plugged it in with a shorted bootpad- but attempts to flash were greeted with "Failed to open USB Device! Are udev rules installed correctly?" (a helpful reminder the first three times, and then gradually more infuriating every time thereafter....).

Logging in as root fixed it- I plugged it in with a shorted bootpad, and sure enough it fired up and flashed.

I am currently running 2018.3a Kali XFCE 64 bit.

I hope this helps the other folks struggling here, and I really hope someone better at this than me can come along and correct / complete the instruction set so we can flash boards from a non-root user.

@Zappelphilipp
Copy link

yeah, seems like a permission issue. cannot find whats the problem though. using root works, thanks. its a dirty hack but the best solution until now...

@wlgrd
Copy link
Author

wlgrd commented Oct 3, 2019

Oh, there is actually activity here? Sorry for not responding, rarely look at my gists :P
I just wrote this gist to send it to a friend. Really happy to see others have put the information to good use as well.
Did you find a solution @Zappelphilipp ?

@as3k
Copy link

as3k commented Sep 7, 2020

Thank you so much!

@wlgrd
Copy link
Author

wlgrd commented Sep 7, 2020

Thank you so much!

Happy that this still helps people!

@mcelhennyi
Copy link

Beautiful, THANKS!

@nicorellius
Copy link

As usual, each flavor and version of Ubuntu behaves differently (I'm still on 18.04). I messed around with this for a while, never seeing the MODE 0664 thing from the test... (for number 5 test):

MODE 0664 /etc/udev/rules.d/45-stdfu-permissions.rules

So I tried the hint from jobot1984 commented on Jan 21, 2018 and then unplugged/plugged in, rebooted BetaFlight, and my drone was recognized: ProTek25 (with XM+ receiver).

Thanks everyone!

@durfu
Copy link

durfu commented Apr 30, 2021

Just sending a big TANK YOU for this guide. Worked perfectly for me (I even had the same vendor and model ids :) )

@TioMoises
Copy link

Just a side note that might be helpful to some.

In Arch based distributions like Manjaro there is no "plugdev" group. When creating the udev rule the permissions need to be given to those in the uucp group, the file should contain thiese two modified lines instead:

# DFU (Internal bootloader for STM32 MCUs)
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE="0664", GROUP="uucp"

As you can see the only thing that changed was plugdev to uucp.

You will also need to add your user to the uucp group, that can be done with the following command:
sudo usermod -aG uucp

Hope this helps someone out.

@Maikpwwq
Copy link

Works for me in Ubuntu 20.04. Then of connect my TinyGo, I set the necessary permissions using command (sudo chmod +666 /dev/ttyACM0), I made a consult (lsusb) to corroborate necessary idVendor and idProduct. It works for me when I don't use mi idProduct, ie ID_MODEL_ID=5740, instead I use the default ATTRS{idProduct}=="df11", set the mode to MODE="0666", and reload the rules. After add my user to both groups plugdev and dialout, finally I can install successful my new firmware Betaflight / STM32F411 (S411) 4.3.0 Jun 14 2022.

@NightCrack
Copy link

Ubuntu 22.04.2 LTS

Firstly, for Betaflight Configurator to actually work with flight controllers, current user was added to "dialout" group:

sudo usermod -aG dialout $USER ($USER - system variable that contains the current user login);

Then, created low-priority rule for STM32 devices:

(echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ACTION=="add", MODE="0664", GROUP="dialout"') | sudo tee /etc/udev/rules.d/80-local.rules

Then - reloaded udev rules:

sudo udevadm control --reload

That solved the problem for me.
Much appreciated the authors effort; used
https://betaflight.com/docs/wiki/archive/DFU-Hijacking#note and
https://opensource.com/article/18/11/udev resources to get things worked.

@BatonExt
Copy link

Dear NightCrack thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment