Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
Joined: 31/01/2014 Location: United StatesPosts: 309
Posted: 08:31am 01 Feb 2016
Copy link to clipboard
Print this post
I decided to give myself a crash course in C programming (silly me) and installed MPLAB IDE 3.20 and MPLAB XC32 1.40. When I tried to build some sample projects from both Peter Carnegie and Peter Mather and they failed. I verified the compiler options were set to "-fPIC -mno-abicalls". Examining the error log, I found a line stating that "-mabicalls" setting is required for position-independent code. When I added that setting everything started to work.
So... Am I doing something wrong? Is this something new for MPLAB IDE 3.20 and/or MPLAB XC32 1.40? Is it okay to keep using this setting or will it cause me grief later on?
Thanks,
Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!!
matherp Guru
Joined: 11/12/2012 Location: United KingdomPosts: 8595
Posted: 08:50am 01 Feb 2016
Copy link to clipboard
Print this post
All the work I do is with XC32 1.33. This is the version Geoff uses for the firmware so it is probably best to stick with it. It was also the last version which Microchip distributed with the integrated plib library. You should definitely use:
-fPIC -mno-abicalls
the abicalls bit stops the compiler generating Unix System V Relase 4 style code (SVR4). It is the -fPIC that sets up position independence (to the extent that MIPS supports it).
The CFGEN program actually modifies the machine code to try and remove non-position independent instructions.
In addition I set the: "Exclude Standard Libraries", "Do not link startup code", and "Exclude Floating point library" tick boxes in the Libraries drop down on the options for xc32-ld
The above setting have been determined by Nathan and allow the use of things like "switch" statements that were previously a problem.
Make sure you are using optimisation level 1. Anything else can give problems. It is worth noting the xc32-1.4 has a very different optimisation engine which may be an issue.
Edited by matherp 2016-02-02
Justplayin
Guru
Joined: 31/01/2014 Location: United StatesPosts: 309
Posted: 09:50am 01 Feb 2016
Copy link to clipboard
Print this post
Thanks Peter,
I installed XC32 1.33 and it works without adding the extra -mabicalls switch. Also, thank you for sharing the other settings from your configuration!
--Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!!
matherp Guru
Joined: 11/12/2012 Location: United KingdomPosts: 8595
Posted: 10:06am 01 Feb 2016
Copy link to clipboard
Print this post
Excellent news
Do post any questions, it is great to have someone else getting stuck into CfunctionsEdited by matherp 2016-02-02
Justplayin
Guru
Joined: 31/01/2014 Location: United StatesPosts: 309
Posted: 10:50am 01 Feb 2016
Copy link to clipboard
Print this post
Grogster
Admin Group
Joined: 31/12/2012 Location: New ZealandPosts: 9066
Posted: 04:04pm 01 Feb 2016
Copy link to clipboard
Print this post
I read my way through several of Peter's cfunction tutorials, but I was lost even there. Nothing wrong with Peter's instructions or writing, it's just C is so bloody confusing!
I don't think I am the only one...
It's some of the syntax that C uses - to me looks like gobble-de-gook, with no really easy to decipher meaning. But then, C is not a BASIC, so there you go.
I guess if I had much more time to devote to learning C, it would get easier. Smoke makes things work. When the smoke gets out, it stops!
Justplayin
Guru
Joined: 31/01/2014 Location: United StatesPosts: 309
Posted: 05:22pm 01 Feb 2016
Copy link to clipboard
Print this post
My biggest problem with trying to learn CFunctions, at the moment, is that it is like dealing with a black hole. You pass your data into it and pray things don't crash for some unknown reason while it is beyond your reach to monitor it. With a regular program you can add lots of print (or printf) statements to monitor whats going on along the way, but can't do that with a CFunction.
Oh well... I have a goal in mind and I going to keep driving the nails into this project with my forehead until I created what want, or knock this whole CFunction idea out of my head.
--Cutis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!!
matherp Guru
Joined: 11/12/2012 Location: United KingdomPosts: 8595
Posted: 10:35pm 01 Feb 2016
Copy link to clipboard
Print this post
With a regular program you can add lots of print (or printf) statements to monitor whats going on along the way, but can't do that with a CFunction.
Watch this space
Justplayin
Guru
Joined: 31/01/2014 Location: United StatesPosts: 309
Posted: 08:17am 02 Feb 2016
Copy link to clipboard
Print this post
Important CFunction lession I just learned... Bad output from the CFunction is not necessarily the fault of the CFunction.
Just spent hours going over and over the same lines of C code only to find I was passing the wrong variable from MMBasic.
Should have written:
a = 1
b = 2
c = addto(a, b)
Print a, b, c
Instead I wrote:
a = 1
b = 2
c = addto(a, c)
Print a, b, c
Could not figure out why a+b did not produce a logical result in c. (no pun intended, but deserved)
--Curtis
I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!!