chipKIT® Development Platform

Inspired by Arduino™

Cross-compiling MPIDE

Created Tue, 09 Apr 2013 12:57:50 +0000 by majenko


majenko

Tue, 09 Apr 2013 12:57:50 +0000

I am in the process of bundling my own version of MPIDE with some custom changes (added a custom board, and hard-coded support for mphidflash).

It's working well on Linux and Windows (the two systems I have access to), but I don't have a MAC to compile on.

Can I cross-compile for OS X using Linux? Since 99% of it is Java I would have though that it'd be a piece of cake - it's more the packaging that's an issue, isn't it?


Jacob Christ

Wed, 10 Apr 2013 13:17:50 +0000

What is mphidflash?

Jacob


majenko

Wed, 10 Apr 2013 13:32:26 +0000

mphidflash is a program which uploads hex files to a chip using the Microchip HID bootloader (AN1388)

It's also the same protocol as the RetroBSD bootloader. I'd prefer to use Serge's pic32prog program (which also supports pickit2, etc) but I can't get it working on Windows.


EmbeddedMan

Wed, 10 Apr 2013 15:00:26 +0000

What is mphidflash? Jacob

Jacob,

I'm one of the maintainers of mphidflash, as I used it for my UBW32 boards and EiBotBoard. It's a cross platform (Mac, Linux, Windows) command line tool that acts as the PC side of a bootloading process if the microcontroller can 'talk' the Microchip HID Bootloader protocol (which, I believe, is actually documented somewhere).

As soon as we can get the ability to use bootloaders other than AVRDUDE into MPIDE then we'll be able to include mphidflash in MPIDE and then upload sketches directly to UBW32 boards and such.

*Brian


majenko

Wed, 10 Apr 2013 15:24:51 +0000

Hard coding another bootloader into the IDE is actually quite a trivial process. On my personal copy I have boardname.upload_using=mphid as an option, and it calls mphidflash to do the uploading to that board. Only a few lines of code - the tricky part is getting the build.xml to get the files in the right place ;)

AvrdudeUploader.java add:

private boolean uploadViaMPHID(String buildPath, String className)
  throws RunnerException, SerialException {

    Map<String, String> boardPreferences = Base.getBoardPreferences();
    List commandDownloader = new ArrayList();

    commandDownloader.add("mphidflash");
    commandDownloader.add("-r");
    commandDownloader.add("-w");
    commandDownloader.add(buildPath + File.separator + className + ".hex");
    return executeUploadCommand(commandDownloader);
  }

and a hook in public boolean uploadUsingPreferences(...)

....
    if (uploadUsing == null) {
      // fall back on global preference
      uploadUsing = Preferences.get("upload.using");
    }
    if (uploadUsing.equals("mphid")) { 
      return uploadViaMPHID(buildPath, className);   
    } else if (uploadUsing.equals("bootloader")) {  
      return uploadViaBootloader(buildPath, className);
    } else {
      Target t;
   ....

Bit hacky, but works.

I have been giving some thought to how to do it properly, and I think that there's 2 ways of doing it.

  1. Have an entry per-board for what to call to upload. This could be up to 4 entries per board - a generic one, and optional per-OS overrides, so you can specify specific programs depending on which OS you are on. This could get messy with duplicated info all over the place. Simple to implement though.

  2. Have a bootloaders.txt (or similar) file which defines the different bootloaders and what program to use on what OS to upload to them. The boards.txt file then just references entries in this bootloaders.txt file. Somewhat harder to implement, but means you don't have as much duplicated information.