Skip to content

pic32-wifire: add support for flashing with pic32prog#9259

Merged
benpicco merged 5 commits intoRIOT-OS:masterfrom
cladmi:pr/pic32/flasher
Sep 24, 2019
Merged

pic32-wifire: add support for flashing with pic32prog#9259
benpicco merged 5 commits intoRIOT-OS:masterfrom
cladmi:pr/pic32/flasher

Conversation

@cladmi
Copy link
Contributor

@cladmi cladmi commented May 31, 2018

Contribution description

Add flash support for pic32-wifire using pic32prog.

Also enable term and a dummy reset as not supported.
However, connecting to the uart already does a reset.

It was tested with a PICkit3 whose firmware was updated to scripting mode as described here #6092 (comment)

A documentation will follow in another PR on the update procedure I used
-> #9260

I am compiling pic32prog from source as it is done for the other tools even if some binaries are available in https://github.com/sergev/pic32prog. I thought it was easier and safer.

pic32-clicker

Regarding pic32-clicker, it requires a specific way for plugging the flasher (crossing cables) so it would come in a separate PR, also the uart is not available on the USB port directly, so would be another job.

Testing

Having a PICkit3 flashed with the scripting firmware, connect everything.

make BOARD=pic32-wifire flash reset term

Despite not having a proper reset test can run as make term reboots the node.

make -C tests/mutex_order BOARD=pic32-wifire flash test
...
2018-05-31 17:22:46,362 - INFO # Test END, check the order of priorities above.

Interactive tests do not work as received bytes (uart led is indeed linking) are not given to the shell.

Issues/PRs references

#6092 (comment)

Depends on #9260 for the documentation to be accessible.

@cladmi cladmi added the Platform: MIPS Platform: This PR/issue effects MIPS-based platforms label May 31, 2018
@cladmi cladmi requested a review from neiljay May 31, 2018 15:26
@cladmi cladmi added the Area: build system Area: Build system label May 31, 2018
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this PR after finally succeeding to finish the instructions in #9260. Still need to review the stuff, but at least a preliminary ACK you get ;-).

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on the code.

# * Connect the chipKIT-Wi-Fire to USB
# * Connect the PICkit3 to ICSP holes
# * https://docs.creatordev.io/wifire/guides/wifire-programming/
# * The Arrow `▶` pin goes into the pin number 1 (with a square shape around it)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't there a discussion already about unicode characters? I don't remember the outcome

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to be fancy on this one :D I can replace by |> and even say "triangle" because it is more a triangle than an arrow.

# * Run PICkit3
# * Tools/Download PICkit Operating System
# * Select C://Program Files/Microchip/PICkit3/PK3OSV020005.hex
#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a reference to your tutorial somewhere in here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not put a reference here as the documentation was not merged. But I could wait for the documentation and update this.

@neiljay
Copy link
Contributor

neiljay commented Jun 12, 2018

@cladmi Cheers for this !

I've tested this on Wifire and PIC32-Clicker with the USB-UART click fitted. It works fine for me ( I did need a u-dev rule as well )

I've not tested spinning up a VM to program the PICkit into script mode as it already was for me (+ I have a window laptop).

Regarding pic32-clicker, it requires a specific way for plugging the flasher (crossing cables) so it would come in a separate PR

This is only true for the rev1.0 hardware, later revisions came with 2 headers one for PICkit and 1 for mProg, also on the rev1 hardware there are 0 Ohm resistors on the back you can swap to permanently set the header pinout to PICkit. So I would add pic32-clicker at the same time, then its an ACK from me.

Note I have been working on improving interrupt support for PIC32 when this gets submitted+merged there will be working UART RX.

@cladmi
Copy link
Contributor Author

cladmi commented Jun 12, 2018

@neiljay Thank you for testing

I've tested this on Wifire and PIC32-Clicker with the USB-UART click fitted. It works fine for me ( I did need a u-dev rule as well )

So I should also put the udev rule in $(RIOTMAKE)/tools/pic32prog.inc.mk

For pic32-clicker, we also need to put a uart to usb cable for the terminal which we did not tested yet. So it is easier to split for me, or at least, don't make this one wait for the test.

Note I have been working on improving interrupt support for PIC32 when this gets submitted+merged there will be working UART RX.

Cool :)

@cladmi cladmi added State: waiting for other PR State: The PR requires another PR to be merged first CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 15, 2018
@cladmi cladmi added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR and removed State: waiting for other PR State: The PR requires another PR to be merged first CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Jun 27, 2018
@cladmi cladmi force-pushed the pr/pic32/flasher branch from 0aa5739 to 1099d20 Compare June 27, 2018 08:49
@cladmi
Copy link
Contributor Author

cladmi commented Jun 27, 2018

I rebased and added the udev rule. I also checked, the documentation link correctly points to the github documentation page.

@neiljay neiljay mentioned this pull request Jun 27, 2018
6 tasks
@cladmi cladmi requested a review from kYc0o July 3, 2018 10:13
@cladmi
Copy link
Contributor Author

cladmi commented Jul 3, 2018

This still needs a ACK. I have a configured board on my desk if needed for re-testing.

@cladmi cladmi added this to the Release 2018.07 milestone Jul 3, 2018
@neiljay
Copy link
Contributor

neiljay commented Jul 3, 2018

@cladmi Can we add pic32-clicker as well, this worked for me. I will ACK then.

@cladmi
Copy link
Contributor Author

cladmi commented Jul 5, 2018

@neiljay sure. Can you do a PR on my branch or even directly push here with pic32-clicker/Makefile.include with the rules and board plugging documentation for both revisions?

@cladmi
Copy link
Contributor Author

cladmi commented Jul 17, 2018

I rebased it as it has merge conflicts.
I also added $(RIOTTOOLS)/pic32prog/Makefile as dependency for pic32prog so it will be rebuild on version changes, like what was done for edbg.

@kYc0o
Copy link
Contributor

kYc0o commented Jul 19, 2018

Tried in OS X with the following result:

gcc  -g -o pic32prog pic32prog.o target.o executive.o serial.o adapter-pickit2.o adapter-hidboot.o adapter-an1388.o adapter-bitbang.o adapter-stk500v2.o adapter-uhb.o adapter-an1388-uart.o configure.o family-mx1.o family-mx3.o family-mz.o hidapi/mac/.libs/libhidapi.a adapter-mpsse.o -framework IOKit -framework CoreFoundation /opt/local/lib/libusb-1.0.a -lobjc
clang: error: no such file or directory: '/opt/local/lib/libusb-1.0.a'
make: *** [makefile:47: pic32prog] Error 1

Apparently, libusb-1.0.a is not found, which is provided on the pic32prog repo, but I guess not for OS X.

The lib however exists in OS X, at least on my setup:

/usr/local/Cellar/libusb/1.0.21/lib/libusb-1.0.a
/usr/local/Cellar/libusb/1.0.22/lib/libusb-1.0.a
/usr/local/lib/libusb-1.0.a

But for some reason is not found.

I tried this using docker:

BUILD_IN_DOCKER=1 make BOARD=pic32-wifire -C examples/default/ flash term

which might also have something to do.

@kYc0o
Copy link
Contributor

kYc0o commented Jul 20, 2018

I checked the original repo and I wasn't able to compile it either. However, there's a binary version that might be used instead of building the whole thing. I'll add this in a follow up PR.

@cladmi cladmi force-pushed the pr/pic32/flasher branch from ae53333 to 10dd794 Compare June 17, 2019 10:24
@cladmi cladmi force-pushed the pr/pic32/flasher branch from 9ee0241 to da6111e Compare June 25, 2019 11:54
@cladmi
Copy link
Contributor Author

cladmi commented Jun 25, 2019

Rebased now that #11699 was merged.
It removed setting FLASHFILE in the 'pic32-wifire' as it is set globally in 'pic32prog.inc.mk"

@cladmi cladmi removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 25, 2019
@MrKevinWeiss
Copy link
Contributor

nice. I will try to get it running tomorrow!

@cladmi
Copy link
Contributor Author

cladmi commented Jun 25, 2019

@MrKevinWeiss as you said you have a clicker, note this currently only adds the pic32-wifire.

@MrKevinWeiss
Copy link
Contributor

Ya I tried to hack it in to the clicker but wasn't successful (I also didn't spend that much time).

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine here, apart from the pic32 compilation process trying to link a static libusb-1.0 library on arch. That's an upstream problem, though.

Minors:

  • update pic32prog PKG_VERSION
  • maybe change PIC32PROG binary selection logic to work like with edbg, dfu. While compiling this list I realize that we're not consistent throughout the code base, so maybe postpone or ignore.

@@ -0,0 +1,19 @@
PKG_NAME = pic32prog
PKG_URL = https://github.com/sergev/pic32prog
PKG_VERSION = f5d27d6c9506bc0d1f2053002e2aadad1ac424cd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried current upstream, also works. current master commit is "b9f8db3b352804392b02b42475fc42874ac8bf04"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the new version looks like it handles new boards and compilation issues.

RESET_FLAGS ?=

# Compile pic32prog if using the one provided in RIOT
FLASHDEPS += $(if $(findstring $(PIC32PROG),$(FLASHER)),$(PIC32PROG))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the FLASHDEPS logic to something like:

RIOT_PIC32PROG = $(RIOTTOOLS)/pic32prog/pic32prog
PIC32PROG ?= $(RIOT_PIC32PROG)
ifeq ($(PIC32PROG), $(RIOT_PIC32PROG))
  FLASHDEPS += pic32prog
endif

As is it doesn't work when overriding with "PIC32PROG=pic32prog make ...". This is how we usually do it with other tools (edbg, ...), not by overriding FLASHER directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the immediate evaluation, but indeed for the RIOT_PIC32PROG.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(damn too fast).
But as FLASHDEPS will be evaluated when declaring flash, it cannot be defined after anyway so, does not hurt.

@kaspar030
Copy link
Contributor

@cladmi ping

@cladmi
Copy link
Contributor Author

cladmi commented Aug 20, 2019

I updated. However, my pickit does not detect my board anymore… Even with the previous commit from pic32prog.

I will try re-updating the flasher tomorrow…

@cladmi
Copy link
Contributor Author

cladmi commented Aug 21, 2019

Was a pebkac, the jtag was not properly connected.

It flashes correctly and as expected has no input:

RIOT_CI_BUILD=1 BUILD_IN_DOCKER=1 DOCKER="sudo docker" BOARD=pic32-wifire make -C examples/default/ flash term


/home/harter/work/git/RIOT/dist/tools/pic32prog/pic32prog /home/harter/work/git/RIOT/examples/default/bin/pic32-wifire/default.hex
Programmer for Microchip PIC32 microcontrollers, Version 2.0.235
    Copyright: (C) 2011-2015 Serge Vakulenko
      Adapter: PICkit3 Version 2.0.5
    Processor: MZ2048EFG100
 Flash memory: 2048 kbytes
  Boot memory: 80 kbytes
         Data: 117736 bytes
        Erase: done
Program flash: ############################ done
 Program boot: #### done
 Verify flash: ########################### done
  Verify boot: ### done
 Program rate: 5991 bytes per second
/home/harter/work/git/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyUSB0" -b "9600"
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2019-08-21 12:15:05,985 - INFO # Connect to serial port /dev/ttyUSB0
Welcome to pyterm!
Type '/exit' to exit.
2019-08-21 12:15:07,107 - INFO # main(): This is RIOT! (Version: 2019.07-devel-820-g66625-pr/pic32/flasher)
2019-08-21 12:15:07,108 - INFO # Welcome to RIOT!
> help


help
help
help
help
2019-08-21 12:15:17,097 - INFO # Exiting Pyterm
/home/harter/work/git/RIOT/examples/default/../../Makefile.include:560: recipe for target 'term' failed
make: *** [term] Interrupt

It correctly only compiles on first use and after uses the compiled tool.

@kaspar030
Copy link
Contributor

I finally got around to testing this. Unfortunately since #12227, master is broken, but reverting the commit on top of this branch makes it work again.

Flashing with pic32prog works fine anways.

For me, automatic pic32prog compilation still fails for missing libusb or similar, I have to override using "PIC32PROG=pic32prog".

Please rebase & squash!

pic32prog is a program for flashing pic32 boards from command line on Linux.

It works with:
* Microchip PICkit2
* Microchip PICkit3 with script firmware.
* Other ones: https://github.com/sergev/pic32prog/wiki
Define a RIOT_PIC32PROG to allow setting 'PIC32PROG' globally from environment.

https://github.com/sergev/pic32prog

For PICkit3 it requires having it with scripting mode firware.

Source
------

RIOT-OS#6092 (comment)
For PICkit3 it requires having a scripting firmware installed.
Copy the udev rule from dist/tools/pic32prog/doc.md
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 24, 2019
@cladmi
Copy link
Contributor Author

cladmi commented Sep 24, 2019

Squashed, then rebased.

If master is broken, then 62415de before rebasing should still be working I guess.

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.

(With this master on the wifire is still broken and needs rebased #12256, but this PR is a step in the right direction).

@benpicco benpicco merged commit 50ba48e into RIOT-OS:master Sep 24, 2019
@cladmi cladmi deleted the pr/pic32/flasher branch September 26, 2019 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: MIPS Platform: This PR/issue effects MIPS-based platforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants