Friday, June 27, 2014

MPLAB-X git plugin

I was pleased to learn there is a git plugin for MPLAB-X.  I use git heavily, and having it inside the IDE could be a win.  I downloaded the plugin from https://code.google.com/p/nbgit/downloads/list?q=0.4 and it installed without much grief.  (OK, installing a NetBeans plugin is a little weird, but MPLAB makes it fairly obvious.)

Initially I was quite impressed.  The basic things you need to do are right there at your fingertips. To initialize a git repository, you simply choose Initialize Project from the Team menu:

Once you have initialized a repository, the git menu choices show on the main Team menu rather than the Git submenu.

You commit changes to the repository by selecting Commit:

You will be prompted for a commit message where you note down what this particular change was about:


You can view the history of your project with the Browser:
Notice that if you highlight one of the commits, the center pane shows the commit details.

Any changes you make which have not been committed are highlighted in the source window:


You can also select Diff and see changes across all files, including deleted lines:

There are also a couple of nice little touches.  If a project is in git, there is a tiny blue icon next to the project icon to let you know:



And any files with uncommitted changes have their name shown in blue both in the tab and in the Projects pane and the Files pane:


One place where the plugin falls down, badly IMO, is in support for branches.  git branches are easy and lightweight, and as a result they are used more often than they are in previous systems.

As an example, when opening a project (shown below in gitg) which had multiple branches:

The plugin only shows the current branch.  You cannot select a branch, and you don't even know that other branches exist.

However, if you merge the branch back into master, you at least see the branch name as well as the master branch:

The other shortcoming is that the Diff only shows differences between the locally, uncommitted changes and the HEAD.  There doesn't appear to be a way to see differences between two commits.

There is also little support for remote repositories.  You can clone a remote repository, but you cannot push changes back.  And of course, with no support for branches you can't checkout remote branches.

Still, for most of what you would want to do, other than perhaps remote repositories, everything is there and easy.  The plugin also allows you to  add your own commands, so simply adding a Push command covers probably 90% of what I would normally do.

So I have to break down and go to the command line for branches, but that isn't a very high price, and it only needs to be done when switching or merging branches, which doesn't happen very often.

All in all, a really nice improvement in an already impressive IDE.

Monday, March 17, 2014

MPLAB-X -- SDCC -- Fedora

I frequently use MPLAB-X (sadly, not entirely free as in speech) for PIC projects.  It works quite well even though it required me to go out and buy a new programmer.  Actually, I got two, both an ICD-3 and a PICkit 3.

Recently I needed to do an 8-bit project, and decided to use SDCC.  It isn't the most efficient compiler in the world, but it is free (as in speech and as in beer) and I kind of like it.  Since I've recently been doing a lot of 16 and 32 bit stuff, I haven't gotten piklab set up in ages, and besides, it doesn't work with the newer programmers.  And MPLAB-X does have an SDCC plugin.

Unfortunately, MPLAB-X apparently expects an older version of SDCC and it includes a couple of compiler switches that no longer exist.  Although this doesn't cause the build to fail, it does lead to annoying messages which might disguise warnings which I care about.

MPLAB-X-warnings

Although MPLAB-X allows you to add switches, it has no provision for removing switches, and I could not find a way to easily modify the defaults.

I did find that I could edit nbproject/Makefile-default.mk, but as soon as I added any files to the project, MPLAB wrote over the edits.

However, MPLAB provides a Makefile that doesn't get written over, and it has targets to be executed at various times during the build.  By using the .build-pre target, I could edit the other Makefile just prior to the build:

MPLABX-Makefile

But there is yet another (small) fly in the ointment. Because I have multiple programmers, I often create configurations for each programmer.  Now there is no longer a Makefile-default.mk but instead a Makefile-Red.mk and Makefile-Blue.mk (for the PICkit and ICD).  Fortunately, MPLAB provides a variable, CONF, with the name of the configuration, hence the ${CONF} in the edit.

Now by simply adding a line to the Makefile, my SDCC project builds cleanly and there is no concern about missing important warnings.