MicroPython & PIC32 chips

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
AriZuu
Posts: 3
Joined: Thu May 07, 2015 3:50 pm
Location: Lemi, Finland
Contact:

MicroPython & PIC32 chips

Post by AriZuu » Thu May 07, 2015 4:03 pm

Hi,

I have been compiling MicroPython for Microchip PIC32 chip. I was first targetting to quite small chip, pic32mx250f128b, which has
only 128 Kb of flash. After compiling a binary I found that that would be to small, at least 256 Kb of flash would be needed.

I'm not developing on bare metal, but on rtos called Pico]OS instead (because I find it nice, and have been doing all kind
of stuff with it earlier). Although my current chips were too small, I had partial success, meaning that the resulting binary
runs (well, starts up) with MPLAB X simulator.

While waiting for bigger chips, I'm just wondering about the assembly stuff that there is in MicroPython for other platforms.
I'm now compiling the unix/gccollect.c with MICROPY_GCREGS_SETJMP set to 1, can anyone comment if that is OK ? If ok, that's nice,
but I could also write similar assembly as there seems to be for other platforms.

All my stuff is at http://github.com/AriZuu/python-test if someone is interested in Pico]OS & MicroPython combo. It's all
pretty preliminary, as I discovered all this MicroPython stuff just a few days ago.

Ari S.

Damien
Site Admin
Posts: 634
Joined: Mon Dec 09, 2013 5:02 pm

Re: MicroPython & PIC32 chips

Post by Damien » Thu May 07, 2015 11:54 pm

The PIC32 uses a MIPS architecture and instruction set which does not have as good code density as Thumb2, hence why you need more than 128k flash.

I'd be interested to hear if you do get this working on actual hardware :)

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: MicroPython & PIC32 chips

Post by pfalcon » Fri May 08, 2015 12:15 am

MIPS has MIPS16 as analog of ARM's Thumb, you can see if PIC32 (or this particular chip) supports it.

Contributing MIPS assembly is surely welcome, and it'll save some stack space and few cpu clocks.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

AriZuu
Posts: 3
Joined: Thu May 07, 2015 3:50 pm
Location: Lemi, Finland
Contact:

Re: MicroPython & PIC32 chips

Post by AriZuu » Fri May 08, 2015 6:00 am

Mips16 code would definitively help, but unfortunately, xc32-gcc -mips16 results in:
warning: Pro Compiler option (mips16 mode) ignored because the free XC32 C compiler does not support this feature

Pro compiler seems to cost > 900 € :-(

As bigger chips are ~4€ I think I'll try first with those.

XC32 compiler is actually gcc and the source code is available. There are also instructions how one can
create a compiler from those sources, bypassing the limitations. But I am under impression
that one has to provide c runtime (newlib would be obvious choice) and startup code.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: MicroPython & PIC32 chips

Post by pfalcon » Fri May 08, 2015 1:59 pm

AriZuu wrote:Mips16 code would definitively help, but unfortunately, xc32-gcc -mips16 results in:
warning: Pro Compiler option (mips16 mode) ignored because the free XC32 C compiler does not support this feature

Pro compiler seems to cost > 900 € :-(

As bigger chips are ~4€ I think I'll try first with those.

XC32 compiler is actually gcc and the source code is available. There are also instructions how one can
create a compiler from those sources, bypassing the limitations.
Well, normal MIPS compiler isn't reality a scarcity, all that veil of superoptimizations which 1K$ vendor compiler does is, well, a marketing campaign (which apparently only hurts them). OpenWRT for example has MIPS compiler with MIPS16 support, generating code which works well in QEMU (trying it all on real hardware is ~ a year in TODO, which is fun, because that's what *I* really wanted uPy for - running on small routers).

https://github.com/pfalcon/micropython/commits/cross has scripts I used for this building and testing.
But I am under impression
that one has to provide c runtime (newlib would be obvious choice) and startup code.
That's certainly true, but it's not a rocket science not black magic either. I see you starred https://github.com/pfalcon/cortex-uni-startup , so you now I tried to do my share to demystify how to do it for Cortex-M's, it's certainly doable for other arch's (the biggest problem is that people usually do it for a particular chip, so there's no critical mass for such projects to become useful).
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

AriZuu
Posts: 3
Joined: Thu May 07, 2015 3:50 pm
Location: Lemi, Finland
Contact:

Re: MicroPython & PIC32 chips

Post by AriZuu » Fri May 08, 2015 4:28 pm

Well, normal MIPS compiler isn't reality a scarcity, all that veil of superoptimizations which 1K$ vendor compiler does is, well, a marketing campaign (which apparently only hurts them). OpenWRT for example has MIPS compiler with MIPS16 support, generating code which works well in QEMU (trying it all on real hardware is ~ a year in TODO, which is fun, because that's what *I* really wanted uPy for - running on small routers).

https://github.com/pfalcon/micropython/commits/cross has scripts I used for this building and testing.
True. I have been building cross-compiler for Cortex-M on FreeBSD, that wasn't difficult at all. I suppose it woudn't be
more difficult for mips.

About startup:
That's certainly true, but it's not a rocket science not black magic either. I see you starred https://github.com/pfalcon/cortex-uni-startup , so you now I tried to do my share to demystify how to do it for Cortex-M's, it's certainly doable for other arch's (the biggest problem is that people usually do it for a particular chip, so there's no critical mass for such projects to become useful).
I do my own startup for Cortex-M (but have been keeping an eye on your cortex-uni-startup stuff), pic32 has a little bit different way for handling interrupt vectors and memory layout, but I could manage those. But there is still a big part missing - header files for device perhipheral registers.
A microcontroller is not very useful without it's peripherals. Maybe one could use those from XC32, however.

Here is a link to one effort for building pic32 toolchain:
http://wise-ware.org/wiki/

I hope there will be some kind of progress with open source toolchain, as I'm really wondering were Microchip is going with
their stuff. They are abandoning their peripheral libraries in favor of "Harmony", which looks like a library / code generator
for building firmwares based on state machine architecture. Looks really complex to me, and more or less forces
to adopt the architecture they are using.

Although pic32mx chips are nice for hobbyist (it will be nice to have python running on DIP28 chip on breadboard), I think
on the openness the Arm chips are a winners today.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: MicroPython & PIC32 chips

Post by pfalcon » Sat May 09, 2015 11:23 am

AriZuu wrote: But there is still a big part missing - header files for device perhipheral registers.
Well, I have a card for that in a pocket too ;-) - https://github.com/pfalcon/libperipha . The idea with it is not that someone will sit for a month and makes a complete description of particular chip, but would add needed things bit by bit, as need arises. I practiced that while working on my other project, https://github.com/pfalcon/PeripheralTemplateLibrary . Both projects are on back-burner though after uPy source code was released ;-). One problem with them is that to be useful, there should be critical mass of people who use/contribute to them. I didn't do much to publicize them beyond a blog post:
http://pfalcon-oe.blogspot.com.tr/2013/ ... x-uni.html .
Although pic32mx chips are nice for hobbyist (it will be nice to have python running on DIP28 chip on breadboard), I think
on the openness the Arm chips are a winners today.
I was *very excited* when PIC32MX chips were released, exactly because they seemed as the most accessible 32-bit MCU (and with a reputable arch) in DIP (accessible because I could find local distributor for them, while ARM DIPs remained more of press-release stuff). But I didn't see community grow around them, apparently because of scarcity of boards, pricing on them, and those tooling issues. I was skipping them either then,why if ARM chips are abundant, competitive, and there's that point when you no longer depend on DIPness ;-). I bought a PIC32 board last Xmas, but it as usual joins couple of dozens other boards in a personal museum-in-a-table-drawer.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

EasyRider
Posts: 94
Joined: Wed Dec 30, 2015 8:17 am

Re: MicroPython & PIC32 chips

Post by EasyRider » Tue Jan 26, 2016 12:12 am

Has anyone made any further progress in porting Micropython to PIC32MX?

Looking at posts in this thread, main issue appears to be ability to set up/use gcc MIPS compiler.

These guys have detailed instructions on how to set up gcc with NewLib for PIC32.
I haven't played with compiler/cross compiler setups, so this is above my head, don't know if similar setup may help/work ?

http://www.wise-ware.org

I couldn't open the previous link in my Win-7 Chrome browser, but this one worked for me.

https://translate.google.com/translate? ... rev=search

User avatar
bmarkus
Posts: 111
Joined: Tue Oct 21, 2014 5:58 am

Re: MicroPython & PIC32 chips

Post by bmarkus » Tue Jan 26, 2016 1:41 pm

I'm planning to port MicroPython to PIC32. Target hardware is MM28 and MM44. They have the same PIC32MX170F256 processor, difference is number of I/O ports:

Image

Regards... Béla
Tiny Core Linux (piCore) developer
HAM radio call: HA5DI (Béla)

EasyRider
Posts: 94
Joined: Wed Dec 30, 2015 8:17 am

Re: MicroPython & PIC32 chips

Post by EasyRider » Tue Jan 26, 2016 9:53 pm

Sounds positive bmarkus,
I am interested in exactly the same MX170 chips.
Please keep us updated with your progress and Good Luck.
Regards
John

Post Reply