openOCD 0.90 + PIC32

Associated Page:

https://hackaday.io/project/6450-operation-learn-the-mips-pic32mx1xx2xx

DIFFERENCES:

In order to use the PIC32MX170F256B and PIC32MX230F064B, I had to make some changes to openOCD. These changes may be necessary in previous versions, as well. But the diffs, here, are for 0.90.

A quick overview of the changes:

    • 32MX170F256B was not in the device-listing

    • The register-names in mips32_regs[] did not correspond to those used in the fast-flash algorithm, so have been reverted(?) per: http://sourceforge.net/p/openocd/mailman/message/28333633/

    • The fast-write algorithm would fail due to testing whether the algorithm's code-memory overlapped the algorithm's data-memory. This failed every time, because of: last_address = (start_address+count,) rather than (start_address+count-1)

    • WITHOUT the fast-write algorithm, flashing took nearly ten minutes. With it, it takes around 30 seconds.

The source files at the bottom of the page are the "hacked" versions, which seem to allow for fast-write flashing, as well as use of the MX170F256. The file 09HACKS.DIFF contains the diffs.

BUILDING:

The build-process can be a bit elusive, especially with regards to libusb and libftdi. These are a few things to keep in mind:

  • Just because your system has libusb and libftdi doesn't mean they will be detected by openOCD's configure script! You need their associated -dev packages! (e.g. libusb-1.0-0-dev, libftdi-dev).

  • You need 'pkg-config' installed on your system (apparently my system didn't come with it installed?!) otherwise libusb will most-likely not be detected.

  • Download the 0.90 source.

    • Extract the source

    • Copy the files (linked at the bottom of the page) to their respective directories, over the files already there. (You can see where they go by looking at the .diff file).

    • In the main 0.90 source-directory run './configure'

    • If the appropriate -dev packages and pkg-config are installed, you should see: "OpenOCD configuration summary" and a list of options followed by "YES"

    • In the same source-directory, run 'make'

    • Be patient

    • now run 'sudo make install'

      • On my system, this placed the new openOCD files at: /usr/local/share/openocd/ and the executable is located at /usr/local/bin/openocd

      • The original openOCD package that came with my system is located at /usr/share/openocd/, with the executable at /usr/bin/openocd so the original package is not overwritten.

      • You might have to modify your PATH variable to point to the new directory...? But I'm pretty sure /usr/local/bin usually overrides /usr/bin...

      • running 'openocd' should tell you the version number (now 0.90)

NOTES ON USING:

    • Some flashing failures can be fixed by *reducing* adapter_khz. I had seemingly unrelated failures in fast-write at 4000kHz that were fixed at 400kHz, despite everything else seemingly working fine at 4000. This is described in the first link below.

FYI: Instructions suggest creating "board" scripts, as needed, and placing them in /usr/local/share/openocd/scripts/board/... I recommend you keep these in a different location, preferably project-specific... then, e.g. the "-f board/<boardScript.cfg>" arguments can be replaced with, e.g. "-f <projectDir>/openOCDscripts/boardScript.cfg" and the project can move around from system to system as a single package...

RANDOM UNSORTED NOTES written a while-back:

These notes are handled by using the hacked-version of 0.90 and notes described above and can be ignored. But details are contained within the following links...

(0.50 came with my system, but appears to be too old to *flash* the PIC32... a brief glimpse at the change-logs: I *think* >=0.60 should work).

(NOTE1: If you can't bare the horrendously-slow flashing-process, check here: https://hackaday.io/project/6450-operation-learn-the-mips-pic32mx1xx2xx/log/20840-wherein-we-discover-with-some-amount-of-certainty )

(NOTE2: apparently there must be an entry for your device in the file src/flash/nor/pic32mx.c in order to flash the device correctly. Check pic32mx_devs[] inhttp://openocd.org/doc/doxygen/html/pic32mx_8c_source.html around line 120. If your device is not listed there, it's really easy to add, but it does require compiling openOCD from source. See: https://hackaday.io/project/6450-operation-learn-the-mips-pic32mx1xx2xx/log/22601-it-shoulda-been-simple)

(NOTE3: not certain, but it seems a default-compilation of openOCD 0.80 doesn't work with my flashing scripts... I don't know/haven't tested whether it will work with different options.)

When/If you compile openOCD yourself, make sure the FTDI driver headers are loaded on your system. On linux: this means making sure that lib-ftdi-dev and lib-usb-dev must be installed before compiling openOCD. (It's not enough to have just lib-ftdi and lib-usb, you must also have the -dev packages!)

NOTE: I've been fighting this for hours, and can't seem to find anything about it online... Here's the deal: You NEED 'pkg-config' installed, or libusb won't be detected (even if it's installed) when you run 'configure'. (Apparently my new OS didn't come with pkg-config by default?!)

----------------

FILES:

09hacks.diff

mips32.c

mips_m4k.c

pic32mx.c ----- TODO: I accidentally deleted this file from the site... please send me an email to remind me to upload it next time I'm at that computer!