Store Custom Data in SFlash for PSoC 6 MCU Device – KBA228374

Author: WangS_81           Version: **

 

The SFlash inside PSoC® 6 MCU occupies a 32-KB flash sector. Data stored in SFlash includes device trim value, Flash Boot executable code, and encryption keys; you can also store any custom data  such as FW/HW information, runtime error log, BLE device address, or any data that would not be changed with normal programming in SFlash. The programming for SFlash is similar to flash. In NORMAL life cycle stage, you can use the Cy_Flash_WriteRow or EraseRow/ProgramRow APIs. After the device transitions into secure mode, SFlash can no longer be changed.

There are four rows in SFlash that are available for user data – 0x16000800, 0x16000A00, 0x16000C00, and 0x1600E00 (total 512 x 4 = 2048 bytes). The automatic SFlash memory allocation is always shown in project linker files after building, as follows:

/* The following regions define device specific memory regions and must not be changed. */

sflash_user_data  (rx)    : ORIGIN = 0x16000800, LENGTH = 0x800      /* Supervisory flash: User data */

sflash_nar        (rx)    : ORIGIN = 0x16001A00, LENGTH = 0x200      /* Supervisory flash: Normal Access Restrictions (NAR) */

sflash_public_key (rx)    : ORIGIN = 0x16005A00, LENGTH = 0xC00 /* Supervisory flash: Public Key */

sflash_toc_2      (rx)    : ORIGIN = 0x16007C00, LENGTH = 0x200      /* Supervisory flash: Table of Content # 2 */

sflash_rtoc_2     (rx)    : ORIGIN = 0x16007E00, LENGTH = 0x200      /* Supervisory flash: Table of Content # 2 Copy */

If you want to use either PSoC Creator or Modus Toolbox™ to place certain custom data in SFlash user row, you can use the “CY_SECTION(".cy_sflash_user_data")”. This is the recommended approach because it is much cleaner than directly writing the data with absolute address, and manageable for future development