Firmware development in Windows

Firmware/software/electronics/mechanics
matejkarasek
Beginner
Posts: 21
Joined: Tue Jul 09, 2019 11:50 am

Firmware development in Windows

Post by matejkarasek »

Hi everyone,

As a newbie to the Bitcraze community, I am setting things up for firmware development...
What is the best option for firmware development (preferably natively) on Windows 10 (and/or 7)?

I found some options on the bitcraze&github wikis but have been told the info might be outdated...
https://github.com/bitcraze/crazyflie-firmware
https://wiki.bitcraze.io/doc:crazyflie:dev:env:windows

Combining these two tutorials I could get the make running via Cygwin, but the build is very slow (and I am getting some build errors when building for the Roadrunner board, CF2 builds fine).

Is there anyone with some recent experience?
Thanks!

Matej
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: Firmware development in Windows

Post by kimberly »

Tricky and valid question :)

@theseankelly ? you work a lot with windows native install development? Could you help Matej out with this?
matejkarasek
Beginner
Posts: 21
Joined: Tue Jul 09, 2019 11:50 am

Re: Firmware development in Windows

Post by matejkarasek »

Just an update:

Following the Cygwin path, I am now able to make and generate the .bin, .hex and .elf files.

make cload gives me the following error after "Restart the Crazyflie you want to bootload in the next 10 seconds ...":
Exception: Cannot find a Crazyradio Dongle
Cannot find a Crazyradio Dongle

Can the Crazyradio dongle be accessed from Cygwin? (the Windows app and the VM can access it, I use the libusb0 driver)
Or is there another way how to flash the firmware if I already have the bin, hex and elf files?

Thanks for any advice...
Matej


PS:
To get this working, I have installed Cygwin with the following packages:
Image

Further, I have cloned and installed:
crazyflie-firmware
crazyflie-lib-python
crazyflie-clients-python
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: Firmware development in Windows

Post by kimberly »

Hi Matej,

I've started to look into it as well. I was at the same phase as you are right now, and indeed, it could not find the crazyradio.

The next step was to install libusb through Cygwin. Now I get the following error with

Code: Select all

 make cload
:
python3 -m cfloader flash cf2.bin stm32-fw
Restart the Crazyflie you want to bootload in the next
10 seconds ...
Traceback (most recent call last):
File "/cygdrive/c/Users/Kimberly/Documents/github_repos/crazyflie-clients-python/src/cfloader/__init__.py", line 150, in main
if bl.start_bootloader(warm_boot=False):
File "/cygdrive/c/Users/Kimberly/Documents/github_repos/crazyflie-lib-python/cflib/bootloader/__init__.py", line 93, in start_bootloader
uri = self._cload.scan_for_bootloader()
File "/cygdrive/c/Users/Kimberly/Documents/github_repos/crazyflie-lib-python/cflib/bootloader/cloader.py", line 83, in scan_for_bootloader
link = cflib.crtp.get_link_driver('radio://0')
File "/cygdrive/c/Users/Kimberly/Documents/github_repos/crazyflie-lib-python/cflib/crtp/__init__.py", line 91, in get_link_driver
instance.connect(uri, link_quality_callback, link_error_callback)
File "/cygdrive/c/Users/Kimberly/Documents/github_repos/crazyflie-lib-python/cflib/crtp/radiodriver.py", line 163, in connect
address)
File "/cygdrive/c/Users/Kimberly/Documents/github_repos/crazyflie-lib-python/cflib/crtp/radiodriver.py", line 102, in __init__
_RadioManager._radios[self._devid] = _SharedRadio(self._devid)
File "/cygdrive/c/Users/Kimberly/Documents/github_repos/crazyflie-lib-python/cflib/crtp/radiodriver.py", line 71, in __init__
self.radio = Crazyradio(devid=devid)
File "/cygdrive/c/Users/Kimberly/Documents/github_repos/crazyflie-lib-python/cflib/drivers/crazyradio.py", line 157, in __init__
self.set_data_rate(self.DR_2MPS)
File "/cygdrive/c/Users/Kimberly/Documents/github_repos/crazyflie-lib-python/cflib/drivers/crazyradio.py", line 203, in set_data_rate
_send_vendor_setup(self.handle, SET_DATA_RATE, datarate, 0, ())
File "/cygdrive/c/Users/Kimberly/Documents/github_repos/crazyflie-lib-python/cflib/drivers/crazyradio.py", line 316, in _send_vendor_setup
wIndex=index, timeout=1000, data_or_wLength=data)
File "/usr/lib/python3.6/site-packages/usb/core.py", line 1043, in ctrl_transfer
self.__get_timeout(timeout))
File "/usr/lib/python3.6/site-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
timeout))
File "/usr/lib/python3.6/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 5] Input/Output Error
[Errno 5] Input/Output Error
So to be continued...
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: Firmware development in Windows

Post by kimberly »

I've moved this thread to developer discussions btw :)
theseankelly
Expert
Posts: 153
Joined: Mon Dec 28, 2015 3:23 pm
Contact:

Re: Firmware development in Windows

Post by theseankelly »

Hey -- apologies for missing this; private message email notifications were turned off on my account :(

Anyway, I'll write up proper instructions in the next week or two, but here's the short of it for my latest workflow on Windows:

Compiling: I use the Ubuntu flavor of WSL exclusively, with the same arm toolchain you use on the VM. WSL has matured quite a bit over the last couple of years, and I see no value in keeping Cygwin around anymore.

Flashing: WSL doesn't support libusb devices, unfortunately. However, you *can* run windows processes from inside WSL! You simply need to install openocd in windows, add it to the path, and then create a symlink called 'openocd' pointing to 'openocd.exe'. Then, 'make flash' in the Ubuntu WSL works as expected.

Debugging: Lately I use VS Code with some manual setup to GDB/OpenOCD -- I'll need to write up instructions on this but it's pretty straightforward once you figure out how to configure VS Code's gdb targets.

Working with cflib (python): I use Anaconda on Windows and do it all natively.
http://www.thejumperwire.com
Tips, tutorials, and science about DIY electronics, drones, and embedded software.
theseankelly
Expert
Posts: 153
Joined: Mon Dec 28, 2015 3:23 pm
Contact:

Re: Firmware development in Windows

Post by theseankelly »

Also, I don't have a great solution to 'make cload'. I either use the debugger (from the WSL terminal as described) or I keep a second windows/python prompt open and use cfloader directly to upload via the radio. Maybe I'll look into a better way...but at the end of the day, until WSL supports libusb communication, there's no great way to bridge between the two.
http://www.thejumperwire.com
Tips, tutorials, and science about DIY electronics, drones, and embedded software.
matejkarasek
Beginner
Posts: 21
Joined: Tue Jul 09, 2019 11:50 am

Re: Firmware development in Windows

Post by matejkarasek »

Hey,
Thanks a lot for sharing your workflow theseankelly! (my notifications were also not set-up correctly...)

I will try it out in the coming days and come back here should I get stuck somewhere. Great to hear this now works fine from the Ubuntu WSL!

Of course, if you managed to write up a tutorial that would be greatly appreciated, could test it and update if needed.
matejkarasek
Beginner
Posts: 21
Joined: Tue Jul 09, 2019 11:50 am

Re: Firmware development in Windows

Post by matejkarasek »

Ok, an update from me...

I followed the WSL path as suggested by @theseankelly and am almost there, but flashing (over Crazyradio PA) still does not work... Haven't tried the debugger yet.

These were my steps:

In Windows:
- Install Ubuntu WSL
- Install python and set path
- Install pip
- Install git for windows
- For convenience, I created symlink to my WSL Ubuntu home folder

In Ubuntu:
- Install git, make, python
- Install Arm toolchain, Ubuntu 16.04+
https://github.com/bitcraze/crazyflie-f ... bianubuntu
- Clone crazyflie-firmware:
https://github.com/bitcraze/crazyflie-firmware#cloning
- Compiling:
https://github.com/bitcraze/crazyflie-f ... #compiling
- Clone crazyflie-clients-python

In Windows:
- Install crazyflie clients
https://github.com/bitcraze/crazyflie-c ... ndows-7810
- Flash with Cfloader
https://wiki.bitcraze.io/doc:crazyflie: ... x#cfloader

CF loader seems to start correctly, I put the Roadrunner board in bootloader mode (should be the same as CF), but I get the following error:
Restart the Crazyflie you want to bootload in the next
10 seconds ...
Traceback (most recent call last):
File "c:\users\matej\appdata\local\programs\python\python36\lib\site-packages\cflib\drivers\crazyradio.py", line 119, in __init__
device = _find_devices()[devid]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\ubuntu\crazyflie-clients-python\src\cfloader\__init__.py", line 150, in main
if bl.start_bootloader(warm_boot=False):
File "c:\users\matej\appdata\local\programs\python\python36\lib\site-packages\cflib\bootloader\__init__.py", line 99, in start_bootloader
self._cload.open_bootloader_uri(uri)
File "c:\users\matej\appdata\local\programs\python\python36\lib\site-packages\cflib\bootloader\cloader.py", line 224, in open_bootloader_uri
self.link = cflib.crtp.get_link_driver(uri)
File "c:\users\matej\appdata\local\programs\python\python36\lib\site-packages\cflib\crtp\__init__.py", line 91, in get_link_driver
instance.connect(uri, link_quality_callback, link_error_callback)
File "c:\users\matej\appdata\local\programs\python\python36\lib\site-packages\cflib\crtp\radiodriver.py", line 191, in connect
address)
File "c:\users\matej\appdata\local\programs\python\python36\lib\site-packages\cflib\crtp\radiodriver.py", line 101, in __init__
_RadioManager._radios[self._devid] = _SharedRadio(self._devid)
File "c:\users\matej\appdata\local\programs\python\python36\lib\site-packages\cflib\crtp\radiodriver.py", line 70, in __init__
self.radio = Crazyradio(devid=devid)
File "c:\users\matej\appdata\local\programs\python\python36\lib\site-packages\cflib\drivers\crazyradio.py", line 121, in __init__
raise Exception('Cannot find a Crazyradio Dongle')
Exception: Cannot find a Crazyradio Dongle
Cannot find a Crazyradio Dongle
But, as a matter of fact, I cannot flash firmware even when using the cfclient windows app.
When I click on "Initiate bootloader cold boot" after a few seconds I get "Cannot find a crazyradio dongle".
During this, windows plays the sound as if a USB device was unplugged and replugged...

Any idea what could be going wrong?
Am on Win 10 ver 1903, and I use the libusb driver for the Crazyradio PA dongle...
Last edited by matejkarasek on Sun Aug 04, 2019 10:02 pm, edited 3 times in total.
theseankelly
Expert
Posts: 153
Joined: Mon Dec 28, 2015 3:23 pm
Contact:

Re: Firmware development in Windows

Post by theseankelly »

Hey Matej

Are you running the cfloader module under WSL or natively on Windows? it's gotta be on Windows (from cmd.exe) because WSL cannot access libusb devices (yet...I've heard rumors and anxiously await the day this changes!).

If you're running natively on Windows (I use 64bit Python3.7 from python.org), some other things to check: make sure you're using libusb-win32 and not libusbK for the driver. The radio should show up in device manager under the 'libusb-win32 devices' node.

By the way, technically you *can* use the Makefile to flash if you install GNU Make for Windows (http://gnuwin32.sourceforge.net/packages/make.htm). I used to often compile from within WSL and then alt-tab over to a windows cmd.exe prompt in the same directory and run "make cload". But these days I'm more often than not hooked up to a debugger and use 'make flash' instead.
http://www.thejumperwire.com
Tips, tutorials, and science about DIY electronics, drones, and embedded software.
Post Reply