From SEGGER Wiki
Jump to: navigation, search

The NXP S32Kxxx series is a scalable family of 32-bit ARM Cortex-M4 based MCUs targeted for general purpose automotive and high-reliability industrial applications.

FlexNVM block partitioning

The S32Kxx series devices come with a FlexNVM area. FlexNVM is an additional separate block of flash memory. The user can configure the FlexNVM block as: Basic data flash, non volatile storage for emulated EEPROM or a combination of both. For further information please refer to the device specific manual from NXP. For programming via J-Link to be successful, the FlexNVM sector must be configured correctly. For this, the "Program Partition command" must be used.

Program Partition command

The Program Partition command sets the partitioning of the FlexNVM block. The changes related to execution of the Program Partition command take effect after the next reset. For FlexNVM to be used as a flash (and/or EEPROM) it has to be partitioned accordingly. Otherwise it is not accessible. Please note that the data flash IFR must be in an erased state prior launching the Program Partition command. This can be accomplished by executing the Erase All Blocks command. Please note that the device needs to be unlocked after this command has been executed and before executing the Program Partition command sequence.

This J-Link Commander example shows how to initialize the FlexNVM section as flash memory / no EEPROM using the "Program Partition command".


  • J-Link Commander V6.40
  • S32K118EVB-Q064 EvalBoard (32 KiB D-FLASH)
  • J-Link Plus V10

J-Link Commander command line arguments

JLink.exe -device S32K118 -if SWD -speed 4000 -autoconnect 1

J-Link Commander sequence

r                       // Reset target to bring it into a known / proper state
w1 0x40020007, 0x80     // FCOOB0 Program Partition command
w1 0x40020006, 0x00     // FCOOB1 Set CSEc Key Size to 0
w1 0x40020005, 0x00     // FCOOB2 SFE disabled
w1 0x40020004, 0x01     // FCOOB3 0 --> FlexRAM loaded with valid EEPROM data during reset; 1 --> FlexRAM not loaded during reset
w1 0x4002000B, 0x0F     // FCOOB4 Data size for EEPROM Set to 0
w1 0x4002000A, 0x0B     // FCOOB5 Partition Code set to not EEPROM (DEPART)
w1 0x40020000, 0x80     // FSTAT Start operation
sleep 100               // Wait 100ms

Check partitioning

By reading the 32-bit FCFG1 register (0x4004804C) the DEPART bits ([15:12]) show the FlexNVM partition code (Note: The device needs to be power cycled after setting a new partition, since the new DEPART value is refreshed only after power off).

J-Link Commander sequence

mem32 4004804C, 1

Erase All Blocks command

The "Erase All Blocks" command can be used to bring the chip into an erased state.

J-Link Commander sequence

speed 4000
r                       // Reset target
w1 0x40020007, 0x44     // FCOOB0 Erase All Blocks command
w1 0x40020000, 0x80     // FSTAT Start operation
sleep 1000              // Wait 1 sec.

Note: After executing the sequence above, the chip is in a "secured" state because the erased value of the security byte means "secured". The J-Link DLL offers a unlock of the device on the next connect after erase.

Debug Requirements

There are some special requirements that need to be fulfilled in order to use the device series with J-Link:

  • Reset pin of MCU needs to be connected to reset pin of J-Link. If this is not the case, proper target connection cannot be guaranteed

ECC protected internal RAM

The device series provide ECC protected internal RAM. By default, J-Link resets the MCU on connect and initializes the RAM contents to 0x00. This is done for the following reasons:

  • If a memory window in the debugger is open during the debug session and points to a non-initialized RAM region, on the next single step etc. a non-maskable ECC error interrupt would be thrown
  • J-Link temporarily uses some portions of the RAM during flash programming and accesses to non-initialized RAM areas would throw non maskable ECC error interrupts

Attach to debug session

For the reasons mentioned in ECC protected internal RAM, no out of the box attach is possible. This is because there is no way to distinguish between an attach and a connect.

To attach to the device the following J-Link script file can be used:

This script file is only supposed to be used in case of an attach, as it skips the device specific connect.

Readout protection of internal flash

The internal flash of the S32K14x series devices can be protected against unwanted readout accesses. The readout protection is configured via the option bytes placed at addr. 0x400 - 0x40F in the internal flash of the devices.

Enabling protection in production

Make sure that the application image that is programmed contains a value not equal to 0xFE to be programmed to addr. 0x40C. Make also sure that for the device selection in J-Flash etc. the variant S32K... (allow security) is selected. If this is not the case, J-Link will inhibit that the readout protection of the device is set.