What's this blog about then?
Greetings, Internet. When I started using PIC32 a few years ago with the PIC32MX220F032B, I quickly came to realise that there were no examples that would help me understand how to use it. Worse still, what little there was was copied and pasted from Microchip's own examples and made extensive use of their peripheral library, PLIB, to do almost everything. This problem became even worse when I wanted to move to the PIC32MZ series because Microchip has moved on from PLIB to Harmony (which itself seems to use PLIB in the background funnily enough).
I contrast this to Arduino which has user libraries and code for seemingly everything under the sun. Every module on eBay and Aliexpress has a library for it on Arduino. Not so for the PIC32! However, I like the PIC32 because of the large amounts of RAM and peripherals available. So after years of not being able to take the hint that PIC32 wasn't for part-time hobbyists like me, and years of making my own development boards and rewriting Arduino code to work on the PIC32 I've decided to share what little I know on this blog. I hope it will be useful for the people like me who want to use the PIC32 but don't want to buy an expensive development board and be forced into using Harmony. A huge audience, I'm sure.
20 comments
Alex S.Elec
Hey, interesting blog!
I had that same problem moving from the MX to the MZ, had to re-write all my drivers.
You learn the hard way I guess.
Aidan Author
Hi Alex, thanks.
Yeah it's a lot of unnecessary work but on the plus side I learned a lot about how the hardware works.
Bert Lewis
Hi Aidan, I have been working with Pic's for at least 20 years. But I am having a lot of trouble cracking the bootloader for 32MZ. Have you tried it? Have you succeded? If so will you post about it?
Aidan Author
Hi Bert,
Reply is quite late, sorry about that. 20 years is quite something and coincidentally exactly as long as I have been using them, starting with the ancient PIC16F84 back in 2000.
I haven't tried anything with the bootloader and the 32MZ unfortunately. You can be sure that when I do I'll write a post about it here but I can't say when that will be :)
Cirilo Bernardo
Bert and I have got a bootloader up and running for the Olimex HMZ144 Rev.C running with the PIC32MZ2048EFM144. https://gitlab.com/cbernard...
If anyone wants to try it out on other MZ hardware just try it out and let me know what problems you run into; I'm building a doc on what to do to target other MZ MCUs. It can be targeted for the MX as well of course but that requires a lot more work.
Aidan Author
Hi Cirilo,
For some reason I didn't get a notification about your reply. Thank you very much for sharing that code, I'll be very interested to take a look at it. I'm currently focusing on USB, which will take some time but after that I plan to write a post on bootloaders. May I reference your code at that time? I'd obviously give you and Bert credit for it.
Anyway, take care and sorry again for the late reply.
Cirilo Bernardo
Sure, no problem there. People can take it and modify it as they please. I was lazy with the crt0.S for the main app; ideally it should just re-initialize the stack, set the new ebase value, and initialize the main app's C/C++ static variables, but I didn't bother to strip all the redundant reinitializations like the cache initialization. Good luck with the USB; it's a challenge to create a good stack.
Cirilo Bernardo
What about the bootloader are you having trouble with? Bootloaders for the PIC32 are simple enough that I just write my own; with the PICkit4 (and your own linker script) you can even use both bootloader pages to implement the bootloader and leave more memory for the main program.
Bert Lewis
Hi Cirilo, Well I have no idea how to write the linker script. I am still using a PK3 - does that matter? Are you willing to share your bootloader?
To answer your question I was trying to get the harmoney to work - I know that was my first mistake.
Cirilo Bernardo
For the PIC32MZ series I'd suggest using a PICkit4 - they're relatively cheap and so far they seem to have good support for programming the PIC32MZ series of processors. I never attempted to use a PICkit3 to program an MZ; I used an ICD3 until Microchip finally had the Programmer-to-Go feature available for the PICkit4. At the moment I'm embarking on writing software for the PIC32MZ-DA development kit with a view to eventually making my own hardware and using it to teach embedded programming (Microchip's dev kits are far too expensive to use as a teaching tool). If you can tell me what features you want from the bootloader and what processor you're using I may be able to help out.
Aidan Author
Hi Cirilo, glad you can be of some help to Bert. Just wanted to point out I've used the PICkit 3 to program the MZ EC, MZ EF and MZ DA series just fine, it's just slower. The PICkit 4 is overall better and it's cheap so no reason not to move to it but the PICkit 3 does work.
I agree that Microchip's dev kits are far too expensive and all of them need additional daughter boards to get the full functionality out of them, making them even more expensive. That's why I make my own dev boards too.
Cirilo Bernardo
Thanks for the info on the PICkit3 programming the PIC32MZ series. Do you know if it can program the 2 Boot Flash regions independently? I know the firmware uploaded to the ICD3 can't do that but the PICkit4 firmware does it. For work I even crammed a graphics driver into the boot flash so we have a graphical bootloader and still have all of the 2MB available for the main app.
Bert Lewis
That sounds pretty great!! I can get the PK4 no problem. I don't
need many features at all. Boot load through UART2. Basically the issue
is I can't really get the programmer in the space provided when it is
embedded in my project. So I would like to be able to develop the code
in MPLABX and load it through the UART2. I Would like to use a seperate
stand alone program for the loading. It could be the one provided by
microchip or something I write. Also I should point out I have no
experience setting up MPLABX to include the bootloader section when I
build my program.
Cirilo Bernardo
OK. You might have to get in touch with me ( Cirilo dot Bernardo at g mail ). I'll need to know a little about your hardware to set things up properly and to customize the linker scripts. When you use a bootloader you need to use a linker script for the bootloader and a linker script for the application; each of those also need their own custom startup code since they have their own drivers and interrupt vector tables. Microchip provide some details in AN1388 but aside from describing the UART protocol that Microchip use, that document's not very helpful because it's worded in such a way that if you didn't already know how to write a bootloader , linker script, and startup code the document might read as though it were written in Minoan-A.
Bert Lewis
Oh great thank you! I will send you an email right now. And thank you for confirming about the app note. I am sure I have read that 30 - 40 times in the last 10 years or so. The UART side I understand conceptually, but that is as far as I get. I am so glad I posted here!!!
Thanks Aidan also for having this blog!!
Aidan Author
Hey Bert and Cirilo if you ever get something working please let me know. I'd like to put up a post on this stuff one day too :) Cirilo, thanks for providing so much help to Bert it's great to see!
Cirilo Bernardo
No problem. I created a project on gitlab so I can make that open to the public when I've got it working and created some notes on porting it to other PIC32 processors.
Philip Argosy
Hi Aidan, I always thought I was very experienced with PIC32 processors, but then I tried the PIC32MZ That forced me down the Harmony path and several times I have tried to get to grips with it and I have failed!!
Thank you for this blog which gives me hope that I can finally get a PIC32MZ project off the ground and use the enhanced speed, expanded Flash memory etc.
regards
PhilipJ
AlPl PaL
Many thanks to you, Aidan! Without your tutorial I would have never looked into the PIC32MZ devices or - within reasonable time - have been able to get them working (I feel much more confident with dsPIC33s and the 8bit-PICs).
On the Microchip website I was stumbling over the PIC32MZ Graphics DA family with DDR2 SDRAM (32MB), 3-layer graphics controller and a high-performance 2D GPU. For me these devices are out of scope (169 to 288 pins) but maybe this information is interesting for somebody here who wants to implement display support to their project.
Emodin
Life saver - I'm just starting to use the PIC32MZ.
Comments are hosted by Disqus, which loads only when you ask for it.