Helpful ReplyXC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED

Author
UT_Tech
Junior Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2015/04/13 16:17:40
  • Location: 0
  • Status: offline
2017/01/16 14:24:04 (permalink)
4.75 (4)

XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED

Hello All,
 
Like many of you I ran into errata DS80000712B.  Adding +NVMREG in the errata field in the linker properties did not change the symptom for me.  I found other threads on the forum with the same result.  Adding powerup.as worked for me, as it did for others.  One thing to be careful of is that the syntax and formatting of the .as file is exact.  The code should look like the attached photo.  Make sure that you do not have any extraneous blank lines after the "end" keyword on line 9.  Blank lines after end will give you a preprocessor syntax error which is blank.
 
To make it easier I've also attached a working powerup.as file.  Just add this file to your project as a Source file.  One more thing, if you use arrays in EEPROM the NVMREG bits will be changed.  You can change back to PFM (Program Flash Memory) for normal const array reads by adding this line to your C code:
 
NVMCON1=0x80
 
Thank you,
Steve

Attached Image(s)

#1
NKurzman
A Guy on the Net
  • Total Posts : 16440
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/01/16 16:04:42 (permalink)
+1 (1)
Alternately, for Version XC8 1.40 you can add that errata to the command line and the compiler will take care of it.
#2
UT_Tech
Junior Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2015/04/13 16:17:40
  • Location: 0
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/01/16 18:29:32 (permalink)
+1 (1)
Just to be clear "that errata" means adding +NVMREG to the Errata field of the Linker options, under the Additional Options selection.  See the attached screen shot.  The errata option is added to the --errata field in the command line, as shown in the command line window.  This is the method that did NOT work for me.  If it works for you, that's great.  If not then the method of adding powerup.as will work.  
 
Steve
 

Attached Image(s)

#3
NKurzman
A Guy on the Net
  • Total Posts : 16440
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/01/16 18:49:08 (permalink)
0
And you have V1.40?
 
The Compiler writes appear to believe it works.
Does it show up in the actual command line?
#4
CinziaG
morite
  • Total Posts : 3144
  • Reward points : 0
  • Joined: 2016/12/07 14:20:36
  • Location: Wien
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/01/17 03:07:37 (permalink)
0
Linker or Compiler options?

mi fate schifo, umani di merda.
#5
timijk
Super Member
  • Total Posts : 1216
  • Reward points : 0
  • Joined: 2007/11/26 00:30:07
  • Location: Taiwan
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/01/17 04:02:06 (permalink)
+1 (1)
I tried the linker option --errata=+NVMREG with XC8 1.40, it will add two instructions 
 
BSF NVMCON1,7,ACCESS
BCF NVMCON1,6,ACCESS
#6
mad_c
Super Member
  • Total Posts : 1107
  • Reward points : 0
  • Joined: 2010/12/12 17:48:27
  • Location: Brisbane, Australia
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/01/18 13:36:38 (permalink)
+3 (3)
UT_Tech
Adding +NVMREG in the errata field in the linker properties did not change the symptom for me.

Is there any more information you can provide? The compiler should be able to work around this errata. If it cannot, then that needs to be addressed. Have you been able to confirm that the extra workaround code was added when you specified the +NVMREG errata? If it is being added but it does not work the same as when you add the same code to the powerup routine, then maybe there is an issue with when the compiler-added code is being executed, in other words your project produces code executed before the workaround that triggers the failure. In that instance, would you be able to send a project to Support that illustrates the issue?
 
Many thanks.
 
Jeff.
#7
Freitas
Starting Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2014/05/21 09:37:53
  • Location: 0
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/02/13 05:16:53 (permalink)
+1 (1)
I am running into the same issue. Check the details from my system:
1 - MPLAB X IDE v3.51
2 - XC8 Compiler v1.41
3 - PIC18F26K40
 
I tried using the errata option (nvmreg) and it didn't work even though I can see the code in the .lst file (below for reference)

 
574  0000                     _NVMCON1bits set 3969
 
...
 
590 ; NVMREG Errata
591 000FB2 if 3969
592 000FB2 8E81 bsf 129,7,c
593 000FB4 9C81 bcf 129,6,c
594 000FB6 endif

 
I also tried adding the powerup.as as told in the errata document, DS80000712B,  but again I was unsuccessfully. Since I am a newbie in reading .lst file (never thought i would need it) I can check whether any code is being added or not. Can someone help me with that?
 
So I got tired and just added a line of code in the beginning of my main.c:

 
    NVMCON1bits.NVMREG = 2;
 

 
and it worked. =D
 
But still, can someone help me find out why my powerup.as solution didn't work?
EDIT: I found the issue, I was actually loading my initial config from EEPROM and MCC generated function for EEPROM were setting NVMREG = 0. Now i just added one temp variable to save NVMREG data before accessing EEPROM and restoring it later on. For those who are curious, the code is below:

...
//Errata for PIC18FxxK40 family
#if defined(_PIC18F26K40_H_)
uint8_t old_NVMREG = NVMCON1bits.NVMREG;
#endif
 
... //call MCC function to access eeprom data
 
#if defined(_PIC18F26K40_H_)
//Reset the NVMREG to its original value
NVMCON1bits.NVMREG = old_NVMREG; //Errata for PIC18FxxK40 family
#endif

 
Regards,
post edited by Freitas - 2017/02/13 11:07:59
#8
rodyne
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2015/12/07 10:57:58
  • Location: New Zealand
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/03/04 20:20:16 (permalink)
0
mad_c
UT_Tech
Adding +NVMREG in the errata field in the linker properties did not change the symptom for me.

Is there any more information you can provide? The compiler should be able to work around this errata. If it cannot, then that needs to be addressed. Have you been able to confirm that the extra workaround code was added when you specified the +NVMREG errata? If it is being added but it does not work the same as when you add the same code to the powerup routine, then maybe there is an issue with when the compiler-added code is being executed, in other words your project produces code executed before the workaround that triggers the failure. In that instance, would you be able to send a project to Support that illustrates the issue?
 
Many thanks.
 
Jeff.




I have exactly the same IDE/XC8 versions and 18F26K40 as Freitas above however I have not got it to work using any of the methods described by people here including powerup.as, setting ERRATA=+NVMREG and even mixing and matching the various work-arounds such as setting NVMCON1bits.NVMREG=2 as the fist line of code or just before the const arrays are used. I too also see the errata code in the .lst file
"C:\Program Files\Microchip\xc8\v1.41\bin\xc8.exe" --chip=18F26K40 -G -mdist/default/production/Firmware.production.map --double=24 --float=24 --emi=wordwrite --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --errata=+NVMREG --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,-plib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" --memorysummary dist/default/production/memoryfile.xml -odist/default/production/Firmware.production.elf build/default/production/main.p1 build/default/production/hardware.p1 build/default/production/lcd.p1 build/default/production/functions.p1 build/default/production/rfm69.p1
The release notes from the XC8 compiler seem to imply the work around +NVMREG is the way to do this as you suggest but so far everything I have tried gives me the array value 0x00 I have even tried reverting to 1.4 and 1.38 with the powerup.as file also but the same
 
Very frustrating as I'm not a C Guru and I've lost a few days getting to where I am now and dont seem to be able to proceed any further until either XC8 gets fixed or I can source some A4 revision chips sad: sad
 
The Project is here is anyone at microchip wants to reproduce it, the place I noticed the error is in the font tables and lcd init tables in lcd.h and lcd.c both these files are modified from another working project using another cpu, all other areas using const arrays are also affected too. (The code will eventually be open sourced and still work in progress but will compile so no restriction on use)
 
Cheers
 
Boz
#9
jack@kksound
code tags!
  • Total Posts : 2761
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/03/06 11:27:58 (permalink)
+3 (3)
@Rodyne: as this forum is a user forum I would suggest you start a support ticket directly with Microchip to ensure that they receive your request for help. There is no guarantee that an official Microchip person will read and respond to your request on these forums.
#10
rodyne
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2015/12/07 10:57:58
  • Location: New Zealand
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/03/06 18:51:05 (permalink)
0
Thanks for the reply
 
I did a full delete and re-install of MPLab and XC8 which did not fix it so I will open a case with support. I subsequently saw there were a lot of posts about this issue on the forum and most have been solved by the fix so its strange why I have a problem still.. (I wont be buying a lottery ticket this week!)
 
I have un-soldered the 18F26K40 and soldered a 16F chip in for now which works OK and will get me over the next few weeks.
#11
timijk
Super Member
  • Total Posts : 1216
  • Reward points : 0
  • Joined: 2007/11/26 00:30:07
  • Location: Taiwan
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/03/06 19:58:13 (permalink) ☄ Helpfulby rodyne 2017/03/06 20:00:33
+2 (2)
I checked the hex file, the fix "BSF NVMCON1,7,ACCESS" is applied.  NVMCON1 bit 6 should be 0 at POR, so it should be OK.
 
You can see the Assembly code in menu Window/PIC Memory Views/Program Memory.
post edited by timijk - 2017/03/06 20:04:09
#12
rodyne
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2015/12/07 10:57:58
  • Location: New Zealand
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/03/06 21:37:23 (permalink)
0
Thank You.
 
Your information has helped me dig a bit deeper into my problem and I have added a breakpoint at the first line of the code where I use a const array.
 
In this line I copy a const unsigned char array from rom to a unsigned char array in ram to initialise my starting values. On line 1262 where the program stopped I see the NVMCON1 bits being set by my C code, however almost immediately following this on line 1265 I see it set again, possibly because there is another RAM array involved.
 
Link to picture here
 
I dont think I'm doing anything wrong here so If nobody can see any flaw in the logic I will add this to my support case
 
I really appreciate your guys help
 
Boz
 
PS: Sorry I cannot attach picture as I get
Access Denied
You don't have permission to access "http://www.microchip.com/forums/post.aspx?" on this server.
Reference #18.26346d68.1488861308.22a06b
 
Nothing seems to work for me this week :-(
#13
qhb
Superb Member
  • Total Posts : 7142
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/03/06 22:13:23 (permalink)
+2 (2)
rodyne
On this line I copy a const unsigned char array from rom to a unsigned char array in ram to initialise my starting values. On line 1262 where the program stopped I see the NVMCON1 bits being set by my C code, however almost immediately following this on line 1265 I see it set again, possibly because there is another RAM array involved.
 ...

You are misinterpreting what the assembly is doing.
Your C line
NVMCON1bits.NVMREG = 2;

is generating four assembly instructions
MOVF NVMCON1,W,ACCESS ;copy NVMCON1 to W
ANDLW 0x3F ;force bits 6 and 7 to zero
IORLW 0x80 ;force bit 7 to 1
MOVWF NVMCON1,ACCESS ;copy W back to NVMCON1

 
I am surprised they are using four instructions when you can do it in two
BSF  NVMCON1,7 ;force bit 7 high
BCF  NVMCON1,6 ;force bit 6 low

the only advantage of the four instruction version is it writes to both bits at the same time.
 
post edited by qhb - 2017/03/06 22:37:10
#14
rodyne
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2015/12/07 10:57:58
  • Location: New Zealand
  • Status: offline
Re: XC8 Table Array Workaround for PIC18FXXK40, Slicon Rev A3, SOLVED 2017/03/06 22:34:04 (permalink)
0
Thanks again for your help
 
I'm not sure the debuggers helping (or more likely I'm not using it properly) as it says NVMCON1 = 0x00 at the end of setting NVMREG=2.  I think it is time to read up on what's happening in the IDE, compiler and assembly code until I understand what's going on and stop wasting everyone's precious time.
 
At least my replacement PIC is working, thank god for pin compatibility.
#15
Jump to:
© 2018 APG vNext Commercial Version 4.5