There is an important erratum for all chips in the 'K40 family.
With XC8 version 1.38, you need the workaround shown in Section 3.1 of the Errata document DS80000712B
Create a new file, powerup.as
, in your project. (But: See edited information below.)
Here's what I put in that file:
; From Errata document DS80000712B for the PIC168F27K40
; From davekw7x: This workaround is still necessary
; as of XC8 version 1.40 (December 14, 2016)
bsf NVMCON1, 7; From errata document DS80000712B
Without this fix, global initialization won't work, and a lot of other stuff won't work. (Anything that accesses data in program memory, like printf()
, for example)
Release notes for XC8 version 1.40 indicate that the following should fix it, but it didn't work for me:
Add the following command-line option to the project Properties->XC8 Global Options->XC8 compiler->Additional Options line --ERRATA=NVMREG So I am still using the powerup.as fix as shown in the Errata, even for XC8 version 1.40.
The proper way to do it with XC8 version 1.40 and later is the following:
- Enter +nvmreg in the Project Properties XC8 global options->XC8 Linker->Additional Options->Errata box
That is, it's a Linker option, not a Compiler option.
Bottom line: With recent compiler versions you don't need powerup.as
any more. (Huzzah!)
The Errata document indicates that is not necessary for silicon revision A4, but I don't have any such chips to test.
Tested on my MPLABX version 3.50 PIC18F27K40 project with XC8 version 1.38 and version 1.40. Both in "Free" mode. Note that I did not test with simulator or debugger or anything other than bare-metal hardware and software: Real chip running with production release at full speed, using printf()
to verify memory contents and other functionality.
post edited by davekw7x - 2017/06/26 07:49:48