A rainy Sunday afternoon gave me the perfect motivation to begin re-testing the projects and code examples of the “Graphics, Touch, Sound and USB” book with a PIC32 Mikromedia board to verify the claimed portability of the whole experience across 16 and 32-bit platforms.
The first step was to create a new
PICConfig.h file to set the proper PIC32MX460F512L configuration bits, easy!
Next was adapting the HardwareProfile.h to the specific pin assignments used on the PIC32 Mikromedia: just a few touches here and there (80MHz, 16-bit PMP, a pair of I/Os…). Mind I had done all this before (actually long before the PIC24 MIkromedia existed) but years have passed, MLA revisions have changed, and even the PIC32 Mikromedia has changed a little since the early prototypes I had been privileged to play with and test.
uMedia.c support module was my next adaptation. The PIC32 cache needs to be initialised, interrupt mode must set, Jtag port has to be disabled, so it is a good idea to call the uMBInit() in every project right from the start.
Then I began re-testing starting from Chapter 3, when the MLA Graphics lib starts flexing muscles. Obviously Bitmaps and Fonts need to be re-packaged for the PIC32 using the GRC tool with the 32-bit setting. Note that any individual resource that is smaller than 32K can be packaged directly in 32-bit mode and will be accepted by both XC16 and XC32 (see the LCDTerminalFont.c as an example!).
Chapter 4, the Touch support module required the first use of interrupt (Timer3 sets the touch scanning state machine rithm) and the PIC32 uses a different pragma syntax:
#define _TIMER3_ISR __attribute__(( vector(_TIMER_3_VECTOR), interrupt(ipl1), nomips16))
But also the timer3 interrupt flag ‘shortcut’ (_T3IF) is missing in the device definition and I ‘d better use the full spelling: IFS0bits.T3IF.
More, the PIC32 interrupt mechanism requires a specific interrupt priority level to be assigned (the default is 0) or no interrupt will be generated regardless of the enable bit state: I PC3bits.T3IP = 1;
Chapter 5, SD card and Serial Flash worked as a charm.
Chapter 6, exercising the Audio Codec required a few more changes to the support module V1053.c because of the rearranged SPI registers. Note, lesson learned, this was one of the places where using the peripheral libs from the very beginning would have paid off!
Chapter 7, GOL at this point was a walk in the park, but I have left the GDD projects for later as I rushed to check the last two USB projects in Chapter 8. Once the USB PLL is turned on, adding a pragma to the PICConfig.h, all is well and both the CDC Serial Port emulation and the HID Simple demo worked right away.
In summary, a few rough spots were identified here and there, mostly punishing me for going too low level with the Audio Codec and the SPI/Timer peripherals.
A few more checks and then I will be ready to post the entire set of source codes (repository and archive) for the PIC32 Mikromedia on BitBucket….