embedXcode: Use MPIDE with Apple Xcode
The MPIDE is great and provides plug-and-play and instant gratification but, sometimes, complex sketches require a more powerful IDE. Also, some niceties are welcomed, as syntax colouring, line numbering, function highlighting, code-sense, template with parameters for a function, check-as-you-type, click-to-error, tool-tip texts, object browser, self documentation, version management, repository management, code snippets, Git repository management and even debugging…
I’m using Xcode because I own a MacBook. Xcode is flexible enough to deliver code-sense with just being provided the paths of the source libraries. And the main benefit is faster development.
Modular Set of Makefiles
The paradigm is that a sketch consists on a standard C++ code, and thus processed accordingly. embedXcode requires the prior installation of the IDEs like MPIDE, as they include everything, including tool-chain, framework and utilities. embedXcode relies on a modular set of makefiles, which can be used with other IDEs. I use Xcode because I own a MacBook, but I tested the set of makefiles successfully with NetBeans. As at today, embedXcode supports the most popular Processing-based Wiring-derived Arduino-like platforms: chipKIT MPIDE, Arduino (23 + 1.0 + 1.5), Digistark, DFRobot BLuno, LaunchPad (MSP430, FR5739 and Stellaris LM4F), LeafLabs Maple, Microduino, Teensy 3 and Wiring.
- Install MPIDE normally and run it once
- Double-click on the embedXcode installation package to install the template
- Launch Xcode
Dedicated Website and Forum Thread
The dedicated website includes:
Also check the MPIDE on Xcode thread on the chipKIT forum.
Running on Microchip Starter Kits
- PIC32 Starter Kit
- PIC32 USB Starter Kit
- PIC32 Ethernet Starter Kit
- Explorer 16 Starter Kit
Using other PIC32 boardsAs far as using MPIDE with other boards, the answer is YES, it should work with ANY PIC32 there is. The only limit might be it won’t work on chips smaller than 32K, And that’s because it hasn’t been tried on anything smaller. To get it to work on other boards, a few things have be be done.
- First, the bootloader has to be burned onto the target board. The source is on github and MPLAB is used to compile and burn the bootloader. The multi-platform MPLAB-X was used on a Mac, but other versions should work as well.
- If you using a chip that has not already been added to avrdude.conf, that has to be done.
- You need to add a new entry to boards.txt and then you will be able to program the board directly from MPIDE.
- Microchip PIC32 USB starter kit
- Microchip PIC32 Ethernet starter kit
- UBW32 – MX460
- UBW32 – MX795
- Fubarino SD
- Fubarino Mini
- PIC32-avrdude-bootloader – This new bootloader for MPIDE/chipKIT PIC32 boards is buildable for all currently available chipKIT boards (UNO32, MAX32, uC32) as well as other PIC32 based boards like the UBW32 and Fubarino boards.
- pic32-Arduino-USB-Bootloader-original – This is the original version of the bootloader that works only if compiled with the C32 v1.xx version due to changes in the way that newer version of C32/XC32 handles the linker scripts files.
- pic32-Arduino-Bootloader – This is the older original version of the bootloader which supports only Digilent uno and mega pic32 boards.This bootloader is compatible with v5.8 of avrdude.
- For Digilent pic32 boards, it is highly recommended to download the Digilent official bootloader from the Digilent website at http://www.digilentinc.com/.
> dim motor1 as pin 3 for servo output > let motor1=1000 > _In StickOS BASIC, it is equally trivial to use timers, UARTs, advanced I2C or SPI peripherals, as well as HD44780-compatible LCDs and simple scanned keypads. And most importantly, it can all be done interactively — no more guessing what your MCU is up to! The StickOS debugger supports command-line program interruption, breakpoints, assertions, watchpoints, live variable (and pin) manipulation and examination, execution tracing and single-stepping, sampling profiling, and even edit-and-continue! When you’re ready to move up, you can then port your BASIC program to C using the MPLAB X StickOS Skeleton project, and take advantage of all the same pin/peripheral configuration, flash manipulation, etc., used by StickOS BASIC. A detailed introduction to StickOS on the chipKIT boards is here: http://www.cpustick.com/chipkit.htm An overview of the StickOS BASIC language features is in the Quick Reference guide, here: http://www.cpustick.com/downloads/quickref.v1.82.pdf More information and downloads for the chipKIT boards are available here: http://www.cpustick.com/downloads.htm
avr/pgmspace.h (AVR)Tools to access program space of the AVR processor, not needed on PIC32, but some macros can be used in its place to make AVR code run on a PIC32. <source>
- if defined(__PIC32MX__)
// neither PROGMEM or PSTR are needed for PIC32, just define them as null #define PROGMEM #define PSTR(s) (s)
#define pgm_read_byte(x) (*((char *)x)) #define pgm_read_byte_near(x) (*((char *)x)) #define pgm_read_byte_far(x) (*((char *)x)) #define pgm_read_word(x) (*((short *)x)) #define pgm_read_word_near(x) (*((short *)x)) #define pgm_read_workd_far(x) (*((short *)x)) #define prog_void const void #define prog_char const char #define prog_uchar const unsigned char #define prog_int8_t const int8_t #define prog_uint8_t const uint8_t #define prog_int16_t const int16_t #define prog_uint16_t const uint16_t #define prog_int32_t const int32_t #define prog_uint32_t const uint32_t #define prog_int64_t const int64_t #define prog_uint64_t const uint64_t
- include <avr/pgmspace.h>
coffee.hThe start of all good programming sessions.
plib.h (PIC32)Contains type definitions for PIC32 registers.
SPI.h (AVR|PIC32) portedLibrary to provide SPI communications.
stdint.h (AVR|PIC32) ported
Arduino-32MX795F512L>V show interrupt Vectors FLASH_PROG_BASE=9D000000 EBASE =9D000000 IntCtl =00000020 VectorSpacing =00000001 +++ 0= 02 00---0B4017F0 jump 9D005FC0 _CORE_TIMER_VECTOR +++ 1= 00 00---FFFFFFFF unused _CORE_SOFTWARE_0_VECTOR +++ 2= 00 00---FFFFFFFF unused _CORE_SOFTWARE_1_VECTOR +++ 3= 00 00---FFFFFFFF unused _EXTERNAL_0_VECTOR +++ 4= 00 00---0B401E5A jump 9D007968 _TIMER_1_VECTOR +++ 5= 00 00---FFFFFFFF unused _INPUT_CAPTURE_1_VECTOR +++ 6= 00 00---FFFFFFFF unused _OUTPUT_COMPARE_1_VECTOR +++ 7= 00 00---FFFFFFFF unused _EXTERNAL_1_VECTOR +++ 8= 00 00---FFFFFFFF unused _TIMER_2_VECTOR +++ 9= 00 00---FFFFFFFF unused _INPUT_CAPTURE_2_VECTOR +++10= 00 00---FFFFFFFF unused _OUTPUT_COMPARE_2_VECTOR +++11= 00 00---FFFFFFFF unused _EXTERNAL_2_VECTOR +++12= 00 00---FFFFFFFF unused _TIMER_3_VECTOR +++13= 00 00---FFFFFFFF unused _INPUT_CAPTURE_3_VECTOR +++14= 00 00---FFFFFFFF unused _OUTPUT_COMPARE_3_VECTOR +++15= 00 00---FFFFFFFF unused _EXTERNAL_3_VECTOR +++16= 00 00---FFFFFFFF unused _TIMER_4_VECTOR +++17= 00 00---FFFFFFFF unused _INPUT_CAPTURE_4_VECTOR +++18= 00 00---FFFFFFFF unused _OUTPUT_COMPARE_4_VECTOR +++19= 00 00---FFFFFFFF unused _EXTERNAL_4_VECTOR +++20= 00 00---FFFFFFFF unused _TIMER_5_VECTOR +++21= 00 00---FFFFFFFF unused _INPUT_CAPTURE_5_VECTOR +++22= 00 00---FFFFFFFF unused _OUTPUT_COMPARE_5_VECTOR +++23= 00 00---FFFFFFFF unused _SPI_1_VECTOR +++24= 00 00---0B401B67 jump 9D006D9C _I2C_3_VECTOR _UART_1A_VECTOR _UART_1_VECTOR _SPI_1A_VECTOR _I2C_1A_VECTOR _SPI_3_VECTOR +++25= 01 00---FFFFFFFF unused _I2C_1_VECTOR +++26= 00 00---FFFFFFFF unused _CHANGE_NOTICE_VECTOR +++27= 01 00---FFFFFFFF unused _ADC_VECTOR +++28= 00 00---FFFFFFFF unused _PMP_VECTOR +++29= 00 00---FFFFFFFF unused _COMPARATOR_1_VECTOR +++30= 00 00---FFFFFFFF unused _COMPARATOR_2_VECTOR +++31= 00 00---0B401BDD jump 9D006F74 _UART_2A_VECTOR _I2C_2A_VECTOR _SPI_2_VECTOR _SPI_2A_VECTOR _I2C_4_VECTOR _UART_3_VECTOR +++32= 00 00---0B401C53 jump 9D00714C _UART_2_VECTOR _SPI_3A_VECTOR _I2C_3A_VECTOR _UART_3A_VECTOR _SPI_4_VECTOR _I2C_5_VECTOR +++33= 00 00---FFFFFFFF unused _I2C_2_VECTOR +++34= 00 00---FFFFFFFF unused _FAIL_SAFE_MONITOR_VECTOR +++35= 01 00---FFFFFFFF unused _RTCC_VECTOR ===36= 00 00---FFFFFFFF unused _DMA_0_VECTOR ===37= 00 00---FFFFFFFF unused _DMA_1_VECTOR ===38= 00 00---FFFFFFFF unused _DMA_2_VECTOR ===39= 00 00---FFFFFFFF unused _DMA_3_VECTOR ===40= 00 00---FFFFFFFF unused _DMA_4_VECTOR ===41= 00 00---FFFFFFFF unused _DMA_5_VECTOR ===42= 00 00---FFFFFFFF unused _DMA_6_VECTOR ===43= 00 00---FFFFFFFF unused _DMA_7_VECTOR ===44= 00 00---FFFFFFFF unused _FCE_VECTOR ===45= 00 00---FFFFFFFF unused _USB_1_VECTOR ===46= 00 00---FFFFFFFF unused _CAN_1_VECTOR ===47= 00 00---FFFFFFFF unused _CAN_2_VECTOR ===48= 00 00---FFFFFFFF unused _ETH_VECTOR ===49= 00 00---0B401BA2 jump 9D006E88 _UART_4_VECTOR _UART_1B_VECTOR ===50= 00 00---0B401C18 jump 9D007060 _UART_6_VECTOR _UART_2B_VECTOR ===51= 00 00---0B401C8E jump 9D007238 _UART_5_VECTOR _UART_3B_VECTOR
Note: Information in this post applies to MPIDE, which has been deprecated. The recommended IDE for chipKIT core is now Arduino IDE or UECIDE. MPIDE still offers support for legacy code. For more information about MPIDE, please visit the legacy Install Page.
This is a fork of the compiler from about October 2010. So it’s ahead of the Microchip MPLAB C32 v1.12 release, but behind the upcoming C32 v2.00 release. Basically it’s similar to C32 v1.12, but updated to GCC 4.5.1. Also, the default linker scripts are modified to work with the chipKIT bootloader. There are no optimization restrictions in this build, but it will likely be updated less often than the official MPLAB C32 compiler.
Source code: https://github.com/chipKIT32/chipKIT-cxx
MPIDE Compiler optimisation
Currently, MPIDE is configured to call the compiler with the -O2 optimization option. The -O2 set of optimization usually results in a nice balance between code size and speed. However, there are some instances where you want to sacrifice code size (use more FLASH memory) in order to get more speed. Luckily, Rick has introduced features in MPIDE that makes changing the default compiler options easy to change.
To change the optimization level:
1. Open the /hardware/pic32/platforms.txt file in your favorite text editor. 2. Find the lines beginning with pic32.compiler.c.flags and pic32.compiler.cpp.flags. In those lines, you should see a compiler optimization option, -O0, -O1, -O2, -Os, or -O3. 3. Change the optimization level option to the desired level, as listed below. 4. Save platforms.txt 5. Restart MPIDE.Optimization levels
-O0 - Disable optimizations -O1 - Reduce code size and execution time, without performing any optimizations that take a great deal of compilation time. -O2 - Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed trade-off. As compared to -O1, this option increases both compilation time and the performance of the generated code. (This is currently the default.) -O3 - Optimize yet more. GCC optimizes for maximum performance at the expense of code size. -Os - Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size.It also performs further optimizations designed to reduce code size.
pic32.compiler.c.flags=-O3::-c::-mno-smart-io::-ffunction-sections::-fdata-sections pic32.compiler.cpp.flags=-O3::-c::-mno-smart-io::-ffunction-sections::-fdata-sectionsIf you really want aggressive performance for your sketch, you could also add the -funroll-loops option. Note that this option almost always increases code size but it may or may not increase performance.