Where are the source files that get compiled for each firmware target defined?

I’m using MatekF405SE flight controller and it’s ardupilot firmware target is MatekF405-WING. I’ve built the hex file using waf and setup the quad and flown it fine using mission planner.

What I want to do now is understand the source code/firmware so that I can modify it. There are so many source files and the docs aren’t detailed enough to get a full understanding. I want to see which source files are compiled by waf for this firmware target and then work backwards/reverse engineer to learn the code as I’ll know which files to study and which to ignore. So then my question is: Where are the source files that get compiled by the waf system for each firmware target defined? Or better yet where is each firmware target defined?

For context I’ve made my own board and hwdef file. It is similar to the Matek board except contains my own hardware to control a servo motor of which I have my own driver source files that I need to add to the ardupilot firmware in order to use it alongside flying the drone. Hence I would like to understand the ardupilot code structure in detail so I can add this custom code for controlling of the motor into the scheduler. If anyone has a better idea on how to study the ardupilot code in detail, please share some ideas thanks.

Hi @clinteastwood,

I’m not sure if this is what you’re looking for but we have some info in the learning the code section of the wiki.

Thanks but ive covered the docs already. Was wondering if there is anything a bit more detailed as there is a lot happening in the code and if not, where to find the firmware targets (board configurations in waf) are defined so I can see what code is compiled for my board and refer only to them for self study.

I guess you’ve already found the AP_HAL_ChibiOS/hwdef folder for your board?

If the servo requires a special driver then it might be good to look at how the Robotis servo support is done.

Yeah I’ve figured the hwdef file out for the board. The servo module has a driver i’ve made that is not related to ardupilot. I wish to figure out the firmware scheduling/task system works in detail so I can know where to insert a thread to execute the servo functions amid all the other ardupilot threads.

For scheduling there are basically two methods… add the driver’s update (or whatever you call the method that should be executed regularly) method to the vehicle’s scheduler table which means it will run from the main thread OR create a thread within the driver’s init method (many drivers do this so hopefully you can find examples but tell me if you can’t).

Once i’ve done that, How do i add the servo source/header files to the build process?


Normally you don’t need to add individual files to the build process. If they’re in an existing directory waf just compiles them in. For files in new directories the directory might need to be added to the wscript file.

1 Like


I know this is a bit old but I am in a similar situation. Could you please share any examples within the source code of drivers that use a separate thread? Thanx!