• AVR Freaks

AnsweredHot!How to convert #pragma config's

Page: 12 > Showing page 1 of 2
Author
JakeSays
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2020/03/28 03:32:15
  • Location: 0
  • Status: offline
2020/07/20 10:25:02 (permalink)
2 (1)

How to convert #pragma config's

Does anyone know how to convert XC32 #pragma config's in to regular C?
#1
dan1138
Super Member
  • Total Posts : 3841
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 10:35:34 (permalink)
+4 (6)
JakeSays
Does anyone know how to convert XC32 #pragma config's in to regular C?



This question does not make any sense.
 
Almost all of the #pragma statements for XC32 are used to manage the initialization of controller specific states that a "regular C" compiler does not know or care about.
 
Compilers that conform to the ISO C standard are suppose to silently ignore any #pragma they do not know about.
 
So what is the actual problem you need help with?
#2
JakeSays
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2020/03/28 03:32:15
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 12:37:26 (permalink)
0
Ok so each one of those pragma's controls an MCU setting. I need to set those values w/o the pragmas.
 
Make sense?
#3
jdeguire
Super Member
  • Total Posts : 596
  • Reward points : 0
  • Joined: 2012/01/13 07:48:44
  • Location: United States
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 12:39:20 (permalink) ☄ Helpfulby JakeSays 2020/07/21 05:17:00
+2 (2)
You can probably use the "section" attribute to do this.  The config registers are located in sections labelled ".config_<kseg1_address>" such as ".config_BFC02FF0".  This assumes that your linker scripts are based on the ones that come with XC32.  If not, then you'll need to add sections to your linker script for the config registers yourself.
 
If you are using the XC32 linker scripts, remember to add in the ".text" and ".data" sections somewhere.  Those aren't called out in the XC32 scripts because Microchip added their own extensions to the linker to have it place the sections automatically.
post edited by jdeguire - 2020/07/20 12:42:46
#4
dan1138
Super Member
  • Total Posts : 3841
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 12:59:31 (permalink)
0 (2)
JakeSays
Ok so each one of those pragma's controls an MCU setting. I need to set those values w/o the pragmas.
 
Make sense?

Actually no it does not make sense.
 
My understanding of what you're asking must be wrong. You seem to want to use a C compiler other than the Microchip XC32 compiler to build code for a Microchip MIPS based 32-bit controllers.
 
If true you are letting yourself in for a nightmare of finding out about all of the controller specific hacks that Microchip development environment deals with for their variations of the MIPS implementation in silicon.
#5
JakeSays
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2020/03/28 03:32:15
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 13:03:02 (permalink)
0
Dan, no. I have no idea where you got MIPS from. I am working with a ATSAME54P20A which is arm m4.
 
I am moving from atmel start to harmony 3, and I have an existing workflow that uses generic gcc compilers. I do not want to add a different toolchain.
#6
JakeSays
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2020/03/28 03:32:15
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 13:06:21 (permalink)
0
@jdeguire, thank you for the suggestion. I will look in to it.
 
I'll investigate how atmel start's code does it. 
#7
dan1138
Super Member
  • Total Posts : 3841
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 13:20:52 (permalink)
0 (2)
JakeSays
Dan, no. I have no idea where you got MIPS from. I am working with a ATSAME54P20A which is arm m4.
 
I am moving from atmel start to harmony 3, and I have an existing workflow that uses generic gcc compilers. I do not want to add a different toolchain.

Well you could have mentioned the target controller in you first post, I might not have looked like such a idiot.
 
Using a generic ARM tool chain may require you to set the configuration words using an assembly language source file as the C compilers can be more than a little cryptic when it comes to the initialization of objects at fixed address at build time.
 
Almost everyone here is using the Microchip tool chain like me.
 
How to do this with a tool chain I do not know about is something I could only guess at.
 
I have little more to offer than good luck with that!
#8
NKurzman
A Guy on the Net
  • Total Posts : 18901
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: How to convert #pragma config's 2020/07/20 13:22:23 (permalink)
+1 (3)
JakeSays
Dan, no. I have no idea where you got MIPS from. I am working with a ATSAME54P20A which is arm m4.

 Because you are posting on a Microchip board, and did NOT say what chip you were using.
Always Specify your chip if you want a useful answer.
 
#9
JakeSays
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2020/03/28 03:32:15
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 13:25:37 (permalink)
0
NKurzman
JakeSays
Dan, no. I have no idea where you got MIPS from. I am working with a ATSAME54P20A which is arm m4.

 Because you are posting on a Microchip board, and did NOT say what chip you were using.
Always Specify your chip if you want a useful answer.
 




I thought I was posting to a compiler board about compiler specific details unrelated to specific hardware. All versions of the xc series compilers (that I know of) use #pragma config, so my question should stand on its own. I didn't see the target MPU as an issue in this case.
#10
ric
Super Member
  • Total Posts : 28365
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How to convert #pragma config's 2020/07/20 13:30:52 (permalink)
+2 (4)
JakeSays
I didn't see the target MPU as an issue in this case.

Yet you are asking how to set highly target specific options in your controller.
That is WHY they are implemented use #pragma lines, specifically because they are not part of the standard C paradigm.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#11
dan1138
Super Member
  • Total Posts : 3841
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 13:35:19 (permalink)
+1 (3)
JakeSays
NKurzman
JakeSays
Dan, no. I have no idea where you got MIPS from. I am working with a ATSAME54P20A which is arm m4.

 Because you are posting on a Microchip board, and did NOT say what chip you were using.
Always Specify your chip if you want a useful answer.

I thought I was posting to a compiler board about compiler specific details unrelated to specific hardware. All versions of the xc series compilers (that I know of) use #pragma config, so my question should stand on its own. I didn't see the target MPU as an issue in this case.



Almost anything a C compiler does for a #pragma is something specific to the build environment or the hardware that will execute the compiled code that is not part of the ISO C standard.
#12
JakeSays
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2020/03/28 03:32:15
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 13:38:28 (permalink)
0
Yes, I am aware of this. However it is most definitely possible to do such things in a standard C way without pragmas, because all that is going on is the setting of registers, etc.
 
Anyway, thank you for your time.
#13
ric
Super Member
  • Total Posts : 28365
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How to convert #pragma config's 2020/07/20 13:39:50 (permalink)
+1 (3)
JakeSays
Yes, I am aware of this. However it is most definitely possible to do such things in a standard C way without pragmas, because all that is going on is the setting of registers, etc.

These are not standard registers. It does not happen at run time.
These are special FLASH locations that have to be set when the chip is programmed.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#14
JakeSays
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2020/03/28 03:32:15
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 13:49:36 (permalink)
+1 (1)
Ok well whatever they are it's still doable with out pragmas. The atmel start generated code works fine with a generic, off the shelf gcc/binutils.
#15
jdeguire
Super Member
  • Total Posts : 596
  • Reward points : 0
  • Joined: 2012/01/13 07:48:44
  • Location: United States
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 14:05:35 (permalink) ☄ Helpfulby JakeSays 2020/07/21 05:17:29
+2 (2)
It looks like the config registers on the SAME54 are three 32-bit words starting at address 0x00804000, so you'll want to update your linker script to create those sections.  Here's a portion of a linker script that I generated that might be of use to you.  I'd post the whole script, but I haven't actually tested it yet.
 

MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000
config_00804000 : ORIGIN = 0x00804000, LENGTH = 0x4
config_00804004 : ORIGIN = 0x00804004, LENGTH = 0x4
config_00804008 : ORIGIN = 0x00804008, LENGTH = 0x4
qspi : ORIGIN = 0x04000000, LENGTH = 0x1000000
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x40000
}
 
SECTIONS
{
.config_00804000 : {
KEEP(*(.config_00804000))
} > config_00804000
 
.config_00804004 : {
KEEP(*(.config_00804004))
} > config_00804004
 
.config_00804008 : {
KEEP(*(.config_00804008))
} > config_00804008
}

 
#16
JakeSays
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2020/03/28 03:32:15
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 14:07:28 (permalink)
0
jdeguire
It looks like the config registers on the SAME54 are three 32-bit words starting at address 0x00804000, so you'll want to update your linker script to create those sections.  Here's a portion of a linker script that I generated that might be of use to you.  I'd post the whole script, but I haven't actually tested it yet.
 
 



 
Thank you! I really appreciate your help :)
#17
dan1138
Super Member
  • Total Posts : 3841
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 14:11:10 (permalink)
0 (2)
ric
These are not standard registers. It does not happen at run time.
These are special FLASH locations that have to be set when the chip is programmed.

I doubt JakeSays is hearing what you are trying to tell him.
 
The last time I reviewed the ISO C specification there was a distinct lack of any standard syntax for selecting the physical address of an object initialized at build time.
 
Now GNU compilers have the __attribute__() storage class directive but that's not part of ISO C (yet?).
#18
JakeSays
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2020/03/28 03:32:15
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 14:17:05 (permalink)
+1 (1)
Lol no I fully get what he's saying, and I'm telling you both that I don't need magic pragmas to make it happen on the ATSAME54. Whatever is happening, an apt install gcc-arm-non-eabi binutils-arm-none-eabi is all that is required to create fully functional firmware for that device. 
 
completely understand the fact that there is configuration data stored in various segments in the firmware.
#19
dan1138
Super Member
  • Total Posts : 3841
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: How to convert #pragma config's 2020/07/20 14:35:28 (permalink)
0 (2)
JakeSays
... I fully get what he's saying, and I'm telling you both that I don't need magic pragmas ...

After reading this thread again I do not see where anyone suggested at any time you needed #pragmas.
 
The bottom line in all of this is that initializing the configuration words for a controller is something that is specific to the tool chain and target controller. That standard C syntax is usually not up to that task.
 
You have received good suggestions on how to declare sections in the linker script to associate symbolic names to physical address that can then be used by C language statements that can be initialized at build time with GNU language extensions. It seems likely this is how the Atmel tools make this happen.
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5