The SPC564Bxx and SPC56ECxx is a family of Power Architecture® based microcontrollers
that target automotive vehicle body and gateway applications such as Central body
controller, Smart junction boxes, Front modules, High end gateway, Combined Body
controller and gateway.
These dual core architecture devices contain an e200z4d and e200z0h core, compliant with
the Power Architecture standard.
It provides the scalability needed to implement platform approaches and delivers the
performance required by increasingly sophisticated software architectures.
These devices feature up to 3 MB of internal Flash and up to 256 KB of internal SRAM
memory.
It operates at speeds of up to 120 MHz and offers high performance processing optimized
for low power consumption.
The SPC564Bxx and SPC56ECxx family expands the range of the SPC560B/C
microcontroller family but differs from it by being the first device to feature the e200z4d core
and the e200z0h in a dual core configuration.
The differences between this family and the previous one (SPC560B/C) mean that the
initialization and configuration are different.
This application note details the steps required to properly initialize the SPC564Bxx and
SPC56ECxx from reset as well as how to control the second core. An example code is
described throughout the application note to explain the steps.
It is intended that this application note is read along with the SPC564Bxx and SPC56ECxx Reference Manual, RM0070 that can be obtained from the STMicroelectronics
http://www.st.com (see Section C.1: Reference document).
This application note describes the necessary steps to configure the device in order to run
two independent codes on the two cores.
This family is quite different from the previous one, indeed apart from the memories size
now it has been introduced the dual core concept: in the SPC564Bxx and SPC56ECxx
family the primary core is an e200z4d while the second one is a e200z0h.
While the second core (e200z0h) is thought only as performance core (only to speed up the
execution), the introduction of the e200z4d implies that the user has a more powerful
architecture to cope with the application tasks.
The availability of MMU, ICache and Signal Processing instructions enhance the
performance, but require the correct configuration.
The example code described herein toggles two LEDs with each core running the
application independent of the other.
It has been chosen to treat the two applications separately to better understand the dual
core concept even for compiler projects: of course each project produces one executable
image. The user then has to program the device with both executable images (the
instruction codes are located in different places).
Following this strategy the device is perceived as two separate MCUs each with proprietary
Flash and SRAM.
In this application note, it has been decided to split (in equal parts) the Flash and the SRAM
for both cores.
The memory partition and the XBAR (crossbar architecture) have been optimized for dual
core operations and in particular to give priority to e200z4d core (see Section 3.1.7:
Performance Hints Initialization):
●The SRAM is split over 2 slave ports, 0x4000_0000 to 0x4001_FFFF on slave port 2
(used by e200z4d) and 0x4002_0000 to 0x4003_FFFF on slave port 3 (used by
e200z0h);
●There are 2 Flash ports, z4 instruction port on slave port 0 and a second Flash port for
everything else on slave port 1.
By splitting the SRAM in the linker file(s) so that the e200z4d has access to one block and
the e200z0h has access to the other block, crossbar contentions are generally avoided
between the cores for SRAM access
(a)
(see Appendix B: Linker file).
a. When, for example, there are large amounts of DMA transfers to/from SRAM it could be useful to use the
SRAM allocated to the processor which allows fewer accesses to SRAM. User has to take care that none of
this prevents either core from writing the full SRAM array so care has to be taken in software (using
semaphores and / or software interrupts) to ensure memory coherency.
6/49Doc ID 022384 Rev 1
AN3995Microcontroller boot
2 Microcontroller boot
This chapter describes the configuration required by the user, and the steps performed by
the microcontroller
(b)
and in particular, by the SSCM (System Status and Configuration
Module), in order to achieve a successful boot from Flash memory.
For further information, look at SPC564Bxx and SPC56ECxx Reference Manual (see
Section C.1: Reference document).
2.1 Boot mechanism
SPC564Bxx and SPC56ECxx family (as other SPC56xx devices), has two hardware boot
configuration pins, FAB (Force Alternate Boot mode) and ABS (Alternate Boot Select).
These 2 external pins on the microcontroller are latched during reset and used by the SSCM
to determine whether the microcontroller boots from Flash memory or attempts a serial
download via FlexCAN or LINFlex (RS232) (see Tab l e 1 ).
In this application note, the focus is on the default operating mode: the Flash boot mode.
Table 1.Boot mode selection
ModeFAB pin (PA[9])ABS pin (PA[8])
Flash Boot (Default Mode)0–
Serial Boot (LINFlex)10
Serial Boot (FlexCAN)11
When the device is powered on, the SSCM (System Status Configuration Module) searches
the pre-determined locations in Flash for a valid RCHW (Reset Configuration Half Word)
(see Section 2.1.1: Bootable sectors and RCHW).
●If a valid BOOT_ID is found, the SSCM reads the VLE bit and the boot vector address
(as well as the CSE block size).
●If a valid BOOT_ID is not found, the SSCM starts the process of putting the
microcontroller (e200z4d) into static mode
(c)
. See SPC564Bxx and SPC56ECxx family
Reference Manual for detailed information (see Section C.1: Reference document).
Note:The static mode differs from safe mode. Static mode is a non-operational mode which can
only be entered via the BAM (Boot Assist Module).
b. The booting mechanism has an impact only on the e200z4d core.
c. Static Mode Sequence:
1. The SSCM creates a 4 KB MMU page at the start of the BAM with the VLE bit set (the BAM is VLE code).
2. The SSCM then sets the CPU core (e200z4d) instruction pointer to the BAM address and the core starts to
execute the code to enter static mode as follows:
- the Software Watchdog Timer (SWT) is enabled;
- the core executes the "wait" instruction which halts the core.
After the microcontroller enters static mode, the SWT periodically resets the core (approximately every 10 ms)
to re-attempt a boot from Flash memory.
Doc ID 022384 Rev 17/49
Microcontroller bootAN3995
In all these conditions, the e200z0h core remains held in reset: for further information please
refer to SPC564Bxx and SPC56ECxx Reference Manual, RM0070 (see Section C.1:
Reference document).
In order to access memory (for the e200z4d core), a valid MMU TLB entry has to be
created. The SSCM does this automatically by reading the reset vector and modifying TLB
entry 0 to create a 4 KB page containing the reset vector address.
The MMU VLE bit is set depending on the status of the VLE bit within the RCHW. The 4 KB
MMU page
(d)
must be 4 KB aligned. This means that the most efficient place to put the
application code is immediately after the boot sector (see Section 2.1.1: Bootable sectors
and RCHW). So in order to maximize the available space inside the 4 KB block, the reset
vector should be set close to the start of a 4 KB boundary.
Note:For example, if the reset vector is set to address 0x0000_0020, then the SSCM aligns the 4
KB MMU page to the start of the 4 KB aligned block containing address 0x0000_0020 – an
MMU page starting at address 0x0000_0000.
Similarly, if the reset vector is set to address 0x0000_0FF0 which is towards the end of an
aligned 4 KB block, the MMU page still has to start at 0x0000_0000 leaving very little room
in the 4 KB MMU page for code execution.
Finally, the SSCM sets the e200z4d core instruction pointer to the reset vector address and
starts the core running.
2.1.1 Bootable sectors and RCHW
In order to successfully boot from Flash memory, the user must program two 32-bit fields
into one of the 5 possible boot blocks (see Figure 1).
The entities to program are:
●16-bit Reset Configuration Half Word (RCHW), which contains:
–A BOOT_ID field that must be correctly set to 0x5A in order to "validate" the boot
sector;
–A VLE bit which configures the initial MMU entry to either Power Architecture Book
VLE or Power Architecture Book III-E as described later on in this chapter;
●32-bit reset vector (this is the start address of the user code)
The boot sector also contains a 32-bit field containing the size of the block of data to be
checked by the CSE (Cryptographic Security Engine) during a secure boot. See
SPC564Bxx and SPC56ECxx family Reference Manual, RM0070 for detailed information
(Section C.1: Reference document).
Note:Application code can then be programmed from offset address 0x000C.
d. The 4 KB block provides sufficient space to the user to:
1. Add MMU entries for SRAM and peripherals
2. Perform standard system initialization tasks (initialize the SRAM, setup stack, copy constant data)
3. Transfer execution to RAM, re-define the Flash memory MMU entry and transfer execution back to Flash
memory.
8/49Doc ID 022384 Rev 1
AN3995Microcontroller boot
Figure 1.Boot sector structure
0x0000_0000
0x0000_8000
0x0000_C000
0x0001_0000
0x0001_8000
Boot sector 0
32 KB
Boot sector 1
16 KB
Boot sector 2
16 KB
Boot sector 3
32 KB
Boot sector 4
32 KB
Bit 0Bit 31
0x0
(RCHW)
0x4
0x8
0xC
Code Flash memory
The structure of RCHW is described in Ta bl e 2 :
Table 2.RCHW field description
Boot sector structure
6781516
ReservedReserved
32-bit reset vector (points to star t address of application code)
BOOT_ID
(0x5A)
VLE
Size of Flash memory array to be verified by CSE
(see the CSE chapter)
Application code (from offset 0xC and onward)
FieldDescription
VLE Bit
VLE
0 MMU TLB Entry 0 is configured for Power Architecture Book III-E.
1 MMU TLB Entry 0 is configured for Power Architecture Book VLE.
BOOT_ID
Boot identifier.
If BOOT_ID = 0x5A, the boot sector is considered valid and bootable.
Doc ID 022384 Rev 19/49
e200z4d initialization and example codeAN3995
3 e200z4d initialization and example code
3.1 Creating e200z4d Flash boot file
In order to run an application from Flash memory, the user code must perform a series of
mandatory actions for proper execution:
●Provide reset vector in the location after the RCHW (Section 2.1: Boot mechanism);
●Configure MMU;
●Initialize SRAM (ECC) (see Section 3.1.3: Initialize the SRAM ECC);
●Configure wait states for Flash and SRAM (see Section 3.1.7: Performance Hints
Initialization);
●Configure XBAR (see Section 3.1.7: Performance Hints Initialization);
●Enable SPE (Signal Processing Extension) instructions if needed by the application
●Enable BTB
Initialization).
3.1.1 MMU remarks
The e200z4d core has a Memory Management Unit (MMU)
the e200z4d core to the XBAR (Crossbar) unless a valid MMU entry is configured for that
access.
(e)
(Branch Prediction Buffers) (see Section 3.1.7: Performance Hints
(f)
which prohibits access from
The user has to take care that the MMU only protects access from the e200z4d core to the
crossbar so that, it does not affect any of the other crossbar masters such as the e200z0h
core, FlexRay or the eDMA (see Figure 2).
e. See section e200z4 core in RM0070 (Section C.1: Reference document)
f. MMU is not present on e200z0h core
10/49Doc ID 022384 Rev 1
AN3995e200z4d initialization and example code
Figure 2.SPC564Bxx/SPC56ECxx block diagram
JTAG Port
Nexus Port
NMI0
NMI1
Clocks
Interrupt
Request
Voltage
regulator
16 x
Semaphores
Reset Control
Pad Control
Nexus
FMPLL
SIUL
External
Interrupt
Request
IMUX
GPIO &
RTC/A PI
NMI0
NMI1
4×STM
10 ch
1×12-bit
ADC
JTAGC
Interrupt requests
from peripheral
blocks
CMU
ECSM
SWT
(1)
27 ch or 33 ch
1×10-bit
ADC
Nexus 3+
e200z0h
e200z4d
Nexus 3+
8
PIT RTI
(2)
INTC
×
FlexRay
Instructions
Instructions
MPU
registers
Peripheral Bridge
CTU
FEC
CSE
(Master)
Data
(Master)
(Master)
Data
(Master)
2
32 ch
×
eMIOS
64-bit 8 x 5 crossbar switch
eDMA
(Master)
10
LINFlexD
MPU
×
SRAM
×
128 KB
2
2
×
SRAM
controller
MC_PCUMC_MEMC_CGMMC_RGM
8
DSPI
×
(Slave)
(Slave)
Code Flash
×
1.5 MB
2
Flash memory
controller
DMAMUX
CAN
Sampler
BAM
I2C
Data Flash
64 KB
(Slave)
STCU
SSCM
6
FlexCAN
WKPU
×
Legend:
Notes:
I/O
ADCAnalog-to-Digital Converter
BAMBoot Assist Module
CSECryptographic Services Engine
CANController Area Network (FlexCAN)
CMUClock Monitor Unit
CTUCross Triggering Unit
DMAMUX DMA Channel Multiplexer
DSPIDeserial Serial Peripheral Interface
eDMAenhanced Direct Memory Access
FlexCAN Controller Area Network controller modules
FECFast Ethenet Controller
eMIOSEnhanced Modular Input Output System
ECSMError Correction Status Module
FMPLLFrequency-Modulated Phase-Locked Loop
FlexRay FlexRay Communication Controller
I2CInter-integrated Circuit Bus
IMUXInternal Multiplexer
INTCInterrupt Controller
(3)
(3)
JTAGCJTAG controller
LINFlexD Local Interconnect Network Flexible with DMA support
MC_MEMode Entry Module
MC_CGM Clock Generation Module
MC_PCU Power Control Unit
MC_RGM Reset Generation Module
MPUMemory Protection Unit
NexusNexus Development Interface
NMINon-Maskable Interrupt
PIT_RTI Periodic Interrupt Timer with Real-Time Interrupt
RTC/API Real-Time Clock/ Autonomous Periodic Interrupt
SIULSystem Integration Unit Lite
SRAMStatic Random-Access Memory
SSCMSystem Status Configuration Module
STMSystem Timer Module
SWTSoftware Watchdog Timer
STCUSelf Test Control Unit
WKPUWakeup Unit
1) 10 dedicated channels plus up to 19 shared channels. See the device-comparison table.
2) Package dependent. 27 or 33 dedicated channels plus up to 19 shared channels. See the device-comparison table.
3)
16 x precision channels (ANP) are mapped on input only I/O cells.
Doc ID 022384 Rev 111/49
e200z4d initialization and example codeAN3995
As previously described in the Section 2.1: Boot mechanism the MMU is not automatically
configured
(g)
apart from a small 4 KB page containing the reset vector address in the TLB
entry 0.
This means that the MMU must be configured by the user, before any access outside to the
block mapped by the SSCM.
In a typical application, the e200z4d core accesses Flash, SRAM and the peripheral blocks
and therefore MMU access needs to be granted.
An example of configuration is showed in Ta bl e 3 .
This configuration is quite similar to the ones implemented in this application note with the
exception of the SRAM 2 memory area (second row of the table). The relative TLB was not
configured because this area is used by the performance core (e200z0h).
Note:The e200z4d core has 16 MMU TLB entries and these allow the user to increase if needed
the protection granularity by splitting the memory in several blocks.
For further information see Memory Protection Unit section in the Reference Manual (see
Section C.1: Reference document).
Table 3.Example of MMU configuration
Memory areaMemory addressSizeClosest MMU size
SRAM 10x4000_0000 - 0x4001_FFFF128KB128KB
SRAM 20x4002_0000 - 0x4003_FFFF128KB128KB
Flash including shadow
sector
Peripherals0xC000_0000 - 0xFFFF_FFFF1GB1GB
0x0000_0000 - 0x00FF_FFFF16MB16MB
The user has to take into account setting up the stack (see Section 3.1.3: Initialize the
SRAM ECC), prior to performing any RAM accesses like executing the mandatory ECC
initialization, or before any peripheral register writes, the memory spaces have to be
configured through the MMU entries.
These considerations both with small block (4KB) mapped by SSCM on TLB entry 0 by
default (see Section 2.1: Boot mechanism) imply that all MMU regions have to be mapped at
the start of the boot code.
MMU pages must not overlap and must also be configured on a boundary matching their
size (for example, 4 KB MMU page must sit on a 4 KB boundary).
Moreover, it is strongly recommended that the user doesn’t change the MMU configuration
of a memory location currently being accessed, otherwise there is potential for errors.
The suggested order of MMU configuration could be defined as follows:
g. In this device family the Boot Assist Module (BAM) does not run when the device performs a normal Flash boot
then the MMU configurations must be done by the user.
12/49Doc ID 022384 Rev 1
AN3995e200z4d initialization and example code
1.Configure the MMU TLB entry for RAM. In this manner, the user code can initialize the
SRAM ECC (seeSection 3.1.3: Initialize the SRAM ECC).
2. Configure the MMU TLB entry for Flash
(h)
(see Section 3.1.4: Configure MMU for
Flash)
–Copy configuration code to SRAM
(i)
–Jump to first instruction of this code in SRAM and execute it
–Transfer execution back to the Flash
3. Configure the MMU TLB entry for the IPBridge (peripherals space) (see Section 3.1.5:
Configure MMU for Peripheral Bridge)
3.1.2 Configure MMU for SRAM
In order to configure MMU TLB entries, there are four MMU Assist registers (MAS) which
are written with the TLB entry number, start address and size of the MMU entry and other
information such as whether the page is VLE or BookE instructions.
In Figure 3 is showed a scratch code of MMU configuration
Figure 3.MMU configuration code for SRAM
#/*************************************************************************/
#/* MMU configuration code for SRAM */
#/* TLB1, Entry 1 128KB 0x4000_0000 to 0x4001_FFFF */
#/*************************************************************************/
The SRAM space mapped through the TLB 1 is half of the space available on the device
(k)
and it corresponds to the bank placed at the lower addresses.
The example shown here is using this as the upper bank is reserved for the e200z0h core.
h. In this application note the strategy suggested is to re-uses the TLB 0 to map all Flash memory space.
i. User can use this mechanism at this time (the execution from SRAM) to configure the wait states for Flash (see
Section 3.1.7: Performance Hints Initialization): to avoid executing code from Flash while wait states are
changing. This means that should copy also this configuration code to SRAM at this time and execute it with
the MMU ones.
j. After the MAS registers are written, the TLB is validated with a single “tlbwe” (TLB Write Entry) instruction
k. This device family has two 128KB contiguous banks start at 0x4000_0000
Doc ID 022384 Rev 113/49
e200z4d initialization and example codeAN3995
This means that the e200z4d core doesn’t need to have any mapping on this memory space
(see Section 1: Application example description).
3.1.3 Initialize the SRAM ECC
The SRAM in the SPC564Bxx and SPC56ECxx family (as other SPC56xx devices) has the
ECC (Error Correction Code) protection.
ECC checks are performed during the read portion of an SRAM ECC read/write (R/W)
operation, and ECC calculations are performed during the write portion of a R/W operation.
Because the ECC bits can contain random data after the device is powered on, the SRAM
must be initialized by executing 32-bit write operations prior to any read accesses
ECC error and therefore an exception being raised.
Figure 4 shows a scratch code of SRAM initialization.
Figure 4.SRAM ECC initialization code
#/**************************************************************************/
#/* Initialize all SRAM space by copying all 32GPR's to RAM (fast) */
#/* Counter defines number of 32 x 32-bit words needed to write to RAM*/
#/**************************************************************************/
e_lis r5, _SRAM_ADDR_Z4@h #/* SRAM start address defined in the linker file */
e_or2i r5, _SRAM_ADDR_Z4@l
(l)
to avoid
e_lis r6, _SRAM_SIZE_Z4@h #/* SRAM size defined in the linker file */
e_or2i r6, _SRAM_SIZE_Z4@l
e_srwi r6, r6, 0x7 #/* Divide SRAM size by 128 bytes */
mtctr r6 #/* Move to counter for use with "bdnz" */
sram_loop:
e_stmw r0,0x0(r5) #/* Write all 32 registers to SRAM */
e_addi r5,r5,128 #/* Increment the RAM pointer to next */
e_bdnz sram_loop #/* Loop for all of SRAM */
3.1.4 Configure MMU for Flash
It is strongly recommended (see Section 3.1.1: MMU remarks), not to re-configure an MMU
entry for memory that is currently being used because doing so that can cause stability
issues at the point when the MMU TLB region is re-validated.
From the user point of view this means that it should be fine to configure additional TLB
entries while executing from an existing entry.
Of course users could use the same TLB 0 to map all the Flash but the MMU configuration
code must be executed by the SRAM: the code has to be copied to SRAM and then the
execution flow is transferred to SRAM so that the Flash MMU entry can be safely reconfigured (in this Application Note was described this strategy).
#/* 128byte(4bytes*32 registers) */
Figure 5 shows a scratch code of MMU configuration for Flash using TLB entry 0.
l. This is also true for implicit read accesses caused by any write accesses of less than 32 bits
14/49Doc ID 022384 Rev 1
AN3995e200z4d initialization and example code
When the code is executed from Flash, all the code between the labels
“conf_sram_code_begin” and “conf_sram_code_end” is copied
(m)
to and executed from the
SRAM.
Figure 6 shows a scratch code of copy code from Flash to SRAM.
Figure 5.MMU configuration code for Flash
#/**************************************************************************/
#/* MMU configuration code for Flash (TLB1 entry 0) -> copy to RAM */
#/* TLB1 entry 0, 0x0000_0000 to 0x00FF_FFFF overwriting existing TLB */
#/* infact MMU have configured the small 4 KB block at the reset vector. */
#/* NOTE: this configuration allows access to all device Flash */
#/**************************************************************************/
#/* ---- MMU configuration (TLB1, Entry 0) for Code Flash:this block will be
copied to RAM */