Search the Community
Showing results for tags 'xc32'.
Found 5 results
I decided to write this up as bootloaders have pretty much become ubiquitous for 32-bit projects, yet I was unable to find any good information on the web about how to use linker scripts with XC32 and MPLAB-X. When you need to control where the linker will place what part of your code, you need to create a linker script which will instruct the linker where to place each section of the program. Before we get started you should download the MPLAB XC32 C/C++ Linker and Utilities Users Guide. There is also some useful information in the MPLAB XC32 C/C++ Compiler User’s Guide for PIC32M MCUs, the appropriate version for your compiler should be in the XC32 installation folder under "docs". This business of linker scripts is quite different from processor to processor. I have recently been working quite a bit with the PIC32MZ2048EFM100, so I will target this to this device using the latest XC32 V2.15. This post will focus on what you need to to do to get the tools to use your linker script. Since XC32 is basically a variant of the GNU C compiler you can find a lot of information on the web about how to write linker scripts, here is a couple. http://www.scoberlin.de/content/media/http/informatik/gcc_docs/ld_3.html https://sourceware.org/binutils/docs-2.17/ld/Scripts.html#Scripts Adding a linker script The default linker script for the PIC32MZ2048EFM100 can be found in the compiler folder at /xc32/v2.15/pic32mx/lib/proc/32MZ2048EFM100/p32MZ2048EFM100.ld. If you need a starting point that would be a good place. For MPLAB-X and XC32 the extention of the linker script does not have any meaning. The linker script itself is not compiled, it is passed into the linker at the final step of building your program. The command line should look something like this for a simple program: "/Applications/microchip/xc32/v2.15/bin/xc32-gcc" -mprocessor=32MZ2048EFM100 -o dist/default/production/mine.X.production.elf build/default/production/main.o -DXPRJ_default=default -legacy-libc -Wl,--defsym=__MPLAB_BUILD=1,--script="myscript.ld",--no-code-in-dinit,--no-dinit-in-serial-mem,-Map="dist/default/production/mine.X.production.map",--memorysummary,dist/default/production/memoryfile.xml" The linker script should be listed on the command line as "--script="name" When you create a new project MPLAB will create a couple of "Logical Fodlers" for you. These folders are not actual folders on your file system, but files in these are sometimes treated differently, and Linker Files is a particular case of this. My best advice is not to ever rename of in any other way mess with these folders created for you by MPLAB. If you did edit configurations.xml or renamed any of these I suggest you just create new project file as there are so many ways this could go wrong fixing it will probably take you longer than just re-creating it. I have seen cases where it all looks 100% but the IDE simply does not use the linker script, just ignoring it. The normal way to add files to a MPLAB-X project is to right-click on the Logical folder you wanted the file to appear in and select which kind of file under the "New" menu. In this menu files that you use often are shown as a shortcut, to see the entire list of possible files you need to select "Other..." at the bottom of the list. Unfortunatley Microchip has not placed "Linker Script" in this list, so there is no way to discover using the IDE how to add a linker script. When it all goes according to plan (the happy path) you can simply right-click on "Linker Files" and add your script. This is also what the manual says to do of course. When you have added the file it should look like this (pay careful attention to the icon of the linker script file, it should NOT have a source code icon. It should just be a white block like this, and if this is the case the program should compile just fine using the linker script, you can confirm that the script is being passed in by inspecting the linker command line. Adding a linker script - Problems - when it all goes wrong! I noticed in the IDE that the icon for the script was actually that of a .C source file. When this happens something has gone very wrong, and the compiler will attempt to compiler your linker script as a C source file. You will end up getting an error similar to this, stating that there is "No rule to make target": CLEAN SUCCESSFUL (total time: 51ms) make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf make: *** No rule to make target 'build/default/production/newfile.o', needed by 'dist/default/production/aaa.X.production.hex'. Stop. make: Entering directory '/Users/cobusve/MPLABXProjects/aaa.X' make: *** Waiting for unfinished jobs.... make -f nbproject/Makefile-default.mk dist/default/production/aaa.X.production.hex make: Entering directory '/Users/cobusve/MPLABXProjects/aaa.X' make: *** [.build-conf] Error 2 "/Applications/microchip/xc32/v2.15/bin/xc32-gcc" -g -x c -c -mprocessor=32MZ2048EFM100 -MMD -MF build/default/production/main.o.d -o build/default/production/main.o main.c -DXPRJ_default=default -legacy-libc make: *** [.build-impl] Error 2 make: Leaving directory '/Users/cobusve/MPLABXProjects/aaa.X' nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed make: Leaving directory '/Users/cobusve/MPLABXProjects/aaa.X' nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed BUILD FAILED (exit value 2, total time: 314ms) I tried jumping through every hoop here, even did the hokey pokey but nothing would work to get the IDE to accept my linker script! I even posted a question on the forum here and got no help. At first I thought I would be clever and remove the script I just added, and just re-add it to the project, but no luck there. So now I was following the instructions exactly, my project was building without the script, I right-clicked on "Linker Files" selected "Add Existing Item" and then selected my script and once again it showed up as a source file and caused the project build to fail by trying to compile this as C code 😞 Next attempt was to remove the file, then close the IDE. Open the IDE, build the project and then after this add the existing file. Nope, still does not work 😞 I know MPLAB-X from time to time will cache information and you can get rid of this by deleting everything from the project except for your source files, Makefile and configurations.xml and project.xml. I went ahead and deleted all these files, restarted the IDE, added the file again - nope - still does not work. So much for RTFM! Eventually our of desperation I tried to rename the file before adding it back in. Even this did not work until I got lucky - I changed the extention of the file to gld (a commonly used extension for gnu linker files), and tried to re-add the file, and this eventually worked ! If you are having a hard time getting MPLAB-X to add your linker script, do not dispair. You are probably not doing anywthing wrong! The right way to add a linker script to your project is indeed to just add it to "Linker Files" as they say, sometimes you just get unlucky due to some exotic bugs in the IDE. Just remove the file from your project, change the extention to something else (it seems like you can choose anything as long as it is different) and add the file back in and it should work. If not come back here and let me know and we can figure it out together :)
PIC32 Linker scripts in MPLAB-X
Orunmila posted a question in Questions and AnswersI am trying to use a linker script with MPLAB-X for my PIC32 project but for some reason the script is not being passed to the linker at all. I expected that all I had to do was add the .ld file to my project, typically by placing it in the "Linker Files" virtual folder in MPLAB-X in my project. I did this and the linker script is being ignored by the linker. This is one of those $100 questions (if you know the story of the mechanic asking $100 for knowing where to hit ...). So my question is how do I get MPLAB-X to use my linker script which I have added to the PIC32 project?
I have a MPLAB-X project which uses a loadable (it is combining my program with a bootloader which is in another project). I need to compile this project from the command line for CI automation. For the entire build process every command executed is nicely printed in the build window, but for the loadable it claims to be using Hexmate, but the command line to execute it is not shown at all. Can anyone help me with the syntax using Hexmate to get the same behavior as adding the Loadable from MPLAB-X?
Preprocessor defines for XC32 used to select include file
Orunmila posted a question in Questions and AnswersI am trying to pass an include file name on the command line to XC32 to select the file to include in the code. Don't ask why, this is not my code, I am just trying to compile it with this compiler without modifying the code ... I am passing -DCONFIG_FILE=\"demo_config.h\" but the compiler does not seem to like this, error message is error: #include expects "FILENAME" or <FILENAME> Anyone know how to bend XC32 to my will here to do this correctly? EDIT: I have confirmed that this works fine on vanilla GCC. On MCHP XC32 I can do this and then it compiles fine #undef CONFIG_FILE #define CONFIG_FILE "demo_config.h" #include CONFIG_FILE It seems like when I pass in the filename via the command line something weird and unexpected is happening ... I used a trick to print the value and the filename is ending up in the code correctly it seems ... #define XSTR(x) STR(x) #define STR(x) #x #pragma message "The include is " XSTR(CONFIG_FILE) #ifdef CONFIG_FILE #include CONFIG_FILE #endif This will produce: #pragma message: The include is "demo_config.h" error: #include expects "FILENAME" or <FILENAME>
I just downloaded XC32 V2.15, I was using V2.10 before. I find that some of my projects no longer compile. On my first check I noticed that the problems seem to occur when inline functions are used and the same header where the inline implementation is done is included in more than one compilation unit? Has any of you seen similar issues? I will investigate further and post here if I arrive at an answer. UPDATE: Ok, I managed to make a small test project to replicate the problem. I am attaching it here. TestInlineXC32_2.15.zip Next I am going to test this on some other compilers to see what the deal is. I have confirmed that with that project when you switch it to V2.10 or older it all compiles just fine, but if you use V2.15 it failes to link with the following error: "/Applications/microchip/xc32/v2.15/bin/xc32-gcc" -mprocessor=32MZ2048EFM100 -o dist/default/production/TestInlineXC32_2.15.X.production.elf build/default/production/main.o build/default/production/otherFile.o -DXPRJ_default=default -legacy-libc -Wl,--defsym=__MPLAB_BUILD=1,--no-code-in-dinit,--no-dinit-in-serial-mem,-Map="dist/default/production/TestInlineXC32_2.15.X.production.map",--memorysummary,dist/default/production/memoryfile.xml nbproject/Makefile-default.mk:151: recipe for target 'dist/default/production/TestInlineXC32_2.15.X.production.hex' failed make: Leaving directory '/Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X' nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed make: Leaving directory '/Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X' nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed build/default/production/otherFile.o: In function `myInlineFunction': /Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X/inlinedheader.h:6: multiple definition of `myInlineFunction' build/default/production/main.o:/Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X/inlinedheader.h:6: first defined here /Applications/microchip/xc32/v2.15/bin/bin/gcc/pic32mx/4.8.3/../../../../bin/pic32m-ld: Link terminated due to previous error(s). collect2: error: ld returned 255 exit status make: *** [dist/default/production/TestInlineXC32_2.15.X.production.hex] Error 255 make: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2 BUILD FAILED (exit value 2, total time: 680ms)