Vault 7: Projects
This publication series is about specific projects related to the Vault 7 main publication.
MPLAB
®
XC16 C Compiler Users Guide
DS50002071C-page 326 2012-2013 Microchip Technology Inc.
__builtin_write_NVM_secure
Description: Enables the Flash for writing by issuing an unlock sequence specified by two keys and
enabling the Write bit of the NVMCON register.
Interrupts may need to be disable for proper operation.
This builtin function can be used as a part of a complex sequence discussed in the data
sheet or family reference manual.
See this documentation for more information.
Prototype: void __builtin_write_NVM_secure(unsigned int key1,
unsigned int key2);
Argument: key1 first key in the NVM unlock sequence
key2 second key in the NVM unlock sequence
Return Value: None.
Assembler Operator/
Machine Instruction:
Depending on the lcoatin of the keys:
mov W0, Wn
mov Wn, _NVMKEY
mov W1, Wn
mov Wn, _NVMKEY
bset _NVMCON, #15
nop
nop
Error Messages None.
__
builtin_write_PWMSFR
Description: Writes the PWM unlock sequence to the SFR pointed to by PWM_KEY and then writes
value to the SFR pointed to by PWM_sfr.
Prototype: void __builtin_write_PWMSFR(volatile unsigned int *PWM_sfr,
unsigned int value, volatile unsigned int *PWM_KEY);
Argument: PWM_sfr register to be written
value value to write
PWM_KEY hardware unlock key location
Return Value: None.
Assembler Operator/
Machine Instruction:
mov #<it>PWM_KEY</it>, w3
mov #<it>value</it>, w2
mov #0x4321, w1
mov #0xABCD, w0
mov w1,[w3]
mov w0,[w3]
mov w2,[w3]
Error Messages None.
Examples Example 1:
__builtin_write_PWMSFR(&PWM1CON1, 0x123, &PWM1KEY);
Example 2:
__builtin_write_PWMSFR(&P1FLTACON, 0x123, &PWMKEY);
The choice of PWM_KEY may depend upon architecture.
Protego_Release_01_05-Related-OEM-Documentation-MPLAB-XC16-C-Compiler.pdf