This page has deprecated and moved to the new documentation framework of the main Bitcraze website. Please go to [[https://www.bitcraze.io/documentation/system/]] ====== On-chip debugging ====== One of the key components of getting really serious about developing on the crazyflie, is to dive into the C-based firmware. If you really want to do some major changes to the intrinsic of the code, it is essential to have proper tools to be able to debug the code (place breakpoints, read real-time values ect...). On this page, we will put a few examples how to do this with IDE's and different environments. This page requires our debug adapter! See this page: [[projects:crazyflie2:debugadapter:index|Debug adapter]] ===== Eclipse ===== ==== Ubuntu 18.04 ==== * Ubuntu 18.04.2 LTS (64 bit) * Eclipse 2019-03 (Eclipse IDE for C/C++ Developers) * Debug Adapter * ST Link V2 Debugger === Installing prerequisites === First install GDB and openOCD: sudo apt-get update sudo apt-get install gdb sudo apt-get install openocd Then install java: sudo apt install default-jre Then install eclipse itself: Go to their download page: [[https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/2019-03/R/eclipse-cpp-2019-03-R-linux-gtk-x86_64.tar.gz|eclipse 20]] and then go into you download folder and unzip the file. tar -zxvf "your-downloaded-file".tar.gz and start up eclipse: "YOUR-UNZIPPED-FOLDER"/.eclipse === Installing required Eclipse Plugins === Install the C++ development tools and GNU MCU plugin by following the instructions [[https://gnu-mcu-eclipse.github.io/plugins/install/|here]]. * C++ Development - Follow the instructions under the header 'CDT'. * GNU MCU plugin - Follow the instructions under the header 'Plug-ins install/update -> The Eclipse Marketplace way' === Import Crazyflie Firmware === First import the [[https://github.com/bitcraze/crazyflie-firmware|crazyflie-firmware]] into eclipse: *File > import... *C/C++ > Existing Code as Makefile Project -> Next *Give it a name *Existing Code Location > Browse... > //Look for the firmware folder// *//Toolchain for Indexer Settings// can be ignored. *Finish === Setting up Eclipse Debugging environment === * Go to: Run > Debug Configurations... * Double click 'GDB OpenOCD Debugging' Now input the following settings in the debug configurations: == Main == {{:projects:crazyflie2:development:stm_openocd_main.png?200|}} Insert the filepath to the cf2.elf file to //C/C++ Application//. == Debugger == {{:projects:crazyflie2:development:stm_openocd_debugger.png?200|}} check the following settings: OpenOCD setup -> Config options: -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c init -c targets GDB Client Setup: * Executable name: Filepath to gdb toolchain * Commands: set mem inaccessible-by-default off == Startup == {{:projects:crazyflie2:development:stm_openocd_startup.png?200|}} == Hit Debug! == If you don't see any errors, eclipse should go to an dedicated debugging environment automatically and it automatically halts the crazyflie's firmware before it goes into the main function of src/init/main.c. Press F8 or Run > Resume to let it continue and place a breakpoints anywhere in the code (double clicking just in front of the line in the gray area or press Shift+Ctrl+B). Now you should be able to read out the values of the defined variables at that very position. Make sure that your cf2.elf is the same as the one you uploaded to the crazyflie. ==== Mac OS ==== Install gdb and openocd brew install gdb brew install open-ocd Install java JDK [[https://www.oracle.com/technetwork/java/javase/downloads/index.html|java download]] Download eclipse [[https://www.eclipse.org/downloads/download.php?file=/oomph/epp/2019-06/R/eclipse-inst-mac64.dmg|eclipse download]] Choose destination folders - Install Run eclipse and choose work folder == Installing required eclipse Plugins == The rest is the same as for Linux. Make sure that the arm-none-eabi-gcc is properly installed and its path is configured in the //debug configurations//.