PIC32MX270F256B Support?

Let us know what you think about the chipKIT, and what can be done to make it better!
rs2845
Posts: 18
Joined: Tue May 17, 2016 9:02 pm

PIC32MX270F256B Support?

Post by rs2845 » Tue May 17, 2016 9:20 pm

Hello all,

I'm wondering if the ChipKit Arduino bootloader can be flashed onto my PIC32MX270F256B chips for a project requiring custom PCB's (eventually). I have built the circuits that "mimic" a ChipKit board but don't want to brick any of my PIC chips by rushing. I did google a few times but saw posts dating back a few years, and it seems like Chipkit development hasn't stood still, so I would like some up-to-date advice.

Question: Can I use the ChipKit Arduino bootloader on a PIC32MX270F256B? I know it's used on a MX250F128B. If it is possible- what do I need to change?

Am I correct in assuming that this is the correct bootloader to use?

Question 2: The DIY circuit shows the use of an external oscillator. Is this necessary if the PIC already has an internal one?

Here is the source of the DIY circuit I have built


I look forward to hearing from you :) Apologies if any rules have been broken or if this is in the wrong place...

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: PIC32MX270F256B Support?

Post by majenko » Wed May 18, 2016 12:30 am

Yes, it can be used, but not in its current form.

I have a pull request pending with the correct linker script and other associated code for use on an MX270 (I am developing a new chipKIT board that is MX270 based - to be released on the masses shortly).

Until that PR gets accepted you will have to work from my fork of the bootloader: https://github.com/majenkotech/PIC32-avrdude-bootloader

You can check out the config for the chipKIT Lenny (in https://github.com/majenkotech/PIC32-av ... /majenko.h) and also the Lenny entry in https://github.com/majenkotech/PIC32-av ... s/Makefile.

There is no MPLAB-X configuration for it at the moment, though I am sure you could make one if needed. I never use MPLAB-X unless I really really have to, so I have a simple Makefile that does it all for me. It's about 1000000x quicker than using MPLAB-X...
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

rs2845
Posts: 18
Joined: Tue May 17, 2016 9:02 pm

Re: PIC32MX270F256B Support?

Post by rs2845 » Wed May 18, 2016 5:44 am

Hi majenko,

Thanks for your fast reply! Great to know you've managed to get it working on the 270f256b!

As I'm brand new to all this- I'd just like to confirm the procedure I'm going to follow on a test chip when I get chance tomorrow.

1. Download your amended boot loader from your pull request.
2. Follow the instructions for using MPLab X and PICKIT3 to flash the MCU from the DIY board thread.
3. Use MPIDE until relevant patch made to MPLAB X so it recognises the 270F as Chipkit compatible (I'd prefer to use this so I need to figure out how and what to change in order to get it working).

Uncertainties still at this point:
1. Can I leave out the USB port from my MCU circuit and opt to only use ICSP port 1 for both boot loader flashing and sketch uploading?
2. Once I get MPLAB X to recognise the 270F256B as Chipkit compatible- I use my PICKIT3 to flash the boot loader and also to upload the sketches to my MCU - BUT Does the MCU need to be put into programmer mode for sketch uploading too (from the DIY cct there's a button)? How does MPLAB know the difference between bootloader and sketch uploading and not overwrite one another?
3. Can any debugging be used to check variable values as the MCU is running? Ie with my Pickit connected somehow?
4. Are there any limitations that the Arduino bootloader faces on a PIC32MX270F? Im concerned that the internal clock might not be fast enough for WS2812B LEDs as many Chipkit examples online run on 80mhz clocks.

I'm going to search the forum again in case I can answer some of these points myself. But the phpbb search system doesn't return much for me when I do!

Thank you once again!

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: PIC32MX270F256B Support?

Post by majenko » Wed May 18, 2016 10:54 am

1. Can I leave out the USB port from my MCU circuit and opt to only use ICSP port 1 for both boot loader flashing and sketch uploading?
No. It's ICSP for direct programming, and USB for bootloader programming. You can directly upload a sketch using the pickit3 if the sketch is linked appropriately, but this is done without the bootloader and, in fact, the bootloader will be eradicated by that process. There are ways of combining both a normally compiled sketch HEX file and the bootloader HEX file and uploading them both together from within MPLAB-X (as a "precompiled" project) but that's a bit nasty ;)

Basically it's either you have a bootloader and use the USB or you don't have a bootloader and you use ICSP - unless you want to try doing special things in MPLAB-X.
2. Once I get MPLAB X to recognise the 270F256B as Chipkit compatible- I use my PICKIT3 to flash the boot loader and also to upload the sketches to my MCU - BUT Does the MCU need to be put into programmer mode for sketch uploading too (from the DIY cct there's a button)? How does MPLAB know the difference between bootloader and sketch uploading and not overwrite one another?
When you link the sketch you either link it with a bootloader-enabled linker script, or a non-bootloader enabled linker script. The former filters out any config bits and places the code in the right locations to run with the bootloader. The latter has its own set of config bits embedded in it (and so has to be tailored to the specific board) and the bootloader is overwritten during writing.
3. Can any debugging be used to check variable values as the MCU is running? Ie with my Pickit connected somehow?
If you burn a non-bootloader version, or a combined bootloader + bootloader-enabled version to the chip using MPLAB-X you can use all the debugging tools that MPLAB-X provides - breakpoints, watches, etc.
4. Are there any limitations that the Arduino bootloader faces on a PIC32MX270F? Im concerned that the internal clock might not be fast enough for WS2812B LEDs as many Chipkit examples online run on 80mhz clocks.
No, there's no limitations as such. Once the bootloader has finished installing your sketch it's not used again (except to start your sketch running) so it's down to what your sketch can do. 40MHz (or 50Mhz if you have a -50 version of the chip) is plenty fast enough - after all, Arduinos do it at 16MHz :P The main limitation though is that (IIRC) the WS2812 library only supports a few boards at the moment, so you may need to add specific support to it for your board. IIRC it uses DMA, which the MX270 has, which is fine.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

rs2845
Posts: 18
Joined: Tue May 17, 2016 9:02 pm

Re: PIC32MX270F256B Support?

Post by rs2845 » Thu May 19, 2016 3:38 am

When you link the sketch you either link it with a bootloader-enabled linker script, or a non-bootloader enabled linker script.
Isn't the bootloader vital for the Arduino to function? How am I meant to get a sketch onto my MCU if the bootloader gets erased?

In an ideal world I would like a way to use MPLab X with my PICKit3, write a sketch, power up and it just "work" :D I just want a use for my Pickit3! Though if I have to use MPIDE and the USB port only, then it's okay.

Sorry again if all this is basic, but I really am a beginner with this! I have only used Picaxe and Atmel Arduino's before...

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: PIC32MX270F256B Support?

Post by majenko » Thu May 19, 2016 10:53 am

No. The bootloader merely provides a convenient method for uploading a sketch without needing a hardware programmer. If you want to use your hardware programmer then you don't need a bootloader. In fact, for debugging, the bootloader gets in the way. The debugger uses the top page of flash in the bootloader area to store its control software while you're debugging (breakpoints and things).

When using a pickit3 it's just the same as if you were programming a bare chip. There's nothing "fancy" there at all. In MPLAB-X you have all the things you would expect from a full development environment, but you don't get any of the ease-of-use the Arduino API gives you - things like simple libraries, integrated USB support, etc. You will either have to somehow port all that kind of thing into MPLAB-X or use (urgh) Harmony.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

rs2845
Posts: 18
Joined: Tue May 17, 2016 9:02 pm

Re: PIC32MX270F256B Support?

Post by rs2845 » Thu May 19, 2016 7:26 pm

In MPLAB-X you have all the things you would expect from a full development environment, but you don't get any of the ease-of-use the Arduino API gives you - things like simple libraries, integrated USB support, etc.
So with regards to this guide, it's confusing because how do people with Chipkit boards use the Arduino libraries etc - step 4 in that instruction article is a little sparse. Or are they using bare C without Arduino?

Harmony is meant to be "simple" but there's still a learning curve for me with things like the oscillator set up and the faff of using their "wizards" to add in libraries. There's also less example code online compared to Arduino

If I can't easily use Arduino's libraries in MPLab X, perhaps I should just learn Harmony.

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: PIC32MX270F256B Support?

Post by majenko » Thu May 19, 2016 8:05 pm

In that page they aren't using the Arduino libraries - just programming in plain C using XC32.

Harmony is not simple. It's a complete and utter nightmare.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

rs2845
Posts: 18
Joined: Tue May 17, 2016 9:02 pm

Re: PIC32MX270F256B Support?

Post by rs2845 » Thu May 19, 2016 8:25 pm

So, to sum up my two options then from the above:

Option 1:- Use MPIDE and the Arduino bootloader to program my sketch via USB.
If I wish to debug I could just make a debug function that printf's my variables to the screen.
Positives:
- Faster development
- Superior support
- I don't pull my hair out.

Negatives:
- Need to add USB ports to all my MCU's
- PICKIT gathers dust


Option 2:- Use MPLAB X and my PICKIT3, but have a lifetime of learning and trouble

Positives:
- my PICKIT gets use
- I learn industry standard tools(?)
- I get to debug easily and to a higher standard

Negatives:
- Hard to learn harmony
- Lack of code examples
- Things won't be simpler.

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: PIC32MX270F256B Support?

Post by majenko » Thu May 19, 2016 9:52 pm

Option 3:

Use UECIDE to compile with a non-bootloader linker script, then use MPLAB-X with your PICKIT3 to program and debug the .elf file it produces.

That's what I do. It's a reasonable half-way house. It gives you the ease of programming of the Arduino API and libraries, with a much nicer user interface, and then when you need to do the debugging you switch over to MPLAB-X and do the debugging. In UECIDE it is possible to program (though not debug) the .elf into the board using the PICKIT3 and "MDB" which comes with MPLAB-X (it's a java file that can do rudimentary debugging).
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

Post Reply