4.2.1 Configuration of SAFLOCK Feature

To enable the SAFLOCK feature, program the SAFLOCK bit of the CONFIG13 Configuration register to 0.

Figure 4-6. CONFIG13 Register
Note: The SAFLOCK Configuration bit may be present in different configuration registers for other families of 8-bit PIC microcontrollers, which can be found in their respective device data sheets.

The SAF area spans the end of the program memory, and the code stored in the SAF area cannot be executed by the CPU. Also, the expansion of the SAF region progresses upwards within the SAF Block and extends toward the Application Block, by increasing the SAF area through the SAFSZ Configuration bits.

Tip: For more details on the maximum configurable SAF area available on a microcontroller, refer to the Device Configuration section of the respective device data sheet.

Once the SAFLOCK feature is enabled, the configured SAF area will be permanently locked. It is important to note that once the SAFLOCK feature has been enabled, SAFSZ can still be increased, but it can never be decreased. Once the SAFLOCK configuration bit has been activated, it is permissible to expand the region by writing a value of 0 to the individual bits of SAFSZ. However, it is not possible to reduce the size of the SAF, as erasing or writing a value of 1 to SAFSZ is prohibited. Therefore, it is important to configure the desired SAF area and write the content to the SAF area before enabling the SAFLOCK feature.

Tip: For more details on how to configure and access the SAF Block, refer to TB3163 – Memory Access Partition on 8-Bit PIC® Microcontrollers.

In the firmware project, it is necessary to configure the application code block to the specified program size to ensure that the application code does not overlap with the configured SAF area.

Tip: When using MPLAB X IDE and the XC8 compiler, set the ROM (program memory space) ranges appropriately by accessing the XC8 compiler’s global options section of MPLAB X project, as shown in the Setting ROM Ranges in MPLAB® X IDE figure.
Figure 4-7. Setting ROM Ranges in MPLAB® X IDE