chipKIT® Development Platform

Inspired by Arduino™

PIC32MX270F256B Support?

Created Tue, 17 May 2016 20:20:46 +0000 by rs2845


rs2845

Tue, 17 May 2016 20:20:46 +0000

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...


majenko

Tue, 17 May 2016 23:30:55 +0000

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 [url]https://github.com/majenkotech/PIC32-avrdude-bootloader/blob/master/bootloaders/configs/majenko.h[/url]) and also the Lenny entry in [url]https://github.com/majenkotech/PIC32-avrdude-bootloader/blob/master/bootloaders/Makefile[/url].

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...


rs2845

Wed, 18 May 2016 04:44:58 +0000

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!


majenko

Wed, 18 May 2016 09:54:45 +0000

  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.

  1. 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.

  1. 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.

  1. 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.


rs2845

Thu, 19 May 2016 02:38:03 +0000

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...


majenko

Thu, 19 May 2016 09:53:03 +0000

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.


rs2845

Thu, 19 May 2016 18:26:46 +0000

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.


majenko

Thu, 19 May 2016 19:05:59 +0000

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.


rs2845

Thu, 19 May 2016 19:25:43 +0000

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.

majenko

Thu, 19 May 2016 20:52:14 +0000

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).


Marevealous

Tue, 02 Aug 2016 12:53:56 +0000

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).

Hey, what is the state of PIC32MX270F256B support? Does it have a working USB bootloader for chipkit? Which hex file is that? (Again, the names are confusing, why not name bootloaders with prefix of chip name)..


majenko

Tue, 02 Aug 2016 15:23:30 +0000

MX270 is fully supported. The Lenny board uses the MX270F256D chip and is part of the standard repertoire of chipKIT now.

There is no active board with the B version though so there is no pre-built bootloader for that chip. Only the D version for the Lenny. A B version can be built easily enough though should it be required - if you provide the pin definitions for it of course.

The reason the bootloaders are named after the boards and not the chips is because the bootloader is specific to the board. You can have multiple boards that use the same chip yet require their own distinct bootloaders because the IO pin definitions and config bits are different.

All the major boards are listed in the wiki (http://chipkit.net/wiki/index.php?title=Boards) with the chips they use. Find a board that uses the same chip you want to use and replicate the relevant parts. That way you can use the same bootloader as that board.


Marevealous

Tue, 02 Aug 2016 19:01:25 +0000

Only the D version for the Lenny. A B version can be built easily enough though should it be required - if you provide the pin definitions for it of course.

Well... http://wiki.pinguino.cc/images/7/75/Pinguino32-DIY-schematic-corrected_june_2013.png That's the PCB I have. I will program PIC32MX270F256B with pic32 prog (already tested and working) and put that chip there (socket). So the pin definitions are: LED PIN: 2 BOOTLOADER button (on press it's connected to ground): 3 Is this what you meant? Thanks in advance.


majenko

Tue, 02 Aug 2016 19:54:07 +0000

Yep, that's just what I meant. Here's a bootloader compiled with those pins and that chip / crystal combination.


Marevealous

Wed, 03 Aug 2016 00:06:25 +0000

That's great! LED blinks happily and PC detects some STK500v2 device, but... what now ?

Well, I will try to follow http://chipkit.net/diy-chipkit-board/, but what board should I select?

UPDATE: I have manuall installed the chipkit core libraries for Arduino IDE (the downloaded from within IDE stuck at 0kb), and now I separately downloaded the USBDriverInstaller.exe and installed the USB drivers. So now the question is which board should I choose? Now I have a virtual chipkit serial in my Devices Mangager.

UPDATE2: I've chosen Lenny board, is that correct? I have now:

Programmer for Microchip PIC32 microcontrollers, Version 2.0.220
    Copyright: (C) 2011-2015 Serge Vakulenko
      Adapter: STK500v2 Bootloader
 Program area: 1d000000-1d1fffff
    Processor: Bootloader
 Flash memory: 2048 kbytes
  Boot memory: 80 kbytes
         Data: 6228 bytes
        Erase: done
Program flash: ........######### done
 Verify flash: ........######## done
 Program rate: 36635 bytes per second

but I don't even know which PIN number has my LED which I'd like to blink...

UPDATE: I've managed to receive something in realterm from CDC. Code:

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // print out the state of the button:
  Serial.println("Hello");
  delay(1);        // delay in between reads for stability
}

Questions:

  1. which pin number here is my LED?
  2. How to know which pin has which number?
  3. Why can't I view CDC messages in Arduino terminal?
  4. IDE says that there is 128 KB memory and not 256...
  5. Sometimes I am getting random errors (with random file names) like:
Arduino\hardware\chipkit-core\pic32\cores\pic32\pins_arduino.c:86:0: fatal error: opening dependency file core\pins_arduino.c.d: No such file or directory

What's wrong? 6. It seems that the Arduino IDE with chipkit stuff does not check for the board compatitiblity, I mean, I tried both "Lenny board" and "Pinguino board" selection and in both cases it downloaded the code! 7. Huh, I have managed to blink a LED, but, oh, well, see yourself:

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  for(int i = 0; i < 25; i++)
  {
    pinMode(i, OUTPUT);
  }
}

// the loop function runs over and over again forever
void loop() {
  for(int i = 0; i < 25; i++)
      digitalWrite(i, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  for(int i = 0; i < 25; i++)
      digitalWrite(i, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

It indeed works, and I'm pretty happy because pinMode and digitalWrite functions are able to take a variable as pin index.


majenko

Wed, 03 Aug 2016 10:06:19 +0000

You require a specific board configuration that matches your circuit. Not only must the chips match (at least broadly), but the IO pin definitions must be configured right.

Without that things like digitalWrite() etc won't know where to route the commands.

Selecting a similar board may kind of work, but the IO pin numbers won't even remotely resemble your board.

Without a board configuration the closest you can really do is pick one with the same base chip and manually control the chip using the low-level registers, like TRISA, PORTA, LATA, etc.


Marevealous

Wed, 03 Aug 2016 10:31:25 +0000

Which files do I edit? Only boards.txt?

Btw, is this just purely inlogical, or did I find a bug:

# 128KB - 4K for EEPROM - 4K for bootloader
lenny.upload.maximum_size=122880
lenny.upload.speed=115200
lenny.upload.tool=pic32prog

( ... )

lenny.build.mcu=32MX270F256D
lenny.build.f_cpu=40000000L
lenny.build.core=pic32
lenny.build.variant=Lenny

32MX270F256D has 128KB? The wiki says that Lenny has 256KB: http://chipkit.net/wiki/index.php?title=ChipKIT_Lenny PS: I have used chipkit-core-windows.16778040.master-v1.2.0-4-g3088e62.zip pack.


majenko

Wed, 03 Aug 2016 11:33:57 +0000

Yes, that is a mistake. It shouldn't affect anything though, it's just for reporting of sketch size %.

It's the Board_Data.c and Board_Defs.h files that define how the board is layed out.


Marevealous

Wed, 03 Aug 2016 12:30:12 +0000

So now, if I want to use Serial0 and Serial1 (because Serial is just USB virtual com port) on my board, and also I2C and SPI (assuming that it's supported), I need to change those files?

Those are .c files, do I need to recompile and reburn bootloader as well?

*/ #define _SER1_BASE _UART1_BASE_ADDRESS #define _SER1_IRQ _UART1_ERR_IRQ #define _SER1_VECTOR _UART_1_VECTOR #define _SER1_IPL_ISR _UART1_IPL_ISR #define _SER1_IPL _UART1_IPL_IPC #define _SER1_SPL _UART1_SPL_IPC #define _SER1_TX_OUT PPS_OUT_U1TX #define _SER1_TX_PIN 2 #define _SER1_RX_IN PPS_IN_U1RX #define _SER1_RX_PIN 4

I understand what is TX_OUT and RX_IN, because it's using PPS system just like the PIC32 in mikroC and I used that before. But what is 2 and 4 here? Is 2 and 4 here just for the Arduino, or is this some value from PIC datasheet?


majenko

Wed, 03 Aug 2016 12:32:32 +0000

2 and 4 refer to entries in the pin definition tables in Board_Data.c. Those are the main ones that you need to edit to suit your board arrangement.

And no, you don't need to reburn the bootloader. These files are compiled as part of your sketch and uploaded from the IDE.


Marevealous

Wed, 03 Aug 2016 13:06:18 +0000

Is there any tutorial how to add a new board? I mean, I know that I will copy the "Lenny" directory, and also copy its definition in boards.txt, but I'm not sure, is that all?

I will also rename in those new files all "Lenny" occurences to "my_new_board", right?


majenko

Wed, 03 Aug 2016 13:20:21 +0000

Creating a new board definition is quite a complex task and not something that most people would undertake. So there's not really any tutorials as such. There are still some aspects of those files that I don't fully understand (how all the analog tables and things relate together).

I have started work on a web-based program to build board definitions for you, but making it (thanks to PPS) is a rather complex task. It's going to be a long long time before it's even able to be tested...


Marevealous

Thu, 04 Aug 2016 09:28:31 +0000

Do you mean "Creating a new board definition" as in "creating new"?

For the start, I'd like just to copy the Lenny definition, rename it to something like "My_Board". Is this also complicated?

EDIT: I need working Serial0 and Serial1 for this board, also PWM and ADC. Will it work with Lenny board without any modifications?


majenko

Thu, 04 Aug 2016 17:51:35 +0000

You will need to copy all the Lenny files and change them. The main thing to do is to set the right number of io pins in the header file and change all the entries in the pin tables in the c file to be what your setup is.

You might be better off starting with the dp32 files since it has a 28 pin chip not 44 pin, and change the chip type in the boards.txt file.

Sent from my SM-T555 using Tapatalk


rs2845

Thu, 04 Aug 2016 19:53:18 +0000

Just wanted to say, you've also helped me as I was beginning to ask myself the same questions!

It'd be great if someone published a definitive, clear-cut guide as to the steps to take for either the 270F256B and other boards. Majenko your website tool will be great when completed!


guymc

Thu, 04 Aug 2016 21:42:22 +0000

Well, there is a detailed guide about adding new board definition files (aka, variant files)

Go to the front page of chipkit.net and search for "board variant"

Cheers!