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.
@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