Friday, August 27, 2010

I've been spending a lot of time searching for the best C editor for MCU's.
There are a lot around the internet, many of them have many important features, but no one is still perfect for MCU's, because they are made for Windows' C so they provide class handling, inheritance, and so on...
"Must have" features for an editor should be:

Syntax highlight

Code folding

Self completion (like MS Intellisense)

Show Hints when mouse hovers a variable/function

Functions List (argh! this is a point I have to discuss!)

Functional Find in Files

Parenthesis matching

Hyperlink in comments (this is a point I have a great idea, later on this post)

Everyone has many of the above features but none has them all. Slickedit is probably the best but it lacks of the last two features (a crappy illegal portable version exists but you won't be able to run any batch to compile using WinAvr).
Jfe is the lightest and portable one: you can find in workspace files even if files are not yet saved, but it remains a little steps behind (no code folding or hints on variables, just a sort of help when typing functions).

Ehm, one question: WHY DO FUNCTIONS LIST HAVE TO BE ORDERED ALPHABETICALLY???
I like only editors who show functions the same order I have typed them! When coding for a MCU you probably have one single file which contains all. No prototyping, just a list of methods.
I need an overview of the functions I wrote, not the alphabetical list of them. The upper part of my code is initializations, the middle part are interrupts, followed by low level functions then more high level ones who call the preceeding ones.
If you sort it alphabetically I lose control of who is calling who.

Ok, at the end of the day I decided that Codelite (without Windows' facilites, no wxWidgets and so on) is my choice. It is also opensource so I could make changes to SymbolView.dll to show functions not sorted alphabetically.

For version 2.6 (and not following).

You can install it (but copying the folder to another pc will make it portable), then go to C:\Program Files\Codelite\Plugins and replace the SymbolView.dll using the one you can find zipped here.
Then, after opening the program, go to Plugins menu -> Manage Plugins... and check the SymbolView plugin.
It is shown as a tab in the workspace pane, right click on that tab and choose "Detach".
Now finally you have functions list (and only functions, no macros, variables, etc...) ordered by line number...

It still lacks of hyperlink in comments. If a part of my code is a result of an Excel Sheet computation I would like to write:// Details on computations: file://algorithm.xls
So when i hover the mouse on it, and click, the file opens.

Some of the above editors have this feature, but Codelite hasn't. Let's hope in future.

MY IDEA

This is my idea (who knows, someone in future will implement it): instead of placing just an hyperlink why can't I link the file directly?
Let me explain: I write some code with a clock and signal.
This is what I want to see on screen just for better documentation of what I'm doing:

And this is what is stored in real file (thus not interfering with compilation) opened with notepad:

Hi everybody.A few weeks ago I bought the DSO 0201 oscilloscope (you can find it on eBay or in Italy you can buy it from www.futurashop.it).

It's awsome and open source.You can find all the resources here: Google Code including schematics and source code for version 1.1.

Personally I think that best firmware version is the one named "Paul's 1.5" instead of latest 2.xIt's the one I currently use, but no source is provided because some parts of code are now copyright protected. What a pity.

HACKING!!!!

What if you wanted do some minor changes to an already compiled firmware? For example the beloved Paul's 1.5? Just need to know how to handle dfu files and a hex editor.

In the next steps I'll show you how to change the language of a version (I repacked it to Italian), and also how to edit some characters fonts.

2) Open it with an Hex editor and trim away last 4 bytes (which represent the checksum) in this example: 21 1C B8 BB3) Search for any string, for example "RUNNING" and go to that address.

4) Change the strings you want (the horrible "PAUSHED" should be "PAUSED" or the string in your language) from that point onward. Almost at the end of the file there are error messages. I noticed that if a string ends with many zeroes you can overwrite them (but leave at least one!) proved that the resulting string fits in the screen, once you upload the new file.

5) When you have done you must recompute the checksum. So save the modified file and zip or rar it. And open it (for example) using WinRar. You'll notice that CRC32 is computed as last column:

6) Now you must complement the CRC32. Open Windows Calculator in Scientific mode and select the Hex data input. Type in FFFFFFF - 116BA0B2 (eight times F minus the number you find in the rightmost column of WinRar).

7) Now, the resulting number must be added to the end of the edited dfu in reversed byte order (i.e. you obtain EE945F4D, at the end of the file you must add 4D 5F 94 EE).

8) Finally, open the DfuSe Demo for firmware upgrading, power on the unit with the minus key pressed to enter upgrade mode and upload the new file.

9) If you are Italian, you can download my translated version from the same address above, I also added the accented "a" (à) and made a better "delta" symbol. To understand how fonts were mapped I needed to download the 1.1 source code but I also made a pdf guide(Enter the font directory at the end...).