• AVR Freaks

Helpful ReplyHot!#pragma config IDLOCx

Author
VincenzoV
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2011/02/06 10:41:25
  • Location: Monticello Brianza - LC - Italy
  • Status: offline
2018/01/01 14:55:01 (permalink)
0

#pragma config IDLOCx

Hi all
I need a serial number for PIC18F26K22, using ID Locations (0x2000000 -> 0x2000007)
Using MPLABX IPE all works fine: I can write up to 8 byte from SQTP file and read it from program
For testing and debug, using IDE (MPLAB X 4.05, XC8 1.45) and "#pragma config IDLOCx" statment, I can write only 8 nibble: for example, if I write
#pragma config IDLOC0 0x34

I read back 0x4, "3" is lost...
It's a bug or I'm using wrong #pragma?
 
Thanks
 
 
 

Vincenzo Villa - https://www.vincenzov.net
#1
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: #pragma config IDLOCx 2018/01/01 16:07:06 (permalink)
0
I think XC8 only ever writes to the bottom 4 bits as they are not affected by code protection.

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#2
1and0
Access is Denied
  • Total Posts : 10005
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: #pragma config IDLOCx 2018/01/01 16:08:58 (permalink) ☄ Helpfulby VincenzoV 2018/01/02 05:25:02
+5 (5)
To program the upper nybbles too, you will need to edit the mask value in the your PIC device .cfgdata file, located in the XC8 install /dat folder; i.e. change the :F: in
CWORD:200000:F:FF:IDLOC0
CWORD:200001:F:FF:IDLOC1
CWORD:200002:F:FF:IDLOC2
CWORD:200003:F:FF:IDLOC3
CWORD:200004:F:FF:IDLOC4
CWORD:200005:F:FF:IDLOC5
CWORD:200006:F:FF:IDLOC6
CWORD:200007:F:FF:IDLOC7

to :FF:
#3
VincenzoV
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2011/02/06 10:41:25
  • Location: Monticello Brianza - LC - Italy
  • Status: offline
Re: #pragma config IDLOCx 2018/01/02 05:34:58 (permalink)
0
It works!
Thank you 1and0

Vincenzo Villa - https://www.vincenzov.net
#4
RISC
Super Member
  • Total Posts : 5379
  • Reward points : 0
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 11:49:17 (permalink)
0
Hi,
 
According to the XC8 compiler manual it accepts nibble or bytes (section 5.3.7).
The correct syntax must have "=" :
#pragma config IDLOC0 = 0x34
 
Regards
post edited by RISC - 2018/01/06 12:42:30
#5
1and0
Access is Denied
  • Total Posts : 10005
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 12:34:55 (permalink)
0
Good catch on the "=" but I think it's a typo in OP's posting, because without the "=" it will generate a compiler error.
#6
RISC
Super Member
  • Total Posts : 5379
  • Reward points : 0
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 13:43:37 (permalink)
0
Hi,
I checked the HEX code generated for PIC18F47K40 with the correct syntax and it does correctly generates the bytes.
I guess OP forgot the "="
Regards
post edited by RISC - 2018/01/06 14:25:49
#7
1and0
Access is Denied
  • Total Posts : 10005
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 13:49:54 (permalink)
0
RISC
I checked the HEX code generated for PIC18F47K70 with the correct syntax and it does correctly generates the bytes.
I guess OP forgot the "="

Nah, without the "=" the compiler will generate
Error   [1361] syntax error in configuration argument

It is the mask value in the .cfgdata file.
 
 
<edit> Without editing the .cfgdata file, it will generate a warning
Warning [1388] configuration setting/register of "IDLOC0" with 0x34 will be truncated by 0xF

when an 8-bit value is used.
post edited by 1and0 - 2018/01/06 13:54:51
#8
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11432
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 14:35:11 (permalink)
+1 (1)
From the programming specification:
 
It is recommended that the Most Significant nibble of each ID be Fh. In doing so, if the user code inadvertently tries to execute from the ID space, the ID data will  execute as a NOP.

#9
RISC
Super Member
  • Total Posts : 5379
  • Reward points : 0
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 14:41:42 (permalink)
0
Hi,
I use the XC8 compiler v1.44 and no warning is generated in case of PIC18F47K40 :

#pragma config IDLOC0 = 0x12
#pragma config IDLOC1 = 0x34
#pragma config IDLOC2 = 0x56
#pragma config IDLOC3 = 0x78
#pragma config IDLOC4 = 0x9A
#pragma config IDLOC5 = 0xBC

Which compiler version / PIC do you use to see the warning ?
Regards
#10
1and0
Access is Denied
  • Total Posts : 10005
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 14:44:21 (permalink)
0
jtemples
From the programming specification:
It is recommended that the Most Significant nibble of each ID be Fh. In doing so, if the user code inadvertently tries to execute from the ID space, the ID data will  execute as a NOP.


... and the XC8 compiler is _not_ following that recommendation as the upper nybble is truncated to be 0x0. Besides, that recommendation makes no sense. How does a PIC device execute from the ID space, located at 0x200000, when the PC is limited to 0x1FFFFF?
 
#11
1and0
Access is Denied
  • Total Posts : 10005
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 14:46:44 (permalink)
0
RISC
I use the XC8 compiler v1.44 and no warning is generated in case of PIC18F47K40 :
...
Which compiler version / PIC do you use to see the warning ?

XC8 v1.44 for OP's PIC device. 
 
I guess they fixed the .cfgdata files for newer PICs such as the K40. ;)
 
<edit> ... so they did. From 18f47k40.cfgdata:
CWORD:200000:FFF:FFF:IDLOC0
CWORD:200002:FFF:FFF:IDLOC1
CWORD:200004:FFF:FFF:IDLOC2
CWORD:200006:FFF:FFF:IDLOC3
CWORD:200008:FFF:FFF:IDLOC4
CWORD:20000A:FFF:FFF:IDLOC5
CWORD:20000C:FFF:FFF:IDLOC6
CWORD:20000E:FFF:FFF:IDLOC7

and it looks like you can use 3 nybbles per loc.
post edited by 1and0 - 2018/01/06 14:49:26
#12
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11432
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 15:16:49 (permalink)
0
How does a PIC device execute from the ID space, located at 0x200000, when the PC is limited to 0x1FFFFF?

 
"Only the lower nibble is recommended" goes back to ancient PICs like the PIC16C family, though no explanation as to why was provided.  Maybe it's just legacy voodoo.
#13
RISC
Super Member
  • Total Posts : 5379
  • Reward points : 0
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 15:26:11 (permalink)
0
Hi,
The warning shows up for PIC18F26K22 but not PIC18F47K40 so I guess this is a compiler issue...
Regards
#14
1and0
Access is Denied
  • Total Posts : 10005
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: #pragma config IDLOCx 2018/01/06 20:54:40 (permalink)
0
jtemples
"Only the lower nibble is recommended" goes back to ancient PICs like the PIC16C family, though no explanation as to why was provided.  Maybe it's just legacy voodoo.

RISC
The warning shows up for PIC18F26K22 but not PIC18F47K40 so I guess this is a compiler issue...

Straight from the horse's mouth ;) -- http://www.microchip.com/forums/FindPost/945345
#15
Andy123
Super Member
  • Total Posts : 573
  • Reward points : 0
  • Joined: 2005/04/25 14:20:54
  • Status: offline
Re: #pragma config IDLOCx 2019/11/12 07:34:18 (permalink)
0
Sorry for bringing this old thread back, but can somebody explain why XC8 limits PIC18F27K40 IDLOCx to FFF?
Manual does not list this limitation so should it be FFFF - full 2 bytes?
Works externally.
CWORD:200000:FFF:FFF:IDLOC0
CWORD:200002:FFF:FFF:IDLOC1
CWORD:200004:FFF:FFF:IDLOC2
CWORD:200006:FFF:FFF:IDLOC3
CWORD:200008:FFF:FFF:IDLOC4
CWORD:20000A:FFF:FFF:IDLOC5
CWORD:20000C:FFF:FFF:IDLOC6
CWORD:20000E:FFF:FFF:IDLOC7

#16
du00000001
Just Some Member
  • Total Posts : 3244
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: #pragma config IDLOCx 2019/11/12 08:58:19 (permalink)
+1 (1)
@Andy123
 
According to the datasheet (DS40001844E-page 34), there are only bytes available at these addresses.
So the (0x)FFF masks are somewhat "over-specified" - (0x)FF would do as well.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#17
1and0
Access is Denied
  • Total Posts : 10005
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: #pragma config IDLOCx 2019/11/12 10:21:01 (permalink)
+1 (1)
Andy123
Manual does not list this limitation so should it be FFFF - full 2 bytes?
Works externally.

The ID locations are both readable and writable at runtime. Did you try it and see if they can hold 3 or 4 nybbles each?
 
#18
Andy123
Super Member
  • Total Posts : 573
  • Reward points : 0
  • Joined: 2005/04/25 14:20:54
  • Status: offline
Re: #pragma config IDLOCx 2019/11/12 17:15:11 (permalink)
0
1and0
The ID locations are both readable and writable at runtime. Did you try it and see if they can hold 3 or 4 nybbles each?

I did not try runtime but I used 3rd party programmer and was able to use numbers over 4095 (0xfff) without any issues.
I can read these numbers as well.
But then I changed my code to
#pragma config IDLOC0=4200
and got compiler warning about fff limit that brought me here.
 
post edited by Andy123 - 2019/11/13 06:59:26
#19
Jump to:
© 2019 APG vNext Commercial Version 4.5