Difference between revisions of "S32Kxxx"

From SEGGER Wiki
Jump to: navigation, search
(Solution example)
(Note)
Line 11: Line 11:
 
For FlexNVM to be used as a flash it has to be partitioned accordingly. Otherwise it is not accessible.
 
For FlexNVM to be used as a flash it has to be partitioned accordingly. Otherwise it is not accessible.
 
Further the flash needs to be in the "erased" state before it can be partitioned (see [[S32Kxx#Erase_All_Blocks_command|"Erase All Blocks" command]]). Note that NXP advises to always erase the chip before partitioning, since the "erased" state might decay over time.
 
Further the flash needs to be in the "erased" state before it can be partitioned (see [[S32Kxx#Erase_All_Blocks_command|"Erase All Blocks" command]]). Note that NXP advises to always erase the chip before partitioning, since the "erased" state might decay over time.
 
=== Note ===
 
* In the following examples J-Link Commander V6.40 was used with the S32K118EVB-Q064 EvalBoard and a J-Link Plus V10.
 
* For easy access to the J-Link Commander, a cmd line is advised (for further information please refer to "[[J-Link_Commander#Batch_processing|Batch processing]]"):
 
: <code>"<JLinkInstallPath>\JLink.exe" -device S32K118 -if SWD -speed 4000 -autoconnect 1 </code>
 
:* If you need an automated process, you can also execute the steps via a J-Link Commander script (.jlink) by adding <code>-CommanderScript <PathToScript>\script.jlink</code> to the cmd line:
 
:: <code>"<J-LinkInstallPath>\JLink.exe" -device S32K118 -if SWD -speed 4000 -autoconnect 1 -CommanderScript <PathToScript>\<scriptName>.jlink </code>
 
   
 
=== Solution example ===
 
=== Solution example ===

Revision as of 12:15, 12 March 2019

FlexNVM block partitioning

The S32Kxx series devices comes with a FlexNVM block partitioning for FlexRAM. 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 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 prepares the FlexNVM block for use as data flash, emulated EEPROM backup or a combination of both and initializes the FlexRAM. The Changes related to execution of the Program Partition command take effect after the next reset.

Problem description

For FlexNVM to be used as a flash it has to be partitioned accordingly. Otherwise it is not accessible. Further the flash needs to be in the "erased" state before it can be partitioned (see "Erase All Blocks" command). Note that NXP advises to always erase the chip before partitioning, since the "erased" state might decay over time.

Solution example

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

After connecting to the device with the J-Link Commander (e.g. using a cmd line). This code initializes FlexNVM as flash memory only (No EEPROM) using the "Program Partition command":

r // Reset target
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 0,1 sec.
q

Check partitioning

When using the mentioned setup: By reading the 32-bit FCFG1 register (4004804C) 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):

mem32 4004804C, 1

Erase All Blocks command

The "Erase All Blocks" command can be used to bring the chip into an erased state. As mentioned in Problem description the partition can be set after bringing the chip into an erased state. (Note: The chip is also in "secured" state after erasing and is unlocked automatically by connecting to it). The Code should look like the following:

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

Power cycle device. Then connect to it agian and unsecure the chip. After that the Program Partition command can then be used. It is important to powercycle and unsecure the chip before partitioning it. Otherwise the partitioning will be erased by unsecuring the chip again.