An4035 Flash Programming Through Nexusjtag Stmicroelectronics
An4035 Flash Programming Through Nexusjtag Stmicroelectronics
Application note
Flash programming through Nexus/JTAG
Introduction
The SPC56x/RPC56x family of devices has internal Flash used for code and data. The
Nexus debug interface can be used to program the Flash using the JTAG communication
protocol through the JTAG port. This allows programming of the internal Flash by an
external tool.
This application note first addresses the JTAG and Nexus communication protocol. The
JTAG discussion includes the JTAG signals, TAP controller state machine, and the JTAG
controller. The explanation of Nexus includes the on-chip emulation (OnCE) module and the
Nexus read/write (R/W) access block.
Nexus/JTAG Flash programming supports the following products:
SPC563Mxx
SPC564Axx
SPC56APxx
SPC560Dxx
SPC560Bxx
SPC564Bxx
SPC560Cxx
SPC560Pxx
SPC56ECxx
SPC56ELxx
RPC56ELxx
RPC560Bxx
RPC564Bxx
RPC56APxx
RPC564Axx
Contents
1 JTAG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1 JTAG signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 TAP controller state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 JTAG controller (JTAGC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4 Modes of operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4.1 Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.4.2 Test mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.5 Enabling debug of a censored device . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.5.1 CENSOR_CTRL register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 System initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.1 Internal SRAM initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.2 Setting up the memory management unit . . . . . . . . . . . . . . . . . . . . . . . . 35
6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
List of tables
List of figures
1 JTAG
JTAG is a serial communication protocol created by the Joint Test Access Group. Originally
developed for boundary scan, JTAG is also used for communication with the Nexus debug
interface (NDI) on the SPC56x/RPC56x devices.
The JCOMP pin assertion allows to put the JTAGC in reset state.
7(67/2*,&
5(6(7
5817(67,'/( 6(/(&7'56&$1 6(/(&7,56&$1
&$3785('5 &$3785(,5
6+,)7'5 6+,)7,5
(;,7'5 (;,7,5
3$86('5 3$86(,5
(;,7'5 (;,7,5
83'$7('5 83'$7(,5
*$3*36
-&203
7HVW$FFHVV3RUW7$3
706 &RQWUROOHU
7&.
%LW%\SDVV5HJLVWHU
%LW'HYLFH,GHQWLILFDWLRQ5HJLVWHU
7',
%RXQGDU\6FDQ5HJLVWHU
7'2
7(67B&75/5HJLVWHU
&(1625B&75/5HJLVWHU
%LW7$3,QVWUXFWLRQ'HFRGHU
%LW7$3,QVWUXFWLRQ5HJLVWHU
*$3*36
the shifter to the register during the update-DR state. When reading a register, there is no
requirement to shift out the entire register contents. Shifting can be terminated after fetching
the required number of bits.
1.4.1 Reset
The JTAGC is placed in reset when the TAP controller state machine is in the TEST-LOGIC-
RESET state.
The TEST-LOGIC-RESET state is entered upon the assertion of the power-on reset signal,
negation of JCOMP, or through TAP controller state machine transitions controlled by TMS.
Asserting power-on reset or negating JCOMP results in asynchronous entry into the reset
state. While in reset, the following actions occur:
The TAP controller is forced into the test-logic-reset state, thereby disabling the test
logic and allowing normal operation of the on-chip system logic to continue unhindered.
The instruction register is loaded with the IDCODE instruction.
In addition, execution of EXTEST instruction results in assertion of the internal system reset.
2WKHU1H[XV&OLHQWV
&HQVRUHG)ODVK$UUD\ H'0$
H]SURFHVVRU
ELW3DVVZRUG
(QDEOHGLVDEOH
&RPSDUH
1H[XVFOLHQW
7$3FRQWUROOHU
-7$*3RUW&RQWUROOHU
ELW3DVVZRUG
&(1625B&75/UHJLVWHU
'HEXJ&DOLEUDWLRQ7RRO
$FFHVV
*$3*36
The steps to enable the debug port on a censored device are as follows:
1. After the RSTOUT pin has is negated, hold the device in system reset state using a
debugger or other tool.
2. While the device is being held in system reset state shift the 64-bit password into the
CENSOR_CTRL register (via the JTAG port using the JTAG
ENABLE_CENSOR_CTRL instruction. The JTAG serial password is compared against
the serial boot flash password from the flash shadow block.
3. If there is a match the Nexus client TAP controller enters normal operation mode and
the DISNEX flag in the SIU_CCR register is negated (for the SPC56xB/RPC56xB and
SPC56xP/RPC56xP families the flag NXEN in the SSCM_STATUS register is negated)
indicating Nexus is enabled. Upon negation of reset the debug / calibration tool is able
to access the device via NEXUS port and JTAG. If the JTAG serial password does not
match the serial boot flash password or the serial boot flash password is an illegal
password then the debug / calibration tool is not able to access the device. After the
debug port is enabled, the tool can access the censored device and can erase and
reprogram the shadow flash block in order to uncensor the device.
Note: If the shadow flash block is erased without reprogramming a new valid password before a
reset, it contains an illegal password and the debug port is inaccessible.
4. Subsequent resets clear the JTAG censor password register and the Nexus client TAP
controller holds in reset again. Therefore, the tool must resend the JTAG serial
password, as described above, in order to enable the Nexus client TAP controller
again.
All of the SPC56x/RPC56x devices possess a OnCE module for debug control of the Power
Architecture® e200 core. The OnCE logic provides Nexus class 1 static debug capability
including run-time control, register access, and memory access to all memory-mapped
regions including on-chip peripherals, as well as providing access to the Nexus2 & Nexus3
configuration registers. The OnCE module is controlled by the JTAG signals through the
OnCE TAP controller.
)URP
-7$*& ^ H]B7567
H]B706
7HVW$FFHVV3RUW7$3
&RQWUROOHU
7&. 7'20X[
&RQWURO
7$3,QVWUXFWLRQ5HJLVWHU
2Q&(2&0'
%\SDVV5HJLVWHU
7',
H]B7'2
([WHUQDO'DWD5HJLVWHU WR-7$*&
2Q&(0DSSHG'HEXJ5HJLVWHUV
$X[LOLDU\'DWD5HJLVWHU
*$3*36
state. The state machine is returned to the RUN-TEST/IDLE state when the write is
complete.
1 1 X SELECT-DR-SCAN
2 1 X SELECT-IR-SCAN
3 0 X CAPTURE-IR
4 0 X SHIFT-IR
5 0 1 SHIFT-IR
6 0 0 SHIFT-IR
7 0 0 SHIFT-IR
8 0 0 SHIFT-IR
9 1 1 SHIFT-IR
10 1 X UPDATE-IR
11 0 X RUN-TEST/IDLE
controlling access to a resource, as well as controlling single step operations and exit from
debug mode. Figure 7 shows the register definition for the OnCE command register.
5
5: *2 (; 56>@
:
5HVHW
*$3*36
Table 4 shows the OnCE register addresses. Access to the registers CPUSCR, DAC1-2,
DBCNT, DBCR0-3, DBSR, and IAC1-4 require that the external debug mode bit,
DBCR0[EDM], be set to a logical 1. Only the DBCR0[EDM] is accessible in the DBCR0
register prior to that bit being set. Setting DBCR0[EDM] enables external debug mode and
disables software updates to debug registers. The CPU should be placed in debug mode via
the OCR[DR] bit prior to setting the DBCR0[EDM] bit.
*$3*36
The example of writing DBCR0 is divided into two parts: writing OCMD to select a write to
DBCR0, and writing the value 0x80000000 to DBCR0. All data are scanned in the least
significant bit first.
Figure 9 shows writing the value 0b00_0011_0001 to OCMD through the IR path to select a
write to DBCR0 assuming the TAP controller state machine is initially in the RUN-
TEST/IDLE state. The state machine is returned to the RUN-TEST/IDLE state when the
write is complete.
Figure 10 shows writing the value 0x80000000 to DBCR0 through the DR path to set the
EDM bit assuming the TAP controller state machine is initially in the RUN-TEST/IDLE state.
The state machine is returned to the RUN-TEST/IDLE state when the write is complete.
Figure 11. Signal transitions for writing OCMD to select a read from DBCR0
Figure 12 shows reading the value 0x80000000 from DBCR0 through the DR path
assuming the TAP controller state machine is initially in the RUN-TEST/IDLE state. The
state machine is returned to the RUN-TEST/IDLE state when the read is complete.
*$3*36
Figure 14 shows reading the OnCE status register on TDO while writing the OCMD on TDI
assuming the TAP controller state machine is initially in the RUN-TEST/IDLE state. The
state machine is returned to the RUN-TEST/IDLE state when the read is complete. The
OCMD is written with the value 0b10_0001_0001 choosing a read of No Register Selected.
The data read on TDO from the OnCE status register is 0b10_0000_1001 showing that the
OSR[MCLK] and OSR[DEBUG] status bits are set. All data is scanned in and out least
significant bit first.
:.
'0',6 ': ', '0 '* '( )'% '5
83
*$3*36
The OCR[DR] bit is the CPU debug request control bit and requests the CPU to
unconditionally enter debug mode. The OCR[WKUP] bit is the wakeup request bit used to
guarantee that the CPU clock is running. Debug status and CPU clock activity can be
determined by reading the DEBUG and MCLK bits in the OnCE status register. After
entering debug mode, the OCR[DR] bit should be cleared leaving the OCR[WKUP] bit set.
OCR[FDB] should also then be set to enable recognition of software breakpoints.
The steps required for entering debug mode during reset assuming the OnCE TAP
controller has been enabled are listed below:
1. Assert RESET.
2. Set the OCR[DR] and OCR[WKUP] bits.
3. De-assert RESET.
4. Verify debug mode via the DEBUG bit in the OnCE status register.
5. Clear the OCR[DR] bit while leaving OCR[WKUP] set and set OCR[FDB].
,'( 8'( 055 ,&03 %57 ,537 75$3 ,$& ,$& ,$& ,$& '$& '$& '$& '$&
5
5 : 5 :
:
5HVHW
'(97 '(9 '&17 '&17 &,537 &5(7 &17
5 5(7
7 5*
:
5HVHW
*$3*36
7'2
7&.
:%%5ORZ
7',
:%%5KLJK
065
3&
,5
&7/
*$3*36
3&2)67
,567$7
,567$7
,567$7
,567$7
,567$7
,567$7
,567$7
,567$7
,567$7
,567$7
3&,19
))5$
*$3*36
The “*” in the CTL register represents the internal processor state bits that should be
restored to the value they held when debug mode was entered prior to exiting debug mode.
If a single step is executing an instruction that is in the normal instruction flow of the
program that was running when debug mode was entered, these bits should be restored. If
a single step is executing an instruction outside the normal instruction flow, these bits should
be cleared to zero.
The PCOFST field indicates whether the value in the PC portion of the CPUSCR must be
adjusted prior to exiting debug mode. Due to the pipelined nature of the CPU, the PC value
must be backed-up under certain circumstances. The PCOFST field specifies the value to
be subtracted from the PC value when debug mode was entered. This PC value should be
adjusted according to PCOFST prior to exit from debug mode if continuation of the normal
instruction stream is desired. In the event that PCOFST is non-zero, the IR should be
loaded with a nop instruction instead of the value in the IR when debug mode was entered.
Below are the possible values and meanings of the PCOFST field:
0000—No correction required.
0001—Subtract 0x04 from PC.
0010—Subtract 0x08 from PC.
0011—Subtract 0x0C from PC.
0100—Subtract 0x10 from PC.
0101—Subtract 0x14 from PC.
All other encodings are reserved.
After entering debug mode, the PCINV field overrides the PCOFST field and indicates that
values in the PC and IR are invalid. Exiting debug mode with these PC and IR values have
unpredictable results:
No error condition exists.
Error condition exists. PC and IR are corrupted.
The FFRA control bit causes the contents of WBBR to be used as the rA (rS for logical and
shift operations) operand value of the first instruction to be executed when exiting debug
mode or the instruction to be single stepped. This allows the external tool to update CPU
registers and memory. rA and rS are instruction syntax used to identify a source GPR:
No action.
Contents of WBBR used as rA (rS for logical and shift operations) operand value.
The IRStat0-9 bits provide status information to the external tool. The IRStat8 bit indicates
that the instruction in the IR is a VLE or non-VLE instruction. For MPC5500 devices without
VLE, bits IRstat8 and IRstat9 of the CTL do not exist. Below is a description of the IRStat8
bit.
All other CTL bits are discussed as needed.:
IR contains a BookE instruction.
IR contains a PowerPC VLE instruction, aligned in the most significant portion of IR if
16-bit.
PC and IR portions of the CPUSCR. Care must be taken to insure that the next instruction
fetched after the single step, points to a valid memory location.
For SPC56x/RPC56x devices with VLE, the CTL[IRstat8] bit indicates that the instruction in
the IR is a VLE or non-VLE instruction. The CTL[FFRA], CTL[IRStat8], and the CTL bits
indicated by “*” should be set as appropriate before single stepping. All other CTL bits
should be set to zero. Single stepping can be used during normal execution of the
instruction flow or to force execution of a particular instruction by loading the desired
instruction into the IR portion of the CPUSCR. By forcing execution of particular instructions,
single stepping can be used for memory and register access by the tool.
saved GPR and WBBRlow, and then restoring the GPR. As an example, to read SPR 624,
first save r31. Then execute mfspr r31, 624. The value that was in SPR 624 is now in
WBBRlow of the CPUSCR and can be read by the external tool. Finally r31 should be
restored.
To write an SPR, single step over a mtspr instruction with the value to write to the SPR in
WBBRlow and the CTL[FFRA] bit set. For example, to write SPR 624 with the value
0x10050000, single step over mtspr 624, X with the value to write to SPR 624 in WBBRlow
and CTL[FFRA] set. The X in the instruction is replaced by WBBRlow.
DBCR0-3, DBSR, DBCNT, IAC1-4, DAC1-2 cannot be written by single stepping over mtspr
like the other SPRs while in external debug mode. They can however be written by the
method detailed in Section 2.2: OnCE register access.
2.13 Breakpoints
The OnCE debug module provides the capability for both software and hardware
breakpoints to be set at a particular address.
As a reference, instruction address hardware breakpoints are also discussed in this section.
The Nexus module provided on the cores of the SPC56x/RPC56x family of devices offers
the capability for program trace, data trace, ownership trace, watch-point messaging and
trigger, and read/write (R/W) access to memory mapped regions. This section covers R/W
access using the Nexus R/W access block. The other features of the Nexus module are out
of the scope of this document and are not covered.
Unlike the OnCE method of memory access, the Nexus R/W access block provides the
ability to read and write memory without having to stop code execution by entering debug
mode. The Nexus R/W access method provides faster memory access over the OnCE
method due to fewer JTAG scans, and it doesn’t require loading and single stepping over
any instructions. The Nexus R/W access block is independent of the CPU.
The R/W access block is controlled by three Nexus registers. These registers are the
Read/Write Access Control/Status register (RWCS), Read/Write Access Data register
(RWD), and Read/Write Access Address register (RWA). Access to the Nexus registers is
covered inSection 3.1. RWCS is shown in Figure 19 and Figure 5 gives the field
descriptions.
5 $& 5: 6= 0$3 35 %67
:
5HVHW
1H[XV
[
5HJ
5
&17 (55 '9
:
5HVHW
1H[XV
[
5HJ
*$3*36
Access control.
31 AC 0 End access
1 Start access
Read/write select.
30 RW 0 Read access
1 Write access
Word size.
0008-bit (byte)
SZ 0016-bit (half-word)
29–27
[2:0] 01032-bit (word)
01164-bit (double-word - only in burst mode)
100–111 Reserved (default to word)
MAP select.
MAP
26–24 000Primary memory map
[2:0]
001-111 Reserved
Read/write access priority.
00Lowest access priority
PR
23–22 01Reserved (default to lowest priority)
[1:0]
10Reserved (default to lowest priority)
11Highest access priority
BST Burst control.
21 BST 0 Module accesses are single bus cycle at a time.
1 Module accesses are performed as burst operation.
20–16 — Reserved.
CNT
15–2 Access control count. Number of accesses of word size SZ.
[13:0]
1 ERR Read/write access error. See Table 6.
0 DV Read/write access data valid. See Table 6.
5
5HDG:ULWH'DWD
:
5HVHW
1H[XV
[$
5HJ
5
5HDG:ULWH'DWD
:
5HVHW
1H[XV
[$
5HJ
*$3*36
5
5HDG:ULWH$GGUHVV
:
5HVHW
1H[XV
[
5HJ
5
5HDG:ULWH$GGUHVV
:
5HVHW
1H[XV
[
5HJ
*$3*36
ELWV ELW
1H[XV5HJLVWHU,QGH[ 5:
5(6(79DOXH[
*$3*36
0 Read
Read/Write (R/W)
1 Write
2. The second pass through the DR then shifts the data in or out depending on the type of
access LSB first.
a) During a read access, the data is latched from the Nexus register when the TAP
controller state machine passes through the CAPTURE-DR state. The data from
the Nexus register can be read by the external tool by shifting the data out in the
SHIFT-DR state. The last bit is shifted out with TMS set to 1, causing transition to
the EXIT1-DR state.
b) During a write access, the data is shifted in while in the SHIFT-DR state. The last
bit is shifted in with TMS set to 1, causing transition to the EXIT1-DR state. The
data is latched into the Nexus register when the TAP controller state machine
passes through the UPDATE-DR state.
is buffered internally by the burst data buffer. The endianess of the 32-bit data written to
RWD needs to be little endian.
Value of 0xDEADBEEF to be written to memory: RWD = 0xEFBEADDE
4. The Nexus block then arbitrates for the system bus and transfer the burst data from the
burst data buffer to the memory starting at the address in RWA. When the access has
completed without error, then RWCS[ERR] = 0 and RWCS[DV] = 0. This indicates that
the device is ready for the next access. Nexus also asserts the RDY pin when the
transaction has completed without error. The external tool can use this as an
alternative to polling the RWCS status bits.
4 System initialization
For Flash programming, there is some system initialization that needs to be performed by
the external tool.
The initialization to perform is the SRAM initialization.
This section covers the Flash drivers provided by STMicroelectronics®, the tool
requirements, and also suggests a functional division of the tool.
5.2.2 FlashInit
After the drivers are loaded into internal SRAM, operations on the Flash can begin. The
FlashInit driver should be called first to initialize the Flash.
This function reads the Flash configuration information from the Flash control registers and
initialize parameters in SSD configuration structure. ‘FlashInit()’ must be called prior to any
other flash operations.
The steps required are outlined below.
1. Setup the SSD_CONFIG structure as required. This is documented in the SSD user’s
manual. The user should correctly initialize the fields c90flRegBase, mainArrayBase,
shadowRowBase, shadowRowSize, pageSize, and BDMEnable. The other fields are
initialized when FlashInit is executed. BDMEnable should be set to 1 to cause debug
mode to be entered via a software breakpoint when each driver completes execution.
This is the easiest way for the external tool to determine when driver execution is
complete.
2. Setup r1 as the stack pointer by writing r1 using the method described in Section 2.10:
GPR access.
3. Setup r3 to point to the SSD_CONFIG structure in internal SRAM.
4. Set the PC to the beginning of FlashInit minus 0x4 and load the IR with a nop
(0x60000000). See Section 2.7: CPU Status and Control Scan Chain Register
(CPUSCR) for details.
5. Exit debug mode and begin execution of the driver as described in Section 2.9: Exit
from debug mode to normal execution.
6. Poll the OnCE Status Register to determine when debug mode has been re-entered.
Reading the OnCE Status Register is described in Section 2.4: OnCE status register.
7. When debug mode has been entered, read the return value in r3.
5.2.3 SetLock
After the Flash has been initialized using the FlashInit function, the SetLock function should
be called as many times as required to unlock or lock the appropriate Flash blocks. This
function sets the block lock state for Shadow/Low/Middle/High address space on the C90FL
module to protect them from program/erase. The API provides password to enable block
lock register writes when needed and write the block lock value to block lock register for the
requested address space.
For the low and mid blocks as well as the shadow block, the lock bits in both the primary and
secondary lock registers must be set appropriately. It is recommended to lock the shadow
block unless programming of the shadow block is absolutely necessary. Erasing the shadow
block without re-programming the censorship information prior to a reset causes the device
to be censored with an invalid password and the Flash of the device is not able to be
uncensored.
The steps to call the SetLock driver are listed below.
5.2.4 FlashErase
When the appropriate blocks have been locked or unlocked, then an erase of the unlocked
blocks can be performed.
This function erases the enabled blocks in the main array or the shadow row. Input
arguments together with relevant Flash module status is checked, and relevant error code
returns if there is any error.
The steps to call the FlashErase driver are listed below.
1. Setup r1 as the stack pointer.
2. Setup r3 to point to the SSD_CONFIG structure in internal SRAM.
3. Setup r4 to indicate either the main array or shadow block to be erased. Erasing the
shadow block without re-programming the censorship control information prior to a
reset results in the device being censored.
4. Setup r5 to select the low address array blocks to be erased.
5. Setup r6 to select the mid address array blocks to be erased.
6. Setup r7 to select the high address array blocks to be erased.
7. Setup r8 with the pointer to the call back function.
8. Set the PC to the beginning of FlashErase minus 0x4 and load the IR with a nop
(0x60000000).
9. Exit debug mode and begin execution of the driver.
10. Poll the OnCE Status Register to determine when debug mode has been re-entered.
11. When debug mode has been entered, read the return value in r3.
5.2.5 FlashProgram
When Flash blocks have been erased, they then can be programmed. To program the
Flash, the internal SRAM should first be written with the data to be programmed in Flash.
Depending on the size of the data buffer in internal SRAM and the size of the data to be
programmed to Flash, the FlashProgram driver may need to be called multiple times.
This function programs the specified flash areas with the provided source data. Input
arguments together with relevant flash module status is checked, and relevant error code is
returned if there is any error.
The steps to call the FlashProgram driver are listed below.
6 Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.