Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MPLAB IDE and Pinguino 32 DIY PIC32MX250F128B
12-01-2014, 10:11 PM,
#1
MPLAB IDE and Pinguino 32 DIY PIC32MX250F128B
Hi all, after a few days of experiments i've been able to use MPLAB_X to develop a program and upload it on the Pinguino 32 DIY board based on PIC32MX250F128B

Even if i consider the Pinguino IDE a great and valuable work for beginners, in my opinion, the features available on MPLAB_X are fairly better for those who need more control about what's happen underneath. It also allows using the Microchip Harmony platform which is rich of ready peripheral applications

So i want to share with the community the steps i've done to make the application working.

First in the MPLAB-X i picked a template with "New Project - Samples - Microchip Embedded and i choose PIC32 C Template.
Then in File - Project Properties i've selected the right processor and compiler XC32. In my case it was the PIC32MX250F128B but i guess the same procedure apply for all processor. Only pay attention to use the specific file tailored for your Pic.

At this point the template wizard has inserted in the program tree many .c and .h that are the skeleton for the application. If you choose to clean and build now the compiler should complete without errors even if the application don't do anything.
The .hex file generated at this point is not suitable to be uploaded through the bootloader because the absolute address of the program code and other memory areas does not take into account the structure the bootloader expect.

In order to make the application loadable with the bootloader you need to add a file in the program tree structure in MPLAB under the tab linker-files

1 Step. Copy the file
/opt/microchip/xc32/v1.31/pic32mx/lib/ldscripts/elf32pic32mx.x
in the root directory of your project, usually in the directory MPLABXProjects/

2 Step. Rename the file elf32pic32mx.x to elf32pic32mx.ld
then in MPLAB add this existing file in the Linker Files tree structure

3 Step. Open in MPLAB editor this file elf32PIC32MX.ld and remove the line that say
INCLUDE procdefs.ld

Now we have to add here the procdefs.ld file that came with the Pinguino IDE that have all the reference to the memory address areas. For my processor this file is
x.4/p32/lkr/PINGUINO32MX250/procdefs.ld under the directory where you installed the IDE.

4. Step Copy this file and insert it where it was INCLUDE procdefs.ld in the
elf32pic32mx.ld file

5. Step Since the template include the peripheral lib that has been excluded in the pinguino
ide procdefs.ld you need to add this two lines

/*************************************************************************
* Processor-specific peripheral libraries are optional
*************************************************************************/
OPTIONAL("libmchp_peripheral.a")
OPTIONAL("libmchp_peripheral_32MX250F128B.a")


after the line
INPUT("processor.o")

in the elf32pic32mx.ld file modified.

Now you can clean and rebuild everything that should be error free.
As a test i implemented a simple blink test for RA0 that in PInguino 32 DIY is the
userled in the board.

The hex file generated that is here
/MPLABXProjects/<name of your project>/dist/XC32_PIC32MX250F128B/production #

can be upload to the piguino board with pic32prog with the command

# pic32prog file.hex -D -S -p

All done. The led should start to blink ...
I hope that everything is clear.
I dont gave any listing since i guess that who need to use MPLAB instead of Pinguino IDE Know what to do following this instructions but if you need any more detailed info i will be glad to help.

Enjoy, Fabio.
Reply
13-01-2014, 05:25 PM,
#2
RE: MPLAB IDE and Pinguino 32 DIY PIC32MX250F128B
Would you like to add this to the Wiki ? It would be more accessible for all users.
Thank you.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
15-01-2014, 03:34 PM,
#3
RE: MPLAB IDE and Pinguino 32 DIY PIC32MX250F128B
Ok Regis, i will update the wiki ... just let me implement some example more complex than simple led blink to be sure everything work.

Currently i'm testing this setup with Microchip Harmony platform that has a very rich set of libraries. Drawback is that with the free version of XC32 compiler even for simple programs the flash memory is almost completely used because the harmony library is statically linked.

(13-01-2014, 05:25 PM)regis Wrote: Would you like to add this to the Wiki ? It would be more accessible for all users.
Thank you.
Reply
18-01-2014, 01:35 AM,
#4
RE: MPLAB IDE and Pinguino 32 DIY PIC32MX250F128B
Good news, i tested the procedure described here with more examples and it seem to work nice.
Harmony usage has been optimized using the level 1 optimization feature of XC32 compiler thas is available in the free version. Now the code is very small.
I updated the wiki and added a new entry in the main page under the Section Documentation.
Enjoy, Fabio.

(15-01-2014, 03:34 PM)fcapozzi Wrote: Ok Regis, i will update the wiki ... just let me implement some example more complex than simple led blink to be sure everything work.

Currently i'm testing this setup with Microchip Harmony platform that has a very rich set of libraries. Drawback is that with the free version of XC32 compiler even for simple programs the flash memory is almost completely used because the harmony library is statically linked.

(13-01-2014, 05:25 PM)regis Wrote: Would you like to add this to the Wiki ? It would be more accessible for all users.
Thank you.
Reply
18-01-2014, 03:01 PM,
#5
RE: MPLAB IDE and Pinguino 32 DIY PIC32MX250F128B
Great Fabio. Thanks a lot.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
22-05-2017, 11:45 AM,
#6
RE: MPLAB IDE and Pinguino 32 DIY PIC32MX250F128B
Hi, I'm trying to follow these steps to program a PINGUINO32-OTG board from Olimex (with a 32MX440F256H microcontroller), but I had no success and need some light. I'm using the following setup:
- MPLAB X IDE v3.61
- XC32 compiler from Microchip, v1.43
- Downloaded pic32prog from the pointed github project

The steps I followed:
1. Copied the file /opt/microchip/xc32/v1.43/pic32mx/lib/ldscripts/elf32pic32mx.x to the root directory of my project
2. Renamed the file elf32pic32mx.x to elf32pic32mx.ld and added it to the Linker Files tree structure of my project
3. Openned that file to edit and commented out the line that say INCLUDE procdefs.ld
4. As I was unable to find the procdefs.ld file under Pinguino, I copied the file /opt/pinguino/v12/p32/lkr/32MX440F256H.ld to my MPLAB project directory and iserted it where it was the old INCLUDE procdefs.ld I just commented in previous step
5. I added the lines
OPTIONAL("libmchp_peripheral.a")
OPTIONAL("libmchp_peripheral_32MX440F256H.a")
after the INPUT("processor.o") line
6. compiled but got a lot of errors from the Linker

So I did the following:
7- Noticed that in the 32MX440F256H.ld file I just inserted within elf32pic32mx.ld the INPUT("processor.o") line was commented, so I uncommented it
8. I added the line
PROVIDE(_ebase_address = 0x9D005000);
and commented the one
//_ebase_address = 0x9D005000;
9. I commented out sections .bev_excpt; .dbg_excpt; .dbg_code; .app_excpt on the elf32pic32mx.ld file, as the needed constants are commented in 32MX440F256H.ld
10. Compiled, but there were still errors.
11. I checked the box "Do not link startup code" under Project->Properties->Xc32-ld (option categories: libraries)
12. Compiled and now there is only one warning telling me "/opt/microchip/xc32/v1.43/bin/bin/gcc/pic32mx/4.8.3/../../../../bin/xc32-ld: warning: cannot find entry symbol _reset; defaulting to 9d006010"

13. I uploaded the code using prog32pic by typing "pic32prog MyProject.hex -D -S -p"

Apparently, the file was correctly uploaded, but the program did not work. WHAT IS WRONG?

This is the file elf32pic32mx.ld I finally used:

/* Default linker script, for normal executables */
OUTPUT_FORMAT("elf32-tradlittlemips")
OUTPUT_ARCH(pic32mx)
ENTRY(_reset)
/*
* Provide for a minimum stack and heap size
* - _min_stack_size - represents the minimum space that must be made
* available for the stack. Can be overridden from
* the command line using the linker's --defsym option.
* - _min_heap_size - represents the minimum space that must be made
* available for the heap. Can be overridden from
* the command line using the linker's --defsym option.
*/
EXTERN (_min_stack_size _min_heap_size)
PROVIDE(_min_stack_size = 0x400) ;
/* PROVIDE(_min_heap_size = 0) ; Defined on the command line */



/*************************************************************************
* Processor-specific object file. Contains SFR definitions.
*************************************************************************/

/*INPUT("processor.o")*/


/*************************************************************************
* Processor-specific object file. Contains SFR definitions.
*************************************************************************/
INPUT("processor.o")

/*************************************************************************
* Processor-specific legacy peripheral libraries are optional.
* These plibs are available as a separate download from
* http://www.microchip.com/mplabxc
* Use MPLAB Harmony for new projects.
* http://www.microchip.com/mplabharmony
*************************************************************************/
OPTIONAL("libmchp_peripheral.a")
OPTIONAL("libmchp_peripheral_32MX440F256H.a")


/* not PIC32 specific, so define them here */
BMXDUPBA = 0xBF882030;
BMXDKPBA = 0xBF882010;
BMXDUDBA = 0xBF882020;

/*************************************************************************
* For interrupt vector handling
*************************************************************************/
PROVIDE(_vector_spacing = 0x00000001);
PROVIDE(_ebase_address = 0x9D005000);

/*************************************************************************
* Memory Address Equates
*************************************************************************/
//_ebase_address = 0x9D005000;
_RESET_ADDR = 0x9D006000;

/*
_BEV_EXCPT_ADDR = 0x9D006380;
_DBG_EXCPT_ADDR = 0x9D006480;
_DBG_CODE_ADDR = 0xBFC02000;
_GEN_EXCPT_ADDR = _ebase_address + 0x180;
*/

/*************************************************************************
* Memory Regions
*
* Memory regions without attributes cannot be used for orphaned sections.
* Only sections specifically assigned to these regions can be allocated
* into these regions.
*************************************************************************/
MEMORY
{
exception_mem : ORIGIN = 0x9D005000, LENGTH = 0xA00
kseg0_boot_mem : ORIGIN = 0x9D005A00, LENGTH = 0x200
kseg1_boot_mem : ORIGIN = 0x9D006000, LENGTH = 0x10
kseg0_program_mem (rx) : ORIGIN = 0x9D006010, LENGTH = 0x39FF0
/*
debug_exec_mem : ORIGIN = 0xBFC02000, LENGTH = 0xFF0
*/
config3 : ORIGIN = 0xBFC02FF0, LENGTH = 0x4
config2 : ORIGIN = 0xBFC02FF4, LENGTH = 0x4
config1 : ORIGIN = 0xBFC02FF8, LENGTH = 0x4
config0 : ORIGIN = 0xBFC02FFC, LENGTH = 0x4
boot_software_key : ORIGIN = 0xA0000000, LENGTH = 0x4
kseg1_data_mem (w!x) : ORIGIN = 0xA0000004, LENGTH = 0x7FFC
sfrs : ORIGIN = 0xBF800000, LENGTH = 0x100000
}

SECTIONS
{
.config_BFC02FF0 : {
KEEP(*(.config_BFC02FF0))
} > config3
.config_BFC02FF4 : {
KEEP(*(.config_BFC02FF4))
} > config2
.config_BFC02FF8 : {
KEEP(*(.config_BFC02FF8))
} > config1
.config_BFC02FFC : {
KEEP(*(.config_BFC02FFC))
} > config0
}

PROVIDE(_DBG_CODE_ADDR = 0xBFC02000) ;
PROVIDE(_DBG_CODE_SIZE = 0xFF0) ;
SECTIONS
{
/* Boot Sections */
.reset _RESET_ADDR :
{
KEEP(*(.reset))
KEEP(*(.reset.startup))
} > kseg1_boot_mem

/* .bev_excpt _BEV_EXCPT_ADDR :
{
KEEP(*(.bev_handler))
} > kseg1_boot_mem
*/
/* .dbg_excpt _DBG_EXCPT_ADDR (NOLOAD) :
{
. += (DEFINED (_DEBUGGER) ? 0x8 : 0x0);
} > kseg1_boot_mem
*/
/* .dbg_code _DBG_CODE_ADDR (NOLOAD) :
{
. += (DEFINED (_DEBUGGER) ? _DBG_CODE_SIZE : 0x0);
} > debug_exec_mem
*/
/* .app_excpt _GEN_EXCPT_ADDR :
{
KEEP(*(.gen_handler))
} > exception_mem
*/
.vector_0 _ebase_address + 0x200 :
{
KEEP(*(.vector_0))
} > exception_mem


/* END OF MODIFICATIONS
FILE CONTINUES AS IT WAS */
Reply
22-05-2017, 01:23 PM, (This post was last modified: 22-05-2017, 02:20 PM by pingotg.)
#7
RE: MPLAB IDE and Pinguino 32 DIY PIC32MX250F128B
What code are you trying to put into the board?

Olimex Pinguino boards already have a bootloader so you do not need any of MPLAB, xc32, pic32prog or whatever.

If you want to change the bootloader you'll need either to download using the existing one or a tool such as a PICkit3 (many alternatives are available, such as an Arduino or RPi).

John
Reply
22-05-2017, 03:03 PM,
#8
RE: MPLAB IDE and Pinguino 32 DIY PIC32MX250F128B
I know Olimex board has a bootloader; I'm not trying to change the bootloader. I just wanted to upload a code made using MPLAB IDE using the onboard bootloader; as MPLAB IDE allows for total control of the board. The whole history is at thebeginning of the thread, a couple of years ago...
Reply
24-05-2017, 10:41 PM,
#9
RE: MPLAB IDE and Pinguino 32 DIY PIC32MX250F128B
Much easier to use any of the ICSP / JTAG tools to do that. Cheapest is a clone arduino for about $3.

John
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)