Way to analysis Firmware

Thread Starter

Alex1700

Joined Jan 12, 2020
107
Recently my senior give me her previous project firmware using PIC32MX microcontroller inside have 16 of c file
may I know any best way to break this firmware into smaller pieces easier for me to understand and study ??
 

Papabravo

Joined Feb 24, 2006
21,159
One line at a time function by function. Then use the main function to organize the functions that you already understand, having broken them down one line at a time.
 

dcbingaman

Joined Jun 30, 2021
1,065
I would start by determining the hierarchy. That is determine which files use which functions. If she wrote decent abstraction layers, draw up a dependency diagram first. Next examine the functions by name, again if she was a good programmer the names of the functions should indicate the intended purpose of each one and give you a good idea what each one is for. Finally examine the code within each one keeping in mind the 'intended purpose' based on the names. You should also read over her comments within the code. Again if she is a good programmer you will find plenty of comments to help explain the code. You may be able to run some of the c files using a compiler on a PC next in debug mode and examine it that way. Of course that can only be used by functions that do not work with the PIC hardware.

Prioritize which functions you look at first by starting with the ones that are the 'easiest' to understand. This will help fill in the holes of what the more complex functions do.

For the hardware, be sure you have the PIC32MX datasheets handy, as you will need them to augment the code to enhance understanding.

If you find a lot of global variables with interdependencies. That is ones that are not kept 'static' to the intended source files to minimize scope, you may find it very challenging to figure that sort of code out. In other words, if she is 'not' a good programmer it will be much more difficult to follow the code. But the fact that she broke it into 16 smaller c files is a good indication she knows how to accomplish good abstraction layers.
 

nsaspook

Joined Aug 27, 2009
13,087
If the code is PIC32 code is compatible using the MPLABX ide you can use the Call Graph function to explore the program structure.
1681439440294.png
1681439467560.png
 

Papabravo

Joined Feb 24, 2006
21,159
I not understand could elaborate more ?
I think the sentences are quite clear.
  1. Make a list of all the functions in the source files.
  2. Pick any of the functions at random.
  3. Study the function line by line until you understand the purpose and the operation of the function. Make copious notes.
  4. Repeat #3 for each of the functions on the list you made in step #1.
  5. Save the main() function for last, and when you finish your line by line analysis of that function, you can pull it all together.
I've done this numerous times and it was always successful.
 
Last edited:

Thread Starter

Alex1700

Joined Jan 12, 2020
107
First compile (clean and build) the code to generated the needed linkages then left click highlight select the 'main' function. Right click to get a pull down menu to Call Graph the selected function.
View attachment 292111
thank you I found it.
I am still learning the PIC32MX microcontroller do you have any suggestions tutorial or example code project from the internet
 
Top