Infineon-PSoC 6 MCU CY8C6xx8 CY8C6xxA Architecture Technical Reference Manual TRM PSoC 61 PSoC 62 MCU-AdditionalTechnicalInformation-V10 00-En
Infineon-PSoC 6 MCU CY8C6xx8 CY8C6xxA Architecture Technical Reference Manual TRM PSoC 61 PSoC 62 MCU-AdditionalTechnicalInformation-V10 00-En
The document following this cover page is marked as “Cypress” document as this is the
company that originally developed the product. Please note that Infineon will continue
to offer the product to new and existing customers as part of the Infineon product
portfolio.
www.infineon.com
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture Technical
Reference Manual (TRM) PSoC 61, PSoC 62 MCU
Cypress Semiconductor
An Infineon Technologies Company
198 Champion Court
San Jose, CA 95134-1709
www.cypress.com
www.infineon.com
Copyrights
© Cypress Semiconductor Corporation, 2018-2023. This document is the property of Cypress Semiconductor Corporation, an
Infineon Technologies company, and its affiliates ("Cypress"). This document, including any software or firmware included or
referenced in this document ("Software"), is owned by Cypress under the intellectual property laws and treaties of the United
States and other countries worldwide. Cypress reserves all rights under such laws and treaties and does not, except as
specifically stated in this paragraph, grant any license under its patents, copyrights, trademarks, or other intellectual property
rights. If the Software is not accompanied by a license agreement and you do not otherwise have a written agreement with
Cypress governing the use of the Software, then Cypress hereby grants you a personal, non-exclusive, nontransferable
license (without the right to sublicense) (1) under its copyright rights in the Software (a) for Software provided in source code
form, to modify and reproduce the Software solely for use with Cypress hardware products, only internally within your
organization, and (b) to distribute the Software in binary code form externally to end users (either directly or indirectly through
resellers and distributors), solely for use on Cypress hardware product units, and (2) under those claims of Cypress's patents
that are infringed by the Software (as provided by Cypress, unmodified) to make, use, distribute, and import the Software
solely for use with Cypress hardware products. Any other use, reproduction, modification, translation, or compilation of the
Software is prohibited.
TO THE EXTENT PERMITTED BY APPLICABLE LAW, CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, WITH REGARD TO THIS DOCUMENT OR ANY SOFTWARE OR ACCOMPANYING HARDWARE, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. No computing device can be absolutely secure. Therefore, despite security measures implemented in Cypress
hardware or software products, Cypress shall have no liability arising out of any security breach, such as unauthorized access
to or use of a Cypress product. CYPRESS DOES NOT REPRESENT, WARRANT, OR GUARANTEE THAT CYPRESS
PRODUCTS, OR SYSTEMS CREATED USING CYPRESS PRODUCTS, WILL BE FREE FROM CORRUPTION, ATTACK,
VIRUSES, INTERFERENCE, HACKING, DATA LOSS OR THEFT, OR OTHER SECURITY INTRUSION (collectively,
"Security Breach"). Cypress disclaims any liability relating to any Security Breach, and you shall and hereby do release
Cypress from any claim, damage, or other liability arising from any Security Breach. In addition, the products described in
these materials may contain design defects or errors known as errata which may cause the product to deviate from published
specifications. To the extent permitted by applicable law, Cypress reserves the right to make changes to this document
without further notice. Cypress does not assume any liability arising out of the application or use of any product or circuit
described in this document. Any information provided in this document, including any sample design information or
programming code, is provided only for reference purposes. It is the responsibility of the user of this document to properly
design, program, and test the functionality and safety of any application made of this information and any resulting product.
"High-Risk Device" means any device or system whose failure could cause personal injury, death, or property damage.
Examples of High-Risk Devices are weapons, nuclear installations, surgical implants, and other medical devices. "Critical
Component" means any component of a High-Risk Device whose failure to perform can be reasonably expected to cause,
directly or indirectly, the failure of the High-Risk Device, or to affect its safety or effectiveness. Cypress is not liable, in whole
or in part, and you shall and hereby do release Cypress from any claim, damage, or other liability arising from any use of a
Cypress product as a Critical Component in a High-Risk Device. You shall indemnify and hold Cypress, including its affiliates,
and its directors, officers, employees, agents, distributors, and assigns harmless from and against all claims, costs, damages,
and expenses, arising out of any claim, including claims for product liability, personal injury or death, or property damage
arising from any use of a Cypress product as a Critical Component in a High-Risk Device. Cypress products are not intended
or authorized for use as a Critical Component in any High-Risk Device except to the limited extent that (i) Cypress's published
data sheet for the product explicitly states Cypress has qualified the product for use in a specific High-Risk Device, or (ii)
Cypress has given you advance written authorization to use the product as a Critical Component in the specific High-Risk
Device and you have signed a separate indemnification agreement.
Cypress, the Cypress logo, and combinations thereof, PSoC, CapSense, EZ-USB, F-RAM, Traveo, WICED, and
ModusToolbox are trademarks or registered trademarks of Cypress or a subsidiary of Cypress in the United States or in other
countries. For a more complete list of Cypress trademarks, visit cypress.com. Other names and brands may be claimed as
property of their respective owners.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 2
Content Overview
Section A: Overview 18
1. Introduction ........................................................................................................... 19
2. Getting Started ...................................................................................................... 25
3. Document Organization and Conventions ............................................................... 26
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 3
Content Overview
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 4
Contents
Section A: Overview 18
1. Introduction 19
1.1 Features..................................................................................................................................19
1.2 PSoC 61 and PSoC 62 MCU Series Differences ...................................................................22
1.3 Architecture.............................................................................................................................22
2. Getting Started 25
2.1 PSoC 6 MCU Resources ........................................................................................................25
3. Document Organization and Conventions 26
3.1 Major Sections ........................................................................................................................26
3.2 Documentation Conventions...................................................................................................26
3.2.1 Register Conventions.............................................................................................26
3.2.2 Numeric Naming ....................................................................................................26
3.2.3 Units of Measure....................................................................................................27
3.2.4 Acronyms and Initializations ..................................................................................27
Section B: CPU Subsystem 30
4. CPU Subsystem (CPUSS) 32
4.1 Features..................................................................................................................................32
4.2 Architecture.............................................................................................................................33
4.2.1 Address and Memory Maps ...................................................................................34
4.3 Registers.................................................................................................................................35
4.4 Operating Modes and Privilege Levels ...................................................................................37
4.5 Instruction Set.........................................................................................................................38
5. SRAM Controller 39
5.1 Features..................................................................................................................................39
5.2 Architecture.............................................................................................................................39
5.3 Wait States .............................................................................................................................40
6. Inter-Processor Communication 41
6.1 Features..................................................................................................................................42
6.2 Architecture.............................................................................................................................42
6.2.1 IPC Channel...........................................................................................................42
6.2.2 IPC Interrupt...........................................................................................................43
6.2.3 IPC Channels and Interrupts..................................................................................43
6.3 Implementing Locks................................................................................................................44
6.4 Message Passing ...................................................................................................................44
6.5 Typical Usage Models ............................................................................................................46
6.5.1 Full Duplex Communication ...................................................................................46
6.5.2 Half Duplex with Independent Event Handling.......................................................47
6.5.3 Half Duplex with Shared Event Handling ...............................................................47
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 5
Contents
7. Fault Monitoring 49
7.1 Features..................................................................................................................................49
7.2 Architecture.............................................................................................................................50
7.2.1 Fault Report ...........................................................................................................50
7.2.2 Signaling Interface .................................................................................................52
7.2.3 Monitoring ..............................................................................................................52
7.2.4 Low-power Mode Operation...................................................................................53
7.2.5 Using a Fault Structure ..........................................................................................53
7.2.6 CPU Exceptions Versus Fault Monitoring ..............................................................53
7.3 Fault Sources..........................................................................................................................54
7.4 Register List............................................................................................................................55
8. Interrupts 56
8.1 Features..................................................................................................................................56
8.2 Architecture.............................................................................................................................57
8.3 Interrupts and Exceptions - Operation ....................................................................................58
8.3.1 Interrupt/Exception Handling..................................................................................58
8.3.2 Level and Pulse Interrupts .....................................................................................59
8.3.3 Exception Vector Table ..........................................................................................59
8.4 Exception Sources..................................................................................................................60
8.4.1 Reset Exception.....................................................................................................60
8.4.2 Non-Maskable Interrupt Exception.........................................................................60
8.4.3 HardFault Exception ..............................................................................................61
8.4.4 Memory Management Fault Exception ..................................................................61
8.4.5 Bus Fault Exception ...............................................................................................61
8.4.6 Usage Fault Exception...........................................................................................61
8.4.7 Supervisor Call (SVCall) Exception .......................................................................62
8.4.8 PendSupervisory (PendSV) Exception ..................................................................62
8.4.9 System Tick (SysTick) Exception ...........................................................................62
8.5 Interrupt Sources ....................................................................................................................62
8.6 Interrupt/Exception Priority .....................................................................................................69
8.7 Enabling and Disabling Interrupts...........................................................................................69
8.8 Interrupt/Exception States ......................................................................................................70
8.8.1 Pending Interrupts/Exceptions ...............................................................................70
8.9 Stack Usage for Interrupts/Exceptions ...................................................................................71
8.10 Interrupts and Low-Power Modes...........................................................................................71
8.11 Interrupt/Exception – Initialization/ Configuration ...................................................................71
8.12 Register List............................................................................................................................72
9. Protection Units 73
9.1 Architecture.............................................................................................................................73
9.2 PSoC 6 Protection Architecture ..............................................................................................74
9.3 Register Architecture ..............................................................................................................76
9.3.1 Protection Structure and Attributes ........................................................................76
9.4 Bus Master Protection Attributes ............................................................................................79
9.5 Protection Context ..................................................................................................................79
9.6 Protection Contexts 0, 1, 2, 3 .................................................................................................80
9.7 Protection Structure ................................................................................................................81
9.7.1 Protection Violation ................................................................................................81
9.7.2 MPU .......................................................................................................................81
9.7.3 SMPU.....................................................................................................................81
9.7.4 PPU........................................................................................................................82
9.7.5 Protection of Protection Structures ........................................................................89
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 6
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 7
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 8
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 9
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 10
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 11
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 12
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 13
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 14
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 15
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 16
Contents
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 17
Section A: Overview
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 18
1. Introduction
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC™ MCU is a scalable and reconfigurable platform architecture that supports a family of programmable embedded
system controllers with Arm® Cortex® CPUs (single and multi-core). The CY8C6xx8/CY8C6xxA product family(CY8C61x8,
CY8C62x8, CY8C61xA, and CY8C62xA), based on the PSoC 6 MCU platform, is a combination of a dual-core
microcontroller with built-in programmable peripherals. It incorporates integrated low-power flash technology, high-
performance analog-to-digital conversion, low-power comparators, touch sensing, serial memory interface with encryption,
secure digital host controller (SDHC), and standard communication and timing peripherals.
1.1 Features
32-bit Dual CPU Subsystem
■ 150-MHz Arm® Cortex®-M4F (CM4) CPU with single-cycle multiply, floating point, and memory protection unit (MPU)
■ 100-MHz Cortex-M0+ (CM0+) CPU with single-cycle multiply and MPU
■ User-selectable core logic operation at either 1.1 V or 0.9 V
■ Active CPU current slope with 1.1-V core operation
■ Active CPU current slope with 0.9-V core operation
■ Three DMA controllers
Memory Subsystem
■ 2048-KB application flash, 32-KB auxiliary flash (AUXFlash), and 32-KB supervisory flash (SFlash); read-while-write
(RWW) support. Two 8-KB flash caches, one for each CPU
■ 1024-KB SRAM with three independent blocks for power and data retention control
■ One-time-programmable (OTP) 1-Kb eFuse array
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 19
Introduction
Serial Communication
■ Thirteen run-time configurable serial communication blocks (SCBs)
❐ Eight SCBs: configurable as SPI, I2C, or UARTs
❐ Four SCBs: configurable as I2C or UART
❐ One Deep Sleep SCB: configurable as SPI or I2C
■ USB full-speed device interface
■ Two independent SD Host Controller/eMMC/SD controllers
Audio Subsystem
■ Two PDM channels and one I2S channel with TDM mode
Programmable Analog
■ 12-bit 2-Msps SAR ADC with differential and single-ended modes and 16-channel sequencer with result averaging
■ Two low-power comparators available in Deep Sleep and Hibernate modes
■ Two opamps
■ Always-on low frequency Deep Sleep operation
■ Built-in temp sensor connected to ADC
LCD
■ LCD segment direct block support up to 61 segments and up to 8 commons
■ Operates in Active, Sleep, and Deep Sleep modes
Capacitive Sensing
■ CapSense Sigma-Delta (CSD) provides best-in-class SNR, liquid tolerance, and proximity sensing
■ Enables dynamic usage of both self and mutual sensing
■ Automatic hardware tuning (SmartSense™)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 20
Introduction
Cryptography Accelerators
■ Hardware acceleration for symmetric and asymmetric cryptographic methods and hash functions
■ True Random Number Generator (TRNG) function
Profiler
■ Eight counters provide event or duration monitoring of on-chip resources
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 21
Introduction
1.3 Architecture
Figure 1-1 shows the major components of the PSoC 6 MCU architecture.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 22
Introduction
SARMUX
Peripheral clock (PCLK)
Domains Power Clocks
Temperature
System LP/ULP Mode OVP LVD IMO ECO Sensor
CPUs Active/Sleep POR BOD FLL 2x PLL
CPU Subsystem
SCB
Boundary Scan
Cortex M0+ CPU
100/25 MHz, 1.1/0.9 V
SWJ, MTB, CTI
Audio Subsystem
3x DMA
System Interconnect (Multi Layer AHB, IPC, MPU/SMPU)
Controller
Crypto
DES/TDES, AES, SHA,
CRC, TRNG, RSA/ECC
Accelerator
Flash
2048 KB + 32 KB + 32 KB
8 KB cache for each CPU
SRAM0
512 KB USB
PHY
SRAM1
256 KB
SRAM2
256 KB
ROM
64 KB
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 23
Introduction
The block diagram shows the device subsystems and gives a simplified view of their interconnections. The color-code shows
the lowest power mode where the particular block is still functional (for example, LP comparator is functional in Deep Sleep
and Hibernate modes).
Note: In the PSoC 61 series (CY8C61x8, CY8C61xA), only the Arm Cortex-M4F CPU is available for applications. The
Cortex M0+ is reserved for system functions, and is not available for applications. When not executing the system functions,
the CM0+ will be in CPU Deep Sleep mode.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 24
2. Getting Started
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 25
3. Document Organization and Conventions
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 26
Document Organization and Conventions
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 27
Document Organization and Conventions
Table 3-2. Acronyms and Initializations (continued) Table 3-2. Acronyms and Initializations (continued)
Acronym Definition Acronym Definition
DI digital or data input IRQ interrupt request
DL drive level ISA instruction set architecture
DMA direct memory access ISR interrupt service routine
DMIPS Dhrystone million instructions per second ITM instrumentation trace macrocell
DNL differential nonlinearity IVR interrupt vector read
DO digital or data output IZTAT zero dependency to absolute temperature
DSP digital signal processing JWT JSON web token
DSM Deep Sleep mode L2CAP logical link control and adaptation protocol
DU data unit LCD liquid crystal display
DW data wire LFCLK low-frequency clock
ECO external crystal oscillator LFSR linear feedback shift register
electrically erasable programmable read only LIN local interconnect network
EEPROM
memory
LJ left justified
EMIF external memory interface
LL link layer
ETM embedded trace macrocell LNA low-noise amplifier
FB feedback
LP system low-power mode
FIFO first in first out
LPCOMP Low-Power comparator
FPU floating point unit LPM link power management
FSR full scale range
LR link register
GAP generic access profile
LRb last received bit
GATT generic attribute profile LRB last received byte
GFSK Gaussian frequency-shift keying
LSb least significant bit
GPIO general-purpose I/O
LSB least significant byte
HCI host-controller interface LUT lookup table
HFCLK high-frequency clock
MAC message authentication code
HMAC hashed message authentication code
MISO master-in-slave-out
HPF high-pass filter MMIO memory mapped input/output
HSIOM high-speed I/O matrix
MOSI master-out-slave-in
I2 C inter-integrated circuit MPU memory protection unit
I2 S inter-IC sound MSb most significant bit
IDE integrated development environment MSB most significant byte
ILO internal low-speed oscillator MSP main stack pointer
ITO indium tin oxide MTB micro trace buffer
IMO internal main oscillator NI next instant
INL integral nonlinearity NMI non-maskable interrupt
I/O input/output NVIC nested vectored interrupt controller
IOR I/O read OE output enable
IOW I/O write OSR over-sampling ratio
IPC inter-processor communication OVP over-voltage protection
IPTAT proportional to absolute temperature PA power amplifier
IRES initial power on reset PC program counter
IRA interrupt request acknowledge PCB printed circuit board
IRK identity resolution key PCH program counter high
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 28
Document Organization and Conventions
Table 3-2. Acronyms and Initializations (continued) Table 3-2. Acronyms and Initializations (continued)
Acronym Definition Acronym Definition
PCL program counter low SP stack pointer
PD power down SPD sequential phase detector
PDU protocol data unit SPI serial peripheral interconnect
PGA programmable gain amplifier SPIM serial peripheral interconnect master
PHY physical layer SPIS serial peripheral interconnect slave
PLD programmable logic device SRAM static random-access memory
PM power management SROM supervisory read only memory
PMA PSoC memory arbiter SRSS system resources subsystem
POR power-on reset SSADC single slope ADC
PPOR precision power-on reset SSC supervisory system call
PPU peripheral protection units SVCall supervisor call
PRNG pseudo random number generator SYSCLK system clock
PRS pseudo random sequence SWD single wire debug
PSA Platform Security Architecture SWV serial wire viewer
PSSDC power system sleep duty cycle TDM time division multiplexed
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 29
Section B: CPU Subsystem
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 30
CPU Subsystem
CPU Subsystem
3x DMA
Crypto
DES/TDES, AES, SHA,
CRC, TRNG, RSA/ECC
Accelerator
Flash
2048 KB + 32 KB + 32 KB
Color Key: 8 KB cache for each CPU
Power Modes and
Domains
System SRAM1
DeepSleep Mode 256 KB
System SRAM2
Hibernate Mode 256 KB
Backup
Domain ROM
64 KB
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 31
4. CPU Subsystem (CPUSS)
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The CPU subsystem is based on dual 32-bit Arm Cortex CPUs, as Figure 4-1 shows. The Cortex-M4 is the main CPU. It is
designed for short interrupt response time, high code density, and high 32-bit throughput while maintaining a strict cost and
power consumption budget. A secondary Cortex-M0+ CPU implements security, safety, and protection features.
This section provides only an overview of the Arm Cortex CPUs in PSoC 6 MCUs. For details, see the Arm documentation
sets for Cortex-M4 and Cortex-M0+.
Some PSoC 6 MCU parts have only one CPU. See the PSoC 61 datasheet/PSoC 62 datasheet for details.
4.1 Features
The PSoC 6 MCU Arm Cortex CPUs have the following features:
■ Cortex-M4 has a floating-point unit (FPU) that supports single-cycle digital signal processing (DSP) instructions, and a
memory protection unit (MPU). Cortex-M0+ has an MPU.
■ Both CPUs have 8-KB instruction caches with four-way set associativity.1
■ Maximum clock frequency of 150 MHz for the Cortex-M4 and 100 MHz for the Cortex-M0+.
■ The Cortex-M4 implements a version of the Thumb instruction set based on Thumb-2 technology (defined in the Armv7-M
Architecture Reference Manual). The Cortex-M0+ supports the Armv6-M Thumb instruction set (defined in the Armv6-M
Architecture Reference Manual). See “Instruction Set” on page 38.
■ Both CPUs have nested vectored interrupt controllers (NVIC) for rapid and deterministic interrupt response. For details,
see the Interrupts chapter on page 56
■ Both CPUs have extensive debug support. For details, see the Program and Debug Interface chapter on page 154.
❐ SWJ: combined serial wire debug (SWD) and Joint Test Action Group (JTAG) ports
❐ Serial wire viewer (SWV): provides real-time trace information through the serial wire output (SWO) interface
❐ Breakpoints
❐ Watchpoints
❐ Trace: Cortex-M4: embedded trace macrocell (ETM). Cortex-M0+: 4-KB micro trace buffer (MTB)
■ Inter-processor communication (IPC) hardware – see the Inter-Processor Communication chapter on page 41.
1. PSoC 6 does not support cache coherency. As a result when a particular row of flash that executes instructions is written/updated, the updated information will
not be reflected in the cache. The cache should be cleared in the firmware during such instances. This is applicable for both CM4 and CM0+ cache – the ap-
propriate (CM0+ and/or CM4) cache should be invalidated.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 32
CPU Subsystem (CPUSS)
4.2 Architecture
Figure 4-1. CPU Subsystem Block Diagram
CPU Subsystem
3x DMA
Crypto
DES/TDES, AES, SHA,
CRC, TRNG, RSA/ECC
Accelerator
Flash
2048 KB + 32 KB + 32 KB
Color Key: 8 KB cache for each CPU
Power Modes and
Domains
System SRAM1
DeepSleep Mode 256 KB
System SRAM2
Hibernate Mode 256 KB
Backup
Domain ROM
64 KB
Each CPU is a 32-bit processor with its own 32-bit datapath and a 32-bit memory interface. Each CPU has its own set of 32-
bit registers. They support a wide variety of instructions in the Thumb instruction set. They support two operating modes (see
“Operating Modes and Privilege Levels” on page 37).
The Cortex-M4 instruction set includes:
■ Signed and unsigned, 32×32 32-bit and 32×32 64-bit, multiply and multiply-accumulate, all single-cycle
■ Signed and unsigned 32-bit divides that take two to 12 cycles
■ DSP instructions, including single instruction multiple data (SIMD) instructions
■ Complex memory-load and store access
■ Complex bit manipulation; see the bitfield instructions in Table 4-6
The Cortex-M4 FPU has its own set of registers and instructions. It is compliant with the ANSI/IEEE Std 754-2008, IEEE
Standard for Binary Floating-Point Arithmetic.
The Cortex-M0+ has a single cycle 32x32 32-bit signed multiplication instruction.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 33
CPU Subsystem (CPUSS)
The device memory map shown in Table 4-2 applies to both CPUs. That is, the CPUs share access to all PSoC 6 MCU
memory and peripheral registers.
SRAM is located in the code region for both CPUs (see Table 4-1). This facilitates executing code out of SRAM. There is no
physical memory located in the CPUs’ SRAM region.
Note: The CPUSS_CM0_VECTOR_TABLE_BASE and CPUSS_CM4_VECTOR_TABLE_BASE registers determine the
location of the vector table for each CPU. A number of LS bits in each register are set to 0. As a result, there are restrictions
on the location of vector tables – they must be on a 256-byte boundary for CM0+ and a 1024-byte boundary for CM4.
Ultra-Low Power
Clk_HF0 (MHz)
Mode
Clk_HF0 16 16 < Clk_HF0 33 33 < Clk_HF0
True
0 1 2
Flash
Clk_HF0 29 29 < Clk_HF0 58 58 < Clk_HF0 87 87 < Clk_HF0 120 120 < Clk_HF0 150
False
0 1 2 3 4
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 34
CPU Subsystem (CPUSS)
4.3 Registers
Both CPUs have sixteen 32-bit registers, as Table 4-3 shows. See the Arm documentation for details.
■ R0 to R12 – General-purpose registers. R0 to R7 can be accessed by all instructions; the other registers can be accessed
by a subset of the instructions.
■ R13 – Stack pointer (SP). There are two stack pointers, with only one available at a time. In thread mode, the CONTROL
register indicates the stack pointer to use – Main Stack Pointer (MSP) or Process Stack Pointer (PSP).
■ R14 – Link register. Stores the return program counter during function calls.
■ R15 – Program counter. This register can be written to control program flow.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 35
CPU Subsystem (CPUSS)
The Cortex-M4 floating-point unit (FPU) also has the following registers:
■ Thirty-two 32-bit single-precision registers, S0 to S31. These registers can also be addressed as sixteen 64-bit double-
precision registers, D0 to D15.
■ Five FPU control and status registers:
❐ CPACR – Coprocessor Access Control Register
❐ FPCCR – Floating-point Context Control Register
❐ FPCAR – Floating-point Context Address Register
❐ FPSCR – Floating-point Status Control Register
❐ FPDSCR – Floating-point Default Status Control Register
For more information on how these registers are used, see the Arm Cortex-M4 documentation.
Use the MSR and MRS instructions to access the PSR, PRIMASK, CONTROL, FAULTMASK, and BASEPRI registers.
Table 4-4 and Table 4-5 show how the PSR bits are assigned.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 36
CPU Subsystem (CPUSS)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 37
CPU Subsystem (CPUSS)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 38
5. SRAM Controller
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
This chapter explains the PSoC 6 MCU SRAM Controller, its features, architecture, and wait states. The SRAM controller
enables the CPU to read and write parts of the PSoC 6 SRAM.
5.1 Features
The CPUSS has up to three identical SRAM controllers; see the PSoC 61 datasheet/PSoC 62 datasheet for details.
The SRAM controller has the following features:
■ Consists of two AHB-Lite interfaces:
❐ An AHB-Lite bus interface on clk_fast that connects to the fast bus infrastructure
❐ An AHB-Lite bus interface on clk_slow that connects to the slow bus infrastructure
■ Supports programmable number of clk_hf wait states
■ Supports 8-, 16-, and 32-bit accesses
5.2 Architecture
The design has two AHB-Lite interfaces that connect to the AHB-Lite infrastructure. Each AHB-Lite interface is connected to
a synchronization component that translates between the interface clock (either clk_fast or clk_slow) and the high-frequency
clock (clk_hf).
Arbitration is performed on the AHB-Lite transfers from the two ports (AHB-Lite interface). Arbitration uses device-wide bus
master specific arbitration priorities. Therefore, although two AHB-Lite interfaces are provided, only one AHB-Lite transfer is
accepted by the port arbitration component.
The AHB-Lite transfers are the origin for all SRAM accesses; that is, the write buffer and SRAM repair requests result from
AHB-Lite transfers. The SRAM controller differentiates between the following three types of AHB-Lite transfers:
■ AHB-Lite read transfers
■ 32-bit AHB-Lite write transfers
■ 8-bit and 16-bit AHB-Lite write transfers (also referred to as partial AHB-Lite write transfers)
Each type is described in more detail here.
AHB-Lite read transfers. An AHB-Lite read transfer is translated into an SRAM read access. If the read address matches
in the write buffer, the SRAM has stale data and the write data provides the requested read data (this functionality is provided
by the read merge component).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 39
SRAM Controller
32-bit AHB-Lite write transfers. A 32-bit AHB-Lite write access. If the entry valid field is ‘0’, no SRAM access is
transfer is translated into an SRAM write access. If the write performed.
address matches in the write buffer, the matching write
On an SRAM read access, a matching entry provides write
buffer entries have stale data and these entries are
buffer merge data for the read merge component.
invalidated.
On an SRAM write access resulting from a 32-bit AHB-Lite
Partial AHB-Lite write transfers. A partial AHB-Lite write write transfer, a matching entry invalidated field is set to ‘1’.
transfer is translated into an SRAM read access and an
SRAM write access. The SRAM read access is the direct The state of the write buffer is reflected by
result of the partial write transfer and the SRAM write RAMi_STATUS.WB_EMPTY. The write buffer is not retained
access is the result of a write buffer request. A partial write in Deep Sleep power mode. Therefore, when transitioning to
transfer requires an SRAM read access to retrieve the system Deep Sleep power mode, the write buffer should be
“missing” data bytes from the SRAM. If the read address empty. Note that this requirement is typically met, because a
matches in the write buffer, the SRAM has stale data and transition to Deep Sleep power mode also requires that
the write data provides the requested read data (this there are no outstanding AHB-Lite transfers. If there are no
functionality is provided by the read merge component). The outstanding AHB-Lite transfers, the write buffer gets SRAM
requested read data is merged with the partial write data to access.
provide a complete 32-bit data word (this functionality is
provided by the write merge component). The address and
the merged write data are written to the write buffer. A future
5.3 Wait States
write buffer request results in an SRAM write access with The programmable wait states represent the number of
the merged write data. clk_hf cycles for a read path through the SRAM memory to
Only the partial AHB-Lite write transfers use the write buffer. flipflops in either the fast domain (CM4 CPU) or slow domain
(such as CM0+ CPU, DataWire, and DMA controller).
Write buffer. The write buffer is a temporary holding As the wait states are represented in clk_hf cycles, the wait
station for future SRAM write accesses. states do not have to be reprogrammed when the fast clock
The buffer allows SRAM write accesses to be postponed. domain frequency (clk_fast) or slow clock domain frequency
This allows for more performance critical AHB-Lite requests (clk_slow) is changed. However, it may be necessary to
to “overtake” write buffer requests. Memory consistency is reprogram the wait states when the high-frequency clock
guaranteed by matching the SRAM access address with the domain (clk_hf) is changed. This means the required
write buffer entries' addresses: a “matching” SRAM read number of wait states is a function of the clk_hf frequency.
access uses the read merge component and a matching The fast clock domain is timing closed at a higher frequency
SRAM write access invalidates the matching write buffer than the slow clock domain. Therefore, the read path
entries. through the SRAM memory to flipflops in the fast domain is
When the write buffer is full, an entry needs to be freed to faster than the read path through the SRAM memory to
accommodate future partial AHB-Lite write transfers. flipflops in the slow domain. In other words, the required
Therefore, a full write buffer raises the priority of the write number of “fast” wait states (RAMi_CTL.FAST_WS) should
buffer request path. be less than or equal to the required number of “slow” wait
states (RAMi_CTL.SLOW_WS).
The write buffer is constructed as a FIFO with four entries
(the order in which entries are written is the same as the The SRAM controller also has internal SRAM read paths.
order in which entries are read). Each entry consists of: These paths are to flipflops in the SRAM controller in the
high-frequency clock domain (clk_hf). For these SRAM
■ A valid field accesses (for example, an SRAM read access to support a
■ An invalidated field partial AHB-Lite write transfer), the fast wait states are used.
■ A word address This is because the maximum fast domain frequency
(clk_fast) equals the high-frequency domain frequency
■ A 32-bit data word
(clk_hf).
Note that the merged write data written to the write buffer
is always a 32-bit data word. Therefore, no byte mask is
required.
When the write buffer is written (an entry is added): the entry
valid field is set to ‘1’ and the invalidated field is set to ‘0’.
When the write buffer is read (an entry is removed): the
entry valid field is set to ‘0’. If the entry invalidate field is ‘1’,
the write buffer request path is selected for an SRAM write
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 40
6. Inter-Processor Communication
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
Inter-processor communication (IPC) provides the functionality for multiple processors to communicate and synchronize their
activities. IPC hardware is implemented using two register structures.
■ IPC Channel: Communication and synchronization between processors is achieved using this structure.
■ IPC Interrupt: Each interrupt structure configures an interrupt line, which can be triggered by a ‘notify’ or ‘release’ event of
any IPC channel.
The Channel and Interrupt structures are independent and have no correlation to each other as shown in Figure 6-1. This
allows for building varying models of interface shown in Typical Usage Models on page 46.
Figure 6-1. IPC Register Architecture
System bus
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 41
Inter-Processor Communication
6.1 Features
The features of IPC are as follows:
■ Implements locks for mutual exclusion between processors
■ Allows sending messages between processors
■ Supports up to 16 channels for communication
■ Supports up to 16 interrupts, which can be triggered using notify or release events from the channels
6.2 Architecture
6.2.1 IPC Channel
An IPC channel is implemented as six hardware registers, as shown in Figure 6-2. The IPC channel registers are accessible
to all the processors in the system.
■ IPC_STRUCTx_ACQUIRE: This register determines the lock feature of the IPC. The IPC channel is acquired by reading
this register. If the SUCCESS field returns a ‘1’, the read acquired the lock.
If the SUCCESS field returns a ‘0’, the read did not acquire the lock.
Note that a single read access performs two functions:
❐ The attempt to acquire a lock.
❐ Return the result of the acquisition attempt (SUCCESS field).
The atomicity of these two functions is essential in a CPU with multiple tasks that can preempt each other.
The register also has bitfields that provide information about the processor that acquired it. When acquired, this register is
released by writing any value into the IPC_STRUCTx_RELEASE register. If the register was already in an acquired state
another attempt to read the register will not be able to acquire it.
■ IPC_STRUCTx_NOTIFY: This register is used to generate an IPC notify event. Each bit in this register corresponds to an
IPC interrupt structure. The notify event generated from an IPC channel can trigger any or multiple interrupt structures.
■ IPC_STRUCTx_RELEASE: Any write to this register will release the IPC channel. This register also has a bit that
corresponds to each IPC interrupt structure. The release event generated from an IPC channel can trigger any or multiple
interrupt structures. To only release the IPC channel and not generate an interrupt, you can write a zero into the IPC
release register.
■ IPC_STRUCTx_DATA0 and IPC_STRUCTx_DATA1: These are two 32-bit registers with a combined size of 64 bits that
are meant to hold data. These registers can be considered as the shared data memory for the channel. Typically, these
registers will hold messages that need to be communicated between processors. If the messages are larger than the
combined 64-bit size, place pointers in one or both of these registers.
■ IPC_STRUCTx_LOCK_STATUS: This register provides the instantaneous lock status for the IPC channel. The register
provides details if the channel is acquired. If acquired, it provides the processor’s ID, protection context, and other details.
The reading of lock status provides only an instantaneous status, which can be changed in the next cycle based on the
activity of other processors on the channel.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 42
Inter-Processor Communication
31
0
0
INTR_NOT15
INTR_NOT14
INTR_NOT13
INTR_NOT12
INTR_NOT11
INTR_NOT10
INTR_NOT9
INTR_NOT8
INTR_NOT7
INTR_NOT6
INTR_NOT5
INTR_NOT4
INTR_NOT3
INTR_NOT2
INTR_NOT1
INTR_NOT0
SUCCESS
MS[3:0]
PC[3:0]
NS
P
IPC_STRUCTx_RELEASE IPC_STRUCTx_DATA0
31
31
0
0
INTR_REL15
INTR_REL14
INTR_REL13
INTR_REL12
INTR_REL11
INTR_REL10
INTR_REL9
INTR_REL8
INTR_REL6
INTR_REL4
INTR_REL3
INTR_REL7
INTR_REL5
INTR_REL2
INTR_REL1
INTR_REL0
DATA[31:0]
IPC_STRUCTx_LOCK_STATUS IPC_STRUCTx_DATA1
31
31
0
ACQUIRED
ACQUIRED
DATA[31:0]
MS[3:0]
PC[3:0]
NS
P
6.2.2 IPC Interrupt
Each IPC interrupt line in the system has a corresponding IPC interrupt structure. An IPC interrupt can be triggered by a notify
or a release event from any of the IPC channels in the system. You can choose to mask any of the sources of these events
using the IPC interrupt registers. Figure 6-3 shows the registers in an IPC Interrupt structure.
IPC_INTR_STRUCTx_INTR: This register provides the instantaneous status of the interrupt sources. Note that there are 16
notify and 16 release event bits in this register. These are the notify and release events corresponding to the 16 IPC
channels. When a notify event is triggered in the IPC channel 0, the corresponding Notify0 bit is activated in the interrupt
registers. A write of ‘1’ to a bit will clear the interrupt.
IPC_INTR_STRUCTx_INTR_MASK: The bit in this register masks the interrupt sources. Only the interrupt sources with their
masks enabled can trigger the interrupt.
IPC_INTR_STRUCTx_INTR_SET: A write of ‘1’ into this register will set the interrupt.
IPC_INTR_STRUCTx_INTR_MASKED: This register provides the instantaneous value of the interrupts after they are
masked. The value in this register is (IPC_INTR_STRUCTx_INTR AND IPC_INTR_STRUCTx_INTR_MASK).
Figure 6-3. IPC Interrupt Structure
IPC_INTR_STRUCTx_INTR IPC_INTR_STRUCTx_INTR_MASK
31
31
0
0
RELEASE15
RELEASE14
RELEASE13
RELEASE12
RELEASE15
RELEASE14
RELEASE13
RELEASE12
RELEASE11
RELEASE11
RELEASE10
RELEASE10
RELEASE9
RELEASE9
NOTIFY15
NOTIFY14
NOTIFY13
NOTIFY12
NOTIFY11
NOTIFY10
RELEASE8
RELEASE6
RELEASE4
RELEASE3
RELEASE8
RELEASE6
RELEASE4
RELEASE3
RELEASE7
RELEASE5
NOTIFY15
NOTIFY14
NOTIFY13
NOTIFY12
NOTIFY11
NOTIFY10
RELEASE7
RELEASE5
RELEASE2
RELEASE1
RELEASE0
RELEASE2
RELEASE1
RELEASE0
NOTIFY9
NOTIFY8
NOTIFY7
NOTIFY6
NOTIFY5
NOTIFY4
NOTIFY3
NOTIFY2
NOTIFY1
NOTIFY0
NOTIFY9
NOTIFY8
NOTIFY7
NOTIFY6
NOTIFY5
NOTIFY4
NOTIFY3
NOTIFY2
NOTIFY1
NOTIFY0
IPC_INTR_STRUCTx_INTR_SET IPC_INTR_STRUCTx_INTR_MASKED
31
31
0
0
RELEASE15
RELEASE14
RELEASE13
RELEASE12
RELEASE15
RELEASE14
RELEASE13
RELEASE12
RELEASE11
RELEASE10
RELEASE11
RELEASE10
RELEASE9
NOTIFY15
NOTIFY14
NOTIFY13
NOTIFY12
NOTIFY11
NOTIFY10
RELEASE8
RELEASE6
RELEASE4
RELEASE3
RELEASE9
RELEASE7
RELEASE5
NOTIFY15
NOTIFY14
NOTIFY13
NOTIFY12
NOTIFY11
NOTIFY10
RELEASE8
RELEASE6
RELEASE4
RELEASE3
RELEASE7
RELEASE5
RELEASE2
RELEASE1
RELEASE0
RELEASE2
RELEASE1
RELEASE0
NOTIFY9
NOTIFY8
NOTIFY7
NOTIFY6
NOTIFY5
NOTIFY4
NOTIFY3
NOTIFY2
NOTIFY1
NOTIFY0
NOTIFY9
NOTIFY8
NOTIFY7
NOTIFY6
NOTIFY5
NOTIFY4
NOTIFY3
NOTIFY2
NOTIFY1
NOTIFY0
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 43
Inter-Processor Communication
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 44
Inter-Processor Communication
configured to interrupt Processor A. IPC interrupt B is notify event was enabled by setting the mask bit
configured to interrupt Processor B. (IPC_INTR_STRUCTx_INTR_MASK [31:23]) in the IPC
1. The sender will attempt to acquire the IPC channel by interrupt B, this will generate an interrupt in the receiver.
reading the IPC_STRUCTx_ACQUIRE register. If the 4. When it receives IPC interrupt B, the receiver can poll
channel was acquired, the sender has ownership of the the IPC_INTR_STRUCTx_INTR_MASKED register to
channel for data transmission. This also changes the understand which IPC channel had triggered the notify
status of the channel and its corresponding event. Based on this, the receiver identifies the channel
IPC_STRUCTx_LOCK_STATUS register. If the channel to read and reads from the IPC channel’s
was not acquired, the processor should wait until the IPC_STRUCTx_DATA0 and IPC_STRUCTx_DATA1
channel is free for acquisition. This can be done by registers. The receiver has now received the data sent
polling the IPC channel’s by the sender. It needs to release the channel so that
IPC_STRUCTx_LOCK_STATUS register. other processors/processes can use it.
2. After the IPC channel is acquired, the sender has control 5. The receiver releases the channel. It also optionally
of the channel for communication and places the 64-bit generates a release event on the sender’s IPC interrupt
message data in the IPC_STRUCTx_DATA0 and A. This will generate a release event interrupt on the
IPC_STRUCTx_DATA1 registers. sender if the corresponding channel release event was
3. Now that the message is placed in the IPC channel, the masked.
sender generates a notify event on the receiver’s On receiving the release interrupt, the sender can act on the
interrupt line. It does this by setting the corresponding bit event based on the application requirement. It can either try
in the IPC channel’s IPC_STRUCTx_NOTIFY register. to reacquire the channel for further transmission or go on to
This event creates a notify event at IPC interrupt B other tasks because the transmission is complete.
(IPC_INTR_STRUCTx_INTR). If the IPC channel’s
Figure 6-5. Sending Messages using IPC
IPC Channel Receiver
Sender (Processor B)
(4)
(Processor A) (1) Acquire
(3) Notify (3) (3)
(5)
(5) Release
(2) Data
IPC
IPC interrupt B
interrupt A
(1) Status (5)
Hardware action
User action
In the previous example, the size of the data being transmitted was just 64 bits. Larger messages can be sent as pointers.
The sender can allocate a larger message structure in memory and pass the pointers in the data registers. Figure 6-6 shows
the usage. Note that the user code must implement the synchronization of the message read process.
■ The implementation can stall the channel until the receiver has used up all the data in the message packet and the
message packet can be rewritten. This is wasteful because it will stall other inter-process communications as the number
of IPC channels is limited.
■ The receiver can release the channel as soon as it receives the pointer to the message packet. It implements the
synchronization logic in the message packet as a flag, which the sender sets on write complete and receiver clears on a
read complete.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 45
Inter-Processor Communication
Message
Packet
Write Read
IPC Channel X
Core 0 Core 1
IPC Channel Y
System IPC
Interrupt Interrupt Y
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 46
Inter-Processor Communication
IPC
System Interrupt
Interrupt X
System IPC
Interrupt Interrupt Y
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 47
Inter-Processor Communication
System Interrupt
IPC
Interrupt
X
System Interrupt
Note: Some IPC channel and interrupt structures are reserved as part of the SROM code. Refer to the SROM architecture
and API in Flash Memory Programming on page 167 for a list IPC channels and interrupts being used by this API.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 48
7. Fault Monitoring
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
Fault monitoring allows you to monitor various faults generated within the device and take actions based on the fault reported.
The fault structures present in the PSoC 6 MCU monitor access violation faults at protection units (MPU, SMPU, or PPU) and
flash controller bus error/fault. In addition to reporting faults, the fault structures in PSoC 6 MCUs provide a mechanism to log
data from the fault sources and optionally perform soft reset.
The PSoC 6 MCU family supports two centralized fault report/monitoring structures that monitor faults generated within the
device. Each fault report structure can monitor and report faults from up to 96 sources.
7.1 Features
Each PSoC 6 MCU fault report structure supports:
■ Monitoring protection unit access violation faults and flash controller bus errors
■ Four 32-bit data registers to record fault information
■ Soft reset on fault detection while retaining the fault information
■ Interrupt on fault detection
■ Trigger output to DMA for fault data transfer
■ Fault detected output to a pin for external fault handling
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 49
Fault Monitoring
7.2 Architecture
Figure 7-1. Fault Report Structure
Fault report Structure [x]
FAULT_CTL interrupt_fault[x]
FAULT_STATUS tr_fault[x]
FAULT_DATA0 fault_out[x]
Fault source 0 Fault Data
...
FAULT_DATA3 fault_reset_req[x]
Fault report
ﺫup to 96 ... Pending faults Fault report
Structure[0]
FAULT_PENDING0
Structure[1]
Retained during
Fault source 95 Fault Data FAULT_PENDING1 soft reset
FAULT_PENDING2
FAULT_MASK0
Single structure,
used by all fault FAULT_MASK1
report structures. FAULT_MASK2
INTR_FAULT
INTR_FAULT_SET
INTR_FAULT_MASK
INTR_FAULT_MASKED
The PSoC 6 MCU family uses centralized fault report structures. This centralized nature allows for a system wide handling of
faults simplifying firmware development. Only a single fault interrupt handler is required to monitor multiple faults. The fault
report structure provides the fault source and additional fault specific information through a single set of registers; no iterative
search for the fault source and fault information is required.
The fault structure can be configured to capture one or more faults as listed in Table 7-2. When a fault structure is configured
to capture a specific fault, an occurrence of that fault will be recorded as a pending fault. If the fault structure has finished
processing all other faults or if there are no other pending faults, the fault data will be captured into the fault structure
registers. In addition, a successful capture can trigger an interrupt and be processed by either Cortex-M4 or Cortex-M0+
depending on the application requirement.
It should be noted that each fault structure is capable of capturing only one fault at a time and as long as that fault is not
serviced, subsequent faults will not be captured by the fault structure. In addition to capturing faults, the fault structure can
optionally perform a soft reset while retaining the fault information. This reset results in RESET_ACT_FAULT reset cause in
the SRSS_RES_CAUSE register.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 50
Fault Monitoring
information on the violating bus address, the bus master identifier, and bus access control information in only two
FAULT_DATA registers. The details of the fault information for various faults is explained in Table 7-1.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 51
Fault Monitoring
fault_reset_req[0]
fault_reset_req
fault_reset_req[1] (to device soft reset line)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 52
Fault Monitoring
fault. Fault structure 0 has precedence over fault c. Enable the FAULTx interrupt to the CPU by configur-
structure 1. ing the appropriate ISER register. Refer to the
Interrupts chapter on page 56.
The fault structure captures “enabled” faults only when
VALID bit [31] of FAULT_STRUCTx_STATUS register is ‘0’. 3. For fault handling through DMA
When a fault is captured, hardware sets the VALID bit [31] of a. Set the TR_EN bit [0] of the FAULT_STRUCTx_CTL
the FAULT_STRUCTx_STATUS register. In addition, register.
hardware clears the associated pending bit to ‘0’. When a b. Route the tr_fault[x] signal to the trigger input DMA
fault structure is processed, firmware or a DMA transfer controller. Refer to the Trigger Multiplexer
should clear the VALID bit [31] of the Block chapter on page 294.
FAULT_STRUCTx_STATUS register. Note that fault
c. Configure and enable the DMA controller to transfer
capturing does not consider FAULT bit [0] of
FAULT_STRUCTx_STATUS and FAULT_STRUCTx-
FAULT_STRUCTx_INTR register and firmware should clear
_DATA registers to memory and write back ‘0’ to
the bit after servicing the interrupt, if the interrupt is enabled.
FAULT_STRUCTx_STATUS register after the trans-
fer is complete. Refer to the DMA Controller
7.2.4 Low-power Mode Operation (DW) chapter on page 91.
The fault report structure functionality is available in Active 4. For fault handling outside the device
and Sleep (and their LP counterparts) power modes only. a. Set the OUT_EN bit [1] of FAULT_STRUCTx_CTL
The interfaces between the fault sources and fault report register.
structures are reset in the Deep Sleep power mode.
b. Route the fault_out[x] signal to a pin through HSIOM.
Because the fault report structure is an active functionality,
Refer to the PSoC 61 datasheet/PSoC 62 datasheet.
pending faults (in the FAULT_STRUCTx_PENDING
registers) are not retained when transitioning to Deep Sleep c. Use the signal externally for processing the fault –
power mode. The fault structure’s registers can be generate external reset, power cycle, or log fault
partitioned based on the reset domain and their retention information.
capability as follows: 5. Set the RESET_REQ_EN bit [2] of the FAULT_-
■ Active reset domain: FAULT_STRUCTx_PENDING, STRUCTx_CTL register, if a soft reset is required on any
FAULT_STRUCTx_INTR, fault detection in the structure.
FAULT_STRUCTx_INTR_SET, and 6. Clear VALID bit [31] of the FAULT_STRUCTx_STATUS
FAULT_STRUCTx_INTR_MASKED registers. These register to clear any fault captured.
registers are not retained in Deep Sleep power mode. 7. Set the fault index bits in the FAULT_STRUCTx_MASK
■ Deep Sleep reset domain: FAULT_STRUCTx_CTL, registers for faults that need to be captured by the fault
FAULT_STRUCTx_MASK, and structure as explained in 7.2.3 Monitoring.
FAULT_STRUCTx_INTR_MASK registers. These
registers are retained in Deep Sleep power mode but 7.2.6 CPU Exceptions Versus Fault
any system reset will reset these registers to the default
state.
Monitoring
■ Hard reset domain: FAULT_STRUCTx_STATUS and Some faults captured in Table 7-2 also result in bus errors or
FAULT_STRUCTx_DATA registers. These registers are CPU exceptions (Cortex-M4 Bus/Usage/Memory/Hard
retained through soft resets (detectable in faults). The faults can be communicated in two ways:
SRSS_RES_CAUSE registers). However, hard resets ■ As a bus error to the master of the faulting bus transfer.
such as XRES/POR/BOD will reset the registers. This will result in Bus, Usage, Memory, or Hard fault
exceptions in the CPU.
7.2.5 Using a Fault Structure ■ As a fault in a fault report structure. This fault can be
communicated as a fault interrupt to any processor in the
Follow these steps to configure and use a fault structure:
system. This allows fault handling on a processor that is
1. Identify the faults from Table 7-2 to be monitored in the not the master of the faulting bus transfer. It is useful for
system. faults that cause the master of the faulting transfer to
2. For firmware fault handling through interrupts become unresponsive or unreliable.
a. Set the FAULT bit [0] of the FAULT_STRUCTx_IN-
TR_MASK register.
b. Set the FAULT bit [0] of the FAULT_STRUCTx_INTR
register to clear any pending interrupt.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 53
Fault Monitoring
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 54
Fault Monitoring
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 55
8. Interrupts
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC 6 MCU family supports interrupts and CPU exceptions on both Cortex-M4 and Cortex-M0+ cores. Any condition
that halts normal execution of instructions is treated as an exception by the CPU. Thus an interrupt request is treated as an
exception. However, in the context of this chapter, interrupts refer to those events generated by peripherals external to the
CPU such as timers, serial communication block, and port pin signals; exceptions refer to those events that are generated by
the CPU such as memory access faults and internal system timer events. Both interrupts and exceptions result in the current
program flow being stopped and the exception handler or interrupt service routine (ISR) being executed by the CPU. Both
Cortex-M4 and Cortex-M0+ cores provide their own unified exception vector table for both interrupt handlers/ISR and
exception handlers.
8.1 Features
The PSoC 6 MCU supports the following interrupt features:
■ Supports 168 system interrupts
❐ 168 Arm Cortex-M4 interrupts
❐ Eight Arm Cortex-M0+ external interrupts and eight Arm Cortex-M0+ internal (software only) interrupts. The CPU sup-
ports up to 32 interrupts, but only 16 interrupts are used by PSoC 6 interrupt infrastructure. The eight external CPU
interrupts support deep sleep (WIC) functionality
❐ Four system interrupts can be mapped to each of the CPU non-maskable interrupt (NMI)
❐ Up to 39 interrupt sources capable of waking the device from Deep Sleep power mode
■ Nested vectored interrupt controller (NVIC) integrated with each CPU core, yielding low interrupt latency
■ Wakeup interrupt controller (WIC) enabling interrupt detection (CPU wakeup) in Deep Sleep power mode
■ Vector table may be placed in either flash or SRAM
■ Configurable priority levels (eight levels for Cortex-M4 and four levels for Cortex-M0+) for each interrupt
■ Level-triggered and pulse-triggered interrupt signals
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 56
Interrupts
8.2 Architecture
Figure 8-1. PSoC 6 MCU Interrupts Block Diagram
INT Source 1
168 M0+ Cortex M0+
Interrupt sources
INT Source 2 Interrupt Processor core
(Peripherals)
gen NVIC
Wakeup
Wakeup Interrupt
INT Source 167 168 Controller (WIC)1
M0+ Wakeup
System Wakeup
M4 Wakeup
M4 interrupt settings
Enable / Disable Interrupt
Set Priority
Mask Interrupt
Set NMI source
Software Trigger
Note1 - Input IRQn lines to the WIC are unsynchronized
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 57
Interrupts
Figure 8-1 shows the PSoC 6 MCU interrupt architecture. 2. On detecting the signal from the NVIC, the CPU stores
The PSoC 6 MCU has 168 system interrupts that are its current context by pushing the contents of the CPU
generated by various peripherals. These interrupt signals registers onto the stack.
are processed by the NVIC of the individual core. In the 3. The CPU also receives the exception number of the
Cortex-M4 core, the system interrupt source ‘n’ is directly triggered interrupt from the NVIC. All interrupts and
connected to IRQn. The Cortex-M0+ interrupt architecture exceptions have a unique exception number, as given in
uses eight CPU interrupts IRQ[7:0] out of the 32 available Table 8-1. By using this exception number, the CPU
IRQn lines of the core. In the Cortex-M0+ core, the system fetches the address of the specific exception handler
interrupt source connection to a particular IRQn of the core from the vector table.
is configurable and any of the 168 system interrupts can be
4. The CPU then branches to this address and executes
mapped to any of the IRQ[7:0]. This ensures that all the
the exception handler that follows.
system interrupts can be mapped onto any CPU interrupt
simultaneously. Refer to Interrupt Sources on page 62 for 5. Upon completion of the exception handler, the CPU
more details about the system interrupt to CPU interrupt registers are restored to their original state using stack
mapping. The NVIC takes care of enabling/disabling pop operations; the CPU resumes the main code
individual interrupt IRQs, priority resolution, and execution.
communication with the CPU core. The other exceptions Figure 8-2. Interrupt Handling When Triggered
such as NMI and hard faults are not shown in Figure 8-1
because they are part of CPU core generated events, unlike Rising Edge on Interrupt Line is
interrupts, which are generated by peripherals external to registered by the NVIC
the CPU.
In addition to the NVIC, the PSoC 6 MCU supports wakeup
interrupt controllers (WIC) for each CPU and a shared CPU detects the request signal
from NVIC and stores its
interrupt synchronization block that synchronizes the current context by pushing
interrupts to CLK_HF domain (adds two CLK_HF cycles contents onto the stack
delay for synchronization). The WIC provides detection of
Deep Sleep interrupts in the Deep Sleep CPU power mode.
Each CPU can individually be in Deep Sleep mode; the
CPU receives exception
device is said to be in Deep Sleep mode only when both the number of triggered interrupt
CPUs are in Deep Sleep mode. Refer to the Device Power and fetches the address of the
Modes chapter on page 225 for details. The Cortex-M4 WIC specific exception handle from
vector table.
block supports up to 39 interrupts that can wake up the CPU
from Deep Sleep power mode. The Cortex-M0+ WIC block
supports all eight interrupts. The device exits Deep Sleep
mode (System Wakeup signal in Figure 8-1) as soon as one CPU branches to the received
CPU wakes up. The synchronization blocks synchronize the address and executes
exception handler
interrupts to the CPU clock frequency as the peripheral
interrupts can be asynchronous to the CPU clock frequency.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 58
Interrupts
8.3.2 Level and Pulse Interrupts is initially inactive (logic low), the following sequence of
events explains the handling of level and pulse interrupts:
Both CM0+ and CM4 NVICs support level and pulse signals
1. On a rising edge event of the interrupt signal, the NVIC
on the interrupt lines (IRQn). The classification of an
registers the interrupt request. The interrupt is now in the
interrupt as level or pulse is based on the interrupt source.
pending state, which means the interrupt requests have
Figure 8-3. Level Interrupts not yet been serviced by the CPU.
2. The NVIC then sends the exception number along with
IRQn the interrupt request signal to the CPU. When the CPU
CPU
IRQn is still high starts executing the ISR, the pending state of the
Execution ISR ISR ISR interrupt is cleared.
main main main
State
3. For pulse interrupts, when the ISR is being executed by
the CPU, one or more rising edges of the interrupt signal
are logged as a single pending request. The pending
Figure 8-4. Pulse Interrupts interrupt is serviced again after the current ISR
execution is complete (see Figure 8-4 for pulse
IRQn interrupts).
CPU 4. For level interrupts, if the interrupt signal is still high after
Execution ISR ISR ISR
main main main completing the ISR, it will be pending and the ISR is
State
executed again. Figure 8-3 illustrates this for level
triggered interrupts, where the ISR is executed as long
Figure 8-3 and Figure 8-4 show the working of level and as the interrupt signal is high.
pulse interrupts, respectively. Assuming the interrupt signal
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 59
Interrupts
In Table 8-1 and Table 8-2, the first word (4 bytes) is not CM0+ core executes the ROM boot code and can enable
marked as exception number zero. This is because the first Cortex-M4 core from the application code. The reset
word in the exception table is used to initialize the main exception of the CM0+ core is tied to the device reset or
stack pointer (MSP) value on device reset; it is not startup. When the Cortex-M0+ core releases the Cortex-M4
considered as an exception. In the PSoC 6 MCU, both the reset, the M4 reset exception is executed. A device reset
vector tables can be configured to be located either in flash can occur due to multiple reasons, such as power-on-reset
memory or SRAM. The vector table offset register (VTOR) (POR), external reset signal on XRES pin, or watchdog
present as part of Cortex-M0+ and Cortex-M4 system reset. When the device is reset, the initial boot code for
control space registers configures the vector table offset configuring the device is executed by the Cortex-M0+ out of
from the base address (0x0000). The CM0P_SCS_VTOR supervisory read-only memory (SROM). The boot code and
register sets the vector offset address for the CM0+ core other data in SROM memory are programmed by Cypress,
and CM4_SCS_VTOR sets the offset for the M4 core. The and are not read/write accessible to external users. After
VTOR value determines whether the vector table is in flash completing the SROM boot sequence, the Cortex-M0+ code
memory (0x10000000 to 0x10100000) or SRAM execution jumps to flash memory. Flash memory address
(0x08000000 to 0x08048000). Note that the VTOR registers 0x10000004 (Exception#1 in Table 8-1) stores the location
can be updated only in privilege CPU mode. The advantage of the startup code in flash memory. The CPU starts
of moving the vector table to SRAM is that the exception executing code out of this address. Note that the reset
handler addresses can be dynamically changed by exception address in the SRAM vector table will never be
modifying the SRAM vector table contents. However, the used because the device comes out of reset with the flash
nonvolatile flash memory vector table must be modified by a vector table selected. The register configuration to select the
flash memory write. Note that the exception table must be SRAM vector table can be done only as part of the startup
256 byte-aligned for Cortex-M0+ and 1024 byte-aligned for code in flash after the reset is de-asserted. Note that the
Cortex-M4. reset exception flow for Cortex-M4 is the same as Cortex-
M0+. However, Cortex-M4 execution begins only after
The exception sources (exception numbers 1 to 15) are
CM0+ core de-asserts the M4 reset.
explained in 8.4 Exception Sources. The exceptions marked
as Reserved in Table 8-1 are not used, although they have
addresses reserved for them in the vector table. The 8.4.2 Non-Maskable Interrupt Exception
interrupt sources (exception numbers 16 to 183) are Non-maskable interrupt (NMI) is the highest priority
explained in 8.5 Interrupt Sources. exception next to reset. It is always enabled with a fixed
priority of –2. Both the cores have their own NMI exception.
8.4 Exception Sources There are three ways to trigger an NMI exception in a CPU
core:
This section explains the different exception sources listed ■ NMI exception from a system interrupt: Both Cortex-
in Table 8-1 and Table 8-2 (exception numbers 1 to 15). M0+ and Cortex-M4 provide an option to trigger an NMI
exception from up to four of the 168 system interrupts.
8.4.1 Reset Exception The NMI exception triggered due to the interrupt will
execute the NMI handler pointed to by the active
Device reset is treated as an exception in PSoC 6 MCUs. exception vector table. The CPUSS_CM4_NMI_CTLx
Reset exception is always enabled with a fixed priority of –3, and CPUSS_CM0P_NMI_CTLx registers select the
the highest priority exception in both the cores. When the interrupt source that triggers the NMI from hardware.
device boots up, only the Cortex-M0+ core is available. The
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 60
Interrupts
The registers have a default value of 1023; that is, if the the NMI. NMI is triggered when any of the four interrupts
register is set to 1023, then that particular register does are triggered; that is, the interrupts are logically ORed.
not map any interrupt source to the NMI. There are four See Figure 8-5.
such registers and each can map one interrupt vector to
Figure 8-5. NMI Trigger
CPUSS_CM4_NMI_CTLx
Or
CPUSS_CM0P_NMI_CTLx
10
0
0
INT Source 0 n
1023
System interrupt
sources INT Source 1 1
n CM4 NMI
INT Source 2 1023
Or
n <= 1023
CM0+ NMI
(device n
2
dependent) 1023
1023
■ NMI exception by setting NMIPENDSET bit (user NMI because of an error during normal or exception processing.
exception): An NMI exception can be triggered in HardFault has a fixed priority of –1, meaning it has higher
software by setting the NMIPENDSET bit in the interrupt priority than any exception with configurable priority. A
control state registers (CM0P_SCS_ICSR and HardFault exception is a catch-all exception for different
CM4_SCS_ICSR). Setting this bit will execute the NMI types of fault conditions, which include executing an
handler pointed to by the active vector table in the undefined instruction and accessing an invalid memory
respective CPU cores. addresses. The CPU does not provide fault status
■ System Call NMI exception: This exception is used for information to the HardFault exception handler, but it does
nonvolatile programming and other system call permit the handler to perform an exception return and
operations such as flash write operation and flash continue execution in cases where software has the ability
checksum operation. Inter processor communication to recover from the fault situation.
(IPC) mechanism is used to implement a system call in
PSoC 6 MCUs. A dedicated IPC mailbox is associated 8.4.4 Memory Management Fault
with each core (M0+ and M4) and the debug access port Exception
(DAP) to trigger a system call. The CPU or DAP A memory management fault is an exception that occurs
acquires this dedicated mailbox, writes the system call because of a memory protection-related fault. The fixed
opcode and argument to the mailbox, and notifies a memory protection constraints determine this fault, for both
dedicated IPC structure. Typically, the argument is a instruction and data memory transactions. This fault is
pointer to a structure in SRAM. This results in an NMI always used to abort instruction accesses to Execute Never
interrupt in the CM0+ core. Note that all the system calls (XN) memory regions. The memory management fault is
are serviced by Cortex-M0+ core. A Cortex-M0+ NMI only supported by the M4 core. The priority of the exception
exception triggered by this method executes the NMI is configurable from 0 (highest) to 7 (lowest).
exception handler code that resides in SROM. Note that
the NMI exception handler address is automatically
initialized to the system call API located in SROM (at 8.4.5 Bus Fault Exception
0x0000000D) by the boot code. The value should be A Bus Fault is an exception that occurs because of a
retained during vector table relocations; otherwise, no memory-related fault for an instruction or data memory
system call will be executed. The NMI handler code in transaction. This might be from an error detected on a bus in
SROM is not read/write accessible because it contains the memory system. The bus fault is supported only by the
nonvolatile programming routines that cannot be M4 core. The priority of the exception is configurable from 0
modified by the user. The result of the system call is (highest) to 7 (lowest).
passed through the same IPC mechanism. For details,
refer to the Inter-Processor Communication chapter on 8.4.6 Usage Fault Exception
page 41.
A Usage Fault is an exception that occurs because of a fault
8.4.3 HardFault Exception related to instruction execution. This includes:
■ an undefined instruction
Both CM0+ and CM4 cores support HardFault exception.
■ an illegal unaligned access
HardFault is an always-enabled exception that occurs
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 61
Interrupts
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 62
Interrupts
bit remains set until all the system interrupts connected SYSTEM_INT_VALID bit set. After Port 0 interrupt is
to the CPU interrupts are cleared at the source. serviced and cleared, IRQ0 will be triggered again with
■ SYSTEM_INT_IDX bits[9:0] of the register specifies the SYSTEM_INT_IDX bit set to 2 (Port 2 interrupt) in the
index (a number in the range [0, 1022]) of the lowest CPUSS_CM0_INT0_STATUS register. Only after servicing
active system interrupt mapped to the corresponding Port 2 interrupt and clearing, the SYSTEM_INT_VALID bit
CPU interrupt. will be cleared.
For instance, say CM0+ IRQ0 is connected to Port 0 and The CPU interrupt handler should use the
Port 2 GPIO interrupts. When an interrupt in both Port 0 and SYSTEM_INT_IDX field to index a system interrupt lookup
Port 2 are triggered simultaneously, IRQ0 in CM0+ will be table and jump to the system interrupt handler. The lookup
triggered with CPUSS_CM0_INT0_STATUS reading 0 (Port table is typically located in one of the system memories. The
0 interrupt) in SYSTEM_INT_IDX bit and following code illustrates the approach:
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 63
Interrupts
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 64
Interrupts
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 65
Interrupts
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 66
Interrupts
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 67
Interrupts
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 68
Interrupts
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 69
Interrupts
The Interrupt Control State Register (CM0P_SCS_ICSR and CM4_SCS_ICSR) contains status bits describing the various
exceptions states.
■ The VECTACTIVE bits ([8:0]) in the ICSR store the exception number for the current executing exception. This value is
zero if the CPU does not execute any exception handler (CPU is in thread mode). Note that the value in VECTACTIVE
bitfields is the same as the value in bits [8:0] of the Interrupt Program Status Register (IPSR), which is also used to store
the active exception number.
■ The VECTPENDING bits ([20:12]) in the ICSR store the exception number of the highest priority pending exception. This
value is zero if there are no pending exceptions.
■ The ISRPENDING bit (bit 22) in the ICSR indicates if a NVIC generated interrupt is in a pending state.
Setting the pending bit when the same bit is already set Note that the ISPR and ICPR registers are used only for the
results in only one execution of the ISR. The pending bit can peripheral interrupts. These registers cannot be used for
be updated regardless of whether the corresponding pending the exception numbers 1 to 15. These 15
interrupt is enabled. If the interrupt is not enabled, the exceptions have their own support for pending, as explained
interrupt line will not move to the pending state until it is in Exception Sources on page 60.
enabled by writing to the ISER register.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 70
Interrupts
8.9 Stack Usage for Interrupts/ Chip low-power modes have two categories of interrupt
sources:
Exceptions ■ Interrupt sources that are available in the Active, Sleep,
When the CPU executes the main code (in thread mode) and Deep Sleep modes (watchdog timer interrupt, RTC,
and an exception request occurs, the CPU stores the state GPIO interrupts, and Low-Power comparators)
of its general-purpose registers in the stack. It then starts ■ Interrupt sources that are available only in the Active and
executing the corresponding exception handler (in handler Sleep modes
mode). The CPU pushes the contents of the eight 32-bit
When using the WFE instruction in CM4, make sure to call
internal registers into the stack. These registers are the
the WFE instruction twice to properly enter and exit Sleep/
Program and Status Register (PSR), ReturnAddress, Link
Deep Sleep modes. This behavior comes from the event
Register (LR or R14), R12, R3, R2, R1, and R0. Both
register implementation in Arm v7 architecture used in
Cortex-M4 and Cortex-M0+ have two stack pointers - MSP
Cortex-M4. According to the ARM V7 architecture reference
and PSP. Only one of the stack pointers can be active at a
manual (Section B1.5.18 Wait For Event and Send Event):
time. When in thread mode, the Active Stack Pointer bit in
the Control register is used to define the current active stack ■ A reset clears the event register.
pointer. When in handler mode, the MSP is always used as ■ Any WFE wakeup event, or the execution of an
the stack pointer. The stack pointer always grows exception return instruction, sets the event register.
downwards and points to the address that has the last ■ A WFE instruction clears the event register.
pushed data.
■ Software cannot read or write the value of the event
When the CPU is in thread mode and an exception request register directly.
comes, the CPU uses the stack pointer defined in the
Therefore, the first WFE instruction puts CM4 to sleep and
control register to store the general-purpose register
second WFE clears the event register after a WFE wakeup,
contents. After the stack push operations, the CPU enters
which sets the event register. So the next WFE will put the
handler mode to execute the exception handler. When
core to sleep.
another higher priority exception occurs while executing the
current exception, the MSP is used for stack push/pop Note that this behavior is not present in Arm v6 architecture
operations, because the CPU is already in handler mode. used in Cortex-M0+. Therefore, in CM0+ only one WFE
See the CPU Subsystem (CPUSS) chapter on page 32 for instruction is sufficient to successfully enter or exit Sleep
details. and Deep Sleep modes.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 71
Interrupts
b. Define the exception handler function and write the c. For Cortex-M0+, define and enable the additional
address of the function to the exception vector table. system interrupt handler table and functions as
Table 8-1 gives the exception vector table format; the explained in Interrupt Sources on page 62.
exception handler address should be written to the d. Set up the exception priority, as explained in
appropriate exception number entry in the table. Interrupt/Exception Priority on page 69.
e. Enable the exception, as explained in Enabling and
Disabling Interrupts on page 69.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 72
9. Protection Units
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
Protection units are implemented in the PSoC 6 MCU to enforce security based on different operations. A protection unit
allows or restricts bus transfers. The rules are enforced based on specific properties of a transfer. The rules that determine
protection are implemented in protection structures (a register structure). A protection structure defines the protected address
space and the protection attributes. The hardware that evaluates these protection structures, to restrict or permit access, is
the protection unit. The PSoC device has different types of protection units such as MPU, SMPU, and PPU. Each have a
distinct set of protection structures, which helps define different protection regions and their attributes.
9.1 Architecture
Figure 9-1 shows a conceptual view of implementation of the PSoC protection system.
Figure 9-1. Conceptual View of PSoC Protection System
Bus Masters
Test
CPU1 CPU2 DMA
Controller
Bus Master’s Bus Master’s Bus Master’s Bus Master’s
Protection Protection Protection Protection
Attribute Attribute Attribute Attribute
Sets rules to
Protection check against
Unit
Protection
Attribute
PSoC 6 Memory Map
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 73
Protection Units
The functioning of a secure system is based on the Each bus master is qualified by its own protection attribute.
following: For every bus transfer, the protection unit compares the bus
■ Bus masters: This term refers to the bus masters in the master's protection attribute and accessed address against
architecture. In a PSoC 6 device, an example of a bus the rules set in the protection structures and decides on
master is a Cortex-M core, DMA, or a test controller. providing or denying access.
■ Protection units: Protection units are the hardware
engines that enforce the protection defined by protection 9.2 PSoC 6 Protection
structures. There are three types of protection units,
acting at different levels of memory access with different Architecture
precedence and priority of protection – MPU, SMPU,
When there is a memory (SRAM/flash/peripheral) access by
and PPU.
a bus master, the access is evaluated by a protection unit
■ Protection structure: A protection structure is a register against the protection attributes set in protection structures
structure in memory that sets up the rules based on for the memory location being accessed. If the bus master’s
which each protection unit will evaluate a transfer. Each protection attributes satisfy the protection attributes set in
protection unit associates itself to multiple protection the protection structures, then access is allowed by the
structures. The protection structure associated with a protection unit. If there is an access restriction, a fault
protection unit are evaluated in the order starting with condition is triggered and a bus error occurs. Thus
the protection structure with the largest index. For protection units secure bus transfer address range either in
example, if there are 16 protection structures associated memory locations (SRAM/flash) or peripheral registers.
with a protection unit, then the evaluation of a transfer From an architectural perspective, there is no difference
starts from protection structure 15 and counts down. between memory protection and peripheral protection.
Physically a protection structure is a register structure in However, from an implementation perspective, separate
the memory map that defines a protection rule. Each memory and peripheral protection is provided.
protection structure constitutes the following:
Two types of protection units, memory protection units
❐ Defines a memory region on which the rule is
(MPU) and shared memory protection units (SMPU), are
applied. It designates what the bus transfer needs to
provided in the CPU subsystem (CPUSS) to protect memory
be evaluated against this protection structure.
locations. A separate protection unit type is provided for
- Base address peripheral protection (PPU) in the PERI:
- Size of memory block ■ A bus master may have a dedicated MPU. In a CPU bus
❐ A set of protection attributes master, the MPU is typically implemented as part of the
- R/W/X CPU and is under control of the OS/kernel. In a non-
CPU bus master, the MPU is typically implemented as
- User/privilege
part of the bus infrastructure and under control of the
- Secure/non Secure OS/kernel of the CPU that “owns or uses” the bus
- Protection context master. If a CPU switches tasks or if a non-CPU
■ Protection attributes: These are properties based on switches ownership, the MPU settings are typically
which a transfer is evaluated. There are multiple updated by OS/kernel software. The different MPU types
protection attributes. The set of protection attributes are:
available for a protection structure depends on the ❐ An MPU that is implemented as part of the CPU. This
protection unit it is associated with. Protection attributes type is found in the Arm CM0+ and CM4 CPUs.
appear in two places: ❐ An MPU that is implemented as part of the bus infra-
❐ Protection structures: Protection attributes associ- structure. This type is found in bus masters such as
ated with a protection structure set the rules for crypto and test controller. The definition of this MPU
access based on these attributes. type follows the Arm MPU definition (in terms of
❐ Bus master's protection attribute: Each bus master memory region and access attribute definition) to
has its own access attributes, which define the bus ensure a consistent software interface.
master's access privileges. Some of these attributes, ■ SMPUs are intended for implementing protection in a
such as secure/non-secure, are set for a master. situation with multiple bus masters. These protection
Other attributes such as protection context and user/ units implement a concept called Protection Context. A
privilege attribute are dynamic attributes, which protection context is a pseudo state of a bus master,
change based on bus master's context and state. which can be used to determine access attributes across
multiple masters. The protection context is a protection
In summary, a PSoC 6 device has protection units that act attribute not specific to a bus master. The SMPUs can
as a gate for any access to the PSoC memory map. The distinguish between different protection contexts; they
rules for protection are set by the protection structures. can also distinguish secure from non-secure accesses.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 74
Protection Units
This allows for an effective protection in a multi-core occurrence of a fault. This is useful if the violating bus
scenario. master cannot resolve the bus error by itself, but requires
■ PPUs are protection units provided in the PERI register another CPU bus master to resolve the bus error on its
space for peripheral protection. The PPU attributes are behalf.
similar to the SMPU, except that they are intended for For a buffered mode of transfer
protecting the peripheral space. Refer to the registers (CPUSS_BUFF_CTL[WRITE_BUFF]), the behavior during
TRM for details. The PPUs are intended to distinguish protection violation is different. When
between different protection contexts and to distinguish CPUSS_BUFF_CTL[WRITE_BUFF] is set to ‘1’, the write
secure from non-secure accesses and user mode transfers on the bus are buffered. So the transfer is first
accesses from privileged mode accesses. There are two acknowledged when the buffer receives the transfer. A
types of PPU structures. protection violation will be only evaluated when the actual
❐ Fixed PPUs implement protection for fixed address write happens at the destination register. This leads to the
regions that typically correspond to a specific periph- write transfer not generating a bus error for buffered mode.
eral However, a fault will be registered as soon as the transfer
❐ Programmable PPUs allows the user to program the tries to write the destination location. Therefore, for buffered
address region to be protected writes, the user must verify the fault structure to make sure
no violations have occurred.
The platform’s DMA controller does not have an MPU.
Instead, a DMA controller channel inherits the access A protection violation results in a bus error and the bus
control attributes of the bus transfer that programmed the transfer will not reach its target. An MPU or SMPU violation
channel. that targets a peripheral will not reach the associated
protection evaluation (PPU). In other words, MPU and
The definition of SMPU and PPU follows the MPU definition SMPU have a higher priority over PPU.
and adds the capability to distinguish accesses from
different protection contexts (the MPU does not include Protection unit addresses the following:
support for a protection context). If security is required, the ■ Security requirements. This includes prevention of
SMPU and possibly PPUs MMIO registers must be malicious attacks to access secure memory or
controlled by a secure CPU that enforces system-wide peripherals. For example, a non-secure master should
protection. not be able to access key information in a secure
memory region.
Figure 9-2 gives an overview of the location of MPUs,
SMPUs, and PPUs in the system. Note that a peripheral ■ Safety requirements. This includes detection of
group PPU needs to provide access control only to the accidental (non-malicious) software errors and random
peripherals within a peripheral group (group of peripherals hardware errors. Enabling failure analysis is important
with a shared bus infrastructure). so the root cause of a safety violation can be
investigated. For example, analyzing a flash memory
As mentioned, the MPU, SMPU, and PPU protection failure on a device that is returned from the field should
functionality follows the Arm MPU definition: be possible.
■ Multiple protection structures are supported.
To address security requirements, the Cortex M0+ is used
■ Each structure specifies an address range in the unified as a ‘secure CPU’. This CPU is considered a trusted entity.
memory architecture and access attributes. An address Any access by the CPU tagged as “secure” will be called
range can be as small as 32 bytes. “secure access”.
A protection violation is caused by a mismatch between a
bus master’s access attributes and the protection structure
and access attributes for the memory region configured in
the protection structure.
A bus transfer that violates a protection structure results in a
bus error.
For AXI transfers, the complete address range is matched. If
a transfer references multiple 32-byte regions (the smallest
protection structure address range is 32 bytes), multiple
cycles are required for matching – one cycle per 32-byte
region.
Protection violations are captured in the fault report
structure to allow for failure analysis. The fault report
structures can generate an interrupt to indicate the
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 75
Protection Units
DMA Test
CM0+ CM4 Crypto
(DataWire) Controller
Arm MPU Arm MPU
MPU MPU
AHB
GPIO
Fixed Programmable
Function Analog and Digital
Blocks Blocks
The different types of protection units cater to different use cases for protection.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 76
Protection Units
The REGION_SIZE field specifies the size of a region. The region size is a power of 2 in the range of [256 B, 4 GB]. The base
address ADDR specifies the start of the region, which must be aligned to the region size. A region is partitioned into eight
equally sized sub-regions. The SUBREGION_DISABLE field specifies individual enables for the sub-regions within a region.
For example, a REGION_SIZE of “0x08” specifies a region size of 512 bytes. If the start address is 0x1000:5400 (512-byte
aligned), the region ranges from 0x1000:5400 to 0x1000:55ff. This region is partitioned into the following eight 64-byte
subregions:
subregion 0 from 0x1000:5400 to 0x1000:543f
subregion 1 from 0x1000:5440 to 0x1000:547f
…
subregion 7 from 0x1000:55c0 to 0x1000:55ff.
If the SUBREGION_DISABLE is 0x82 (bitfields 1 and 7 are ‘1’), subregions 1 and 7 are disabled; subregions 0, 2, 3, 4, 5, and
6 are enabled.
In addition, an ATT.ENABLED field specifies whether the region is enabled. Only enabled regions participate in the protection
“matching” process. Matching identifies if a bus transfer address is contained within an enabled subregion
(SUBREGION_DISABLE) of an enabled region (ENABLED).
Protection attributes: The protection attributes specify access control to the region (shared by all subregions within the
region). Access control is performed by comparing against a bus master's protection attributes of the bus master performing
the transfer. The following access control fields are supported:
■ Control for read accesses in user mode (ATT.UR field).
■ Control for write accesses in user mode (ATT.UW field).
■ Control for execute accesses in user mode (ATT.UX field).
■ Control for read accesses in privileged mode (ATT.PR field).
■ Control for write accesses in privileged mode (ATT.PW field).
■ Control for execute accesses in privileged mode (ATT.PX field).
■ Control for secure access (ATT.NS field).
■ Control for individual protection contexts (ATT.PC_MASK[15:0], with MASK[0] always constant at 1). This protection
context control field is present only for the SMPU and PPU.
The execute and read access control attributes are orthogonal. Execute transfers are typically read transfers. To allow
execute and read transfers in user mode, both ATT.UR and ATT.UX must be set to ‘1’. To allow data and read transfers in user
mode, only ATT.UR must be set to ‘1’. In addition, the ATT.PC_MATCH control field is supported, which controls “matching”
and “access evaluation” processes. This control field is present only for the SMPU and PPU protection structures.
For example, only protection context 2 can access a specific address range. These accesses are restricted to read and write
secure accesses in privileged mode. The access control fields are programmed as follows:
■ ATT.UR is 0: read accesses in user mode not allowed.
■ ATT.UW is 0: write accesses in user mode not allowed.
■ ATT.UX is 0: execute accesses in user mode not allowed.
■ ATT.PR is 1: read accesses in privileged mode allowed.
■ ATT.PW is 1: write accesses in privileged mode allowed.
■ ATT.PX is 0: execute accesses in privileged mode not allowed.
■ ATT.NS is 0: secure access required.
■ ATT.PC_MASK is 0x0005: protection context 1 and 3 accesses enabled (all other protection contexts are disabled).
■ ATT.PC_MATCH is 0: the PC_MASK field is used for access evaluation. Three separate access evaluation subprocesses
are distinguished:
❐ A subprocess that evaluates the access based on read/write, execute, and user/privileged access attributes.
❐ A subprocess that evaluates the access based on the secure/non-secure attribute.
❐ A subprocess that evaluates the access based on the protection context index (used only by the SMPU and PPU
when ATT.PC_MATCH is 0).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 77
Protection Units
If all access evaluations are successful, access is allowed. If any process evaluation is unsuccessful, access is not allowed.
Matching the bus transfer address and access evaluation of the bus transfer (based on access attributes) are two
independent processes:
■ Matching process. For each protection structure, the process identifies whether a transfer address is contained within the
address range. This identifies the “matching” regions.
■ Access evaluation process. For each protection structure, the process evaluates the bus transfer access attributes
against the access control attributes.
A protection unit typically has multiple protection structures and evaluates the protection structures in decreasing order. The
first matching structure provides the access control attributes for the evaluation of the transfer's access attributes. In other
words, higher-indexed structures take precedence over lower-indexed structures.
The following pseudo code illustrates the process.
match = 0;
for (i = n-1; i >= 0; i--)// n: number of protection regions
if (Match (“transfer address”, “protection context”
“MMIO registers ADDR and ATT of protection structure i”)) {
match = 1; break;
}
|
if (match)
AccessEvaluate (“transfer access attributes”, “protection context”
“MMIO register ATT of protection structure i”);
else
“access allowed”
Notes:
■ If no protection structure provides a match, the access is allowed.
■ If multiple protection structures provide a match, the access control attributes for the access evaluation are provided by
the protection structure with the highest index.
An example of using the PC_MATCH feature is as follows. Two SMPU structures are configured to protect the same address
range:
■ Case 1: SMPU#2: PC = 3, PC_MATCH = 0 SMPU#1: PC = 2, PC_MATCH = 0
To access the master of protection context 2, SMPU#2 has the highest index and address match, but attributes do not
match; therefore, access is restricted. The SMPU#1 is not evaluated because the PC_MATCH is 0.
■ Case 2: SMPU#2: PC = 3, PC_MATCH = 1 SMPU#1: PC = 2, PC_MATCH = 0
The SMPU#2 address matches but PC does not match and is skipped because PC_MATCH is 1. SMPU#1 is evaluated
and the address and attributes match; therefore, access is allowed.
As mentioned, the protection unit evaluates the protection structures in decreasing order. From a security requirements
perspective, this is of importance: a non-secure protection context must not be able to add protection structures that have a
higher index than the protection structures that provide secure access. The protection structure with a higher index can be
programmed to allow non-secure accesses. Therefore, in a secure system, the higher programmable protection structures
are protected to only allow restricted accesses
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 78
Protection Units
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 79
Protection Units
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 80
Protection Units
protection region CPUSS.BOOT is assigned to be accessible from PC=0 only, which ensures these settings can no
longer be changed after boot.
❐ The boot process then changes the current PC by changing MPUn.MS_CTL.PC to a protection context that is not a
special context. This is done for all currently active masters (which typically is only the CM0+).
❐ When the above is complete, the system executes a regular (not special) context and can enter into special contexts
only through the use of interrupts using the special handler addresses.
9.7.2 MPU
The MPUs are situated in the CPUSS and are associated to a single master. An MPU distinguishes user and privileged
accesses from a single bus master. However, the capability exists to perform access control on the secure/non-secure
attribute.
As an MPU is associated to a single master, the MPU protection structures do not provide protection context control
attributes.
Figure 9-3. MPU Functionality
Protection structures
transfer address
are 32 B aligned
transfer access
Two MMIO registers
attributes
per protection structure MPU protection
ADDR structures
31
0
SUBREGION_
MPU protection
ADDR[23:0]
DISABLE
structure 0
Memory
0
protection
MPU protection
REGION_
ENABLED
PW
UW
NS
PX
PR
UX
UR
Interface to fault
context attributes structures
...
9.7.3 SMPU
The SMPU is situated in the CPUSS and is shared by all bus masters. The SMPU distinguishes between different protection
contexts and distinguishes secure from non-secure accesses. However, the capability exists to perform access control on the
user/privileged mode attribute.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 81
Protection Units
transfer address
(pairs) are 64 B aligned
transfer access
Two MMIO registers
attributes
per protection structure
SMPU protection
ADDR structures
31
0
SUBREGION_
SMPU protection
ADDR[23:0]
DISABLE
structure pair 0
0
Shared
memory
SMPU protection Shared
memory
protection
PC_MATCH
REGION_
PC_MASK
ENABLED
(SMPU)
[15:1]
PW
UW
Interface to fault
PR
UR
NS
PX
UX
unitprotection
(SMPU) structures
... unit (SMPU)
Note that a single set of SMPU region structures provides the same protection information to all SMPUs in the systems.
9.7.4 PPU
■ The PPUs are situated in the PERI block and are associated with a peripheral group (a group of peripherals with a shared
AHB-Lite bus infrastructure). A PPU is shared by all bus masters. The PPU distinguishes between different protection
contexts; it also distinguishes secure from non-secure accesses and user mode from privileged mode accesses.
Figure 9-5. PPU Functionality
transfer address
transfer access
Six MMIO registers per
attributes
protection structure
PPU protection
ADDR structures
31
ADDR[31:2]
PPU protection
Size structure pair 0
31
Size [28:24]
PPU protection fault_req
structure pair 1 fault_ack
ATT0 fault_data
31
Peripheral
0
protection
PPU protection
unit (PPU)
PC3_PW
PC2_PW
PC1_PW
PC0_PW
PC3_UW
PC2_UW
PC1_UW
PC0_UW
PC3_PR
PC2_PR
PC1_PR
PC0_PR
PC3_UR
PC2_UR
PC1_UR
PC0_UR
PC3_NS
PC2_NS
PC1_NS
PC0_NS
structure pair 2
Interface to fault
structures
...
ATT1
31
0
PC7_PW
PC6_PW
PC5_PW
PC4_PW
PC7_UW
PC6_UW
PC5_UW
PC4_UW
PC7_PR
PC6_PR
PC5_PR
PC4_PR
PC7_UR
PC6_UR
PC5_UR
PC4_UR
PC7_NS
PC6_NS
PC5_NS
PC4_NS
ATT2
31
0
PC11_UW
PC10_UW
PC11_PW
PC10_PW
PC11_UR
PC10_UR
PC11_NS
PC10_NS
PC11_PR
PC10_PR
PC9_PW
PC8_PW
PC9_UW
PC8_UW
PC9_PR
PC8_PR
PC9_UR
PC8_UR
PC9_NS
PC8_NS
ATT3
31
0
PC14_UW
PC14_UW
PC13_UW
PC12_UW
PC14_PW
PC14_PW
PC13_PW
PC12_PW
PC14_NS
PC14_NS
PC13_NS
PC12_NS
PC14_UR
PC14_UR
PC13_UR
PC12_UR
PC14_PR
PC14_PR
PC13_PR
PC12_PR
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 82
Protection Units
configured for each protection context. The following table summarizes the different fixed PPU structures in CY8C62xx
devices and details the regions they protect.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 83
Protection Units
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 84
Protection Units
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 85
Protection Units
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 86
Protection Units
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 87
Protection Units
■ The programmable PPU structures can have Each peripheral group has a dedicated PPU. The
configurable address regions. Similar to fixed-PPU protection information is provided by peripheral group
structures, the protection attributes of programmable MMIO registers. A peripheral group PPU uses fixed
PPU structures can be configured for each protection protection structure pairs for two purposes.
context. Programmable PPU structures are similar to ❐ Fixed protection structure pairs protect peripherals
SMPU structures but are intended to be used with the (one pair for each peripheral). The master structure
peripheral register space. These protection structures protects the MMIO registers of the pair (the memory
are typically used to protect registers in a specific block, region encompasses the MMIO registers of the pair’s
which are not covered by the resolution of fixed PPU master structure and slave structure). The slave
structures. structure protects the peripheral (the memory region
Note that the memory regions of the fixed master encompasses the peripheral address region).
structures, fixed slave structures, and programmable ❐ Fixed protection structure pairs protect specific
master structures are fixed by hardware and are peripheral subregions (one pair for each subregion).
mutually exclusive; that is, they do not overlap. The The master structure protects the MMIO registers of
memory regions of the programmable slave structure the pair. The slave structure protects the peripheral
are software-programmable and can potentially overlap. subregion. These pairs can be used to protect, for
Therefore, it is important to assign priority to the example, individual DW channels in the DW periph-
protection structure matching process. The order in eral or individual IPC structures in the IPC periph-
which these are evaluated are as follows: eral.
❐ The fixed master structures are evaluated in Note that the memory regions of the fixed peripheral
decreasing order. master structures, fixed peripheral slave structures, and
❐ The fixed slave structures are evaluated in decreas- fixed peripheral subregion master structures are fixed by
ing order. hardware and are mutually exclusive; that is, they do not
❐ The programmable master structures are evaluated overlap. The memory regions of the fixed peripheral
in decreasing order. subregion slave structures are fixed by hardware and
typically are a subset of a peripheral address region, and
❐ The programmable slave structures are evaluated in
therefore overlap with a fixed peripheral slave structure.
decreasing order.
Therefore, it is important to assign priority to how the
The programmable slave structures are evaluated last. protection structure matching process:
These structures are software-programmable and can
❐ The fixed peripheral subregion master structures are
potentially overlap (overlapping should not allow
evaluated in decreasing order.
software to circumvent the protection as provided by the
fixed protection structure pairs). ❐ The fixed peripheral subregion slave structures are
evaluated in decreasing order.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 88
Protection Units
❐ The fixed peripheral master structures are evaluated PPU protection information (the master and slave protection
in decreasing order. structures are registers).
❐ The fixed peripheral slave structures are evaluated in
decreasing order. 9.7.6 Protection Structure Types
It is important to evaluate the fixed peripheral subregion Different protection structure types are used because some
master structures first. This allows software to assign resources, such as peripheral registers, have a fixed
different protection for a subregion of a peripheral. address range. Protection of protection structures requires
pairs of neighboring protection structures.
9.7.5 Protection of Protection Structures
Three types of protection structures with a consistent
The MPU, SMPU, and PPU-based protection architecture is register interface are described here:
consistent and provides the flexibility to implement different ■ Programmable protection structures. These are 32-byte
system-wide protection schemes. Protection structures can protection structures with a programmable address
be set once at boot time or can be changed dynamically range. These structures are used by the MPUs.
during device execution. For example, a CPU RTOS can
■ Fixed protection structure pairs. These are 64-byte
change the CPU’s MPU settings; a secure CPU can change
master/slave protection structure pairs, consisting of two
the SMPU and PPUs settings. But such a system will be left
32-byte protection structures. These structures are used
insecure if there is no way to protect the protection
by the PPUs. Both structures have a fixed, constant
structures themselves. There must be a way to restrict
address region. The master structure has the UX and PX
access to the protection structures.
attributes as constant ‘0’ (execution is never allowed)
The protection of protection structures is achieved using and the UR and PR attributes as constant ‘1’ (reading is
another protection structure. For this reason, protection always allowed). The slave structure has the UX and PX
structures are defined in pairs of master and slave. We refer attributes as constant ‘1’.
to the slave and master protection structures as a protection ■ Programmable protection structure pairs. These are 64-
pair. Note that the address range of the master protection byte master/slave protection structure pairs, consisting
structure is known, that is, it is constant. of two 32-byte protection structures. These structures
The first (slave) protection structure protects the resource are used by the PPU and SMPU. The master structure
and the second (master) protection structure protects the has a fixed, constant address region. The slave structure
protection (address range of the second protection structure has a programmable address region. The master
includes both the master and slave protection structures). structure has the UX and PX attributes as constant ‘0’
(execution is never allowed) and the UR and PR
The protection architecture is flexible enough to allow for attributes as constant ‘1’ (reading is always allowed).
variations: The PPU slave structure has the UX and PX attributes
■ Exclusive peripheral ownership can be shared by more as constant ‘1’. The SMPU slave structure has
than two protection contexts. programmable UX and PX attributes.
■ The ability to change ownership is under control of a Note that the master protection structure in a protection
single protection context, and exclusive or non-exclusive structure pair is required only to address security
peripheral ownership is shared by multiple protection requirements. The distinction between the three protection
contexts. structure types is an implementation optimization. From an
Note that in secure systems, typically a single secure CPU architectural perspective, all PPU protection structures are
is used. In these systems, the ability to change ownership is the same, with the exception that for some protection
assigned to the secure CPU at boot time and not structures the address range is fixed and not programmable.
dynamically changed. Therefore, you must assign the As mentioned earlier, a protection unit evaluates the
secure CPU its own, dedicated protection context. protection regions in decreasing protection structure index
Both PPU and SMPU is intended to distinguish between order. The protection structures are evaluated in the
different protection contexts and to distinguish secure from following order:
non-secure accesses. Therefore, both PPU and SMPU ■ Fixed protection structures for specific peripherals or
protection use protection structure pairs. In the SMPU, the peripheral register address ranges.
slave protection structure provides SMPU protection ■ Programmable protection structures.
information and the master protection structure provides
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 89
Protection Units
3
1
0
ADDR
SUBREGI
DISABLE
3
1
ADDR[
23:0]
ON_
Programmable ADDR Encompassing Peripheral Slave MMIO Registers
SIZE
3
1
0
Programmable REGION SIZE ATT
3
1
0
PC_MATCH
REGION_
PC_MASK
ENABLED
3
1
0
ATT0,1,2&3
SIZE
[15:1]
PW
UW
PR
PX
UR
NS
UX
1
Programmable PC Attributes
3
1
0
ADDR Constant
3
1
0
Constant ADDR[23:0], encompassing
Constant ADDR Encompassing Peripheral Slave MMIO Registers SUBREGION_DISA
master and slave protection structures
BLE
SIZE
3
1
0
Constant REGION SIZE ATT
3
1
0
PC_MATCH
PC_MASK
ENABLED
REGION_
3
1
0
ATT0,1,2&3
Constant
UR = 1
PX = 0
PR = 1
UX = 0
[15:1]
PW
UW
SIZE
NS
1
Programmable PC Attributes
ATT0,1,2&3
Programmable PC Attributes
Master Structure
ADDR
3
1
ATT0,1,2&3
Programmable PC Attributes
Note: By default, both CPUs (CM0+ and CM4) are in protection context 0 when they come out of reset. In protection context
0, the master is able to access all memory regardless of its protection settings. The master’s protection context will need to be
changed from protection context 0 to make any protection structure configuration effective. Multiple protection structures may
be preconfigured as part of the boot code, which sets up a secure environment at boot time. See the Boot Code chapter on
page 193 for details of these configurations.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 90
10. DMA Controller (DW)
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The DMA transfers data to and from memory, peripherals, and registers. These transfers occur independent from the CPU.
The DMA can be configured to perform multiple independent data transfers. All data transfers are managed by a channel.
There can be up to 32 channels in the DMA. The number of channels in the DMA controller can vary with devices. Refer to
the PSoC 61 datasheet/PSoC 62 datasheet for the number of channels supported in the device. A channel has an associated
priority; channels are arbitrated according to their priority.
10.1 Features
The DMA controller has the following features:
■ Supports up to 29 channels per DMA controller; see the PSoC 61 datasheet/PSoC 62 datasheet for details
■ Supports multiple DMA controller instances in a device
■ Four levels of priority for each channel
■ Descriptors are defined in memory and referenced to the respective channels
■ Supports single, 1D, or 2D transfer modes for a descriptor
■ Supports transfer of up to 65536 data elements per descriptor
■ Configurable source and destination address increments
■ Supports 8-bit, 16-bit, and 32-bit data widths at both source and destination
■ Configurable input trigger behavior for each descriptor
■ Configurable interrupt generation in each descriptor
■ Configurable output trigger generation for each descriptor
■ Descriptors can be chained to other descriptors in memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 91
DMA Controller (DW)
10.2 Architecture
Figure 10-1. DMA Controller
DMA
Descriptors
Descriptors
Descriptors
Memory
A data transfer is initiated by an input trigger. This trigger connects to a specific system trigger through a trigger
may originate from the source peripheral of the transfer, the multiplexer that is outside the DMA controller.
destination peripheral of the transfer, CPU software, or from
Channel priority: A channel is assigned a priority
another peripheral. Triggers provide Active/Sleep
(CHi_CTL.PRIO) between 0 and 3, with 0 being the highest
functionality and are not available in Deep Sleep and
priority and 3 being the lowest priority. Channels with the
Hibernate power modes.
same priority constitute a priority group. Priority decoding
The data transfer details are specified by a descriptor. determines the highest priority pending channel, which is
Among other things, this descriptor specifies: determined as follows.
■ The source and destination address locations and the ■ The highest priority group with pending channels is
size of the transfer. identified first.
■ The actions of a channel; for example, generation of ■ Within this priority group, round-robin arbitration is
output triggers and interrupts. See the Interrupts chapter applied.
on page 56 for more details.
Channel state: At any given time, one channel actively
■ Data transfer types can be single, 1D, or 2D as defined performs a data transfer. This channel is called the active
in the descriptor structure. These types define the channel. A channel can be in one of four channel states.
address sequences generated for source and The active channel in a DW controller can be determined by
destination. 1D and 2D transfers are used for “scatter reading the DWx_STATUS[ACTIVE] and
gather” and other useful transfer operations. DWx.STATUS[CH_IDX].
Pending state of a channel is determined by reading the
10.3 Channels DW_CH_STRUCT_CH_STATUS[PENDING] associated
with that channel. If a channel is enabled and is not in the
The DMA controller supports multiple independent data Pending or Active state, then it is considered blocked.
transfers that are managed by a channel. Each channel
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 92
DMA Controller (DW)
The data transfer associated with a trigger is made up of event that will trigger the interrupt for the channel. In
one or more ‘atomic transfers’ or ‘single transfers’; see addition each DMA channel has INTR, INTR_SET,
Table 10-2 for a better understanding. A single trigger could INTR_MASK, and INTR_MASKED registers to control their
be configured to transfer multiple “single transfers”. respective interrupt lines. INTR_MASK can be used to mask
the interrupt from the DMA channel. The INTR and
A channel can be marked preemptable
INTR_SET can be used to clear and set the interrupt,
(CHi_CTL.PREEMPTABLE). If preemptable, and there is a
respectively, for debug purposes.
higher priority pending channel, then that higher priority
channel can preempt the current channel between single The DW_CH_STRUCT_CH_STATUS[INTR_CAUSE] field
transfers. If a channel is preempted, the existing single provides the user a means to determine the cause of the
transfer is completed; the current channel goes to pending interrupt being generated. The following are different values
state and the higher priority channel is serviced. On for this register:
completion of the higher priority channel's transfer, the ■ 0: No interrupt generated
pending channel is resumed. Note that preemption has an
■ 1: Interrupt based on transfer completion configured
impact on the data transfer rates of the channel being
based on INTR_TYPE field in the descriptor
preempted. Refer to “DMA Performance” on page 100 for
these performance implications. ■ 2: Source bus error
■ 3: Destination bus error
A channel has two access control attributes that are used by
the shared memory protection units (SMPUs) and peripheral ■ 4: Misaligned source address
protection units (PPUs) for access control. These fields are ■ 5: Misaligned destination address
typically inherited from the master that modified the ■ 6: Current descriptor pointer is null
channel’s control register.
■ 7: Active channel is in disabled state
■ The Privileged Mode (CHi_CTL.P) attribute can be set to
privileged or user. ■ 8: Descriptor bus error
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 93
DMA Controller (DW)
10.4 Descriptors
The data transfer between a source and destination in a channel is configured using a descriptor. Descriptors are stored in
memory. The descriptor pointer is specified in the DMA channel registers. The DMA controller does not modify the descriptor
and treats it as read only. A descriptor is a set of up to six 32-bit registers that contain the configuration for the transfer in the
associated channel. There are three types of descriptors.
Performs a one-dimensional “for loop”. This transfer is made up of X number of single transfers
A B
A+1 B+1
1D transfer A+2 B+2
A+X-1 B+ X-1
A+X-1 B+X-1
A+X B+X
A+X+1 B+X+1
2nd 1D transfer A+X+2 B+X+2
th
Y 1D transfer
A+(X*Y)-1 B+X*Y-1
This performs a one-dimensional “for loop” similar to the 1D transfer. However, the source data is not trans-
ferred to a destination. Instead, a CRC is calculated over the source data. The CRC configuration is provided
through a set of registers that is shared by all DMA channels. The assumption is that the DMA channels use
CRC transfer
the CRC functionality mutually exclusively in time. These registers are: CRC_CTL, CRC_DATA_CTL,
CRC_POL_CTL, CRC_LFSR_CTL, CRC_REM_CTL, and CRC_REM_RESULT. Note that the CRC configu-
ration is the same as the Crypto CRC configuration.
Single Transfer:
The following pseudo code illustrates a single transfer.
// DST_ADDR is a pointer to an object of type defined by DST_TRANSFER_SIZE
// SRC_ADDR is a pointer to an object of type defined by SRC_TRANSFER_SIZE
// t_DATA_SIZE is the type associated with the DATA_SIZE
DST_ADDR[0] = (t_DATA_SIZE) SRC_ADDR[0];
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 94
DMA Controller (DW)
1D Transfer:
The following pseudo code illustrates a 1D transfer. Note that the 1D transfer is represented by a loop with each iteration
executing a single transfer.
// DST_ADDR is a pointer to an object of type defined by DST_TRANSFER_SIZE
// SRC_ADDR is a pointer to an object of type defined by SRC_TRANSFER_SIZE
// t_DATA_SIZE is the type associated with the DATA_SIZE
for (X_IDX = 0; X_IDX <= X_COUNT; X_IDX++) {
DST_ADDR[X_IDX * DST_X_INCR] =
(t_DATA_SIZE) SRC_ADDR[X_IDX * SRC_X_INCR];
}
2D Transfer:
The following pseudo code illustrates a 2D transfer. Note that the 2D transfer is represented by a loop with each iteration
executing an inner loop, which is the 1D transfer.
// DST_ADDR is a pointer to an object of type defined by DST_TRANSFER_SIZE
// SRC_ADDR is a pointer to an object of type defined by SRC_TRANSFER_SIZE
// t_DATA_SIZE is the type associated with the DATA_SIZE
for (Y_IDX = 0; Y_IDX <= Y_COUNT; Y_IDX++) {
for (X_IDX = 0; X_IDX <= X_COUNT; X_IDX++) {
DST_ADDR[X_IDX * DST_X_INCR + Y_IDX * DST_Y_INCR ] =
(t_DATA_SIZE) SRC_ADDR[X_IDX * SRC_X_INCR + Y_IDX * SRC_Y_INCR];
}
}
CRC Transfer:
The following pseudo code illustrates CRC transfer.
// DST_ADDR is a pointer to an address location where the calculated CRC is stored.
// SRC_ADDR is a pointer to an object of type defined by SRC_TRANSFER_SIZE
// t_DATA_SIZE is the type associated with the DATA_SIZE
CRC_STATE = CRC_LFSR_CTL;
for (X_IDX = 0; X_IDX <= X_COUNT; X_IDX++) {
Update_CRC (CRC_STATE, (t_DATA_SIZE) SRC_ADDR[X_IDX * SRC_X_INCR];
}
DST_ADDR = CRC_STATE;
The parameters in the descriptor help configure the different aspects of the transfers explained.
Figure 10-2 shows the structure of a descriptor.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 95
DMA Controller (DW)
Descriptor
DESCR_SRC
Source Address
DESCR_DST
Destination Address
DESCR_CTL
DESCR_TYPE
TR_IN_TYPE TR_OUT_TYPE
SCR_TRANSFER_SIZE DST_TRANSFER_SIZE
DATA_SIZE
INTR_TYPE CH_DISABLE WAIT_FOR_DEACT
X Size
SRC_X_INR DST_X_INCR
Y Size
SRC_Y_INR DST_Y_INCR
DESCR_NEXT_PTR
Next Descriptor Address
10.4.1 Address Configuration trigger setting will not automatically trigger the next
descriptor.
Source and Destination Address: The source and
■ Type 3: A trigger results in execution of the current
destination addresses are set in the respective registers in
descriptor and also triggering the next descriptor. The
the descriptor. These set the base addresses for the source
execution of the next descriptor from this point will be
and destination location for the transfer. In case the
determined by the TR_IN_TYPE setting of the next
descriptor is configured to transfer a single element, this
descriptor.
field holds the source/destination address of the data
element. If the descriptor is configured to transfer multiple Trigger out type, TR_OUT_TYPE: This field determines
elements with source address or destination address or both what completion event will generate the output trigger
in an incremental mode, this field will hold the address of the signal. This field can be configured to one of the following
first element that is transferred. modes:
DESCR_TYPE: This field configures whether the descriptor ■ Type 0: Generates a trigger output for completion of
has a single, 1D, or 2D type. every single element transfer.
■ Type 1: Generates a trigger output for completion of a
Trigger input type, TR_IN_TYPE: This field determines
1D transfer
how the DMA engine responds to input trigger signal. This
field can be configured for one of the following modes: ■ Type 2: Generates a trigger output for completion of the
current descriptor. This trigger output is generated
■ Type 0: A trigger results in execution of a single transfer.
independent of the state of the DESCR_NEXT_PTR.
Regardless of the DESCR_TYPE setting, a trigger input
will trigger only a single element transfer. For example, ■ Type 3: Generates a trigger output on completion of the
in a 1D transfer, the DMA will transfer only one data current descriptor, when the current descriptor is the last
element in every trigger. descriptor in the descriptor chain. This means a trigger is
generated when the descriptor execution is complete
■ Type 1: A trigger results in the execution of a single 1D
and the DESCR_NEXT_PTR is ‘0’.
transfer. If the DESCR_TYPE was set to single transfer,
the trigger signal will trigger the single transfer specified Interrupt Type, INTR_TYPE: This field determines which
by the descriptor. For a DESCR_TYPE set to 1D completion event will generate the output interrupt signal.
transfer, the trigger signal will trigger the entire 1D This field can be configured to one of the following modes:
transfer configured in the descriptor. For a 2D transfer, ■ Type 0: Generates an interrupt output for completion of
the trigger signal will trigger only a single iteration of the every single element transfer.
Y loop transfer.
■ Type 1: Generates an interrupt output for completion of a
■ Type 2: A trigger results in execution of the current 1-D transfer.
descriptor. Regardless of DESCR_TYPE, the trigger will
execute the entire descriptor. If there was a next
descriptor configured for the current descriptor, this
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 96
DMA Controller (DW)
■ Type 2: Generates an interrupt output for completion of that has a trigger going to the DMA when its not full.
the current descriptor. This interrupt output is generated Free space in FIFO will trigger a DMA transfer to the
independent of the state of the DESCR_NEXT_PTR. FIFO, which in turn will deactivate the trigger. However,
■ Type 3: Generates an interrupt output on completion of there can be a delay in this deactivation by the agent,
the current descriptor, when the current descriptor is the which may cause the DMA to have initiated another
last descriptor in the descriptor chain. This means an transfer that can cause a FIFO overflow. This can be
interrupt is generated when the descriptor execution is avoided by using the four or 16 clock cycle delays.
complete and the DESCR_NEXT_PTR is ‘0’. X Count: This field determines the number of single
WAIT_FOR_DEACT: When the DMA transfer based on the element transfers present in the X loop (inner loop). This
TR_IN_TYPE is completed, the data transfer engine checks field is valid when the DESCR_TYPE is set to 1D or 2D
the state of trigger deactivation. The data transfer on the transfer.
second trigger is initiated only after deactivation of the first. Source Address Increment (X loop) (SCR_X_INCR): This
The WAIT_FOR_DEACT parameter will determine when the field configures the index by which the source address is to
trigger signal is considered deactivated. The first DMA be incremented for every iteration in an X loop. The field is
transfer is activated when the trigger is activated, but the expressed in multiples of SRC_TRANSFER_SIZE. This field
transfer is not considered complete until the trigger is is a signed number and hence may be decrementing or
deactivated. This field is used to synchronize the controller’s incrementing. If the source address does not need to be
data transfers with the agent that generated the trigger. This incremented, you can set this parameter to zero.
field has four settings:
Destination Address Increment (X loop) (DST_X_INCR):
■ 0 – Pulse Trigger: Do not wait for deactivation. When a
This field configures the index by which the destination
trigger is detected, the transfer is initiated. After
address is to be incremented, for every iteration in an X
completing the transfer, if the trigger is still active then it
loop. The field is expressed in multiples of
is considered as another trigger and the subsequent
DST_TRANSFER_SIZE. This field is a signed number and
transfer is initiated immediately.
hence may be decrementing or incrementing. If the
■ 1 – Level-sensitive waits four slow clock cycles after the destination address does not need to be incremented, you
transfer to consider as a deactivation. When a trigger is can set this parameter to zero.
detected, the transfer is initiated. After completing the
transfer, if the trigger is still active then it is considered Y Count: This field determines the number of 1-D transfers
as another trigger after waiting for four cycles. Then, a present in the Y loop (outer loop). This field is valid when the
subsequent transfer is initiated. The transfer DESCR_TYPE is set to 2-D transfer.
corresponding to the trigger is considered complete only Source Address Increment (Y loop) (SCR_Y_INCR): This
at the end of the four additional cycles. Even trigger field configures the index by which the source address is to
output events will be affected based on this delay. This be incremented, for every iteration in a Y loop. The field is
parameter adds a four-cycle delay in each trigger expressed in multiples of SRC_TRANSFER_SIZE. This field
transaction and hence affects throughput. is a signed number and hence may be decrementing or
■ 2 – Level-sensitive waits 16 slow clock cycles after the incrementing. If the source address does not need to be
transfer to consider as a deactivation. When a trigger is incremented, you can set this parameter to zero.
detected, the transfer is initiated. After completing the
transfer, if the trigger is still active then it is considered Destination Address Increment (X loop) (DST_Y_INCR):
as another trigger after waiting for 16 cycles. Then, a This field configures the index by which the destination
subsequent transfer is initiated. The transfer address is to be incremented, for every iteration in a Y loop.
corresponding to the trigger is considered complete only The field is expressed in multiples of
at the end of the 16 additional cycles. Even trigger DST_TRANSFER_SIZE. This field is a signed number and
output events will be affected based on this delay. This hence may be decrementing or incrementing. If the
parameter adds a 16-cycle delay in each trigger destination address does not need to be incremented, you
transaction and hence affects throughput. can set this parameter to zero.
■ 3 – Pulse trigger waits indefinitely for deactivation. The Channel Disable (CH_DISABLE): This field specifies
DMA transfer is initiated after the trigger signal whether the channel is disabled or not after completion of
deactivates. The next transfer is initiated only if the the current descriptor (independent of the value of the
trigger goes low and then high again. A trigger signal DESCR_NEXT_PTR). A disabled channel will ignore its
that remains active or does not transition to zero input triggers.
between two transaction will simply stall the DMA
channel. 10.4.2 Transfer Size
The WAIT_FOR_DEACT field is used in a system to
The word width for a transfer can be configured using the
cater to delayed response of other parts of the system to
transfer/data size parameter in the descriptor. The settings
actions of the DMA. Consider an example of a TX FIFO
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 97
DMA Controller (DW)
are diversified into source transfer size, destination transfer be set to 32 bit to match the width of the PWM register,
size, and data size. The data size parameter (DATA_SIZE) because the peripheral register width for the TCPWM block
sets the width of the bus for the transfer. The source and (and most PSoC 6 MCU peripherals) is always 32-bit wide.
destination transfer sizes set by SCR_TRANSFER_SIZE However, in this example the DATA_SIZE for the destination
and DST_TRANSFER_SIZE can have a value either the may still be set to 16 bit because the 16-bit PWM only uses
DATA_SIZE or 32 bit. DATA_SIZE can have a 32-bit, 16-bit, two bytes of data. SRAM and Flash are 8-bit, 16-bit, or 32-
or 8-bit setting. bit addressable and can use any source and destination
transfer sizes to match the needs of the application.
The source and destination transfer size for the DMA must
match the addressable width of the source and destination, Table 10-3 summarizes the possible combinations of the
regardless of the width of data that must be moved. The transfer size settings and its description.
DATA_SIZE parameter will correspond to the width of the
actual data. For example, if a 16-bit PWM is used as a
destination for DMA data, the DST_TRANSFER_SIZE must
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 98
DMA Controller (DW)
DMA
Descriptors
Descriptors
Descriptors
Memory
10.5.1 Trigger Selection highest priority activated channel. It is also responsible for
reading the channel descriptor from memory.
Trigger signals can be generated from different sections of
the chips. A trigger multiplexer block helps route these Master I/F is an AHB-Lite bus master that allows the DMA
trigger signals to the destination. The DMA is one such controller to initiate AHB-Lite data transfers to the source
destination of triggers. The trigger multiplexer block is and destination locations as well as to read the descriptor
outside the DMA block and is discussed in the Trigger from memory.
Multiplexer Block chapter on page 294. Slave I/F is an AHB-Lite bus slave that allows the main CPU
to access DMA controller control/status registers.
10.5.2 Pending Triggers
Pending triggers keep track of activated triggers by locally 10.5.3 Output Triggers
storing them in pending bits. This is essential because Each channel has an output trigger. This trigger is high for
multiple channel triggers may be activated simultaneously, two slow clock cycles. The trigger is generated on the
whereas only one channel can be served by the data completion of a data transfer. At the system level, these
transfer engine at a time. This component enables the use output triggers can be connected to the trigger multiplexer
of both level-sensitive (high/‘1’) and pulse-sensitive (two component. This connection allows a DMA controller output
high/‘1’ clk_slow cycles) triggers. trigger to be connected to a DMA controller input trigger. In
■ Level-sensitive triggers are associated with a certain other words, the completion of a transfer in one channel can
state, for example, a FIFO being full. These triggers activate another channel or even reactivate the same
remain active as long as the state is maintained. It is not channel.
required to track pending level-sensitive triggers in the
DMA output triggers routing to other DMA channels or other
DMA controller because the triggers are maintained
peripheral trigger inputs is achieved using the trigger
outside the controller.
multiplexer. Refer to the Trigger Multiplexer Block chapter
■ Pulse-sensitive triggers are associated with a certain on page 294.
event, for example, sample has become available. It is
essential to track these triggers in the DMA controller
because the trigger pulse may disappear before it is
10.5.4 Status registers
served by the data transfer engine. Pulse triggers should The controller status register (DWx_STATUS) contains the
be high/‘1’ for two clk_slow cycles. following information.
The priority decoder determines the highest priority ■ ACTIVE – Active channel present, yes/no.
pending channel. ■ P – Active channel's access control user/privileged
The data transfer engine is responsible for the data ■ NS – Active channel's access control secure/non-secure
transfer from a source location to a destination location. ■ CH_IDX – Active channel index if there is an active
When idle, the data transfer engine is ready to accept the channel
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 99
DMA Controller (DW)
For subsequent transfers on a preloaded descriptor, cycles are needed only to move the data from source to destination.
Therefore, transfers such as 1-D and 2-D, which are not preempted, incurs all the cycles only for the first transfer; subsequent
transfers will cost three cycles.
Based on the configuration of TRIG_IN_TYPE, the trigger synchronization cycles may be incurred for each single element
transfer or for each 1-D transfer.
The descriptor is four words long for a single transfer type, five words for 1-D transfer, and six words for a 2-D transfer. Hence,
the number of cycles needed to fetch a descriptor will vary based on its type.
Another factor to note is the latency in data or descriptor fetch due to wait states or bus latency.
The DMA performance for different types of transfers can be summarized as follows.
■ Single transfer
❐ 14 cycles per transfer + latency due to wait states or bus latency
■ 1D transfer
❐ To transfer n data elements
Number of cycles = 12 + n * 3 + m
m is the total number of wait states seen by DMA while loading or storing descriptors or data. An additional cycle is
required for the first transfer, to load the X-Loop configuration register.
■ 2D transfer
❐ If the 2 D transfer is transferring n elements then
Number of cycles = 13 + n * 3 + m
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 100
DMA Controller (DW)
m is total number of wait states seen by DMA while loading or storing descriptors or data. Two additional cycles are
required for the first transfer, to load the X-loop and Y-Loop configuration register.
Note: Descriptors in memory and memory wait states will also affect the descriptor load delay.
■ Wait states: Memory accesses can have a wait state associated with them. These wait states need to be accounted into
the calculation of throughput.
■ Channel arbitration: Some time channels are not immediately made active after reception of trigger. This is due to other
active channels in the system. This can lead to multiple cycles being lost before the channel is even made active.
■ Preemption: The choice of making a DMA channel preemptable impacts its performance. This is because every time a
channel is preempted:
❐ The channel is in a pending state for as long as the higher priority channel is running
❐ On resumption, the channel descriptor needs to be fetched again. This is additional cycles for every resume. So if
there are a large number of high-priority channels, making a low-priority channel preemptable can have adverse
effects on its throughput. On the other hand, if there is a low-priority channel that is transferring a large amount of data,
then not making it preemptable can starve other high-priority channels for too long.
Sometimes, users can also distribute channels across multiple DW blocks to avoid conditions of preemption and deal with
the contention at the bus arbitration level.
■ Bus arbitration: Several bus masters access the bus, including the CPU cores and multiple DMA (DW) and DMAC. This
makes any access to data movement over the bus subject to arbitration with other masters. Actions such as fetching the
descriptor or data can be stalled by arbitration. The arbitration of the bus is based on the arbitration scheme configured in
PROT_SMPU_MSx_CTL[PRIO]
■ Transfer width: The width of the transfer configured by the Data_size parameter in the descriptor is important in the
transfer throughput calculation. 32-bit transfers are four times faster than 8-bit transfers.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 101
11. DMAC Controller (DMAC)
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The DMAC transfers data to and from memory, peripherals, and registers. These transfers occur independent from the CPU.
The DMAC can be configured to perform multiple independent data transfers. All data transfers are managed by a channel.
There can be up to 32 channels in the DMAC. The number of channels in the DMAC controller can vary with devices. Refer to
the PSoC 61 datasheet/PSoC 62 datasheet for the number of channels supported in the device. A channel has an associated
priority; channels are arbitrated according to their priority. The main difference between the DMA (DW) and DMAC relate to
their usage. The DMA (DW) is meant as a small data size, transactional DMA, which would typically be used to transfer bytes
between peripherals such as, from ADC to RAM. Using the DMA (DW) for large transaction is expensive on a system due to
its relatively low performance. The DMAC is a transitional DMA. It is more efficient than the DMA (DW) and should be used to
transfer large amounts of data. The DMAC has dedicated channel logic for all channels. Furthermore, the DMAC also
includes a 12-byte FIFO for temporary data storage. This results in increased memory bandwidth for the DMAC. The DMAC
also supports an additional transfer mode called memory copy and scatter transfer.
11.1 Features
The DMAC controller has the following features:
■ Supports up to 32 channels per DMAC controller; see the PSoC 61 datasheet/PSoC 62 datasheet for details
■ Four levels of priority for each channel
■ Descriptors are defined in memory and referenced to the respective channels
■ Supports single, 1D, 2D, Memory-copy, or Scatter-transfer modes for a descriptor
■ Supports transfer of up to 2^32 data elements per descriptor
■ Configurable source and destination address increments
■ Supports 8-bit, 16-bit, and 32-bit data widths at both source and destination
■ Configurable input trigger behavior for each descriptor
■ Configurable interrupt generation in each descriptor
■ Configurable output trigger generation for each descriptor
■ Descriptors can be chained to other descriptors in memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 102
DMAC Controller (DMAC)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 103
DMAC Controller (DMAC)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 104
DMAC Controller (DMAC)
11.4 Descriptors
The data transfer between a source and destination in a channel is configured using a descriptor. Descriptors are stored in
memory. The descriptor pointer is specified in the DMAC channel registers. The DMAC controller does not modify the
descriptor and treats it as read only. A descriptor is a set of up to six 32-bit registers that contain the configuration for the
transfer in the associated channel. There are three types of descriptors.
Performs a one-dimensional “for loop”. This transfer is made up of X number of single transfers
A B
A+1 B+1
1D transfer A+2 B+2
A+X-1 B+ X-1
A+X-1 B+X-1
A+X B+X
A+X+1 B+X+1
2nd 1D transfer A+X+2 B+X+2
th
Y 1D transfer
A+(X*Y)-1 B+X*Y-1
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 105
DMAC Controller (DMAC)
Single Transfer:
The following pseudo code illustrates a single transfer.
// DST_ADDR is a pointer to an object of type defined by DST_TRANSFER_SIZE
// SRC_ADDR is a pointer to an object of type defined by SRC_TRANSFER_SIZE
// t_DATA_SIZE is the type associated with the DATA_SIZE
DST_ADDR[0] = (t_DATA_SIZE) SRC_ADDR[0];
1D Transfer:
The following pseudo code illustrates a 1D transfer. Note that the 1D transfer is represented by a loop with each iteration
executing a single transfer.
// DST_ADDR is a pointer to an object of type defined by DST_TRANSFER_SIZE
// SRC_ADDR is a pointer to an object of type defined by SRC_TRANSFER_SIZE
// t_DATA_SIZE is the type associated with the DATA_SIZE
for (X_IDX = 0; X_IDX <= X_COUNT; X_IDX++) {
DST_ADDR[X_IDX * DST_X_INCR] =
(t_DATA_SIZE) SRC_ADDR[X_IDX * SRC_X_INCR];
}
2D Transfer:
The following pseudo code illustrates a 2D transfer. Note that the 2D transfer is represented by a loop with each iteration
executing an inner loop, which is the 1D transfer.
// DST_ADDR is a pointer to an object of type defined by DST_TRANSFER_SIZE
// SRC_ADDR is a pointer to an object of type defined by SRC_TRANSFER_SIZE
// t_DATA_SIZE is the type associated with the DATA_SIZE
for (Y_IDX = 0; Y_IDX <= Y_COUNT; Y_IDX++) {
for (X_IDX = 0; X_IDX <= X_COUNT; X_IDX++) {
DST_ADDR[X_IDX * DST_X_INCR + Y_IDX * DST_Y_INCR ] =
(t_DATA_SIZE) SRC_ADDR[X_IDX * SRC_X_INCR + Y_IDX * SRC_Y_INCR];
}
}
Memory copy:
The following pseudo code illustrates a memory copy.
// DST_ADDR is a pointer to an object of type uint8_t
// SRC_ADDR is a pointer to an object of type uint8_t
// This transfer type uses 8-bit, 16-bit an 32-bit transfers. The HW ensures that
// alignment requirements are met.
for (X_IDX = 0; X_IDX <= X_COUNT; X_IDX++) {
DST_ADDR[X_IDX] = SRC_ADDR[X_IDX];
}
Scatter:
The following pseudo code illustrates the scatter transfer
// SRC_ADDR is a pointer to an object of type uint32_t
for (X_IDX = 0; X_IDX < X_COUNT; X_IDX += 2) {
address = SRC_ADDR[X_IDX];
data = SRC_ADDR[X_IDX + 1];
*address = data;
}
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 106
DMAC Controller (DMAC)
The parameters in the descriptor help configure the different aspects of the transfers explained.
Figure 11-2 shows the structure of a descriptor.
Figure 11-1. Descriptor Structure
Descriptor
DESCR_SRC
Source Address
DESCR_DST
Destination Address
DESCR_CTL
DESCR_TYPE
TR_IN_TYPE TR_OUT_TYPE
SCR_TRANSFER_SIZE DST_TRANSFER_SIZE
DATA_SIZE
INTR_TYPE CH_DISABLE WAIT_FOR_DEACT
X Size
SRC_X_INR DST_X_INCR
Y Size
SRC_Y_INR DST_Y_INCR
DESCR_NEXT_PTR
Next Descriptor Address
11.4.1 Address Configuration will trigger only a single element transfer. For example,
in a 1D transfer, the DMAC will transfer only one data
Source and Destination Address: The source and element in every trigger.
destination addresses are set in the respective registers in
■ Type 1: A trigger results in the execution of a single 1D
the descriptor. These set the base addresses for the source
transfer. If the DESCR_TYPE was set to single transfer,
and destination location for the transfer. In case the
the trigger signal will trigger the single transfer specified
descriptor is configured to transfer a single element, this
by the descriptor. For a DESCR_TYPE set to 1D
field holds the source/destination address of the data
transfer, the trigger signal will trigger the entire 1D
element. If the descriptor is configured to transfer multiple
transfer configured in the descriptor. For a 2D transfer,
elements with source address or destination address or both
the trigger signal will trigger only a single iteration of the
in an incremental mode, this field will hold the address of the
Y loop transfer. If the descriptor type is “memory copy”,
first element that is transferred.
the trigger results in the execution of a memory copy
DESCR_TYPE: This field configures whether the descriptor transfer.
has a single, 1D, 2D type, memory copy, or scatter transfer. ■ Type 2: A trigger results in execution of the current
Source data prefetch, DATA_PREFETCH: When enabled, descriptor. Regardless of DESCR_TYPE, the trigger will
source data transfers are initiated as soon as the channel is execute the entire descriptor. If there was a next
enabled; the current descriptor pointer is not “0” and there is descriptor configured for the current descriptor, this
space available in the channel's data FIFO. When the input trigger setting will not automatically trigger the next
trigger is activated, the trigger can initiate destination data descriptor.
transfers with data that is already in the channel's data ■ Type 3: A trigger results in execution of the current
FIFO. This effectively shortens the initial delay of the data descriptor and also triggering the next descriptor. The
transfer. execution of the next descriptor from this point will be
determined by the TR_IN_TYPE setting of the next
Note: Data prefetch should be used with care to ensure that descriptor.
data coherency is guaranteed and that prefetches do not
cause undesired side effects.
Trigger input type, TR_IN_TYPE: This field determines
how the DMAC engine responds to input trigger signal. This
field can be configured for one of the following modes:
■ Type 0: A trigger results in execution of a single transfer.
Regardless of the DESCR_TYPE setting, a trigger input
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 107
DMAC Controller (DMAC)
Trigger out type, TR_OUT_TYPE: This field determines ■ 2 – Level-sensitive waits 16 SYSCLK cycles: The DMAC
what completion event will generate the output trigger transfer is initiated if the input trigger is seen to be
signal. This field can be configured to one of the following activated after 16 clock cycles.
modes: ■ 3 – Pulse trigger waits indefinitely for deactivation. The
■ Type 0: Generates a trigger output for completion of DMAC transfer is initiated after the trigger signal
every single element transfer. deactivates. The next transfer is initiated only if the
■ Type 1: Generates a trigger output for completion of a trigger goes low and then high again.
1D transfer. If the descriptor type is “memory copy”, the X Size: This field determines the number of single element
output trigger is generated after the execution of a transfers present in the X loop (inner loop). This field is valid
memory copy transfer. If the descriptor type is “scatter”, when the DESCR_TYPE is set to 1D or 2D transfer. For the
the output trigger is generated after the execution of a “memory copy” descriptor type, (X_COUNT + 1) is the
scatter transfer. number of transferred Bytes. For the “scatter” descriptor
■ Type 2: Generates a trigger output for completion of the type, ceiling (X_COUNT/2) is the number of (address, write
current descriptor. This trigger output is generated data) initialization pairs processed.
independent of the state of the DESCR_NEXT_PTR.
Source Address Increment (X loop) (SCR_X_INCR): This
■ Type 3: Generates a trigger output on completion of the field configures the index by which the source address is to
current descriptor, when the current descriptor is the last be incremented for every iteration in an X loop. The field is
descriptor in the descriptor chain. This means a trigger is expressed in multiples of SRC_TRANSFER_SIZE. This field
generated when the descriptor execution is complete is a signed number and hence may be decrementing or
and the DESCR_NEXT_PTR is ‘0’. incrementing. If the source address does not need to be
Interrupt Type, INTR_TYPE: This field determines which incremented, you can set this parameter to zero.
completion event will generate the output interrupt signal. Destination Address Increment (X loop) (DST_X_INCR):
This field can be configured to one of the following modes: This field configures the index by which the destination
■ Type 0: Generates an interrupt output for completion of address is to be incremented, for every iteration in an X
every single element transfer. loop. The field is expressed in multiples of
■ Type 1: Generates an interrupt output for completion of a DST_TRANSFER_SIZE. This field is a signed number and
1-D transfer. If the descriptor type is “memory copy”, the hence may be decrementing or incrementing. If the
interrupt is generated after the execution of a memory destination address does not need to be incremented, you
copy transfer. If the descriptor type is “scatter” the can set this parameter to zero.
interrupt is generated after the execution of a scatter Y Size: This field determines the number of 1-D transfers
transfer. present in the Y loop (outer loop). This field is valid when the
■ Type 2: Generates an interrupt output for completion of DESCR_TYPE is set to 2-D transfer.
the current descriptor. This interrupt output is generated
Source Address Increment (Y loop) (SCR_Y_INCR): This
independent of the state of the DESCR_NEXT_PTR.
field configures the index by which the source address is to
■ Type 3: Generates an interrupt output on completion of be incremented, for every iteration in a Y loop. The field is
the current descriptor, when the current descriptor is the expressed in multiples of SRC_TRANSFER_SIZE. This field
last descriptor in the descriptor chain. This means an is a signed number and hence may be decrementing or
interrupt is generated when the descriptor execution is incrementing. If the source address does not need to be
complete and the DESCR_NEXT_PTR is ‘0’. incremented, you can set this parameter to zero.
WAIT_FOR_DEACT: When the DMAC transfer based on Destination Address Increment (X loop) (DST_Y_INCR):
the TR_IN_TYPE is completed, the data transfer engine This field configures the index by which the destination
checks the state of trigger deactivation. The data transfer on address is to be incremented, for every iteration in a Y loop.
the second trigger is initiated only after deactivation of the The field is expressed in multiples of
first. The WAIT_FOR_DEACT parameter will determine DST_TRANSFER_SIZE. This field is a signed number and
when the trigger signal is considered deactivated. The first hence may be decrementing or incrementing. If the
DMAC transfer is activated when the trigger is activated, but destination address does not need to be incremented, you
the transfer is not considered complete until the trigger is can set this parameter to zero.
deactivated. This field is used to synchronize the controller’s
data transfers with the agent that generated the trigger. This Channel Disable (CH_DISABLE): This field specifies
field has four settings: whether the channel is disabled or not after completion of
the current descriptor (independent of the value of the
■ 0 – Pulse Trigger: Do not wait for deactivation.
DESCR_NEXT_PTR). A disabled channel will ignore its
■ 1 – Level-sensitive waits four SYSCLK cycles: The input triggers.
DMAC trigger is deactivated after the level trigger signal
is detected for four cycles.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 108
DMAC Controller (DMAC)
11.4.2 Transfer Size actual data. For example, if a 16-bit PWM is used as a
destination for DMAC data, the DST_TRANSFER_SIZE
The word width for a transfer can be configured using the must be set to 32 bit to match the width of the PWM register,
transfer/data size parameter in the descriptor. The settings because the peripheral register width for the TCPWM block
are diversified into source transfer size, destination transfer (and most PSoC 6 MCU peripherals) is always 32-bit wide.
size, and data size. The data size parameter (DATA_SIZE) However, in this example the DATA_SIZE for the destination
sets the width of the bus for the transfer. The source and may still be set to 16 bit because the 16-bit PWM only uses
destination transfer sizes set by SCR_TRANSFER_SIZE two bytes of data. SRAM and Flash are 8-bit, 16-bit, or 32-
and DST_TRANSFER_SIZE can have a value either the bit addressable and can use any source and destination
DATA_SIZE or 32 bit. DATA_SIZE can have a 32-bit, 16-bit, transfer sizes to match the needs of the application.
or 8-bit setting.
Table 11-2 summarizes the possible combinations of the
The source and destination transfer size for the DMAC must transfer size settings and its description.
match the addressable width of the source and destination,
regardless of the width of data that must be moved. The
DATA_SIZE parameter will correspond to the width of the
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 109
DMAC Controller (DMAC)
11.5.1 Trigger Selection Slave I/F is an AHB-Lite bus slave that allows the main CPU
to access DMAC controller control/status registers.
Trigger signals can be generated from different sections of
the chips. A trigger multiplexer block helps route these
11.5.3 Output Triggers
trigger signals to the destination. The DMAC is one such
destination of triggers. The trigger multiplexer block is Each channel has an output trigger. This trigger is high for
outside the DMAC block and is discussed in the Trigger two slow clock cycles. The trigger is generated on the
Multiplexer Block chapter on page 294. completion of a data transfer. At the system level, these
output triggers can be connected to the trigger multiplexer
11.5.2 Channel Logic component. This connection allows a DMAC controller
output trigger to be connected to a DMAC controller input
The channel logic keeps track of pending triggers for each trigger. In other words, the completion of a transfer in one
channel and initiates the transfer corresponding to the active channel can activate another channel or even reactivate the
descriptor, based on availability of the bus and arbitration by same channel.
priority decoder.
DMAC output triggers routing to other DMAC channels or
The priority decoder determines the highest priority other peripheral trigger inputs is achieved using the trigger
pending channel. multiplexer. Refer to the Trigger Multiplexer Block chapter
Master I/F is an AHB-Lite bus master that allows the DMAC on page 294.
controller to initiate AHB-Lite data transfers to the source
and destination locations as well as to read the descriptor
from memory.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 110
12. Cryptographic Function Block (Crypto)
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The Cryptographic block (Crypto) provides hardware implementation and acceleration of cryptographic functions.
Implementation in hardware takes less time and energy than the equivalent firmware implementation. In addition, the block
provides True Random Number generation functionality in silicon, which is not available in firmware.
12.1 Features
■ Advanced encryption standard (AES)
■ Data Encryption and Triple Data Encryption Standards (DES, TDES)
■ Secure Hash Algorithm (SHA)
■ Cyclic redundancy checking (CRC)
■ Pseudo random number generator (PRNG)
■ True random number generator (TRNG)
■ Vector unit (VU) to support asymmetric key cryptography, such as RSA and ECC.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 111
Cryptographic Function Block (Crypto)
12.2 Architecture
The following figure gives an overview of the cryptographic block.
Figure 12-1. Crypto Block Diagram
AHB-Lite infrastructure
AHB-Lite Master
AHB-Lite Slave Interface
Interface
Memory Buffer
Control (up to 16KB)
Interrupt Instruction & clk_sys
FIFO Status
(MMIO)
Memory interface
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 112
Cryptographic Function Block (Crypto)
12.3.1 Instructions
An instruction consists of a sequence of one, two, or three instruction words. Most instructions are encoded by a single
instruction word.
The instruction FIFO can hold up to eight 32-bit instruction words. A CPU writes instruction words to the instruction FIFO
(INSTR_FF_WR register) and the crypto block decodes the instruction words to execute the instructions.
INSTR_FF_STATUS.USED specifies how many of the eight instruction FIFO entries are used. The instruction FIFO
decouples the progress of CPU execution from the crypto block execution: the CPU can write new instruction words to the
FIFO, while the block executes previously written instructions.
There are multiple interrupt causes associated with the instruction FIFO and the instruction decoder:
■ The INTR.INSTR_FF_OVERFLOW interrupt cause is activated on a write to a full instruction FIFO.
■ THE INTR.INSTR_FF_LEVEL interrupt cause is activated when the number of used FIFO entries
(INSTR_FF_STATUS.USED) is less than a specified number of FIFO entries (INSTR_FF_CTL.LEVEL).
■ The INTR.INSTR_OPC_ERROR interrupt cause is activated when an instruction's operation code is not defined.
■ The INTR.INSTR_CC_ERROR interrupt cause is activated when a vector unit instruction has an undefined condition
code.
Most instructions perform specific cryptographic functionality. For example, the AES instruction performs and Advanced
Encryption Standard (AES) block cipher operation. Some instructions perform more generic functionality: most generic
instructions move operand data between different locations. Higher level symmetric cipher and hash functionality is
implemented using a combination of cryptographic instructions and generic instructions. Higher level asymmetric cipher
functionality is implemented using a set of vector unit (VU) instructions.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 113
Cryptographic Function Block (Crypto)
Both the block’s external system memory and internal memory buffer are accessed through the same memory interface
component. The access address specifies if the access is to the system memory or the internal memory buffer (also see
VU_CTL.ADDR[31:14]).
External bus masters can access both the system memory and the crypto’s internal memory. The external bus masters
access the internal memory through the slave bus interface.
Instruction FIFO. For some instructions, immediate operand data is provided by the instruction words. The limited 32-bit
instruction words only allow for limited immediate operand data.
Load and store FIFOs. Most instructions have stream-like operand data: sequences of bytes that are specified by the access
address of the start byte. The two load FIFOs provide access to source operand data and the single store FIFO provides
access to destination operand data. Typically, vector unit instruction operand data is “streamed” from the crypto block memory
buffer.
Register buffer. Most symmetric and hash cryptographic instructions benefit from a large (2048-bit) register buffer. This
register buffer provides access flexibility that is not provided by the load and store FIFOs. The register buffer is shared by
different instructions to amortize its cost (silicon area). After an Active reset or a crypto block reset (CTL.ENABLED), the
register buffer is set to ‘0’.
Vector unit register file. Most vector unit instructions perform large integer arithmetic functionality. For example, the VU
ADD instruction can add two 4096-bit numbers. Typically, operand data is “streamed” from the memory buffer. In addition, a
vector unit register file with sixteen registers is provided. Each register specifies the location of a number (start word access
address) and the size of the number (the size is in bits).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 114
Cryptographic Function Block (Crypto)
The status of the load and store FIFOs is provided through the LOAD0_FF_STATUS, LOAD1_FF_STATUS, and
STORE_FF_STATUS registers.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 115
Cryptographic Function Block (Crypto)
Some instructions work on the complete register buffer and some instructions work on 128-bit subpartitions.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 116
Cryptographic Function Block (Crypto)
Some instructions work on (up to) 128-bit subpartitions or blocks. In addition, these instructions can work on the load and
store FIFOs. The instructions' source and destination operand identifiers are encoded as follows:
■ 0: block0[127:0] = reg_buff[0*128+127:0*128]
■ 1: block1[127:0] = reg_buff[1*128+127:1*128]
■ 2: block2[127:0] = reg_buff[2*128+127:2*128]
■ 3: block3[127:0] = reg_buff[3*128+127:3*128]
■ 4: block4[127:0] = reg_buff[4*128+127:4*128]
■ 5: block5[127:0] = reg_buff[5*128+127:5*128]
■ 6: block6[127:0] = reg_buff[6*128+127:6*128]
■ 7: block7[127:0] = reg_buff[7*128+127:7*128]
■ 8: load FIFO 0
■ 9: load FIFO 1
■ 12: store FIFO
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 117
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 118
Cryptographic Function Block (Crypto)
3: return block3[127:0];
4: return block4[127:0];
5: return block5[127:0];
6: return block6[127:0];
7: return block7[127:0];
default: return GetFifoData (src, size);
}
}
The SHA1 instruction supports a single algorithm with a specific message digest size. The SHA2_256 and SHA2_512
instructions support multiple algorithms with different message digest sizes.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 119
Cryptographic Function Block (Crypto)
A SHA algorithm calculates a fixed-length hash value from a variable length message. The hash value is used to produce a
message digest or signature. It is computationally impossible to change the message without changing the hash value. The
algorithm is stateless: a given message always produces the same hash value. To prevent “replay attacks”, a counter may be
included in the message.
The variable length message must be preprocessed: a ‘1’ bit must be appended to the message followed by ‘0’s and a bit size
field. The preprocessed message consists of an integer multiple of 512 bit or 1024 bit blocks. The SHA component processes
a single block at a time:
■ The first SHA instruction on the first message block uses an initial hash value as defined by the standard (each SHA
algorithm has a specific initial hash value).
■ Subsequent SHA instructions on successive message blocks use the produced hash value of the previous SHA
operation.
The SHA instruction of the last message block produces the final hash value. The message digest is a subset of this final
hash value.
The SHA instructions do not perform the following functionality:
■ Preprocessing of a message.
■ Initialization of the register buffer with the algorithm’s specific initial hash value.
■ Copy the algorithm’s message digest to memory.
Software is required to preprocess the message. The FIFO_START instruction can be used to load (load FIFO) the register
buffer with the initial hash value and to store (store FIFO) the message digest.
A SHA instruction uses “round weights” that are derived from the message block. Each SHA round uses a dedicated round
weight. The “round weights” are derived on-the-fly (a new round weight is calculated when needed, and replaces a round
weight from a previous round). The following table provides the number of rounds.
Instruction Rounds
SHA1 80
SHA2_256 64
SHA2_512 80
The instructions use register buffer operands. Specifically, the instructions use reg_buff[2047:0]:
■ reg_buff[1023:0] is used for the round weights. Before an instruction, this region is written with the message block. The
SHA1 and SHA2_256 instructions use reg_buff[511:0] and the SHA2_512 instruction uses reg_buff[1023:0].
■ reg_buff[1535:1024] is used for the hash value. Before the first SHA instruction, this region is written with the algorithm’s
initial hash value. The algorithms with hash values smaller than 512 bits only use the lower bits of this region.
■ reg_buff[2047:1536] is used as a working copy of the hash value. This working copy is updated during the SHA rounds
and copied to reg_buff[1535:1024] at the end of the instruction.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 120
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 121
Cryptographic Function Block (Crypto)
12.4.2 SHA3
The Secure Hash Algorithm-3 (SHA-3) is a family of six algorithms:
■ SHA3-224
■ SHA3-256
■ SHA3-384
■ SHA3-512
■ SHAKE128
■ SHAKE256
Each of these algorithms relies on a specific instance of the Keccak-p[b, nr] permutation, with b = 1600 and nr = 24. The
parameter b specifies the permutation bit width (1600 bits) and the parameter nr specifies the number of permutation rounds
(24 rounds).
The permutation bit width b is the sum of:
■ The rate r, which is the number of consumed message bits or produced digest bits per application of the Keccak
permutation (SHA3 instruction).
■ The capacity c, which is defined as b-r.
All six hash algorithms are constructed by padding a message M and applying the Keccak-p[1600, 24] permutation
repeatedly. The algorithms differ in terms of the rate r and the padding.
The permutation’s rate r determines the speed of the algorithm: a higher rate requires less applications of the permutation
function (SHA3 instruction).
The permutation’s capacity c determines the security of the algorithm: a higher capacity provides higher security.
Table 12-17 lists the algorithms’ rate and capacity. In addition, it lists the size of the message digest. Note: The SHA3 hash
algorithms have fixed-length digests and the SHAKE extendable output functions have variable-length digests.
The padded message has a length that is an integer multiple of the rate r. The message is processed by repeatedly applying
the SHA3 permutation instruction. Each instruction application uses a message block of r bits. The permutation function
combines the message block of r bits with the current permutation state of b bits and calculates a new permutation state of b
bits.
■ The first SHA3 instruction on the first message block uses the first message block as the initial permutation state.
■ Subsequent SHA3 instructions on successive message blocks first combine the message block with an exclusive or
(XOR) with the current state and calculate a new permutation state.
The message digest is produced in a similar way as the message is consumed: each application of the permutation
instruction produces a message digest of r bits.
The SHA3 functionality includes a SHA3 instruction. The instruction performs a permutation on the 1600-bit state in
reg_buf[1599:0].
The instruction implements the permutation, all other functionality is implemented in software (combination of message block
with the permutation state and copying the message digest to memory).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 122
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 123
Cryptographic Function Block (Crypto)
The (T)DES instructions are used with the FF_START, FF_CONTINUE, FF_STOP, BLOCK_MOV, BLOCK_XOR, and
BLOCK_SET instructions to implement different block cipher modes, such as EBC, CBC, OFB, CTR, and CMAC.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 124
Cryptographic Function Block (Crypto)
12.6 AES
The AES functionality includes a block cipher and an inverse block cipher per the AES standard (FIPS 197):
■ The block cipher (AES instruction) encrypts a 128-bit block of plaintext data into a 128-bit block of ciphertext data.
■ The inverse block cipher (AES_INV instruction) decrypts a 128-bit block of ciphertext data into a 128-bit block of plaintext
data.
AES is a symmetric block cipher: it uses the same symmetric key for the block cipher and inverse block cipher. The (inverse)
block cipher consists of multiple rounds. Each round uses a round key that is generated from the symmetric key.
The block cipher uses the symmetric key as the (start) round key for the first cipher round. The round key for second cipher
round is generated from the symmetric key. The round key for the third cipher round is generated from the round key of the
second cipher round, and so forth. The round key for the last cipher round is generated from the round key of the one-before-
last cipher round.
The inverse block cipher uses the round key of the final block cipher round as the (start) round key for the first inverse cipher
round. The round key for the second inverse cipher round is generated from the round key of the first inverse cipher round,
and so forth. The round key for the last inverse cipher round is generated from the round key of the one-before-last inverse
cipher round. The round key of the last inverse cipher round is the same as the round key of the first cipher round (the
symmetric key).
Round key generation is independent of the plaintext data or ciphertext data. The AES instruction requires the symmetric key
as input to the block cipher. The AES_INV instruction requires the round key of the final cipher round as input to the inverse
block cipher.
The component supports 128 bit, 192 bit, and 256 bit keys. The key size is specified by AES_CTL.KEY_SIZE[1:0]. The key
size determines the number of rounds. Table 12-23 gives the number of rounds.
AES and AES_INV are the two different AES instructions; they use register buffer operands. Specifically, the instructions use
the 128-bit subpartitions block0, block1, block4, block5, block6, and block7.
■ Subpartitions block0 and block1 are used for plaintext and ciphertext data.
■ Subpartitions block4, block5, block6 and block7 are used for key information.
Unlike, for example, the BLOCK_MOV instruction, the AES and AES_INV instructions use predetermined/fixed subpartitions.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 125
Cryptographic Function Block (Crypto)
The AES and AES_INV instructions are used with the FF_START, FF_CONTINUE, FF_STOP, BLOCK_MOV, BLOCK_XOR,
and BLOCK_SET instructions to implement different block cipher modes, such as EBC, CBC, OFB, CTR, and CMAC.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 126
Cryptographic Function Block (Crypto)
12.7 CRC
The CRC functionality performs a cyclic redundancy check with a programmable polynomial of up to 32 bits.
The load FIFO 0 provides the data (and the size of the data) on which the CRC is performed. The data must be laid out in little
endian format (least significant byte of a multi-byte word should be located at the lowest memory address of the word).
CRC_DATA_CTL.DATA_XOR[7:0] specifies a byte pattern with which each data byte is XOR’d. This allows for inversion of
the data byte value.
CRC_CTL.DATA_REVERSE allows for bit reversal of the data byte (this provides support for serial interfaces that transfer
bytes in most-significant-bit first and least-significant bit first configurations).
CRC_POL_CTL.POLYNOMIAL[31:0] specifies the polynomial. The polynomial specification omits the high order bit and
should be left aligned. For example, popular 32-bit and 16-bit CRC polynomials are specified as follows:
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 127
Cryptographic Function Block (Crypto)
Single Byte
CRC_DATA_CTL.DATA_XOR[]
CRC_CTL.DATA_REVERSE
Data bit
reverse
CRC_POL_CTL.POLYNOMIAL[]
CRC
calculation
RESULT.DATA[]
(LFSR state)
CRC_REM_CTL.DATA_XOR[]
CRC_CTL.REM_REVERSE
Remainder bit
reverse
CRC_REM_RESULT.REM[]
The Linear Feedback Shift Register functionality operates on the LFSR state. It uses the programmed polynomial and
consumes a data bit for each iteration (eight iterations are performed per cycle to provide a throughput of one data byte per
cycle). Figure 12-3 illustrates the functionality for the CRC32 polynomial (x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7
+ x5 + x4 + x2 + x + 1).
Figure 12-3. CRC32 Functionality
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LFSR0
Q D
bit
clk
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 128
Cryptographic Function Block (Crypto)
Different CRC algorithms require different seed values and have different requirements for XOR functionality and bit reversal.
Table 12-27 provides the proper settings for the CRC32, CRC16-CCITT, and CRC16 algorithms. The table also provides the
remainder after the algorithms are performed on a five-byte array {0x12, 0x34, 0x56, 0x78, 0x9a}.
12.8 PRNG
The pseudo random number generation (PRNG) component generates pseudo random numbers in a fixed range [0,
PR_MAX_CTL.DATA[31:0]]. The generator is based on three Fibonacci-based Linear Feedback Shift Registers (LFSRs). The
following three irreducible polynomials (with minimum feedback) are used:
■ 32-bit polynomial: x32 + x30 + x26 + x25 + 1
■ 31-bit polynomial: x31 + x28 + 1
■ 29-bit polynomial: x29 + x27 + 1
Figure 12-4 illustrates the LFSR functionality.
Figure 12-4. Fixed Fibonacci-based LFSRs
32-bit irreducible polynomial: x 32 + x 30 + x 26 + x 25 + 1 (32 bit LFSR[31:0])
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
D Q
LFSR32
output
clk
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
D Q
LFSR31
output
clk
28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
D Q
LFSR29
output
clk
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 129
Cryptographic Function Block (Crypto)
Software initializes the LFSRs with non-zero seed values. The PR_LFSR_CTL0, PR_LFSR_CTL1 and PR_LFSR_CTL2
registers are provided for this purpose. At any time, the state of these registers can be read to retrieve the state of the LFSRs.
The 32-bit LFSR generates a repeating bit sequence of 232 – 1 bits, the 31-bit LFSR generates a repeating bit sequence of
231 – 1 and the 29-bit LFSR generates a repeating bit sequence of 229 – 1. As the
numbers 232-1, 231-1, and 229-1 are relatively prime, the XOR output is a repeating bit sequence of roughly 232+31+29.
The final pseudo random bit is the XOR of the three bits that are generated by the individual LFSRs.
Figure 12-5. XOR Reduction Logic
LFSR32 output
LFSR31 output pseudo random bit
LFSR29 output
The pseudo random number generator uses a total of 33 pseudo random bits to generate a result in the range [0,
PR_MAX_CTL.DATA[31:0]].
To generate a pseudo random number result, the following calculation is performed.
MAX[31:0] = PR_MAX_CTL.DATA[31:0]
MAX_PLUS1[32:0] = MAX[31:0] + 1;
product[63:0] = MAX_PLUS1[32:0] * pr[32:1] + MAX[31:0] * pr[0];
result = product[63:32];
PR_CMD.START is the PR command. The maximum value of the generated random number (in PR_RESULT.DATA) is
specified by PR_MAX_CTL.DATA. The PR command can be executed in parallel with the instruction FIFO instructions and
the TR command.
12.9 TRNG
The true random number generator component (TRNG) generates true random numbers. The bit size of these generated
numbers is programmable (TR_CTL.SIZE is in the range [0,32]).
The TRNG relies on up to six ring oscillators to provide physical noise sources. A ring oscillator consists of a series of
inverters connected in a feedback loop to form a ring. Due to (temperature) sensitivity of the inverter delays, jitter is
introduced on a ring's oscillating signal. The jittered oscillating signal is sampled to produce a “digitized analog signal” (DAS).
This is done for all multiple ring oscillators.
To increase entropy and to reduce bias in DAS bits, the DAS bits are further postprocessed. Post-processing involves two
steps:
■ An optional reduction step (over up to six ring oscillator DAS bits and over one or multiple DAS bit periods) to increase
entropy.
■ An optional “von Neumann correction” step to reduce a ‘0’ or ‘1’ bias.
This correction step processes pairs of reduction bits as produced by the previous step. Given two reduced bits r0 and r1
(with r0 being produced before r1), the correction step is defined as follows:
❐ {r0, r1} = {0, 0}: no bit is produced
❐ {r0, r1} = {0, 1}: a ‘0’ bit is produced (bit r0)
❐ {r0, r1} = {1, 0}: a ‘1’ bit is produced (bit r0)
❐ {r0, r1} = {1, 1}: no bit is produced
In other words the correction step only produces a bit on a ‘0’ to ‘1’ or ‘1’ to ‘0’ transition. Note that for a random input bit
sequence, the correction step produces an output bit sequence of roughly one-quarter the frequency of the input bit sequence
(the input reduction bits are processed in non-overlapping pairs and only half of the pair encodings result in an output bit).
Post-processing produces bit samples that are considered true random bit samples. The true random bit samples are shifted
into a register, to provide random values of up to 32 bits.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 130
Cryptographic Function Block (Crypto)
As a result of high-switching activity, ring oscillators consume a significant amount of power. Therefore, when the TRNG
functionality is disabled, the ring is “broken” to prevent switching. When the TRNG functionality is enabled, a ring oscillator
initially has predictable behavior. However, over time, infinitesimal environmental (temperature) changes cause an increasing
deviation from this predictable behavior.
■ During the initial delay, the ring oscillator is not a reliable physical noise source.
■ After an initial delay, the same ring oscillator will show different oscillation behavior and provides a reliable physical noise
source.
Therefore, the DAS bits can be dropped during an initialization period (TR_CTL.INIT_DELAY[]).
Figure 12-6 gives an overview of the TRNG component.
Figure 12-6. TRNG Overview
SAMPLE_CLOCK_DIV[]
digitized Post-processing
oscillating signal analog
samples (DAS)
RO11_EN RO11 Sampler
INIT_DELAY[] RED_CLOCK_DIV[] TR_RESULT.DATA[31:0]
FIRO31_EN
FIRO31 Sampler
POLYNOMIAL[30:0]
INTR.TR_INITIALIZED INTR.TR_DATA_AVAILABLE
The “Sampler” logic digitizes an oscillating signal. Figure 12-7 illustrates the functionality (the complete logic is implemented
using standard platform toolkit components).
Figure 12-7. Sampler Logic
Sampler
clock_sample_en
(derived from SAMPLE_CLOCK_DIV[]) mxtk_clk_gate
clk_sys clk_sampler
test_icg_control
START mxtk_rst_and
rst_sys_act_n rst_sampler_n
test_reset_control
Note that when a ring oscillator is disabled, the synchronization logic is reset. Therefore, the ring oscillator contributes a
constant ‘0’ to the reduction step of the post-processing. As mentioned, the TRNG relies on up to six ring oscillators:
■ RO11: A fixed ring oscillator consisting of 11 inverters.
■ RO15: A fixed ring oscillator consisting of 15 inverters.
■ GARO15: A fixed Galois based ring oscillator of 15 inverters.
■ GARO31: A flexible Galois based ring oscillator of up to 31 inverters. A programmable polynomial of up to order 31
provides the flexibility in the oscillator feedback.
■ FIRO15: A fixed Fibonacci based ring oscillator of 15 inverters.
■ FIRO31: A flexible Fibonacci based ring oscillator of up to 31 inverters. A programmable polynomial of up to order 31
provides the flexibility in the oscillator feedback.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 131
Cryptographic Function Block (Crypto)
Each ring oscillator can be enabled or disabled. When disabled, the ring is “broken” to prevent switching. The following
Figures illustrate the schematics of the fixed ring oscillators.
Figure 12-8. Four Fixed Ring Oscillators: RO11, RO15, GARO15, FIRO15
RO11: oscillator with 11 inverters
10 9 8 7 6 5 4 3 2 1 0
RO11_EN output
14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RO15_EN output
14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
output
14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FIRO15_EN output
POLYNOMIAL[29]
POLYNOMIAL[28]
POLYNOMIAL[27]
POLYNOMIAL[26]
POLYNOMIAL[25]
POLYNOMIAL[24]
POLYNOMIAL[23]
POLYNOMIAL[22]
POLYNOMIAL[10]
POLYNOMIAL[0]
POLYNOMIAL[9]
POLYNOMIAL[8]
POLYNOMIAL[7]
POLYNOMIAL[6]
POLYNOMIAL[5]
POLYNOMIAL[4]
POLYNOMIAL[3]
POLYNOMIAL[2]
POLYNOMIAL[1]
30 29 28 27 26 25 24 23 22 21 10 9 8 7 6 5 4 3 2 1 0
output
When the ring oscillator is disabled (GARO31_EN is ‘0’), the polynomial is forced to “0” and the ring is broken as illustrated by
Figure 12-10.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 132
Cryptographic Function Block (Crypto)
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
30 29 28 27 26 25 24 23 22 21 20 10 9 8 7 6 5 4 3 2 1 0
output
Constant ‘1’
30 29 28 27 26 25 24 23 22 21 20 10 9 8 7 6 5 4 3 2 1 0
‘0’
output
The programmable polynomial specifies the oscillator feedback. Figure 12-11 illustrates two examples.
Figure 12-11. GARO31 – Two Examples
7-bit polynomial: x7 + x 6 + 1 (POLYNOMIAL = 0x0000:0041 << 24)
Constant ‘0’
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 4 2 1 0
‘0’
output
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
output
30 29 28 27 26 25 24 23 22 21 10 9 8 7 6 5 4 3 2 1 0
output
POLYNOMIAL[30]
POLYNOMIAL[29]
POLYNOMIAL[28]
POLYNOMIAL[27]
POLYNOMIAL[26]
POLYNOMIAL[25]
POLYNOMIAL[24]
POLYNOMIAL[23]
POLYNOMIAL[22]
POLYNOMIAL[21]
POLYNOMIAL[10]
POLYNOMIAL[9]
POLYNOMIAL[8]
POLYNOMIAL[7]
POLYNOMIAL[6]
POLYNOMIAL[5]
POLYNOMIAL[4]
POLYNOMIAL[3]
POLYNOMIAL[2]
POLYNOMIAL[1]
POLYNOMIAL[0]
When the ring oscillator is disabled (FIRO31_EN is ‘0’), the polynomial is forced to “0” and the ring is broken as illustrated by
Figure 12-13.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 133
Cryptographic Function Block (Crypto)
Constant ‘1’
30 29 28 27 26 25 24 23 22 21 20 10 9 8 7 6 5 4 3 2 1 0
output
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
‘0’
The programmable polynomial specifies the oscillator feedback. Figure 12-14 illustrates two examples.
Figure 12-14. FIRO31 – Two Examples
7-bit polynomial: x7 + x 6 + 1 (POLYNOMIAL = 0x0000:0041 << 24)
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
output
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
output
There is one TR command, TR_CMD.START, which can be executed in parallel with the instruction FIFO instructions and the
PR command. The size of the generated random number (in TR_RESULT.DATA) is specified by TR_CTL.SIZE.
The TRNG has a built-in health monitor that performs tests on the digitized noise source to detect deviations from the
intended behavior. For example, the health monitor detects “stuck at” faults in the digitized analog samples. The health
monitor tests one out of three selected digitized bit streams:
■ DAS bitstream. This is XOR of the digitized analog samples.
■ RED bitstream. This is the bitstream of reduction bits. Note that each reduction bit may be calculated over multiple DAS
bits.
■ TR bitstream. This is the bitstream of true random bits (after the “von Neumann reduction” step).
The health monitor performs two different tests:
The repetition count test. This test checks for the repetition of the same bit value (‘0’ or ‘1’) in a bitstream. A detection
indicates that a specific active bit value (specified by a status field BIT) has repeated for a pre-programmed number of bits
(specified by a control field CUTOFF_COUNT[7:0]). The test uses a counter to maintain the number of repetitions of the
active bit value (specified by a status field REP_COUNT[7:0]).
If the test is started (specified by START_RC field) and a change in the bitstream value is observed, the active bit value BIT is
set to the new bit value and the repetition counter REP_COUNT[] is set to ‘1’. If the bitstream value is unchanged, the
repetition counter REP_COUNT[] is incremented by “1”.
A detection stops the repetition count test (the START_RC field is set to ‘0’), sets the associated interrupt status field to ‘1’ and
ensures that hardware does not modify the status fields. When the test is stopped, REP_COUNT[] equals
CUTOFF_COUNT[].
A detection stops the TRNG functionality (all TR_CTL.XXX_EN fields are set to ‘0’) if TR_CTL.STOP_ON_RC_DETECT is
set to ‘1’.
The adaptive proportion test. This test checks for a disproportionate occurrence of a specific bit value (‘0’ or ‘1’) in a bit
stream. A detection indicates that a specific active bit value (specified by a status field BIT) has occurred a pre-programmed
number of times (specified by a control field CUTOFF_COUNT[15:0]) in a bit sequence of a specific bit window size (specified
by a control field WINDOW_SIZE[15:0]). The test uses a counter to maintain an index in the current window (specified by
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 134
Cryptographic Function Block (Crypto)
WINDOW_INDEX[15:0]) and a counter to maintain the number of occurrences of the active bit value (specified by a status
field OCC_COUNT[15:0]).
If the test is started (specified by START_AP field), the bitstream is partitioned in bit sequences of a specific window size. At
the first bit of a bit sequence, the active bit value BIT is set to the first bit value, the counter WINDOW_INDEX is set to “0” and
the counter OCC_COUNT is set to “1”. For all other bits of a bit sequence, the counter WINDOW_INDEX is incremented by
“1”. If the new bit value equals the active bit value BIT, the counter OCC_COUNT[15:0] is incremented by “1”. Note that the
active bit value BIT is only set at the first bit of a bit sequence.
A detection stops adaptive proportion test (the START_AP field is set to ‘0’), sets the associated interrupt status field to ‘1’ and
ensures that hardware does not modify the status fields. When the test is stopped, OCC_COUNT[] equals
CUTOFF_COUNT[] and the WINDOW_INDEX identifies the bit sequence index on which the detection occurred.
A detection stops the TRNG functionality (all TR_CTL.XXX_EN fields are set to ‘0’) if TR_CTL.STOP_ON_AP_DETECT is set
to ‘1’.
Figure 12-15 illustrates the health monitor functionality.
Figure 12-15. Health Monitor Functionality
Post-processing
digitized
analog INIT_DELAY[] RED_CLOCK_DIV[]
samples (DAS)
true
random
von bit
Neumann
corrector
Health monitor
DAS_SEL RED_SEL TR_SEL
BITSTREAM_SEL[]
Adaptive proportion
START_RC Repetition count test START_AP
test
CUTOFF_COUNT[] CUTOFF_COUNT[]
WINDOW_SIZE[]
BIT BIT
REP_COUNT[] OCC_COUNT[]
INTR.TR_RC_DETECT WINDOW_INDEX[]
INTR.TR_AP_DETECT
Implementation note. The ring oscillators have special design requirements. They are not synthesized logic, but manually
constructed from selected cells from the standard cell library. Three types of standard cells are required:
■ An inverter cell. The selected cell should have similar rise and fall time requirements. Clock tree inverter cells tend to have
this property and are the preferred implementation of the inverter cell.
■ A two-input XOR cell.
■ A two-input AND cell.
The design uses three Verilog design modules to instantiate the selected cells. This allows easy porting from one standard
cell library to another standard cell library. The three Verilog design modules should not be changed by tools (similar to how
the platform toolkit components are treated in the design flow).
A ring oscillator should be placed and routed in a self-contained rectangular area. This area should preferably be as small as
possible.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 135
Cryptographic Function Block (Crypto)
Vector unit
Register-file
16 registers; each register: 13-bit data field and 13-bit size field
The VU addresses asymmetric key cryptography. Asymmetric key cryptography includes RSA, Diffie-Hellman key exchange,
digital signature authentication, and elliptic curve cryptography (ECC). These algorithms share the requirement to efficiently
perform computations in a Galois field on large integers of up to 1000’s of bits.
The VU performs instructions on operand data.
■ The VU instructions are provided by the instruction FIFO.
■ The VU operand data is specified by any of the following (all encoded as part of the 32-bit instruction word):
❐ instruction operation code
❐ instruction register indices
❐ instruction immediate values
The VU uses the VU register file. A VU register is a (data, size) pair: a 13-bit data field (bits 28 down to 16) and a 13-bit size
field (bits 12 down to 0). The data field is either used as:
■ Instruction operand data: the complete 13-bit data is used.
■ An offset into memory: the 13-bit data value is a word offset wrt. a base address into memory.
The size field is only used when the data field is used as an offset into memory. In this case, the size field specifies the bit size
(minus 1) of the memory operand (the 13-bit field specifies a size in the range of [1, 8192] bits).
The VU is a “trimmed down” application domain specific CPU:
■ “Trimmed down”. It does not have a CPU instruction fetch unit that supports non-sequential program flow. This
functionality is typically not required for asymmetric key cryptography functions or needs to be provided by the external
AHB-Lite bus master (typically a CPU). This design decision simplifies the VU.
Note that the instruction FIFO provides the mechanism by which instructions are provided. This mechanism only supports
a sequential VU program flow.
■ Application domain specific. The VU instructions and operand data are tuned for asymmetric key cryptography. For
example, instructions are provided for arithmetic over binary extension fields (GF(2m)) or prime fields (GF(p)), and
memory operands allow for a large operand length of up to 8192 bits (although the VU internal data path is limited to 32
bit).
■ CPU. The VU has CPU-like design components, such as an instruction decoder, a register file, and data path with multiple
functional units.
The VU architecture is the result of a tradeoff between silicon area, design complexity, performance efficiency, and
algorithmic flexibility. Note that most asymmetric key algorithms can be performed by the regular CPU. However, this typically
comes at a lower performance level, possibly large code footprint (due to loop unrolling of code to improve performance when
operating on large operand data), and possibly large data footprint (due to lookup tables to improve performance).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 136
Cryptographic Function Block (Crypto)
The improved performance of the VU (over a regular CPU) for asymmetric key algorithms also allows for more generic
algorithmic implementations, as opposed to implementations targeting, such as specific primes or irreducible polynomials.
Before describing the architecture, a short C example is illustrates the VU functionality.
#define SIZE 4096
void Example ()
{
int a = 0; int b = 1; int c = 2; // assign register indices
uint8_t c_data[SIZE/8];
ALLOC_MEM (a, SIZE); // allocate 4096 bits of data
ALLOC_MEM (b, SIZE); // allocate 4096 bits of data
ALLOC_MEM (c, SIZE); // allocate 4096 bits of data
Crypto_WriteMemNumber (a, “0x21542555:fed35532: … :ffea2345”);
Crypto_writeMemNumber (b, “0xef45ac2a:34a312bc: … :000003ab”);
ADD (c, a, b);
Crypto_ReadMemNumber (c, c_data);
}
The example adds two 4096-bit numbers and produces a 4096-bit number. The example is explained as follows:
■ Three local variables are assigned VU register indices:
❐ local variable a uses register 0
❐ local variable b uses register 1
❐ local variable c used register 2
■ Memory is allocated in the memory buffer for each variable: each variable needs 4096 bits.
■ A function “Crypto_WriteMemNumber” is called to initialize the memory operand data for source variables a and b.
■ A VU ADD instruction (long integer addition) is executed.
■ A function “Crypto_WriteMemNumber” is called to read the result of the instruction from the memory.
The example illustrates that the full expressive power of the C language is available when writing software for the VU.
The example illustrates that relatively complex functionality can be expressed in only a few lines of C code (consider
implementing the same functionality on a 32-bit Arm processor).
The “Crypto_” functions copy data to and from the memory. These functions are executed on the regular CPU and may take a
significant number of cycles. Asymmetric key algorithm typically requires little copy functions and a lot of VU instructions. As
a result, the cycle overhead of the copy functions is negligible. As an example, RSA requires exponentiation of a number by a
second number modulo a third number. This RSA functionality requires only four copy functions (three to initialize three
memory operands and one to read the result), but requires thousands of VU instructions.
The following sections provide an architectural overview of the VU.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 137
Cryptographic Function Block (Crypto)
■ Each non-leaf function restricts its register use to registers r4 through r14.
■ Each leaf function either restricts its register use to registers r0 through r3 or follows the same save/restore convention as
non-leaf functions.
The register-file register r15 serves a specific purpose. Similar to the Arm architecture, register r15 is used as a stack pointer.
Figure 12-17 illustrates the register file and how the data fields are used as offsets in a 16 KB memory region (either in the
crypto memory buffer or the system memory). The base address of the memory region is provided by VU_CTL.ADDR[31:8]
and the memory region size is specified by VU_CTL.MASK[].
Figure 12-17. Register File
16 KB
Register-file memory region
4096 entries
r13 size[12:0] data[12:0]
r12 size[12:0] data[12:0]
... ...
...
r1 size[12:0] data[12:0]
r0 size[12:0] data[12:0]
32-bit word
12.10.2 Stack
The VU stack resides in the memory region. Register r15 is used as a stack pointer. The stack has two purposes:
■ It is used to save/restore registers r0 through r14. Each register (data field and size field) uses a single 32-bit word.
The instruction PUSH_REG saves/pushes all registers r0 through r14 on the stack (and register r15 is decremented by
15).
The instruction POP_REG restores/pops all registers r0 through r14 from the stack (and register r15 is incremented by
15).
The use of the stack pointer (register r15) is implied by the PUSH_REG and POP_REG instructions.
■ It is used to allocate memory operands.
The instruction ALLOC_MEM (rx, size-1) allocates enough 32-bit words to hold a memory operand of “size” bits for regis-
ter rx. The stack pointer (register r15) is decremented by the number of allocated 32-bit words. The data field of register rx
is updated with the new stack pointer value.
The instruction FREE_MEM (“15 bit pattern”) frees the 32-bit words that hold memory operand data associated with the
registers identified by the bit pattern. Note that a register’s size field specifies the number 32-bit words that hold its asso-
ciated memory operand. The stack pointer is incremented by the number of freed 32-bit words.
The use of the stack pointer (register r15) is implied by the instruction. Note that to allocate multiple memory operands,
multiple ALLOC_MEM instructions are required. However, to free multiple memory buffer operands, only a single
FREE_MEM instruction is required.
Figure 12-18 illustrates the VU register-file state before and after the execution of instructions ALLOC_MEM (r0, 32-1) (32 bits
requiring one 32-bit stack element) and ALLOC_MEM (r1, 80-1) (80 bits requiring three 32-bit stack elements).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 138
Cryptographic Function Block (Crypto)
Figure 12-18. Left: Register File State before ALLOC_MEM Instructions; Right: Register File after ALLOC_MEM Instructions
16 KB 16 KB
Register-file memory region Register-file memory region
Figure 12-19 illustrates the VU component state after the execution of the instruction FREE_MEM ((1 << r1) | (1 << r0)).
Figure 12-19. Register File State after FREE_MEM Instruction
16 KB
Register-file memory region
Freeing of stack elements should be in the reverse order of allocation of stack elements. Also see the description of the
FREE_MEM instruction for the order in which registers are freed (lower registers are freed before higher registers).
12.10.4 Datapath
The VU instructions can operate on 13-bit register data values and/or large memory operands. The VU datapath is limited to
32 bits (the width of a single memory word).
To operate on large memory operands, multiple datapath iterations are required. Dependent on the instruction opcode, these
iterations may be independent of each other (for example, a OR instruction) or may be dependent of each other (for example,
an ADD instruction requires a carry). This complexity is completely hidden from software.
■ The instruction opcode specifies whether datapath iterations are dependent or independent.
■ The register size field provides the VU decoder and datapath with all the information it needs to determine the number of
datapath iterations.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 139
Cryptographic Function Block (Crypto)
If a conditional instruction has a condition code that evaluates to ‘0’/FALSE, it does not change the VU functional state. This
means that:
■ a destination operand is not updated
■ the STATUS register is not updated
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 140
Cryptographic Function Block (Crypto)
12.10.6 Instructions
The VU instructions operate on either register operand data or memory operand data.
Operand types. Typically, VU instruction operands all have the same type: either register or memory operands. However,
some exceptions do exist. For example, consider the following CTSAME (count trailing same) instruction.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 141
Cryptographic Function Block (Crypto)
■ Mnemonic
■ Operation code
■ Functionality
For instructions with memory operands, the source and destination memory operands may overlap, unless otherwise
mentioned (the USQUARE, XSQUARE, UMUL, and XMUL instructions do not allow memory operand overlap).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 142
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 143
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 144
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 145
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 146
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 147
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 148
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 149
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 150
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 151
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 152
Cryptographic Function Block (Crypto)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 153
13. Program and Debug Interface
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC 6 MCU Program and Debug interface provides a communication gateway for an external device to perform
programming or debugging. The external device can be a Cypress-supplied programmer and debugger, or a third-party
device that supports programming and debugging. The serial wire debug (SWD) or the JTAG interface can be used as the
communication protocol between the external device and PSoC 6 MCUs.
13.1 Features
■ Supports programming and debugging through the JTAG or SWD interface.
■ CM4 supports 4-bit ETM tracing, serial wire viewer (SWV), and printf() style debugging through the single-wire output
(SWO) pin. CM0+ supports Micro Trace Buffer (MTB) with 4 KB dedicated RAM.
■ Supports Cross Triggering Interface (CTI) and Cross Triggering Matrix (CTM).
■ CM0+ supports four hardware breakpoints and two watchpoints. CM4 supports six hardware breakpoints and four
watchpoints.
■ Provides read and write access to all memory and registers in the system while debugging, including the Cortex-M4 and
Cortex-M0+ register banks when the core is running or halted
13.2 Architecture
Figure 13-1 shows the block diagram of the program and debug interface in the PSoC 6 MCU. The debug and access port
(DAP) acts as the program and debug interface. The external programmer or debugger, also known as the “host”,
communicates with the DAP of the PSoC 6 MCU “target” using either the SWD or JTAG interface. The debug physical port
pins communicate with the DAP through the high-speed I/O matrix (HSIOM). See the I/O System chapter on page 261 for
details on HSIOM.
The debug infrastructure is organized in the following four groups:
■ DAP (provides pin interfaces through which the debug host can connect to the chip)
■ Cortex-M0+ core debug components
■ Cortex-M4 core debug components
■ Other debug infrastructure (includes the CM4 tracing, the CTM, and the System ROM table)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 154
Program and Debug Interface
PSoC 6
DAP BUS
ITM
Debug APB
Port Pins
Debug
ROM table
The DAP communicates with the Cortex-M0+ CPU using the Arm-specified advanced high-performance bus (AHB) interface.
AHB is the systems interconnect protocol used inside the device, which facilitates memory and peripheral register access by
the AHB master. The PSoC 6 MCU has six AHB masters – Arm CM4 CPU core, Arm CM0 CPU core, Datawire0, Datawire1,
Crypto, and DAP. The external host can effectively take control of the entire device through the DAP to perform programming
and debugging operations.
The following are the various debug and trace components:
■ Debug components
❐ JTAG and SWD for debug control and access
■ Trace source components
❐ Micro trace buffer (MTB-M0+) for tracing Cortex-M0+ program execution
❐ Embedded trace macrocell (ETM-M4) for tracing Cortex-M4 program execution
■ Trace sink components
❐ Trace port interface unit (TPIU) to drive the trace information out of the chip to an external trace port analyzer
■ Cross-triggering components
❐ Cross-trigger interface (CTI)
❐ Cross-trigger matrix (CTM)
■ ROM tables
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 155
Program and Debug Interface
13.2.1 Debug Access Port (DAP) Note: The debug slave interfaces of both the CPUs bypass
the internal CPU MPU.
The DAP consists of a combined SWD/JTAG interface
(SWJ) that also includes the SWD listener. The SWD 13.2.1.2 DAP Power Domain
listener decides whether the JTAG interface (default) or
SWD interface is active. Note that JTAG and SWD are Almost all the debug components are part of the Active
mutually exclusive because they share pins. power domain. The only exception is the SWD/JTAG-DP,
which is part of the Deep Sleep power domain. This allows
The debug port (DP) connects to the DAP bus, which in turn the debug host to connect during Deep Sleep, while the
connects to one of three Access Ports (AP), namely: application is ‘running’ or powered down. This enables in-
■ The CM0-AP, which connects directly to the AHB debug field debugging for low-power applications in which the chip
slave port (SLV) of the CM0+ and gives access to the is mostly in Deep Sleep.
CM0+ internal debug components. This also allows
After the debugger is connected to the chip, it must bring the
access to the rest of the system through the CM0+ AHB
chip to the Active state before any operation. For this, the
master interface. This provides the debug host the same
SWD/JTAG-DP has a register (DP_CTL_STAT) with two
view as an application running on the CM0+. This
power request bits. The two bits are CDBGPWRUPREQ
includes access to the MMIO of other debug
and CSYSPWRUPREQ, which request for debug power
components of the Cortex M0+ subsystem. These
and system power, respectively. These bits must remain set
debug components can also be accessed by the CM0+
for the duration of the debug session.
CPU, but cannot be reached through the other APs or by
the CM4 core. Note that only the two SWD pins (SWCLKTCK and
■ The CM4-AP located inside the CM4 gives access to the SWDIOTMS) are operational during the Deep Sleep mode –
CM4 internal debug components. The CM4-AP also the JTAG pins are operational only in Active mode. The
allows access to the rest of the system through the CM4 JTAG debug and JTAG boundary scan are not available
AHB master interfaces. This provides the debug host the when the system is in Deep Sleep mode. JTAG functionality
same view as an application running on the CM4 core. is available only after a chip power-on-reset.
Additionally, the CM4-AP provides access to the debug
components in the CM4 core through the External 13.2.2 ROM Tables
Peripheral Bus (EPB). These debug components can
also be accessed by the CM4 CPU, but cannot be The ROM tables are organized in a tree hierarchy. Each AP
reached through the other APs or by the CM0+ core. has a register that contains a 32-bit address pointer to the
base of the root ROM table for that AP. For PSoC 6 MCUs,
■ The System-AP, which through an AHB mux gives
there are three such root ROM tables.
access to the rest of the system. This allows access to
the System ROM table, which cannot be reached any Each ROM table contains 32-bit entries with an address
other way. The System ROM table provides the chip ID pointer that either points to the base of the next level ROM
but is otherwise empty. table. Each ROM table also contains a set of ID registers
that hold JEDEC compliant identifiers to identify the
13.2.1.1 DAP Security manufacturer, part number, and major and minor revision
numbers. For all ROM tables in PSoC 6 MCUs, these IDs
For security reasons all three APs each can be are the same. Each ROM table and CoreSight compliant
independently disabled. Each AP disable is controlled by component also contains component identification registers.
two MMIO bits. One bit, CPUSS_AP_CTL.xxx_DISABLE
(where xxx can be CM0 or CM4 or SYS), can be set during
boot, before the debugger can connect, based on eFuse 13.2.3 Trace
settings. After this bit is set it cannot be cleared. The micro trace buffer (MTB-M0+) component captures the
The second bit, CPUSS_AP_CTL.xxx_ENABLE, is a regular program execution flow from Cortex-M0+ CPU and stores it
read/write bit. This bit also resets to zero and is set to ‘1’ by in a local SRAM memory. This information can be read by
either the ROM boot code or the flash boot code depending an external debug tool through JTAG/SWD interface to
on the life-cycle stage. This feature can be used to block construct the program execution flow.
debug access during normal operation, but re-enable some The embedded trace macro (ETM) component connected to
debug access after a successful authentication. Cortex-M4 captures the program execution flow from
In addition to the above, the System AP is also protected by Cortex-M4 CPU and generates trace output on its advanced
an MPU. This can be used to give the debugger limited trace bus (ATB) interface. The instrumentation trace
access to the rest of the system. Allow access to the System macrocell (ITM), which is inside Cortex-M4, also generates
ROM table for chip identification. If debug access is restored trace output on its ATB interface. These two ATB interfaces
after successful authentication, this MPU must be (from ETM-M4 and ITM) are connected a trace port interface
configured to allow authentication requests. unit (TPIU).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 156
Program and Debug Interface
The TPIU drives the external pins of a trace port (through frequency clock domain. For more details, refer to the Arm
IOSS interface), so that the trace can be captured by an documentation.
external trace port analyzer (TPA). For more details, refer to
the Arm Debug Interface Architecture Specification ADIv5.0
to ADIv5.2. 13.3 Serial Wire Debug (SWD)
Interface
13.2.4 Embedded Cross Triggering
The PSoC 6 MCU supports programming and debugging
The Arm CoreSight includes Embedded Cross Triggering through the SWD interface. The SWD protocol is a packet-
(ECT) to communicate events between debug components. based serial transaction protocol. At the pin level, it uses a
These events are particularly useful with tracing and single bidirectional data signal (SWDIO) and a unidirectional
multicore platforms. For example trigger events can be used clock signal (SWDCK). The host programmer always drives
to: the clock line, whereas either the host or the target drives
■ Start or stop both CPUs at (almost) the same time the data line. A complete data transfer (one SWD packet)
■ Start or stop instruction tracing based on trace buffer requires 46 clocks and consists of three phases:
being full or not or based on other events ■ Host Packet Request Phase – The host issues a
request to the PSoC 6 MCU target.
CoreSight uses two components to support ECT, namely a
CTI and a CTM, both of which are used in PSoC 6 MCUs. ■ Target Acknowledge Response Phase – The PSoC 6
MCU target sends an acknowledgement to the host.
The CTI component interfaces with other debug ■ Data Transfer Phase – The host or target writes data to
components, sending triggers back and forth and the bus, depending on the direction of the transfer.
synchronizing them as needed. The CTM connects several
CTIs, thus allowing events to be communicated from one When control of the SWDIO line passes from the host to the
CTI to another. target, or vice versa, there is a turnaround period (Trn)
where neither device drives the line and it floats in a high-
The PSoC 6 MCU has three CTIs, one for each CPU and impedance (Hi-Z) state. This period is either one-half or one
one for the trace components in the debug structure. These and a half clock cycles, depending on the transition.
three CTIs are connected together through the CTM. The
CM4 CTI is located in the fast clock domain and the other Figure 13-2 shows the timing diagrams of read and write
two CTIs and the CTM are all located in the same slow- SWD packets.
SWDCK ...
SWDIO ...
Trn (Hi-Z)
wdata[31]
Trn (Hi-Z)
RnW (0)
Start (1)
wdata[0]
wdata[1]
Stop (0)
Park (1)
1 0 0
APnDP
...
Parity
Parity
A[2:3]
ACK[0:2]
Host Packet Request Phase Target ACK Phase Host Data Transfer Phase
SWDCK ...
SWDIO ...
Trn (Hi-Z)
Trn (Hi-Z)
RnW (1)
rdata[31]
Start (1)
Stop (0)
Park (1)
1 0 0
APnDP
rdata[0]
rdata[1]
...
Parity
Parity
A[2:3]
ACK[0:2]
Host Packet Request Phase Target ACK and Data Transfer Phases
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 157
Program and Debug Interface
The sequence to transmit SWD read and write packets are drives the SWDIO line during the Host Packet Request
as follows: phase and, if the host is writing data to the target, during the
1. Host Packet Request Phase: SWDIO driven by the host Data Transfer phase as well. When the host is driving the
SWDIO line, each new bit is written by the host on falling
a. The start bit initiates a transfer; it is always logic 1.
SWDCK edges, and read by the target on rising SWDCK
b. The AP not DP (APnDP) bit determines whether the edges. The target drives the SWDIO line during the Target
transfer is an AP access – 1b or a DP access – 0b. Acknowledge Response phase and, if the target is reading
c. The Read not Write bit (RnW) controls which out data, during the Data Transfer phase as well. When the
direction the data transfer is in. 1b represents a ‘read target is driving the SWDIO line, each new bit is written by
from’ the target, or 0b for a ‘write to’ the target. the target on rising SWDCK edges, and read by the host on
d. The Address bits (A[3:2]) are register select bits for falling SWDCK edges.
AP or DP, depending on the APnDP bit value. Table 13-1 and Figure 13-2 illustrate the timing of SWDIO bit
Note: Address bits are transmitted with the LSb first. writes and reads.
e. The parity bit contains the parity of APnDP, RnW,
and ADDR bits. It is an even parity bit; this means, Table 13-1. SWDIO Bit Write and Read Timing
when XORed with the other bits, the result will be 0. SWDIO Edge
If the parity bit is not correct, the header is ignored by SWD Packet Phase
Falling Rising
the PSoC 6 MCU; there is no ACK response (ACK =
Host Packet Request
111b). The programming operation should be Host Write Target Read
aborted and retried again by following a device reset. Host Data Transfer
f. The stop bit is always logic 0. Target Ack Response
Host Read Target Write
g. The park bit is always logic 1. Target Data Transfer
2. Target Acknowledge Response Phase: SWDIO driven
by the target 13.3.2 ACK Details
a. The ACK[2:0] bits represent the target to host The acknowledge (ACK) bitfield is used to communicate the
response, indicating failure or success, among other status of the previous transfer. OK ACK means that previous
results. See Table 13-1 for definitions. Note: ACK packet was successful. A WAIT response requires a data
bits are transmitted with the LSb first. phase. For a FAULT status, the programming operation
3. Data Transfer Phase: SWDIO driven by either target or should be aborted immediately. Table 13-2 shows the ACK
host depending on direction bit-field decoding details.
a. The data for read or write is written to the bus, LSb
first. Table 13-2. SWD Transfer ACK Response Decoding
b. The data parity bit indicates the parity of the data Response ACK[2:0]
read or written. It is an even parity; this means when
OK 001b
XORed with the data bits, the result will be 0.
WAIT 010b
If the parity bit indicates a data error, corrective
action should be taken. For a read packet, if the host FAULT 100b
detects a parity error, it must abort the programming NO ACK 111b
operation and restart. For a write packet, if the target
detects a parity error, it generates a FAULT ACK Details on WAIT and FAULT response behaviors are as
response in the next packet. follows:
According to the SWD protocol, the host can generate any ■ For a WAIT response, if the transaction is a read, the
number of SWDCK clock cycles between two packets with host should ignore the data read in the data phase. The
SWDIO low. Three or more dummy clock cycles should be target does not drive the line and the host must not
generated between two SWD packets if the clock is not free- check the parity bit as well.
running or to make the clock free-running in IDLE mode. ■ For a WAIT response, if the transaction is a write, the
The SWD interface can be reset by clocking the SWDCK data phase is ignored by the PSoC 6 MCU. But, the host
line for 50 or more cycles with SWDIO high. To return to the must still send the data to be written to complete the
idle state, clock the SWDIO low once. packet. The parity bit corresponding to the data should
also be sent by the host.
13.3.1 SWD Timing Details ■ A WAIT response means that the PSoC 6 MCU is
processing the previous transaction. The host can try for
The SWDIO line is written to and read at different times a maximum of four continuous WAIT responses to see
depending on the direction of communication. The host whether an OK response is received. If it fails, then the
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 158
Program and Debug Interface
TMS
TCK
TDO
The JTAG interface architecture within each device is shown in Figure 13-4. Data at TDI is shifted in, through one of several
available registers, and out to TDO.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 159
Program and Debug Interface
Boundary
Scan Cells
IO Pads
Core
Logic
BYPASS Register
ID Register
Other Register
TCK
Test Access Port
TMS
Controller
TRST
TDO
The TMS signal controls a state machine in the TAP. The state machine controls which register (including the boundary scan
path) is in the TDI-to-TDO shift path, as shown in Figure 13-5. The following terms apply:
■ IR - the instruction register
■ DR - one of the other registers (including the boundary scan path), as determined by the contents of the instruction
register
■ capture - transfer the contents of a DR to a shift register, to be shifted out on TDO (read the DR)
■ update - transfer the contents of a shift register, shifted in from TDI, to a DR (write the DR)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 160
Program and Debug Interface
TMS = 1 TMS = 1
select dr scan select ir scan
TMS = 0 TMS = 0
TMS = 1 TMS = 1
capture dr capture ir
TMS = 0 TMS = 0 TMS = 0 TMS = 0
shift dr shift ir
TMS = 1 TMS = 1
TMS = 1
exit 1 dr exit 1 ir
TMS = 0 TMS = 0 TMS = 0 TMS = 0
pause dr pause ir
TMS = 1 TMS = 1
TMS = 0 TMS = 0
exit 2 dr exit 2 ir
TMS = 1 TMS = 1
update dr update ir
TMS = 1 TMS = 0 TMS = 1 TMS = 0
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 161
Program and Debug Interface
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 162
Program and Debug Interface
13.6 Registers
Table 13-3. List of Registers
Register Name Description
CM0P_DWT Cortex M0+ Data Watchpoint and Trace (DWT) registers
CM0P_BP Cortex M0+ BreakPoint (BP) registers
CM0P_ROM Cortex M0+ CPU Coresight ROM table
CM0P_CTI Cortex M0+ Cross-Trigger Interface (CTI) registers
CM0P_MTB Cortex M0+ Micro Trace Buffer (MTB) registers
CM4_ITM Cortex M4 Instrumentation Trace Macrocell (ITM) registers
CM4_DWT Cortex M4 Data Watchpoint and Trace (DWT) registers
CM4_FPB Cortex M4 Flash Patch and Breakpoint (FPB) registers
CM4_SCS Cortex M4 System Control Space (SCS) registers
CM4_ETM Cortex M4 Embedded Trace Macrocell (ETM) registers
CM4_CTI Cortex M4 Cross-Trigger Interface (CTI) registers
CM4_ROM Cortex M4 CPU Coresight ROM table
TRC_TPIU System Trace Coresight Trace Port Interface Unit (TPIU) registers
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 163
14. Nonvolatile Memory
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
Nonvolatile memory refers to the flash and SROM memory in the PSoC 6 MCU. This chapter explains the geometry and
capability of the flash memory. It also lists the SROM API functions that are used to program the flash memory.
14.1.1 Features
This section lists the features of PSoC 6 flash.
■ 512-byte row size; minimum programmable unit
■ Supports the Read While Write (RWW) feature with a sector size of 256KB
■ 10-year retention
■ Endurance of 100 k program cycles
14.1.2 Configuration
14.1.2.1 Block Diagram
Flash is part of the CPU subsystem. The Cortex-M4 and Cortex M0+, as well as other bus masters, can access flash via the
AHB.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 164
Nonvolatile Memory
DataWire/
CM4 CM0+ Flash SRAM0-4 Crypto ROM
DMA
System
Resources Peripheral Interconnect (MMIO)
Interface (QSPI)
Serial Memory
2x SDHC
Peripherals
USBFS
I/O Subsystem
SFlash S1 R63
2 Sectors (32 kB) 64 Rows (0.5 kB)
AUXFlash S0
R0
S1
2 Sectors (32 kB) R63
64 Rows (0.5 kB)
Application
flash S0
R0
S7 R511
8 Sectors (256 kB) 512 Rows (0.5 kB)
Flash
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 165
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 166
Nonvolatile Memory
each way containing a valid bit, tag, and data. The cache looks at all of the ways in a selected set, checking for validity and a
matching tag. These caches can be enabled/disabled through the FLASHC_CM0/4_CA_CTL.CA_EN registers.
The cache supports faster flash memory reads when enabled. On a read transfer “miss”, however, a normal flash controller
access will occur.
Cache Prefetch. The caches support pre-fetching through the CM0/4_CA_CTL.PREF_EN register.
Table 14-3. CM0/4 Cache Control Prefetch Enable Register Values and Bit Field
Register Bit Field and Bit Name Description
Prefetch enable:
CM0_CA_CTL[32:0] PREF_EN[30] 0: Disabled
1: Enabled
Prefetch enable:
CM4_CA_CTL[32:0] PREF_EN[30] 0: Disabled
1: Enabled
If prefetch is enabled, a cache miss results in a 16 B refill for 14.2 Flash Memory Programming
the missing data and a 16 B prefetch for the next sequential
data. The prefetch data is stored in a temporary buffer and is
only copied to the cache when a read transfer “misses” and 14.2.1 Features
requires that data. ■ SROM API library for flash management through system
calls such as Program Row, Erase Flash, and Blow
14.1.5 Read While Write (RWW) Support eFuse
The PSoC 6 MCU supports read operations on one area ■ System calls can be performed using CM0+, CM4, or
while programming/erasing in another area. This is DAP
implemented to support firmware upgrades and parallel
tasks in the dual-core system. The application flash contains 14.2.2 Architecture
eight sectors, each 256KB in size. The AUXFlash and
SFlash are additional sectors apart from the main flash. Flash programming operations are implemented as system
calls. System calls are executed out of SROM in Protection
The RWW feature is available between sectors – you can Context 0. System calls are executed inside CM0+ NMI. The
read/execute from one sector while there is an ongoing system call interface makes use of IPC to initiate an NMI to
write/erase operation in another sector. However, when the CM0+.
code execution/read is in the last 16 bytes of a given sector
(say sector 0) and the flash write/erase operation is in the System calls can be performed by CM0+, CM4, or DAP.
next sector (sector 1), an RWW violation may occur if Each of them have a reserved IPC structure (used as a
prefetch is enabled. This is because prefetch will fetch the mailbox) through which they can request CM0+ to perform a
next 16 bytes of data, which is part of sector 1 while a write system call. Each one acquires the specific mailbox, writes
operation is underway in the same sector. This will result in the opcode and argument to the data field of the mailbox,
a fault and should be considered during firmware design. and notifies a dedicated IPC interrupt structure. This results
Firmware can be designed to place dead code in the last 16 in an NMI interrupt in CM0+. The following diagram
bytes of every sector making sure the last 16 bytes of a illustrates the system call interface using IPC.
sector are never accessed or can disable prefetch during a
flash write/erase operation.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 167
Nonvolatile Memory
IPC Structure 1
Control IPC Interrupt
Reserved for M4 Access M0+ NMI
Data (32 bytes) Structure 0
IPC Structure 2
Control
Reserved for DAP Access
Data (32 bytes)
The PSoC 6 MCU’s IPC component carries only a single 32- ■ The result is to be passed in SRAM: CM0+ writes the
bit argument. This argument is either a pointer to SRAM or a result in SRAM and releases the IPC structure. The
formatted opcode or argument value that cannot be a valid requester knows that the result is ready from the
SRAM address. The encoding used for DAP and the CM4 or RELEASE interrupt.
CM0+ is slightly different. ■ The result is scalar ( 32 bits) and there is no SRAM to
pass the result: in this case, the CM0+ writes the result
DAP. If (opcode + argument) is less than or equal to 31 to the data field of the IPC structure and releases it. The
bits, store them in the data field and set the LSb of the data requester can read the data when the IPC structure lock
field as ‘1’. Upon completion of the call, a return value is is released. The requester polls the IPC structure to
passed in the IPC data register. For calls that need more know when it is released.
argument data, the data field is a pointer to a structure in
SRAM (aligned on a word boundary) that has the opcode External programmers program the PSoC 6 MCU flash
and the argument. So it is a pointer if and only if the LSb is memory using the JTAG or SWD protocol by sending the
0. commands to the DAP. The programming sequence for
PSoC 6 MCUs with an external programmer is given in the
CM4 or CM0+. A pointer is always used to structure SRAM. PSoC 6 MCU Programming Specifications. Flash memory
Commands that are issued as a single word by DAP can still can also be programmed by the CM4/CM0+ CPU by
be issued by CM0+ or CM4, but use an SRAM structure accessing the IPC interface. This type of programming is
instead. typically used to update a portion of the flash memory as
part of a bootload operation, or other application
The NMI interrupt handler for system calls works as follows. requirement, such as updating a lookup table stored in the
■ If the ROM boot process code is not initialized in the flash memory. All write operations to flash memory, whether
protection state (PROTECTION is still at its default/reset from the DAP or from the CPU, are done through the CM0+.
value UNKOWN), the NMI calls have no effect and the
handler returns.
■ A jump table is used to point to the code in ROM or flash.
This jump table is located in ROM or flash (as configured
in SFlash).
The IPC mechanism is used to return the result of the
system call. Two factors must be considered.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 168
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 169
Nonvolatile Memory
Erase Sector 0x14 Erases the addressed flash sector FLS CM0+, CM4, DAP CM0+, CM4, DAP CM0+, CM4, DAP
Provides system reset to either or
Soft Reset 0x1B SYS CM0+, CM4, DAP DAPc CM0+, CM4
both cores
Erase Row 0x1C Erases the addressed flash row FLS CM0+, CM4, DAP CM0+, CM4, DAP CM0+, CM4, DAP
Erases the addressed flash
Erase Subsector 0x1D FLS CM0+, CM4, DAP CM0+, CM4, DAP CM0+, CM4, DAP
subsector
Generates the hash of the objects
GenerateHash 0x1E SYS CM0+, CM4, DAP None None
indicated by the table of contents
Returns the unique ID of the die from
ReadUniqueID 0x1F SYS CM0+, CM4, DAP CM0+, CM4, DAP CM0+, CM4, DAP
SFlash
CheckFactoryHash 0x27 Checks if FACTORY HASH is valid SYS CM0+, CM4, DAP None None
TransitionToRMA 0x28 Convert part to RMA life cycle SYS None CM0+, CM4, DAP None
ReadFuseByteMargin 0x2B Marginally reads eFuse SYS CM0+, CM4, DAP CM0+, CM4, DAPd None
Blows required eFuses to transition CM0+, CM4,
TransitionToSecure 0x2F to SECURE or SYS None None
SECURE_WITH_DEBUG DAPe
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 170
Nonvolatile Memory
14.5.1 Cypress ID
This function returns a 12-bit family ID, 16-bit silicon ID, 8-bit revision ID, and the current device protection mode. These
values are returned to the IPC_STRUCT_DATA register if invoked with IPC_STRUCT_DATA[0] set to ‘1’. Parameters are
passed through the IPC_STRUCT_DATA register.
Note that only 32 bits are available to store the return value in the IPC structure. Therefore, the API takes a parameter ID type
based on which it will return family ID and revision ID if the ID type is set to ‘0’, and silicon ID and protection state if the ID type
is set to ‘1’.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 171
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 172
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 173
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 174
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 175
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 176
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 177
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 178
Nonvolatile Memory
14.5.7 Checksum
This function reads either the entire flash or a row of flash, and returns the sum of each byte read. Bytes 1 and 2 of the
parameters select whether the checksum is performed on the entire flash or on a row of flash. This function will inherit the
identity of the master that called the function. Hence if a non-secure master requests for either the whole or row checksum of
a secured flash, then the fault exception will be raised by the hardware.
The values are returned to the IPC_STRUCT_DATA register. Parameters are passed through the IPC_STRUCT_DATA
register.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 179
Nonvolatile Memory
14.5.8 FmTransitionToLpUlp
This system call configures the required flash macro from trim bits when transitioning from LP to ULP mode or vice-versa.
This function takes approximately 20 µs; reads from flash are stalled during this time.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 180
Nonvolatile Memory
Return if DAP/CM0+/CM4 Invoked the System Call and SRAM is not used
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 181
Nonvolatile Memory
14.5.10 ConfigureRegionBulk
This API writes a 32-bit data value to a set of contiguous addresses. It cannot be used to configure protected registers or
flash. The Start and End addresses of the region are configurable but must be within a writable area. The region must also be
32-bit aligned. The data will be written to the region starting at the start address up to and including the memory at the end
address. The start address must be lower than the end address or the API will return an error status.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 182
Nonvolatile Memory
14.5.11 DirectExecute
This function directly executes code located at a configurable address. This function is only available in normal life-cycle state
if the DIRECT_EXECUTE_DISABLE bit is 0.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 183
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 184
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 185
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 186
Nonvolatile Memory
14.5.16 GenerateHash
This function returns the truncated SHA-256 of the Flash boot programmed in SFlash. This function gets the Flash Boot size
from the TOC. This function is typically called to confirm that the hash value to be blown into eFuse matches what the ROM
Boot expects.
This function returns the number of zeros of the SECURE_HASH
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 187
Nonvolatile Memory
14.5.17 ReadUniqueID
This function returns the unique ID of the die from SFlash.
14.5.18 CheckFactoryHash
This function generates the FACTORY_HASH according to the TOC1 and compares the value with the FACTORY1_HASH
eFuse value.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 188
Nonvolatile Memory
14.5.19 TransitionToRMA
This function converts the part from SECURE, SECURE_WITH_DEBUG, or NORMAL to the RMA life-cycle stage. This API
performs eFuse programming, VDD should be set to 2.5 V for successful programming.
This function uses Flash Boot functions. The stack consumed by these functions is around 700 bytes. This function returns
STATUS_EMB_ACTIVE failure code if any active embedded flash operations are going on.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 189
Nonvolatile Memory
14.5.20 ReadFuseByteMargin
This API returns the eFuse contents of the addressed byte read marginally. The read value of a blown bit is ‘1’ and of a not
blown bit is ‘0’.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 190
Nonvolatile Memory
14.5.21 TransitionToSecure
This API validates the FACTORY_HASH value and programs the SECURE_HASH, secure access restrictions, and dead
access restrictions into eFuse. This function programs the SECURE or SECURE_WITH_DEBUG eFuse to transition to the
SECURE or SECURE_WITH_DEBUG life-cycle stage. If the FACTORY_HASH or the TOC1 magic number is invalid, then
the API fails and returns status code 0xF00000b5. Note that if the Factory_HASH in eFuse is invalid, then the
TransitionToSecure API fails and the error code is written to the IPC[2].DATA register.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 191
Nonvolatile Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 192
15. Boot Code
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
System boot is defined as the process of validating and starting the product firmware. PSoC 6-2M has 64KB of embedded
SROM, which stores the firmware to begin the boot process. This firmware is called ROM boot. The second stage of the boot
process takes place in SFlash and is called Flash boot. The main function of the boot process is to configure the system
(apply trims, configure access, and set protection settings according to the product life-cycle stage), authenticate the
application, and transfer control to the application.
15.1 Features
The PSoC 6 boot code supports the following features:
■ After reset, the boot code starts execution from ROM on the CM0+.
■ The boot process consists of two parts – ROM boot process and Flash boot process.
■ The ROM boot code applies life-cycle stage and protection state.
■ The ROM boot code validates the integrity of the Flash boot process before starting it.
■ The Flash boot code validates the integrity of the user application before starting it when the device in the SECURE life-
cycle stage. User application validation may optionally be enabled in the NORMAL life-cycle stage.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 193
Boot Code
integrity of these objects. If the TOC structures fail integrity checks, then the RTOC structures are checked for validity. If the
RTOC structures are valid, then the boot process uses the RTOC structures in place of the TOC structures. The
SECURE_HASH is programmed automatically during the TransitionToSecure system call. If the TransitionToSecure system
call fails, it will exit before programming the SECURE_HASH in eFuse. See System Call Status on page 192 for more
information.
A summary of the objects used in the data integrity checks is shown in Figure 15-1. The TOC structure formats are outlined in
Table 15-1 to Table 15-3.
Figure 15-1. Objects, Memory Regions, and Stages of Boot Process for Data Integrity Checks
Secure_HASH
Factory_HASH
DAP Configs
LifeCycle State
eFuse (OTP)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 194
Boot Code
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 195
Boot Code
The wait window time is configurable; however, the CRC value used to validate the TOC2 must be updated after changing the
value. New entries that need HASH can grow from the top starting at offset 0x28; entries that do not need HASH can grow
from the bottom starting at offset 0x1F8. When the device is in the SECURE life-cycle state, the TOC2 can no longer be
modified.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 196
Boot Code
The LIFECYCLE_STAGE object in eFuse is used to set the life-cycle state of the device. Table 15-6 shows the bits and the
associated settings of the LIFECYCLE_STAGE location.
DAP settings for Secure and Dead protection states are set in the SECURE_ACCESS_RESTRICT0 and
DEAD_ACCESS_RESTRICT0 registers. DAP settings for the Normal protection state is set in
NORMAL_ACCESS_RESTRICTIONS in SFlash. Table 15-7 shows the format used to set the DAP settings for these states.
For more information about the protection states, see the Device Security chapter on page 212.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 197
Boot Code
Table 15-7. DAP Access Restriction Registers for Normal, Secure, and Dead Protection States (all default to 0)
Bits Name Description
0 CM0_AP_DISABLE A ‘1’ indicates that this device does not allow access to the M0+ debug access port.
1 CM4_AP_DISABLE A ‘1’ indicates that this device does not allow access to the M4 debug access port.
2 SYS_AP_DISABLE A ‘1’ indicates that this device does not allow access to the system debug access port.
A ‘1’ indicates that the MPU on the system debug access port must be programmed and
locked according to the settings in the next four fields. The SYS_DISABLE bit must be left at
3 SYS_AP_MPU_ENABLE
‘0’ for this setting to matter. If the SYS_DISABLE bit is set to ‘1’, then the next four fields are
invalid. This affects only the SYS_AP. It does not affect the CM0/4 AP.
This field indicates what portion of Supervisory Flash is accessible through the system debug
access port. Only a portion of Supervisory Flash starting at the bottom of the area is exposed.
Encoding is as follows:
0: entire region
5:4 SFLASH_ALLOWED 1: one-half
2: one-quarter
3: nothing
For example, for an encoding of “2: one-quarter”, the valid code region starts at address
0x16000000 and will go up to one-quarter of the SFlash memory region.
This field indicates what portion of the MMIO region is accessible through the system debug
access port. Encoding is as follows:
7:6 MMIO_ALLOWED 0: All MMIO registers
1: Only IPC MMIO registers accessible (system calls)
2, 3: No MMIO access
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 198
Boot Code
As an example, if you want to limit the lower one-quarter of flash of a device with 2MB of flash, a “4” is written into the
FLASH_ALLOWED field. Only the flash area between 0x1000_0000 and 0x1007_FFFF will be accessible via the SYS_DAP.
The remaining areal between 0x1008_0000 to 0x101F_FFFF is not accessible. This means that only the lower quarter of
flash can be reprogrammed, erased, or read by the debug port.
Figure 15-2. FLASH_ALLOWED with encoding “4”
0x10200000
Main Flash
Address
0x10080000
DAP Accessable
0x10000000
As shown in Figure 15-2, if you want to limit the lower fourth of flash of a device with 2MB of flash, write a ‘4’ into the
FLASH_ALLOWED field. Only the flash area between 0x10000000 and 0x1007FFFF will be accessible via the SYS_DAP.
The remaining area between 0x10080000 to 0x101FFFFF would not be accessible. This means that only the lower fourth of
flash can be reprogrammed, erased, or read by the debug port.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 199
Boot Code
Other protection units are set up during ROM boot to restrict access to various regions to ensure device security. The
following tables list those structures, the regions they protect, and the protection settings applied to those regions. The
protection settings are applied in all life-cycle stages except VIRGIN.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 200
Boot Code
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 201
Boot Code
Enable SRAMs
Hash on trim No
area OK ? (SFlash)
Yes
No
No Secure Boot ?
(eFuse)
Yes
Deploy NORMAL
Access Restrictions Corrupt
(SFlash) Authenticate Flash Boot
PROTECTION=NORMAL
PROTECTION=SECURE
PROTECTION=DEAD
(DEAD)
(SECURE)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 202
Boot Code
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 203
Boot Code
15.3.4.1 Header
The Flash boot header consists of:
■ The Flash boot object size
■ The Flash boot application version
■ The number of cores (set to ‘1’ for Flash boot)
■ CM0+ vector table offset
■ Cypress ID and CPU Core Index
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 204
Boot Code
* Set up SP
Interrupt and
(1) * Enable IRQ (50)
System Calls
* Initialization
Yes
(4)
(30) Set Error Code
Is Hard Fault Yes
(3) Trigger a Hardfault
triggered?
No
Protection = Yes
(31) Set up SP (17)
Get App #0 Virgin?
(5)
Reset Handler
No
Is Reset No
(6)
Handler valid?
Lifecycle = Yes
(32)
Yes SECURE?
(7)
No (33) Protection = DEAD
No Authenticate
App?
Is Public Key No
(8)
valid?
Enable System Calls (10) Enable System Calls
Yes
No
(11) Is DAP enabled?
(10) Enable System
Calls
Yes
No
(11) Is DAP enabled?
Configure SWD/JTAG
(12)
pins
Yes
No
(17) Setup-SP
Wait window
(14)
(default = 20 ms)
No
(17) Set up SP
Launch CM0+
(16)
Idle Loop Application
(18)
( In SROM )
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 205
Boot Code
15.3.5.1 Entry from ROM Boot (0) 15.3.5.6 Get App #0 Reset Handler (5)
ROM boot transfers control to Flash boot after it validates Flash boot reads the application start address from the
the SFlash block and TOC1 in the user flash. TOC2 entry:
■ SFLASH_TOC2_FIRST_USER_APP_ADDR for App#0.
15.3.5.2 Basic Initialization (1)
The application format is stored in the TOC2 entry:
This stage sets the value of the stack pointer during runtime.
■ SFLASH_TOC2_FIRST_USER_APP_FORMAT for App
To support recovery from Hard-Fault exceptions during
#0.
Flash boot, this stage also enables interrupts.
The address of reset handler inside the application depends
15.3.5.3 Is TOC2 Valid? (2) on the application format.
The TOC2 may be in three states: 15.3.5.7 Is Reset Handler Valid? (6)
■ VALID: The TOC2 structure and CRC are valid. This is
the default state of the TOC2. Flash boot checks if the address of the reset handler for the
user application is in RAM, SFlash, application flash, or
■ CORRUPTED: Either the TOC2 structure or CRC value
AUXFlash.
are incorrect.
■ ERASED: The first two 32-bit words at the start of TOC2 15.3.5.8 Authenticate App? (7)
are equal to the SFlash erase value. The erased value is
0x0000_0000. Flash boot optionally authenticates a digital signature for the
application image if the TOC2_FLAGS bit
If the PROTECTION is SECURE then ERASED state is a APP_AUTH_DISABLE = 0.
part of CORRUPTED state.
If this field is set then the authentication step is skipped.
If the PROTECTION is not SECURE then ERASED state is
a special case of VALID state. In this case, Flash boot treats 15.3.5.9 Is Public Key Valid (8)
all the TOC2 entries as having a default value:
■ SFLASH_TOC2_FIRST_USER_APP_ADDR is The public key structure is filled by the user. Thus, it must be
0x1000_0000 (the start of Flash). validated to ensure the correctness of the its entries before
being used.
■ SFLASH_TOC2_FIRST_USER_APP_FORMAT is 0
(Basic Application Format). 15.3.5.10 Is Digital Signature Valid? (9)
■ SFLASH_TOC2_FLAGS = 0x0000_0000
The user application located in main flash is validated using
The other TOC2 entries will not be used when TOC2 is in the standard RSA 2048-bit algorithm (RSASSA-PKCS1-
ERASED or corrupted states. v1_5-2048). The public key used for this operation is stored
in the user public key area of SFlash.
15.3.5.4 Is Hard Fault Triggered? (3)
The application can be in one of three formats, only two of
The Flash boot test system requires a way to trigger a hard which are validated using a public key.
fault in the Flash boot code. The condition to trigger a hard-
fault is as follows: The Crypto block is used for validation and is only enabled
during the application validation process to conserve power.
1. SFLASH_FLAGS bit FB_HARDFAULT is set.
2. A 32-bit word in TOC2 at offset + 500 contains an The following figure shows the application validation flow.
address to a 32-bit word named HardFaultTrigger.
3. HardFaultTrigger value is 0x0000_0001.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 206
Boot Code
Binary Firmware
Binary (Not Encrypted)
Code Binary
Image Code
(Firmware) Application
Image Bundle
Digital
Signature
Hash
Digital
Function Signature
SHA-256
Decrypt
Public Key
( 2048-bit)
( RSA N-bit )
Calculated
Digital
Digest Decrypted
Digital
Digest
Do No Invalid
Signatures
Application
Match?
Yes
Valid
Application
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 207
Boot Code
If the TOC2 is valid and the life-cycle stage is NORMAL, 15.3.5.18 Set Up SP (17)
then the application can be in either the Basic or Cypress
Standard Secure application formats. The SP register value for Flash boot is at the top of user
RAM.
Otherwise, the application is stored in the Cypress Secure
application format. 15.3.5.19 Idle Loop (18)
The procedure to launch a user application is: Before going to an idle loop the Flash boot sets the
1. Set CPUSS_CM0_VECTOR_TABLE_BASE to the start CPUSS_CM0_VECTOR_TABLE_BASE MMIO register to
of the user application interrupt vector table. 0xFFFF_0000.
2. Set CPUSS_CM4_VECTOR_TABLE_BASE to In this state, a NMI interrupt can wake up the device. To
0xFFFF_0000. prevent unwanted firmware access, device access
3. Perform a core reset. restrictions must be set up correctly for the appropriate life
4. After a core reset is performed ROM boot is launched cycle stage. The protection settings for each life-cycle stage
(on CM0+). are listed in Life-cycle Stages and Protection States on
page 196.
5. ROM boot checks if CPUSS_PROTECTION ! = 0, which
means ROM boot is launched on CM0+ after a core
15.3.5.20 Set Error Code (30)
reset.
6. If (5) is true, ROM boot sets SP and PC register values If the user application flash or the TOC2 was determined to
from the user interrupt vector table. The address of a be invalid, an error code will be written to IPC.DATA
user application interrupt vector table is stored at step (structure 2); this will enable to detect the cause during
(1) to CPUSS_CM0_VECTOR_TABLE_BASE. debug.
7. When ROM boot sets PC register value with the user
reset handler address, user code starts executing.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 208
Boot Code
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 209
16. eFuse Memory
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The eFuse memory consists of a set of eFuse bits. When an eFuse bit is programmed, or “blown”, its value can never be
changed. Some of the eFuse bits are used to store various unchanging device parameters, including critical device factory
trim settings, device life cycle stages (see the Device Security chapter on page 212), DAP security settings, and encryption
keys. Other eFuse bits are available for custom use.
16.1 Features
The PSoC 6 MCU eFuses have the following features:
■ A total of 1024 eFuse bits. 512 of them are available for custom purposes.
■ The eFuse bits are programmed one at a time, in a manufacturing environment. The eFuse bits cannot be programmed in
the field.
■ Multiple eFuses can be read at the bit or byte level through a PDL API function call or an SROM call. An unblown eFuse
reads as logic 0 and a blown eFuse reads as logic 1. There are no hardware connections from eFuse bits to elsewhere in
the device.
■ SROM system calls are available to program and read eFuses. See the Nonvolatile Memory chapter on page 164. For
detailed information on programming eFuses, see the PSoC 6 MCU Programming Specifications.
16.2 Architecture
The PSoC 6 MCU eFuses can be programmed only in a manufacturing environment. VDDIO0 must be set to 2.5 V, and the
device must be in a specific test mode, entered through an XRES key. For more information, see the PSoC 6 MCU
Programming Specifications.
Table 16-1 shows the usage of the PSoC 6 MCU eFuse bytes.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 210
eFuse Memory
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 211
17. Device Security
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC 6 MCU offers several features to protect user designs from unauthorized access or copying. Selecting a secure life
cycle stage, enabling flash protection, and using hardware-based encryption can provide a high level of security.
17.1 Features
The PSoC 6 MCU provides the following device security features:
■ Nonvolatile and irreversible life cycle stages that can limit program and debug access.
■ Shared memory protection unit (SMPU) that provides programmable flash, SRAM, and register protection.
■ Cryptographic function block that provides hardware-based encryption and decryption of data and code.
17.2 Architecture
17.2.1 Life Cycle Stages and Protection States
PSoC 6 MCUs have configurable, nonvolatile life cycle stages. Life cycle stages follow a strict, irreversible progression
governed by writing to eFuse – a 1024-bit nonvolatile memory with each bit being one time programmable (OTP). The eFuse
can hold unalterable keys and trim information. See the eFuse Memory chapter on page 210 for more details of the eFuse;
see the Nonvolatile Memory chapter on page 164 for eFuse access system calls.
This chapter discusses hardware blocks used to implement device security. For system-level implementation of device
security, see AN221111 - PSoC™ 6 MCU designing a custom secured system.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 212
Device Security
Virgin
Write
Nomal
eFuse
Normal
Write Write
Secure Secure /w
eFuse Debug
eFuse
Write RMA
eFuse
RMA
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 213
Device Security
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 214
Device Security
UNKNOWN
(After Reset)
No
eFuse Lifecycle Bits Set? VIRGIN
Yes
No
Corruption or error
detected during the boot
process
DEAD
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 215
Device Security
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 216
Section C: System Resources Subsystem (SRSS)
Color Key:
System Resources
Power Modes and
Power Clocks
Domains
OVP LVD IMO ECO
System LP/ULP Mode
CPUs Active/Sleep POR BOD FLL 2x PLL
System Buck Regulator 2x MCWDT
DeepSleep Mode
ILO WDT
System XRES Reset
Hibernate Mode
RTC WCO
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 217
18. Power Supply and Monitoring
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC 6 MCU family supports an operating voltage range of 1.7 V to 3.6 V. It integrates multiple regulators including an
on-chip buck converter to power the blocks within the device in various power modes. The device supports multiple power
supply rails – VDDD, VDDA, VDDIO, and VBACKUP – enabling the application to use a dedicated supply for different blocks within
the device. For instance, VDDA is used to power analog peripherals such as ADC and opamps.
The PSoC 6 MCU family supports power-on-reset (POR), brownout detection (BOD), over-voltage protection (OVP), and low-
voltage-detection (LVD) circuit for power supply monitoring and failure protection purposes.
18.1 Features
The power supply subsystem of the PSoC 6 MCU supports the following features:
■ Operating voltage range of 1.7 V to 3.6 V
■ User-selectable core logic operation at either 1.1 V (LP) or 0.9 V (ULP)
■ Three independent supply rails (VDDD, VDDA, and VDDIO) for PSoC core peripherals and one independent supply rail
(VBACKUP) for backup domain
■ Multiple on-chip regulators
❐ One low-dropout (LDO) regulator to power peripherals in Active power mode
❐ One buck converter
❐ Multiple low-power regulators to power peripherals operating in different low-power modes
■ Two BOD circuit (VDDD and VCCD) in all power modes except Hibernate mode
■ LVD circuit to monitor VDDD, VAMUXA, VAMUXB, VBACKUP, or VDDIO
■ One OVP block monitoring VCCD
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 218
Power Supply and Monitoring
18.2 Architecture
Figure 18-1. Power System Block Diagram
Active domain and Deep Sleep domain Active mode power supply/logic
Dee-Sleep and SRAM (Active)
High frequency logic/ peripherals / SRAM Analog peripherals
Retention regulators
4.7 µF peripherals On-chip buck connections
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 219
Power Supply and Monitoring
See the PSoC 61 datasheet/PSoC 62 datasheet for the operation of the peripherals from VDDD. The regulator is
values to be used for the capacitors and inductor shown in capable of providing 0.9 V and 1.1 V for core operation. See
Figure 18-1. Core Operating Voltage on page 221. The regulator is
The regulators and supply pins/rails shown in Figure 18-1 available in Active and Sleep power modes. This regulator
power various blocks inside the device. The availability of implements two sub-modes – high-current and low-current
various supply rails/pins for an application will depend on modes. LINREG_LPMODE bit [24] of the PWR_CTL
the device package selected. Refer to the PSoC 61 register selects between the two modes of operation. The
datasheet/PSoC 62 datasheet for details. high-current mode is the normal operating mode, that is, the
device operates to its full capacity in Active or Sleep power
All the core regulators draw their input power from the VDDD modes. In the low-current mode or the minimum regulator
supply pin. The on-chip buck uses the VDD_NS supply pin as current mode, the current output from the regulator is
its input. VCCD supply is used to power all active domain and limited. This mode implements the Low-Power Active and
high frequency peripherals. The output of the buck is Sleep power modes. The low-current mode sets a limitation
connected to the VCCD pin and in firmware the VCCD supply on the capabilities and availability of resources in the Low-
can be switched to the buck output. A dedicated Deep Sleep Power Active and Sleep modes. For details, see the Device
regulator powers all the Deep Sleep peripherals. The Deep Power Modes chapter on page 225.
Sleep regulator switches its output to VCCD when available
and to its regulated output when VCCD is not present By default, the linear regulator is powered on reset. The
(System Deep Sleep power mode). Hibernate domain does regulator can be disabled by setting the LINREG_DIS bit
not implement any regulators and the peripherals available [23] of the PWR_CTL register. Note that the linear regulator
in that domain such as Low-Power comparator and ILO should be turned OFF only when the following conditions
operate directly from VDDD. are satisfied:
■ Switching buck regulator is ON.
When the VDDA pin is not present, analog peripherals run
directly from the VDDD. ■ The load current requirement of the device from the
VCCD supply does not exceed 20 mA. This should be
The I/O cells operate from various VDDx (VDDA, VDDD, or ensured by the firmware by disabling power consuming
VDDIO) pins depending on the port where they are located. high-frequency peripherals and reducing the system
VCCD supply is used to drive logic inside the I/O cells from clock frequency.
core peripherals. VDDA powers the analog logic such as
analog mux switches inside the I/O cell. To know which I/Os If the linear regulator is turned OFF without the above
operate from which supply, refer to the PSoC 61 datasheet/ conditions satisfied, it will result in VCCD brownout and the
PSoC 62 datasheet. device will reset.
The device includes a VBACKUP supply pin to power a small Switching (Buck) Core Regulator
set of peripherals such as RTC and WCO, which run
independent from other supply rails available in the device. The device includes a switching (buck) core regulator. The
When the VBACKUP supply is not present, the device uses buck requires an inductor and a capacitor to generate the
VDDD to power these peripherals. output. Note that the buck output is also available in the
Deep Sleep device power mode.
In addition to the power rails and regulators, the device
provides options to monitor supply rails and protection The buck regulator can be enabled by setting the BUCK_EN
against potential supply failures. These include a POR bit [30] of the PWR_BUCK_CTL register. The buck output
circuit, a BOD circuit, an OVP circuit, and a LVD circuit. can be enabled/disabled using the BUCK_OUT1_EN bit [31]
of the PWR_BUCK_CTL registers. The buck output
supports voltages from 0.85 V to 1.20 V. Use either 0.9 V or
18.3 Power Supply 1.1 V for VCCD operation.
The output selection can be made using BUCK_OUT_SEL
18.3.1 Regulators Summary bits in the PWR_BUCK_CTL registers.
18.3.1.1 Core Regulators When used to power the core peripherals, the buck
regulator provides better power efficiency than the linear
The device includes the following core regulators to power regulator, especially at higher VDDD. However, the buck
peripherals and blocks in various power modes. regulator has less load current capability (20 mA individually
or 30 mA combined) than the linear regulator. Therefore,
Linear Core Regulator when using the buck regulator, take care not to overload the
The device includes a linear LDO regulator to power the regulator by running only the necessary peripherals at a
Active and Sleep mode peripherals. This regulator lower frequency in firmware. Overload conditions can cause
generates the core voltage (VCCD) required for Active mode the buck output to drop and result in a brownout reset.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 220
Power Supply and Monitoring
Follow these steps in firmware when switching to the buck Core Operating Voltage
regulator for core (VCCD) operation without causing a
PSoC 6 MCUs can operate at either 0.9 V LP mode
brownout.
(nominal) or 1.1 V ULP mode (nominal) core voltage. On
1. Make sure the necessary inductor and capacitor reset, the core is configured to operate at 1.1 V by default.
connection for the buck as explained in Figure 18-1 is At 0.9 V, power consumption is less, but there are some
present in the hardware. limitations. The maximum operating frequency for all HFCLK
2. Change the core supply voltage to 50 mV more than the paths should not exceed 50 MHz, whereas the peripheral
final buck voltage. For instance, if the final buck voltage and slow clock should not exceed 25 MHz.
is 0.9 V, then set the LDO output to 0.95 V and 1.15 V for
Follow these steps to change the PSoC 6 MCU core
1.1 V buck operation. Set the ACT_REG_TRIM bits[4:0]
voltage:
of the PWR_TRIM_PWRSYS_CTL register to ‘0x0B’ to
switch to 0.9 V and '0x1B' to switch to 1.1 V buck 1. While transitioning to 0.9 V (ULP mode), reduce the
operation. This is discussed in Core Operating Voltage. operating frequency to be within the HFCLK and peri
clock limits defined in the PSoC 61 datasheet/PSoC 62
3. Reduce the device current consumption by reducing
datasheet for ULP mode. Turn off blocks, if required, to
clock frequency and switching off blocks to meet the
be within the maximum current consumption limit of the
buck regulator’s load capacity.
linear regulator at 0.9 V.
4. Disable System Deep Sleep mode regulators. Because
2. Set the ACT_REG_TRIM bits[4:0] of the
the buck regulator is available in the System Deep Sleep
PWR_TRIM_PWRSYS_CTL register to ‘0x07’ for 0.9 V
power mode, other deep-sleep regulators can be
or ‘0x17’ for 1.1 V. For the buck regulator, set the
powered down. This is done by setting the following bits
BUCK_OUT1_SEL bits[2:0] of the PWR_BUCK_CTL
in the PWR_CTL register:
register to ‘0x02’ for 0.9 V and ‘0x05’ for 1.1 V.
a. DPSLP_REG_DIS bit [20] – Disables the deep-sleep
3. In the case of 1.1 V to 0.9 V transition, the time it takes
core regulator.
to discharge or settle to the new voltage may depend on
b. RET_REG_DIS bit [21] – Disables the logic retention the load. So the system can continue to operate while
regulator. the voltage discharges.
c. NWELL_REG_DIS bit [22] – Disables the nwell 4. In the case of 0.9 V to 1.1 V transition, wait 9 µs for the
regulator. regulator to stabilize to the new voltage. The clock
5. Set the buck output to the desired value by writing ‘2’ (for frequency can be increased after the settling delay.
0.9 V) or ‘5’ (for 1.1 V) to the BUCK_OUT1_SEL bits[2:0]
Notes:
of the PWR_BUCK_CTL register.
■ When changing clock frequencies, make sure to update
6. Enable the buck regulator and output by setting the
wait states of RAM/ROM/FLASH. Refer to the CPU
BUCK_EN bit[30] and BUCK_OUT1_EN bit[31] of the
Subsystem (CPUSS) chapter on page 32 for details on
PWR_BUCK_CTL register.
the wait states.
7. Wait 200 µs for the buck regulator to start up and settle.
■ Flash write is not allowed in 0.9 V (ULP mode) core
8. Disable the linear regulator by setting the LINREG_DIS operation.
bit[23] of the PWR_CTL register.
After transitioning to the buck regulator, do not switch back Other Low-power Regulators
to the linear regulator mode to ensure proper device In addition to the core active regulators, the device includes
operation. This should happen once during powerup. multiple low-power regulators for powering Deep Sleep
peripherals/logic (VCCDPSLP), digital retention logic/SRAM
(VCCRET), and N-wells (VNWELL) in the device. Note that
VNWELL is not shown in Figure 18-1 because this rail is used
across the device for powering all the N-wells in the chip.
These rails are shorted to VCCD in Active and Sleep power
modes. VCCRET powers all the Active mode logic that needs
to be in retention in Deep Sleep mode.
Note that none of these power rails are available in
Hibernate mode. In Hibernate mode, all the hibernate logic
and peripherals operate from VDDD directly and a Hibernate
wakeup resets the device. For details, refer to the Device
Power Modes chapter on page 225.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 221
Power Supply and Monitoring
18.3.3 Power Sequencing Requirements Other supply rails and pins such as VDDA, VDDIO, and
VBACKUP exist independent of VDDD and VCCD.
VDDD, VBACKUP, VDDIO, and VDDA do not have any
sequencing limitation and can establish in any order. The
presence of VDDA without VDD or VDDD can cause some 18.4 Voltage Monitoring
leakage from VDDA. However, it will not drive any analog or
The PSoC 6 MCU offers multiple voltage monitoring and
digital output. All the VDDA pins in packages that offer
supply failure protection options. This includes POR, BOD,
multiple VDDA supply pins, must be shorted externally (on
LVD, and OVP.
the PCB). Note that the system will not exit reset until both
VDDD and VDDA are established. However, it will not wait for
18.4.1 Power-On-Reset (POR)
other supplies to establish.
POR circuits provide a reset pulse during the initial power
18.3.4 Backup Domain ramp. POR circuits monitor VDDD voltage. Typically, the
POR circuits are not very accurate about the trip-point.
The PSoC 6 MCU offers an independent backup supply
option (VBACKUP). This rail powers a small set of peripherals POR circuits are used during initial chip power-up and then
that includes an RTC, WCO, and a small number of disabled. Refer to the PSoC 61 datasheet/PSoC 62
retention registers. This rail is independent of all other rails datasheet for details on the POR trip-point levels.
and can exist even when other rails are absent. As
Figure 18-1 shows, this pin sources the VDDBAK rail in the 18.4.2 Brownout-Detect (BOD)
device. The VDDBAK rail is connected to VDDD when no
The BOD circuit protects the operating or retaining logic
VBACKUP supply exists. For details on the backup domain, from possibly unsafe supply conditions by applying reset to
refer to the Backup System chapter on page 235. the device. The PSoC 6 MCU offers two BOD circuits –
high-voltage BOD (HVBOD) and low-voltage BOD (LVBOD).
18.3.5 Power Supply Sources The HVBOD monitors the VDDD voltage and LVBOD
monitors the VCCD voltage. Both BOD circuits generate a
The PSoC 6 MCU offers power supply options that support
reset if a voltage excursion dips below the minimum VDDD/
a wide range of application voltages and requirements.
VDDD input supports a voltage range of 1.7 V to 3.6 V. If the VCCD voltage required for safe operation (see the PSoC 61
application voltage is in this range, then the PSoC 6 MCU datasheet/PSoC 62 datasheet for details). The system will
(VDDD) can be interfaced directly to the application voltage. not come out of RESET until the supply is detected to be
valid again.
In applications that have voltage beyond this range, a
suitable PMIC (Buck or Boost or Buck-Boost) should be The HVBOD circuit guarantees a reset in System LP, ULP,
used to bring the voltage to this range. and Deep Sleep power modes before the system crashes,
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 222
Power Supply and Monitoring
provided the VDDD supply ramp satisfies the datasheet bits[1:0] of SRSS_INTR_CFG register. By default, the
maximum supply ramp limits in that mode. There is no BOD configuration disables the interrupt. Note: LVD logic may
support in Hibernate mode. Applications that require BOD falsely detect a falling edge during Deep Sleep entry.
support should not use Hibernate mode and should disable This applies only when HVLVD1_EDGE_SEL is set to
it. Refer to the Device Power Modes chapter on page 225 FALLING(2) or BOTH(3). Firmware can workaround this
for details. condition by disabling falling edge detection before
entering Deep Sleep, and re-enabling it after exiting
The LVBOD, operating on VCCD, is not as robust as the Deep Sleep.
HVBOD. The limitation is because of the small voltage
4. Enable the LVD by setting the HVLVD1_EN bit in the
detection range available for LVBOD on the minimum
PWR_LVD_CTL register. This may cause a false LVD
allowed VCCD.
event.
For details on the BOD trip-points, supported supply ramp 5. Wait at least 8 µs for the circuit to stabilize.
rate, and BOD detector response time, refer to the PSoC 61 6. Clear any false event by setting the HVLVD1 bit in the
datasheet/PSoC 62 datasheet. SRSS_INTR register. The bit will not clear if the LVD
condition is truly present.
18.4.3 Low-Voltage-Detect (LVD) 7. Unmask the interrupt by setting the HVLVD1 bit in
An LVD circuit monitors external supply voltage and SRSS_INTR_MASK.
accurately detects depletion of the energy source. The LVD LVD is used to detect potential brownouts. When the supply
generates an interrupt to cause the system to take being monitored drops below the threshold, the interrupt
preventive measures. generated can be used to save necessary data to flash,
The LVD can be configured to monitor VDDD, VAMUXA, dump logs, trigger external circuits, and so on.
VAMUXB, or VDDIO. The HVLVD1_SRCSEL bits [6:4] of the For details on supported LVD thresholds, refer to the PSoC
PWR_LVD_CTL register selects the source of the LVD. The 61 datasheet/PSoC 62 datasheet and the PWR_LVD_CTL
LVD support up to 15 voltage levels (thresholds) to monitor register definition in the registers TRM.
between 1.2 V to 3.1 V. The HVLVD1_TRIPSEL bits [3:0] of
the PWR_LVD_CTL register select the threshold levels of
the LVD. LVD should be disabled before selecting the
threshold. The HVLVD1_EN bit [7] of the PWR_LVD_CTL
register can be used to enable or disable the LVD.
Whenever the voltage level of the supply being monitored
drops below the threshold, the LVD generates an interrupt.
This interrupt status is available in the SRSS_INTR register.
HVLVD1 bit [1] of the SRSS_INTR register indicates a
pending LVD interrupt. The SRSS_INTR_MASK register
decides whether LVD interrupts are forwarded to the CPU or
not.
Note that the LVD circuit is available only in Active,
LPACTIVE, Sleep, and LPSLEEP power modes. If an LVD is
required in Deep Sleep mode, then the device should be
configured to periodically wake up from Deep Sleep mode
using a Deep Sleep wakeup source. This makes sure an
LVD check is performed during Active/LPACTIVE mode.
When enabling the LVD circuit, it is possible to receive a
false interrupt during the initial settling time. Firmware can
mask this by waiting for 8 µs after setting the HVLVD1_EN
bit in the PWR_LVD_CTL register. The recommended
firmware procedure to enable the LVD function is:
1. Ensure that the HVLVD1 bit in the SRSS_INTR_MASK
register is 0 to prevent propagating a false interrupt.
2. Set the required trip-point in the HVLVD1_TRIPSEL field
of the PWR_LVD_CTL register.
3. Configure the LVD edge (falling/rising/both) that triggers
the interrupt by configuring HVLVD1_EDGE_SEL
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 223
Power Supply and Monitoring
HVLVD1_EN
HVLVD1_SRCSEL [2:0]
VDDD
VAMUXA -
VAMUXB
HVLVD1 SRSS_INTR[HVLVD1]
To CPU as SRSS
1.2 V . SRSS_INTR_MASK[HVLVD1]
. interrupt
.
.
+
.
3.1 V
4
HVLVD1_TRIPSEL [3:0]
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 224
19. Device Power Modes
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC 6 MCU can operate in four system and three CPU power modes. These modes are intended to minimize the
average power consumption in an application. The power modes supported by PSoC 6 MCUs, in the order of decreasing
power consumption, are:
■ System Low Power (LP) – All peripherals and CPU power modes are available at maximum speed and current
■ System Ultra Low Power (ULP) – All peripherals and CPU power modes are available, but with limited speed and current
■ CPU Active – CPU is executing code in system LP or ULP mode
■ CPU Sleep – CPU code execution is halted in system LP or ULP mode
■ CPU Deep Sleep – CPU code execution is halted and system deep sleep is requested while in system LP or ULP mode
■ System Deep Sleep – Entered only after both CPUs enter CPU Deep Sleep mode. Only low-frequency peripherals are
available
■ System Hibernate – Device and I/O states are frozen and the device resets on wakeup
CPU Active, Sleep, and Deep Sleep are standard Arm-defined power modes supported by the Arm CPU instruction set
architecture (ISA). System LP, ULP, Deep Sleep and Hibernate modes are additional low-power modes supported by PSoC 6.
Hibernate mode is the lowest power mode in the PSoC 6 MCU and on wakeup, the CPU and all peripherals go through a
reset.
19.1 Features
The PSoC 6 MCU power modes have the following features:
■ Four system and three CPU power modes aimed at optimizing power consumption in an application
■ System ULP mode with reduced operating current and clock frequency while supporting full device functionality
■ System Deep Sleep mode with support for multiple wakeup sources and configurable amount of SRAM retention
■ System Hibernate mode with wakeup from I/O, comparator, WDT, RTC, and timer alarms
The power consumption in different power modes is further controlled by using the following methods:
■ Enabling and disabling clocks to peripherals
■ Powering on/off clock sources
■ Powering on/off peripherals and resources inside the PSoC 6 device
19.2 Architecture
The PSoC 6 device supports multiple power modes. Some modes only affect the CPUs (CPU power modes) and others affect
the whole system (system power modes). The system and CPU power modes are used in combination to control the total
system performance and power. CPU power modes are entered separately for each CPU on the device.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 225
Device Power Modes
The SysPm Peripheral Driver Library (PDL) driver supports all device power mode transitions and is the recommended
method of transition and configuration of PSoC 6 MCU power resources.
Table 19-1 summarizes the power modes available in PSoC 6 MCUs, their description, and details on their entry and exit
conditions.
Table 19-1. PSoC 6 MCU Power Modes
System MCU
Wakeup Wakeup
Power Power Description Entry Conditions
Sources Action
Mode Mode
Reset from external reset, brownout,
System – Primary mode of operation. 1.1 power on reset system and Hibernate
V core voltage. All peripherals are avail- mode. Manual register write from sys-
Active able (programmable). Maximum clock fre- tem ULP mode. Wakeup from CPU Not applicable N/A
quencies Sleep or CPU Deep Sleep while in sys-
CPU – Active mode tem LP mode. Wakeup from system
Deep Sleep after entered from LP mode.
1.1 V core voltage. One or more CPUs in
LP In system LP mode, CPU executes WFI/
Sleep mode (execution halted). All periph- Any interrupt to
Sleep WFE instruction with Deep Sleep dis- Interrupt
erals are available (programmable). Maxi- CPU
abled
mum clock frequencies
1.1 V core voltage. One CPU in Deep
Sleep mode (execution halted). Other In system LP mode, CPU executes WFI/
Deep Any interrupt to
CPU in Active or Sleep mode. All periph- WFE instruction with Deep Sleep Interrupt
Sleep CPU
erals are available (programmable). Maxi- enabled
mum clock frequencies
Manual register write from system LP
0.9 V core voltage. All peripherals are mode. Wakeup from CPU Sleep or CPU
Active available (programmable). Limited clock Deep Sleep while in system ULP mode. Not applicable N/A
frequencies. No Flash write. Wakeup from system Deep Sleep after
entered from ULP mode.
0.9 V core voltage. One or more CPUs in
In system ULP mode, CPU executes
Sleep mode (execution halted). All periph- Any interrupt to
ULP Sleep WFI/WFE instruction with Deep Sleep Interrupt
erals are available (programmable). Lim- CPU
disabled
ited clock frequencies. No Flash write.
0.9 V core voltage. One CPU in Deep
Sleep mode (execution halted). Other In system ULP mode, CPU executes
Deep Any interrupt to
CPU in Active or Sleep mode. All periph- WFI/WFE instruction with Deep Sleep Interrupt
Sleep CPU
erals are available (programmable). Lim- enabled
ited clock frequencies. No Flash write.
All high-frequency clocks and peripherals GPIO interrupt,
are turned off. Low-frequency clock (32 Low-Power
Deep Deep kHz) and low-power analog and digital Both CPUs simultaneously in CPU Deep comparator,
Interrupt
Sleep Sleep peripherals are available for operation Sleep mode. SCB, watchdog
and as wakeup sources. SRAM is timer, and RTC
retained (programmable). alarms
GPIO states are frozen. All peripherals
and clocks in the device are completely WAKEUP pin,
turned off except optional low-power com- low- power com-
parators and backup domain. Wakeup is Manual register write from LP or ULP parator, watch- Reset
Hibernate N/A
possible through WAKEUP pins, XRES, modes.
dog timera, and
low-power comparator (programmable),
WDT, and RTC alarms (programmable). RTCb alarms
Device resets on wakeup.
a. Watchdog timer is capable of generating a hibernate wakeup. See the Watchdog Timer chapter on page 283 for details.
b. RTC (along with WCO) is part of the backup domain and is available irrespective of the device power mode. RTC alarms are capable of waking up the device
from any power mode.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 226
Device Power Modes
19.2.1 CPU Power Modes voltage, which then requires reduced operating clock
frequency and limited high-frequency clock sources. Flash
The CPU Active, Sleep, and Deep Sleep modes are the write operations are not available in ULP mode. Table 19-5
standard Arm-defined power modes supported by both provides the list of resources available in ULP mode along
Cortex-M4 and Cortex-M0+ CPUs. All Arm CPU power with limitations.
modes are available in both system LP and ULP power
modes. CPU power modes affect each CPU independently. While in system ULP mode, the CPUs may operate in any of
the standard Arm-defined CPU modes detailed in 19.2.1
19.2.1.1 CPU Active Mode CPU Power Modes.
In CPU Active mode, the CPU executes code and all logic Transitioning between LP and ULP modes is performed by
and memory is powered. The firmware may decide to reducing the core regulator voltage from the LP mode
enable or disable specific peripherals and power domains voltage to the ULP mode voltage. The lower voltage reduces
depending on the application and power requirements. All system operating current and slows down signal speeds
the peripherals are available for use in Active mode. The requiring a lower maximum operating frequency. Refer to
device enters CPU Active mode upon any device reset or Core Operating Voltage section in Power Supply and
wakeup. Monitoring chapter on page 218 for details on how to switch
between LP and ULP modes.
19.2.1.2 CPU Sleep Mode
19.2.3 System Deep Sleep Mode
In CPU Sleep mode, the CPU clock is turned off and the
CPU halts code execution. Note that in the PSoC 6 MCU, In system Deep Sleep mode, all the high-speed clock
Cortex-M4 and Cortex-M0+ both support their own CPU sources are off. This in turn makes high-speed peripherals
Sleep modes and each CPU can be in sleep independent of unusable in system Deep Sleep mode. However, low-speed
the other CPU state. All peripherals available in Active mode clock sources and peripherals may continue to operate, if
are also available in Sleep mode. Any peripheral interrupt, configured and enabled by the firmware. In addition, the
masked to the CPU, will wake the CPU to Active mode. Only peripherals that do not need a clock or receive a clock from
the CPU(s) with the interrupt masked will wake. their external interface (I2C or SPI slave) may continue to
operate, if configured for system Deep Sleep operation. The
19.2.1.3 CPU Deep Sleep Mode PSoC 6 MCU provides an option to configure the amount of
SRAM, in blocks of 32 KB, that are retained during Deep
In CPU Deep Sleep mode, the CPU requests the device to Sleep mode.
go into system Deep Sleep mode. When the device is ready,
it enters Deep Sleep mode as detailed in 19.2.3 System Both Cortex-M0+ and Cortex-M4 can enter CPU Deep
Deep Sleep Mode. Sleep mode independently. However, the entire device
enters system Deep Sleep mode only when both the CPUs
Because PSoC 6 has more than one CPU, both CPUs must are in CPU Deep Sleep. On wakeup, the CPU that woke up
independently enter CPU Deep Sleep before the system will enters CPU Active mode and the other CPU remains in CPU
transition to system Deep Sleep. Deep Sleep mode. On wakeup, the system will return to LP
or ULP mode based on what mode was Active before
19.2.2 System Power Modes entering system Deep Sleep. Both CPUs may wake up to
CPU Active simultaneously from the same wakeup source if
System power modes affect the whole device and may be so configured.
combined with CPU power modes.
The device enters system Deep Sleep mode after the
19.2.2.1 System Low Power Mode following conditions are met.
■ The LPM_READY bit of the PWR_CTL register should
System Low Power (LP) mode is the default operating mode
read ‘1’. This ensures the system is ready to enter Deep
of the device after reset and provides maximum system
Sleep. If the bit reads ‘0’, then the device will wait in
performance. In LP mode all resources are available for
system LP or ULP mode instead of system Deep Sleep
operation at their maximum power level and speed.
until the bit is set, at which instant the device
While in system LP mode the CPUs may operate in any of automatically enters Deep Sleep mode, if requested.
the standard Arm defined CPU modes detailed in 19.2.1 ■ Both Cortex-M0+ and Cortex-M4 must be in CPU Deep
CPU Power Modes. Sleep. This is achieved by setting the SLEEPDEEP bit
[2] of the SCR register of both Cortex-M0+ and Cortex-
19.2.2.2 System Ultra Low Power Mode M4 and then executing WFI or WFE instruction.
System Ultra Low Power (ULP) mode is identical to LP ■ The HIBERNATE bit [31] of the PWR_HIBERNATE
mode with a performance tradeoff made to achieve lower register should be cleared; otherwise, the device will
system current. This tradeoff lowers the core operating enter system Hibernate mode.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 227
Device Power Modes
In system Deep Sleep mode, the LP and ULP mode stable. In addition, make sure the supply is stable for at least
regulator is turned off and a lower power, Deep Sleep 250 µs before the device enters Hibernate mode. To prevent
regulator sources all the peripherals enabled in system accidental entry into Hibernate mode in applications that
Deep Sleep mode. Alternatively, the buck regulator can be cannot meet these requirements, an option to disable the
used to power the Deep Sleep peripherals. See the Power Hibernate mode is provided. Set the HIBERNATE_DISABLE
Supply and Monitoring chapter on page 218 for details. bit [30] of the PWR_HIBERNATE register to disable
Table 19-5 provides the list of resources available in system Hibernate mode in the device. Note that this bit is a write-
Deep Sleep mode. once bit during execution and is cleared only on reset.
Debug functionality will be lost and the debugger will
Interrupts from low-speed, asynchronous, or low-power
disconnect on entering Hibernate mode.
analog peripherals can cause a CPU wakeup from system
Deep Sleep mode. Note that when a debugger is running on 19.2.5 Other Operation Modes
either core, the device stays in system LP or ULP mode and
In addition to the power modes discussed in the previous
the CPUs enter CPU Sleep mode instead of CPU Deep
sections, there are three other states the device can be in –
Sleep mode. PSoC 6 uses buffered writes. Therefore, writes
Reset, Off, and Backup states. These states are determined
to an MMIO register or memory can take few a cycles from
by the external power supply and XRES connections. No
the write instruction execution. The only way to ensure that
firmware action is required to enter these modes nor an
the write operation is complete is by reading the same
interrupt or wakeup event to exit them.
location after the write. It is required to follow a write by a
read to the same location before executing a WFI/WFE 19.2.5.1 Backup Domain
instruction to enter CPU Deep Sleep mode.
PSoC 6 offers an independent backup supply option that
19.2.4 System Hibernate Mode can be supplied through a separate Vbackup pin. For details
on the backup domain and the powering options, refer to the
System Hibernate mode is the lowest power mode of the
Backup System chapter on page 235. This domain powers a
device when external supplies are still present and XRES is
real-time clock (RTC) block, WCO, and a small set of
deasserted. It is intended for applications in a dormant state.
backup registers. Because the power supply to these blocks
In this mode, both the Active LP/ULP mode regulator and
come from a dedicated Vbackup pin, these blocks continue
Deep Sleep regulator are turned off and GPIO states are
to operate in all CPU and system power modes, and even
automatically frozen. Wakeup is facilitated through
when the device power is disconnected or held in reset as
dedicated wakeup pins and a Low-Power comparator
long as a Vbackup supply is provided. The RTC present in
output. Low-Power comparator operation in Hibernate mode
the backup domain provides an option to wake up the
requires externally generated voltages for wakeup
device from any CPU or system power mode. The RTC can
comparison. Internal references are not available in
be clocked by an external crystal (WCO) or the internal low-
Hibernate mode. Optionally, an RTC alarm from the backup
speed oscillator (ILO). However, the ILO is available only if
domain or a watchdog timer (16-bit free-running WDT)
the device is powered – the device should not be in the off or
interrupt can generate a Hibernate wakeup signal. Set the
reset state. Using ILO is not recommended for timekeeping
MASK_HIBALARM bit [18] of the PWR_HIBERNATE
purpose; however, it can be used for wakeup from Hibernate
register to enable the RTC alarm wakeup from Hibernate
power mode.
mode.
The device goes through a reset on wakeup from Hibernate. 19.2.5.2 Reset State
I/O pins remain in the configuration they were frozen before Reset is the device state when an external reset (XRES pin
entering Hibernate mode. To differentiate between other pulled low) is applied or when POR/BOD is asserted. Reset
system resets and a Hibernate mode wakeup, the TOKEN is not a power mode. During the reset state, all the
bits [7:0] of the PWR_HIBERNATE register can be used as components in the device are powered down and I/Os are
described in the Power Mode Transitions on page 230. The tristated, keeping the power consumption to a minimum.
PWR_HIBERNATE (except the HIBERNATE bit [31])
register along with the PWR_HIB_DATA register are 19.2.5.3 Off State
retained through the Hibernate wakeup sequence and can The off state simply represents the device state with no
be used by the application for retaining some content. Note power applied. Even in the device off state, the backup
that these registers are reset by other reset events. On a domain can continue to receive power (Vbackup pin) and
Hibernate wakeup event, the HIBERNATE bit [31] of the run the peripherals present in that domain. The reset and off
PWR_HIBERNATE register is cleared. states are discussed for completeness of all possible modes
and states the device can be in. These states can be used in
The brownout detect (BOD) block is not available in
a system to further optimize power consumption. For
Hibernate mode. As a result, the device does not recover
instance, the system can control the supply of the PSoC 6
from a brownout event in Hibernate mode. Do not enter
MCU by enabling or disabling the regulator output powering
Hibernate mode in applications that require brownout
the device using the PMIC interface.
detection, that is, applications where the supply is not
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 228
Device Power Modes
O ff
XRES/
X R E S /P O R /B O D
d e a s s e rt XRES P O R /B O D
a s s e rt
S y s te m L P S y s te m U L P
(1 .1 V C o re ) (0 .9 V C o re )
F irm w a re
C P U A c tiv e a c tio n C P U A c tiv e F irm w a re
a c tio n
C P U S le e p / C P U S le e p /
D e e p s le e p D e e p s le e p
B o th
C P U s in
D e e p s le e p D e e p s le e p D e e p s le e p D e e p s le e p D e e p s le e p
in te rru p t fo r in te rru p t fo r in te rru p t fo r in te rru p t fo r
th is C P U o th e r C P U o th e r C P U th is C P U
S y s te m
D e e p s le e p
W akeup S y s te m
a s s e rt
H ib e rn a te
LEGEND:
R eset event
F irm w a re a c tio n
H ib e rn a te w a k e u p e v e n ts
P e rip h e ra l in te rru p ts /
H a rd w a re e v e n ts
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 229
Device Power Modes
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 230
Device Power Modes
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 231
Device Power Modes
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 232
Device Power Modes
19.4 Summary
Table 19-5. Resources Available in Different Power Modes
Power Modes
LP ULP
Component Power Off
CPU Sleep/ CPU Sleep/ Deep Sleep Hibernate XRES
CPU Active CPU Active with Backup
Deep Sleep Deep Sleep
Core functions
CPU On Sleep On Sleep Retention Off Off Off
SRAM On On On On Retention Off Off Off
Flash Read/Write Read/Write Read Only Read Only Off Off Off Off
High-Speed Clock
On On On On Off Off Off Off
(IMO, ECO, PLL, FLL)
LVD On On On On Off Off Off Off
ILO On On On On On On Off Off
Peripherals
SMIF/SHDC On On On On Retention Off Off Off
SAR ADC On On On On On Off Off Off
LPCMP On On On On a a Off Off
On On
TCPWM On On On On Off Off Off Off
CSD On On On On Retention Off Off Off
LCD On On On On On Off Off Off
Retention (I2C/SPI
SCB On On On On Off Off Off
wakeup available)b
GPIO On On On On On Freeze Off Off
Watchdog timer On On On On On On Off Off
Multi-Counter WDT On On On On On Off Off Off
Resets
XRES On On On On On On On Off
POR On On On On On On Off Off
BOD On On On On On Off Off Off
Watchdog reset On On On On On Onc Off Off
Backup domain
WCO, RTC, alarms On On On On On On On On
a. Low-Power comparator may be optionally enabled in the Hibernate mode to generate wakeup.
b. Only the SCB with system Deep Sleep support is available in the Deep Sleep power mode; other SCBs are not available in the Deep Sleep power mode.
c. Watchdog interrupt can generate a Hibernate wakeup. See the Watchdog Timer chapter on page 283 for details.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 233
Device Power Modes
Name Description
Cortex-M0+ System Control register – controls the CM0+ CPU sleep and deep sleep decisions on the WFI/
CM0P_SCS_SCR WFE instruction execution. This register is detailed in the ARMv7-M Architecture Reference Manual available
from Arm
Controls the CM0+ power state. Note that this register may only be modified by the CM4 while the CM0+ is in
CPUSS_CM0_CTL
CPU Deep Sleep mode
CPUSS_CM0_STATUS Specifies if the CM0+ is in CPU Active, Sleep, or Deep Sleep power mode
Controls the CM4 power state. Note that this register may only be modified by the CM0+ while the CM4 is in
CPUSS_CM4_PWR_CTL
CPU Deep Sleep mode.
CPUSS_CM4_STATUS Specifies if the CM4 is in CPU Active, Sleep, or Deep Sleep power mode
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 234
20. Backup System
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The Backup domain adds an “always on” functionality to PSoC 6 MCUs using a separate power domain supplied by a backup
supply (VBACKUP) such as a battery or supercapacitor. It contains a real-time clock (RTC) with alarm feature, supported by a
32768-Hz watch crystal oscillator (WCO), and power-management IC (PMIC) control.
Backup is not a power mode; it is a power domain with its own power supply, which can be active during any of the device
power modes. For more details, see the Power Supply and Monitoring chapter on page 218 and Device Power
Modes chapter on page 225.
20.1 Features
■ Fully-featured RTC
❐ Year/Month/Date, Day-of-Week, Hour : Minute : Second fields
❐ All fields binary coded decimal (BCD)
❐ Supports both 12-hour and 24-hour formats
❐ Automatic leap year correction
■ Configurable alarm function
❐ Alarm on Month/Date, Day-of-Week, Hour : Minute : Second fields
❐ Two independent alarms
■ 32768-Hz WCO with calibration
■ Automatic backup power switching
■ Built-in supercapacitor charger
■ External PMIC control
■ 32-byte backup registers
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 235
Backup System
20.2 Architecture
Figure 20-1. Block Diagram
AHB-Lite Bus
Config Config
PMIC_W akeup_In
W atch
Backup PMIC_W akeup_Out
Crystal
Registers
Oscillator
(32 bytes)
(W CO) (Controls an External
Power Management IC)
LFCLK
(from System Resources)
WCO_IN W CO_OUT
(Crystal and Capacitor Connections /
External Clock Input)
The Backup system includes an accurate WCO that can The VDDBAK_CTL bitfield in the BACKUP_CTL register
generate the clock required for the RTC with the help of an controls the behavior of the power selector switch. See the
external crystal or external clock inputs. The RTC has a registers TRM for details of this register. Possible options
programmable alarm feature, which can generate interrupts are:
to the CPU. An AHB-Lite interface provides firmware access ■ VDDBAK_CTL = 0 (Default mode): Selects VDDD when
to MMIO registers in the Backup domain.
the brownout detector in the system resources is
An automatic backup power switch selects the VDDBAK enabled and no brownout situation is detected (see the
supply required to run the blocks in the Backup domain – Power Supply and Monitoring chapter on page 218 for
either VDDD (main power) or VBACKUP (backup battery/ more details). Otherwise, it selects the highest supply
supercapacitor power). among VDDD and VBACKUP.
■ VDDBAK_CTL = 1, 2, or 3: Always selects VBACKUP for
The domain also has backup registers that can store 32
bytes of data and retain its contents even when the main debug purposes.
supply (VDDD) is OFF as long as the backup supply If a supercapacitor is connected to VBACKUP, the PSoC 6
(VBACKUP) is present. The Backup system can also control MCU can charge the supercapacitor while VDDD is available.
an external PMIC that supplies VDDD. Supercapacitor charging can be enabled by writing “3C” to
the EN_CHARGE_KEY bitfield in the BACKUP_CTL
register. Note that this feature is for charging
20.3 Power Supply supercapacitors only and cannot safely charge a battery. Do
not write this key when VBACKUP is connected to a battery.
Power to the backup system (VDDBAK) is automatically
Battery charging must be handled at the board level using
switched between VDDD (main supply) and VBACKUP
external circuitry.
(Backup domain supply). VBACKUP is typically connected to
an independent supply derived from a battery or Note: If VDDD and VBACKUP are connected on the PCB, the
supercapacitor (see the Power Supply and Backup domain may require an explicit reset triggered by
Monitoring chapter on page 218 for more details). firmware using the RESET bitfield in the BACKUP_RESET
register. This firmware reset is required if the VBACKUP
There are no VBACKUP versus VDDD sequencing restrictions
supply was invalid during a previous power supply ramp-up
for the power selector switch. Either VBACKUP or VDDD may or brownout event. It is not necessary to reset the Backup
be removed during normal operation, and the Backup domain if the RES_CAUSE register indicates a non-power-
system will remain powered. related reset as the reset cause, or if the PSoC 6 MCU just
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 236
Backup System
woke from the Hibernate power mode and the supply is 20.4.1 WCO with External Clock/Sine
assumed to have been valid the entire time.
Wave Input
It is possible to monitor the VBACKUP supply using an ADC
The WCO can also operate from external clock/sine wave
attached to AMUXBUS-A by setting the VBACKUP_MEAS inputs. In these modes, WCO must be bypassed by setting
bit in the BACKUP_CTL register. Note that the VBACKUP the WCO_BYPASS bit in the BACKUP_CTL register before
signal is scaled by 10 percent so it is within the supply range enabling the WCO. Also, GPIOs must be configured for
of the ADC. See the SAR ADC chapter on page 506 for WCO_OUT and WCO_IN signals (in Analog mode). The
more details on how to connect the ADC to AMUXBUS-A. external clock/sine wave input modes, prescaler settings,
and electrical connections are as follows:
20.4 Clocking ■ 32768-Hz external clock mode: In this mode, WCO_IN is
floating and WCO_OUT is externally driven by a 32768-
The RTC primarily runs from a 32768-Hz clock, after it is Hz square wave clock toggling between ground and
scaled down to one-second ticks. This clock signal can VDDD supply levels. In this configuration, the WCO_OUT
come from either of these internal sources: pin functions as a digital input pin for the external clock.
■ Watch-crystal oscillator (WCO). This is a high-accuracy The PRESCALER bitfield in BACKUP_CTL must be
clock generator that is suitable for RTC applications and configured for a prescaler value of 32768.
requires a 32768-Hz external crystal populated on the ■ 60-Hz external clock mode: This mode can be used for
application board. WCO can also operate without deriving a clock from the 60-Hz AC mains supply. In this
crystal, using external clock/sine wave inputs. These mode, WCO_OUT is floating and WCO_IN is driven with
additional operating modes are explained later in this an external sine wave with zero DC offset, derived from
section. WCO is supplied by the Backup domain and can the 60-Hz/120-V mains through a 100:1 capacitive
therefore run without VDDD present. divider. For example, a suitable capacitive divider can be
■ Alternate Backup Clock (ALTBAK): This option allows formed by connecting a 220-pF/6-V capacitor between
the use of LFCLK generated by the System Resources WCO_IN and ground, and a 2.2-pF/ 200-V capacitor
Subsystem (SRSS) as the Backup domain clock. Note between WCO_IN and the 60-Hz/120-V mains input.
that LFCLK is not available in all device power modes or The PRESCALER bitfield in BACKUP_CTL must be
when the VDDD is removed. (See the Device Power configured for a prescaler value of 60.
Modes chapter on page 225 for more detail.) ■ 50-Hz external clock mode: This mode is similar to the
60-Hz mode, and can be used for 50-Hz/220-V mains
Clock glitches can propagate into the Backup system
standard. The capacitive divider explained previously
when LFCLK is enabled or disabled by the SRSS. In
can be modified to fit this type of supply by having a 1-pF
addition, LFCLK may not be as accurate as WCO
/250-V capacitor between WCO_IN and the mains input.
depending on the actual source of LFCLK. Because of
The PRESCALER bitfield in BACKUP_CTL must be
these reasons, LFCLK is not recommend for RTC
configured for a prescaler value of 50.
applications. Also, if the WCO is intended as the clock
source then choose it directly instead of routing through
LFCLK. 20.4.2 Calibration
For more details on these clocks and calibration, see the The absolute frequency of the clock input can be calibrated
Clocking System chapter on page 242. using the BACKUP_CAL_CTL register. Calibration only
works when the PRESCALER bitfield in BACKUP_CTL is
The RTC clock source can be selected using the CLK_SEL set to 32768.
bitfield in the BACKUP_CTL register. The WCO_EN bit in
the BACKUP_CTL register can be used to enable or disable CALIB_VAL is a 6-bit field in the BACKUP_CAL_CTL
the WCO. If the WCO operates with an external crystal, register that holds the calibration value for absolute
make sure the WCO_BYPASS bit in the BACKUP_CTL frequency (at a fixed temperature). One bit of this field
register is cleared before enabling the WCO. In addition, the translates into 128 ticks to be added or removed from the
PRESCALER bitfield in BACKUP_CTL must be configured clock count. Therefore, each bit translates to a change of
for a prescaler value of 32768. 1.085 ppm (= 128/(60*60*32768)).
Note: External crystal and bypass capacitors of proper The CALIB_SIGN field in the BACKUP_CAL_CTL register
values must be connected to WCO_IN and WCO_OUT and controls whether the ticks are added (it takes fewer clock
pins. See the PSoC 61 datasheet/PSoC 62 datasheet for ticks to count one second) or subtracted (it takes more clock
details of component values and electrical connections. In ticks to count one second).
addition, GPIOs must be configured for WCO_OUT and
For more information, see the BACKUP_CAL_CTL register
WCO_IN signals. See the I/O System chapter on page 261
in the registers TRM.
to know how to configure the GPIOs.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 237
Backup System
20.5 Reset
The PSoC 6 MCU reset sources that monitor device power supply such as power-on reset (POR) and brownout reset (BOD)
cannot reset the backup system as long as the backup supply (VDDBAK) is present. Moreover, internal and external resets
such as watchdog timer (WDT) reset and XRES cannot reset the backup system. The backup system is reset only when:
■ all the power supplies are removed from the Backup domain, also known as a “cold-start”.
■ the firmware triggers a Backup domain reset using the RESET bitfield in the BACKUP_RESET register.
BCD encoding indicates that each four-bit nibble represents registers require special care. These processes are
one decimal digit. Constant bits are omitted in the RTC explained in the following section.
implementation. For example, the maximum RTC_SEC is
59, which can be represented as two binary nibbles 0101b 20.6.1 Reading RTC User Registers
1001b. However, the most significant bit is always zero and
is therefore omitted, making the RTC_SEC a 7-bit field. To start a read transaction, the firmware should set the
READ bit in the BACKUP_RTC_RW register. When this bit
The RTC supports both 12-hour format with AM/PM flag, is set, the RTC registers will be copied to user registers and
and 24-hour format for “hours” field. The RTC also includes frozen so that a coherent RTC value can safely be read by
a “day of the week” field, which counts from 1 to 7. You the firmware. The read transaction is completed by clearing
should define which weekday is represented by a value of the READ bit.
‘1’.
The READ bit cannot be set if:
The RTC implements automatic leap year correction for the
Date field (day of the month). If the Year is divisible by 4, the ■ RTC is still busy with a previous operation (that is, the
month of February (Month=2) will have 29 days instead of RTC_BUSY bit in the BACKUP_STATUS register is set)
28. When the year reaches 2100 - the Year field rolls over ■ WRITE bit in the BACKUP_RTC_RW register is set
from 99 to 00 - the leap year correction will be wrong (2100
The firmware should verify that the above bits are not set
is flagged as a leap year which it is not); therefore, an
before setting the READ bit.
interrupt is raised to allow the firmware to take appropriate
actions. This interrupt is called the century interrupt.
20.6.2 Writing to RTC User Registers
User registers containing these bitfields are
BACKUP_RTC_TIME and BACKUP_RTC_DATE. See the When the WRITE bit in the BACKUP_RTC_RW register is
corresponding register descriptions in the registers TRM for set, data can be written into the RTC user registers;
details. As the user registers are in the high-frequency bus- otherwise, writes to the RTC user registers are ignored.
clock domain and the actual RTC registers run from the low- When all the RTC writes are done, the firmware must clear
frequency 32768-Hz clock, reading and writing RTC the WRITE bit for the RTC update to take effect. After the
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 238
Backup System
WRITE bit is cleared, the hardware will copy all the new data cleared by a WRITE transaction. If the write operation is in
on one single WCO clock edge to ensure coherency to the progress (RTC_BUSY), data corruption can occur if the
actual RTC registers. system is reset or enters Deep Sleep or Hibernate mode.
The WRITE bit cannot be set if:
■ RTC is still busy with a previous operation (that is, the 20.7 Alarm Feature
RTC_BUSY bit in the BACKUP_STATUS register is set)
The Alarm feature allows the RTC to be used to generate an
■ READ bit in the BACKUP_RTC_RW register is set
interrupt, which may be used to wake up the system from
The firmware should make sure that the values written to the Sleep, Deep Sleep, and Hibernate power modes.
RTC fields form a coherent legal set. The hardware does not
The Alarm feature consists of six fields corresponding to the
check the validity of the written values. Writing illegal values
fields of the RTC: Month/Date, Day-of-Week, and
results in undefined behavior of the RTC.
Hour : Minute : Second. Each Alarm field has an enable bit
When in the middle of an RTC update with the WRITE bit that needs to be set to enable matching; if the bit is cleared,
set, and a brownout, reset, or entry to Deep Sleep or then the field will be ignored for matching.
Hibernate mode occurs, the write operation will not be
The Alarm bitfields are as follows:
complete. This is because the WRITE bit will be cleared by
a reset, and the RTC update is triggered only when this bit is
If the master enable (ALM_EN) is set, but all alarm fields for date and time are disabled, an alarm interrupt will be generated
once every second. Note that there is no alarm field for Year because the life expectancy of a chip is about 20 years and thus
setting an alarm for a certain year means that the alarm matches either once or never in the lifetime of the chip.
The PSoC 6 MCU has two independent alarms. See the BACKUP_ALM1_TIME, BACKUP_ALM1_DATE,
BACKUP_ALM2_TIME, and BACKUP_ALM2_DATE registers in the registers TRM for details.
Note that the alarm user registers, similar to RTC user registers, require certain special steps before read/write operations, as
explained in sections Reading RTC User Registers on page 238 and Writing to RTC User Registers on page 238.
Interrupts must be properly configured for the RTC to generate interrupts/wake up events. Also, to enable RTC interrupts to
wake up the device from Hibernate mode, the MASK_HIBALARM bit in the PWR_HIBERNATE register must be set. See the
Device Power Modes chapter on page 225 and Interrupts chapter on page 56 for details.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 239
Backup System
The BACKUP_INTR_MASK register can be used to disable certain interrupts from the backup system.
The RTC alarm can also control an external PMIC as explained in the following section.
Note that two writes to the BACKUP_PMIC_CTL register removed. The time between firmware disabling the
are required to change the PMIC_EN setting. The first write PMIC_EN bit and the actual removal of VDDD depends on
should update the desired settings (including the UNLOCK the external PMIC and supply-capacitor characteristics.
code) but should not change PMIC_EN or
Additionally, PMIC can be turned on by one of these events:
PMIC_EN_OUTEN. The second write must use the same bit
values as the first one except desired PMIC_EN/ ■ An RTC Alarm/Century Interrupt
PMIC_EN_OUTEN settings. ■ A logic high input at the PMIC_Wakeup_In pin. See the
PSoC 61 datasheet/PSoC 62 datasheet for the location
When the PMIC_EN bit is cleared by firmware, the external
of this pin. This allows a mechanical button or an
PMIC is disabled and the system functions normally until
external input from another device to wake up the
VDDD is no longer present (OFF with Backup mode). The
system and enable the PMIC. The POLARITY bit in the
firmware can set this bit if it does so before VDDD is actually
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 240
Backup System
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 241
21. Clocking System
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
PSoC 6 MCU provides flexible clocking options with on-chip crystal oscillators, phase lock loop, frequency lock loop, and
supports multiple external clock sources.
21.1 Features
The PSoC 6 MCU clock system includes these resources:
■ Two internal clock sources:
❐ 8-MHz internal main oscillator (IMO)
❐ 32-kHz internal low-speed oscillator (ILO)
■ Three external clock sources
❐ External clock (EXTCLK) generated using a signal from an I/O pin
❐ External 16–35 MHz crystal oscillator (ECO)
❐ External 32-kHz watch crystal oscillator (WCO)
■ One frequency lock loop (FLL) with 24–100 MHz output range
■ Two phase-locked loop (PLL) with 10.625–150 MHz output range
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 242
Clocking System
21.2 Architecture
Figure 21-1 gives a generic view of the clocking system in PSoC 6 MCUs.
Figure 21-1. Clocking System Block Diagram
Path Mux (FLL/PLLs) Root Clock mux (Clks_HF[i] are Root Clocks)
CM4
Clock
Predivider CLK_HF[0]
FLL (1/2/4/8) CM0+
IMO clk_peri
Clock
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 243
Clocking System
21.3 Clock Sources sets the crystal drive level when automatic gain control
(AGC) is enabled (CLK_ECO_CONFIG.AGC_EN = 1). AGC
must be enabled all the time.
21.3.1 Internal Main Oscillator (IMO)
ATRIM and WDTRIM values are set at 15 and 7,
The IMO is an accurate, high-speed internal (crystal-less) respectively.
oscillator that produces a fixed frequency of 8 MHz. The
IMO output can be used by the PLL or FLL to generate a The GTRIM sets up the trim for amplifier gain based on the
wide range of higher frequency clocks, or it can be used calculated gm, as shown in Table 21-1.
directly by the high-frequency root clocks.
Table 21-1. GTRIM Settings
When USB is present the USB Start-of-Frame (SOF) signal
gm GTRIM
is used to trim the IMO to ensure that the IMO matches the
accuracy of the USB SOF. The ENABLE_LOCK bitfield in gm < 9 mA/V 0x01
the USBFS0_USBDEV_CR register of the USB block needs 9 mA/V < gm < 18 mA/V 0x00
to be set for this feature to work. The driver for the USB
block in the PDL does this automatically. gm > 18 mA/V INT (gm / 9 mA/V)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 244
Clocking System
the MCWDT timers; see the Watchdog Timer chapter on 21.3.5 Watch Crystal Oscillator (WCO)
page 283 for details.
The WCO is a highly accurate 32.768-kHz clock source. It is
The ILO is always the source of the watchdog timer (WDT). the primary clock source for the RTC. The WCO can also be
The ILO is enabled and disabled with the ENABLE bit of the used as a source for CLK_LF.
CLK_ILO_CONFIG register. Always leave the ILO enabled The WCO can be enabled and disabled by setting the
as it is the source of the WDT. WCO_EN bit in the CTL register for the backup domain. The
If the WDT is enabled, the only way to disable the ILO is to WCO can also be bypassed and an external 32.768-kHz
first clear the WDT_LOCK bit in the WDT_CTL register and clock can be routed on a WCO output pin. This is done by
then clear the ENABLE bit in the CLK_ILO_CONFIG setting the WCO_BYPASS bit in the CTL register for the
register. If the WDT_LOCK bit is set, any register write to backup domain. See WCO with External Clock/Sine Wave
disable the ILO will be ignored. Enabling the WDT will Input on page 237 for more details.
automatically enable the ILO.
The calibration counters described in Clock Calibration 21.4 Clock Generation
Counters on page 256 can be used to measure the ILO
against a high-accuracy clock such as the ECO. This result
21.4.1 Phase-Locked Loop (PLL)
can then be used to determine how the ILO must be
adjusted. The ILO can be trimmed using the The PSoC 6 MCU contains two PLLs, which reside on
CLK_TRIM_ILO_CTL register. CLK_PATH1 and CLK_PATH2. They are capable of
generating a clock output in the range 10.625–150 MHz; the
input frequency must be between 4 and 64 MHz. This
makes it possible to use the IMO to generate much higher
clock frequencies for the rest of the system.
Figure 21-2. PLL Block Diagram
Lock
Detect Bypass
Reference Logic
Clock
Reference
Divider (Q) Voltage
Phase Charge control Output PLL OUT
Detector pump Oscillator Divider
Feedback (VCO)
Divider (P)
The PLL is configured following these steps: granularity; therefore, consider the frequency error of
the two closest choices.
Note: fref is the input frequency of the PLL, that is, the
d. Choose the best combination of divider parameters
frequency of input clock, such as 8 MHz for the IMO.
depending on the application. Some possible
1. Determine the desired output frequency (fout). Calculate decision-making factors are: minimum output
the reference (REFERENCE_DIV), feedback frequency error, lowest power consumption (lowest
(FEEDBACK_DIV), and output (OUTPUT_DIV) dividers fvco), or lowest jitter (highest fvco).
subject to the following constraints:
2. Program the divider settings in the appropriate
a. PFD frequency (phase detector frequency). fpfd = fref CLK_PLL_CONFIG register. Do not enable the PLL on
/ REFERENCE_DIV. It must be in the range 4 MHz the same cycle as configuring the dividers. Do not
to 8 MHz. There may be multiple reference divider change the divider settings while the PLL is enabled.
values that meet this constraint.
3. Enable the PLL (CLK_PLL_CONFIG.ENABLE = 1). Wait
b. VCO frequency. fvco = fpfd * FEEDBACK_DIV. It must at least 1 µs for PLL circuits to start.
be in the range 170 MHz to 400 MHz. There may be 4. Wait until the PLL is locked before using the output. By
multiple feedback divider values that meet this default, the PLL output is bypassed to its reference clock
constraint with different REFERENCE_DIV choices. and will automatically switch to the PLL output when it is
c. Output frequency. fout = fvco / OUTPUT_DIV. It must locked. This behavior can be changed using
be in the range 10.625 MHz to 150 MHz. Note that PLL_CONFIG.BYPASS_SEL. The status of the PLL can
your device may not be capable of operating at this be checked by reading CLK_PLL_STATUS. This register
frequency; check the device datasheet. It may not be contains a bit indicating the PLL has locked. It also
possible to get the desired frequency due to contains a bit indicating if the PLL lost the lock status.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 245
Clocking System
To disable the PLL, first set the PLL_CONFIG.BYPASS_SEL is set by the FLL_REF_DIV field in the CLK_FLL_CONFIG2
to PLL_REF. Then wait at least six PLL output clock cycles register.
before disabling the PLL by setting PLL_CONFIG.ENABLE
After the CCO clocks are counted, they are compared
to ‘0’.
against an ideal value and an error is calculated. The ideal
value is programmed into the FLL_MULT field of the
21.4.2 Frequency Lock Loop (FLL) CLK_FLL_CONFIG register.
The PSoC 6 MCU contains one frequency lock loop (FLL), As an example, the reference clock is the IMO (8 MHz), the
which resides on Clock Path 0. The FLL is capable of desired CCO frequency is 100 MHz, the value for
generating a clock output in the range 24 MHz to 100 MHz; FLL_REF_DIV is set to 146. This means that the FLL will
the input frequency must be between 0.001 and 100 MHz, count the number of CCO clocks within 146 clock periods of
and must be at least 2.5 times less than the CCO frequency. the reference clock. In one clock cycle of the reference clock
This makes it possible to use the IMO to generate much (IMO), there should be 100 / 8 = 12.5 clock cycles of the
higher clock frequencies for the rest of the system. CCO. Multiply this number by 146 and the value of
The FLL is similar in purpose to a PLL but is not equivalent: FLL_MULT should be 1825.
■ FLL can start up (lock) much faster than the PLL. If the FLL counts a value different from 1825, it attempts to
■ It consumes less current than the PLL. adjust the CCO such that it achieves 1825 the next time it
counts. This is done by scaling the error term with
■ FLL does not lock the phase. At the heart of the FLL is a FLL_LF_IGAIN and FLL_LF_PGAIN found in
current-controlled oscillator (CCO). The output CLK_FLL_CONFIG3. Figure 21-3 shows how the error (err)
frequency of this CCO is controlled by adjusting the trim term is multiplied by FLL_LF_IGAIN and FLL_LF_PGAIN
of the CCO; this is done in hardware and is explained in and then summed with the current trim to produce a new
detail later in this section. trim value for the CCO. The CCO_LIMIT field in the
■ FLL can produce up to 100-MHz clock with good duty CLK_FLL_CONFIG4 can be used to put an upper limit on
cycle through its divided clock output. the trim adjustment; this is not needed for most situations.
■ FLL reference clock can be the WCO (32 kHz), IMO
(8 MHz), or any other periodic clock source.
Note: The CCO frequency must be at least 2.5 times
greater than the reference frequency.
The CCO can output a stable frequency in the 48 MHz to
200 MHz range. This range is divided into five sub-ranges
as shown by Table 21-2.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 246
Clocking System
PGAIN
X max
err + new_trim
X 0
IGAIN
current_trim
The FLL determines whether it is “locked” by comparing the error term with the LOCK_TOL field in the CLK_FLL_CONFIG2
register. When the error is less than LOCK_TOL the FLL is considered locked.
After each adjustment to the trim the FLL can be programmed to wait a certain number of reference clocks before doing a
new measurement. The number of reference clocks to wait is set in the SETTLING_COUNT field of CLK_FLL_CONFIG3. Set
this such that the FLL waits ~1 µs before a new count. Therefore, if the 8-MHz IMO is used as the reference this field should
be programmed to ‘8’.
When configuring the FLL there are two important factors that must be considered: lock time and accuracy. Accuracy is the
closeness to the intended output frequency. These two numbers are inversely related to each other via the value of REF_DIV.
Higher REF_DIV values lead to higher accuracy, whereas lower REF_DIV values lead to faster lock times.
In the example used previously the 8-MHz IMO was used as the reference, and the desired FLL output was 100 MHz. For
that example, there are 12.5 CCO clocks in one reference clock. If the value for REF_DIV is set to ‘1’ then FLL_MULT must
be set to either ‘13’ or ‘12’. This will result in a CCO output of either 96 MHz or 104 MHz, and an error of 4 percent from the
desired 100 MHz. Therefore, the best way to improve this is to increase REF_DIV. However, the larger REF_DIV is, the
longer each measurement cycle takes, thus increasing the lock time. In this example, REF_DIV was set to 146. This means
each measurement cycle takes 146 * (1/8 MHz) = 18.25 µs, whereas when REF_DIV is set to 1, each measurement cycle
takes 1 * (1/ 8 MHz) 0.125 µs.
Another issue with lower REF_DIV values is that the minimum LOCK_TOL is 1, so the output of the CCO can have an error of
±1. In the example where REF_DIV = 1 and FLL_MULT = 13, the MULT value can really be 12, 13, or 14 and still be locked.
This means the output of the FLL may vary between 96 and 112 MHz, which may not be desirable.
Thus, a choice must be made between faster lock times and more accurate FLL outputs. The biggest change to make for this
is the value of REF_DIV. The following section describes how to configure all of the FLL registers and gives some example
equations to set REF_DIV N for best accuracy.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 247
Clocking System
2 f ref
N = ROUNDUP -----------------------------------------------------------
CCO Trim Step f CCO T arg et
Equation 21-1
The CCOTrimStep is found in Table 21-4.
A larger N results in better precision on the FLL output, but longer lock times; a smaller N will result in faster lock times,
but less precision.
Note: When the WCO is used as the reference clock, N must be set to 19.
4. Set FLL_MULT in CLK_FLL_CONFIG.
FLL_MULT is the ratio between the desired CCO frequency and the divided input frequency. This is the ideal value for the
counter that counts the number of CCO clocks in one period of the divided input frequency.
N
M = f CCO --------
T arg et f ref
Equation 21-2
5. Set the FLL_LF_IGAIN and FLL_LF_PGAIN in CLK_FLL_CONFIG3.
Within each range of the CCO there are 512 steps of adjustment for the CCO frequency. These steps are controlled by
CCO_FREQ in the CLK_FLL_CONFIG4 register. The FLL automatically adjusts CCO_FREQ based on the output of the
FLL counter.
The output of the counter gives the number of CCO clocks, over one period of the divided reference clock, by which the
FLL is off. This value is then multiplied by the sum of FLL_LF_IGAIN and FLL_LF_PGAIN. The result of this multiplication
is then summed with the value currently in the CCO_FREQ register.
To determine the values for IGAIN and PGAIN use the following equation:
0.85
I GAIN -----------------------------
K N
--------
CCO f ref
Equation 21-3
Find the value of IGAIN closest but not over the values in the gain row in Table 21-5.
Register Value 0 1 2 3 4 5 6 7 8 9 10 11
Gain Value 1/256 1/128 1/64 1/32 1/16 1/8 1/4 1/2 1 2 4 8
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 248
Clocking System
Program FLL_LF_IGAIN with the register value that corresponds to the chosen gain value.
Take the IGAIN value from the register and use it in the following equation:
0.85
P GAIN I GAIN reg – -----------------------------
N
K CCO --------
f ref
Equation 21-4
Find the value of PGAIN closest but not over the values in the gain row in Table 21-5. Program FLL_PF_IGAIN with the
register value that corresponds to the chosen gain value.
For best performance Pgain_reg + Igain_reg should be as close as possible to calculated IGAIN without exceeding it.
kCCO is the gain of the CCO; Table 21-6 lists the kCCO for each CCO range.
Do not set the settling time to anything less than 1 µs, greater will lead to longer lock times.
1. Set LOCK_TOL in CLK_FLL_CONFIG2.
LOCK_TOL determines how much error the FLL can tolerate at the output of the counter that counts the number of CCO
clocks in one period of the divided reference clock. A higher tolerance can be used to lock more quickly or track a less
accurate source. The tolerance should be set such that the FLL does not unlock under normal conditions. A lower
tolerance means a more accurate output, but if the input reference is unstable then the FLL may unlock.
The following equation can be used to help determine the value:
1 + CCO accuracy
LOCK_TOL = M ----------------------------------------- – 1
1 – F refaccuracy
Equation 21-5
CCO (accuracy) = 0.25% or 0.0025
ref (accuracy) is the accuracy of the reference clock
2. Set CCO_FREQ in CLK_FLL_CONFIG4.
This field determines the frequency at which the FLL starts before any measurement. The nearer the FLL is to the desired
frequency, the faster it will lock.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 249
Clocking System
1 + f ref accuracy
Precision FLL = f ref ----------------------------------------------
N f CCO T arg et
Equation 21-7
Or (CCO_Trim_Steps / 2)
Example: The desired FLL output is 100 MHz, thus CCO target is 200 MHz. The 2 percent accurate 8 MHz IMO is used as
the reference input. N is calculated to be 69.
PrecisionFLL = ((8 MHz * 1.02)/(69 * 200 MHz)) = 0.059%, which is greater than the (CCO_Trim_Steps / 2)
The accuracy of the FLL output is the precision multiplied by the lock tolerance. If the CCO goes beyond this range, then
the FLL will unlock.
AccuracyFLL = PrecisionFLL * LOCK_TOL
The value for the reference divider N should be tuned such that it achieves the best precision/accuracy versus lock time.
The lock time depends on the time for each adjustment step in the locking process;
Step_Time = (N / fref) + (SETTLING_COUNT / fref)
Multiply this number by the number of steps it takes to lock, to determine lock time. Typically, the FLL locks within the first
~10 steps.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 250
Clocking System
Table 21-9. Clock Path Source Selections Table 21-12. HFCLK Input Selection Bits
Name Description
Name Description
HFCLK input clock selection
Selects the source for clk_path[i]
0: Select CLK_PATH0
0: IMO
1: Select CLK_PATH1
1: EXTCLK
PATH_MUX[2:0] ROOT_MUX[3:0] 2: Select CLK_PATH2
2: ECO
3: Select CLK_PATH3
4: DSI_MUX
4: Select CLK_PATH4
3: Reserved
5: Select CLK_PATH5
The DSI mux is configured through the
CLK_DSI_SELECT[i] register. Each CLK_HF has a pre-divider, which is set in the
CLK_ROOT_SELECT register.
Table 21-10. DSI Mux Source Selection
Table 21-13. HFCLK Divider Selection
Name Description
Name Description
Selects the source for the DSI_MUX[i]
0-15: Reserved Selects predivider value for the clock
root
16: ILO
0: No Divider
DSI_MUX[4:0] 17: WCO ROOT_DVI[5:4]
1: Divide clock by 2
18: Reserved
2: Divide clock by 4
19: Reserved
3: Divide clock by 8
20-31: Invalid
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 251
Clocking System
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 252
Clocking System
Predivider
CLK_HF[0] CLK_FAST CM4
1-256
Predivider Predivider
CLK_PERI CLK_SLOW CM0+
1-256 1-256
To peripheral
clock dividers
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 253
Clocking System
After the divider is configured use the DIV_CMD register to 21.7.2.1 Phase Aligning Dividers
enable the divider. This is done by setting the DIV_SEL to
the divider number you want to enable, and setting the For specific use cases, you must generate clocks that are
TYPE_SEL to the divider type. For example, if you wanted phase-aligned. For example, consider the generation of two
to enable the 0th 16.5-bit divider, write ‘0’ to DIV_SEL and gated clocks at 24 and 12 MHz, both of which are derived
‘2’ to TYPE_SEL. If you wanted to enable the tenth 16-bit from a 48-MHz CLK_PERI. If phase alignment is not
divider, write ‘10’ to DIV_SEL and ‘1’ to TYPE_SEL. See the considered, the generated gated clocks appear as follows.
registers TRM for more details.
Figure 21-5. Non Phase-Aligned Clock Dividers
No phase alignment
These clock signals may or may not be acceptable, depending on the logic functionality implemented on these two clocks. If
the two clock domains communicate with each other, and the slower clock domain (12 MHz) assumes that each high/‘1’ pulse
on its clock coincides with a high/‘1’ phase pulse in the higher clock domain (24 MHz), the phase misalignment is not
acceptable. To address this, it is possible to have dividers produce clock signals that are phase-aligned with any of the other
(enabled) clock dividers. Therefore, if (enabled) divider x is used to generate the 24-MHz clock, divider y can be phase-
aligned to divider x and used to generate the 12-MHz clock. The aligned clocks appear as follows.
Figure 21-6. Phase-Aligned Clock Dividers
Phase alignment
Phase alignment also works for fractional divider values. If (enabled) divider x is used to generate the 38.4-MHz clock (divide
by 1 8/32), divider y can be phase-aligned to divider x and used to generate the 19.2-MHz clock (divide by 2 16/32). The
generated gated clocks appear as follows.
Figure 21-7. Phase-Aligned Fractional Dividers
Phase alignment
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 254
Clocking System
Divider phase alignment requires that the divider to which it Table 21-15. Clock Dividers to Peripherals
is phase-aligned is already enabled. This requires the
Clock Number Destination
dividers to be enabled in a specific order.
18 tcpwm[0].clocks[3]
Phase alignment is implemented by controlling the start
19 tcpwm[0].clocks[4]
moment of the divider counters in hardware. When a divider
is enabled, the divider counters are set to ‘0’. The divider 20 tcpwm[0].clocks[5]
counters will only start incrementing from ‘0’ to the 21 tcpwm[0].clocks[6]
programmed integer and fractional divider values when the 22 tcpwm[0].clocks[7]
divider to which it is phase-aligned has an integer counter
23 tcpwm[1].clocks[0]
value of ‘0’.
24 tcpwm[1].clocks[1]
Note that the divider and clock multiplexer control register
25 tcpwm[1].clocks[2]
fields are all retained during the Deep Sleep power mode.
However, the divider counters that are used to implement 26 tcpwm[1].clocks[3]
the integer and fractional clock dividers are not. These 27 tcpwm[1].clocks[4]
counters are set to ‘0’ during the Deep Sleep mode. 28 tcpwm[1].clocks[5]
Therefore, when transitioning from Deep Sleep to Active
mode, all dividers (and clock signals) are enabled and 29 tcpwm[1].clocks[6]
phase-aligned by design. 30 tcpwm[1].clocks[7]
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 255
Clocking System
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 256
22. Reset System
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC 6 MCU family supports several types of resets that guarantee error-free operation during power up and allow the
device to reset based on user-supplied external hardware or internal software reset signals. The PSoC 6 MCU also contains
hardware to enable the detection of certain resets.
22.1 Features
The PSoC 6 MCU has these reset sources:
■ Power-on reset (POR) to hold the device in reset while the power supply ramps up to the level required for the device to
function properly
■ Brownout reset (BOD) to reset the device if the power supply falls below the device specifications during normal operation
■ External reset (XRES) to reset the device using an external input
■ Watchdog timer (WDT) reset to reset the device if the firmware execution fails to periodically service the watchdog timer
■ Software initiated reset to reset the device on demand using firmware
■ Logic-protection fault resets to reset the device if unauthorized operating conditions occur
■ Clock-supervision logic resets to reset the device when clock-related errors occur
■ Hibernate wakeup reset to bring the device out of the Hibernate low-power mode
22.2 Architecture
The following sections provide a description of the reset sources available in the PSoC 6 MCU family.
Note: None of these sources can reset the Backup system. The Backup domain is reset only when all the power supplies are
removed from it, also known as a “cold start” or if the firmware triggers a reset using the BACKUP_RESET register. Firmware
reset is required if the VBACKUP supply was invalid during a previous power supply ramp-up or brownout event. For more
details, see the Backup System chapter on page 235.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 257
Reset System
Table 22-1 lists all the reset sources in the PSoC 6 MCU.
22.2.1 Power-on Reset PSoC 62 datasheet. See the Power Supply and
Monitoring chapter on page 218 for more details.
Power-on reset is provided to keep the system in a reset
state during power-up. POR holds the device in reset until BOD events do not set a reset cause status bit, but in some
the supply voltage, VDDD reaches the datasheet cases they can be detected. In some BOD events, VDDD will
specification. The POR activates automatically at power-up. fall below the minimum logic operating voltage specified by
Refer to thePSoC 61 datasheet/PSoC 62 datasheet for the datasheet, but remain above the minimum logic
details on the POR trip-point levels. retention voltage.
POR events do not set a reset cause status bit, but can be
partially inferred by the absence of any other reset source. If
22.2.3 Watchdog Timer Reset
no other reset event is detected, then the reset is caused by Watchdog timer reset causes a reset if the WDT is not
POR, BOD, or XRES. serviced by the firmware within a specified time limit. See
the Watchdog Timer chapter on page 283 for more details.
22.2.2 Brownout Reset The RESET_WDT bit or RESET_MCWDT0 to
Brownout reset monitors the chip digital voltage supply RESET_MCWDT3 status bits of the RES_CAUSE register
VDDD and generates a reset if VDDD falls below the minimum is set when a watchdog reset occurs. This bit remains set
logic operating voltage specified in the PSoC 61 datasheet/
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 258
Reset System
until cleared by the firmware or until a POR, XRES, or BOD 22.2.6 Logic Protection Fault Reset
reset occurs. All other resets leave this bit unaltered.
Logic protection fault reset detects any unauthorized
For more details, see the Watchdog Timer chapter on protection violations and causes the device to reset if they
page 283. occur. One example of a protection fault is reaching a debug
breakpoint while executing privileged code.
22.2.4 Software Initiated Reset The RESET_ACT_FAULT or RESET_DPSLP_FAULT bits of
Software initiated reset is a mechanism that allows the CPU the RES_CAUSE register is set when a protection fault
to request a reset. The Cortex-M0+ and Cortex-M4 occurs in Active or Deep Sleep modes, respectively. These
Application Interrupt and Reset Control registers bits remain set until cleared or until a POR, XRES, or BOD
(CM0_AIRCR and CM4_AIRCR, respectively) can request a reset. All other resets leave this bit unaltered.
reset by writing a ‘1’ to the SYSRESETREQ bit of the
respective registers. 22.2.7 Clock-Supervision Logic Reset
Note that a value of 0x5FA should be written to the Clock-supervision logic initiates a reset due to the loss of a
VECTKEY field of the AIRCR register before setting the high-frequency clock or watch-crystal clock, or due to a
SYSRESETREQ bit; otherwise, the processor ignores the high-frequency clock error.
write. See the CPU Subsystem (CPUSS) chapter on
page 32 and Arm documentation on AIRCR for more details. The RESET_CSV_WCO_LOSS bit of the RES_CAUSE
register is set when the clock supervision logic requests a
The RESET_SOFT status bit of the RES_CAUSE register is reset due to the loss of a watch-crystal clock (if enabled).
set when a software reset occurs. This bit remains set until
cleared by firmware or until a POR, XRES, or BOD reset The RESET_CSV_HF_LOSS is a 16-bit field in the
occurs. All other resets leave this bit unaltered. RES_CAUSE2 register that can be used to identify resets
caused by the loss of a high-frequency clock. Similarly, the
RESET_CSV_HF_FREQ field can be used to identify resets
22.2.5 External Reset caused by the frequency error of a high-frequency clock.
External reset (XRES) is a reset triggered by an external
For more information on clocks, see the Clocking
signal that causes immediate system reset when asserted.
System chapter on page 242.
The XRES pin is active low – a logic ‘1’ on the pin has no
effect and a logic ‘0’ causes reset. The pin is pulled to logic
‘1’ inside the device. XRES is available as a dedicated pin. 22.2.8 Hibernate Wakeup Reset
For detailed pinout, refer to the pinout section of the PSoC Hibernate wakeup reset occurs when one of the Hibernate
61 datasheet/PSoC 62 datasheet. wakeup sources performs a device reset to return to the
The XRES pin holds the device in reset as long as the pin Active power mode. See the Device Power Modes chapter
input is ‘0’. When the pin is released (changed to logic ‘1’), on page 225 for details on Hibernate mode and available
the device goes through a normal boot sequence. The wakeup sources.
logical thresholds for XRES and other electrical TOKEN is an 8-bit field in the PWR_HIBERNATE register
characteristics are listed in the Electrical Specifications that is retained through a Hibernate wakeup sequence. The
section of the PSoC 61 datasheet/PSoC 62 datasheet. firmware can use this bitfield to differentiate hibernate
XRES is available in all power modes, but cannot reset the wakeup from a general reset event. Similarly, the
Backup system. PWR_HIB_DATA register can retain its contents through a
An XRES event does not set a reset cause status bit, but Hibernate wakeup reset, but is cleared when XRES is
can be partially inferred by the absence of any other reset asserted.
source. If no other reset event is detected, then the reset is
caused by POR, BOD, or XRES.
22.3 Identifying Reset Sources
When the device comes out of reset, it is often useful to
know the cause of the most recent or even older resets. This
is achieved through the RES_CAUSE and RES_CAUSE2
registers. These registers have specific status bits allocated
for some of the reset sources. These registers record the
occurrences of WDT reset, software reset, logic-protection
fault, and clock-supervision resets. However, these registers
do not record the occurrences of POR, BOD, XRES, or
Hibernate wakeup resets. The bits in these registers are set
on the occurrence of the corresponding reset and remain
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 259
Reset System
set after the reset, until cleared by the firmware or a loss of an XRES cannot be detected. The other reset sources can
retention, such as a POR, XRES, or BOD. be inferred to some extent by the status of the RES_CAUSE
and RES_CAUSE2 registers, as shown in Table 22-2.
Hibernate wakeup resets can be detected by examining the
TOKEN field in the PWR_HIBERNATE register as described
previously. Hibernate wakeup resets that occur as a result of
For more information, see the RES_CAUSE and RES_CAUSE2 registers in the registers TRM.
If these methods cannot detect the cause of the reset, then it can be one of the non-recorded and non-retention resets: BOD,
POR, or XRES. These resets cannot be distinguished using on-chip resources.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 260
23. I/O System
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
This chapter explains the PSoC 6 MCU I/O system, its features, architecture, operating modes, and interrupts. The I/O
system provides the interface between the CPU core and peripheral components to the outside world. The flexibility of
PSoC 6 MCUs and the capability of its I/O to route most signals to most pins greatly simplifies circuit design and board layout.
The GPIO pins in the PSoC 6 MCU family are grouped into ports; a port can have a maximum of eight GPIO pins.
23.1 Features
The PSoC 6 MCU GPIOs have these features:
■ Analog and digital input and output capabilities
■ Eight drive strength modes
■ Separate port read and write registers
■ Overvoltage tolerant (OVT-GPIO) pins
■ Separate I/O supplies and voltages for up to six groups of I/O
■ Edge-triggered interrupts on rising edge, falling edge, or on both edges, on all GPIO
■ Slew rate control
■ Frozen mode for latching previous state (used to retain the I/O state in System Hibernate Power mode)
■ Selectable CMOS and low-voltage LVTTL input buffer mode
■ CapSense support
■ Smart I/O provides the ability to perform Boolean functions in the I/O signal path
■ Segment LCD drive support
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 261
I/O System
23.2 Architecture
The PSoC 6 MCU is equipped with analog and digital peripherals. Figure 23-1 shows an overview of the routing between the
peripherals and pins.
Figure 23-1. GPIO Interface Overview
Configuration
CapSense Segment Function
Interface
Interrupt
Controller LCD Digital
Peripherals
I/O Cell
Pin
CapSense Analog
Sensing Peripherals
AMUXBUS-A
AMUXBUS-B
GPIO pins are connected to I/O cells. These cells are equipped with an input buffer for the digital input, providing high input
impedance and a driver for the digital output signals. The digital peripherals connect to the I/O cells via the high-speed I/O
matrix (HSIOM). The HSIOM for each pin contains multiplexers to connect between the selected peripheral and the pin.
Analog peripherals such as SAR ADC, Low-Power comparator (LPCOMP), and CapSense are either connected to the GPIO
pins directly or through the AMUXBUS.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 262
I/O System
GPIO_PRTx_CFG_IN[VTRIP_SELy_0]
GPIO_PRTx_CFG[IN_ENy]
GPIO_PRTx_INTR[EDGEy]
GPIO_PRTx_INTR[IN_INy]
GPIO_PRTx_MASK[EDGEy]
GPIO
GPIO_PRTx_INTR_MASKED[EDGEy] Edge
x = Port Number
y = Pin Number
GPIO_PRTx_INTR_SET[EDGEy]
Detect
GPIO_PRTx_INTR_CFG[EDGEy_SEL]
Pin Interrupt Signal
GPIO_PRTx_IN[INy]
ACTIVE_[15:0]
DEEP_SLEEP_[7:0]
Input Buffer
GPIO_PRTx_CFG_OUT[SLOWy] Output Driver
GPIO_PRTx_CFG_OUT[DRIVE_SELy] 2
HSIOM_PRTx_PORT_SEL[1:0][IOy_SEL] 5
GPIO_PRTx_OUT[OUTy]
ACTIVE_0(TCPWM)
ACTIVE_1(SCB)
ACTIVE_2(CAN) VDD
ACTIVE_[15:3] OUT
OUT_EN
DEEP_SLEEP_0(LCD-COM) 13
DEEP_SLEEP_1(LCD-SEG) Pin
Digital Slew
DEEP_SLEEP_2(SCB) Logic Rate
Control
DEEP_SLEEP_[7:3] 5
Note: HSIOM selection connects OUT and OUT_EN.
ACTIVE_[2:0] and DEEP_SLEEP_[2:0] connections are examples.
See Device Datasheet for specific connections to HSIOM ACTIVE
and DEEP_SLEEP selections.
VSS
GPIO_PRTx_CFG[DRIVE_MODEy] 3 Drive
Mode
Switches
23.2.2 Digital Input Buffer The input buffer is connected to the HSIOM for routing to the
CPU port registers and selected peripherals. Writing to the
The digital input buffer provides a high-impedance buffer for HSIOM port select register (HSIOM_PORT_SELx) selects
the external digital input. The buffer is enabled or disabled the pin connection. See the PSoC 61 datasheet/PSoC 62
by the IN_EN[7:0] bit of the Port Configuration Register datasheet for the specific connections available for each pin.
(GPIO_PRTx_CFG, where x is the port number).
If a pin is connected only to an analog signal, the input
buffer should be disabled to avoid crowbar currents.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 263
I/O System
Each pin’s input buffer trip point and hysteresis are Each GPIO pin has ESD diodes to clamp the pin voltage to
configurable for the following modes: the I/O supply source. Ensure that the voltage at the pin
does not exceed the I/O supply voltage VDDIO/VDDD/VDDA or
■ CMOS + I2C
drop below VSSIO/VSSD/VSSA. For the absolute maximum
■ TTL and minimum GPIO voltage, see the PSoC 61 datasheet/
These buffer modes are selected by the VTRIP_SEL[7:0]_0 PSoC 62 datasheet.
bit of the Port Input Buffer Configuration register.
(GPIO_PRTx_CFG_IN). 23.2.3.1 Drive Modes
Each I/O is individually configurable to one of eight drive
23.2.3 Digital Output Driver modes by the DRIVE_MODE[7:0] field of the Port
Configuration register, GPIO_PRTx_CFG. Table 23-1 lists
Pins are driven by the digital output driver. It consists of
the drive modes. Drive mode ‘1’ is reserved and should not
circuitry to implement different drive modes and slew rate
be used in most designs. CPU register and AMUXBUS
control for the digital output signals. The HSIOM selects the
connections support seven discrete drive modes to
control source for the output driver. The two primary types of
maximize design flexibility. Fixed-function digital peripherals,
control sources are CPU registers and fixed-function digital
such as SCB and TCPWM blocks, support modified
peripherals. A particular HSIOM connection is selected by
functionality for the same seven drive modes compatible
writing to the HSIOM port select register
with fixed peripheral signaling. Figure 23-3 shows simplified
(HSIOM_PORT_SELx).
output driver diagrams of the pin view for CPU register
I/O ports are powered by different sources. The specific control on each of the eight drive modes. Figure 23-4 is a
allocation of ports to supply sources can be found in the simplified output driver diagram that shows the pin view for
Pinout section of the PSoC 61 datasheet/PSoC 62 fixed-function-based peripherals for each of the eight drive
datasheet. modes.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 264
I/O System
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 265
I/O System
Resistive modes provide a series resistance in one of the Note: For some devices in the PSoC 6 MCU family,
data states and strong drive in the other. Pins can be used simultaneous GPIO switching with unrestricted drive
for either digital input or digital output in these modes. If strengths and frequency can induce noise in on-chip
resistive pull-up is required, a ‘1’ must be written to that pin’s subsystems affecting CapSense and ADC results. Refer to
Data Register bit. If resistive pull-down is required, a ‘0’ the Errata section in the respective device datasheet for
must be written to that pin’s Data Register. Interfacing details.
mechanical switches is a common application of these drive
modes. The resistive modes are also used to interface 23.2.3.3 GPIO-OVT Pins
PSoC with open drain drive lines. Resistive pull-up is used Select device pins are overvoltage tolerant (OVT) and are
when the input is open drain low and resistive pull-down is useful for interfacing to busses or other signals that may
used when the input is open drain high. exceed the pin’s VDDIO supply, or where the whole device
■ Open Drain Drives High and Open Drain Drives Low supply or pin VDDIO may not be always present. They are
identical to regular GPIOs with the additional feature of
Open drain modes provide high impedance in one of the
being overvoltage tolerant. GPIO-OVT pins have hardware
data states and strong drive in the other. Pins are useful as
to compare VDDIO to the pin voltage. If the pin voltage
digital inputs or outputs in these modes. Therefore, these
exceeds VDDIO, the output driver is disabled and the pin
modes are widely used in bidirectional digital
driver is tristated. This results in negligible current sink at the
communication. Open drain drive high mode is used when
pin.
the signal is externally pulled down and open drain drive low
is used when the signal is externally pulled high. A common Note that in overvoltage conditions, the input buffer data will
application for the open drain drives low mode is driving I2C not be valid if the external source’s specification of VOH and
bus signal lines. VOL do not match the trip points of the input buffer defined
■ Strong Drive by the current VDDIO voltage.
The strong drive mode is the standard digital output mode
for pins; it provides a strong CMOS output drive in both high
and low states. Strong drive mode pins should not be used
as inputs under normal circumstances. This mode is often
used for digital output signals or to drive external devices.
■ Resistive Pull-Up and Resistive Pull-Down
In the resistive pull-up and pull-down mode, the GPIO will
have a series resistance in both logic 1 and logic 0 output
states. The high data state is pulled up while the low data
state is pulled down. This mode is useful when the pin is
driven by other signals that may cause shorts.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 266
I/O System
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 267
I/O System
Note: The Active and Deep Sleep sources are pin dependent. See the “Pinouts” section of the PSoC 61 datasheet/PSoC 62
datasheet for more details on the features supported by each pin.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 268
I/O System
23.6 Interrupt
All port pins have the capability to generate interrupts. Figure 23-5 shows the routing of pin signals to generate interrupts.
Figure 23-5. Interrupt Signal Routing
■ Pin signal through the “GPIO Edge Detect” block with direct connection to the CPU interrupt controller
Figure 23-6 shows the GPIO Edge Detect block architecture.
Figure 23-6. GPIO Edge Detect Block Architecture
50 ns Glitch Filter Edge Detector
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 269
I/O System
An edge detector is present at each pin. It is capable of The GPIO_PRTx_INTR_MASK register enables forwarding
detecting rising edge, falling edge, and both edges without of the GPIO_PRTx_INTR edge detect signal to the interrupt
any reconfiguration. The edge detector is configured by controller when a ‘1’ is written to a pin’s corresponding
writing into the EDGEv_SEL bits of the Port Interrupt bitfield. The GPIO_PRTx_INTR_MASKED register can then
Configuration register, GPIO_PRTx_INTR_CFG, as shown be read to determine the specific pin that generated the
in Table 23-4. interrupt signal forwarded to the interrupt controller. The
masked edge detector outputs of a port are then ORed
Table 23-4. Edge Detector Configuration together and routed to the interrupt controller (NVIC in the
EDGE_SEL Configuration CPU subsystem). Thus, there is only one interrupt vector
per port.
00 Interrupt is disabled
01 Interrupt on Rising Edge The masked and ORed edge detector block output is routed
10 Interrupt on Falling Edge to the Interrupt Source Multiplexer shown in Figure 8-3 on
page 59, which gives an option of Level and Rising Edge
11 Interrupt on Both Edges
detection. If the Level option is selected, an interrupt is
triggered repeatedly as long as the Port Interrupt Status
Writing ‘1’ to the corresponding status bit clears the pin edge register bit is set. If the Rising Edge detect option is
state. Clearing the edge state status bit is important; selected, an interrupt is triggered only once if the Port
otherwise, an interrupt can occur repeatedly for a single Interrupt Status register is not cleared. Thus, the interrupt
trigger or respond only once for multiple triggers, which is status bit must be cleared if the Edge Detect block is used.
explained later in this section. When the Port Interrupt
Control Status register is read at the same time an edge is All of the port interrupt vectors are also ORed together into a
occurring on the corresponding port, it can result in the edge single interrupt vector for use on devices with more ports
not being properly detected. Therefore, when using GPIO than there are interrupt vectors available. To determine the
interrupts, read the status register only inside the port that triggered the interrupt, the GPIO_INTR_CAUSEx
corresponding interrupt service routine and not in any other registers can be read. A ‘1’ present in a bit location indicates
part of the code. that the corresponding port has a pending interrupt. The
indicated GPIO_PRTx_INTR register can then be read to
Firmware and the debug interface are able to trigger a determine the pin source.
hardware interrupt from any pin by setting the corresponding
bit in the GPIO_PRTx_INTR_SET register.
In addition to the pins, each port provides a glitch filter
23.7 Peripheral Connections
connected to its own edge detector. This filter can be driven
by one of the pins of a port. The selection of the driving pin 23.7.1 Firmware-Controlled GPIO
is done by writing to the FLT_SEL field of the
GPIO_PRTx_INTR_CFG register as shown in Table 23-5. For standard firmware-controlled GPIO using registers, the
GPIO mode must be selected in the HSIOM_PORT_SELx
Table 23-5. Glitch Filter Input Selection register.
FLT_SEL Selected Pin The GPIO_PRTx_OUT register is used to read and write the
000 Pin 0 is selected output buffer state for GPIOs. A write operation to this
001 Pin 1 is selected
register changes the GPIO’s output driver state to the
written value. A read operation reflects the output data
010 Pin 2 is selected
written to this register and the resulting output driver state. It
011 Pin 3 is selected does not return the current logic level present on GPIO pins,
100 Pin 4 is selected which may be different. Using the GPIO_PRTx_OUT
101 Pin 5 is selected register, read-modify-write sequences can be safely
110 Pin 6 is selected performed on a port that has both input and output GPIOs.
111 Pin 7 is selected In addition to the data register, three other registers –
GPIO_PRTx_SET, GPIO_PRTx_CLR, and
When a port pin edge occurs, you can read the Port GPIO_PRTx_INV – are provided to set, clear, and invert the
Interrupt Status register, GPIO_PRTx_INTR, to know which output data respectively on specific pins in a port without
pin caused the edge. This register includes both the latched affecting other pins. This avoids the need for read-modify-
information on which pin detected an edge and the current write operations in most use cases. Writing ‘1’ to these
pin status. This allows the CPU to read both information in a register bitfields will set, clear, or invert the respective pin;
single read operation. This register has an additional use – writing ‘0’ will have no affect on the pin state.
to clear the latched edge state.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 270
I/O System
GPIO_PRTx_IN is the port I/O pad register, which provides 23.8 Smart I/O
the actual logic level present on the GPIO pin when read.
Writes to this register have no effect. The Smart I/O block adds programmable logic to an I/O port.
This programmable logic integrates board-level Boolean
23.7.2 Analog I/O logic functionality such as AND, OR, and XOR into the port.
A graphical interface is provided with the ModusToolbox
Analog resources, such as LPCOMP and SAR ADC, which install for configuring the Smart I/O block. For more informa-
require low-impedance routing paths have dedicated pins. tion about the configurator tool, see the ModusToolbox
Dedicated analog pins provide direct connections to specific Smart I/O Configurator Guide.
analog blocks. They help improve performance and should
be given priority over other pins when using these analog The Smart I/O block has these features:
resources. See the PSoC 61 datasheet/PSoC 62 datasheet ■ Integrate board-level Boolean logic functionality into a
for details on these dedicated pins of the PSoC 6 MCU. port
To configure a GPIO as a dedicated analog I/O, it should be ■ Ability to preprocess HSIOM input signals from the GPIO
configured in high-impedance analog mode (see Table 23-1) port pins
with input buffer disabled. The respective connection should ■ Ability to post-process HSIOM output signals to the
be enabled via registers in the specific analog resource. GPIO port pins
To configure a GPIO as an analog pin connecting to ■ Support in all device power modes except Hibernate
AMUXBUS, it should be configured in high-impedance ■ Integrate closely to the I/O pads, providing shortest
analog mode with the input buffer disabled and then routed signal paths with programmability
to the correct AMUXBUS using the HSIOM_PORT_SELx
register. 23.8.1 Overview
While it is preferred for analog pins to disable the input The Smart I/O block is positioned in the signal path between
buffer, it is acceptable to enable the input buffer if the HSIOM and the I/O port. The HSIOM multiplexes the
simultaneous analog and digital input features are required. output signals from fixed-function peripherals and CPU to a
specific port pin and vice-versa. The Smart I/O block is
23.7.2.1 AMUXBUS Connection placed on this signal path, acting as a bridge that can
Static connection of AMUXBUS A or B is made by selecting process signals between port pins and HSIOM, as shown in
AMUXA or AMUXB in the HSIOM_PORT_SELx register. Figure 23-7.
23.7.4 CapSense
The pins that support CapSense can be configured as
CapSense widgets such as buttons, slider elements,
touchpad elements, or proximity sensors. CapSense also
requires external capacitors and optional shield lines. See
the PSoC 4 and PSoC 6 MCU CapSense Design Guide for
more details.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 271
I/O System
4
HSIOM GPIO Input
Input Signals Signals
The signal paths supported through the Smart I/O block as clock. Therefore, communication between Smart I/O and
shown in Figure 23-7 are as follows: other synchronous logic should be treated as asynchronous.
1. Implement self-contained logic functions that directly The following clock sources are available for selection:
operate on port I/O signals
■ GPIO input signals “io_data_in[7:0]”. These clock
2. Implement self-contained logic functions that operate on sources have no associated reset.
HSIOM signals
■ HSIOM output signals “chip_data[7:0]”. These clock
3. Operate on and modify HSIOM output signals and route sources have no associated reset.
the modified signals to port I/O signals
■ Smart I/O clock (clk_smartio). This is derived from the
4. Operate on and modify port I/O signals and route the system clock (clk_sys) using a peripheral clock divider.
modified signals to HSIOM input signals See the Clocking System chapter on page 242 for
The following sections discuss the Smart I/O block details on peripheral clock dividers. This clock is
components, routing, and configuration in detail. In these available only in System LP and ULP power modes. The
sections, GPIO signals (io_data) refer to the input/output clock can have one out of two associated resets:
signals from the I/O port; device or chip (chip_data) signals rst_sys_act_n and rst_sys_dpslp_n. These resets
refer to the input/output signals from HSIOM. determine in which system power modes the block
synchronous state is reset; for example, rst_sys_act_n is
intended for Smart I/O synchronous functionality in the
23.8.2 Block Components System LP and ULP power modes and reset is activated
The internal logic of the Smart I/O includes these in the System Deep Sleep power mode.
components: ■ Low-frequency system clock (clk_lf). This clock is
■ Clock/reset available in System Deep Sleep power mode. This clock
has an associated reset, rst_lf_dpslp_n. Reset is
■ Synchronizers
activated if the system enters Hibernate, or is at POR.
■ Three-input lookup table (LUT)
When the block is enabled, the selected clock (clk_block)
■ Data unit
and associated reset (rst_block_n) are provided to the fabric
components. When the fabric is disabled, no clock is
23.8.2.1 Clock and Reset
released to the fabric components and the reset is activated
The clock and reset component selects the Smart I/O (the LUT and data unit components are set to the reset
block’s clock (clk_block) and reset signal (rst_block_n). A value of ‘0’).
single clock and reset signal is used for all components in
The I/O input synchronizers introduce a delay of two
the block. The clock and reset sources are determined by
clk_block cycles (when synchronizers are enabled). As a
the CLOCK_SRC[4:0] bitfield of the SMARTIO_PRTx_CTL
result, in the first two cycles, the block may be exposed to
register. The selected clock is used for the synchronous
stale data from the synchronizer output. Hence, during the
logic in the block components, which includes the I/O input
first two clock cycles, the reset is activated and the block is
synchronizers, LUT, and data unit components. The
in bypass mode.
selected reset is used to asynchronously reset the
synchronous logic in the LUT and data unit components.
Note that the selected clock (clk_block) for the block’s
synchronous logic is not phase-aligned with other
synchronous logic in the device, operating on the same
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 272
I/O System
23.8.2.2 Synchronizer
Each GPIO input signal and device input signal (HSIOM input) can be used either asynchronously or synchronously. To use
the signals synchronously, a double flip-flop synchronizer, as shown in Figure 23-8, is placed on both these signal paths to
synchronize the signal to the Smart I/O clock (clk_block). The synchronization for each pin/input is enabled or disabled by
setting or clearing the IO_SYNC_EN[i] bitfield for GPIO input signal and CHIP_SYNC_EN[i] for HSIOM signal in the
SMARTIO_PRTx_SYNC_CTL register, where ‘i’ is the pin number.
Figure 23-8. Smart I/O Clock Synchronizer
Clock Synchronizer
0
To SMARTIO
block io_data_in[i]
1 Q D Q D
Or
chip_data_in[i]
clk clk
clk_block
SYNC_CTL.IO_SYNC_EN[i]
Or
SYNC_CTL.CHIP_SYNC_EN[i]
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 273
I/O System
The SMARTIO_PRTx_LUT_SELy registers select the three input signals (tr0_in, tr1_in, and tr2_in) going into each LUT. The
input can come from the following sources:
■ Data unit output
■ Other LUT output signals (tr_out)
■ HSIOM output signals (chip_data[7:0])
■ GPIO input signals (io_data[7:0])
LUT_TR0_SEL[3:0] bits of the SMARTIO_PRTx_LUT_SELy register selects the tr0_in signal for the yth LUT. Similarly,
LUT_TR1_SEL[3:0] bits and LUT_TR2_SEL[3:0] bits select the tr1_in and tr2_in signals, respectively. See Table 23-7 for
details.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 274
I/O System
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 275
I/O System
tr0_in
tr2_in
LUT[7:0]
OPC[1:0] = 1
tr0_in
tr2_in
clk_block 8
LUT[7:0]
OPC[1:0] = 2
tr0_in
tr2_in
8 clk_block
LUT[7:0]
LUT[5] OPC[1:0] = 3
Enable
LUT[4]
tr2_in
LUT[3]
LUT[2] Set
tr1_in tr_out
Clr
LUT[1] Clk
LUT[0]
tr0_in
clk_block
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 276
I/O System
The trigger signals are selected using the DU_TRx_SEL[3:0] bitfield of the SMARTIO_PRTx_DU_SEL register. The DUT_-
DATAx_SEL[1:0] bits of the SMARTIO_PRTx_DU_SEL register select the 8-bit input data source. The size of the DU (number
of bits used by the datapath) is defined by the DU_SIZE[2:0] bits of the SMARTIO_PRTx_DU_CTL register. See Table 23-8
for register control details.
The DU generates a single output trigger signal (tr_out). The internal state (du_data[7:0]) is captured in flip-flops and requires
clk_block.
The following pseudo code describes the various datapath operations supported by the DU opcode. Note that “Comb”
describes the combinatorial functionality – that is, functions that operate independent of previous output states. “Reg”
describes the registered functionality – that is, functions that operate on inputs and previous output states (registered using
flip-flops).
// The following is shared by all operations.
mask = (2 ^ (DU_SIZE+1) – 1)
data_eql_data1_in = (data & mask) == (data1_in & mask));
data_eql_0 = (data & mask) == 0);
data_incr = (data + 1) & mask;
data_decr = (data - 1) & mask;
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 277
I/O System
// INCR operation: increments data by 1 from an initial value (data0) until it reaches a
// final value (data1).
Comb:tr_out = data_eql_data1_in;
Reg: data <= data;
if (tr0_in) data <= data0_masked; //tr0_in is reload signal - loads masked data0
// into data
else if (tr1_in) data <= data_eql_data1_in ? data : data_incr; //increment data until
// it equals data1
// INCR_WRAP operation: operates similar to INCR but instead of stopping at data1, it wraps
// around to data0.
Comb:tr_out = data_eql_data1_in;
Reg: data <= data;
if (tr0_in) data <= data0_masked;
else if (tr1_in) data <= data_eql_data1_in ? data0_masked : data_incr;
// DECR operation: decrements data from an initial value (data0) until it reaches 0.
Comb:tr_out = data_eql_0;
Reg: data <= data;
if (tr0_in) data <= data0_masked;
else if (tr1_in) data <= data_eql_0 ? data : data_decr;
// INCR_DECR operation: combination of INCR and DECR. Depending on trigger signals it either
// starts incrementing or decrementing. Increment stops at data1 and decrement stops at 0.
Comb:tr_out = data_eql_data1_in | data_eql_0;
Reg: data <= data;
if (tr0_in) data <= data0_masked; // Increment operation takes precedence over
// decrement when both signal are available
else if (tr1_in) data <= data_eql_data1_in ? data : data_incr;
else if (tr2_in) data <= data_eql_0 ? data : data_decr;
// ROR operation: rotates data right and LSb is sent out. The data for rotation is taken from
// data0.
Comb:tr_out = data[0];
Reg: data <= data;
if (tr0_in) data <= data0_masked;
else if (tr1_in) {
data <= {0, data[7:1]} & mask; //Shift right operation
data[du_size] <= data[0]; //Move the data[0] (LSb) to MSb
}
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 278
I/O System
// SHR operation: performs shift register operation. Initial data (data0) is shifted out and
// data on tr2_in is shifted in.
Comb:tr_out = data[0];
Reg: data <= data;
if (tr0_in) data <= data0_masked;
else if (tr1_in) {
data <= {0, data[7:1]} & mask; //Shift right operation
data[du_size] <= tr2_in; //tr2_in Shift in operation
}
// SHR_MAJ3 operation: performs the same functionality as SHR. Instead of sending out the
// shifted out value, it sends out a '1' if in the last three samples/shifted-out values
// (data[0]), the signal high in at least two samples. otherwise, sends a '0'. This function
// sends out the majority of the last three samples.
Comb:tr_out = (data == 0x03)
| (data == 0x05)
| (data == 0x06)
| (data == 0x07);
Reg: data <= data;
if (tr0_in) data <= data0_masked;
else if (tr1_in) {
data <= {0, data[7:1]} & mask;
data[du_size] <= tr2_in;
}
// SHR_EQL operation: performs the same operation as SHR. Instead of shift-out, the output is
// a comparison result (data0 == data1).
Comb:tr_out = data_eql_data1_in;
Reg: data <= data;
if (tr0_in) data <= data0_masked;
else if (tr1_in) {
data <= {0, data[7:1]} & mask;
data[du_size] <= tr2_in;
}
// AND_OR operation: ANDs data1 and data0 along with mask; then, ORs all the bits of the
// ANDed output.
Comb:tr_out = | (data & data1_in & mask);
Reg: data <= data;
if (tr0_in) data <= data0_masked;
23.8.3 Routing
The Smart I/O block includes many switches that are used to route the signals in and out of the block and also between
various components present inside the block. The routing switches are handled through the PRTGIO_PRTx_LUT_SELy and
SMARTIO_PRTx_DU_SEL registers. Refer to the registers TRM for details. The Smart I/O internal routing is shown in
Figure 23-10. In the figure, note that LUT7 to LUT4 operate on io_data/chip_data[7] to io_data/chip_data[4] whereas LUT3 to
LUT0 operate on io_data/chip_data[3] to io_data/chip_data[0].
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 279
I/O System
8 rst_block_n
0x00 Clock and
8 Reset
SMARTIO_PRTx_DATA.DATA[7:0] clk_block
8
chip_data[7:0]
8
io_data[7:0]
data_in0
data_in1
clk_smartio
Data Unit clk_sys
tr_out
tr0_in
tr1_in
tr2_in
clk_lf
Sync io_data[7]
smartio_data[7] smartio_data[7]
chip_data[7] Sync chip_data[7]
Sync io_data[6]
smartio_data[6] smartio_data[6]
chip_data[6] Sync chip_data[6]
Sync io_data[5]
smartio_data[5] smartio_data[5]
chip_data[5] Sync chip_data[5]
Sync io_data[4]
smartio_data[4] smartio_data[4]
chip_data[4] Sync chip_data[4]
Sync io_data[3]
smartio_data[3] smartio_data[3]
chip_data[3] Sync chip_data[3]
Sync io_data[2]
smartio_data[2] smartio_data[2]
chip_data[2] Sync chip_data[2]
Sync io_data[1]
smartio_data[1] smartio_data[1]
chip_data[1] Sync chip_data[1]
Sync io_data[0]
smartio_data[0] smartio_data[0]
chip_data[0] Sync chip_data[0]
1'b0
tr1_in
tr2_in
tr0_in
tr1_in
tr0_in
tr1_in
tr2_in
tr1_in
tr_out
tr_out
tr_out
tr_out
tr_out
tr_out
tr_out
tr_out
tr0_in
tr2_in
tr0_in
tr1_in
tr2_in
tr0_in
tr1_in
tr2_in
tr0_in
tr2_in
tr0_in
tr1_in
tr2_in
tr0_in
tr1_in
tr2_in
1'b1
clk_block
LUT0 LUT1 LUT2 LUT3 LUT4 LUT5 LUT6 LUT7 Various signals
8-bit wide data bus
Programmable Switch (ONLY ONE of the switches along a
vertical line can be closed at a time)
Closed switch connecting a bit of the 8-bit data bus
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 280
I/O System
23.8.4 Operation
The Smart I/O block should be configured and operated as follows:
1. Before enabling the block, all the components and routing should be configured as explained in “Block Components” on
page 272.
2. In addition to configuring the components and routing, some block level settings must be configured correctly for desired
operation.
a. Bypass control: The Smart I/O path can be bypassed for a particular GPIO signal by setting the BYPASS[i] bitfield in
the SMARTIO_PRTx_CTL register. When bit ‘i’ is set in the BYPASS[7:0] bitfield, the ith GPIO signal is bypassed to
the HSIOM signal path directly – Smart I/O logic will not be present in that signal path. This is useful when the Smart I/
O function is required only on select I/Os.
b. Pipelined trigger mode: The LUT input multiplexers and the LUT component itself do not include any combinatorial
loops. Similarly, the data unit also does not include any combinatorial loops. However, when one LUT interacts with
the other or to the data unit, inadvertent combinatorial loops are possible. To overcome this limitation, the
PIPELINE_EN bitfield of the SMARTIO_PRTx_CTL register is used. When set, all the outputs (LUT and DU) are
registered before branching out to other components.
3. After the Smart I/O block is configured for the desired functionality, the block can be enabled by setting the ENABLED
bitfield of the SMARTIO_PRTx_CTL register. If disabled, the Smart I/O block is put in bypass mode, where the GPIO
signals are directly controlled by the HSIOM signals and vice-versa. The Smart I/O block must be configured; that is, all
register settings must be updated before enabling the block to prevent glitches during register updates.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 281
I/O System
23.9 Registers
Table 23-10. I/O Registers
Name Description
GPIO_PRTx_OUT Port output data register reads and writes the output driver data for I/O pins in the port.
GPIO_PRTx_OUT_CLR Port output data clear register clears output data of specific I/O pins in the port.
GPIO_PRTx_OUT_SET Port output data set register sets output data of specific I/O pins in the port.
GPIO_PRTx_OUT_INV Port output data invert register inverts output data of specific I/O pins in the port.
GPIO_PRTx_IN Port input state register reads the current pin state present on I/O pin inputs.
GPIO_PRTx_INTR Port interrupt status register reads the current pin interrupt state.
Port interrupt mask register configures the mask that forwards pin interrupts to the CPU’s
GPIO_PRTx_INTR_MASK
interrupt controller.
Port interrupt masked status register reads the masked interrupt status forwarded to the CPU
GPIO_PRTx_INTR_MASKED
interrupt controller.
GPIO_PRTx_INTR_SET Port interrupt set register allows firmware to set pin interrupts.
GPIO_PRTx_INTR_CFG Port interrupt configuration register selects the edge detection type for each pin interrupt.
GPIO_PRTx_CFG Port configuration register selects the drive mode and input buffer enable for each pin.
GPIO_PRTx_CFG_IN Port input buffer configuration register configures the input buffer mode for each pin.
GPIO_PRTx_CFG_OUT Port output buffer configuration register selects the output driver slew rate for each pin.
High-speed I/O Mux (HSIOM) port selection register selects the hardware peripheral connection
HSIOM_PORT_SELx
to I/O pins.
Note The ‘x’ in the GPIO register name denotes the port number. For example, GPIO_PTR1_OUT is the Port 1 output data
register.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 282
24. Watchdog Timer
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The watchdog timer (WDT) is a hardware timer that automatically resets the device in the event of an unexpected firmware
execution path. The WDT, if enabled, must be serviced periodically in firmware to avoid a reset. Otherwise, the timer elapses
and generates a device reset. In addition, the WDT can be used as an interrupt source or a wakeup source in low-power
modes.
The PSoC 6 MCU family includes one free-running WDT and two multi-counter WDTs (MCWDT). The WDT has a 16-bit
counter. Each MCWDT has two 16-bit counters and one 32-bit counter. Thus, the watchdog system has a total of seven
counters – five 16-bit and two 32-bit. All 16-bit counters can generate a watchdog device reset. All seven counters can
generate an interrupt on a match event.
24.1 Features
The PSoC 6 MCU WDT supports these features:
■ One 16-bit free-running WDT with:
❐ ILO as the input clock source
❐ Device reset generation if not serviced within a configurable interval
❐ Periodic Interrupt/wakeup generation in LP/ULP Active, LP/ULP Sleep, Deep Sleep, and Hibernate power modes
■ Two MCWDTs, each supporting:
❐ Device reset generation if not serviced within a configurable interval
❐ LFCLK (ILO or WCO) as the input clock source
❐ Periodic interrupt/wake up generation in LP/ULP Active, LP/ULP Sleep, and Deep Sleep power modes (Hibernate
mode is not supported)
❐ Two 16-bit and one 32-bit independent counters, which can be configured as a single 64-bit or 48-bit (with one 16-bit
independent counter), or two 32-bit cascaded counters
24.2 Architecture
The PSoC 6 MCU supports 174 system interrupts. The interrupts are routed to both the CPU cores. In the case of CM4 only
the first 39 interrupts are routed to WIC while all 174 interrupts are routed to NVIC. The CM0 has access to only eight
interrupts of the maximum supported 32 interrupts. The 174 interrupt sources are multiplexed and at a time eight interrupt
sources can be connected to the CM0. The CPUSS_CM0_SYSTEM_INT_CTLx register decides which interrupts are
connected to the CM0. See the Interrupts chapter on page 56 for details on how to configure the interrupt for the free-running
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 283
Watchdog Timer
WDT/MCWDT to the required CPU. The free-running WDT/MCWDT resource must be used by one CPU only; it is not
intended for simultaneous use by both CPUs because of the complexity involved in coordination.
Figure 24-1. Watchdog Timer Block Diagram
Device Interrupt
CFG/STATUS
Registers WIC
Free running watchdog
timer
ILO Clock
Reset
2
CFG/STATUS Interrupt
Low
Multi counter watchdog
frequency
Clock
timers (x2) Device
clock 2 Reset
Reset
(LFCLK)
Bitwise AND
== WDT_MATCH.MATCH **
Yes
INTERRUPT
++Count
Count == 3 RESET
***
SRSS_INTR.WDT_MATCH Count = 0
(Write 1 from Firmware)
Reset Generation
logic
Free-running WDT
* WDT_MATCH.IGNORE_BITS refer to value held by the bits[19:16] of the WDT_MATCH register.
** WDT_MATCH.MATCH refer to the value held by the bits[15:0] of the WDT_MATCH register.
*** SRSS_INTR.WDT_MATCH refers to the WDT_MATCH bit of the SRSS_INTR register.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 284
Watchdog Timer
When enabled, the WDT counts up on each rising edge of bits are ignored while performing the match and the WDT
the ILO. When the counter value (WDT_CNT register) counter behaves similar to a 13-bit counter. Note that these
equals the match value stored in MATCH bits [15:0] of the bits do not reduce the counter size – the WDT_CNT register
WDT_MATCH register, an interrupt is generated. The match still counts from 0 to 65535 (16-bit).
event does not reset the WDT counter and the WDT keeps
The WDT can be enabled or disabled using the WDT_EN bit
counting until it reaches the 16-bit boundary (65535) at
[0] of the WDT_CTL register. The WDT_CTL register
which point, it wraps around to 0 and counts up. The match
provides a mechanism to lock the WDT configuration
interrupt is generated every time the counter value equals
registers. The WDT_LOCK bits [31:30] control the lock
the match value.
status of the WDT registers. These bits are special bits,
The WDT_MATCH bit of the SRSS_INTR register is set which can enable the lock in a single write; to release the
whenever a WDT match interrupt occurs. This interrupt must lock, two different writes are required. The WDT_LOCK bits
be cleared by writing a ‘1’ to the same bit. Clearing the protect the WDT_EN bit, WDT_MATCH register,
interrupt resets the watchdog. If the firmware does not clear CLK_ILO_CONFIG register, and LFCLK_SEL bits [1:0] of
the interrupt for two consecutive occasions, the third the CLK_SELECT register. Note that the WDT_LOCK bits
interrupt generates a device reset. are not retained in Deep Sleep mode and reset to their
default (LOCK) state after a deep sleep wakeup. As a result,
In addition, the WDT provides an option to set the number of
to update any register protected by the WDT_LOCK bits
bits to be used for comparison. The IGNORE_BITS (bits
after a deep sleep wakeup, a WDT UNLOCK sequence
[19:16] of the WDT_MATCH register) is used for this
should be issued before the register update.
purpose. These bits configure the number of MSbs to ignore
from the 16-bit count value while performing the match. For Table 24-1 explains various registers and bitfields used to
instance, when the value of these bits equals 3, the MSb 3 configure and use the WDT.
Table 24-1. Free-running WDT Configuration Options
Register [Bit_Pos] Bit_Name Description
Enable or disable the watchdog reset
WDT_CTL[0] WDT_EN 0: WDT reset disabled
1: WDT reset enabled
Lock or unlock write access to the watchdog configuration and clock related registers. When
the bits are set, the lock is enabled.
0: No effect
1: Clear bit 0
WDT_CTL[31:30] WDT_LOCK
2: Clear bit 1
3: Set both bit 0 and 1 (lock enabled)
WDT will lock on a reset. This field is not retained in Deep Sleep or Hibernate mode, so the
WDT will be locked after wakeup from these modes.
WDT_CNT[15:0] COUNTER Current value of WDT counter
WDT_MATCH[15:0] MATCH Match value to a generate watchdog match event
Number of MSbs of the WDT_CNT register to ignore for comparison with the MATCH value.
WDT_MATCH[19:16] IGNORE_BITS
Up to 12 MSbs can be ignored; settings above 12 act same as a setting of 12.
WDT interrupt request
SRSS_INTR[0] WDT_MATCH This bit is set whenever a watchdog match event happens. The WDT interrupt is cleared by
writing a ‘1’ to this bit
Mask for the WDT interrupt
SRSS_INTR_MASK[0] WDT_MATCH 0: WDT interrupt is blocked
1: WDT interrupt is forwarded to CPU
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 285
Watchdog Timer
16 – IGNORE_BITS
Watchdog reset period = ILO period 2 2 + WDT_MATCH
Equation 24-1
4. Set the WDT_MATCH bit in the SRSS_INTR register to clear any pending WDT interrupt.
5. Enable ILO by setting the ENABLE bit [31] of the CLK_ILO_CONFIG register.
6. Enable the WDT by setting the WDT_EN bit in WDT_CTL register.
7. Lock the WDT and ILO configuration by writing ‘3’ to the WDT_LOCK bits. This also locks the LFCLK_SEL bits of the
CLK_SELECT register.
8. In the firmware, write ‘1’ to the WDT_MATCH bit in the SRSS_INT register to feed (clear interrupt) the watchdog.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 286
Watchdog Timer
Because of its free-running nature, the WDT should not be used for periodic interrupt generation. Use the MCWDT instead;
see 24.4 Multi-Counter WDTs. The MCWDT counters can be used to generate periodic interrupts. If absolutely required,
follow these steps to use the WDT as a periodic interrupt generator:
1. Unlock the WDT if this is the first update to the WDT registers after a deep sleep or hibernate wakeup, or a device reset.
2. Write the desired IGNORE_BITS in the WDT_MATCH register to set the counter resolution to be used for the match.
3. Write the desired match value to the WDT_MATCH register.
4. Set the WDT_MATCH bit in the SRSS_INTR register to clear any pending WDT interrupt.
5. Enable the WDT interrupt to CPU by setting the WDT_MATCH bit in SRSS_INTR_MASK.
6. Enable SRSS interrupt to the CPU by configuring the appropriate ISER register (See the Interrupts chapter on page 56 for
details).
7. In the ISR, unlock the WDT; clear the WDT interrupt and add the desired match value to the existing match value. By
doing so, another interrupt is generated when the counter reaches the new match value (period).
16 16 32
MCWDT_CTR0 == MCWDT_CTR1 ==
MCWDT_BITS2
MCWDT_MATCH0 MCWDT_MATCH1
5
INTERRUPT
Multi counter
RESET WDT
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 287
Watchdog Timer
0xFFFF
MCWDTx_WDT0/
WDT1 Match value
MCWDTx_WDT0/WDT1 MCWDTx_WDT0/WDT1
counters overflow counters overflow
Counts value
MCWDTx_WDT0/WDT1 operation with WDT_CLEARx bit = 1
0xFFFF
MCWDTx_WDT0/
WDT1 Match value
Time
MCWDTx_WDT0/WDT1
interrupt and WDT0
reset
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 288
Watchdog Timer
0xFFFFFFFF
0x0000 0010
0x0000 000F
0x0000 000E
0x0000 000D
0x0000 000C
0x0000 000B
0x0000 000A
0x0000 0009
0x0000 0008
0x0000 0007
0x0000 0006
0x0000 0005
0x0000 0004
0x0000 0003
0x0000 0002
0x0000 0001
0x0000 0000
Time
MCWDTx_WDT2 Interrupt
WDT_BITS2 = 1 MCWDTx_WDT2
MCWDTx_WDT2 Interrupt counter period
WDT_BITS2 = 2
MCWDTx_WDT2 Interrupt
WDT_BITS2 = 3
MCWDTx_WDT2 Interrupt
WDT_BITS2 = 4
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 289
Watchdog Timer
Note: When the watchdog counters are configured to generate an interrupt every LFCLK cycle, make sure you read the
MCWDTx_INTR register after clearing the watchdog interrupt (setting the WDT_INTx bit in the MCWDTx_INTR register).
Failure to do this may result in missing the next interrupt. Hence, the interrupt period becomes LFCLK/2.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 290
Watchdog Timer
When using cascade (WDT_CASCADE0_1 or WDT_CASCADE1_2 set), resetting the counters when the prescaler or lower
counter is at its match value with the counter configured to clear on match, results in the upper counter incrementing to 1
instead of remaining at 0. This behavior can be corrected by issuing a second reset to the upper counter after approximately
100 µs from the first reset. Note that the second reset is required only when the first reset is issued while the prescaler
counter value is at its match value. Figure 24-6 illustrates the behavior when MCWDTx_WDT0 and MCWDTx_WDT1 are
cascaded along with the second reset timing.
Figure 24-6. MCWDT Reset Behavior in Cascaded Mode
LFCLK
WDT_RESET1
~100 µs
Other settings:
WDT_CASCADE0_1 = 1
WDT_CLEAR0 = 1
WDT_MATCH0 = 0x0020
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 291
Watchdog Timer
In addition, the counters exhibit non-monotonicity in the 6. Lock the MCWDTx configuration by setting the
following cascaded conditions: WDT_LOCK bits of the MCWDTx_CTL register.
■ If WDT_CASCADE0_1 is set, then WDT_CTR1 does not 7. In the firmware, feed (reset) the watchdog as explained
increment the cycle after WDT_CTR0 = WDT_MATCH0. in step 4.
■ If WDT_CASCADE1_2 is set, then WDT_CTR2 does not Do not reset watchdog in the WDT ISR. It is also not
increment the cycle after WDT_CTR1 = WDT_MATCH1. recommended to use the same watchdog counter to
■ If both WDT_CASCADE0_1 and WDT_CASCADE1_2 generate a system reset and interrupt. For example, if
are set, then WDT_CTR2 does not increment the cycle MCWDTx_WDT0 is used to generate system reset against
after WDT_CTR1 = WDT_MATCH1 and WDT_CTR1 crashes, then MCWDTx_WDT1 or MCWDTx_WDT2 should
does not increment the cycle after WDT_CTR0 = be used for periodic interrupt generation.
WDT_MATCH0.
When cascading is enabled, always read the WDT_CTR1 or 24.4.5 MCWDT Interrupt
WDT_CTR2 counter value only when the prescaler counter When configured to generate an interrupt, the WDT_INTx
(WDT_CTR0 or WDT_CTR1) value is not 0. This makes bits of the MCWDTx_INTR register provide the status of any
sure the upper counter is incremented after a match event in pending watchdog interrupts. The firmware must clear the
the prescaler counter. interrupt by setting the WDT_INTx. The WDT_INTx bits of
the MCWDTx_INTR_MASK register mask the
24.4.4 MCDWT Reset corresponding WDTx interrupt of the MCWDTx block to the
CPU.
MCWDTx_WDT0 and MCWDTx_WDT1 can be configured
to generate a device reset similar to the free-running WDT Follow these steps to use WDT as a periodic interrupt
reset. Note that when the debug probe is connected, the generator:
device reset is blocked but an interrupt is generated if 1. Write the desired match value to the WDT_MATCH
configured. Follow these steps to use the MCWDTx_WDT0 register for MCWDTx_WDT0/WDT1 or the WDT_BITS2
or MCWDTx_WDT1 counter of a MCWDTx block to value to the MCWDTx_CONFIG register for
generate a system reset: MCWDTx_WDT2. Note: The legal value for the
1. Configure the MCWDT to generate a reset using the WDT_MATCH field is 1 to 65535.
WDT_MODEx bits in MCWDTx_CONFIG. Configure the 2. Configure the WDTx to generate an interrupt using the
WDT_MODE0 or WDT_MODE1 bits in WDT_MODEx bits in MCWDTx_CONFIG. Configure the
MCWDTx_CONFIG to ‘2’ (reset on match) or ‘3’ WDT_MODE0 or WDT_MODE1 bits in
(interrupt on match and reset on the third unhandled MCWDTx_CONFIG for MCWDTx_WDT0 or
interrupt). MCWDTx_WDT1 to ‘1’ (interrupt on match) or ‘3’
2. Optionally, set the WDT_CLEAR0 or WDT_CLEAR1 bit (interrupt on match and reset on third unhandled
in the MCWDTx_CONFIG register for MCWDTx_WDT0 interrupt). For MCWDTx_WDT2, set the WDT_MODE2
or MCWDTx_WDT1 to reset the corresponding bit in the MCWDTx_CONFIG register.
watchdog counter to ‘0’ on a match event. Otherwise, 3. Set the WDT_INT bit in MCWDTx_INTR to clear any
the counters are free running. See Table 24-2 on pending interrupt.
page 289 for details.
4. Set the WDT_CLEAR0 or WDT_CLEAR1 bit in the
3. Calculate the watchdog reset period such that firmware MCWDTx_CONFIG register for MCWDTx_WDT0 or
is able to reset the watchdog at least once during the MCWDTx_WDT1 to reset the corresponding watchdog
period, even along the longest firmware delay path. For counter to ‘0’ on a match event.
WDT_MODEx == 2, match value is same as the
5. Mask the WDTx interrupt to the CPU by setting the
watchdog period. For WDT_MODEx == 3, match value
WDT_INTx bit in the MCWDTx_INTR_MASK register
is one-third of the watchdog period. Write the calculated
match value to the WDT_MATCH register for 6. Enable WDTx by setting the WDT_ENABLEx bit in the
MCWDTx_WDT0 or MCWDTx_WDT1. Optionally, MCWDTx_CTL register. Wait until the WDT_ENABLEDx
enable cascading to increase the interval. Note: The bit is set.
legal value for the WDT_MATCH field is 1 to 65535. 7. Enable MCWDTx interrupt to the CPU by configuring the
4. For WDT_MODEx == 2, set the WDT_RESETx bit in the appropriate ISER register. Refer to the
MCWDTx_CONFIG register to reset the WDTx counter Interrupts chapter on page 56.
to 0. For WDT_MODEx == 3, set the WDT_INTx bit in 8. In the ISR, clear the WDTx interrupt by setting the
MCWDTx_INTR to clear any pending interrupts. WDT_INTx bit in the MCWDTx_INTR register.
5. Enable WDTx by setting the WDT_ENABLEx bit in the Note that interrupts from all three WDTx counters of the
MCWDTx_CTL register. Wait until the WDT_ENABLEDx MCWDT block are mapped as a single interrupt to the CPU.
bit is set. In the interrupt service routine, the WDT_INTx bits of the
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 292
Watchdog Timer
MCWDTx_INTR register can be read to identify the interrupt 24.5 Reset Cause Detection
source. However, each MCWDT block has its own interrupt
to the CPU. For details on interrupts, see the The RESET_WDT bit [0] in the RES_CAUSE register
Interrupts chapter on page 56. indicates the reset generated by the free-running WDT. The
RESET_MCWDTx bit in the RES_CAUSE register indicates
The MCWDT block can send interrupt requests to the CPU
the reset generated by the MCWDTx block. These bits
in Active power mode and to the WIC in Sleep and Deep
remain set until cleared or until a power-on reset (POR),
Sleep power modes. It works similar to the free-running
brownout reset (BOD), or external reset (XRES) occurs. All
WDT.
other resets leave this bit unaltered.
For more details, see the Reset System chapter on
page 257.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 293
25. Trigger Multiplexer Block
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
Every peripheral in the PSoC 6 MCU is interconnected using trigger signals. Trigger signals are means by which peripherals
denote an occurrence of an event or a state. These triggers are used as means to affect or initiate some action in other
peripherals. The trigger multiplexer block helps to route triggers from a source peripheral block to a destination.
25.1 Features
■ Ability to connect any trigger signal from one peripheral to another
■ Supports a software trigger, which can trigger any signal in the block
■ Supports multiplexing of triggers between peripherals
■ One-to-one trigger paths for dedicated triggers that are more commonly routed
■ Ability to configure a trigger multiplexer with trigger manipulation features in hardware such as inversion and edge/level
detection
■ Ability to block triggers in debug mode
25.2 Architecture
The trigger signals in the PSoC 6 MCU are digital signals generated by peripheral blocks to denote a state such as FIFO
level, or an event such as the completion of an action. These trigger signals typically serve as initiator of other actions in other
peripheral blocks. An example is an ADC peripheral block sampling three channels. After the conversion is complete, a
trigger signal will be generated, which in turn triggers a DMA channel that transfers the ADC data to a memory buffer. This
example is shown in Figure 25-1.
Figure 25-1. Trigger Signal Example
Ch1
DMA
Ch2 ADC
Ch3 EoC
Trigger signal
A PSoC 6 MCU has multiple peripheral bocks; each of these blocks can be connected to other blocks through trigger signals,
based on the system implementation. To support this, the PSoC 6 MCU has hardware, which is a series of multiplexers used
to route the trigger signals from potential sources to destinations. This hardware is called the trigger multiplexer block. The
trigger multiplexer can connect to any trigger signal emanating out of any peripheral block in the PSoC 6 MCU and route it to
any other peripheral to initiate or affect an operation at the destination peripheral block.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 294
Trigger Multiplexer Block
Out_0
In_(N-1)
Out_1
Out_(M-1)
An equivalent implementation of
a trigger multiplexer group with N
inputs and M outputs
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 295
Trigger Multiplexer Block
Trigger Group 9
Trigger Group 5 1 [0]
1 [0] 24 [1:24]
29 [1:29] 72 [25:96] 1
29 [30:58] PASS tr_sar_in
14 [97:110]
24 [59:82] 14 [111:124]
72 [83:154] 2 [125:126]
*TCPWM1(16-bit)
4 [155:158]
Tr_overflow[0:23]
Tr_compare_match[0:23] 39 [159:197]
Tr_underflow[0:23] 2 [198:199]
8 [200:207]
3 [208:210] 2
CTI tr_in[0:1]
2 [211:212] 1 PROFILE tr_start
1 [213] 1 PROFILE tr_stop
1 [214]
1 [215]
1 [216]
14 [217:230]
14 [231:244]
FAULT Tr_out[0:1] 2 [245:246]
CTI Tr_out[0:1] 2 [247:248]
2 [249:250]
Note: * indicates that Figure 25-4 shows details about the TCPWM and SCB inputs.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 296
Trigger Multiplexer Block
[17]
Tr_overflow[0]
[18]
Tr_compare_match[0]
[19]
TCPWM0(32-bit) Tr_underflow[0]
Tr_overflow[0:3] 12[17:28] ...
...
Tr_compare_match[0:3] ... [26]
Tr_underflow[0:3] Tr_overflow[3]
[27]
Tr_compare_match[3]
[28]
Tr_underflow[3]
[61]
Tr_i2c_scl_filtered[0]
[62]
Tr_tx_req[0]
[63]
SCB Tr_rx_req[0]
Tr_i2c_scl_filtered[0:12] 39 [61:99] ...
...
Tr_tx_req[0:12] ... [97]
Tr_rx_req[0:12] Tr_i2c_scl_filtered[12]
[98]
Tr_tx_req[12]
[99]
Tr_tx_req[12]
Note: The format in these diagrams apply to all TCPWM and SCB connections in the trigger groups that have these
connections. The trigger input line number will change between trigger groups and will not always start at 17 and 61 as shown
in the TCPWM and SCB diagrams.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 297
Trigger Multiplexer Block
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 298
26. Profiler
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC 6 MCU Profiler provides counters that can measure duration or number of events of a particular peripheral.
Functions such as DMA transfers or buffered serial communications can happen asynchronously, and are not directly tied to
the CPU or code execution. The profiler provides additional insight into the device so you can identify an asynchronous
activity that could not be monitored previously.
The profiler manages a set of counters. You configure an available counter to monitor a particular source. Depending on the
nature of the source, you count either duration (reference clock cycles) or the number of events.
The ability to monitor specific peripherals enables you to understand and optimize asynchronous hardware, including:
■ Identify the activity of a particular peripheral
■ Identify asynchronous activity
26.1 Features
The profiler has these features and capabilities:
■ A variety of sources you can monitor (see Table 26-1)
■ Support for eight counters, to monitor up to eight sources simultaneously
■ For each counter you specify:
❐ what source to monitor (can be changed dynamically if required)
❐ what to measure (duration or events)
❐ what reference clock to use for the count (only affects duration)
■ Provides ability to easily detect active peripherals that may be difficult to measure by external monitoring
■ Provides an absolute count of events or reference clock cycles for each monitored source
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 299
Profiler
26.2 Architecture
Figure 26-1. Profiler Block Diagram
The profiler supports up to 32 counters. The actual number of counters is hardware dependent. This device supports up to
eight counters.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 300
Profiler
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 301
Profiler
To measure duration accurately, the sample clock should have a stable frequency throughout the profiling session. If your
application remains in active power states, you can use CLK_HF as the sample clock. CLK_HF gives you the greatest
resolution in your results.
The profiler can be enabled in CPU Active and Sleep modes. However, clock frequencies can change based on the power
state of the application. The source clock frequency should be stable throughout the profiling session to ensure reliable data.
High-frequency clocks are not available in System Deep Sleep and Hibernate power modes, so the profiler is disabled. The
configuration registers maintain state through Deep Sleep. Profiler data is lost (registers are not maintained) in Hibernate
mode. See the Device Power Modes chapter on page 225.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 302
Profiler
The count value is a 32-bit register. If that is not a sufficiently large number for your purposes, you must also enable the
profiling interrupt for the counter. See Handle Counter Overflow on page 303.
When gathering data, you may want to know the actual number of clock cycles that occurred during the profiling session. To
get this number, configure a counter to use:
■ PROFILE_ONE as the monitored source
■ duration (not events)
■ a reference clock
The count for that counter is the actual number of reference clock cycles that occurred during the profiling session.
By design, all counters that are in use start and stop simultaneously. During the profiling session, each counter increments at
its own rate based on the monitored signal and (if measuring duration) the reference clock.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 303
Profiler
When an overflow occurs for a particular counter, hardware sets the corresponding bit in the INTR register. You typically do
not read this register.
To enable the profiling interrupt for a particular counter, set the corresponding bit in the INTR_MASK register.
When an interrupt occurs, your interrupt handler reads the bits in the INTR_MASKED register. This register reflects a bitwise
AND between the INTR register (an overflow interrupt has occurred for a particular counter) and the INTR_MASK register
(this counter has the interrupt enabled). When a bit is set in the INTR_MASKED register, the corresponding counter is
enabled and has experienced an overflow.
You can artificially trigger an overflow interrupt to test your code. The INTR_SET register also has one bit per counter. For
debug purposes, software can set the appropriate bit to activate a specific overflow interrupt. This enables debug of the
interrupt without waiting for hardware to cause the interrupt.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 304
Section D: Digital Subsystem
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 305
Digital Subsystem
Boundary Scan
Audio Subsystem
Color Key:
Power Modes and
Domains
System
DeepSleep Mode
System
Hibernate Mode
Backup USB
Domain PHY
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 306
27. Secure Digital Host Controller (SDHC)
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The secure digital host controller (SDHC) in the PSoC 6 MCU allows interfacing with embedded multimedia card (eMMC)-
based memory devices, secure digital (SD) cards, and secure digital input output (SDIO) cards. The block supports all three
interfaces – SD, SDIO, and eMMC. The block can also work with devices providing SDIO interface, such as Cypress' Wi-Fi
products (for example, CYW4343W). Figure 27-1 illustrates a typical application using the SDHC block.
Figure 27-1. Typical SDHC Application
PSoC 6
27.1 Features
■ Complies with eMMC 5.1, SD 6.0, and SDIO 4.10 standards
■ Supports host controller interface (HCI) 4.2 shared by eMMC and SD
■ SD interface supports 1-bit and 4-bit bus interfaces, and the following speed modes. The specified data rate is for a 4-bit
bus.
❐ 3.3-V signal voltage: Default speed (12.5 MB/s at 25 MHz) and high speed (25 MB/s at 50 MHz)
❐ UHS-I modes using 1.8-V signal voltage: SDR12 (12.5 MB/s at 25 MHz), SDR25 (25 MB/s at 50 MHz), SDR40 (40
MB/s at 80 MHz), and DDR40 (40 MB/s at 40 MHz)
■ eMMC interface supports 1-bit and 4-bit bus interfaces, and the following speed modes. The specified data rate is for a 4-
bit bus.
❐ Legacy (13 MB/s at 26 MHz), high-speed SDR (26 MB/s at 52 MHz), and high-speed DDR (52 MB/s at 52 MHz)
■ Supports three DMA modes – SDMA, ADMA2, and ADMA3 – through a dedicated DMA engine
■ Provides 1KB SRAM for buffering up to two 512-byte blocks
■ Provides I/O interfaces for bus interface voltage selection (3.3 V/1.8 V) and for power enable/disable
■ Provides I/O interfaces for functions such as card detection, mechanical write protection, eMMC card reset, and LED
control
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 307
Secure Digital Host Controller (SDHC)
SDHC
To System
Interconnect
AHB Master DMA Engine
Interface (SDMA, ADMA2, ADMA3) IOSS
clk_card
card_cmd
card_dat_3to0[3:0]
To Peripheral To I/O
Interconnect Sub-System
AHB Slave Configuration eMMC/SD/SDIO
Interface Registers Interface
Interrupts io_volt_sel
to CPU card_detect_n
Sub-System card_mech_write_prot
card_if_pwr_en
SRAM Controller
CLK_HF[i]
CLK_SYS
1 KB Packet
CLK_SLOW
Buffer SRAM
The SDHC controller supports all three interfaces – SD, SDIO, and eMMC; it supports up to 4-bit bus width. The AHB master
interface helps to transfer data to and from the system memory and the AHB slave interface provides access to the
configuration registers. The register set comprises the standard SD host controller interface (HCI) registers as specified in the
SD Specifications Part A2 SD Host Controller Standard Specification. These registers are described in the registers TRM. The
DMA engine handles direct data transfer between the SDHC logic and system memory. It supports SDMA, ADMA2, and
ADMA3 modes based on the configuration.
The SDHC block complies with the following standards. Refer to the specifications documents for more information on the
protocol and operations.
■ SD Specifications Part 1 Physical Layer Specification Version 6.00
■ SD Specifications Part A2 SD Host Controller Standard Specification Version 4.20
■ SD Specifications Part E1 SDIO Specifications Version 4.10
■ Embedded Multi-Media Card (eMMC) Electrical Standard 5.1
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 308
Secure Digital Host Controller (SDHC)
27.3 Clocking
Table 27-1 lists the different clocks used in the SDHC block. While configuring the clock for SDHC make sure that clk_slow
clk_sys clk_card.
27.3.1 Clock Gating sourced from CLK_HF[i] as explained in Table 27-1. SDCLK
frequency is equal to base clock frequency when the divider
All the clocks except the slave interface clock can be gated value is zero.
internally to enter standby mode (See Power Modes on
page 310). In standby mode, you can also stop the clocks SDCLK Frequency = Base Clock Frequency / (2 × 10-bit
externally if required. The slave clock cannot be gated divider value)
because it is used for wakeup logic (see Interrupts to CPU These fields are set automatically, based on the selected
on page 310) during the standby mode. Bus Speed mode, to a value specified in one of the preset
The card clock is gated by clearing the SD_CLK_EN bit and registers when HOST_CTRL2_R.PRESET_VAL_ENABLE
other clocks are gated by clearing the INTERNAL_CLK_EN is set. The preset registers are selected according to
bit of the CLK_CTRL_R register. See Clock Setup on Table 27-2.
page 316 for the sequence to be followed while modifying
this bit. 27.3.4 Timeout (TOUT) Configuration
An internal timer is used for command and data timeouts.
27.3.2 Base Clock (CLK_HF[i]) The timeout value is specified through the
Configuration TOUT_CTRL_R.TOUT_CNT register field. The timer clock
(TMCLK) frequency indicated by the read-only fields
The HCI register (Capabilities) has a read-only field
TOUT_CLK_FREQ and TOUT_CLK_UNIT of
(BASE_CLK_FREQ) to indicate the base clock frequency so
CAPABILITIES1_R register is 1 MHz. Timer clock is derived
that an SD HCI-compatible driver can easily configure the
by dividing the CLK_HF[i], which means that CLK_HF[i]
divider for the required bus speed. This value is set to 0x64
must be set to 100 MHz to be compatible with the
(100 MHz) and hence CLK_HF[i] must be set to 100 MHz. If
Capabilities register.
this compatibility is not required, CLK_HF[i] can be set to
any value. See 27.3.4 Timeout (TOUT) Configuration.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 309
Secure Digital Host Controller (SDHC)
27.5 Power Modes insertion. See 27.5.1 Standby Mode for details. As card
insertion and removal is not applicable to an embedded
The block can operate during active and sleep system device, wakeup interrupt should not be used in this case.
power modes. It does not support deep sleep mode and However it can still be used for SDIO card interrupt.
cannot wake up from events such as card insertion and ■ General Interrupt Signal – Triggered on all other events,
removal when the system is in deep sleep. All the core in either normal conditions or error conditions.
registers except the packet buffer SRAM are retained when
the system enters deep sleep mode and the SRAM is A host driver must not enable the wakeup and general
switched off to save power. Retention is performed so that interrupt signals at the same time.
the block can resume operation immediately after wakeup To use only the wakeup interrupt signal, clear the
from deep sleep without requiring reconfiguration. Make NORMAL_INT_STAT_R and
sure that no AHB traffic (such as register read/write and NORMAL_INT_SIGNAL_EN_R registers, and then set the
DMA operation) is present, the SD/SDIO/eMMC bus enable bits of the required wakeup events in the
interface is idle, and no data packets are pending in the WUP_CTRL_R and NORMAL_INT_STAT_EN registers.
packet buffer SRAM when the system transitions into deep
sleep mode. To use only the general interrupt signal, clear the
WUP_CTRL_R and NORMAL_INT_STAT_R registers.
Then, set the required bits in
27.5.1 Standby Mode NORMAL_INT_SIGNAL_EN_R and
The block can be put into standby mode to save power NORMAL_INT_STAT_EN registers.
during the active and sleep system power modes by turning
These interrupts remain asserted until the CPU clears the
off the clocks. See Clock Gating on page 309 for details.
interrupt status through one of the status registers –
The block can detect wakeup interrupts (see Interrupts to
NORMAL_INT_STAT_R and ERROR_INT_STAT_R.
CPU on page 310) in standby mode.
The SDIO card interrupt status bit, CARD_INTERRUPT, is a
read-only bit. The host driver may clear the
27.6 Interrupts to CPU NORMAL_INT_STAT_EN_R.CARD_INTERRUPT_STAT_E
N bit before servicing the SDIO card interrupt and may set
The block provides two interrupt signals to CPUSS:
this bit again after all interrupt requests from the card are
■ Wakeup Interrupt Signal – Triggered on events such as cleared to prevent inadvertent interrupts.
card insertion, removal, and SDIO card interrupt. This
interrupt source cannot wake up the system from deep
sleep mode and is provided so that a host driver can
take appropriate action on those events. For example,
resuming operation from standby mode on card
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 310
Secure Digital Host Controller (SDHC)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 311
Secure Digital Host Controller (SDHC)
27.7.1 Switching Signaling Voltage from transfers to the cards do not occur simultaneously, a single
shared buffer is used for read and write operations. During
3.3 V to 1.8 V the data transfer command handshake, the read/write bit of
The I/Os operate at the voltage level supplied through the the command register is sampled and stored. This internal
external VDDIO pin. The SD mode supports switching the bit defines whether the SDHC is in read or write mode.
signaling voltage from 3.3 V to 1.8 V after negotiation with
Figure 27-3 shows how data flows from the card interface to
the SD card. The block sets the
the AHB master interface through the packet buffer for a
HOST_CTRL2_R.SIGNALING_EN bit to indicate the switch.
card read transfer. Received data from the card interface is
This value is reflected on the io_volt_sel pin, which can be
written into packet buffer. When one block of data is
connected to an external regulator powering VDDIO to switch
received, DMA starts transmitting that data to the system by
between 3.3 V and 1.8 V. Note that PSoC 6 does not
reading it from the packet buffer. For a card write transfer,
provide an internal regulator to power the SD interface I/Os.
data flows in the reverse direction. DMA writes data into a
packet buffer that is subsequently read by the card interface
27.8 Packet Buffer SRAM logic. DMA and card interface logic can work simultaneously
because read and write to packet buffer can be interleaved.
SRAM that is internal to the SDHC block is used as a packet For card read, DMA can send out the previous block while
buffer to store data packets while carrying out data transfer card interface logic is receiving the current block. For card
to and from the card. The size of the SRAM is 1KB to write, DMA can write the current block into packet buffer
support buffering of two 512 bytes blocks. As write and read while card interface logic is sending out the previous block.
Figure 27-3. Data Flow in a Read Transfer
Card
SRAM
AHB DMA Interface
Controller SD/eMMC
Master Logic
Bus
Packet Buffer
(SRAM)
27.8.1 Packet Buffer Full/Empty is moving data during task execution (for CMD46 and
CMD47).
When the packet buffer becomes full in card read, the clock
■ Prefetches data for back-to-back eMMC write
to the card is stopped to prevent the card from sending the
commands.
next data block. When packet buffer is empty, data block is
not sent. In both cases, card interface logic is idle. SDHC ■ Writes back the received data packets to system
does not support SDIO Read Wait signaling through DAT[2]. memory.
Therefore, the I/O command (CMD52) cannot be performed Figure 27-4 shows the data flow between the host driver and
during a multiple read cycle because the card clock is SD bus. The host driver can transfer data using either a
stopped. programmed I/O (PIO) method in which the internal buffer is
accessed through the buffer data port (BUF_DATA_R)
register or using any of the defined DMA methods. PIO
27.9 DMA Engine mode is much slower and burdens the processor. Do not
The DMA engine handles data transfer between SDHC and use the PIO mode for large transfers.
system memory. Following are the features of this unit:
■ Supports SDMA, ADMA2, and ADMA3 modes based on
the configuration.
■ The same DMA engine is used to interleave data
transfer and descriptor fetch. This enables new task
descriptor fetches (for CMD44 and CMD45) while DMA
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 312
Secure Digital Host Controller (SDHC)
Figure 27-4. Data Flow Refer to the respective specifications documents listed in
Block Diagram on page 308 to learn more about the DMA
Host Driver operation.
YES IS
DMA supports both single block and multi-block transfers. EMBEDDED
The control bits in the block gap control (BGAP_CTRL_R) CARD?
Card detect
register is used to stop and restart a DMA operation. SDMA NO interrupt occurs
mode is used for short data transfer because it generates
interrupts at page boundaries. These interrupts disturb the
IS CARD NO Configure interrupt
CPU to reprogram the new system address. Only one SD PRESENT? for card detection
command transaction can be executed for every SDMA
operation. YES
ADMA2 and ADMA3 are used for long data transfers. They Initialize SDHC
adopt scatter gather algorithm so that higher data transfer
speed is available. The host driver can program a list of data
transfers between system memory and SD card to the Setup Clock
descriptor table. ADMA2 performs one read/write SD
command operation at a time. ADMA3 can program multiple Initialize Card
read/write SD command operation in a descriptor table.
In SDMA and ADMA2 modes, writing the CMD_R register
Card Read/Write
triggers the DMA operation. In ADMA3 mode, writing
ADMA_ID_LOW_R register triggers the DMA operation.
SD mode commands are generated by writing into the END
following registers – system address (SDMASA_R), block
size (BLOCKSIZE_R), block count (BLOCKCOUNT_R),
transfer mode (XFER_MODE_R), and command (CMD_R). 27.10.1 Enabling SDHC
When HOST_CTRL2_R.HOST_VER4_EN = 0, SDMA uses
SDMASA_R as system address register and hence Auto Ensure clk_sys is configured to be greater than or equal to
CMD23 cannot be used with SDMA because this register is clk_card and is running. Then, follow the sequence in
assigned for Auto CMD23 as the 32-bit block count register. Figure 27-6 to enable the block. The internal clock can also
When HOST_CTRL2_R.HOST_VER4_EN = 1, SDMA uses be enabled later during clock setup. It must be enabled to
ADMA_SA_LOW_R as system address register and detect card insertion or removal through general interrupts
SDMASA_R is reassigned to 32-bit block count and hence when SDHC is not in standby mode. See 27.10.2 Card
SDMA may use Auto CMD23. Detection for details.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 313
Secure Digital Host Controller (SDHC)
Figure 27-6. SDHC Enable Sequence Figure 27-7. Card Status Check Sequence
START START
SDHC_WRAP_CTL.ENABLE = 1 GP_OUT_R.CARD_DETECT_EN = 1
CLK_CTRL_R.INTERNAL_CLK_EN = 1
IS NO
PSTATE_REG.CARD
IS _STABLE = 1?
CLK_CTRL_R.INTER
NO
NAL_CLK_STABLE =
1?
YES
YES
Card is not
IS present
END PSTATE_REG.CARD
_INSERTED = 1?
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 314
Secure Digital Host Controller (SDHC)
GP_OUT_R.CARD_DETECT_EN = 1
WUP_CTRL_R = 0
NORMAL_INT_STAT_EN_R.CARD_INSERTION_STAT_EN = 1
NORMAL_INT_SIGNAL_EN_R.CARD_INSERTION_SIGNAL_EN = 1
NORMAL_INT_STAT_EN_R.CARD_REMOVAL_STAT_EN = 1
NORMAL_INT_SIGNAL_EN_R.CARD_REMOVAL_SIGNAL_EN = 1
Card is
IS YES Clear interrupt status:
NORMAL_INT_STAT_
present
R.CARD_INSERTION
NORMAL_INT_STAT_R.
= 1? CARD_INSERTION = 1
NO
Card is not
IS YES Clear interrupt status: present
NORMAL_INT_STAT_
R.CARD_REMOVAL
NORMAL_INT_STAT_R.
= 1? CARD_REMOVAL = 1
NO
END
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 315
Secure Digital Host Controller (SDHC)
Is Card Type = NO
eMMC? YES
YES Configure
GP_OUT_R.CARD_CLOCK_OUT_DLY and
GP_OUT_R.CARD_CLOCK_IN_DLY
EMMC_CTRL_R.CARD_IS_EMMC = 1 as per speed mode*
CLK_CTRL_R.PLL_ENABLE = 1
Configure DMA type through
HOST_CTRL1_R.DMA_SEL
YES
END
END
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 316
Secure Digital Host Controller (SDHC)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 317
28. Serial Communications Block (SCB)
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The Serial Communications Block (SCB) supports three serial communication protocols: Serial Peripheral Interface (SPI),
Universal Asynchronous Receiver Transmitter (UART), and Inter Integrated Circuit (I2C or IIC). Only one of the protocols is
supported by an SCB at any given time. The number of SCBs in a PSoC 6 MCU varies by part number; consult the PSoC 61
datasheet/PSoC 62 datasheet to determine number of SCBs and the SCB pin locations. Not all SCBs support all three modes
(SPI, UART, and I2C); consult the PSoC 61 datasheet/PSoC 62 datasheet to determine which modes are supported by which
SCBs. Not all SCBs operate in deep sleep, consult the PSoC 61 datasheet/PSoC 62 datasheet to determine which SCBs
operate in deep sleep.
28.1 Features
The SCB supports the following features:
■ Standard SPI master and slave functionality with Motorola, Texas Instruments, and National Semiconductor protocols
■ Standard UART functionality with SmartCard reader, Local Interconnect Network (LIN), and IrDA protocols
❐ Standard LIN slave functionality with LIN v1.3 and LIN v2.1/2.2 specification compliance
■ Standard I2C master and slave functionality
■ Trigger outputs for connection to DMA
■ Multiple interrupt sources to indicate status of FIFOs and transfers
■ Features available only on Deep Sleep-capable SCB:
❐ EZ mode for SPI and I2C slaves; allows for operation without CPU intervention
❐ CMD_RESP mode for SPI and I2C slaves; allows for operation without CPU intervention
❐ Low-power (Deep Sleep) mode of operation for SPI and I2C slaves (using external clocking)
❐ Deep Sleep wakeup on I2C slave address match or SPI slave selection
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 318
Serial Communications Block (SCB)
28.2 Architecture CMD_RESP mode is available only for SPI slave and I2C
slave. It is available only on the Deep Sleep-capable SCB.
The operation modes supported by SCB are described in
the following sections. CMD_RESP mode operation is available in Active, Sleep,
and Deep Sleep power modes.
28.2.1 Buffer Modes
28.2.2 Clocking Modes
Each SCB has 256 bytes of dedicated RAM for transmit and
receive operation. This RAM can be configured in three The SCB can be clocked either by an internal clock provided
different modes (FIFO, EZ, or CMD_RESP). The following by the peripheral clock dividers (referred to as clk_scb in this
sections give a high-level overview of each mode. The document), or it can be clocked by the external master.
sections on each protocol will provide more details. ■ UART, SPI master, and I2C master modes must use
■ Masters can only use FIFO mode clk_scb.
■ I2C and SPI slaves can use all three modes. Note: EZ ■ Only SPI slave and I2C slave can use the clock from and
Mode and CMD Response Mode are available only on external master, and only the Deep Sleep capable SCB
the Deep Sleep-capable SCB supports this.
■ UART only uses FIFO mode Internally- and externally-clocked slave functionality is
determined by two register fields of the SCB CTRL register:
Note: This document discusses hardware implementation of
the EZ mode; for the firmware implementation, see the PDL. ■ EC_AM_MODE indicates whether SPI slave selection or
I2C address matching is internally (‘0’) or externally (‘1’)
28.2.1.1 FIFO Mode clocked.
■ EC_OP_MODE indicates whether the rest of the
In this mode the RAM is split into two 128-byte FIFOs, one protocol operation (besides SPI slave selection and I2C
for transmit (TX) and one for receive (RX). The FIFOs can address matching) is internally (‘0’) or externally (‘1’)
be configured to be 8 bits x 128 elements or 16 bits x 64 clocked.
elements; this is done by setting the BYTE_MODE bit in the
SCB control register. Notes:
■ FIFO mode supports an internally- or externally-clocked
FIFO mode of operation is available only in Active and Sleep
address match (EC_AM_MODE is ‘0’ or ‘1’); however,
power modes. However, the I2C address or SPI slave select
data transfer must be done with internal clocking.
can be used to wake the device from Deep Sleep on the
(EC_OP_MODE is ‘1’).
Deep Sleep-capable SCB.
■ EZ and CMD_RESP modes are supported with
Statuses are provided for both the RX and TX FIFOs. There externally clocked operation (EC_OP_MODE is ‘1’).
are multiple interrupt sources available, which indicate the
status of the FIFOs, such as full or empty; see “SCB Table 28-1 provides an overview of the clocking and buffer
Interrupts” on page 366. modes supported for each communication mode.
28.2.1.2 EZ Mode
In easy (EZ) mode the RAM is used as a single 256-byte
buffer. The external master sets a base address and reads
and writes start from that base address.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 319
Serial Communications Block (SCB)
28.3.1 Features
■ Supports master and slave functionality
■ Supports three types of SPI protocols:
❐ Motorola SPI – modes 0, 1, 2, and 3
❐ Texas Instruments SPI, with coinciding and preceding data frame indicator – mode 1 only
❐ National Semiconductor (MicroWire) SPI – mode 0 only
■ Master supports up to four slave select lines
❐ Each slave select has configurable active polarity (high or low)
❐ Slave select can be programmed to stay active for a whole transfer, or just for each byte
■ Master supports late sampling for better timing margin
■ Master supports continuous SPI clock
■ Data frame size programmable from 4 bits to 16 bits
■ Programmable oversampling
■ MSb or LSb first
■ Median filter available for inputs (when using the median filter, the minimum oversample factor is increased)
■ Supports FIFO Mode
■ Supports EZ Mode (slave only) and CMD_RESP mode (slave only) on the Deep Sleep-capable SCB
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 320
Serial Communications Block (SCB)
SCLK
MOSI
SPI
SPI MISO Slave 1
Master Slave Select (SS) 1
SPI
Slave 2
Slave Select (SS) 2
SPI
Slave 3
Slave Select (SS) 3
SPI
Slave 4
Slave Select (SS) 4
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 321
Serial Communications Block (SCB)
Three different variants of the SPI protocol are supported by the SCB:
■ Motorola SPI: This is the original SPI protocol.
■ Texas Instruments SPI: A variation of the original SPI protocol, in which data frames are identified by a pulse on the SS
line.
■ National Semiconductors SPI: A half-duplex variation of the original SPI protocol.
SCLK
CPOL = 0 CPHA = 1
SCLK
MISO /
MSb LSb
MOSI
CPOL = 1 CPHA = 0
SCLK
MISO /
MSb LSb
MOSI
CPOL = 1 CPHA = 1
SCLK
MISO /
MOSI MSb LSb
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 322
Serial Communications Block (SCB)
Figure 28-3 illustrates a single 8-bit data transfer and two successive 8-bit data transfers in mode 0 (CPOL is ‘0’, CPHA is ‘0’).
Figure 28-3. SPI Motorola Data Transfer Example
CPOL = 0, CPHA = 0 single data transfer
SCLK
SS
SCLK
SS
clk_scb
SS0
SCLK
¾ SCLK ¼ SCLK
CPHA = 1, CPOL = 0
Oversampling = 5 (1 SCLK period contains 6 clk_scb periods)
clk_scb
SS0
SCLK
¼ SCLK ¾ SCLK
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 323
Serial Communications Block (SCB)
SCLK
SS
SCLK
SS
Figure 28-6 illustrates a single 8-bit data transfer and two successive 8-bit data transfers. The SELECT pulse coincides with
the first data bit of a frame.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 324
Serial Communications Block (SCB)
SCLK
SS
SCLK
SS
MOSI
MSb LSb MSb LSb
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 325
Serial Communications Block (SCB)
SCLK
SS
MSb LSb
MOSI
idle 0 cycle
SCLK
SS
idle 0 cycle
No idle cycle
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 326
Serial Communications Block (SCB)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 327
Serial Communications Block (SCB)
Figure 28-8. SPI Slave Wakeup from Deep Sleep (Motorola, CPHA = 0, CPOL = 0)
Wakeup event
SS0
SCLK
TDEEPSLEEP
Load TX buffer
EZ Address Write
A write of the EZ address starts with a command byte (0x00) on the MOSI line indicating the master’s intent to write the EZ
address. The slave then drives a reply byte on the MISO line to indicate that the command is acknowledged (0xFE) or not
(0xFF). The second byte on the MOSI line is the EZ address.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 328
Serial Communications Block (SCB)
wrap around to 0. The EZ base address is reset to the address written in the EZ Address Write phase on each slave
selection.
Figure 28-9 illustrates the write of EZ address, write to a memory array and read from a memory array operations in the
EZSPI protocol.
Figure 28-9. EZSPI Example
Command 0x00 : Write EZ address
SCLK
SS
MISO
EZ address (8 bits)
EZ address
Command 0x01 : Write DATA
SCLK
SS
MISO
Write
DATA
EZ address EZ buffer
(32 bytes SRAM)
Read
DATA
SCLK
SS
LEGEND :
CPOL : Clock Polarity 0x00 : Write EZ address
CPHA : Clock Phase 0x01 : Write DATA
SCLK : SPI Interface Clock 0x02 : Read DATA
MISO : SPI Master-In-Slave-Out 0xFE : slave ready
MOSI : SPI Master-Out-Slave-In 0xFF : slave busy
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 329
Serial Communications Block (SCB)
Configuring SCB for EZSPI Mode The CPU writes and reads to the memory buffer through the
SCB_EZ_DATA registers. These accesses are word
By default, the SCB is configured for non-EZ mode of accesses, but only the least significant byte of the word is
operation. To configure the SCB for EZSPI mode, set the used.
register bits in the following order:
1. Select EZ mode by writing ‘1’ to the EZ_MODE bit (bit The slave interface accesses the memory buffer using the
10) of the SCB_CTRL register. current addresses. At the start of a write transfer (SPI slave
selection), the base write address is copied to the current
2. Set the EC_AM and EC_OP modes in the SCB_CTRL write address. A data element write is to the current write
register as appropriate. address location. After the write access, the current address
3. Set the BYTE_MODE bit of the SCB_CTRL register to is incremented by ‘1’. At the start of a read transfer, the base
‘1’. read address is copied to the current read address. A data
4. Follow the steps in “Configuring SCB for SPI Motorola element read is to the current read address location. After
Mode” on page 324. the read data element is transmitted, the current read
address is incremented by ‘1’.
5. Follow steps 2 to 4 mentioned in “Enabling and Initializ-
ing SPI” on page 334. If the current addresses equal the last memory buffer
address (address equals 255), the current addresses are
For more information on these registers, see the registers
not incremented. Subsequent write accesses will overwrite
TRM.
any previously written value at the last buffer address.
Subsequent read accesses will continue to provide the
Active to Deep Sleep Transition
(same) read value at the last buffer address. The bus
Before going to deep sleep ensure the master is not master should be aware of the memory buffer capacity in
currently transmitting to the slave. This can be done by command-response mode.
checking the BUS_BUSY bit in the SPI_STATUS register.
The base addresses are provided through
If the bus is not busy, disable the clock to the SCB by setting CMD_RESP_CTRL. The current addresses are provided
the SDA_IN_FILT_TRIM[1] bit to ‘0’ in the I2C_CFG register. through CMD_RESP_STATUS. At the end of a transfer (SPI
slave de-selection), the difference between a base and
Deep Sleep to Active Transition current address indicates how many read/write accesses
were performed. The block provides interrupt cause fields to
■ EC_AM = 1, EC_OP = 0, EZ Mode. MISO transmits
identify the end of a transfer. Command-response mode
0xFF until the internal clock is enabled. Data on MOSI is
operation is available in Active, Sleep, and Deep Sleep
ignored until the internal clock is enabled. Do not enable
power modes.
the internal clock until clk_hf[0] is at the desired
frequency. After clk_hf[0] is at the desired frequency set The command-response mode has two phases of operation:
the SDA_IN_FILT_TRIM[1] bit to ‘1’ to enable the clock. ■ Write phase – The write phase begins with a selection
The external master needs to be aware that when it byte, which has its last bit set to ‘0’ indicating a write.
reads 0xFF on MISO the device is not ready yet. The master writes 8-bit data elements to the slave’s
■ EC_AM = 1, EC_OP = 1, EZ Mode. Do not enable the memory buffer following the selection byte. The slave’s
internal clock until clk_hf[0] is at the desired frequency. current write address is set to the slave’s base write
After clk_hf[0] is at the desired frequency set the address. Received data elements are written to the
SDA_IN_FILT_TRIM[1] bit to ‘1’ to enable the clock. current write address memory location. After each
memory write, the current write address is incremented.
28.3.4.3 Command-Response Mode ■ Read phase – The read phase begins with a selection
The command-response mode is defined only for an SPI byte, which has its last bit set to ‘1’ indicating a read. The
slave. In the PSoC 6 MCU, only the deep sleep-capable master reads 8-bit data elements from the slave’s
SCB supports this mode. This mode has a single memory memory buffer. The slave’s current read address is set
buffer, a base read address, a current read address, a base to the slave’s base read address. Transmitted data
write address, and a current write address that are used to elements are read from the current address memory
index the memory buffer. The base addresses are provided location. After each read data element is transferred, the
by the CPU. The current addresses are used by the slave to current read address is incremented.
index the memory buffer for sequential accesses of the During the reception of the first byte, the slave (MISO)
memory buffer. The memory buffer holds 256 8-bit data transmits either 0x62 (ready) or a value different from 0x62
elements. The base and current addresses are in the range (busy). When disabled or reset, the slave transmits 0xFF
[0, 255]. This mode is only supported by the Motorola mode (busy). The byte value can be used by the master to
of operation. determine whether the slave is ready to accept the SPI
request.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 330
Serial Communications Block (SCB)
spi_clk
spi_select
spi_miso
ready (0x62 byte)
spi_select
spi_mosi 0x01
Note that a slave’s base addresses are updated by the CPU Configuring SCB for CMD_RESP Mode
and not by the master.
By default, the SCB is configured for non-CMD_RESP mode
Active to Deep Sleep Transition of operation. To configure the SCB for CMD_RESP mode,
set the register bits in the following order:
Before going to deep sleep ensure the master is not 1. Select the CMD_RESP mode by writing ‘1’ to the
currently transmitting to the slave. This can be done by CMD_RESP_MODE bit (bit 12) of the SCB_CTRL
checking the BUS_BUSY bit in the SPI_STATUS register. register.
If the bus is not busy, disable the clock to the SCB by setting 2. Set the EC_AM and EC_OP modes to ‘1’ in the
the SDA_IN_FILT_TRIM[1] bit to 0 in the I2C_CFG register. SCB_CTRL register.
3. Set the BYTE_MODE bit in the SCB_CTRL register.
Deep Sleep to Active Transition
4. Follow the steps in “Configuring SCB for SPI Motorola
EC_AM = 1, EC_OP = 1, CMD_RESP Mode. Mode” on page 324.
Do not enable the internal clock until clk_hf[0] is at the 5. Follow steps 2 to 4 mentioned in“Enabling and
desired frequency. When clk_hf[0] is at the desired Initializing SPI” on page 334.
frequency, set the SDA_IN_FILT_TRIM[1] bit to ‘1’ to enable For more information on these registers, see the registers
the clock. TRM.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 331
Serial Communications Block (SCB)
28.3.5 Clocking and Oversampling the reception of the command byte. In Active power
mode, the slave (MISO) transmits a ready (0xFE)
28.3.5.1 Clock Modes byte during the reception of the command byte.
❐ CMD_RESP mode: Not supported. The slave trans-
The SCB SPI supports both internally and externally clocked mits (MISO) a value different from a ready (0x62)
operation modes. Two bitfields (EC_AM_MODE and byte during the reception of the first byte.
EC_OP MODE) in the SCB_CTRL register determine the
SCB clock mode. EC_AM_MODE indicates whether SPI ■ EC_AM_MODE is ‘1’ and EC_OP_MODE is ‘1’. Use this
slave selection is internally (0) or externally (1) clocked. mode when both Active and Deep Sleep functionality are
EC_OP_MODE indicates whether the rest of the protocol required. When the slave is selected,
operation (besides SPI slave selection) is internally (0) or INTR_SPI_EC.WAKE_UP is set to ‘1’. The associated
externally (1) clocked. Deep Sleep functionality interrupt brings the system into
Active power mode. When the slave is deselected,
An externally-clocked operation uses a clock provided by INTR_SPI_EC.EZ_STOP and/or
the external master (SPI SCLK). Note: In the PSoC 6 MCU INTR_SPI_EC.EZ_WRITE_STOP are set to ‘1’.
only the Deep Sleep-capable SCB supports externally- ❐ FIFO mode: Not supported.
clocked mode of operation and only for SPI slave mode.
❐ EZ mode: Supported.
An internally-clocked operation uses the programmable ❐ CMD_RESP mode: Supported.
clock dividers. For SPI, an integer clock divider must be
used for both master and slave. For more information on If EC_OP_MODE is ‘1’, the external interface logic accesses
system clocking, see the Clocking System chapter on the memory buffer on the external interface clock (SPI
page 242. SCLK). This allows for EZ and CMD_RESP mode
functionality in Active and Deep Sleep power modes.
The SCB_CTRL bitfields EC_AM_MODE and
EC_OP_MODE can be configured in the following ways. In Active system power mode, the memory buffer requires
■ EC_AM_MODE is ‘0’ and EC_OP_MODE is ‘0’: Use this arbitration between external interface logic (on SPI SCLK)
configuration when only Active mode functionality is and the CPU interface logic (on system peripheral clock).
required. This arbitration always gives the highest priority to the
external interface logic (host accesses). The external
❐ FIFO mode: Supported. interface logic takes two serial interface clock/bit periods for
❐ EZ mode: Supported. SPI. During this period, the internal logic is denied service to
❐ Command-response mode: Not supported. The the memory buffer. The PSoC 6 MCU provides two
slave (MISO) transmits a value different from a ready programmable options to address this “denial of service”:
(0x62) byte during the reception of the first byte if ■ If the BLOCK bitfield of SCB_CTRL is ‘1’: An internal
command-response mode is attempted in this logic access to the memory buffer is blocked until the
configuration. memory buffer is granted and the external interface logic
■ EC_AM_MODE is ‘1’ and EC_OP_MODE is ‘0’: Use this has completed access. This option provides normal SCB
configuration when both Active and Deep Sleep register functionality, but the blocking time introduces
functionality are required. This configuration relies on the additional internal bus wait states.
externally-clocked functionality to detect the slave ■ If the BLOCK bitfield of SCB_CTRL is ‘0’: An internal
selection and relies on the internally-clocked logic access to the memory buffer is not blocked, but
functionality to access the memory buffer. fails when it conflicts with an external interface logic
The “hand over” from external to internal functionality access. A read access returns the value 0xFFFF:FFFF
relies on a busy/ready byte scheme. This scheme relies and a write access is ignored. This option does not
on the master to retry the current transfer when it introduce additional internal bus wait states, but an
receives a busy byte and requires the master to support access to the memory buffer may not take effect. In this
busy/ready byte interpretation. When the slave is case, the following failures are detected:
selected, INTR_SPI_EC.WAKE_UP is set to ‘1’. The ❐ Read Failure: A read failure is easily detected
associated Deep Sleep functionality interrupt brings the because the returned value is 0xFFFF:FFFF. This
system into Active power mode. value is unique as non-failing memory buffer read
❐ FIFO mode: Supported. The slave (MISO) transmits accesses return an unsigned byte value in the range
0xFF until the CPU is awoken and the TX FIFO is 0x0000:0000-0x0000:00ff.
populated. Any data on the MOSI line will be ❐ Write Failure: A write failure is detected by reading
dropped until clk_scb is enabled see “Deep Sleep to back the written memory buffer location, and con-
Active Transition” on page 331 for more details firming that the read value is the same as the written
❐ EZ mode: Supported. In Deep Sleep power mode, value.
the slave (MISO) transmits a busy (0xFF) byte during
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 332
Serial Communications Block (SCB)
For both options, a conflicting internal logic access to the memory buffer sets INTR_TX.BLOCKED field to ‘1’ (for write
accesses) and INTR_RX.BLOCKED field to ‘1’ (for read accesses). These fields can be used as either status fields or as
interrupt cause fields (when their associated mask fields are enabled).
If a series of read or write accesses is performed and CTRL.BLOCKED is ‘0’, a failure is detected by comparing the “logical-
or” of all read values to 0xFFFF:FFFF and checking the INTR_TX.BLOCKED and INTR_RX.BLOCKED fields to determine
whether a failure occurred for a series of write or read operations.
1
--- t SCLK t SCLK_PCB_D + t DSO + t SCLK_PCB_D + t DSI
2 Equation 28-2
Where:
tSCLK is the period of the SPI clock
tDSO is the total internal slave delay, time from SCLK edge at slave pin to MISO edge at slave pin
Most slave datasheets will list tDSO, It may have a different name; look for MISO output valid after SCLK edge. Most master
datasheets will also list tDSI, or master setup time. tSCLK_PCB_D and tSCLK_PCB_D must be calculated based on specific
PCB geometries.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 333
Serial Communications Block (SCB)
If after doing these calculations the desired speed cannot be achieved, then consider using the MISO late sample feature of
the SCB. This can be done by setting the SPI_CTRL.LATE_MISO_SAMPLE register. Late sampling addresses the round-trip
delay associated with transmitting SCLK from the master to the slave and transmitting MISO from the slave to the master.
MISO late sample tells the SCB to sample the incoming MISO signal on the next edge of SCLK, thus allowing for ½ SCLK
cycle more timing margin, see Figure 28-11.
Figure 28-11. MISO Sampling Timing
spi_clk
spi_ mosi
MSb LSb
spi_ miso
MSb LSb
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 334
Serial Communications Block (SCB)
Motorola mode to TI mode) or to go from externally clocked to internally clocked operation. The change takes effect only
after the block is re-enabled. Note: Re-enabling the block causes re-initialization and the associated state is lost (for
example, FIFO content).
spi_clk_out spi_clk_out
spi_clk
spi_clk_in spi_clk_in
Normal
output mode
spi_select_out spi_select_out
spi_select
spi_select_in spi_select_in
Normal
output mode
spi_mosi_out spi_mosi_out
spi_mosi
spi_mosi_in spi_mosi_in
Normal
output mode
0 spi_miso_out_en spi_ctl
spi_miso
spi_miso_in spi_miso_in
Input only
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 335
Serial Communications Block (SCB)
spi_clk
spi_clk_in spi_clk_in
Input only
0 spi_select_out_en spi_ctl
spi_select
spi_select_in spi_select_in
Input only
0 spi_mosi_out_en spi_ctl
spi_mosi
spi_mosi_in spi_mosi_in
Input only
i2c_ic_block_ec spi_ctl
spi_miso_out_en
spi_miso_out
spi_miso
spi_miso_in spi_miso_in
Normal output mode
Or
Open-drain mode
spi_ec_miso_out_en spi_ec_ctl
spi_ec_miso_out
Open_Drain is set in the TX_CTRL register. In this mode the SPI MISO pin is actively driven low, and then high-z for driving
high. This means an external pull-up is required for the line to go high. This mode is useful when there are multiple slaves on
the same line. This helps to avoid bus contention issues.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 336
Serial Communications Block (SCB)
SCB_CTRL Enables the SCB, selects the type of serial interface (SPI, UART, I2C), and selects internally and externally
clocked operation, and EZ and non-EZ modes of operation.
SCB_STATUS (Deep Sleep
In EZ mode, this register indicates whether the externally clocked logic is potentially using the EZ memory.
SCB only)
Configures the SPI as either a master or a slave, selects SPI protocols (Motorola, TI, National) and clock-
SCB_SPI_CTRL
based submodes in Motorola SPI (modes 0,1,2,3), selects the type of SS signal in TI SPI.
SCB_SPI_STATUS Indicates whether the SPI bus is busy and sets the SPI slave EZ address in the internally clocked mode.
SCB_TX_CTRL Specifies the data frame width and specifies whether MSb or LSb is the first bit in transmission.
Performs the same function as that of the SCB_TX_CTRL register, but for the receiver. Also decides
SCB_RX_CTRL
whether a median filter is to be used on the input interface lines.
Specifies the trigger level, clears the transmitter FIFO and shift registers, and performs the FREEZE opera-
SCB_TX_FIFO_CTRL
tion of the transmitter FIFO.
SCB_RX_FIFO_CTRL Performs the same function as that of the SCB_TX_FIFO_CTRL register, but for the receiver.
SCB_TX_FIFO_WR Holds the data frame written into the transmitter FIFO. Behavior is similar to that of a PUSH operation.
Holds the data frame read from the receiver FIFO. Reading a data frame removes the data frame from the
SCB_RX_FIFO_RD FIFO - behavior is similar to that of a POP operation. This register has a side effect when read by software:
a data frame is removed from the FIFO.
Holds the data frame read from the receiver FIFO. Reading a data frame does not remove the data frame
SCB_RX_FIFO_RD_SILENT
from the FIFO; behavior is similar to that of a PEEK operation.
Indicates the number of bytes stored in the transmitter FIFO, the location from which a data frame is read by
SCB_TX_FIFO_STATUS the hardware (read pointer), the location from which a new data frame is written (write pointer), and decides
whether the transmitter FIFO holds the valid data.
SCB_RX_FIFO_STATUS Performs the same function as that of the SCB_TX_FIFO_STATUS register, but for the receiver.
SCB_EZ_DATA (Deep Sleep
Holds the data in EZ memory location
SCB only)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 337
Serial Communications Block (SCB)
Not all SCBs support UART mode; refer to the PSoC 61 Note: UART interface does not support external clocking
datasheet/PSoC 62 datasheet for details. operation. Hence, UART operates only in the Active and
Sleep system power modes. UART also supports only the
FIFO buffer mode.
28.4.1 Features
■ Supports UART protocol 28.4.3 UART Modes of Operation
❐ Standard UART
❐ Multi-processor mode 28.4.3.1 Standard Protocol
■ SmartCard (ISO7816) reader A typical UART transfer consists of a start bit followed by
■ IrDA multiple data bits, optionally followed by a parity bit and
■ Supports Local Interconnect Network (LIN) finally completed by one or more stop bits. The start bit
value is always ‘0’, the data bits values are dependent on
❐ Break detection the data transferred, the parity bit value is set to a value
❐ Baud rate detection guaranteeing an even or odd parity over the data bits, and
❐ Collision detection (ability to detect that a driven bit the stop bit value is ‘1’. The parity bit is generated by the
value is not reflected on the bus, indicating that transmitter and can be used by the receiver to detect single
another component is driving the same bus) bit transmission errors. When not transmitting data, the TX
line is ‘1’ – the same value as the stop bits.
■ Data frame size programmable from 4 to 16 bits
■ Programmable number of STOP bits, which can be set Because the interface does not have a clock, the transmitter
in terms of half bit periods between 1 and 4 and receiver must agree upon the baud rate. The transmitter
and receiver have their own internal clocks. The receiver
■ Parity support (odd and even parity)
clock runs at a higher frequency than the bit transfer
■ Median filter on RX input frequency, such that the receiver may oversample the
■ Programmable oversampling incoming signal.
■ Start skipping The transition of a stop bit to a start bit is represented by a
■ Hardware flow control change from ‘1’ to ‘0’ on the TX line. This transition can be
used by the receiver to synchronize with the transmitter
28.4.2 General Description clock. Synchronization at the start of each data transfer
allows error-free transmission even in the presence of
Figure 28-14 illustrates a standard UART TX and RX. frequency drift between transmitter and receiver clocks. The
required clock accuracy is dependent on the data transfer
Figure 28-14. UART Example
size.
Rx
Tx
The stop period or the amount of stop bits between
UART UART successive data transfers is typically agreed upon between
Rx transmitter and receiver, and is typically in the range of 1 to
Tx
3-bit transfer periods.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 338
Serial Communications Block (SCB)
Two successive data transfers (7data bits, 1 parity bit, 2 stop bits)
Tx / Rx
IDLE START DATA DATA DATA DATA DATA DATA DATA PAR STOP START DATA DATA DATA
LEGEND:
Tx / Rx : Transmit or Receive line
The receiver oversamples the incoming signal; the value of the sample point in the middle of the bit transfer period (on the
receiver’s clock) is used. Figure 28-16 illustrates this.
Figure 28-16. UART, Standard Protocol Example (Single Sample)
Tx clock
Tx / Rx
IDLE START DATA DATA DATA DATA DATA DATA DATA PAR STOP START DATA DATA DATA
Rx clock
LEGEND:
Tx / Rx : Transmit or Receive line
Alternatively, three samples around the middle of the bit transfer period (on the receiver’s clock) are used for a majority vote
to increase accuracy; this is enabled by enabling the MEDIAN filter in the SCB_RX_CTRL register. Figure 28-17 illustrates
this.
Figure 28-17. UART, Standard Protocol (Multiple Samples)
Tx clock
Tx / Rx
IDLE START DATA DATA DATA DATA DATA DATA DATA PAR STOP START DATA DATA DATA
Rx clock
LEGEND:
Tx / Rx : Transmit or Receive line
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 339
Serial Communications Block (SCB)
Parity
This functionality adds a parity bit to the data frame and is used to identify single-bit data frame errors. The parity bit is always
directly after the data frame bits.
The transmitter calculates the parity bit (when UART_TX_CTRL.PARITY_ENABLED is 1) from the data frame bits, such that
data frame bits and parity bit have an even (UART_TX_CTRL.PARITY is 0) or odd (UART_TX_CTRL.PARITY is 1) parity. The
receiver checks the parity bit (when UART_RX_CTRL.PARITY_ENABLED is 1) from the received data frame bits, such that
data frame bits and parity bit have an even (UART_RX_CTRL.PARITY is 0) or odd (UART_RX_CTRL.PARITY is 1) parity.
Parity applies to both TX and RX functionality and dedicated control fields are available.
■ Transmit functionality: UART_TX_CTRL.PARITY and UART_TX_CTRL.PARITY_ENABLED.
■ Receive functionality: UART_RX_CTRL.PARITY and UART_RX_CTRL.PARITY_ENABLED.
When a receiver detects a parity error, the data frame is either put in RX FIFO
(UART_RX_CTRL.DROP_ON_PARITY_ERROR is 0) or dropped (UART_RX_CTRL.DROP_ON_PARITY_ERROR is 1).
The following figures illustrate the parity functionality (8-bit data frame).
Figure 28-18. UART Parity Examples
parity enabled, even parity
P
uart_tx/uart_rx STOP START 1 0 1 0 1 0 1 0 0 STOP
st nd rd th th th th th th
1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 bit 8 bit 9 bit
parity enabled, even parity
P
uart_tx/uart_rx STOP START 1 1 1 0 1 0 1 0 1 STOP
Start Skipping
Start skipping applies only to receive functionality. The standard UART mode supports “start skipping”. Regular receive
operation synchronizes on the START bit period (a 1 to 0 transition on the UART RX line), start skipping receive operation
synchronizes on the first received data frame bit, which must be a ‘1’ (a 0 to 1 transition on UART RX).
Start skipping is used to allow for wake up from system Deep Sleep mode using UART. The process is described as follows:
1. Before entering Deep Sleep power mode, UART receive functionality is disabled and the GPIO is programmed to set an
interrupt cause to ‘1’ when UART RX line has a ‘1’ to ‘0’ transition (START bit).
2. While in Deep Sleep mode, the UART receive functionality is not functional.
3. The GPIO interrupt is activated on the START bit and the system transitions from Deep Sleep to Active power mode.
4. The CPU enables UART receive functionality, with UART_RX_CTRL.SKIP_START bitfield set to ‘1’.
5. The UART receiver synchronizes data frame receipt on the next ‘0’ to ‘1’ transition. If the UART receive functionality is
enabled in time, this is the transition from the START bit to the first received data frame bit.
6. The UART receiver proceeds with normal operation; that is, synchronization of successive data frames is on the START
bit period.
Figure 28-19 illustrates the process.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 340
Serial Communications Block (SCB)
Figure 28-19. UART Start Skip and Wakeup from Deep Sleep
uart_rx IDLE/STOP START D START
st
1 bit
Note that the above process works only for lower baud rates. The Deep Sleep to Active power mode transition and CPU
enabling the UART receive functionality should take less than 1-bit period to ensure that the UART receiver is active in time to
detect the ‘0’ to ‘1’ transition.
In step 4 of the above process, the firmware takes some time to finish the wakeup interrupt routine and enable the UART
receive functionality before the block can detect the input rising edge on the UART RX line.
If the above steps cannot be completed in less than 1 bit time, first send a “dummy” byte to the device to wake it up before
sending real UART data. In this case, the SKIP_START bit can be left as 0. For more information on how to perform this in
firmware, visit the UART section of the PDL.
Break Detection
Break detection is supported in the standard UART mode. This functionality detects when UART RX line is low (0) for more
than UART_RX_CTRL.BREAK_WIDTH bit periods. The break width should be larger than the maximum number of low (0) bit
periods in a regular data transfer, plus an additional 1-bit period. The additional 1-bit period is a minimum requirement and
preferably should be larger. The additional bit periods account for clock inaccuracies between transmitter and receiver.
For example, for an 8-bit data frame with parity support, the maximum number of low (0) bit periods is 10 (START bit, 8 ‘0’
data frame bits, and one ‘0’ parity bit). Therefore, the break width should be larger than 10 + 1 = 11
(UART_RX_CTRL.BREAK_WIDTH can be set to 11).
Note that the break detection applies only to receive functionality. A UART transmitter can generate a break by temporarily
increasing TX_CTRL.DATA_WIDTH and transmitting an all zeroes data frame. A break is used by the transmitter to signal a
special condition to the receiver. This condition may result in a reset, shut down, or initialization sequence at the receiver.
Break detection is part of the LIN protocol. When a break is detected, the INTR_RX.BREAK_DETECT interrupt cause is set
to ‘1’. Figure 28-20 illustrates a regular data frame and break frame (8-bit data frame, parity support, and a break width of 12-
bit periods).
Figure 28-20. UART – Regular Frame and Break Frame
Regular frame
st nd rd th th th th th th
1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 bit 8 bit 9 bit
Break frame (12 low/0-bit periods)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 341
Serial Communications Block (SCB)
Flow Control
The standard UART mode supports flow control. Modem flow control controls the pace at which the transmitter transfers data
to the receiver. Modem flow control is enabled through the UART_FLOW_CTRL.CTS_ENABLED register field. When this
field is ‘0’, the transmitter transfers data when its TX FIFO is not empty. When ‘1’, the transmitter transfers data when UART
CTS line is active and its TX FIFO is not empty.
Note that the flow control applies only to TX functionality. Two UART side-band signal are used to implement flow control:
■ UART RTS (uart_rts_out): This is an output signal from the receiver. When active, it indicates that the receiver is ready to
receive data (RTS: Ready to Send).
■ UART CTS (uart_cts_in): This is an input signal to the transmitter. When active, it indicates that the transmitter can trans-
fer data (CTS: Clear to Send).
The receiver’s uart_rts_out signal is connected to the transmitter’s uart_cts_in signal. The receiver’s uart_rts_out signal is de-
rived by comparing the number of used receive FIFO entries with the UART_FLOW_CTRL.TRIGGER_LEVEL field. If the
number of used receive FIFO entries are less than UART_FLOW_CTRL.TRIGGER_LEVEL, uart_rts_out is activated.
Typically, the UART side-band signals are active low. However, sometimes active high signaling is used. Therefore, the
polarity of the side-band signals can be controlled using bitfields UART_FLOW_CTRL.RTS_POLARITY and
UART_FLOW_CTRL.CTS_POLARITY. Figure 28-21 gives an overview of the flow control functionality.
Figure 28-21. UART Flow Control Connection
Receiver (Rx) Transmitter (Tx)
uart_rx_ctl uart_tx_ctl
Rx FIFO Tx FIFO
uart_rx_in uart_tx_out
<
UART_FLOW_CTRL.TRIGGER_LEVEL[] uart_rts_out uart_cts_in
UART_FLOW_CTRL.RTS_POLARITY UART_FLOW_CTRL.CTS_ENABLED
UART_FLOW_CTRL.CTS_POLARITY
UART MP
Master
Tx Rx
Master Tx
Master Rx
Tx Rx Tx Rx Tx Rx
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 342
Serial Communications Block (SCB)
DATA Field
IDLE START DATA DATA DATA DATA DATA DATA DATA DATA MP STOP
The SCB can be used as either master or slave device in UART_MP mode. Both SCB_TX_CTRL and SCB_RX_CTRL
registers should be set to 9-bit data frame size. When the SCB works as UART_MP master device, the firmware changes the
MP flag for every address or data frame. When it works as UART_MP slave device, the MP_MODE field of the
SCB_UART_RX_CTRL register should be set to ‘1’. The SCB_RX_MATCH register should be set for the slave address and
address mask. The matched address is written in the RX_FIFO when ADDR_ACCEPT field of the SCB_CTRL register is set
to ‘1’. If the received address does not match its own address, then the interface ignores the following data, until next address
is received for compare.
Tx Rx Tx Rx Tx Rx
LIN BUS
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 343
Serial Communications Block (SCB)
Master Task
LIN bus
In LIN protocol communication, the least significant bit (LSb) of the data is sent first and the most significant bit (MSb) last.
The start bit is encoded as zero and the stop bit is encoded as one. The following sections describe all the byte fields in the
LIN frame.
Break Field
Every new frame starts with a break field, which is always generated by the master. The break field has logical zero with a
minimum of 13 bit times and followed by a break delimiter. The break field structure is as shown in Figure 28-27.
Figure 28-27. LIN Break Field
Sync Field
This is the second field transmitted by the master in the header field; its value is 0x55. A sync field can be used to synchronize
the clock of the slave task with that of the master task for automatic baud rate detection. Figure 28-28 shows the LIN sync
field structure.
Figure 28-28. LIN Sync Field
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 344
Serial Communications Block (SCB)
Protected Identifier (PID) Field more unconditional frames. The unconditional frames
associated with an event triggered frame should:
A protected identifier field consists of two sub-fields: the
frame identifier (bits 0-5) and the parity (bit 6 and bit 7). The ■ Have equal length
PID field structure is shown in Figure 28-29. ■ Use the same checksum model (either classic or
■ Frame identifier: The frame identifiers are divided into enhanced)
three categories ■ Reserve the first data field to its protected identifier
❐ Values 0 to 59 (0x3B) are used for signal carrying ■ Be published by different slave nodes
frames ■ Not be included directly in the same schedule table as
❐ 60 (0x3C) and 61 (0x3D) are used to carry diagnostic the event-triggered frame
and configuration data
❐ 62 (0x3E) and 63 (0x3F) are reserved for future pro- Sporadic Frame. The purpose of the sporadic frames is to
tocol enhancements merge some dynamic behavior into the schedule table
without affecting the rest of the schedule table. These
■ Parity: Frame identifier bits are used to calculate the
frames have a group of unconditional frames that share the
parity
frame slot. When the sporadic frame is due for transmission,
Figure 28-29 shows the PID field structure. the unconditional frames are checked whether they have
any updated signals. If no signals are updated, no frame will
Figure 28-29. PID Field be transmitted and the frame slot will be empty.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 345
Serial Communications Block (SCB)
Typically, LIN line drivers will drive the LIN line with the value may be sent from the receiver to the transmitter. A NACK is
provided on the SCB TX line and present the value on the always ‘0’. Both master and slave may drive the same line,
LIN line to the SCB RX line. By comparing TX and RX lines although never at the same time.
in the SCB, bus collisions can be detected (indicated by the
A SmartCard transfer has the transmitter drive the start bit
SCB_UART_ARB_LOST field of the SCB_INTR_TX
and data bits (and optionally a parity bit). After these bits, it
register).
enters its stop period by releasing the bus. Releasing results
in the line being ‘1’ (the value of a stop bit). After one bit
28.4.3.3 SmartCard (ISO7816)
transfer period into the stop period, the receiver may drive a
ISO7816 is asynchronous serial interface, defined with NACK on the line (a value of ‘0’) for one bit transfer period.
single-master-single slave topology. ISO7816 defines both This NACK is observed by the transmitter, which reacts by
Reader (master) and Card (slave) functionality. For more extending its stop period by one bit transfer period. For this
information, refer to the ISO7816 Specification. Only the protocol to work, the stop period should be longer than one
master (reader) function is supported by the SCB. This bit transfer period. Note that a data transfer with a NACK
block provides the basic physical layer support with takes one bit transfer period longer, than a data transfer
asynchronous character transmission. The UART_TX line is without a NACK. Typically, implementations use a tristate
connected to SmartCard I/O line by internally multiplexing driver with a pull-up resistor, such that when the line is not
between UART_TX and UART_RX control modules. transmitting data or transmitting the Stop bit, its value is ‘1’.
The SmartCard transfer is similar to a UART transfer, with Figure 28-30 illustrates the SmartCard protocol.
the addition of a negative acknowledgement (NACK) that
Figure 28-30. SmartCard Example
Two successive data transfers (7 data bits, 1 parity bit, 2 stop bits) without NACK
Tx / Rx
IDLE START DATA DATA DATA DATA DATA DATA DATA PAR STOP START DATA DATA DATA
Two successive data transfers (7data bits, 1 parity bit, 2 stop bits) with NACK
Tx / Rx
IDLE START DATA DATA DATA DATA DATA DATA DATA PAR STOP NACK STOP START DATA DATA
LEGEND:
Tx / Rx : Transmit or Receive line
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 346
Serial Communications Block (SCB)
Two successive data transfers (7 data bits, 1 parity bit, 2 stop bits)
Tx / Rx
IrDA
Tx / Rx
LEGEND:
Tx / Rx : Transmit or Receive line
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 347
Serial Communications Block (SCB)
28.4.4 Clocking and Oversampling 28.4.5 Enabling and Initializing the UART
The UART protocol is implemented using clk_scb as an The UART must be programmed in the following order:
oversampled multiple of the baud rate. For example, to 1. Program protocol specific information using the
implement a 100-kHz UART, clk_scb could be set to 1 MHz UART_TX_CTRL, UART_RX_CTRL, and
and the oversample factor set to ‘10’. The oversampling is UART_FLOW_CTRL registers. This includes selecting
set using the SCB_CTRL.OVS register field. The the submodes of the protocol, transmitter-receiver
oversampling value is SCB_CTRL.OVS + 1. In the UART functionality, and so on.
standard sub-mode (including LIN) and the SmartCard sub-
2. Program the generic transmitter and receiver information
mode, the valid range for the OVS field is [7, 15].
using the SCB_TX_CTRL and SCB_RX_CTRL
In UART transmit IrDA sub-mode, this field indirectly registers.
specifies the oversampling. Oversampling determines the a. Specify the data frame width.
interface clock per bit cycle and the width of the pulse. This
b. Specify whether MSb or LSb is the first bit to be
sub-mode has only one valid OVS value–16 (which is a
transmitted or received.
value of 0 in the OVS field of the SCB_CTRL register); the
pulse width is roughly 3/16 of the bit period (for all bit rates). 3. Program the transmitter and receiver FIFOs using the
SCB_TX_FIFO_CTRL and SCB_RX_FIFO_CTRL
In UART receive IrDA sub-mode (1.2, 2.4, 9.6, 19.2, 38.4, registers, respectively.
57.6, and 115.2 kbps), this field indirectly specifies the
a. Set the trigger level.
oversampling. In normal transmission mode, this pulse is
approximately 3/16 of the bit period (for all bit rates). In low- b. Clear the transmitter and receiver FIFO and Shift
power transmission mode, this pulse is potentially smaller registers.
(down to 1.62 µs typical and 1.41 µs minimal) than 3/16 of 4. Enable the block (write a ‘1’ to the ENABLE bit of the
the bit period (for less than 115.2 kbps bit rates). SCB_CTRL register). After the block is enabled, control
bits should not be changed. Changes should be made
Pulse widths greater than or equal to two SCB input clock
after disabling the block; for example, to modify the
cycles are guaranteed to be detected by the receiver. Pulse
operation mode (from SmartCard to IrDA). The change
widths less than two clock cycles and greater than or equal
takes effect only after the block is re-enabled. Note that
to one SCB input clock cycle may be detected by the
re-enabling the block causes re-initialization and the
receiver. Pulse widths less than one SCB input clock cycle
associated state is lost (for example FIFO content).
will not be detected by the receiver. Note that the
SCB_RX_CTRL.MEDIAN should be set to ‘1’ for IrDA
receiver functionality.
The SCB input clock and the oversampling together
determine the IrDA bit rate. Refer to the registers TRM for
more details on the OVS values for different baud rates.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 348
Serial Communications Block (SCB)
1 uart_tx_out_en uart_tx_ctl
uart_tx_out uart_tx_out
uart_tx
uart_tx_in uart_tx_in
Normal
output mode
0 uart_rx_out_en uart_rx_ctl
uart_rx
uart_rx_in uart_rx_in
Input only
uart_tx
uart_tx_in uart_tx_in
uart_rx_out_en uart_rx_ctl
uart_rx_out
uart_rx_in
On-chip I/O
I/O Pads Drive Mode Usage
Signals
Used to receive a data element.
uart_tx_in
Open drain with Receive a negative acknowledgement of a transmitted data element
uart_tx
pull-up uart_tx_out_en Transmit a data element.
uart_tx_out Transmit a negative acknowledgement to a received data element.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 349
Serial Communications Block (SCB)
1 uart_tx_out_en uart_tx_ctl
LIN uart_tx
uart_tx_in uart_tx_in
transceiver
chip
0 uart_rx_out_en uart_rx_ctl
LIN
uart_rx
uart_rx_in uart_rx_in
On-chip I/O
I/O Pads Drive Mode Usage
Signals
Normal output uart_tx_out_en
uart_tx Transmit a data element.
mode uart_tx_out
uart_rx Input only uart_rx_in Receive a data element.
1 uart_tx_out_en uart_tx_ctl
Normal
uart_tx_out uart_tx_out
output mode
IrDA uart_tx
uart_tx_in uart_tx_in
transducer
module
0 uart_rx_out_en uart_rx_ctl
IrDA
don t care uart_rx_out
Input only
uart_rx
uart_rx_in uart_rx_in
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 350
Serial Communications Block (SCB)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 351
Serial Communications Block (SCB)
28.5.1 Features
This block supports the following features:
■ Master, slave, and master/slave mode
■ Standard-mode (100 kbps), fast-mode (400 kbps), and fast-mode plus (1000 kbps) data-rates
■ 7-bit slave addressing
■ Clock stretching
■ Collision detection
■ Programmable oversampling of I2C clock signal (SCL)
■ Auto ACK when RX FIFO not full, including address
■ General address detection
■ FIFO Mode
■ EZ and CMD_RESP modes
VDD
Rp Rp
SCL
SDA
I2C
Master I2C Slave I2C Slave I2C Slave
The standard I2C bus is a two wire interface with the following lines:
■ Serial Data (SDA)
■ Serial Clock (SCL)
I2C devices are connected to these lines using open collector or open-drain output stages, with pull-up resistors (Rp). A
simple master/slave relationship exists between devices. Masters and slaves can operate as either transmitter or receiver.
Each slave device connected to the bus is software addressable by a unique 7-bit address.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 352
Serial Communications Block (SCB)
pull-up
Rp Rp
resistors
Device 1 Device 2
For most designs, the default values shown inTable 28-12 provide excellent performance without any calculations. The
default values were chosen to use standard resistor values between the minimum and maximum limits.
These values work for designs with 1.8 V to 5.0 V VDD, less than 200 pF bus capacitance (CB), up to 25 µA of total input
leakage (IIL), up to 0.4 V output voltage level (VOL), and a max VIH of 0.7 * VDD. Calculation of custom pull-up resistor values
is required if your design does not meet the default assumptions, you use series resistors (RS) to limit injected noise, or you
want to maximize the resistor value for low power consumption. Calculation of the ideal pull-up resistor value involves finding
a value between the limits set by three equations detailed in the NXP I2C specification. These equations are:
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 353
Serial Communications Block (SCB)
The supply voltage (VDD) limits the minimum pull-up resistor 28.5.4.1 Clock Stretching
value due to bus devices maximum low output voltage (VOL)
specifications. Lower pull-up resistance increases current When a slave device is not yet ready to process data, it may
through the pins and can therefore exceed the spec drive a ‘0’ on the SCL line to hold it down. Due to the
conditions of VOH. Equation 26-4 is derived using Ohm's law implementation of the I/O signal interface, the SCL line
to determine the minimum resistance that will still meet the value will be ‘0’, independent of the values that any other
VOL specification at 3 mA for standard and fast modes, and master or slave may be driving on the SCL line. This is
20 mA for fast mode plus at the given VDD. known as clock stretching and is the only situation in which
a slave drives the SCL line. The master device monitors the
Equation 26-5 determines the maximum pull-up resistance SCL line and detects it when it cannot generate a positive
due to bus capacitance. Total bus capacitance is comprised clock pulse (‘1’) on the SCL line. It then reacts by delaying
of all pin, wire, and trace capacitance on the bus. The higher the generation of a positive edge on the SCL line, effectively
the bus capacitance the lower the pull-up resistance synchronizing with the slave device that is stretching the
required to meet the specified bus speeds rise time due to clock. The SCB on the PSoC 6 MCU can and will stretch the
RC delays. Choosing a pull-up resistance higher than clock.
allowed can result in failing timing requirements resulting in
communication errors. Most designs with five of fewer I2C 28.5.4.2 Bus Arbitration
devices and up to 20 centimeters of bus trace length have
less than 100 pF of bus capacitance. The I2C protocol is a multi-master, multi-slave interface. Bus
arbitration is implemented on master devices by monitoring
A secondary effect that limits the maximum pull-up resistor the SDA line. Bus collisions are detected when the master
value is total bus leakage calculated in Equation 26-6. The observes an SDA line value that is not the same as the
primary source of leakage is I/O pins connected to the bus. value it is driving on the SDA line. For example, when
If leakage is too high, the pull-ups will have difficulty master 1 is driving the value ‘1’ on the SDA line and master
maintaining an acceptable VIH level causing communication 2 is driving the value ‘0’ on the SDA line, the actual line
errors. Most designs with five or fewer I2C devices on the value will be ‘0’ due to the implementation of the I/O signal
bus have less than 10 µA of total leakage current. interface. Master 1 detects the inconsistency and loses
control of the bus. Master 2 does not detect any
28.5.4 Terms and Definitions inconsistency and keeps control of the bus.
Table 28-13 explains the commonly used terms in an I2C
communication network. 28.5.5 I2C Modes of Operation
I2C is a synchronous single master, multi-master, multi-slave
Table 28-13. Definition of I2C Bus Terminology
serial interface. Devices operate in either master mode,
Term Description slave mode, or master/slave mode. In master/slave mode,
Transmitter The device that sends data to the bus the device switches from master to slave mode when it is
Receiver The device that receives data from the bus addressed. Only a single master may be active during a
data transfer. The active master is responsible for driving the
The device that initiates a transfer, generates
Master
clock signals, and terminates a transfer clock on the SCL line. Table 28-14 illustrates the I2C modes
of operation.
Slave The device addressed by a master
Multi-master
More than one master can attempt to control Table 28-14. I2C Modes
the bus at the same time
Mode Description
Procedure to ensure that, if more than one
master simultaneously tries to control the bus, Slave Slave only operation (default)
Arbitration
only one is allowed to do so and the winning Master Master only operation
message is not corrupted Multi-master Supports more than one master on the bus
Procedure to synchronize the clock signals of
Synchronization
two or more devices
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 354
Serial Communications Block (SCB)
Table 28-15 lists some common bus events that are part of 28.5.5.1 Write Transfer
an I2C data transfer. The Write Transfer and Read Transfer
sections explain the I2C bus bit format during data transfer. ■ A typical write transfer begins with the master generating
a START condition on the I2C bus. The master then
Table 28-15. I2C Bus Events Terminology
writes a 7-bit I2C slave address and a write indicator (‘0’)
Bus Event Description after the START condition. The addressed slave
A HIGH to LOW transition on the SDA line while transmits an acknowledgment byte by pulling the data
START
SCL is HIGH line low during the ninth bit time.
A LOW to HIGH transition on the SDA line while ■ If the slave address does not match any of the slave
STOP
SCL is HIGH devices or if the addressed device does not want to
The receiver pulls the SDA line LOW and it acknowledge the request, it transmits a no
remains LOW during the HIGH period of the clock acknowledgment (NACK) by not pulling the SDA line
ACK pulse, after the transmitter transmits each byte. low. The absence of an acknowledgement, results in an
This indicates to the transmitter that the receiver SDA line value of ‘1’ due to the pull-up resistor
received the byte properly.
implementation.
The receiver does not pull the SDA line LOW and
■ If no acknowledgment is transmitted by the slave, the
it remains HIGH during the HIGH period of clock
NACK pulse after the transmitter transmits each byte. master may end the write transfer with a STOP event.
This indicates to the transmitter that the receiver The master can also generate a repeated START
did not receive the byte properly. condition for a retry attempt.
Repeated START condition generated by master at the end ■ The master may transmit data to the bus if it receives an
START of a transfer instead of a STOP condition acknowledgment. The addressed slave transmits an
SDA status change while SCL is LOW (data acknowledgment to confirm the receipt of every byte of
DATA changing), and no change while SCL is HIGH data written. Upon receipt of this acknowledgment, the
(data valid) master may transmit another data byte.
■ When the transfer is complete, the master generates a
With all of these modes, there are two types of transfer - STOP condition.
read and write. In write transfer, the master sends data to
slave; in read transfer, the master receives data from slave.
Figure 28-38. Master Write Data Transfer
SCL
START S lave a ddre ss (7 bits) W rite ACK D ata (8 b its) ACK STO P
LE G E N D :
SDA: S e ria l D a ta L in e
SCL: S e ria l C lo c k Lin e (a lw a y s d riv e n by the m a s te r)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 355
Serial Communications Block (SCB)
SCL
START Slave address (7 bits) Read ACK Data (8 bits) NACK STOP
LEGEND :
SDA: Serial Data Line
SCL: Serial Clock Line (always driven by the master)
■ A typical read transfer begins with the master generating 28.5.6.1 FIFO Mode
a START condition on the I2C bus. The master then
writes a 7-bit I2C slave address and a read indicator (‘1’) The FIFO mode has a TX FIFO for the data being
after the START condition. The addressed slave transmitted and an RX FIFO for the data being received.
transmits an acknowledgment by pulling the data line Each FIFO is constructed out of the SRAM buffer. The
low during the ninth bit time. FIFOs are either 64 elements deep with 16-bit data
elements or 128 elements deep with 8-bit data elements.
■ If the slave address does not match with that of the
The width of the data elements are configured using the
connected slave device or if the addressed device does
CTRL.BYTE_MODE bitfield of the SCB. For I2C, put the
not want to acknowledge the request, a no
FIFO in BYTE mode because all transactions are a byte
acknowledgment (NACK) is transmitted by not pulling
wide.
the SDA line low. The absence of an acknowledgment,
results in an SDA line value of ‘1’ due to the pull-up The FIFO mode operation is available only in Active and
resistor implementation. Sleep power modes, not in the Deep Sleep power mode.
■ If no acknowledgment is transmitted by the slave, the However, on the Deep Sleep-capable SCB the slave
master may end the read transfer with a STOP event. address can be used to wake the device from sleep.
The master can also generate a repeated START A write access to the transmit FIFO uses register
condition for a retry attempt. TX_FIFO_WR. A read access from the receive FIFO uses
■ If the slave acknowledges the address, it starts register RX_FIFO_RD.
transmitting data after the acknowledgment signal. The
Transmit and receive FIFO status information is available
master transmits an acknowledgment to confirm the
through status registers TX_FIFO_STATUS and
receipt of each data byte sent by the slave. Upon receipt
RX_FIFO_STATUS. When in debug mode, a read from this
of this acknowledgment, the addressed slave may
register behaves as a read from the
transmit another data byte.
SCB_RX_FIFO_RD_SILENT register; that is, data will not
■ The master can send a NACK signal to the slave to stop be removed from the FIFO.
the slave from sending data bytes. This completes the
read transfer. Each FIFO has a trigger output. This trigger output can be
routed through the trigger mux to various other peripheral on
■ When the transfer is complete, the master generates a
the device such as DMA or TCPWMs. The trigger output of
STOP condition.
the SCB is controlled through the TRIGGER_LEVEL field in
■ When the slave transmits a NACK, even if a new byte is the RX_CTRL and TX_CTRL registers.
written into the TX FIFO it will wait for the NACK to
■ For a TX FIFO a trigger is generated when the number
complete.
of entries in the transmit FIFO is less than
TX_FIFO_CTRL.TRIGGER_LEVEL.
28.5.6 I2C Buffer Modes ■ For the RX FIFO a trigger is generated when the number
I2C can operate in three different buffered modes – FIFO, of entries in the FIFO is greater than the
EZ, and CMD_RESP modes. The buffer is used in different RX_FIFO_CTRL.TRIGGER_LEVEL.
ways in each of the modes. The following subsections Note that the DMA has a trigger deactivation setting. For the
explain each of these buffered modes in detail. SCB this should be set to 16.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 356
Serial Communications Block (SCB)
Before going to deep sleep ensure that all active address is used to address these 256 locations. The CPU
communication is complete. This can be done by checking writes and reads to the memory buffer through the
the BUS_BUSY bit in the I2C_Status register. EZ_DATA registers. These accesses are word accesses,
but only the least significant byte of the word is used.
Ensure that the TX and RX FIFOs are empty as any data will
be lost during deep sleep. The slave interface accesses the memory buffer using the
current address. At the start of a transfer (I2C START/
Before going to deep sleep the clock to the SCB needs to be
RESTART), the base address is copied to the current
disabled. This can be done by setting the
address. A data element write or read operation is to the
SDA_IN_FILT_TRIM[1] bit in the I2C_CFG register to ‘0’.
current address location. After the access, the current
address is incremented by ‘1’.
Deep Sleep to Active Transition
If the current address equals the last memory buffer address
EC_AM = 1, EC_OP = 0, FIFO Mode.
(255), the current address is not incremented. Subsequent
The following descriptions only apply to slave mode. write accesses will overwrite any previously written value at
the last buffer address. Subsequent read accesses will
Master Write: continue to provide the (same) read value at the last buffer
■ I2C_CTRL.S_NOT_READY_ADDR_NACK = 0, address. The bus master should be aware of the memory
I2C_CTRL.S_READY_ADDR_ACK = 1. The clock is buffer capacity in EZ mode.
stretched until SDA_IN_FILT_TRIM[1] is set to ‘1’. After
that bit is set to 1, the clock stretch will be released The I2C base and current addresses are provided through
I2C_STATUS. At the end of a transfer, the difference
■ I2C_CTRL.S_NOT_READY_ADDR_NACK = 0, between the base and current addresses indicates how
I2C_CTRL.S_READY_ADDR_ACK = 0. The clock is many read or write accesses were performed. The block
stretched until SDA_IN_FILT_TRIM[1] is set to ‘1’, and provides interrupt cause fields to identify the end of a
S_ACK or S_NACK is set in the I2C_S_CMD register. transfer. EZI2C can be implemented through firmware or
■ I2C_CTRL.S_NOT_READY_ADDR_NACK = 1, hardware. All SCBs can implement EZI2C through a
I2C_CTRL.S_READY_ADDR_ACK = x. The incoming firmware implementation in both Active and Sleep power
address is NACK’d until SDA_IN_FILT_TRIM[1] is set to modes. The Deep Sleep SCB can implement a hardware-
‘1’. After that bit is set to 1, the slave will respond with an and firmware-based EZI2C with a Deep Sleep power mode.
ACK to a master address. This document focuses on hardware-implemented EZI2C;
for more information on software implementation, see the
Master Read:
PDL.
■ I2C_CTRL.S_NOT_READY_ADDR_NACK = 0,
I2C_CTRL.S_READY_ADDR_ACK = x. The incoming EZI2C distinguishes three operation phases:
address is stretched until SDA_IN_FILT_TRIM[1] is set ■ Address phase: The master transmits an 8-bit address
to ‘1’. After that bit is set to 1, the clock stretch will be to the slave. This address is used as the slave base and
released. current address.
■ I2C_CTRL.S_NOT_READY_ADDR_NACK = 1, ■ Write phase: The master writes 8-bit data element(s) to
I2C_CTRL.S_READY_ADDR_ACK = x. The incoming the slave’s memory buffer. The slave’s current address
address is NACK’d until SDA_IN_FILT_TRIM[1] is set to is set to the slave’s base address. Received data
‘1’. After that bit is set to 1, the slave will ACK. elements are written to the current address memory
Note: When doing a repeated start after a write, wait location. After each memory write, the current address is
until the UNDERFLOW interrupt status is asserted incremented.
before setting the I2C_M_CMD.START bit and writing ■ Read phase: The master reads 8-bit data elements from
the new address into the TX_FIFO. Otherwise, the the slave’s memory buffer. The slave’s current address
address in the FIFO will be sent as data and not as an is set to the slave’s base address. Transmitted data
address. elements are read from the current address memory
location. After each memory read, the current address is
28.5.6.2 EZI2C Mode incremented.
The Easy I2C (EZI2C) protocol is a unique communication Note that a slave’s base address is updated by the master
scheme built on top of the I2C protocol by Cypress. It uses a and not by the CPU.
meta protocol around the standard I2C protocol to
communicate to an I2C slave using indexed memory
transfers. This removes the need for CPU intervention.
The EZI2C protocol defines a single memory buffer with an
8-bit address that indexes the buffer (256-entry array of 8-bit
per entry is supported) located on the slave device. The EZ
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 357
Serial Communications Block (SCB)
SCL
START Slave address (7 bits) Write ACK EZ address (8 bits) ACK Write Data (8 bits) ACK STOP
EZ address
Data
EZ Buffer
(32 bytes SRAM)
Address
SCL
START Slave address (7 bits) Read ACK Read Data (8 bits) NACK STOP
LEGEND :
SDA: Serial Data Line
SCL: Serial Clock Line (always driven by the master)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 358
Serial Communications Block (SCB)
28.5.6.3 Command-Response Mode the last buffer address. The bus master should be aware of
the memory buffer capacity in command-response mode.
This mode has a single memory buffer, a base read
address, a current read address, a base write address, and The base addresses are provided through
a current write address that are used to index the memory CMD_RESP_CTRL. The current addresses can be viewed
buffer. The base addresses are provided by the CPU. The in CMD_RESP_STATUS. At the end of a transfer (I2C stop),
current addresses are used by the slave to index the the difference between a base and current address
memory buffer for sequential accesses of the memory indicates how many read/write accesses were performed.
buffer. The memory buffer holds 256 8-bit data elements. This block provides interrupts to identify the end of a
The base and current addresses are in the range [0 to 255]. transfer, which can be found in SCB8_INTR_I2C_EC and
SCB8_INTR_SPI_EC register sections. Command-
The CPU writes and reads to the memory buffer through the response mode operation is available in Active, Sleep, and
SCB_EZ_DATA registers. These are word accesses, but Deep Sleep power modes. The command-response mode
only the least significant byte of the word is used. has two phases of operation:
The slave interface accesses the memory buffer using the ■ Write phase - The write phase begins with a START/
current addresses. At the start of a write transfer (I2C RESTART followed by the slave address with read/write
START/RESTART), the base write address is copied to the bit set to ‘0’ indicating a write. The slave’s current write
current write address. A data element write is to the current address is set to the slave’s base write address.
write address location. After the write access, the current Received data elements are written to the current write
address is incremented by ‘1’. At the start of a read transfer, address memory location. After each memory write, the
the base read address is copied to the current read address. current write address is incremented.
A data element read is to the current read address location. ■ Read phase - The read phase begins with a START/
After the read data element is transmitted, the current read RESTART followed by the slave address with read/write
address is incremented by ‘1’. bit set to ‘1’ indicating a read. The slave’s current read
If the current addresses equal the last memory buffer address is set to the slave’s base read address.
address (255), the current addresses are not incremented. Transmitted data elements are read from the current
Subsequent write accesses will overwrite any previously address memory location. After each read data element
written value at the last buffer address. Subsequent read is transferred, the current read address is incremented.
accesses will continue to provide the (same) read value at
LEGEND:
S: Start base_wr_addr curr_wr_addr
RS: Repeated start SRAM
P: Stop Memory of
A: ACK written by CPU 256 x 8-bits
N: NACK +1
written by CPU
base_rd_addr +1 curr_rd_addr
read data (8 bits)
read phase
Note: A slave’s base addresses are updated by the CPU and not by the master.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 359
Serial Communications Block (SCB)
28.5.7 Clocking and Oversampling Deep Sleep functionality interrupt brings the system into
Active power mode. When the slave is deselected,
The SCB I2C supports both internally and externally clocked INTR_I2C_EC.EZ_STOP and/or
operation modes. Two bitfields (EC_AM_MODE and INTR_I2C_EC.EZ_WRITE_STOP are set to ‘1’.
EC_OP MODE) in the SCB_CTRL register determine the
❐ FIFO mode: Not supported.
SCB clock mode. EC_AM_MODE indicates whether I2C
address matching is internally (0) or externally (1) clocked. ❐ EZ mode: Supported.
I2C address matching comprises the first part of the I2C ❐ CMD_RESP mode: Supported.
protocol. EC_OP_MODE indicates whether the rest of the
An externally-clocked operation uses a clock provided by
protocol operation (besides I2C address matching) is
the serial interface. The externally clocked mode does not
internally (0) or externally (1) clocked. The externally
support FIFO mode. If EC_OP_MODE is ‘1’, the external
clocked mode of operation is supported only in the I2C slave
interface logic accesses the memory buffer on the external
mode.
interface clock (I2C SCL). This allows for EZ and
An internally-clocked operation uses the programmable CMD_RESP mode functionality in Active and Deep Sleep
clock dividers. For I2C, an integer clock divider must be power modes.
used for both master and slave. For more information on
In Active system power mode, the memory buffer requires
system clocking, see the Clocking System chapter on
arbitration between external interface logic (on I2C SCL) and
page 242. The internally-clocked mode does not support the
the CPU interface logic (on system peripheral clock). This
command-response mode.
arbitration always gives the highest priority to the external
The SCB_CTRL bitfields EC_AM_MODE and interface logic (host accesses). The external interface logic
EC_OP_MODE can be configured in the following ways. takes one serial interface clock/bit periods for the I2C.
■ EC_AM_MODE is ‘0’ and EC_OP_MODE is ‘0’: Use this During this period, the internal logic is denied service to the
configuration when only Active mode functionality is memory buffer. The PSoC 6 MCU provides two
required. programmable options to address this “denial of service”:
❐ FIFO mode: Supported. ■ If the BLOCK bitfield of SCB_CTRL is ‘1’: An internal
logic access to the memory buffer is blocked until the
❐ EZ mode: Supported.
memory buffer is granted and the external interface logic
❐ Command-response mode: Not supported. The has completed access. For a 100-kHz I2C interface, the
slave NACKs every slave address. maximum blocking period of one serial interface bit
■ EC_AM_MODE is ‘1’ and EC_OP_MODE is ‘0’: Use this period measures 10 µs (approximately 208 clock cycles
configuration when both Active and Deep Sleep on a 48 MHz SCB input clock). This option provides
functionality are required. This configuration relies on the normal SCB register functionality, but the blocking time
externally clocked functionality for the I2C address introduces additional internal bus wait states.
matching and relies on the internally clocked ■ If the BLOCK bitfield of SCB_CTRL is ‘0’: An internal
functionality to access the memory buffer. The “hand logic access to the memory buffer is not blocked, but
over” from external to internal functionality relies either fails when it conflicts with an external interface logic
on an ACK/NACK or clock stretching scheme. The access. A read access returns the value 0xFFFF:FFFF
former may result in termination of the current transfer and a write access is ignored. This option does not
and relies on a master retry. The latter stretches the introduce additional internal bus wait states, but an
current transfer after a matching address is received. access to the memory buffer may not take effect. In this
This mode requires the master to support either NACK case, following failures are detected:
generation (and retry) or clock stretching. When the I2C
❐ Read Failure: A read failure is easily detected, as the
address is matched, INTR_I2C_EC.WAKE_UP is set to
returned value is 0xFFFF:FFFF. This value is unique
‘1’. The associated Deep Sleep functionality interrupt
as non-failing memory buffer read accesses return
brings the system into Active power mode.
an unsigned byte value in the range 0x0000:0000-
❐ FIFO mode: See “Deep Sleep to Active Transition” 0x0000:00FF.
on page 357
❐ Write Failure: A write failure is detected by reading
❐ EZ mode: See “Deep Sleep to Active Transition” on back the written memory buffer location, and con-
page 358. firming that the read value is the same as the written
❐ CMD_RESP mode: Not supported. The slave value.
NACKs every slave address.
For both options, a conflicting internal logic access to the
■ EC_AM_MODE is ‘1’ and EC_OP_MODE is ‘1’. Use this memory buffer sets INTR_TX.BLOCKED field to ‘1’ (for write
mode when both Active and Deep Sleep functionality are access-es) and INTR_RX.BLOCKED field to ‘1’ (for read
required. When the slave is selected, accesses). These fields can be used as either status fields
INTR_I2C_EC.WAKE_UP is set to ‘1’. The associated
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 360
Serial Communications Block (SCB)
or as interrupt cause fields (when their associated mask i2c_sda_in input signals (AF_in) to filter glitches of up to 50
fields are enabled). ns. An analog glitch filter is also applied on the i2c_sda_out
output signal (AF_out). Analog glitch filters are enabled and
If a series of read or write accesses is performed and
disabled in the SCB.I2C_CFG register. Do not change the
CTRL.BLOCKED is ‘0’, a failure is detected by comparing
_TRIM bitfields; only change the _SEL bitfields in this
the logical OR of all read values to 0xFFFF:FFFF and
register.
checking the INTR_TX.BLOCKED and
INTR_RX.BLOCKED fields to determine whether a failure Digital glitch filters are applied on the i2c_scl_in and
occurred for a (series of) write or read operation(s). i2c_sda_in input signals (DF_in). The digital glitch filter is
enabled in the SCB.RX_CTRL register via the MEDIAN
28.5.7.1 Glitch Filtering bitfield.
The PSoC 6 MCU SCB I2C has analog and digital glitch
filters. Analog glitch filters are applied on the i2c_scl_in and
i2c_scl DF_in
AF_in i2c_scl_in i2c_scl_in
i2c_sda_in DF_in
AF_out
i2c_ec_scl_out i2c_ec_ctl
i2c_ec_sda_out
i2c_sda
AF_in i2c_sda_in
i2c_scl_in
i2c_sda_in
When operating in EC_OP_MODE = 1, the 100-kHz, 400-kHz, and 1000-kHz modes require the following settings for AF_out:
Internally-clocked Master
The PSoC 6 MCU implements the I2C clock as an oversampled multiple of the SCB input clock. In master mode, the block
determines the I2C frequency. Routing delays on the PCB, on the chip, and the SCB (including analog and digital glitch filters)
all contribute to the signal interface timing. In master mode, the block operates off clk_scb and uses programmable
oversampling factors for the SCL high (1) and low (0) times. For high and low phase oversampling, see
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 361
Serial Communications Block (SCB)
Table 28-17. I2C Frequency and Oversampling Requirements in I2C Master Mode
Supported clk_scb
AF_in AF_out DF_in Mode LOW_PHASE_OVS HIGH_PHASE_OVS
Frequency Frequency
100 kHz [62, 100] kHz [9, 15] [9, 15] [1.98-3.2] MHz
0 0 1 400 kHz [264, 400] kHz [13, 5] [7, 15] [8.45-10] MHz
1000 kHz [447, 1000] kHz [8, 15] [5, 15] [14.32-25.8] MHz
100 kHz [48, 100] kHz [7, 15] [7, 15] [1.55-3.2] MHz
1 0 0 400 kHz [244, 400] kHz [12, 15] [7, 15] [7.82-10] MHz
1000 kHz Not supported
Table 28-17 assumes worst-case conditions on the I2C bus. The following equations can be used to determine the settings for
your own system. This will involve measuring the rise and fall times on SCL and SDA lines in your system.
tCLK_SCB(Min) = (tLOW + tF)/LOW_PHASE_OVS
If clk_scb is any faster than this, the tLOW of the I2C specification will be violated. tF needs to be measured in your system.
tCLK_SCB(Max) = (tVD – tRF – 100 ns)/3 (When analog filter is enabled and digital disabled)
tCLK_SCB(Max) = (tVD – tRF)/4 (When analog filter is disabled and analog filter is enabled)
tRF is the maximum of either the rise or fall time. If clk_scb is slower than this frequency, tVD will be violated.
SCL_out
SCL_bus
1 2 3
SCL_in
If the above three delays combined are greater than one clk_scb cycle, then the high phase of the SCL will be extended. This
may cause the actual data rate on the I2C bus to be slower than expected. This can be avoided by:
■ Decreasing the pull-up resistor, or decreasing the bus capacitance to reduce tR.
■ Reducing the I2C_CTRL.HIGH_PHASE_OVS value.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 362
Serial Communications Block (SCB)
Internally-clocked Slave
In slave mode, the I2C frequency is determined by the incoming I2C SCL signal. To ensure proper operation, clk_scb must be
significantly higher than the I2C bus frequency. Unlike master mode, this mode does not use programmable oversampling
factors.
tCLK_SCB(Max) = (tVD – tRF – 100 ns) / 3 (When analog filter is enabled and digital disabled)
tCLK_SCB(Max) = (tVD – tRF) / 4 (When analog filter is disabled and analog filter is enabled)
tRF is the maximum of either the rise or fall time. If clk_scb is slower than this frequency, tVD will be violated.
or
tCLK_SCB(Min) = (0.6 * tF – 50 ns)/2 (When analog filter is enabled and digital disabled)
tCLK_SCB(Min) = (0.6 * tF)/3 (When analog filter is disabled and digital enabled)
The result that yields the largest period from the two sets of equations above should be used to set the minimum period of
clk_scb.
Master-Slave
In this mode, when the SCB is acting as a master device, the block determines the I2C frequency. When the SCB is acting as
a slave device, the block does not determine the I2C frequency. Instead, the incoming I2C SCL signal does.
To guarantee operation in both master and slave modes, choose clock frequencies that work for both master and slave using
the tables above.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 363
Serial Communications Block (SCB)
1a. Select the EZI2C mode by writing ‘1’ to the EZ_MODE bit (bit 10) of the SCB_CTRL register.
1b. Select CMD_RESP mode by writing a 1 to the CMD_RESP bit (bit 12) of the SCB_CTRL register.
2. Set the S_READY_ADDR_ACK (bit 12) and S_READY_DATA_ACK (bit 13) bits of the SCB_I2C_CTRL register.
Note: For all modes clk_scb must also be configured. For information on configuring a peripheral clock and connecting it to
the SCB consult the Clocking System chapter on page 242.
The GPIO must also be connected to the SCB; see the following section for more details.
oe i2c_ic_block_ec
1 i2c_ctl
Open drain i2c_ic_scl_out
(pull-up) i2c_ic_sda_out
i2c_scl
Filter i2c_scl_in i2c_scl_in
i2c_sda_in
1
Filter i2c_ec_ctl
i2c_ec_scl_out
i2c_ec_sda_out
i2c_sda
Filter i2c_sda_in
i2c_scl_in
Open drain i2c_sda_in
(pull-up)
When configuring the I2C SDA/SCL lines, the following sequence must be followed. If this sequence is not followed, the I2C
lines may initially have overshoot and undershoot.
1. Set SCB_CTRL_MODE to ‘0’.
2. Configure HSIOM for SCL and SDA to connect to the SCB.
3. Set TX_CTRL.OPEN_DRAIN to ‘1’.
4. Configure I2C pins for high-impedance drive mode.
5. Configure SCB for I2C
6. Enable SCB
7. Configure I2C pins for Open Drain Drives Low.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 364
Serial Communications Block (SCB)
SCB_CTRL Enables the SCB block and selects the type of serial interface (SPI, UART, I2C). Also used to select inter-
nally and externally clocked operation and EZ and non-EZ modes of operation.
SCB_I2C_CTRL Selects the mode (master, slave) and sends an ACK or NACK signal based on receiver FIFO status.
Indicates bus busy status detection, read/write transfer status of the slave/master, and stores the EZ slave
SCB_I2C_STATUS
address.
SCB_I2C_M_CMD Enables the master to generate START, STOP, and ACK/NACK signals.
SCB_I2C_S_CMD Enables the slave to generate ACK/NACK signals.
Indicates whether the externally clocked logic is using the EZ memory. This bit can be used by software to
SCB_STATUS
determine whether it is safe to issue a software access to the EZ memory.
SCB_I2C_CFG Configures filters, which remove glitches from the SDA and SCL lines.
SCB_TX_CTRL Specifies the data frame width; also used to specify whether MSb or LSb is the first bit in transmission.
Specifies the trigger level, clearing of the transmitter FIFO and shift registers, and FREEZE operation of the
SCB_TX_FIFO_CTRL
transmitter FIFO.
Indicates the number of bytes stored in the transmitter FIFO, the location from which a data frame is read by
SCB_TX_FIFO_STATUS the hardware (read pointer), the location from which a new data frame is written (write pointer), and decides
if the transmitter FIFO holds the valid data.
SCB_TX_FIFO_WR Holds the data frame written into the transmitter FIFO. Behavior is similar to that of a PUSH operation.
Performs the same function as that of the SCB_TX_CTRL register, but for the receiver. Also decides
SCB_RX_CTRL
whether a median filter is to be used on the input interface lines.
SCB_RX_FIFO_CTRL Performs the same function as that of the SCB_TX_FIFO_CTRL register, but for the receiver.
SCB_RX_FIFO_STATUS Performs the same function as that of the SCB_TX_FIFO_STATUS register, but for the receiver.
Holds the data read from the receiver FIFO. Reading a data frame removes the data frame from the FIFO;
SCB_RX_FIFO_RD behavior is similar to that of a POP operation. This register has a side effect when read by software: a data
frame is removed from the FIFO.
Holds the data read from the receiver FIFO. Reading a data frame does not remove the data frame from the
SCB_RX_FIFO_RD_SILENT
FIFO; behavior is similar to that of a PEEK operation.
SCB_RX_MATCH Stores slave device address and is also used as slave device address MASK.
SCB_EZ_DATA Holds the data in an EZ memory location.
Note: Detailed descriptions of the I2C register bits are available in the registers TRM.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 365
Serial Communications Block (SCB)
Note: To avoid being triggered by events from previous transactions, whenever the firmware enables an interrupt mask
register bit, it should clear the interrupt request register in advance.
Note: If the DMA is used to read data out of RX FIFO, the NOT_EMPTY interrupt may never trigger. This can occur when
clk_peri (clocking DMA) is running much faster than the clock to the SCB. As a workaround to this issue, set the
RX_FIFO_CTRL.TRIGGER_LEVEL to ‘1’ (not 0); this will allow the interrupt to fire.
The following register definitions correspond to the SCB interrupts:
■ INTR_M: This register provides the instantaneous status of the interrupt sources. A write of ‘1’ to a bit will clear the
interrupt.
■ INTR_M_SET: A write of ‘1’ into this register will set the interrupt.
■ INTR_M_MASK: The bit in this register masks the interrupt sources. Only the interrupt sources with their masks enabled
can trigger the interrupt.
■ INTR_M_MASKED: This register provides the instantaneous value of the interrupts after they are masked. It provides
logical and corresponding request and mask bits. This is used to understand which interrupt triggered the event.
Note: While registers corresponding to INTR_M are used here, these definitions can be used for INTR_S, INTR_TX,
INTR_RX, INTR_I2C_EC, and INTR_SPI_EC.
Figure 28-45 shows the physical interrupt lines. All the interrupts are OR'd together to make one interrupt source that is the
OR of all six individual interrupts. All the externally-clocked interrupts make one interrupt line called interrupt_ec, which is the
OR'd signal of interrupt_i2C_ec and interrupt_spi_ec. All the internally-clocked interrupts make one interrupt line called
interrupt_ic, which is the OR'd signal of interrupt_master, interrupt_slave, interrupt_tx, and interrupt_rx. The Active
functionality interrupts are generated synchronously to clk_peri while the Deep Sleep functionality interrupts are generated
asynchronously to clk_peri.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 366
Serial Communications Block (SCB)
Interrupt Lines
Interrupt_master
INTR_M_MASKED[...]
Interrupt_slave
INTR_S_MASKED[...]
Interrupt_ic
Interrupt_tx
INTR_TX_MASKED[...]
Interrupt_rx
INTR_RX_MASKED[...] Interrupt
Interrupt_i2c_ec
Interrupt_ec
Interrupt_spi_ec
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 367
Serial Communications Block (SCB)
❐ RX FIFO trigger - More entries in the RX FIFO than the value specified by RX_FIFO_CTRL.TRIGGER_LEVEL.
■ SPI Externally Clocked
❐ Wake up request on slave select – Active on incoming slave request (with address match). Only set when EC_AM is
‘1’.
❐ SPI STOP detection at the end of each transfer – Activated at the end of every transfer (I2C STOP). Only set for a
slave request with an address match, in EZ and CMD_RESP modes, when EC_OP is ‘1’.
❐ SPI STOP detection at the end of a write transfer – Activated at the end of a write transfer (I2C STOP). This event is
an indication that a buffer memory location has been written to. For EZ mode, a transfer that only writes the base
address does not activate this event. Only set for a slave request with an address match, in EZ and CMD_RESP
modes, when EC_OP is ‘1’.
❐ SPI STOP detection at the end of a read transfer – Activated at the end of a read transfer (I2C STOP). This event is an
indication that a buffer memory location has been read from. Only set for a slave request with an address match, in EZ
and CMD_RESP modes when EC_OP is ‘1’.
Figure 28-46 and Figure 28-47 show how each of the interrupts are triggered. Figure 28-46 shows the TX buffer and the
corresponding interrupts while Figure 28-47 shows all the corresponding interrupts for the RX buffer. The FIFO has 256 split
into 128 bytes for TX and 128 bytes for RX instead of the 8 bytes shown in the figures. For more information on how to
implement and clear interrupts, see the SPI (SCB_SPI_PDL) datasheet and the PDL.
Figure 28-46. TX Interrupt Source Operation
Component Started Write 1 byte Write 1 more byte Write 4 more bytes Write 3 more bytes
TX FIFO Empty =1 TX FIFO Empty =1 TX FIFO Empty = 0 (W1C) TX FIFO Empty =1 TX FIFO Empty =0
TX FIFO Level =1 TX FIFO Level =1 TX FIFO Level =1 TX FIFO Level = 0 (W1C) TX FIFO Level =0
TX FIFO Not F ull = 1 TX FIFO Not F ull = 1 TX FIFO Not F ull = 1 TX FIFO Not F ull = 1 TX FIFO Not F ull = 0 (W1C)
SPI Done =0 SPI Done =0 SPI Done =0 SPI Done =0 SPI Done =0
Transmit 1 byte Transmit 3 more bytes Transmit 4 more bytes Transmit 7 more bits Transmit last bit
TX FIFO Empty =0 TX FIFO Empty =0 TX FIFO Empty =1 TX FIFO Empty =1 TX FIFO Empty =1
TX FIFO Level =0 TX FIFO Level =1 TX FIFO Level =1 TX FIFO Leve l =1 TX FIFO Level =1
TX FIFO Not F ull =1 TX FIFO Not F ull = 1 TX FIFO Not F ull = 1 TX FIFO Not F ull = 1 TX FIFO Not F ull =1
SPI Done =0 SPI Done =0 SPI Done =0 SPI Done =1 TX FIFO Underflo w = 1
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 368
Serial Communications Block (SCB)
Component Started Recevice 1 byte Receive 4 more byte Receive 3 more bytes Receive 3 more bytes
Dropped
RX FIFO Not Empty = 1 RX FIFO Not Empty = 1 RX FIFO Not Empty = 0 (W1C)
RX FIFO Level =1 RX FIFO Level = 0 (W1C) RX FIFO Level =0
RX FIFO Full = 0 (W1C) RX FIFO Full = 0 RX FIFO Full = 0
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 369
Serial Communications Block (SCB)
❐ TX FIFO underflow – Hardware attempts to read from an empty TX FIFO. This happens when the SCB is ready to
transfer data and EMPTY is ‘1’.
❐ TX NACK – UART transmitter receives a negative acknowledgment in SmartCard mode.
❐ TX done – This happens when the UART completes transferring all data in the TX FIFO and the last stop field is trans-
mitted (both TX FIFO and transmit shifter register are empty).
❐ TX lost arbitration – The value driven on the TX line is not the same as the value observed on the RX line. This condi-
tion event is useful when transmitter and receiver share a TX/RX line. This is the case in LIN or SmartCard modes.
■ UART RX
❐ RX FIFO has more entries than the value specified by TRIGGER_LEVEL in SCB_RX_FIFO_CTRL.
❐ RX FIFO full – RX FIFO is full. Note that received data frames are lost when the RX FIFO is full.
❐ RX FIFO not empty – RX FIFO is not empty.
❐ RX FIFO overflow – Hardware attempts to write to a full RX FIFO.
❐ RX FIFO underflow – Firmware attempts to read from an empty RX FIFO.
❐ Frame error in received data frame – UART frame error in received data frame. This can be either a start of stop bit
error:
Start bit error: After the beginning of a start bit period is detected (RX line changes from 1 to 0), the middle of the start
bit period is sampled erroneously (RX line is ‘1’). Note: A start bit error is detected before a data frame is received.
Stop bit error: The RX line is sampled as ‘0’, but a ‘1’ was expected. A stop bit error may result in failure to receive
successive data frames. Note: A stop bit error is detected after a data frame is received.
❐ Parity error in received data frame – If UART_RX_CTL.DROP_ON_PARITY_ERROR is ‘1’, the received frame is
dropped. If UART_RX_CTL.DROP_ON_PARITY_ERROR is ‘0’, the received frame is sent to the RX FIFO. In Smart-
Card sub mode, negatively acknowledged data frames generate a parity error. Note that firmware can only identify the
erroneous data frame in the RX FIFO if it is fast enough to read the data frame before the hardware writes a next data
frame into the RX FIFO.
❐ LIN baud rate detection is completed – The receiver software uses the UART_RX_STATUS.BR_COUNTER value to
set the clk_scb to guarantee successful receipt of the first LIN data frame (Protected Identifier Field) after the synchro-
nization byte.
❐ LIN break detection is successful – The line is ‘0’ for UART_RX_CTRL.BREAK_WIDTH + 1 bit period. Can occur at
any time to address unanticipated break fields; that is, “break-in-data” is supported. This feature is supported for the
UART standard and LIN submodes. For the UART standard submodes, ongoing receipt of data frames is not affected;
firmware is expected to take proper action. For the LIN submode, possible ongoing receipt of a data frame is stopped
and the (partially) received data frame is dropped and baud rate detection is started. Set to ‘1’, when event is detected.
Write with '1' to clear bit.
Figure 28-48 and Figure 28-49 show how each of the interrupts are triggered. Figure 28-48 shows the TX buffer and the
corresponding interrupts while Figure 28-49 shows all the corresponding interrupts for the RX buffer. The FIFO has 256 split
into 128 bytes for TX and 128 bytes for RX instead of the 8 bytes shown in the figures. For more information on how to
implement and clear interrupts see the UART (SCB_UART_PDL) datasheet and the PDL.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 370
Serial Communications Block (SCB)
Component Started Write 1 byte Write 1 more byte Write 4 more bytes Write 3 more bytes
TX FIFO Empty =1 TX FIFO Empty =1 TX FIFO Empty = 0 (W1C) TX FIFO Empty =1 TX FIFO Empty =0
TX FIFO Level =1 TX FIFO Level =1 TX FIFO Level =1 TX FIFO Level = 0 (W1C) TX FIFO Level =0
TX FIFO Not F ull = 1 TX FIFO Not F ull = 1 TX FIFO Not F ull = 1 TX FIFO Not F ull = 1 TX FIFO Not F ull = 0 (W1C)
UART Done =0 UART Done =0 UART Do ne = 0 UART Do ne =0 UART Do ne =0
Transmit 1 byte Transmit 3 more bytes Transmit 4 more bytes Transmit last bit
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 371
Serial Communications Block (SCB)
Component Started Recevice 1 byte Receive 4 more byte Receive 3 more bytes Receive 3 more bytes
Dropped
RX FIFO Not Empty = 1 RX FIFO Not Empty = 1 RX FIFO Not Empty = 0 (W1C)
RX FIFO Level =1 RX FIFO Level = 0 (W1C) RX FIFO Level =0
RX FIFO Full = 0 (W1C) RX FIFO Full = 0 RX FIFO Full = 0
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 372
Serial Communications Block (SCB)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 373
Serial Communications Block (SCB)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 374
29. Serial Memory Interface (SMIF)
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The SMIF block implements a single-SPI, dual-SPI, quad-SPI, or octal-SPI communication to interface with external memory
chips. The SMIF block’s primary use case is to set up the external memory and have it mapped to the PSoC 6 MCU memory
space using the hardware. This mode of operation, called the XIP mode, allows the bus masters in the PSoC 6 MCU to
directly interact with the SMIF for memory access to an external memory location.
A graphical interface is provided with the ModusToolbox for configuring the QSPI (SMIF) block. For more information, see the
ModusToolbox QSPI Configurator Guide.
29.1 Features
The Serial Memory Interface (SMIF) block provides a master interface to serial memory devices that supports the following
functionality.
■ Interfacing up to four memory devices (slaves) at a time
■ SPI protocol
❐ SPI mode 0: clock polarity (CPOL) and clock phase (CPHA) are both ‘0’
❐ Support for single, dual, quad, and octal SPI protocols
❐ Support for dual-quad SPI mode: the use of two quad SPI memory devices to increase data bandwidth for SPI read
and write transfers
❐ Support for configurable MISO sampling time and programmable receiver clock
■ Support for device capacities in the range of 64 KB to 128 MB
■ eXecute In Place (XIP) enables mapping the external memory into an internal memory address
■ Command mode enables using the SMIF block as a simple communication hardware
■ Supports a 4-KB read cache in memory mapped (XIP) mode
■ Supports on-the-fly 128-bit encryption and decryption
29.2 Architecture
Figure 29-1 shows a high-level block diagram of the SMIF hardware in PSoC 6 MCUs. Notice that the block is divided into
multiple clock domains. This enables multiple domains to access the SMIF and still enable maintaining an asynchronous
clock for the communication interface.
The SMIF block can also generate DMA triggers and interrupt signals. This allows events in the SMIF block to trigger actions
in other parts of the system.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 375
Serial Memory Interface (SMIF)
The SMIF interface is implemented using eight data lines, four slave select lines, and a clock line.
The access to the SMIF block can be by two modes: Command mode or XIP mode. The Command mode gives access to the
SMIF’s peripheral registers and the internal FIFOs. This mode is used when the user code is responsible for constructing the
command structure for the external memory. Typically, this mode is used when the SMIF writes to an external flash memory.
The MMIO interface is also used to configure the SMIF hardware block, including configuring the device registers that set up
the XIP operation of the SMIF block.
The XIP mode of operation maps the external memory space to a range of addresses in the PSoC 6 MCU’s address space.
Refer to the registers TRM for details. When this address range is accessed, the hardware automatically generates the
commands required to initiate the associated transfer from the external memory. The typical use case for the XIP mode is to
execute code placed in external memory. Thus executing code from external memory is seamless.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 376
Serial Memory Interface (SMIF)
SMIF
clk_slow domain
clk_fast domain
clk_sys domain
AHB-Lite AHB-Lite interface
interface 0 interface 1
4 KB 4 KB MMIO
cache cache
Port arbiter
tr_tx_req
Cryptography tr_rx_req
interrupt
XIP
clk_hf domain
Mode multiplexer
FIFOs
clk_if_rx domain
clk_if_tx domain
Capture
Logic
clk_if domain
IOSS
The SMIF block has three AHB-Lite interfaces: specified by SMIFn_CTL.XIP_MODE. The operation mode
■ An AHB-Lite interface to access the SMIF’s MMIO should not be modified when the SMIF is busy
registers. (STATUS.BUSY is ‘1’).
■ Two AHB-Lite interfaces to support execute-in-place In the MMIO AHB-Lite interface, access is supported
(XIP). through software writes to transmit (Tx) FIFOs and software
reads from receive (Rx) FIFOs. The FIFOs are mapped on
All interfaces provide access to external memory devices. At
SMIF registers. This interface provides the flexibility to
any time, either the MMIO AHB-Lite interface or the two XIP
implement any memory device transfer. For example,
AHB-Lite interfaces have access to the memory interface
memory device transfers to setup, program, or erase the
logic and external memory devices. The operation mode is
external memory devices.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 377
Serial Memory Interface (SMIF)
In an XIP AHB-Lite interface, access is supported through memory interface. The TX_COUNT command specifies
XIP: AHB-Lite read and write transfers are automatically (by the width of the data transfer and always constitutes the
the hardware) translated in memory device read and write last phase of the memory transfer (implicit “last
transfers. This interface provides efficient implementation of command” indication - de-asserts the slave select). Note
memory device read and write transfers, but does NOT that the TX_COUNT command does not assert the slave
support other types of memory device transfers. To improve select lines. This must be done by a Tx command
XIP performance, the XIP AHB-Lite interface has a 4-KB preceding it.
read cache. ■ RX_COUNT command. The RX_COUNT command
As mentioned, Command mode and XIP mode are mutually specifies the number of bytes to be received from the Rx
exclusive. The operation modes share Tx and Rx FIFOs and data FIFO. This command relies on the Rx data FIFO to
memory interface logic. In Command mode, the Tx and Rx accept the bytes that are received over the memory
FIFOs are accessed through the SMIF registers and under interface. The RX_COUNT command specifies the width
software control. In XIP mode, the Tx and Rx FIFOs are of the data transfer and always constitutes the last
under hardware control. The memory interface logic is phase of the memory transfer (implicit “last command”
controlled through the Tx and Rx FIFOs and is agnostic of indication - de-asserts the slave select). Note that the
the operation mode. RX_COUNT command does not assert the slave select
lines. This must be done by a Tx command preceding it.
29.2.1 Tx and Rx FIFOs ■ DUMMY_COUNT command. The DUMMY_COUNT
command specifies a number of dummy cycles. Dummy
The SMIF block has two Tx FIFOs and one Rx FIFO. These cycles are used to implement a turn-around (TAR) time
FIFOs provide an asynchronous clock domain transfer in which the memory master changes from a transmitter
between clk_hf logic and clk_if_tx/clk_if_rx memory driving the data lines to a receiver receiving on the same
interface logic. The memory interface logic is completely data lines. The DUMMY_COUNT command never
controlled through the Tx and Rx FIFOs. constitutes the last phase of the memory transfer
■ The Tx command FIFO transmits memory commands to (implicit NOT “last command” indication - de-asserts the
the memory interface logic. slave select); that is, it must be followed by another
command. Note that the DUMMY COUNT command
■ The Tx data FIFO transmits write data to the memory
does not assert the slave select lines. This must be done
interface transmit logic.
by a Tx command preceding it.
■ The Rx data FIFO receives read data from the memory
interface receive logic. Together, the four command types can be used to construct
any SPI transfer. The Tx command FIFO is used by both the
29.2.1.1 Tx Command FIFO memory interface transmit and receive logic. This ensures
lockstep operation. The Tx command is a representation of
The Tx command FIFO consists of four 20-bit entries. Each a queue of commands that are to be processed.
entry holds a command. A memory transfer consists of a
series of commands. In other words, a command specifies a The software will write the sequence of commands into the
phase of a memory transfer. Four different types of Tx command FIFO to generate a sequence responsible for
commands are supported: the communication with slave device. The software can read
the number of used Tx command FIFO entries through the
■ Tx command. A memory transfer must start with a Tx
TX_CMD_FIFO_STATUS.USED[2:0] register field.
command. The Tx command includes a byte that is to be
transmitted over the memory interface. The Tx The software can write to the Tx command FIFO through the
command specifies the width of the data transfer (single, MMIO TX_CMD_FIFO_WR register. If software attempts to
dual, quad, or octal data transfer). The Tx command write to a full Tx command FIFO, the MMIO CTL.BLOCK
specifies whether the command is for the last phase of field specifies the behavior:
the memory transfer (explicit “last command” indication). ■ If CTL.BLOCK is ‘0’, an AHB-Lite bus error is generated.
The Tx command specifies which of the four external
■ If CTL.BLOCK is ‘1’, the AHB-Lite write transfer is
devices are selected (multiple devices can be selected
extended until an entry is available. This increases
simultaneously); that is, the device selection as encoded
latency.
by the Tx command is used for the complete memory
transfer. The Tx command asserts the corresponding
slave select lines. This is the reason every memory
29.2.1.2 Tx Data FIFO
transfer should start with this command. The Tx data FIFO consists of eight 8-bit entries. A Tx
■ TX_COUNT command. The TX_COUNT command command FIFO TX_COUNT command specifies the
specifies the number of bytes to be transmitted from the number of bytes to be transmitted; that is, specifies the
Tx data FIFO. This command relies on the Tx data FIFO number of Tx data FIFO entries used. The Tx data FIFO is
to provide the bytes that are to be transmitted over the used by the memory interface transmit logic.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 378
Serial Memory Interface (SMIF)
Software can read the number of used Tx data FIFO entries reads from the Rx FIFO. The Tx command FIFO has
through the TX_DATA_FIFO_STATUS.USED[3:0] register formatted commands (Tx, TX_COUNT, RX_COUNT, and
field. DUMMY_COUNT) that are described in the registers TRM.
Software can write to the Tx data FIFO through the Software should ensure that it generates correct memory
TX_DATA_FIFO_WR1, TX_DATA_FIFO_WR2, and transfers and accesses the FIFOs correctly. For example, if
TX_DATA_FIFO_WR4 registers: a memory transfer is generated to read four bytes from a
■ The TX_DATA_FIFO_WR1 register supports a write of a memory device, software should read the four bytes from
single byte to the FIFO. the Rx data FIFO. Similarly, if a memory transfer is
generated to write four bytes to a memory device, software
■ The TX_DATA_FIFO_WR2 register supports a write of
should write the four bytes to the Tx command FIFO or Tx
two bytes to the FIFO.
data FIFO.
■ The TX_DATA_FIFO_WR4 register supports a write of
four bytes to the FIFO. If software attempts to write more Incorrect software behavior can lock up the memory
bytes than available entries in the Tx data FIFO, the interface. For example, a memory transfer to read 32 bytes
MMIO CTL.BLOCK field specifies the behavior: from a memory device, without software reading the Rx data
FIFO will lock up the memory transfer as the memory
■ If CTL.BLOCK is ‘0’, an AHB-Lite bus error is generated.
interface cannot provide more than eight bytes to the Rx
■ If CTL.BLOCK is ‘1’, the AHB-Lite write transfer is data FIFO (the Rx data FIFO has eight entries). This will
extended until the required entries are available. prevent any successive memory transfers from taking place.
Hence, the software should make sure that it read the FIFOs
29.2.1.3 Rx Data FIFO to avoid congestion. Note that a locked up memory transfer
due to Tx or Rx FIFO states is still compliant to the memory
The Rx data FIFO consists of eight 8-bit entries. A Tx
bus protocol (but undesirable): the SPI protocol allows
command FIFO RX_COUNT command specifies the
shutting down the interface clock in the middle of a memory
number of bytes to be received; that is, specifies the number
transfer.
of Rx data FIFO entries used. The memory interface
transmit logic will stop generating the SPI clock when the Rx
data FIFO is full. This is how flow control is achieved. 29.2.3 XIP Mode
Software can read the number of used Rx data FIFO entries If CTL.XIP_MODE is ‘1’, the SMIF is in XIP mode. Hardware
through the RX_DATA_FIFO_STATUS.USED[3:0] register automatically (without software intervention) generates
field. memory transfers by accessing the Tx FIFOs and Rx FIFO.
Hardware supports only memory read and write transfers.
Software can read from the Rx data FIFO through the MMIO Other functionality such as status reads are not supported.
RX_DATA_FIFO_RD1, RX_DATA_FIFO_RD2, and This means operations such as writing into a flash device
RX_DATA_FIFO_RD4 registers: may not be supported by XIP mode. This is because the
■ The RX_DATA_FIFO_RD1 register supports a read of a writing operation into a flash memory involves not only a
single byte from the FIFO. write command transfer, but also a status check to verify the
■ The RX_DATA_FIFO_RD2 register supports a read of status of the operation.
two bytes from the FIFO. ■ Hardware generates a memory read transfer for an
■ The RX_DATA_FIFO_RD4 register supports a read of AHB-Lite read transfer (to be precise: only for AHB-Lite
four bytes from the FIFO. If software attempts to read read transfers that miss in the cache).
more bytes than available in the Rx data FIFO, the ■ Hardware generates a memory write transfer for an
MMIO CTL.BLOCK field specifies the behavior: AHB-Lite write transfer.
■ If BLOCK is ‘0’, an AHB-Lite bus error is generated and Each slave device slot has a set of associated device
hard fault occurs. configuration registers. To access a memory device in XIP
If BLOCK is ‘1’, the AHB-Lite read transfer is extended until mode, the corresponding device configuration registers
the bytes are available. (SMIFn_DEVICEn) should be initialized. The device
configuration register sets up the following parameters for
Software can also read the first byte of the RX data FIFO memory:
without changing the status of the FIFO through the
■ Write enable (WR_EN): Used to disable writes in XIP
RX_DATA_FIFO_RD1_SILENT register.
mode.
■ Crypto enable (CRYPTO_EN): When enabled, all read
29.2.2 Command Mode access to the memory is decrypted and write access
If CTL.XIP_MODE is ‘0’, the SMIF is in Command mode. encrypted automatically.
Software generates SPI transfers by accessing the Tx ■ Data Select (DATA_SEL): Selects the data lines to be
FIFOs and Rx FIFO. Software writes to the Tx FIFOs and used (Connecting SPI Memory Devices on page 382).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 379
Serial Memory Interface (SMIF)
■ Base address and size: Sets up the mapped memory cache. Read transfers that “miss” result in a XIP memory
space. Any access in this space is converted to the read transfer.
access to the external memory automatically.
If CA_CTL.PREF_EN is ‘1’, prefetching is enabled and if
■ Read and write commands: Used to communicate with CA_CTL.PREF_EN is ‘0’, prefetching is disabled. If prefetch
the external memory device. These commands are is enabled, a cache miss results in a 16 B (subsector) refill
defined by multiple settings. for the missing data AND a 16 B prefetch for the next
As different memory devices support different types of sequential data (independent of whether this data is already
memory read and write commands, you must provide the in the cache or not).
hardware with device specifics, such that it can perform the Cache coherency is not supported by the hardware. For
automatic translations. To this end, each memory device example, an XIP interface 0 write to an address in the XIP
has a set of MMIO registers that specify its memory read interface 0 cache invalidates (clears) the associated cache
and write transfers. This specification includes: subsector in the XIP interface 0 cache, but not in the XIP
■ Presence and value of the SPI command byte. interface 1 cache. This means XIP interface 1 cache now
■ Number of address bytes. has outdated data. The user code can manually invalidate
cache by using the SLOW_CA_CMD[INV] or
■ Presence and value of the mode byte.
FAST_CA_CMD[INV] register.
■ Number of dummy cycles.
Caches should also be invalidated upon mode transitions.
■ Specified data transfer widths.
For example, in Command mode, a write to an address in
The XIP interface logic produces an AHB-Lite bus error the cache interface will cause the data in the cache interface
under the following conditions: to be outdated. The cache should be invalidated when
■ The SMIF is disabled (SMIFn_CTL.ENABLED is ‘0’). transitioning to XIP mode to ensure that only valid data is
used.
■ The SMIF is not in XIP_MODE (SMIFn_CTL.XIP_MODE
is ‘0’).
29.2.5 Arbitration
■ The transfer request is not in a memory region.
■ The transfer is a write and the identified memory region The SMIF provides two AHB-Lite slave interfaces to CPUSS
does not support writes (one fast interface and one slow interface). Both interfaces
(SMIFn_DEVICEn_CTL.WR_EN is ‘0’). have a cache (as described in 29.2.4 Cache) and can
generate XIP requests to the external memory devices.
■ In XIP mode (CTL.XIP_MODE is ‘1’) and dual quad SPI
mode (ADDR_CTL.DIV2 is ‘1’) or the transfer address is An arbitration component (as shown in Figure 29-1)
not a multiple of 2. arbitrates between the two interfaces. Arbitration is based
■ In XIP mode (CTL.XIP_MODE is ‘1’) and dual quad SPI on the master identifier of the AHB-Lite transfer. The
mode (ADDR_CTL.DIV2 is ‘1’), the transfer size is not a arbitration priority is specified by a system wide priority.
multiple of 2. Each master identifier has a 2-bit priority level (“0” is the
highest priority level and “3” is the lowest priority level).
Master identifiers with the same priority level are within the
29.2.4 Cache same priority group. Within a priority group, round-robin
To improve XIP performance, the XIP AHB-Lite interface arbitration is performed.
has a cache. The cache is defined as follows:
■ 4 KB capacity. 29.2.6 Deselect Delay
■ Read-only cache. Write transfers bypass the cache. A The SMIF supports configuration of deselect delay between
write to an address, which is prefetched in the cache, transfers. The SMIFn_CTL.DESELECT_DELAY field
invalidates the associated cache subsector. If there is a controls the minimum number of interface cycles to hold the
write to a memory in Command mode then you must chip select line inactive.
invalidate the cache while switching back to XIP mode.
■ Four-way set associative, with a least recently used 29.2.7 Cryptography
(LRU) replacement scheme.
In XIP mode, a cryptography component supports on-the-fly
Each XIP interface implements a 4-KB cache memory, encryption for write data and on-the-fly decryption for read
enabled by default. Any XIP access can be cached if a data. The use of on-the-fly cryptography is determined by a
cache is enabled. There are separate cache registers for the device’s MMIO CTL.CRYPTO_EN field. In Command mode,
slow cache (in the clk_slow domain) and fast cache (in the the cryptography component is accessible through a
clk_fast domain). The cache can be enabled using the register interface to support offline encryption and
SLOW_CA_CTL[ENABLED] or FAST_CA_CTL[ENABLED] decryption.
registers. Read transfers that “hit” are processed by the
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 380
Serial Memory Interface (SMIF)
The usage scenario for cryptography is: data is encrypted in hardware, by applying AES-128 with KEY[127:0] on a
the external memory devices. Therefore, memory read and plaintext PT[127:0], we get a ciphertext CT[127:0].
write data transfers require decryption and encryption
In XIP mode, the XIP address is used as the plaintext PT[].
functionality respectively. By storing data encrypted in the
The resulting ciphertext CT[] is used on-the-fly and not
external memory devices (nonvolatile devices), leakage of
software accessible. The XIP address is extended with the
sensitive data is avoided.
CRYPTO_INPUT3, …, CRYPTO_INPUT0 registers.
Encryption and decryption are based on the AES-128
In Command mode, the MMIO CRYPTO_INPUT3, …,
forward block cipher: advanced encryption standard block
CRYPTO_INPUT0 registers provide the plaintext PT[]. The
cipher with a 128-bit key. KEY[127:0] is a secret (private)
resulting ciphertext CT[] is provided through the MMIO
key programmed into the CRYPTO_KEY3, …,
CRYPTO_OUTPUT3, …, CRYPTO_OUTPUT0 registers.
CRYPTO_KEY0 registers. These registers are software
write-only: a software read returns “0”. In the SMIF Figure 29-2 illustrates the functionality in XIP and Command
modes.
Figure 29-2. Cryptography in XIP and Command Modes
XIP mode MMIO mode
On-the-fly
{CRYPTO_OUTPUT3,
usage CRYPTO_OUTPUT2,
CRYPTO_OUTPUT1,
ciphertext CT[127:0] CRYPTO_OUTPUT0}
{CRYPTO_KEY3, {CRYPTO_KEY3,
AES-128 AES-128
CRYPTO_KEY2, CRYPTO_KEY2,
forward block forward block
CRYPTO_KEY1, CRYPTO_KEY1,
cipher cipher
CRYPTO_KEY0} CRYPTO_KEY0}
{CRYPTO_INPUT3, {CRYPTO_INPUT3,
CRYPTO_INPUT2, CRYPTO_INPUT2,
CRYPTO_INPUT1, CRYPTO_INPUT1,
A[31:4], CRYPTO_INPUT0}
CRYPT0_INPUT0.INPUT[3:0]}
In XIP mode, the resulting ciphertext CT[] (of the encrypted address) is XOR’d with the memory transfer’s read data or write
data. Note that the AES-128 block cipher is on the address of the data and not on the data itself. For memory read transfers,
this means that as long as the latency of the memory transfer’s read data is longer than the AES-128 block cipher latency, the
on-the-fly decryption does not add any delay. Figure 29-3 illustrates the complete XIP mode functionality.
The XIP mode only encrypts the address and XORs with the data; to implement the same in Command mode, you must
provide the address as the PT[] into the crypto_INPUTx registers.
Figure 29-3. XIP Mode Functionality
encrypted read data encrypted write data
128 128
ciphertext CT[127:0]
{CRYPTO_KEY3,
AES-128
CRYPTO_KEY2,
forward block
CRYPTO_KEY1,
cipher
CRYPTO_KEY0}
128 128
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 381
Serial Memory Interface (SMIF)
29.3 Memory Device Signal ■ The definition of a write transfer to support XIP mode.
29.3.1 Specifying Memory Devices In XIP mode, dual quad SPI mode requires the
ADDR_CTL.DIV2 field of the selected memory devices to be
The SMIF requires that the memory devices are defined for set to ‘1’. When this field is ‘1’, the transfer address is
their operation in XIP mode. The SMIF supports up to four divided by 2 and the divided by 2 address is provided to the
memory devices. Each memory device is defined by a set of memory devices.
registers. The memory device specific register structure
In dual quad SPI mode, each memory device contributes a
includes:
4-bit nibble for each 8-bit byte. However, both memory
■ The device base address and capacity. The ADDR devices are quad SPI memories with a byte interface.
register specifies the memory device’s base address in Therefore, the transfer size must be a multiple of 2.
the PSoC 6 MCU address space and the MASK register
specifies the memory device’s size/capacity. If a memory The XIP_ALIGNMENT_ERROR interrupt cause is set under
device is not present or is disabled, the ADDR and the following conditions (in XIP mode and when
MASK registers specify a memory device with 0 B ADDR_CTL.DIV2 is ‘1’):
capacity. Typically, the devices’ address regions in the ■ The transfer address is not a multiple of 2. In this case
PSoC 6 MCU address space are non-overlapping the divided by 2 address for the memory devices is
(except for dual-quad SPI mode) to ensure that the incorrect.
activation of select signals is mutually exclusive. ■ The transfer size is not a multiple of 2. In this case, the
■ The device data signal connections (as described in memory devices contribute only a nibble of a byte. This
Connecting SPI Memory Devices on page 382). is not supported as the memory devices have a byte
■ The definition of a read transfer to support XIP mode. interface.
Table 29-1 illustrates that each memory has a single clock signal SCK, a single (low active) select signal (CS), and multiple
data signals (IO0, IO1, …).
Each memory device has a fixed select signal connection (to select[3:0]).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 382
Serial Memory Interface (SMIF)
Each memory device has programmable data signal connections (to data[7:0]): the CTL.DATA_SEL[1:0] field specifies how a
device’s data signals are connected. The CTL.DATA_SEL[1:0] is responsible for configuring the selection of data lines to be
used by a slave. This is not to be confused with the select lines that are used for addressing the four slaves of the SMIF
master. This information is used by the SMIF interface to drive out data on the correct spi_data[] outputs and capture data
from the correct spi_data[] inputs. If multiple device select signals are activated, the same data is driven to all selected
devices simultaneously.
Not all data signal connections are legal/supported. Supported connections are dependent on the type of memory device.
CTL.DATA_SEL[1:0] = 0
SoC Device 0: SPI
spi_clk SCK memory
SMIF
CS
spi_select[0]
SI
SO
spi_data[0]
spi_data[1]
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 383
Serial Memory Interface (SMIF)
Because of the pin layout, you might want to connect a memory device to specific data lines. Figure 29-5 illustrates memory
device 0, which is a single SPI memory with data signals connections to spi_data[7:6].
Figure 29-5. Single SPI Memory Device 0 Connected to spi_data[7:6]
CTL.DATA_SEL[1:0] = 3
SoC Device 0: SPI
spi_clk SCK memory
SMIF
CS
spi_select[0]
SI
SO
spi_data[6]
spi_data[7]
Figure 29-6 illustrates memory devices 0 and 1, both of which are single SPI memories. Each device uses dedicated data
signal connections. The device address regions in the PSoC 6 MCU address space must be non-overlapping to ensure that
the activation of select[0] and select[1] are mutually exclusive.
Figure 29-6. Single SPI Memory Devices 0 and 1 - Dedicated Data Signal
CTL.DATA_SEL[1:0] = 0
SoC Device 0: SPI
spi_clk SCK memory
SMIF
CS
spi_select[0]
SI
spi_select[1]
SO
CTL.DATA_SEL[1:0] = 3
Device 1: SPI
spi_data[0] SCK memory
spi_data[1] CS
SI
SO
spi_data[6]
spi_data[7]
Figure 29-7 illustrates memory devices 0 and 1, both of which are single SPI memories. Both devices use shared data signal
connections. The devices’ address regions in the PSoC 6 MCU address space must be non-overlapping to ensure that the
activation of select[0] and select[1] are mutually exclusive. Note that this solution increases the load on the data lines, which
may result in a slower I/O interface.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 384
Serial Memory Interface (SMIF)
Figure 29-7. Single SPI Memory Devices 0 and 1 - Shared Data Signal
CTL.DATA_SEL[1:0] = 0
SoC Device 0: SPI
spi_clk SCK memory
SMIF
CS
spi_select[0]
SI
spi_select[1]
SO
CTL.DATA_SEL[1:0] = 0
Device 1: SPI
spi_data[0] SCK memory
spi_data[1] CS
SI
SO
Figure 29-8 illustrates memory device 0, which is a quad SPI memory with data signals connections to spi_data[7:4].
Figure 29-8. Quad SPI Memory Device 0
CTL.DATA_SEL[1:0] = 0
SoC Device 0:
Quad SPI
spi_clk SCK memory
SMIF
CS
spi_select[0]
SI/IO0
SO/IO1
WP/IO2
HOLD/IO3
spi_data[0]
spi_data[1]
spi_data[2]
spi_data[3]
Figure 29-9 illustrates memory devices 0 and 1, device 0 is a single SPI memory and device 1 is a quad SPI memory. Each
device uses dedicated data signal connections. The device address regions in the PSoC 6 MCU address space must be non-
overlapping to ensure that the activation of select[0] and select[1] are mutually exclusive.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 385
Serial Memory Interface (SMIF)
Figure 29-9. Single SPI Memory 0 and Quad SPI Memory 1 - Dedicated Data Signal
CTL.DATA_SEL[1:0] = 0
SoC Device 0: SPI
spi_clk SCK memory
SMIF
CS
spi_select[0]
SI
spi_select[1]
SO
CTL.DATA_SEL[1:0] = 2
Device 1:
Quad SPI
spi_data[0] SCK memory
spi_data[1] CS
SI/IO0
SO/IO1
spi_data[4] WP/IO2
spi_data[5] HOLD/IO3
spi_data[6]
spi_data[7]
Figure 29-10 illustrates memory devices 0 and 1, device 0 is a single SPI memory and device 1 is a quad SPI memory. Both
devices use shared data signal connections. The device address regions in the PSoC 6 MCU address space must be non-
overlapping to ensure that the activation of select[0] and select[1] are mutually exclusive.
Figure 29-10. Single SPI Memory Device 0 and Quad SPI Memory Device 1 - Shared Data Signal
CTL.DATA_SEL[1:0] = 0
SoC Device 0: SPI
spi_clk SCK memory
SMIF
CS
spi_select[0]
SI
spi_select[1]
SO
CTL.DATA_SEL[1:0] = 0
Device 1:
Quad SPI
spi_data[0] SCK memory
spi_data[1] CS
spi_data[2] SI/IO0
spi_data[3] SO/IO1
WP/IO2
HOLD/IO3
Figure 29-11 illustrates memory devices 0 and 1, both of which are quad SPI memories. Each device uses dedicated data
signal connections. The device address regions in the PSoC 6 MCU address space are the same to ensure that the activation
of select[0] and select[1] are the same (in XIP mode). This is known as a dual-quad configuration: during SPI read and write
transfers, each device provides a nibble of a byte.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 386
Serial Memory Interface (SMIF)
CTL.DATA_SEL[1:0] = 0
SoC Device 0:
Quad SPI
spi_clk SCK memory
SMIF
CS
spi_select[0]
SI/IO0
spi_select[1]
SO/IO1
WP/IO2
HOLD/IO3
spi_data[0]
CTL.DATA_SEL[1:0] = 2
spi_data[1] Device 1:
Quad SPI
spi_data[2] SCK memory
spi_data[3] CS
spi_data[4] SI/IO0
spi_data[5] SO/IO1
spi_data[6] WP/IO2
spi_data[7] HOLD/IO3
Figure 29-12 illustrates memory device 0, which is a octal SPI memory with data signals connections to spi_data[7:0].
Figure 29-12. Octal SPI Memory Device 0
CTL.DATA_SEL[1:0] = 0
Device 0:
SoC
Octal SPI
spi_clk SCK memory
SMIF
CS
spi_select[0]
IO0
IO1
IO2
IO3
spi_data[0] IO4
spi_data[1] IO5
spi_data[2] IO6
spi_data[3] IO7
spi_data[4]
spi_data[5]
spi_data[6]
spi_data[7]
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 387
Serial Memory Interface (SMIF)
bits are transferred per cycle. For a single SPI device and device data signal connections to spi_data[1:0] (DATA_SEL is “0”),
Table 29-3 summarizes the transfer of byte B.
Note that in single SPI data transfer, the data signals are uni-directional: in the table, data[0] is exclusively used for write data
connected to the device SI input signal and data[1] is exclusively used for read data connected to the device SO output
signal.
For a dual SPI device and device data signal connections to data[1:0] (DATA_SEL is “0”), Table 29-4 summarizes the transfer
of byte B.
For a quad SPI device and device data signal connections to data[3:0] (DATA_SEL is “0”), Table 29-5 summarizes the
transfer of byte B.
For a octal SPI device and device data signal connections to data[7:0] (DATA_SEL is “0”), Table 29-6 summarizes the transfer
of byte B.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 388
Serial Memory Interface (SMIF)
CTL.DATA_SEL[1:0] = 0
SoC Device 0:
Quad SPI
spi_clk SCK memory
SMIF
CS
spi_select[0]
SI/IO0
spi_select[1]
SO/IO1
WP/IO2
HOLD/IO3
spi_data[0]
CTL.DATA_SEL[1:0] = 2
spi_data[1] Device 1:
Quad SPI
spi_data[2] SCK memory
spi_data[3] CS
spi_data[4] SI/IO0
spi_data[5] SO/IO1
spi_data[6] WP/IO2
spi_data[7] HOLD/IO3
For dual quad SPI mode, the AHB-Lite bus transfer address is divided by two. Cryptography and write functionality are
disabled in the following example.
#define MASK_1MB 0xfff00000;
DEV0_ADDR = CPUSS_SMIF_BASE;
DEV0_MASK = MASK_1MB // MASK: 1 MB region
DEV0_CTL =(0 << SMIF_DEVICE_CTL_DATA_SEL_Pos) // DATA_SEL: data[3:0]
| (0 << SMIF_DEVICE_CTL_CRYPTO_EN_Pos) // CRYPTO_EN
| (0 << SMIF_DEVICE_CTL_WR_EN_Pos)); // WR_EN
DEV0_ADDR_CTL = (1 << SMIF_DEVICE_ADDR_CTL_DIV2_Pos) // DIV2: enabled
| ((3-1) << SMIF_DEVICE_ADDR_CTL_SIZE2_Pos)); // SIZE: 3 B address
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 389
Serial Memory Interface (SMIF)
DEV1_ADDR = CPUSS_SMIF_BASE;
DEV1_MASK = 0xfff00000; // MASK: 1 MB region
DEV1_CTL = (2 << SMIF_DEVICE_CTL_DATA_SEL_Pos) // DATA_SEL: data[7:4]
| (0 << SMIF_DEVICE_CTL_CRYPTO_EN_Pos) // CRYPTO_EN
| (1 << SMIF_DEVICE_CTL_WR_EN_Pos)); // WR_EN
DEV1_ADDR_CTL = (1 << SMIF_DEVICE_ADDR_CTL_DIV2_Pos) // DIV2: enabled
| ((3-1) << SMIF_DEVICE_ADDR_CTL_SIZE2_Pos)); // SIZE: 3 B address
For XIP read transfers, the 0xEB command/instruction is used (Figure 29-14 illustrates a two-byte transfer from devices 0 and
1 in dual quad SPI mode).
Figure 29-14. Two-Bye Transfer in Dual Quad SPI Mode
0xEB instruction, instruction 1 bit/cycle; address, mode, data 4 bits/cycle
spi_select[0]
spi_select[1]
0 7 8 13 14 15 16 19 20 21
spi_clk
4 dummy
instruction (0xeb) 24 bit address
mode cycles 8-bit data
spi_data[0] 20 16 12 0 4 0 0 0
spi_data[1] 21 17 13 1 5 1 1 1
spi_data[2] 22 18 14 2 6 2 2 2
spi_data[3] 23 19 15 3 7 3 3 3
spi_data[4] 20 16 12 0 4 0 4 4
spi_data[5] 21 17 13 1 5 1 5 5
spi_data[6] 22 18 14 2 6 2 6 6
spi_data[7] 23 19 15 3 7 3 7 7
29.4 Triggers
The SMIF has two level-sensitive triggers:
■ tr_tx_req is associated with the Tx data FIFO.
■ tr_rx_req is associated with the Rx data FIFO.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 390
Serial Memory Interface (SMIF)
If the SMIF is enabled (CTL.ENABLED is ‘1’) and Command operation mode is selected (CTL.XIP_MODE is ‘0’), the trigger
functionality is enabled. If the SMIF is disabled (CTL.ENABLED is ‘0’) or the XIP operation mode is selected (CTL.XIP_MODE
is ‘1’), the triggers functionality is disabled. The trigger functionality is defined as follows:
■ The MMIO TX_DATA_FIFO_CTL.TRIGGER_LEVEL field specifies a number of FIFO entries. The tr_tx_req trigger is
active when the number of used Tx data FIFO entries is smaller or equal than the specified number; that is,
TX_DATA_FIFO_STATUS.USED TRIGGER_LEVEL.
■ The MMIO RX_DATA_FIFO_CTL.TRIGGER_LEVEL field specifies a number of FIFO entries. The tr_rx_req trigger is
active when the number of used Rx data FIFO entries is greater than the specified number; that is,
RX_DATA_FIFO_STATUS.USED > TRIGGER_LEVEL.
29.5 Interrupts
The SMIF has a single interrupt output with six interrupt causes:
■ INTR.TR_TX_REQ. This interrupt cause is activated in Command mode when the tr_tx_req trigger is activated.
■ INTR.TR_RX_REQ. This interrupt cause is activated in Command mode when the tr_rx_req trigger is activated.
■ INTR.XIP_ALIGNMENT_ERROR. This interrupt cause is activated in XIP mode when the selected device’s
ADDR_CTL.DIV2 field is ‘1’ and the AHB-Lite bus address is not a multiple of 2, or the requested transfer size is not a
multiple of 2. This interrupt cause identifies erroneous behavior in dual-quad SPI mode (the selected device
ADDR_CTL.DIV2 field is set to ‘1’).
■ INTR.TX_CMD_FIFO_OVERFLOW. This interrupt cause is activated in Command mode, on an AHB-Lite write transfer to
the Tx command FIFO (TX_CMD_FIFO_WR) with insufficient free entries.
■ INTR.TX_DATA_FIFO_OVERFLOW. This interrupt cause is activated in Command mode, on an AHB-Lite write transfer
to the Tx data FIFO (TX_DATA_FIFO_WR1, TX_DATA_FIFO_WR2, and TX_DATA_FIFO_WR4) with insufficient free
entries.
■ INTR.RX_DATA_FIFO_OVERFLOW. This interrupt cause is activated in Command mode, on an AHB-Lite read transfer
from the Rx data FIFO (RX_DATA_FIFO_RD1, RX_DATA_FIFO_RD2, and RX_DATA_FIFO_RD4) with insufficient free
entries.
29.7 Performance
Accesses to the external memory will have some latency, which is dependent upon the mode of SMIF operation, the amount
of data being transferred, caching, and cryptography. In Command mode, the number of interface clock cycles per transfer is
determined by the equation:
For example, in Figure 29-14, the equation to calculate the number of cycles would be (22 cycles = [8 bit instruction/1 single
width] + [24 bit address/4 width] + [8 bit mode/4 width] + 4 dummy cycles + [16 bit data/8 width]).
In XIP Mode, the performance is affected by the cache. For data reads that hit in the cache, the read will not incur any
interface cycles. Read operations that miss in the cache will occur as a normal SMIF read operation and, if prefetching is
enabled, will result in two 16 B cache sub-sector refills. Writes to external memory in XIP mode will occur as a normal SMIF
write operation.
Enabling cryptography may impact SMIF performance. The AES-128 block cipher has a typical latency of 13 clk_hf cycles.
This means that for transfers that take more than 13 cycles, the on-the-fly decryption does not add any delay. If the transfer is
less than 13 cycles, the transfer latency will be 13 cycles. When the cache is enabled, the 13-cycle latency for encryption is
incurred only once for every 16 B fetched for the cache.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 391
30. Timer, Counter, and PWM (TCPWM)
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The Timer, Counter, Pulse Width Modulator (TCPWM) block in the PSoC 6 MCU uses a 16- or 32-bit counter, which can be
configured as a timer, counter, pulse width modulator (PWM), or quadrature decoder. The block can be used to measure the
period and pulse width of an input signal (timer), find the number of times a particular event occurs (counter), generate PWM
signals, or decode quadrature signals. This chapter explains the features, implementation, and operational modes of the
TCPWM block.
30.1 Features
■ The TCPWM block supports the following operational modes:
❐ Timer-counter with compare
❐ Timer-counter with capture
❐ Quadrature decoding
❐ Pulse width modulation
❐ Pseudo-random PWM
❐ PWM with dead time
■ Up, Down, and Up/Down counting modes.
■ Clock prescaling (division by 1, 2, 4, ... 64, 128)
■ 16- or 32-bit counter widths
■ Double buffering of compare/capture and period values
■ Underflow, overflow, and capture/compare output signals
■ Supports interrupt on:
❐ Terminal count – Depends on the mode; typically occurs on overflow or underflow
❐ Capture/compare – The count is captured to the capture register or the counter value equals the value in the compare
register
■ Complementary output for PWMs
■ Selectable start, reload, stop, count, and capture event signals (events refer to peripheral generated signals that trigger
specific functions in each counter in the TCPWM block) for each TCPWM – with rising edge, falling edge, both edges, and
level trigger options
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 392
Timer, Counter, and PWM (TCPWM)
30.2 Architecture
Figure 30-1. TCPWM Block Diagram
1
C o u n te r i 2 ...
i
Synchronization
T rig g e r in p u ts
Trigger
E ve n t C o n fig u ra tio n
16 1 6-b it o r 3 2-b it co u n te r
G e n e ra tio n re g iste rs
3
co u n te r_ e n 2 pwm ,
u n d e rflo w , in te rru p t pwm _n
F o r e a ch o ve rflo w ,
C o u n te r i cc_ m a tch (ca p tu re o r co m p a re )
The TCPWM block can contain up to 32 counters. Each counter can be 16- or 32-bit wide. The three main registers that
control the counters are:
■ TCPWM_CNT_CC is used to capture the counter value in CAPTURE mode. In all other modes this value is compared to
the counter value.
■ TCPWM_CNT_COUNTER holds the current counter value.
■ TCPWM_CNT_PERIOD holds the upper value of the counter. When the counter counts for n cycles, this field should be
set to n–1.
The number of 16- and 32-bit counters are device specific; refer to the PSoC 61 datasheet/PSoC 62 datasheet for details.
In this chapter, a TCPWM refers to the entire block and all the counters inside. A counter refers to the individual counter
inside the TCPWM. Within a TCPWM block the width of each counter is the same.
TCPWM has these interfaces:
■ I/O signal interface: Consists of input triggers (such as reload, start, stop, count, and capture) and output signals (such as
pwm, pwm_n, overflow (OV), underflow (UN), and capture/compare (CC)). All of these input signals are used to trigger an
event within the counter, such as a reload trigger generating a reload event. The output signals are generated by internal
events (underflow, overflow, and capture/compare) and can be connected to other peripherals to trigger events.
■ Interrupts: Provides interrupt request signals from each counter, based on TC or CC conditions.
The TCPWM block can be configured by writing to the TCPWM registers. See “TCPWM Registers” on page 428 for more
information on all registers required for this block.
30.2.2 Clocking
Each TCPWM counter can have its own clock source and the only source for the clock is from the configurable peripheral
clock dividers generated by the clocking system; see the Clocking System chapter on page 242 for details. To select a clock
divider for a particular counter inside a TCPWM, use the CLOCK_CTL register from the PERI register space.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 393
Timer, Counter, and PWM (TCPWM)
In this section the clock to the counter will be called clk_counter. Event generation is performed on clk_counter. Another clock,
clk_sys is used for the pulse width of the output triggers. clk_sys is synchronous to clk_peri (see “CLK_PERI” on page 253),
but can be divided using CLOCK_CTL from the PERI_GROUP_STRUCT register space.
Note: The count event and pre-scaled counter clock are AND together, which means that a count event must occur to
generate an active count pre-scaled counter clock.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 394
Timer, Counter, and PWM (TCPWM)
If stop, reload, and start coincide, the following precedence relationship holds:
■ A stop has higher priority than a reload.
■ A reload has higher priority that a start.
As a result, when a reload or start coincides with a stop, the reload or start has no effect.
Before going to the counter each Trigger_IN can pass through a positive edge detector, negative edge detector, both edge
detector, or pass straight through to the counter. This is controlled using TCPWM_CNT_TR_CTRL1. In the quadrature mode,
edge detection is done using clk_counter. For all other modes, edge detection is done using the clk_peri.
Multiple detected events are treated as follows:
■ In the rising edge and falling edge modes, multiple events are effectively reduced to a single event. As a result, events
may be lost (see Figure 30-3).
■ In the rising/falling edge mode, an even number of events are not detected and an odd number of events are reduced to a
single event. This is because the rising/falling edge mode is typically used for capture events to determine the width of a
pulse. The current functionality will ensure that the alternating pattern of rising and falling is maintained (see Figure 30-4).
Figure 30-3. Multiple Rising Edge Capture
MODE = CAPTURE
UP_DOWN_MODE = COUNT_UP
CAPTURE_EDGE = RISING_EDGE Missed capture event
reload
capture
1 CC_BUFF
1 3 CC
4 PERIOD = 4
COUNTER
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
CC_MATCH
capture
CC_BUFF
3 CC
4 PERIOD = 4
COUNTER
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 395
Timer, Counter, and PWM (TCPWM)
1 Rising or Falling
edge detect 2 event
Trigger_In[14]
No edge detect 3
TCPWM_CMD registers
(software generated)
TCPWM_CNT_TR_CTRL0
TCPWM_CNT_TR_CTRL1
Notes:
■ All trigger inputs are synchronized to clk_peri.
■ When more than one event occurs in the same clk_counter period, one or more events may be missed. This can happen
for high-frequency events (frequencies close to the counter frequency) and a timer configuration in which a pre-scaled
(divided) clk_counter is used.
30.2.5 Interrupts
The TCPWM block provides a dedicated interrupt output for each counter. This interrupt can be generated for a terminal
count (TC) or CC event. A TC is the logical OR of the OV and UN events.
Four registers are used to handle interrupts in this block, as shown in Table 30-1.
TCPWM_CNT_INTR_MASK 0 TC Mask bit for the corresponding TC bit in the interrupt request register.
(Interrupt mask register) 1 CC_MATCH Mask bit for the corresponding CC_MATCH bit in the interrupt request register.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 396
Timer, Counter, and PWM (TCPWM)
3 No change
0 Set pwm to '1
3 No change
0 Set pwm to '1
3 No change
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 397
Timer, Counter, and PWM (TCPWM)
The counter can be configured to count up, down, and up/down by setting the UP_DOWN_MODE[17:16] field in the
TCPWM_CNT_CTRL register, as shown in Table 30-5.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 398
Timer, Counter, and PWM (TCPWM)
Incrementing and decrementing the counter is controlled by the count event and the counter clock clk_counter. Typical
operation will use a constant ‘1’ count event and clk_counter without pre-scaling. Advanced operations are also possible; for
example, the counter event configuration can decide to count the rising edges of a synchronized input trigger.
Auto reload CC CC and CC_BUFF are exchanged on a cc_match event (when specified by CTRL.AUTO_RELOAD_CC)
Specified by UP_DOWN_MODE:
■ COUNT_UP: The counter counts from 0 to PERIOD.
Up/down modes
■ COUNT_DOWN: The counter counts from PERIOD to 0.
■ COUNT_UPDN1/2: The counter counts from 1 to PERIOD and back to 0.
Table 30-6 lists the trigger outputs and the conditions when they are triggered.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 399
Timer, Counter, and PWM (TCPWM)
Note: Each output is only two clk_sys wide and is represented by an arrow in the timing diagrams in this chapter, for example
see Figure 30-7.
cc_match (CC) Counter changes from a state in which COUNTER equals CC.
Timer Interrupt
tc interrupt
Reload generation
Start PERIOD
cc_match tr_cc_match
Stop == Trigger
underflow tr_underflow
Count generation
COUNTER overflow tr_overflow
==
CC
clk_counter
CC_BUFF
Notes:
■ The timer functionality uses only PERIOD (and not PERIOD_BUFF).
■ Do not write to COUNTER when the counter is running.
Figure 30-7 illustrates a timer in up-counting mode. The counter is initialized (to 0) and started with a software-based reload
event.
Notes:
■ PERIOD is 4, resulting in an effective repeating counter pattern of 4+1 = 5 clk_counter periods. The CC register is 2, and
sets the condition for a cc_match event.
■ When the counter changes from a state in which COUNTER is 4, overflow and tc events are generated.
■ When the counter changes from a state in which COUNTER is 2, a cc_match event is generated.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 400
Timer, Counter, and PWM (TCPWM)
■ A constant count event of ‘1’ and clk_counter without prescaling is used in the following scenarios. If the count event is ‘0’
and a reload event is triggered, the reload will be registered only on the first clock edge when the count event is ‘1’. This
means that the first clock edge when the count event is ‘1’ will not be used for counting. It will be used for reload.
Figure 30-7. Timer in Up-counting Mode
MODE = TIMER
UP_DOWN_MODE = COUNT_UP COUNTER starts with 0 period is PERIOD+1
reload
4 PERIOD = 4
COUNTER
2 CC = 2
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
no TC event CC event on leaving the
COUNTER value
Figure 30-8 illustrates a timer in “one-shot” operation mode. Note that the counter is stopped on a tc event.
Figure 30-8. Timer in One-shot Mode
MODE = TIMER
UP_DOWN_MODE = COUNT_UP
ONE_SHOT = 1
reload
4 PERIOD = 4
COUNTER
2 CC = 2
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
Figure 30-9 illustrates clock pre-scaling. Note that the counter is only incremented every other counter cycle.
Figure 30-9. Timer Clock Pre-scaling
MODE = TIMER
UP_DOWN_MODE = COUNT_UP
ONE_SHOT = 1
PRESCALE = DIV_BY_2
reload
4 PERIOD = 4
COUNTER
2 CC = 2
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
Figure 30-10 illustrates a counter that is initialized and started (reload event), stopped (stop event), and continued/started
(start event). Note that the counter does not change value when it is not running (STATUS.RUNNING).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 401
Timer, Counter, and PWM (TCPWM)
reload
stop
start
4 PERIOD = 4
COUNTER
3
2 CC = 2
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
RUNNING
Figure 30-11 illustrates a timer that uses both CC and CC_BUFF registers. Note that CC and CC_BUFF are exchanged on a
cc_match event.
Figure 30-11. Use of CC and CC_BUFF Register Bits
MODE = TIMER
UP_DOWN_MODE = COUNT_UP
AUTO_RELOAD_CC = 1
0 3 0 3 0 3 0 3 0 3 CC_BUFF
reload 3 0 3 0 3 0 3 0 3 0 CC
4 PERIOD = 4
COUNTER
Underflow (UV)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
Figure 30-12 illustrates a timer in down counting mode. The counter is initialized (to PERIOD) and started with a software-
based reload event.
Notes:
■ When the counter changes from a state in which COUNTER is 0, a UN and TC events are generated.
■ When the counter changes from a state in which COUNTER is 2, a cc_match event is generated.
■ PERIOD is 4, resulting in an effective repeating counter pattern of 4+1 = 5 counter clock periods.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 402
Timer, Counter, and PWM (TCPWM)
reload
4 PERIOD = 4
COUNTER
3
2 CC = 2
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
no TC event CC event on leaving the
COUNTER value
Figure 30-13 illustrates a timer in up/down counting mode 1. The counter is initialized (to 1) and started with a software-based
reload event.
Notes:
■ When the counter changes from a state in which COUNTER is 4, an overflow is generated.
■ When the counter changes from a state in which COUNTER is 0, an underflow and tc event are generated.
■ When the counter changes from a state in which COUNTER is 2, a cc_match event is generated.
■ PERIOD is 4, resulting in an effective repeating counter pattern of 2*4 = 8 counter clock periods.
Figure 30-13. Timer in Up/Down Counting Mode 1
MODE = TIMER
UP_DOWN_MODE = COUNT_UPDN1 COUNTER starts with 1 period is 2*PERIOD
reload
4 PERIOD = 4
COUNTER
2 CC = 2
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
no TC event CC event on leaving the
COUNTER value
Figure 30-14 illustrates a timer in up/down counting mode 1, with different CC values.
Notes:
■ When CC is 0, the cc_match event is generated at the start of the period (when the counter changes from a state in which
COUNTER is 0).
■ When CC is PERIOD, the cc_match event is generated at the middle of the period (when the counter changes from a
state in which COUNTER is PERIOD).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 403
Timer, Counter, and PWM (TCPWM)
reload 1 0 4 CC
4 PERIOD = 4
COUNTER
3
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
cc_matchﺴevent at the
start of the period
Figure 30-15 illustrates a timer in up/down counting mode 2. This mode is same as up/down counting mode 1, except for the
TC event, which is generated when either underflow or overflow event occurs.
Figure 30-15. Up/Down Counting Mode 2
MODE = TIMER
UP_DOWN_MODE = COUNT_UPDN2 COUNTER starts with 1 period is 2*PERIOD
reload
4 PERIOD = 4
COUNTER
2 CC = 2
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
no TC event CC event on leaving the
COUNTER value
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 404
Timer, Counter, and PWM (TCPWM)
Specified by UP_DOWN_MODE:
■ COUNT_UP: The counter counts from 0 to PERIOD.
Up/down modes
■ COUNT_DOWN: The counter counts from PERIOD to 0.
■ COUNT_UPDN1/2: The counter counts from 1 to PERIOD and back to 0.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 405
Timer, Counter, and PWM (TCPWM)
cc_match (CC) CC is copied to CC_BUFF and counter value is copied to CC (cc_match equals capture event).
==
CC
clk_counter
CC_BUFF
capture
1 4 CC_BUFF
1 4 3 CC
4 PERIOD = 4
COUNTER
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 406
Timer, Counter, and PWM (TCPWM)
When multiple capture events are detected before the next “active count” pre-scaled counter clock, capture events are
treated as follows:
■ In the rising edge and falling edge modes, multiple events are effectively reduced to a single event.
■ In the rising/falling edge mode, an even number of events is not detected and an odd number of events is reduced to a
single event.
This behavior is illustrated by Figure 30-18, in which a pre-scaler by a factor of 4 is used.
Figure 30-18. Multiple Events Detected before Active-Count
MODE = CAPTURE
UP_DOWN_MODE = COUNT_UP
CAPTURE_EDGE = RISING_EDGE missed capture event
reload
capture
1 CC_BUFF
1 3 CC
4 PERIOD = 4
COUNTER
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 407
Timer, Counter, and PWM (TCPWM)
Note: Clock pre-scaling is not supported and the count event is used as a quadrature input phiA. As a result, the quadrature
functionality operates on the counter clock (clk_counter), rather than on an “active count” prescaled counter clock.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 408
Timer, Counter, and PWM (TCPWM)
clk_counter 0xFFFF
CC_BUFF
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 409
Timer, Counter, and PWM (TCPWM)
phiA
phiB
Quadrature decoding
QUADRATURE_MODE = X1
incr1
decr1
Quadrature decoding
QUADRATURE_MODE = X2
Two times the events of X1 mode
incr1
decr1
Quadrature decoding
QUADRATURE_MODE = X4
Four times the events of X1 mode
incr1
decr1
Figure 30-21 illustrates quadrature functionality as a function of the reload/index, incr1, and decr1 events. Note that the first
reload/index event copies the counter value COUNTER to CC.
Figure 30-21. Quadrature Mode Reload/Index Timing
Quadrature decoding
increment behavior, no coinciding counter cycle overflow with incr1 event overflow without incr1 event
reload and increment events
Reload / Index
incr1
decr1
COUNTER X 0x8000 0x8001 0x8002 0x8003 0xFFFE 0xFFFF 0x8001 0xFFFE 0xFFFF 0x8000
CC_BUFF Z Y Y X X 0xFFFF
tc
cc_match
RUNNING
Figure 30-22 illustrate quadrature functionality for different event scenarios (including scenarios with coinciding events). In all
scenarios, the first reload/index event is generated by software when the counter is not yet running.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 410
Timer, Counter, and PWM (TCPWM)
Reload / Index
incr1
decr1
COUNTER X 0x8000 0x7FFFF 0x7ffe 0x7ffd 0x0001 0x0000 0x7FFF 0x0001 0x0000 0x8000
CC_BUFF Z Y Y X X 0x0000
tc
cc_match
RUNNING
Quadrature decoding
decrement/increment behavior, no counter cycle underflow with incr1 event overflow with decr1 event
coinciding reload events
Reload / Index
incr1
decr1
COUNTER X 0x8000 0x7FFF 0x7FFE 0x7FFD 0x0001 0x0000 0x8001 0xFFFE 0xFFFF 0x7FFF
CC_BUFF Z Y Y X X 0x0000
tc
cc_match
RUNNING
Quadrature decoding
counter cycle reload event and reload event and
decrement/increment behavior,
underflow with decr1 event overflow with incr1 event
coinciding reload events
Reload / Index
incr1
decr1
COUNTER X 0x8000 0x7FFF 0x7FFE 0x7FFD 0x0001 0x0000 0x7FFF 0xFFFE 0xFFFF 0x8001
CC_BUFF Z Y Y X X 0x0000
tc
cc_match
RUNNING
Reload / Index
incr1
decr1
COUNTER X 0x8000 0x7FFF 0x7FFE 0x7FFF 0x7FFE 0x7FFD 0x8000 0x7FFF 0x7FFE 0x7FFD
CC Y X 0x7FFE 0x7FFD
CC_BUFF Z Y Y 0x7FFE
tc
cc_match
RUNNING
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 411
Timer, Counter, and PWM (TCPWM)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 412
Timer, Counter, and PWM (TCPWM)
CC and CC_BUFF are exchanged on a swap event and tc event (when specified by CTRL.AUTO_RE-
Compare Swap
LOAD_CC).
PERIOD and PERIOD_BUFF are exchanged on a swap event and tc event (when specified by
CTRL.AUTO_RELOAD_PERIOD). Note: When COUNT_UPDN2/Asymmetric mode exchanges PERIOD
Period Swap
and PERIOD_BUFF at a tc event that coincides with an overflow event, software should ensure that the
PERIOD and PERIOD_BUFF values are the same.
Specified by UP_DOWN_MODE:
■ COUNT_UP: The counter counts from 0 to PERIOD. Generates a left-aligned PWM output.
Alignment (Up/Down modes) ■ COUNT_DOWN: The counter counts from PERIOD to 0. Generates a right-aligned PWM output.
■ COUNT_UPDN1/2: The counter counts from 1 to PERIOD and back to 0. Generates a center-aligned/
asymmetric PWM output.
Specified by PWM_STOP_ON_KILL and PWM_SYNC_KILL:
■ PWM_STOP_ON_KILL = ‘1’ (PWM_SYNC_KILL = don’t care): Stop on Kill mode. This mode
stops the counter on a stop/kill event. Reload or start event is required to restart counting.
■ PWM_STOP_ON_KILL = ‘0’ and PWM_SYNC_KILL = ‘0’: Asynchronous kill mode. This
Kill modes mode keeps the counter running, but suppresses the PWM output signals and continues to
do so for the duration of the stop/kill event.
■ PWM_STOP_ON_KILL = ‘0’ and PWM_SYNC_KILL = ‘1’: Synchronous kill mode. This mode
keeps the counter running, but suppresses the PWM output signals and continues to do so
until the next tc event without a stop/kill event.
Note that the PWM mode does not support dead time insertion. This functionality is supported by the separate PWM_DT
mode.
Underflow (UN) Counter is decrementing and changes from a state in which COUNTER equals “0”.
Overflow (OV) Counter is incrementing and changes from a state in which COUNTER equals PERIOD.
Specified by UP_DOWN_MODE:
cc_match (CC) ■ COUNT_UP and COUNT_DOWN: The counter changes to a state in which COUNTER equals CC.
■ COUNT_UPDN1/2: counter changes from a state in which COUNTER equals CC.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 413
Timer, Counter, and PWM (TCPWM)
Note that the cc_match event generation in COUNT_UP and COUNT_DOWN modes are different from the generation in
other functional modes or counting modes. This is to ensure that 0 percent and 100 percent duty cycles can be generated.
Figure 30-23. PWM Mode Functionality
PWM
tc Interrupt
Reload interrupt
PERIOD_BUFF generation
Start
Stop/Kill
Count
Capture/Swap PERIOD
cc_match tr_cc_match
== Trigger
underflow tr_underflow
generation
COUNTER overflow tr_overflow
clk_counter == PWM
pwm_dt_input
generation
CC
The generation of PWM output signals is a multi-step process and is illustrated in Figure 30-24. The PWM output signals are
generated by using the underflow, overflow, and cc_match events. Each of these events can be individually set to INVERT,
SET, or CLEAR pwm_dt_input.
Note: An underflow and cc_match or an overflow and cc_match can occur at the same time. When this happens, underflow
and overflow events take priority over cc_match. For example, if overflow = SET and cc_match = CLEAR then pwm_dt_input
will be SET to ‘1’ first and then CLEARED to ‘0’ immediately after. This can be seen in Figure 30-26.
Figure 30-24. PWM Output Generation
pwm polarity
pwm
underflow PWM Dead time
overflow generation pwm_dt_input insertion kill period
cc_match
pwm_n
pwm_n polarity
only supported in
TCPWM_CNT_TR_CTRL2 PWM_DT mode
PWM polarity and PWM_n polarity as seen in Figure 30-24, allow the PWM outputs to be inverted. PWM polarity is controlled
through CTRL.QUADRATURE_MODE[0] and PWM_n polarity is controlled through CTRL.QUADRATURE_MODE[1].
PWM behavior depends on the PERIOD and CC registers. The software can update the PERIOD_BUFF and CC_BUFF
registers, without affecting the PWM behavior. This is the main rationale for double buffering these registers.
Figure 30-25 illustrates a PWM in up counting mode. The counter is initialized (to 0) and started with a software-based reload
event.
Notes:
■ When the counter changes from a state in which COUNTER is 4, an overflow and tc event are generated.
■ When the counter changes to a state in which COUNTER is 2, a cc_match event is generated.
■ PERIOD is 4, resulting in an effective repeating counter pattern of 4+1 = 5 counter clock periods.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 414
Timer, Counter, and PWM (TCPWM)
reload
4 PERIOD = 4
COUNTER
3
2 CC = 2
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
no tc event cc_match event on entering
the COUNTER value
Figure 30-26 illustrates a PWM in up counting mode generating a left-aligned PWM. The figure also illustrates how a right-
aligned PWM can be created using the PWM in up counting mode by inverting the OVERFLOW_MODE and
CC_MATCH_MODE and using a CC value that is complementary (PERIOD+1 - pulse width) to the one used for left-aligned
PWM. Note that CC is changed (to CC_BUFF, which is not depicted) on a tc event. The duty cycle is controlled by setting the
CC value. CC = desired duty cycle x (PERIOD+1).
Figure 30-26. PWM Left- and Right-Aligned Outputs
MODE = PWM
UP_DOWN_MODE = COUNT_UP
1 0 2 4 5 CC
reload
4 PERIOD = 4
COUNTER
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
pwm
pwm
Figure 30-27 illustrates a PWM in down counting mode. The counter is initialized (to PERIOD) and started with a software-
based reload event.
Notes:
■ When the counter changes from a state in which COUNTER is 0, an underflow and tc event are generated.
■ When the counter changes to a state in which COUNTER is 2, a cc_match event is generated.
■ PERIOD is 4, resulting in an effective repeating counter pattern of 4+1 = 5 counter clock periods.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 415
Timer, Counter, and PWM (TCPWM)
reload
4 PERIOD = 4
COUNTER
3
2 CC = 2
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
no tc event cc_match event on entering
the COUNTER value
Figure 30-28 illustrates a PWM in down counting mode with different CC values. The figure also illustrates how a right-aligned
PWM can be creating using the PWM in down counting mode. Note that the CC is changed (to CC_BUFF, which is not
depicted) on a tc event.
Figure 30-28. Right- and Left-Aligned Down Counting PWM
MODE = PWM
UP_DOWN_MODE = COUNT_DOWN
reload 1 0 2 4 -1 / 0xFFFF CC
4 PERIOD = 4
COUNTER
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
pwm
Left aligned PWM
CC = PERIOD - pulse width
UNDERFLOW_MODE = SET
CC_MATCH_MODE = CLEAR
pwm
Figure 30-29 illustrates a PWM in up/down counting mode. The counter is initialized (to 1) and started with a software-based
reload event.
Notes:
■ When the counter changes from a state in which COUNTER is 4, an overflow is generated.
■ When the counter changes from a state in which COUNTER is 0, an underflow and tc event are generated.
■ When the counter changes from a state in which COUNTER is 2, a cc_match event is generated. Note that the actual
counter value COUNTER from before the reload event is NOT used, instead the counter value before the reload event is
considered to be 0.
■ PERIOD is 4, resulting in an effective repeating counter pattern of 2*4 = 8 counter clock periods.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 416
Timer, Counter, and PWM (TCPWM)
reload
4 PERIOD = 4
COUNTER
3
2 CC = 2
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
no tc event cc_match event on leaving
the COUNTER value
Figure 30-30 illustrates a PWM in up/down counting mode with different CC values. The figure also illustrates how a center-
aligned PWM can be creating using the PWM in up/down counting mode.
Note:
■ The actual counter value COUNTER from before the reload event is NOT used. Instead the counter value before the
reload event is considered to be 0. As a result, when the first CC value at the reload event is 0, a cc_match event is
generated.
■ CC is changed (to CC_BUFF, which is not depicted) on a tc event.
Figure 30-30. Up/Down Counting Center-Aligned PWM
MODE = PWM
UP_DOWN_MODE = COUNT_UPDN1
0 1 3 4 CC
reload
4 PERIOD = 4
COUNTER
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
cc_match event at the overflow and cc_match
start of the period events coincide
Center aligned PWM
CC = PERIOD – pulse width/2
UNDERFLOW_MODE = CLEAR
OVERFLOW_MODE = SET
CC_MATCH_MODE = INVERT
pwm
Different stop/kill modes exist. The mode is specified by PWM_STOP_ON_KILL and PWM_SYNC_KILL.
The following three modes are supported:
■ PWM_STOP_ON_KILL is ‘1’ (PWM_SYNC_KILL is don’t care): Stop on Kill mode. This mode stops the counter on a stop/
kill event. Reload or start event is required to restart the counter. Both software and external trigger input can be selected
as stop kill. Edge detection mode is required.
■ PWM_STOP_ON_KILL is ‘0’ and PWM_SYNC_KILL is ‘0’: Asynchronous Kill mode. This mode keeps the counter
running, but suppresses the PWM output signals synchronously on the next count clock (“active count” pre-scaled
clk_counter) and continues to do so for the duration of the stop/kill event. Only the external trigger input can be selected
as asynchronous kill. Pass through detection mode is required.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 417
Timer, Counter, and PWM (TCPWM)
■ PWM_STOP_ON_KILL is ‘0’ and PWM_SYNC_KILL is ‘1’: Synchronous Kill mode. This mode keeps the counter running,
but suppresses the PWM output signals synchronously on the next count clock (“active count” pre-scaled clk_counter)
and continues to do so until the next tc event without a stop/kill event. Only the external trigger input can be selected as
synchronous kill. Rising edge detection mode is required.
Figure 30-31, Figure 30-32. and Figure 30-33 illustrate the above three modes.
Figure 30-31. PWM Stop on Kill
Right aligned PWM
PWM_STOP_ON_KILL = 1 pwm and pwm_n set to programmed
STOP_EDGE = RISING_EDGE kill event stops counter
polarity
pwm polarity = 0, pwm_n polarity = 0
tc
cc_match
pwm_dt_input
kill
pwm
pwm_n
tc
cc_match
pwm_dt_input
kill
pwm
pwm_n
tc
cc_match
pwm_dt_input
kill
pwm
pwm_n
kill event disappears, but kill period
kill event detected (rising edge) kill period ends at next tc
extended
Figure 30-34 illustrates center-aligned PWM with PERIOD/PERIOD_BUFF and CC/CC_BUFF registers (up/down counting
mode 1). At the TC condition, the PERIOD and CC registers are automatically exchanged with the PERIOD_BUFF and
CC_BUFF registers. The swap event is generated by hardware trigger 1, which is a constant ‘1’ and therefore always active
at the TC condition. After the hardware exchange, the software handler on the tc interrupt updates PERIOD_BUFF and
CC_BUFF.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 418
Timer, Counter, and PWM (TCPWM)
SW update SW update
4 0 1 4 3 CC_BUFF
0 4 1 CC
5 4 3 5 3 PERIOD_BUFF
reload 4 5 3 PERIOD
5
4
COUNTER
3
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
upcounting and CC = 0
=> cc_matchҸevent at
underflow
Asymmetric PWM
CC = PERIOD – pulse width/2
UNDERFLOW_MODE = CLEAR
OVERFLOW_MODE = SET
CC_MATCH_MODE = INVERT
pwm
The PERIOD swaps with PERIOD_BUFF on a terminal count. The CC swaps with CC_BUFF on a terminal count. Software
can then update PERIOD_BUFF and CC_BUFF so that on the next terminal count PERIOD and CC will be updated with the
values written into PERIOD_BUFF and CC_BUFF.
A potential problem arises when software updates are not completed before the next tc event with an active pending swap
event. For example, if software updates PERIOD_BUFF before the tc event and CC_BUFF after the tc event, swapping does
not reflect the CC_BUFF register update. To prevent this from happening, the swap event should be generated by software
through a register write after both the PERIOD_BUFF and CC_BUFF registers are updated. The swap event is kept pending
by the hardware until the next tc event occurs.
The previous section addressed synchronized updates of the CC/CC_BUFF and PERIOD/PERIOD_BUFF registers of a
single PWM using a software-generated swap event. During motor control, three PWMs work in unison and updates to all
period and compare register pairs should be synchronized. All three PWMs have synchronized periods and as a result have
synchronized tc events. The swap event for all three PWMs is generated by software through a single register write. The
software should generate the swap events after the PERIOD_BUFF and CC_BUFF registers of all three PWMs are updated.
Note: When the counter is not running ((temporarily) stopped or killed), the PWM output signal values are determined by their
respective polarity settings. When the counter is disabled the output values are low.
Figure 30-35. PWM Outputs When Killed
Right aligned PWM
PWM_STOP_ON_KILL = 0, PWM_SYNC_KILL = 0
STOP_EDGE = NO_EDGE_DET
pwm polarity = 0, pwm_n polarity = 0
tc
cc_match
pwm_dt_input
kill
pwm
pwm_n
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 419
Timer, Counter, and PWM (TCPWM)
3 1 3 1 3 1 CC_BUFF
reload 1 3 1 3 1 3 CC
4 PERIOD = 4
COUNTER
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
Asymmetric PWM
CC = PERIOD – pulse width/2
UNDERFLOW_MODE = CLEAR
OVERFLOW_MODE = SET
CC_MATCH_MODE = INVERT
pwm
The previous waveform illustrated functionality when the CC values are neither “0” nor PERIOD. Corner case conditions in
which the CC values equal “0” or PERIOD are illustrated as follows.
Figure 30-37 illustrates how the COUNT_UPDN2 mode is used to generate an asymmetric PWM.
Notes:
■ When up counting, when CC value at the underflow event is 0, a cc_match event is generated.
■ When down counting, when CC value at the overflow event is PERIOD, a cc_match event is generated.
■ A tc event is generated for both an underflow and overflow event. The tc event is used to exchange the CC and CC_BUFF
values.
■ Software updates CC_BUFF and PERIOD_BUFF in an interrupt handler on the tc event (and overwrites the hardware
updated values from the CC/CC_BUFF and PERIOD/PERIOD_BUFF exchanges).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 420
Timer, Counter, and PWM (TCPWM)
4 COUNTER
3
Underflow (UN)
Overflow (OV)
Terminal Count (TC)
Compare/Capture (CC)
Asymmetric PWM
CC = PERIOD – pulse width/2
UNDERFLOW_MODE = CLEAR
OVERFLOW_MODE = SET
CC_MATCH_MODE = INVERT
pwm
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 421
Timer, Counter, and PWM (TCPWM)
PWM
Reload tc Interrupt
interrupt
Start PERIOD_BUFF generation
Stop/Kill
Count
Capture/Swap PERIOD
cc_match tr_cc_match
== Trigger
underflow tr_underflow
generation
COUNTER overflow tr_overflow
clk_counter == PWM
pwm_dt_input
CC generation
no clock pre-scaling
CC_BUFF
pwm polarity
pwm
underflow PWM Dead time
overflow generation pwm_dt_input insertion kill period
cc_match
pwm_n
pwm_n polarity
only supported in
TCPWM_CNT_TR_CTRL2 PWM_DT mode
Dead time insertion is a step that operates on a preliminary PWM output signal pwm_dt_input, as illustrated in Figure 30-38.
Figure 30-39 illustrates dead time insertion for different dead times and different output signal polarity settings.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 422
Timer, Counter, and PWM (TCPWM)
pwm_dt_input
MODE = PWM_DT
dead time = 0
pwm polarity = 0
pwm_n polarity = 0
pwm
pwm_n
MODE = PWM_DT
dead time = 1
pwm polarity = 0 dead time: 1
pwm_n polarity = 0
pwm
pwm_n
MODE = PWM_DT
dead time = 2
pwm polarity = 0 dead time: 2
pwm_n polarity = 0 pulse is gone
pwm
pwm_n
MODE = PWM_DT
dead time = 2
pwm polarity = 1 dead time: 2
pwm_n polarity = 1
pwm
pwm_n
Figure 30-40 illustrates how the polarity settings and stop/kill functionality combined control the PWM output signals “pwm”
and “pwm_n”.
Figure 30-40. Dead Time and Kill
Right aligned PWM
PWM_STOP_ON_KILL = 0, PWM_SYNC_KILL = 0
STOP_EDGE = NO_EDGE_DET dead time: 1
dead time = 1
pwm polarity = 0, pwm_n polarity = 1
reload
tc
cc_match
pwm_dt_input
kill
pwm
pwm_n
RUNNING
counter not running counter temporarily killed
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 423
Timer, Counter, and PWM (TCPWM)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 424
Timer, Counter, and PWM (TCPWM)
Note: The count event is not used. As a result, the PWM_PR functionality operates on the pre-scaled counter clock
(clk_counter), rather than on an “active count” pre-scaled counter clock.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 425
Timer, Counter, and PWM (TCPWM)
PWM_PR Interrupt
tc interrupt
Reload generation
PERIOD_BUFF
Start
Stop/Kill Trigger
cc_match tr_cc_match
Capture/Swap generation
PERIOD
==
pwm polarity
COUNTER pwm
CC_BUFF
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 426
Timer, Counter, and PWM (TCPWM)
Note that the LFSR produces a deterministic number sequence (given a specific counter initialization value). Therefore, it is
possible to calculate the COUNTER value after a certain number of LFSR iterations, n. This calculated COUNTER value can
be used as PERIOD value, and the tc event will be generated after precisely n counter clocks.
Figure 30-42 illustrates PWM_PR functionality.
Notes:
■ The grey shaded areas represent the counter region in which the pwm_dt_input value is ‘1’, for a CC value of 0x4000.
There are two areas, because only the lower 15 bits of the counter value are used.
■ When CC is set to 0x4000, roughly one-half of the counter clocks will result in a pwm_dt_input value of ‘1’.
Figure 30-42. PWM_PR Output
MODE = PWM_PR COUNTER is exactly
0xe771
reload
0xFFFF
PERIOD = 0xe771
COUNTER
CC = 0x4000
tc
cc_match
pwm_dt_input
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 427
Timer, Counter, and PWM (TCPWM)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 428
31. Inter-IC Sound Bus
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The Inter-IC Sound Bus (I2S) is a serial bus interface standard used to connect digital audio devices together. The
specification is from Philips® Semiconductor (I2S bus specification: February 1986, revised June 5, 1996). In addition to the
standard I2S format, the I2S block also supports the Left Justified (LJ) format and the Time Division Multiplexed (TDM) format.
31.1 Features
■ Supports standard Philips I2S, LJ, and eight-channel TDM digital audio interface formats
■ Supports both master and slave mode operation in all the digital audio formats
■ Supports independent operation of Receive (Rx) and Transmit (Tx) directions
■ Supports operating from an external master clock provided through an external IC such as audio codec
■ Provides configurable clock divider registers to generate the required sample rates
■ Supports data word length of 8-bit, 16-bit, 18-bit, 20-bit, 24-bit, and 32-bit per channel
■ Supports channel length of 8-bit, 16-bit, 18-bit, 20-bit, 24-bit, and 32-bit per channel (channel length fixed at 32-bit in TDM
format)
■ Provides two hardware FIFO buffers, one each for the Tx block and Rx block, respectively
■ Supports both DMA- and CPU-based data transfers
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 429
Inter-IC Sound Bus
31.2 Architecture
Figure 31-1. I2S Block Diagram
PSoC 6 MCU
Data Wire/
CPU DMA SRAM
AHB bus
clk_i2s_if
I2S tx_sck
TX tx_ws
External IC
tx_sdo (for example, Audio
Codec, I2S Microphones)
I2S rx_sck
RX rx_ws
rx_sdi
I2S
Audio subsystem
Figure 31-1 shows the high-level block diagram of the I2S block, which consists of two sub-blocks – I2S Transmitter (Tx) and
I2S Receiver (Rx). The digital audio interface format and master/slave mode configuration can be done independently for the
Tx and Rx blocks. In the master mode, the word select (ws) and serial data clock (sck) are generated by the I2S block in the
PSoC 6 MCU. In the slave mode, the ws and sck signals are inputs signals to the PSoC 6 MCU, and are generated by the
external master device. The I2S block configuration, control, and status registers, along with the FIFO data buffers are
accessible through the AHB bus. AHB bus masters such as CPU and DMA can access the I2S registers through the AHB
interface. Refer to the PSoC 61 datasheet/PSoC 62 datasheet for information on port pin assignments of the I2S block signals
and AC/DC electrical specifications.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 430
Inter-IC Sound Bus
and the I2S Rx block reads the data (rx_sdi) on the rising edge of rx_sck. The serial data is transmitted most significant bit
(MSb) first. Depending on whether the block is in master or slave mode, the ws/sck signals are either generated by the block
(master mode) or input signals to the block (slave mode).
The I2S block supports configurable word length and channel length selection options. The word length for the Tx and Rx
blocks can be configured using the WORD_LEN bits in the I2S_TX_CTL and I2S_RX_CTL registers, respectively. The
channel length for the Tx and Rx blocks can be configured using the CH_LEN bits in the I2S_TX_CTL and I2S_RX_CTL
registers respectively. The channel length configuration should always be greater than or equal to the word length
configuration. Ensure that when the I2S Rx block is operated in slave mode, the master Tx device ensures that its channel
length configuration aligns with the I2S Rx block channel length setting. If there is channel length mismatch, the PSoC I2S Rx
block in slave mode will not operate correctly.
In the Tx block, when the channel length is greater than the word length, the unused bits can be transmitted either as ‘0’ or ‘1’.
This selection is made using the OVHDATA bit in the I2S_TX_CTL register. In the Rx block, when the word length is less than
32 bits, the unused most significant bits written to the 32-bit Rx FIFO register can either be set to ‘0’ or sign bit extended. This
selection is made using the BIT_EXTENSION bit in the I2S_RX_CTL register.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 431
Inter-IC Sound Bus
Figure 31-2. Standard I2S Format (Word Length and Channel Length Combination Timing Diagrams)
(1) Channel Length = 32-bits
Left Channel Right Channel
(Channel Length = 32-bit) (Channel Length = 32-bit)
SCK ~ ~ ~ ~ ~ ~ ~ ~
WS ~ ~ ~ ~ ~ ~ ~ ~
WS ~ ~ ~ ~ ~ ~
WS ~ ~
WS
Table 31-1 lists the supported word length and channel length combinations.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 432
Inter-IC Sound Bus
Apart from these differences, all the features explained in the standard I2S format section apply to the LJ format as well.
Figure 31-3. Left Justified Digital Audio Format
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 433
Inter-IC Sound Bus
■ The pulse width of the word select (WS) signal in the TDM format can be configured to be either one bit clock (sck) wide
or one channel wide. The selection is made using the WS_PULSE bit in the I2S_TX_CTL and I2S_RX_CTL registers. The
pulse width is fixed to one channel width in the I2S/LJ format.
■ Two types of TDM formats are supported. In TDM mode A, the WS rising edge signal to signify the start of frame coincides
with the start of CH0 data. In TDM mode B, the WS rising edge signal to signify the start of frame is one bit clock (sck)
early, relative to the start of CH0 data (coincides with the last bit of the previous frame). The selection between the two
TDM formats is made using the I2S_MODE bits in the I2S_TX_CTL and I2S_RX_CTL registers.
Figure 31-4. TDM Digital Audio Interface Format
TDM mode A format
Frame
(Frame Length = 256-bits)
Channel
(Channel Length = 32-bits)
SCK ~ ~ ~ ~ ~
Frame
(Frame Length = 256-bits)
Channel
(Channel Length = 32-bits)
SCK ~ ~ ~ ~ ~
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 434
Inter-IC Sound Bus
2
IS I2 S
tx_sck tx_sck
2
I2 S IS
tx_ws tx_ws Transmitter
Transmitter
(Slave) (Slave)
codec_rx_sdi tx_sdo codec_rx_sdi tx_sdo
Codec Codec
(Tx Slave, (Tx Master,
Rx Slave) codec_sck rx_sck Rx Master) codec_sck rx_sck
Figure 31-6 shows the clocking divider structure in the I2S block. In the master mode, the sck and ws signals are generated
either using the clk_audio_i2s internal clock or the clk_i2s_if external clock. Refer to the PSoC 61 datasheet/PSoC 62
datasheet for the port pin assignment of clk_i2s_if clock. The CLOCK_SEL bit in the I2S_CLOCK_CTL register controls the
selection between internal and external clocks.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 435
Inter-IC Sound Bus
CLOCK_SEL bit in
I2S_CLOCK_CTL register
There are two stages of clock dividers in the I2S block as follows.
■ The first stage clock divider is used to generate the internal I2S master clock (MCLK_SOC). The input clock to the first
stage divider is either clk_audio_i2s or clk_i2s_if. The first stage clock divider is configured using the CLOCK_DIV bits in
I2S_CLOCK_CTL register. Divider values from 1 to 64 are supported.
■ The second stage clock divider is used to generate the sck signals. The input clock is the output from the first stage clock
divider. This divider value is fixed at ‘8’ (FTX_SCK = FRX_SCK = FMCLK_SOC/8). The word select (ws) signal frequency
depends on the sck frequency, and the configured channel length value.
When in slave mode, the internal clock (MCLK_SOC) frequency should still be eight times the frequency of the input serial
clock. You must choose the appropriate clock source and the CLOCK_DIV divider value to guarantee this condition is met in
the slave mode of operation. Usually, when the PSoC I2S block operates in the slave mode, the host sends a master clock
which is an integral multiple of the sampling rate. This master clock can be routed to the clk_i2s_if port pin. The CLOCK_DIV
divider value can then be adjusted to ensure that the MCLK_SOC is eight times the input SCK frequency.
Table 31-3 gives an example of the clock divider settings for operating the I2S block at the standard sampling rates in the
standard I2S format. Note that the first stage divider values in the table are the register field values – the actual divider values
are one more than the configured register values as explained in the clock divider section. Refer to the PSoC 61 datasheet/
PSoC 62 datasheet for details on maximum values of SCK frequency, and the output sampling rates.
Table 31-3. I2S Divider Values for Standard Audio Sampling Rates in Standard I2S Format
SCK CLK_HF1 (CLK_HF[1])/SCK Second Stage
Sampling Rate WORD_LEN CLK_CLOCK_DIV
(2*WORD_LEN*SR) (or clk_i2s_if) (Total Divider Divider
(SR) (kHz) (bits) (First Divider)
(MHz) (MHz) Ratio) (Fixed at 8)
8 32 0.512 96 11
16 32 1.024 48 5
49.152
32 32 2.048 24 2 8
48 32 3.072 16 1
44.1 32 2.8224 45.1584 32 3
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 436
Inter-IC Sound Bus
31.7 FIFO Buffer and DMA pointers. This register can be used for debug purposes. The
I2S Tx FIFO read pointer is updated whenever the data is
Support transferred from the Tx FIFO to the internal transmit buffer.
Tx FIFO write pointer is updated whenever the data is
The I2S block has two FIFO buffers - one each for the Tx written to the I2S_TX_FIFO_WR register, either through the
block and Rx block, respectively. The ordering format of the CPU or the DMA controller.
channel data in both Tx and Rx FIFOs depends on the
configured digital audio format. This ordering format should For Tx FIFO data writes using the CPU, the hardware can
be considered when writing to the Tx FIFO or reading from be used to trigger an interrupt event for any of the FIFO
the Rx FIFO. In the standard I2S and LJ digital audio conditions such as TX_TRIGGER, TX_NOT_FULL, and
formats, the ordering of the data is (L, R, L, R, L, ...) where L TX_EMPTY. As part of the interrupt handler, the CPU can
refers to the left channel data and R refers to the right write to the I2S_TX_FIFO_WR register. The recommended
channel data. In the TDM format with the number of active method is to write (256 - TRIGGER_LEVEL) words to the
channels set to four, the data order will be (CH0, CH1, CH2, I2S_TX_FIFO_WR register every time the TX_TRIGGER
CH3, CH0, CH1, CH2, CH3, CH0, .....). If the number of interrupt event is triggered. In addition, interrupt events can
active channels is set to eight, the cycle will repeat after be generated for FIFO overflow/underflow conditions.
CH0–CH7 data.
For DMA-based Tx data transfers, the I2S Tx DMA trigger
I2S Tx FIFO: The I2S Tx block has a hardware FIFO of signal (tr_i2s_tx_req) can be enabled by writing ‘1’ to the
depth 256 elements where each element is 32-bit wide. In TX_REQ_EN bit in I2S_TR_CTL register. The trigger signal
addition to this 256-element FIFO, the I2S block has an output will become high whenever the Tx FIFO has less
internal transmit buffer that can store four 32-bit data to be entries than that configured in the TRIGGER_LEVEL field.
transmitted. This four-element buffer is used as an The DMA channel can be configured to transfer up to (256 -
intermediary to hold data to be transferred on the I2S bus, TRIGGER_LEVEL) words from the applicable source
and is not exposed to the AHB BUS interface. address (such as Flash and SRAM regions). The destination
address of the DMA should always be the
The TX FIFO can be paused by setting the TX_PAUSE bit in I2S_TX_FIFO_WR register address, with the destination
I2S_CMD. When the TX_PAUSE bit is set, the data sent address increment feature disabled in the DMA channel
over I2S is “0”, instead of TX FIFO data. To resume normal configuration. This FIFO address increment logic is handled
operation, the TX_PAUSE bit must be cleared. internally to adjust the write pointer, and the DMA should not
The I2S_TX_FIFO_CTL register is used for FIFO control increment the destination address. For more details on DMA
operations. The TRIGGER_LEVEL bits in the channel configuration, refer to the DMA Controller
I2S_TX_FIFO_CTL register can be used to generate a (DW) chapter on page 91.
transmit trigger event when the Tx FIFO has less entries The data in the I2S_TX_FIFO is always right-aligned. The
than the value configured in the TRIGGER_LEVEL bits. I2S_TX_FIFO_WR format for different word length
The FIFO freeze operation can be enabled by setting the configurations is provided in Figure 31-7.
FREEZE bit in the I2S_TX_FIFO_CTL register. When the
FREEZE bit is set and the Tx block is operational
(TX_START bit in I2S_CMD is set), hardware reads from the
Tx FIFO do not remove the FIFO entries. Also, the Tx FIFO
read pointer will not be advanced. Any writes to the
I2S_TX_FIFO register will increment the Tx FIFO write
pointer; when the Tx FIFO becomes full, the internal write
pointer stops incrementing. The freeze operation may be
used for firmware debug purposes. This operation is not
intended for normal operation. To return to normal operation
after using the freeze operation, the I2S must be reset by
clearing the TX_ENABLED bit in the I2S_CTL register, and
then setting the bit again.
The CLEAR bit in the I2S_TX_FIFO_CTL register is used to
clear the Tx FIFO by resetting the read/write pointers
associated with the FIFO. Write accesses to the Tx FIFO
using the I2S_TX_FIFO_WR or I2S_TX_FIFO_WR_SILENT
registers are not allowed while the CLEAR bit is set.
The I2S_TX_FIFO_STATUS register provides FIFO status
information. This includes number of used entries in the Tx
FIFO and the current values of the Tx FIFO read/write
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 437
Inter-IC Sound Bus
I2S Rx FIFO: The I2S Rx block has a hardware FIFO of from the I2S_RX_FIFO_RD register, either through the CPU
depth 256 elements where each element is 32-bit wide. In or the DMA controller. For debug purposes, the
addition to this 256-element FIFO, the I2S block has an I2S_RX_FIFO_RD_SILENT register is available, which
internal receive buffer that can store four 32-bit data to be always returns the top element of the Rx FIFO without
received. This four-element buffer is used as an updating the read pointer.
intermediary to hold data received on the I2S bus, and is not
For Rx FIFO data reads using the CPU, the hardware can
exposed to the AHB BUS interface.
be used to trigger an interrupt event for any of the FIFO
The I2S_RX_FIFO_CTL register is used for FIFO control conditions such as RX_TRIGGER, RX_NOT_EMPTY, and
operations. The TRIGGER_LEVEL bits in the RX_FULL. As part of the interrupt handler, the CPU can
I2S_RX_FIFO_CTL register is used to generate a receive read from the I2S_RX_FIFO_RD register. The
trigger event when the Rx FIFO has more entries than the recommended method is to read (TRIGGER_LEVEL + 1)
value configured in the TRIGGER_LEVEL bits. In the words from the I2S_RX_FIFO_RD register every time the
standard I2S/LJ format, the TRIGGER_LEVEL bits can be RX_TRIGGER interrupt event is triggered. In addition,
configured up to the allowed maximum value of 253. In the interrupt events can be generated for FIFO overflow/
TDM format, the maximum value of TRIGGER_LEVEL is underflow conditions.
[254–CH_NR) where CH_NR is the number of active
For DMA-based Rx data transfers, the I2S Rx DMA trigger
channels in the TDM frame.
signal (tr_i2s_rx_req) can be enabled by writing ‘1’ to the
The FIFO freeze operation can be enabled by setting the RX_REQ_EN bit in the I2S_TR_CTL register. The trigger
FREEZE bit in the I2S_RX_FIFO_CTL register. When the signal output will become high whenever the Rx FIFO has
FREEZE bit is set and the Rx block is operational more entries than that configured in the TRIGGER_LEVEL
(RX_START bit in the I2S_CMD register is set), hardware field. The DMA channel can be configured to transfer up to
will not write to the Rx FIFO. Also, the Rx FIFO write pointer (TRIGGER_LEVEL + 1) words to the applicable destination
will not be advanced. Any reads from the I2S_RX_FIFO address (such as SRAM regions). The source address of
register will increment the Rx FIFO read pointer; when the the DMA should always be the I2S_RX_FIFO_RD register
Rx FIFO becomes empty, the internal read pointer stops address, with the source address increment feature
incrementing. The freeze operation may be used for disabled in the DMA channel configuration. This FIFO
firmware debug purposes. This operation is not intended for address increment logic is handled internally to adjust the
normal operation. To return to normal operation after using read pointer, and the DMA should not increment the source
the freeze operation, the I2S must be reset by clearing the address. For more details on DMA channel configuration,
RX_ENABLED bit in the I2S_CTL register and then setting refer to the DMA Controller (DW) chapter on page 91.
the bit again.
The data in the I2S_RX_FIFO is always right aligned. The
The CLEAR bit in I2S_RX_FIFO_CTL register is used to I2S_RX_FIFO_RD format for different word length
clear the Rx FIFO by resetting the read/write pointers configurations is provided in Figure 31-8. Note that the
associated with the FIFO. Read accesses from the Rx FIFO unused most significant bits are either set as ‘0’ or sign-bit
using the I2S_RX_FIFO_RD or I2S_RX_FIFO_RD_SILENT extended depending on the BIT_EXTENSION bit in the
registers are not allowed while the CLEAR bit is set. I2S_RX_CTL register.
The I2S_RX_FIFO_STATUS register provides FIFO status
information. This includes number of used entries in the Rx
FIFO and the current values of the Rx FIFO read/write
pointers. This register can be used for debug purposes. The
I2S Rx FIFO write pointer is updated whenever the data is
transferred to the Rx FIFO from the internal receive buffer.
Rx FIFO read pointer is updated whenever the data is read
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 438
Inter-IC Sound Bus
Bit extension "1" "1" "1" "1" "1" "1" "1" "1" "1" 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
"0" "0" "0" "0" "0" "0" "0" "0" "0" 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MSb LSb
Word Length = 20-bit mode
not Bit extension fixed "0" 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Bit extension "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
"0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MSb LSb
Word Length = 18-bit mode
not Bit extension fixed "0" 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Bit extension "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
"0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MSb LSb
Word Length = 16-bit mode
not Bit extension fixed "0" 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Bit extension "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
"0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
In the interrupt service routine (ISR), the I2S_INTR_MASKED register should be read to know the events that triggered the
interrupt event. Multiple events can trigger the interrupt because the final interrupt signal is the logical OR output of the
events. The ISR should do the tasks corresponding to each interrupt event that was triggered. At the end of the ISR, the value
read in the I2S_INTR_MASKED register earlier should be written to the I2S_INTR register to clear the bits whose interrupt
events were processed in the ISR. Unless the bits are not cleared by writing ‘1’ to the I2S_INTR register, the interrupt signal
will always be high. A dummy read of the I2S_INTR register should be done for the earlier register write to take effect.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 439
Inter-IC Sound Bus
Timer Value
0
time Interrupt event
Interrupt event of the
cleared in software
wachdog occurs
Interrupt Event (TX_WD)
(or RX_WD)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 440
32. PDM-PCM Converter
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PDM-PCM unit accepts a stereo or mono serial data stream (pulse modulated 1-bit stream) coming from external digital
PDM microphones. The PDM-PCM converter consists of a fifth order cascaded integrator comb (CIC) filter followed by a
decimator, and a final stage high-pass filter. This block simplifies the conversion process by exposing the different
configuration settings as registers, which you can program to meet the application needs. The entire PDM-PCM conversion
process is handled in hardware; the PCM output data streaming can be done using the DMA controller thus freeing up the
CPU bandwidth from performing periodic audio streaming activities.
32.1 Features
■ Supports Mono/Stereo mode pulse density modulation (PDM) to pulse code modulation (PCM) conversion
■ Accepts 1-bit PDM input and can generate 16-, 18-, 20-, or 24-bit PCM digital data output
■ Configurable PDM microphone clock frequency
■ Ability to generate standard audio sampling rates by adjusting the decimation rate and clock divider values
■ Digital volume control: Programmable gain amplifier (PGA) control from –12 dB to +10.5 dB in 1.5-dB steps
■ Smooth PGA and soft-mute control
■ Hardware receive buffer: 24-bit wide, 255-element FIFO with support for DMA controller-based data transfer
■ Optional high-pass filter to remove DC and low-frequency noise
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 441
PDM-PCM Converter
32.2 Architecture
Figure 32-1. Block Diagram
PSoC
AHB bus
clk
data PDM Microphone
(Right)
L/R Select GND
Figure 32-1 shows the block diagram of the PDM-PCM converter. Refer to the PSoC 61 datasheet/PSoC 62 datasheet for
information on port pin assignments of the PDM block signals, electrical specifications, and the interrupt vector number.
Figure 32-2 shows the clock divider structure in the block. The block has three stages of clock dividers to generate the clock
(PDM_CKO), which goes to the external PDM microphone clock input.
1. The first stage clock divider (CLK_CLOCK_DIV field in the PDM_CLOCK_CTL register) is used to generate the actual
clock signal (PDM_CLK) that goes to the PDM-PCM converter. The input is CLK_HF[1]; the CLK_CLOCK_DIV can be a
value between 0 and 3 (divider value between 1 and 4).
fPDM_CLK = fCLK-HF[1] / (CLK_CLOCK_DIV + 1)
2. The second stage clock divider (MCLKQ_CLOCK_DIV field in the PDM_CLOCK_CTL register) is used to generate the
internal master clock and can take a value between 0 and 3 (divider value between 1 and 4). The input clock is pdm_clk
and the output of the divider is MCLKQ.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 442
PDM-PCM Converter
Table 32-1 gives an example of the PDM clock divider and SINC_RATE register configurations to generate the PCM output at
standard sampling rates. Note that the PDM divider values in the table are the register field values – the actual divider values
are one more than the configured register values as explained in the clock divider section. Refer to the PSoC 61 datasheet/
PSoC 62 datasheet for details on maximum values of PDM_CKO frequency, PDM_CLK frequency, and the output sampling
rates.
Table 32-1. PDM Clock Divider Values for Standard Audio Sampling Rates
(CLK_HF[1])/ MCLKQ_CLOCK
Sampling PDM_CKO CKO_CLOCK_
SINC_RATE CLK_HF1 (PDM_CKO) CLK_CLOCK_DIV _DIV
Rate (SR) (=2*SINC_RATE*SR) DIV
(= OSR/2) (MHz) (Total Divider (First Divider) (Second
(kHz) (MHz) (Third Divider)
Ratio) Divider)
8 32 0.512 96 1 3 11
16 32 1.024 48 1 3 5
49.152
32 32 2.048 24 0 3 5
48 32 3.072 16 0 1 7
44.1 32 2.8224 45.1584 32 0 1 7
There are various methods to generate the CLK_HF[1] register settings for the different operation modes are given
frequencies listed in the table depending on the clocking in Table 32-2. The table also lists the invalid register
options available on the device. Refer to the Clocking settings, which you must not use in the firmware.
System chapter on page 242 for details on the clocking
options available in the device, including the clock sources
and PLL/FLL circuitry. For example, an external crystal
oscillator (ECO) can be used in conjunction with a phase-
locked loop (PLL) to generate the CLK_HF[1] at the desired
frequency of 49.152 MHz or 45.1584 MHz.
One possible combination of PLL divider values to generate
the 49.152 MHz frequency from a 17.2032 MHz ECO are:
REFERENCE_DIV = 7, FEEDBACK_DIV = 100,
OUTPUT_DIV = 5. One possible combination of PLL divider
values to generate the 45.1584 MHz frequency from a
17.2032 MHz ECO are: REFERENCE_DIV = 8,
FEEDBACK_DIV = 105, OUTPUT_DIV = 5.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 443
PDM-PCM Converter
Figure 32-3 shows the timing diagrams for the different operating modes.
Figure 32-3. PDM Mono/Stereo Timing
Mono left mode (PCM_CH_SET = 1, SWAP_LR = 0)
PDM_CKO
PDM_DATA L L L
PDM_CKO
PDM_DATA R R R
PDM_CKO
PDM_DATA L R L R L R
PDM_CKO
PDM_DATA R L R L R L
To alleviate uncertain board delay impact on PDM_IN setup different PDM microphone manufacturers. The SWAP_LR
and hold timing constraints, the PDM-PCM provides bit in the PDM-PCM converter ensures that you can adjust
CKO_DELAY bits in the PDM_MODE_CTL register to add the sampling logic according to the microphone datasheet
extra delay for the PDM_CKO path to internal sampler. recommendations. Refer to the PDM microphone
CKO_DELAY can be a value between 0 and 7. A value of ‘0’ manufacturer datasheet for the exact timing details. Also, in
implies that internal sampling of PDM data is advanced by stereo mode, use the same manufacturer for both the left/
three PDM_CLK clock cycles for the PDM_CKO transition. right PDM microphones to ensure the timing behavior is
A value of ‘7’ implies that internal sampling of PDM data is uniform for both channels.
delayed by four PDM_CLK clock cycles for the PDM_CKO
transition. Refer to the registers TRM for details on the
meaning of different CKO_DELAY values.
Note: Variations have been observed in the
recommendation for left/right sampling logic among the
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 444
PDM-PCM Converter
32.2.5 Hardware FIFO Buffers and DMA For DMA-based data transfers, the DMA trigger signal
(tr_pdm_rx_req) can be enabled by writing ‘1’ to the
Controller Support RX_REQ_EN bit in the PDM_TR_CTL register. The trigger
The PDM-PCM converter has a hardware FIFO depth of signal output will become high whenever the Rx FIFO has
255 elements where each element is 24-bit wide. more entries than that configured in the TRIGGER_LEVEL
field. Refer to the Trigger Multiplexer Block chapter on
The PDM_RX_FIFO_CTL register is used for FIFO control page 294 for details on how to connect the DMA trigger
operations. Refer to the register description in the registers signal to a particular DMA channel. The DMA channel can
TRM for more details. The TRIGGER_LEVEL field in the be configured to transfer up to (TRIGGER_LEVEL + 1)
PDM_RX_FIFO_CTL register is used to generate a receive words to the applicable destination address (such as SRAM
trigger event (interrupt event, DMA trigger signal) when the regions). The source address of the DMA should always be
Rx FIFO has more entries than the value configured in the the PDM_RX_FIFO_RD register address, with the source
TRIGGER_LEVEL field. The TRIGGER_LEVEL field can be address increment feature disabled in the DMA channel
configured up to 254 in the mono microphone recording configuration. This FIFO address increment logic is handled
mode and up to 253 in the stereo microphone recording internally to adjust the read pointer, and the DMA should not
mode. increment the source address. For more details on DMA
The FIFO freeze operation can be enabled by setting the channel configuration, refer to the DMA Controller
FREEZE bit in the PDM_RX_FIFO_CTL register. When the (DW) chapter on page 91.
FREEZE bit is set and the Rx block is operational The successive data read from the PDM_RX_FIFO_RD
(STREAM_EN bit in the PDM_CMD register is set), follows the Left 1/Right 1/Left 2/Right 2/… format in stereo
hardware will not write to the Rx FIFO. Also, the Rx FIFO and swapped stereo modes of operation. For mono left and
write pointer will not be advanced. Any reads from the mono right recording modes, the data read from FIFO
PDM_RX_FIFO_RD register will increment the Rx FIFO contains either the left channel data (mono left mode) or the
read pointer; when the Rx FIFO becomes empty, the internal right channel data (mono right mode).
read pointer stops incrementing. The freeze operation may
be used for firmware debug purposes. This operation is not The data in the PDM_RX_FIFO_RD is always right-aligned.
intended for normal operation. To return to normal operation The PDM_TX_FIFO_RD format for different word length
after using the freeze operation, the PDM-PCM must be configurations is provided in Figure 32-4. Note that the
reset by clearing the ENABLED bit in PDM_CTL register, unused most significant bits are either set as ‘0’ or sign-bit
and then setting the bit again. extended depending on the BIT_EXTENSION field setting in
the PDM_DATA_CTL register.
The CLEAR bit in the PDM_RX_FIFO_CTL register is used
to clear the Rx FIFO by resetting the read/write pointers
associated with the FIFO. Read accesses from the Rx FIFO
using PDM_RX_FIFO_RD or PDM_RX_FIFO_RD_SILENT
registers are not allowed while the CLEAR bit is set.
The PDM_RX_FIFO_STATUS register provides FIFO status
information. This includes number of used entries in the Rx
FIFO and the current values of the Rx FIFO read/write
pointers. This register can be used for debug purposes. The
Rx FIFO write pointer is updated whenever the data is
transferred to the Rx FIFO from the internal receive buffer.
Rx FIFO read pointer is updated whenever the data is read
from the PDM_RX_FIFO_RD register, either through the
CPU or the DMA controller. For debug purposes, the
PDM_RX_FIFO_RD_SILENT register is available, which
always returns the top element of the Rx FIFO without
updating the read pointer.
For Rx FIFO data reads using the CPU, the hardware can
be used to trigger an interrupt event for any of the FIFO
conditions such as RX_TRIGGER and RX_NOT_EMPTY.
As part of the interrupt handler, the CPU can read from the
PDM_RX_FIFO_RD register. The recommended method is
to read (TRIGGER_LEVEL + 1) words from the
PDM_RX_FIFO_RD register every time the RX_TRIGGER
interrupt event is triggered. In addition, interrupt events can
be generated for FIFO overflow and underflow conditions.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 445
PDM-PCM Converter
BIT_EXTENSION = 1 "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
(Sign Bit Extension) "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Each of the interrupt events can be individually enabled or disabled to generate the interrupt condition. The
PDM_INTR_MASK register is used to enable the required events by writing ‘1’ to the corresponding bit.
Irrespective of the INTR_MASK settings, if any event occurs, the corresponding event status bit will be set by the hardware in
the PDM_INTR register. The PDM_INTR_MASKED register is the bitwise AND of the PDM_INTR_MASK and PDM_INTR
registers. The final PDM interrupt signal is the logical OR of all the bits in the PDM_INTR_MASKED register. So only those
events that are enabled in the PDM_INTR_MASK register are propagated as interrupt events to the interrupt controller.
Interrupt events can also be triggered in software by writing to the corresponding bits in PDM_INTR_SET register.
Figure 32-5 illustrates the interrupt signal generation from the PDM-PCM block as explained above. Only the RX_TRIGGER
interrupt generation is highlighted in the figure; the remaining interrupt events also follow the same generation logic.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 446
PDM-PCM Converter
In the interrupt service routine (ISR) corresponding to the configured to a value between 64 sample periods and 512
interrupt vector number of interrupt_pdm, the sample periods using the S_CYCLES bits in the
PDM_INTR_MASKED register should be read to know the PDM_MODE_CTL register. So the STEP_SEL and
events that triggered the interrupt event. Multiple events can S_CYCLES bit settings together determine the rate at which
trigger the interrupt because the final interrupt signal is the PGA gain or the soft mute transitions take effect.
logical OR output of the events. The ISR should do the tasks
corresponding to each interrupt event that was triggered. At 32.2.9 Soft Mute
the end of the ISR, the value read in the
PDM_INTR_MASKED register earlier should be written to The PDM-PCM contains a built-in software-controlled mute
the PDM_INTR register to clear the bits whose interrupt function that digitally attenuates signals to imperceptible
events were processed in the ISR. A dummy read of the levels or zero. When mute function is enabled by setting the
PDM_INTR register should be done for the earlier register SOFT_MUTE bit in the PDM_CTL register, the
write to PDM_INTR to take effect. corresponding PCM output is decreased from current level
to mute state through predefined granular gain step per time
All of the interrupt event bits in PDM_INTR register will constant transition. The STEP_SEL bit setting determines
continue to indicate the event condition regardless of the the gain step and the S_CYCLES bits determine the time
true state until that bit is cleared (for example, when set, the constant. During soft-mute, the block is still ON and the
RX_OVERFLOW bit will continue to indicate an PCM data streaming is operational; the DMA or CPU-based
OVERFLOW state until the RX_OVERFLOW bit is cleared data transfer also happens as usual. Only the PCM output
regardless of the true state of the FIFO. A mere FIFO read level is muted. When mute function is disabled by setting
of the FIFO will not clear the RX_OVERFLOW bit.). Unless SOFT_MUTE = 0, the mute function is OFF and the PDM-
the PDM_INTR bits that are used to generate the interrupt PCM returns to normal operation where output signal level
are not cleared by writing ‘1’ to the PDM_INTR bits, the goes up to normal with current PGA gain.
interrupt signal will always be high.
32.2.10 Word Length and Sign Bit
32.2.7 Digital Volume Gain
Extension
The PDM-PCM converter supports independent digital
volume control on the left/right channels with a range from – The PCM output word length can be configured for either
12.5 dB to +10.5 dB in steps of 1.5 dB. It is programmed by 16-bits, 18-bits, 20-bits, or 24-bits using WORD_LEN bits in
configuring the PGA_R and PGA_L bits in the PDM_CTL the PDM_DATA_CTL register. Irrespective of the word
register. PGA gain may be changed on the fly during normal length setting, the PCM output is always read from the FIFO
operation, or as a one-time setting before starting the PDM- data buffer register (PDM_RX_FIFO_RD) as a 32-bit value.
PCM conversion process. The unused most significant bits in the 32-bit value can
either be sign extended or extended by ‘0’ by using the
BIT_EXTENSION bit in the PDM_DATA_CTL register.
32.2.8 Smooth Gain Transition
To reduce zipper or clip noise during on-the-fly gain 32.2.11 High-Pass Filter
transition or during soft mute operation, a built-in volume
smoother is implemented with fine gain steps and fine time The PDM-PCM converter has a final stage high-pass filter
steps that enable soft ramp up or ramp down of the volume (HPF) that blocks DC offset and low-frequency noise in
levels. Two fine gain options of 0.13 dB and 0.26 dB step signal band. The HPF is enabled when the HPF_EN_N bit in
sizes are available. The fine gain is set by the STEP_SEL the PDM_MODE_CTL register is zero, and disabled when
bit in the PDM_CTL register. In addition to the fine gain the HPF_EN_N bit is 1.
steps, a time step is available for the fine gain change in
terms of the number of sample cycles. The time step can be
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 447
PDM-PCM Converter
The filter response for HPF is characterized as: 4. Configure the Rx FIFO trigger level setting by writing to
–1 the TRIGGER_LEVEL bits in the PDM_RX_FIFO_CTL
1–z register. The CLEAR and FREEZE bits in PDM_RX_FI-
H z = -----------------------------------------------------------
– HPF_GAIN – 1
-
1 – 1 – 2 z FO_CTL are not set for normal operation.
5. Configure the events that must generate the interrupt by
The HPF operates at the final PCM output sampling rate.
setting the corresponding bits in the PDM_INTR_MASK
HPF_GAIN is a 4-bit gain configuration setting in the
register, and clearing the remaining bits.
PDM_MODE_CTL register. In default mode, HPF_GAIN =
0xB, so the HPF can be formulated by polynomial: 6. Configure the interrupt PDM interrupt vector and enable
the interrupt vector. See the Interrupts chapter on
–1
1–z page 56 for details.
H z = -----------------------------------
–1
-
1 – 0.99951z 7. If a DMA-based data transfer is required, connect the
PDM DMA trigger signal (tr_pdm_rx_req) to the trigger
The HPF_GAIN setting can be tuned to adjust HPF cutoff input of the required DMA channel. See the Trigger Mul-
corner frequency for better system configuration. tiplexer Block chapter on page 294 for details on how to
connect to the DMA channel trigger input. Configure the
32.2.12 Enable/Disable Streaming DMA channel as required - the source address of the
DMA descriptor is PDM_RX_FIFO_RD register with the
The PDM-PCM conversion process can be dynamically source address increment feature disabled and the
enabled/disabled by using the STREAM_EN bit in the source data length is word type (32-bits). The DMA
PDM_CMD register. channel can be used to transfer (TRIGGER_LEVEL + 1)
words from the PDM_RX_FIFO_RD register whenever
32.2.13 Power Modes the trigger signal becomes high. The destination address
configuration depends on the application requirements.
The PDM-PCM can operate in Active and Sleep CPU See the DMA Controller (DW) chapter on page 91 for
modes while in LP or ULP system power modes. It is not details on DMA channel configuration.
operational in system Deep Sleep or Hibernate power
modes. When the device transitions from Deep Sleep/ 8. Enable the DMA trigger signal generation by setting the
Hibernate power modes to the LP/ULP power modes, the RX_REQ_EN bit in the PDM_TR_CTL register.
non-retention registers lose their previous configuration
values. So the non-retention registers must be appropriately 32.3.2 Interrupt Service Routine (ISR)
configured before enabling the PDM-PCM again for LP/ULP Configuration
mode operation. One option is to store the non-retention
register values in SRAM before entering Deep Sleep/ The code for the PDM interrupt service routine should have
Hibernate modes. When returning to the LP/ULP modes, the the following flow:
SRAM values can be copied to the registers after enabling 1. The events that triggered the interrupt can be found by
the PDM-PCM by setting the ENABLED bit in the PDM_CTL reading the PDM_INTR_MASKED register in the ISR. All
register. Refer to the registers TRM to identify the non- the bits that are set causes the interrupt event. The reg-
retention registers for the PDM. ister value should also be in a variable “var”.
2. For each of the event bits that are set in PDM_IN-
32.3 Operating Procedure TR_MASKED, appropriate application level tasks can be
executed. For example, the RX_TRIGGER event can be
used for CPU-based data transfers if a DMA-based data
32.3.1 Initial Configuration transfer is not used. DMA transfers should use the tr_pd-
m_rx_req trigger signal (by setting the RX_REQ_EN bit
The sequence of steps for initial configuration of the PDM-
in the PDM_TR_CTL register). The DMA trigger should
PCM converter before starting the conversion process is as
not use the RX_TRIGGER interrupt event to reduce
follows:
CPU usage for data transfer. The RX_OVERFLOW
1. Configure the clock dividers and decimation rate in the event can be used to take appropriate counter measures
PDM_CLOCK_CTL register. This register configuration such as giving higher priority to PDM-PCM DMA chan-
should be done before enabling the PDM-PCM con- nel. The RX_UNDERFLOW event typically indicates
verter. If the ENABLED bit in the PDM_CTL register is wrong data transfer logic in the application – either in the
set, it should be cleared before changing the clock con- CPU-based data transfer code or in the DMA channel
figuration. configuration used to transfer data.
2. Enable the block; set the PGA gain and fine gain step 3. After the event conditions have been processed, the
setting as required by writing to the PDM_CTL register. “var” value read from PDM_INTR_MASKED should be
3. Configure the PDM_MODE_CTL and PDM_DATA_CTL written to the PDM_INTR register to clear the events that
registers as required. are set in the register. Due to the buffered write logic, the
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 448
PDM-PCM Converter
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 449
33. Universal Serial Bus (USB) Device Mode
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC 6 MCU USB block can act as a USB device that communicates with a USB host. The USB block is available as a
fixed-function digital block in the PSoC 6 MCU. It supports full-speed communication (12 Mbps) and is designed to be compli-
ant with the USB Specification Revision 2.0. USB devices can be designed for plug-and-play applications with the host and
also support hot swapping. This chapter details the PSoC 6 MCU USB block and transfer modes. For details about the USB
specification, see the USB Implementers Forum website.
33.1 Features
The USB in the PSoC 6 MCU has the following features:
■ Complies with USB Specification 2.0
■ Supports full-speed peripheral device operation with a signaling bit rate of 12 Mbps
■ Supports eight data endpoints and one control endpoint
■ Provides shared 512-byte buffer for data endpoints
■ Provides dedicated 8-byte memory for control endpoint (EP0)
■ Supports four types of transfers – bulk, interrupt, isochronous, and control
■ Supports bus- and self-powered configurations
■ Enables USB suspend mode for low power
■ Supports three types of logical transfer modes:
❐ No DMA mode (Mode 1)
❐ Manual DMA mode (Mode 2)
❐ Automatic DMA mode (Mode 3)
■ Supports maximum packet size of 512 bytes using Mode 1 and Mode 2, and maximum packet size of 1023 bytes for iso-
chronous transfer using Mode 3
■ Provides integrated 22- USB termination resistors on D+ and D– lines, and 1.5-k pull-up resistor on the D+ line
■ Supports USB 2.0 Link Power Management (LPM)
■ Can be configured using the USB Device Configurator available with the ModusToolbox software
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 450
Universal Serial Bus (USB) Device Mode
33.2 Architecture
Figure 33-1 illustrates the device architecture of the USB block in PSoC 6 MCUs. It consists of the USB Physical Layer (USB
PHY), Serial Interface Engine (SIE), and the local 512-byte memory buffer.
Figure 33-1. USB Device Block Diagram
USB Block
Arbiter
CPU/DMA CPU/DMA
Interface Subsystem
512 Bytes Memory
SRAM Interface
Arbiter
Logic
SIE
Interface
SIE
USB PHY
D+ D- VBUS
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 451
Universal Serial Bus (USB) Device Mode
33.2.3.2 CPU/DMA Interface Block accuracy of ±0.25%. In the PSoC 6 MCU, CLK_HF3 is the
clock source. The USB device block also requires a 100-kHz
This module handles all transactions with the CPU and peripheral clock for USB bus reset timing. The required USB
DMA. The CPU requests for reads and writes to the SRAM clock can be generated using one of the following clocking
memory for each endpoint. These requests are registered in schemes:
this interface and are handled by the block. When the DMA
is configured, this interface is responsible for all transactions ■ IMO (trimmed with USB) -> PLL -> CLK_HF3
between the DMA and USB. The block supports the DMA ■ ECO (with the required accuracy) -> FLL -> CLK_HF3
request line for each data endpoint. The behavior of the ■ ECO (with the required accuracy) -> PLL -> CLK_HF3
DMA depends on the type of logical transfer mode config-
ured in the configuration register. ■ Use external clock (EXTCLK) with the required accuracy
1.5 K
ten 22 D+
td Transmitter Upstream
dpi Logic D- Host/Hub
dmi
22
rd
dpo Receiver
dmo Logic
rse0
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 452
Universal Serial Bus (USB) Device Mode
33.3.2.2 VBUS Detection and the response when a sub PID other than the LPM
token is received from the host.
USB devices can either be bus-powered (power sourced
from the host) or self-powered (power sourced from an ■ The LPM_STAT register stores the values of the Best
external power supply). The VDDUSB power pad pin pow- Effort Service Latency (BESL) and the remote wakeup
ers the USB PHY and USB I/Os (D+ and D– pins). The pres- feature as sent by the host. The firmware should read
ence of VBUS can be detected using the following steps: this register on the LPM interrupt event and enter the
1. Enable the interrupt on VDDUSB power pad. For this appropriate low-power mode (Deep Sleep or Sleep)
write ‘1’ to the VDDIO_ACTIVE[5] bit of VDD_IN- based on the BESL value from the host.
TR_MASK register.
2. VDDIO_ACTIVE[5] bit of the supply detection interrupt 33.3.3 Endpoints
register (VDD_INTR) is set to ‘1’ whenever a change to The SIE and arbiter support eight data endpoints (EP1 to
supply is detected. Clear the interrupt cause by writing EP8) and one control endpoint (EP0). The data endpoints
‘1’ to the bitfield. share the SRAM memory area of 512 bytes. The endpoint
3. Check the status of the VDD_ACTIVE[5] bit of the exter- memory management can be either manual or automatic.
nal power supply detection register (VDD_ACTIVE). The The endpoints are configured for direction and other config-
uration using the SIE and arbiter registers. The endpoint
bit is set to ‘1’ when there is supply and ‘0’ when there is
read address and write address registers are accessed
no supply. through the arbiter.
33.3.2.3 USB D+ Pin Pull-up Enable Logic The endpoints can be individually made active. In the Auto
Management mode, the register EP_ACTIVE is written to
When a USB device is self-powered, the USB specification control the active state of the endpoint. The endpoint activa-
warrants that the device enable the pull-up resistor on its D+ tion cannot be dynamically changed during runtime. In Man-
pin to identify itself as a full-speed device to the host. When ual Memory Management mode, the firmware decides the
the host VBUS is removed, the device should disable the memory allocation, so it is not required to specify the active
pull-up resistor on the D+ line to not back power the host. endpoints. The EP_ACTIVE register is ignored during the
The USB PHY includes an internal 1.5-k pull-up resistor on manual memory management mode. The EP_TYPE regis-
the D+ line to indicate to the host that the PSoC 6 MCU is a ter is used to control the transfer direction (IN, OUT) for the
full-speed device. The pull-up resistor can be enabled or endpoints. The control endpoint has separate eight bytes for
disabled by configuring the DP_UP_EN bit in the its data (EP0_DR registers).
USBLPM_POWER_CTRL register.
33.3.4 Transfer Types
33.3.2.4 Transmitter and Receiver Logic
The PSoC 6 MCU USB supports full-speed transfers and is
The transceiver block transmits and receives USB differen- compliant with the USB 2.0 specification. It supports four
tial signals with an upstream device, and includes the USB types of transfers:
D+ pull-up resistor used to maintain an idle state on the bus.
Output data is differentially transmitted to upstream devices ■ Interrupt Transfer
at a nominal voltage of 3.3 V. The differential inputs ■ Bulk Transfer
received from upstream devices are converted into single- ■ Isochronous Transfer
ended data and sent to the core logic at a nominal voltage of
1.8 V. The D+ and D– pins are terminated with 22- resis- ■ Control Transfer
tors to meet the USB impedance specification. For further details about these transfers, refer to the USB
2.0 specification.
33.3.2.5 GPIO Mode Logic
The D+ and D– pins can be used either as GPIO pins or 33.3.5 Interrupt Sources
USB I/O pins. This is controlled by the IOMODE bit of the
USBDEV_USBIO_CR1 register. This bit should be set HIGH The USB device block generates 14 interrupts to the CPU.
for GPIO functionality and LOW for USB operation. These interrupts are mapped to three general-purpose
interrupt lines – INTR_LO, INTR_MED, and INTR_HI. Each
of these three interrupt lines has an associated status
33.3.2.6 Link Power Management (LPM) register, which identifies the cause of the interrupt event.
The USB PHY supports link power management (LPM), These are the USBLPM_INTR_CAUSE_LO,
which is similar to the suspend mode, but has transitional USBLPM_INTR_CAUSE_MED, and
latencies in tens of microseconds between power states, USBLPM_INTR_CAUSE_HI registers. The routing of these
compared to the greater than 20 ms latency associated with interrupts is controlled by the USBLPM_INTR_LVL_SEL
suspend/resume modes. For more details on LPM, refer to register fields.
the USB 2.0 specification. The following features are sup- The following events generate an interrupt on one of the
ported for LPM. three interrupt lines:
■ The LPM_CTL register should be configured to enable/ ■ USB start of frame (SOF) event
disable LPM, type of response when LPM is enabled,
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 453
Universal Serial Bus (USB) Device Mode
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 454
Universal Serial Bus (USB) Device Mode
33.3.5.7 Arbiter Interrupt Event an IN token is received for that endpoint, it cannot
use the common buffer area, hence resulting in an
The arbiter interrupt can arise from five possible sources. overflow of data. The possible causes of this buffer
Each interrupt source is logically ANDed with its corre-
overflow can be incorrect programming of either the
sponding ENABLE bit and the results are logically ORed to
result in a single arbiter interrupt event. DMA transfer descriptor transfer size or the USB-
DEV_BUF_SIZE register.
The arbiter interrupt event can arise under any of the follow-
ing five scenarios: ❐ In an OUT endpoint, the dedicated buffer can over-
flow if two OUT transactions occur consecutively.
■ DMA Grant
The data from the previous transaction is still present
■ IN Buffer Full in the common area and the current ongoing trans-
■ Buffer Overflow action fills up the OUT endpoint’s dedicated buffer
■ Buffer Underflow space and overflows. The possible causes of this
overflow can be the overall DMA bandwidth con-
■ DMA Termin straint due to other DMA transactions or reduced
size of the dedicated OUT buffer size.
DMA Grant
■ Common area data overflow
This event is applicable in Mode 2 or Mode 3. (See Logical
❐ In an IN endpoint, the common area overflow occurs
Transfer Modes on page 456 for details on DMA modes).
This event is triggered when the DMA controller pulses the when the DMA transfer writes a larger number of
Burstend signal corresponding to that endpoint, for which a bytes than the space available in the common area.
DMA request had been raised to the DMA controller earlier. This situation may arise due to incorrect
The request may have been either a manual DMA request programming of either the DMA transfer descriptor
or an automatic arbiter DMA request. A common grant sta- transfer size or the USBDEV_DMA_THRESH and
tus exists for both modes of requests. This grant status indi- USBDEV_DMA_THRESH_MSB registers.
cates completion of the DMA transaction. This status
❐ In an OUT endpoint, the common area overflow
indication can be used by firmware to determine when the
next manual DMA request can be raised. Multiple requests occurs when the data written to the common area
raised for the same endpoint before the DMA grant status is has not yet been read and new data overwrites the
set will be dropped by the block. Only the first of multiple existing data.
requests will be transmitted to DMA controller.
Buffer Underflow
IN Buffer Full
This event is applicable only in the Cut Through mode
This event status can occur in any of the DMA modes (Mode (Mode 3). This underflow condition can occur only for an IN
1, 2, or 3) and is applicable only for IN endpoints. endpoint. The underflow condition can occur either in the
dedicated buffer space or common buffer space. The under-
■ Store and Forward Mode (Modes 1 and 2): This status is
flow condition on the dedicated buffer space can either be
set when the entire packet data is transferred to the local due to the reduced dedicated IN buffer size or DMA band-
memory. The check is that data written for the particular width constraint. The underflow condition can occur on the
endpoint is equal to the programmed byte count for that common buffer space due to DMA bandwidth constraint
endpoint in the USBDEV_SIE_EPx_CNT0 and USB- and/or lower DMA channel priority.
DEV_SIE_EPx_CNT1 registers.
■ Cut Through Mode (Mode 3): In this mode, the IN buffer DMA Termin
full status is set when the IN endpoint’s dedicated buffer This status is set when USBDEV generates a dma_termin
is filled with the packet data. The size of this buffer is signal to indicate the total programmed/ received bytes that
determined by the value programmed in bits [3:0] of the are written/read by the DMA controller. This status indication
USBDEV_BUF_SIZE register. This status indication can can be used by the firmware to reprogram the IN/OUT end-
be used to determine when the mode value in the USB- point for the next transfer. For an OUT endpoint, this indi-
DEV_SIE_EPx_CR0 register can be programmed to cates that the OUT packet data is available in the system
acknowledge an IN token for that endpoint. memory for further processing by the application.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 455
Universal Serial Bus (USB) Device Mode
ing endpoint is routed using the Trigger Group 9 multiplexer. and from the SRAM memory unit for each endpoint). It does
For more details, see the DMA Controller (DW) chapter on not represent the transfer methods between the device and
page 91 and Trigger Multiplexer Block chapter on page 294. the host (the transfer types specified in the USB 2.0 specifi-
cation).
The USB supports two basic types of transfer modes:
33.4 Logical Transfer Modes
■ Store and Forward mode
The USB block in PSoC 6 MCUs supports two types of logi- ❐ Manual Memory Management with No DMA Access
cal transfers. The logical transfers can be configured using
(Mode 1)
the register setting for each endpoint. Any of the logical
transfer methods can be adapted to support the three types ❐ Manual Memory Management with Manual DMA
of data transfers (Interrupt, Bulk, and Isochronous) men- Access (Mode 2)
tioned in the USB 2.0 specification. The control transfer is ■ Cut Through mode
mandatory in any USB device.
❐ Automatic Memory Management with Automatic
The logical transfer mode is a combination of memory man-
DMA Access (Mode 3)
agement and DMA configurations. The logical transfer
modes are related to the data transfer within the USB (to Table 33-1 gives a comparison of the two transfer modes.
Every endpoint has a set of registers that need to be handled during the modes of operation, as detailed in Table 33-2.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 456
Universal Serial Bus (USB) Device Mode
In Manual memory management, the endpoint read and endpoint write address registers are updated by the firmware. So the
memory allocation can be done by the user. The memory allocation decides which endpoints are active; that is, you can
decide to share the 512 bytes for all the eight endpoints or a lesser number of endpoints.
In Automatic memory management, the endpoint read and endpoint write address registers are updated by the USB block.
The block assigns memory to the endpoints that are activated using the USBDEV_EP_ACTIVE register. The size of memory
allocated depends on the value in the USBDEV_BUF_SIZE register. The remaining memory, after allocation, is called the
common area memory and is used for data transfer.
In all of these modes, either the 8-bit endpoint data register or the 16-bit endpoint data register can be used to read/write to
the endpoint buffer. While transferring data to the 16-bit data registers, ensure that the corresponding SRAM memory
address locations are also 16-bit aligned.
In the following text, the algorithm for the IN and OUT transaction for each mode is discussed. An IN transaction is when the
data is read by the USB host (for example, PC). An OUT transaction is when the data is written by the USB host to the USB
device. The choice of using the DMA and memory management can be configured using the USBDEV_ARB_EPx_CFG reg-
ister.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 457
Universal Serial Bus (USB) Device Mode
Set Packet size in the Endpoint byte Set Packet size in the Endpoint byte
count register count register
Wait
Is all data
No written to
Set mode in CR0 register SRAM?
Yes
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 458
Universal Serial Bus (USB) Device Mode
Figure 33-5 and Figure 33-6 show the flow charts for manual DMA IN and OUT transactions respectively.
Figure 33-5. Manual DMA IN Transaction
Write WA register
(based on required memory allocation)
Is all data
No written
to SRAM
Yes
Wait
No
Is IN
Token Received? Responds
Automatically
With ACK
Yes
No Is all data
Transmitted?
Interrupt
Generated
Yes
End
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 459
Universal Serial Bus (USB) Device Mode
Figure 33-6. Manual DMA OUT Transaction remaining memory (256 bytes) is left as common area and
is common for all endpoints.
Write WA register
(based on the required memory allocation) In this mode, the memory requirement is less and it is suit-
able for full-speed isochronous transfers up to 1023 bytes.
When an IN command is sent by the host, the device
Set Packet size in the Endpoint byte
count register responds with the data present in the dedicated memory
area for that endpoint. It simultaneously issues a DMA
request for more data for that EP. This data fills up the com-
Set mode in CR0 register mon area. The device does not wait for the entire packet of
data to be available. It waits only for the (USBDEV_DMA_-
THRES_MSB, USBDEV_DMA_THRES) number of data
available in the SRAM memory and begins the transfer from
Wait
the common area.
No Is OUT Responds automatically with
Token Received? ACK Similarly, when an OUT command is received, the data for
the OUT endpoint is written to the common area. When
Yes some data (greater than USBDEV_DMA_THRES_MSB,
USBDEV_DMA_THRES) is available in the common area,
Data received from host
Written to SRAM location WA
the arbiter block initiates a DMA request and the data is
WA++ immediately written to the device. The device does not wait
for the common area to be filled.
This mode requires configuration of the
USBDEV_DMA_THRES and
Is all data
No written to USBDEV_DMA_THRES_MSB registers to hold the number
SRAM? of bytes that can be transferred in one DMA transfer (32
bytes). Similarly, the burst count of the DMA should always
Yes be equal to the value set in the USBDEV_DMA_THRES
registers. Apart from the DMA configuration, this mode also
SIE sets mode to NAK. Updates byte count with
actual no. of data received abd sets the data valid needs the configuration of the USBDEV_BUF_SIZE for the
bit IN and the OUT buffers and the USBDEV_EP_ACTIVE and
SIE Data the USBDEV_EP_TYPE registers.
Interrupt
Generated Each DMA channel has two descriptors and both of them
Write RA value (= initial WA value)
are used in this mode. Each descriptor is considered as a
data chunk of 32 bytes and it executes according to the trig-
ger mechanism. The descriptors are chained and hence 64
Configure DMA request bytes can be transferred without firmware interaction. When
Data register is DMA Grant Arbiter
Read by the CPU, RA++ is Interrupted generated
both descriptors complete the endpoint DMA done interrupt
automatically done and the DMA error interrupt triggers (due to the lack of data
USB block reads data at RA to transfer). The descriptors are updated to advance the
location and writes to data register
source SRAM (IN endpoint) or destination SRAM (OUT end-
point) pointer locations and then enabled again. This
No sequence continues till all data is transferred.
The steps for IN and OUT transactions using automatic
Is all data
Read from DMA mode are shown in Figure 33-7 and Figure 33-8.
SRAM?
Yes
End
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 460
Universal Serial Bus (USB) Device Mode
No Is the endpoint
Buffer full?
IN_BUF_FULL Interrupt
generated
Yes
Wait
No Is IN Command
received?
Is the complete
Yes data available No
in the memory
RA++
SIE reads data from SRAM (specified
by location RA) and transmits to host
In the mean time, the PHUB
initiates the transaction. The
Is all data RA++ data from the device is copied to
No
in buffer No the common area. The data
transmitted? from the USB is written to the
SRAM by the DMA
Yes Is all data
in buffer
transmitted?
Set the data valid bits
Yes
Wait
End
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 461
Universal Serial Bus (USB) Device Mode
Wait
No Is OUT
Token Received?
Yes
WA++
No
Is data in
SRAM>(DMA_THRES,DMA_TH
RES_MSB)?
Yes
DMA request is Data in the Data register is read
The process is raised and given to the USB device by
continued till all the DMA. RA is incremented
the data is transferred automatically
USB Block writes the data from
SRAM to the Data register
No
Is all data
from SRAM
copied to device?
Yes
End
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 462
Universal Serial Bus (USB) Device Mode
Figure 33-9. Control Endpoint IN Transaction Figure 33-10. Control Endpoint OUT Transaction
Set the mode bits to ACK Program the mode bits for
the IN token ACK_OUT
No Is SETUP No Is SETUP
token received? token received?
Yes Yes
No
Is Data Valid?
No
Is Data Valid?
Yes
Yes
Read the EP0_DRx register to find the
type of request
Read the EP0_DRx register to find the
type of request
Set the data valid bit and the mode bits. No Is OUT
Also update the byte count value Token Received?
Yes
Yes
Interrupt generated
The block transmits the data from the
EP0_DRx registers
Is data No
Valid?
Block generates interrupt on receiving
ACK from host and sets the IN byte
received bit Yes
Yes
Yes
End
End
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 463
Universal Serial Bus (USB) Device Mode
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 464
Universal Serial Bus (USB) Device Mode
Name Description
USBDEV_ARB_INT_EN Arbiter interrupt enable register
USBDEV_ARB_INT_SR Arbiter interrupt status register
USBDEV_CWA Common area write address register
USBDEV_CWA_MSB Endpoint read address value register
USBDEV_DMA_THRES DMA burst / threshold configuration register
USBDEV_DMA_THRES_MSB DMA burst / threshold configuration register
USBDEV_BUS_RST_CNT Bus reset count register
USBDEV_MEM_DATA Data register
USBDEV_SOF16 Start of frame register
USBDEV_OSCLK_DR16 Oscillator lock data register
Endpoint write address value register. Pointer value increments by 2 when
USBDEV_ARB_RWx_WA16
accessed by CPU/debugger
Endpoint read address value register. Pointer value increments by 2 when
USBDEV_ARB_RWx_RA16
accessed by CPU/debugger
USBDEV_ARB_RWx_DR16 Endpoint data register
USBDEV_DMA_THRES16 DMA burst / threshold configuration register
USBLPM_POWER_CTL Power control register
USBLPM_USBIO_CTL USB IO control register
USBLPM_FLOW_CTL Flow control register
USBLPM_LPM_CTL LPM control register
USBLPM_LPM_STAT LPM status register
USBLPM_INTR_SIE USB SOF, BUS RESET, and EP0 interrupt status register
USBLPM_INTR_SIE_SET USB SOF, BUS RESET, and EP0 interrupt set register
USBLPM_INTR_SIE_MASK USB SOF, BUS RESET, and EP0 interrupt mask register
USBLPM_INTR_SIE_MASKED USB SOF, BUS RESET, and EP0 interrupt masked register
USBLPM_INTR_LVL_SEL Select interrupt level for each interrupt source register
USBLPM_INTR_CAUSE_HI High-priority interrupt cause register
USBLPM_INTR_CAUSE_MED Medium-priority interrupt cause register
USBLPM_INTR_CAUSE_LO Low-priority interrupt cause register
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 465
34. Universal Serial Bus (USB) Host
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The USB subsystem in PSoC 6 MCUs can be configured to function as a USB host. The USB host in the PSoC 6 MCU sup-
ports both full-speed (12 Mbps) and low-speed (1.5 Mbps) devices and is designed to be complaint with the USB Specifica-
tion Revision 2.0. This chapter details the PSoC 6 MCU USB and its operations. For details about the USB specification, refer
to the USB Implementers Forum website.
34.1 Features
The USB host in the PSoC 6 MCU has the following features:
■ Automatic detection of device connection or disconnection
■ Automatic detection of full-speed or low-speed transfer
■ Supports USB bus reset function
■ Supports IN, OUT, SETUP. and SOF tokens
■ Supports Bulk, Control, Interrupt, and Isochronous transfer
■ Automatic detection of handshake packet for OUT token and automatic sending of handshake packet for IN token (exclud-
ing STALL)
■ Supports a maximum packet length of up to 256 bytes
■ Supports action against errors (CRC error, toggle error, and timeout)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 466
Universal Serial Bus (USB) Host
34.2 Architecture
Figure 34-1. USB Host Block Diagram
Interrupt Interrupt
Signals Control Control / Status Registers
Block
Endpoint Block
Endpoint 1
VDDUSB
USB PHY
Registers
FFs x2
USB Clock Clock Host
(48 MHz) Control Controller D+
System Clock Block FIFO Control Unit
(at least 13 MHz) D-
Endpoint 2
Registers
FFs x2
DREQ
DREQ Control
FIFO Control
Signals
34.2.1 USB Physical Layer (USB PHY) be mapped to any of the three interrupt lines. Each of these
three interrupt lines has a status register to identify the
The USB includes the transmitter and receiver (transceiver), interrupt source. These are the
which corresponds to the USB PHY. This module allows USBHOST_INTR_USBHOST_CAUSE_LO,
physical layer communication with the USB device through USBHOST_INTR_USBHOST_CAUSE_MED, and
the D+, D–, and VDDUSB pins. It handles differential mode USBHOST_INTR_USBHOST_CAUSE_HI,
communication with the device. The USB PHY also includes USBHOST_INTR_USBHOST_EP_CAUSE_LO,
pull-down resistors on the D+ and D– lines. Differential USBHOST_INTR_USBHOST_EP_CAUSE_MED and
signaling is used between the USB host and the device. The USBHOST_INTR_USBHOST_EP_CAUSE_HI registers.
host controller unit receives the differential signal from the
device and converts it to a single-ended signal. While
transmitting, the host controller unit converts the single-
34.2.4 Endpoint n (n=1, 2)
ended signal to the differential signal, and transmits it to the The USB host has two endpoints. The maximum buffer size
device. The differential signal is at a nominal voltage range of endpoint 1 is 256 bytes and that of endpoint 2 is 64 bytes.
of 0 V to 3.3 V. The endpoint buffers are used to send and receive data. If
endpoint 1 is used as the transmitter, endpoint 2 must be
34.2.2 Clock Control Block used as the receiver and vice-versa. The DIR bit of the
USBHOST_HOST_EPn_CTL (n=1, 2) register is used to
This block controls the gated clocks – system clock and configure the endpoint as an IN buffer (DIR=0) or OUT buf-
USB clock. The USB host requires a clock frequency of fer (DIR=1).
48 MHz. USB host compliance requires a clock source with
an accuracy of ±0.25 percent. One way of doing this is to
use Clk_HF[3] sourced from an highly accurate ECO. The
34.2.5 DMA Request (DREQ) Control
PLL can be used to generate the required 48-MHz clock The USB host supports data transfer using DMA. DMA
from the ECO. Refer to the Clocking System chapter on operation is enabled by configuring the USB-
page 242 for details on generation of clock required for USB HOST_HOST_DMA_ENBL register. There are two DMA
operation. transfer modes: Automatic data transfer mode and packet
transfer mode. The DMAE bit of the USB-
34.2.3 Interrupt Control Block HOST_HOST_EPn_CTL (n=1, 2) register is used to set the
mode of DMA transfer. The Host Endpoint Block register
This block controls the interrupts associated with USB host (USBHOST_HOST_EPn_BLK; n=1, 2) sets the total num-
operations. The USB host block has three general-purpose ber of bytes for DMA transfer.
interrupt signals: USBHOST_INTR_USBHOST_LO,
USBHOST_INTR_USBHOST_MED, and
USBHOST_INTR_USBHOST_HI. There are 11 interrupt
trigger events associated with USB host operation that can
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 467
Universal Serial Bus (USB) Host
USB DP
USB DM
CSTAT bit of 2.5us or more
HOST_STATUS
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 468
Universal Serial Bus (USB) Host
Figure 34-3. Device Connection and Transfer Speed Detection Flow Chart
START
Enable USB Host Clock and release the reset for USB host
HOST_CTL1.USTP=0
HOST_CTL1.RST=0
No
If
INTR_USBHOST.CNNIRQ=1
Yes
If No
HOST_STATUS.TMODE=1
Yes
END
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 469
Universal Serial Bus (USB) Host
Pin D+ 10 ms or more
Pin D-
URST bit of
USBHOST_HOST_STATUS
CSTAT bit of
USBHOST_HOST_STATUS
URIRQ bit of
USBHOST_INTR_USBHOST
CNNIRQ bit of
USBHOST_INTR_USBHOST
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 470
Universal Serial Bus (USB) Host
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 471
Universal Serial Bus (USB) Host
Figure 34-5. IN Token Flow Chart Figure 34-6. SETUP/OUT Token Flow Chart
START START
INTR_USBHOST.CMPIRQ=1?
Check for token transfer
completion
Set INTR_HOST_EP.EPnDRQ=1
Yes (n=1,2)
No
Check for Handshake error
HOST_ERR.HS=00? Yes
Check for Time out error
Yes HOST_ERR.TOUT=1?
No
Error Processing No
No
Is Check for toggle error Yes
INTR_HOST_EP.EPnDRQ=1 HOST_ERR.TGERR=1?
No
Yes
Error
No Processing
INTR_HOST_EP.EPnDRQ = 0 END
END
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 472
Universal Serial Bus (USB) Host
When issuing an SOF token, specify the EOF time in the Host EOF Setup (USBHOST_HOST_EOF) register and the frame
number in the Host Frame Setup (USBHOST_HOST_FRAME) register respectively. Then, specify an SOF token code in the
TKNEN bit of the USBHOST_HOST_TOKEN register. After sync, SOF token, frame number, CRC5, and EOP are sent, the
SOFBUSY bit of the USBHOST_HOST_STATUS register is set to ‘1’, and the USBHOST_HOST_FRAME register is
incremented by one. The CMPIRQ bit of the USBHOST_INTR_USBHOST register is also set to ‘1’, causing the TKNEN bit of
the USBHOST_HOST_TOKEN register to be cleared to ‘000’. To clear a token completion interrupt, write ‘1’ to the CMPIRQ
bit of the Host Interrupt (USBHOST_HIRQ) register.
An SOF is automatically sent every 1 ms while the SOFBUSY bit of the USBHOST_HOST_STATUS register is ‘1’.
Figure 34-7 depicts steps to send an SOF token
Figure 34-7. SOF Token Flow Chart
START
HOST_FRAME Setting
HOST_EOF Setting
HOST_TOKEN setting
No
INTR_USBHOST.CMPIRQ=1?
Yes
Yes
HOST_ERR.LSTSOF=1?
No Error
Processing
END
The conditions (SOF stop conditions) to set the SOFBUSY bit of the USBHOST_HOST_STATUS register to ‘0’ are as fol-
lows:
■ Writing 0 to the SOFBUSY bit of USBHOST_HOST_STATUS
■ Resetting the USB bus
■ Writing 1 to the SUSP bit of USBHOST_HOST_STATUS
■ Disconnecting the USB device (when the CSTAT bit of USBHOST_HOST_STATUS is ‘0’)
The USBHOST_HOST_EOF register is used to prevent the SOF from being sent simultaneously with other tokens. If the
TKNEN bit of the USBHOST_HOST_TOKEN register is written within the time period specified by the
USBHOST_HOST_EOF register, the specified token is placed into the wait state. After the SOF is sent, the token in the wait
state is issued. The HOST_EOF Setup register specifies a 1-bit time as the time unit. When the EOF setting is shorter than
the 1-packet time, SOF may be sent doubly during execution of other tokens. In this case, the LSTSOF bit of the Host Error
Status (USBHOST_HOST_ERR) register is set to ‘1’ and SOF is not sent. If ‘1’ is set to the LSTSOF bit of the
USBHOST_HOST_ERR register, the value of the Host EOF Setup register must be increased.
Figure 34-8. SOF Timing
SOF SOF
1 ms
EOF > 1-packet time
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 473
Universal Serial Bus (USB) Host
34.3.4.2 Data Packet remented by one when a 1-bit transfer clock (12 MHz in full-
speed mode) is output. When the retry timer reaches 0, the
Follow these steps to send or receive a data packet after target token is sent, and processing ends. If a token retry
sending a token packet. occurs in the EOF area, the retry timer is stopped until SOF
■ Transmitting data (host to device) is sent. After SOF is sent, the retry timer restarts with the
value that is set when the timer stopped.
❐ Sync pattern is automatically sent.
❐ If the TGGL bit of USBHOST_HOST_TOKEN is 0, 34.3.6 Error Status
DATA0 is sent. If the TGGL bit is 1, DATA1 is sent.
❐ If the DIR bit of the USBHOST_HOST_EP1_CTL The USB host supports detection of the following types of
errors:
register is 1 (that is, if EP1 is an OUT endpoint),
select the Endpoint 1 buffer; otherwise, select the ■ Stuffing Error
Endpoint 2 buffer. Then, send all the target data. If 1 is written to six successive bits, 0 is inserted into one
❐ 16-bit CRC is automatically sent. bit. If 1 is successively detected in seven bits, it is
regarded as a Stuffing error, and the STUFF bit of the
❐ 2-bit EOP is automatically sent.
USBHOST_HOST_ERR register is set to 1. To clear this
❐ 1-bit J State is automatically sent. status, write ‘1’ to the STUFF bit.
■ Receiving data (device to host) ■ Toggle Error
❐ Receive sync. When sending an IN token, the Toggle Data field of a
❐ Receive toggle data, and compare it with the value of data packet is compared with the value of the TGGL bit
the TGGL bit of HOST_TOKEN. of the USBHOST_HOST_TOKEN register. If they do not
❐ If the toggle data matches the value of the TGGL bit, match, the TGERR bit of the USBHOST_HOST_ERR
check the DIR bit of HOST_EP1_CTL. If the DIR bit register is set to 1. To clear the TGERR bit, write ‘1’ to
is 1, select the Endpoint 2 buffer; otherwise, select the TGERR bit of the USBHOST_HOST_ERR register.
the Endpoint 1 buffer. Then, distribute the received ■ CRC Error
data to the respective buffers. When receiving an IN token, the data and CRC of the
❐ Verify the 16-bit CRC when EOF is received. received data packet are obtained with the CRC
polynomial G(X) = X16 + X15 + X2 + 1. If the remainder
34.3.4.3 Handshake Packet is not 0x800D, it means that a CRC error has occurred,
and the CRC bit of the USBHOST_HOST_ERR register
A handshake packet is used to notify the remote device of
is set to 1. To clear the CRC bit, write ‘1’ to the CRC bit
the status of the local device. A handshake packet sends
either one of ACK, NAK, and STALL from the receiving side of USBHOST_HOST_ERR. For more details, refer to the
when it is judged that the receiving side is ready to receive documentation: CRC in USB.
data normally. If the USB circuit receives a handshake ■ Time Out Error
packet, the type of the received handshake packet is set to
The TOUT bit of the USBHOST_HOST_ERR register is
the HS bit of the USBHOST_HOST_ERR register.
set and time out error is considered under any of the
following conditions:
34.3.5 Retry Function
❐ A data packet or handshake packet is not input in the
When a NAK or CRC error occurs at the end of a packet, if specified time
‘1’ is set to the RETRY bit of the Host Control 2
❐ SE0 is detected when receiving data
(USBHOST_HOST_CTL2) register, processing is retried
repeatedly for the period specified in the Host Retry Timer ❐ Stuffing error is detected
Setup (USBHOST_HOST_RTIMER) register. To clear the TOUT bit, write 0 to the TOUT bit of the
When an error other than STALL or device disconnection USBHOST_HOST_ERR register.
occurs, the target token is retried if the RETRY bit of ■ Receive Error
HOST_CTL2 is 1. The conditions to end retry processing
are as follows. The PKSn (n = 1, 2) bit of Endpoint Control register
(USBHOST_HOST_EPn_CTL; n=1, 2) indicates the
■ The RETRY bit of HOST_CTL2 is set to 0.
receiver packet size. When the received data exceeds
■ ‘0’ is detected in the retry timer. the specified receive packet size, the RERR bit of the
■ The interrupt flag is generated by SOF (SOFIRQ of USBHOST_HOST_ERR register is set to 1. To clear the
USBHOST_INTR_USBHOST = 1). RERR bit, write ‘1’ to the RERR bit of
■ ACK is detected. USBHOST_HOST_ERR.
■ A device disconnection is detected. ■ Lost SOF Error
The retry timer is activated when a token is sent while the When the LSTSOF bit of the USBHOST_HOST_ERR
RETRY bit of HOST_CTL2 is ‘1’. The retry time is then dec- register is set, it means that the SOF token cannot be
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 474
Universal Serial Bus (USB) Host
sent because another token is in process. When this bit time, if the CMPIRQM bit of the
is ‘0’, it means that no lost SOF error is detected. USBHOST_INTR_USBHOST_MASK register is 1, an
interrupt occurs.
34.3.7 End of Packet (EOP) When a packet ends, the interrupt is generated when the
TKNEN bit of the USBHOST_HOST_TOKEN register is set
If a packet ends in the USB host, the CMPIRQ bit of the as ‘001’ (SETUP token), ‘010’ (IN token), ‘011’ (OUT token),
USBHOST_INTR_USBHOST register is set to 1. At this or ‘100’ (SOF token).
Figure 34-9. EOP Interrupt Timing Diagram (for IN/OUT/SETUP token)
Write data to the
TKNEN bit of
HOST_TOKEN Token Packet Data Packet Handshake Packet
J-ST Sync TKN ADR ENDP CRC5 EOP J-ST Sync TGGL DATA CRC16 EOP J-ST Sync ACK EOP J-ST
J-ST : J State
TKN : Token
ADR : Address
ENDP : Endpoint
TGGL : Toggle
CMPIRQ bit
(HIRQ)
J-ST : J State
TKN : Token
FRAME : Frame Number
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 475
Universal Serial Bus (USB) Host
CM4
Interrupt
Controller
URIRQ
CNNIRQ
SOFIRQ
DIRQ
INTR_HI CM0+
CMPIRQ Interrupt
INTR_MED
TCAN MUX
INTR_LO Controller
RWKIRQ
EP1DRQ
EP1SPK
EP2DRQ
EP2SPK
The following events generate an interrupt on one of the three interrupt lines:
■ Start-of-frame (SOF) event
SOF interrupt is generated when an SOF token is sent. The SOF interrupt is enabled by setting the SOFIRQM bit of the
USBHOST_INTR_USBHOST_MASK register. The status of the SOF interrupt is reflected in the SOFIRQ bit of the
USBHOST_INTR_USBHOST register.
■ Device connection and disconnection events
The CNNIRQ bit of the USBHOST_INTR_USBHOST register is set to ‘1’ when a device connection is detected. The
interrupt can be enabled by setting the CNNIRQM bit of the USBHOST_INTR_USBHOST_MASK register.
When a device is disconnected, an interrupt is generated if the DIRQM bitfield of USBHOST_INTR_USBHOST_MASK is
set to ‘1’. The status of the device disconnection is reflected in the DIRQ bit of the USBHOST_INTR_USBHOST register.
■ USB bus reset event
The URIRQ bit of the USBHOST_INTR_USBHOST register is set when the USB bus reset ends. An interrupt is generated
if the URIRQM bit of the USBHOST_INTR_USBHOST_MASK register is set to ‘1’.
■ Token completion event
When token (IN, OUT, or SETUP token) processing is complete, the CMPIRQ bit of the USBHOST_INTR_USBHOST
register is set. An interrupt is generated if the CMPIRQM bit is set to ‘1’.
■ Interrupt on resume event
The RWKIRQ bit of the USBHOST_INTR_USBHOST register is set when the host enters the resume state from suspend
state. The RWKIRQ bit is set under the following conditions:
❐ The SUSP bit of the USBHOST_HOST_STATUS register is set to ‘0’.
❐ The D+/D– pins are placed in the K-state.
❐ A device connection/disconnection is detected.
An interrupt is generated on a resume event if the RWKIRQM bit of the USBHOST_INTR_USBHOST_MASK register is
set to ‘1’.
■ Interrupt on token cancellation
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 476
Universal Serial Bus (USB) Host
An interrupt is generated when a token send is canceled based on the setting of the CANCEL bit in the Host Control 2
register (USBHOST_HOST_CTL2). If the CANCEL bit is set and if the target token is written to the
USBHOST_HOST_TOKEN register in the EOF area (specified in the Host EOF Setup register), the token send is
canceled.
■ Endpoint interrupts
The USB host has two endpoints: Endpoint1 and Endpoint2. Each endpoint can generate two interrupts. When the packet
transfer of an endpoint ends normally, the EPnDRQ (n=1or 2) bit of the USBHOST_INTR_HOST_EP register is set to ‘1’.
An interrupt can be triggered if the EPnDRQM (n=1or 2) bit of the USBHOST_INTR_HOST_EP_MASK register is set to
‘1’. If the packet size does not match the packet size specified in the PKS bit of the HOST_EPn_CTL (n=1 or 2) register,
the EPnSPK (n=1or 2) bit of the USBHOST_INTR_HOST_EP register is set. An interrupt can be configured by setting the
EPnSPKM (n=1or 2) bit of the USBHOST_INTR_HOST_EP_MASK register.
EPnDRQ bit
(n=1 or 2)
CMPIRQ is set to CMPIRQ is set to
Write the data to the 1 1
HOST_EPn_RW1_DR or Write the data to the
HOST_Epn_RW2_DR by DMAC HOST_EPn_RW1_DR or
OUT token is HOST_Epn_RW2_DR by DMAC OUT token is
(DATA0)
issued (DATA1) issued
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 477
Universal Serial Bus (USB) Host
DATA
Device Host DATA1
0
DM_EPnDRQE
bit 1 EPnDRQ bit EPnDRQ bit
(n=1 or 2) is cleared is cleared
by software by software
EPnDRQ bit
(n=1 or 2)
The data transfer in the IN direction (device to host) involves the following sequence of steps:
1. After the EPnDRQ bit (n=1 or 2) of the USBHOST_INTR_HOST_EP register is set and the interrupt handling is entered,
check the transfer data size.
2. Configure the DMA register setting relevant to the number of transfers and block size corresponding to the transfer data
size, and then enable DMA to start the transfer.
3. After the transfer, clear the EPnDRQ bit (n=1 or 2) of the USBHOST_INTR_HOST_EP register and the interrupt source
flag of DMAC, and return from the interrupt handling.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 478
Universal Serial Bus (USB) Host
To transfer the odd bytes of data via DMA, write the last byte of data by software transfer.
Figure 34-15. Odd Bytes Transfer in the OUT Direction
15 87 0
0x22 0x11
(byte 2) (byte 1)
0x44 0x33
(byte 4) (byte 3) DMA Transfer (Write)
0x66 0x55
(byte 6) (byte 5)
0x88 0x77
(byte 8) (byte 7)
Endpoint n Buffer
The data transfer in the IN direction (device to host) must be processed in the following sequence:
1. Configure the DMA register setting relevant to the number of transfers and block size corresponding to the total data size,
and then enable DMA to start the transfer.
2. Enable DMAE bit of the USBHOST_HOST_EPn_CTL (n = 1 or 2) register and EPnDRQE bit of the
USBHOST_HOST_DMA_ENBL (n = 1 or 2) register.
3. After the transfer, reconfigure the DMA controller using an interrupt generated by the DMAC and clear the flag to return
from interrupt handling.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 479
Universal Serial Bus (USB) Host
DM_EPnDRQE bit
1 EPnDRQ bit is EPnDRQ bit is
(n=1 or 2)
cleared by cleared by
software software
EPnDRQ bit
(n=1 or 2)
To transfer the data size corresponding to odd number of bytes via DMA, either of the following methods can be used:
■ Use the software transfer only for the last data, and read the low-order byte (HOST_EPn_RW1_DR: n=1 or 2).
■ Transfer all the data + 1 byte via DMA, and discard the last data after an endian conversion.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 480
Universal Serial Bus (USB) Host
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 481
Universal Serial Bus (USB) Host
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 482
35. LCD Direct Drive
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC 6 MCU Liquid Crystal Display (LCD) drive system is a highly configurable peripheral that allows the device to
directly drive STN and TN segment LCDs.
35.1 Features
The PSoC 6 MCU LCD segment drive block has the following features:
■ Supports up to 61 segments and 8 commons
■ Supports Type A (standard) and Type B (low-power) drive waveforms
■ Any GPIO can be configured as a common or segment
■ Supports five drive methods:
❐ Digital correlation
❐ PWM at 1/2 bias
❐ PWM at 1/3 bias
❐ PWM at 1/4 bias
■ Ability to drive 3-V displays from 1.8 V VDD in Digital Correlation mode
■ Operates in Active, Sleep, and Deep Sleep modes
■ Digital contrast control
35.2 Architecture
35.2.1 LCD Segment Drive Overview
A segmented LCD panel has the liquid crystal material between two sets of electrodes and various polarization and reflector
layers. The two electrodes of an individual segment are called commons (COM) or backplanes and segment electrodes
(SEG). From an electrical perspective, an LCD segment can be considered as a capacitive load; the COM/SEG electrodes
can be considered as the rows and columns in a matrix of segments. The opacity of an LCD segment is controlled by varying
the root-mean-square (RMS) voltage across the corresponding COM/SEG pair.
The following terms/voltages are used in this chapter to describe LCD drive:
■ VRMSOFF: The voltage that the LCD driver can realize on segments that are intended to be off.
■ VRMSON: The voltage that the LCD driver can realize on segments that are intended to be on.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 483
LCD Direct Drive
■ Discrimination Ratio (D): The ratio of VRMSON and VRMSOFF that the LCD driver can realize. This depends on the type of
waveforms applied to the LCD panel. Higher discrimination ratio results in higher contrast.
Liquid crystal material does not tolerate long term exposure to DC voltage. Therefore, any waveforms applied to the panel
must produce a 0-V DC component on every segment (on or off). Typically, LCD drivers apply waveforms to the COM and
SEG electrodes that are generated by switching between multiple voltages. The following terms are used to define these
waveforms:
■ Duty: A driver is said to operate in 1/M duty when it drives ‘M’ number of COM electrodes. Each COM electrode is effec-
tively driven 1/M of the time.
■ Bias: A driver is said to use 1/B bias when its waveforms use voltage steps of (1/B) × VDRV. VDRV is the highest drive
voltage in the system (equals VDD). The PSoC 6 MCU supports 1/2, 1/3, and 1/4 biases in PWM drive modes.
■ Frame: A frame is the length of time required to drive all the segments. During a frame, the driver cycles through the com-
mons in sequence. All segments receive 0-V DC (but non-zero RMS voltage) when measured over the entire frame.
The PSoC 6 MCU supports two different types of drive waveforms in all drive modes. These are:
■ Type-A Waveform: In this type of waveform, the driver structures a frame into M sub-frames. ‘M’ is the number of COM
electrodes. Each COM is addressed only once during a frame. For example, COM[i] is addressed in sub-frame i.
■ Type-B Waveform: The driver structures a frame into 2M sub-frames. The two sub-frames are inverses of each other.
Each COM is addressed twice during a frame. For example, COM[i] is addressed in sub-frames i and M+i. Type-B wave-
forms are slightly more power efficient because it contains fewer transitions per frame.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 484
LCD Direct Drive
PWM Generator
COM
VPWM VLCD
PWM Generator
SEG
VPWM
VDDD
0
t
VLCD
VDDDD
2/3 VDDD
1/3 VDDD
0
t
The output waveform of the drive electronics is a PWM waveform. With the Indium Tin Oxide (ITO) panel resistance and the
segment capacitance to filter the PWM, the voltage across the LCD segment is an analog voltage, as shown in Figure 35-1.
This figure illustrates the generation of a 1/3 bias waveform (four commons and voltage steps of VDD/3). See the Clocking
System chapter on page 242 for details.
The PWM is derived from either CLK_LF (32 kHz, low-speed operation) or CLK_PERI (high-speed operation). See the Clock-
ing System chapter on page 242 for more details of peripheral and low-frequency clocks. The filtered analog voltage across
the LCD segments typically runs at low frequency for segment LCD driving.
Figure 35-2 and Figure 35-3 illustrate the Type A and Type B waveforms for COM and SEG electrodes for 1/2 bias and 1/4
duty. Only COM0/COM1 and SEG0/SEG1 are drawn for demonstration purpose. Similarly, Figure 35-4 and Figure 35-5 illus-
trate the Type A and Type B waveforms for COM and SEG electrodes for 1/3 bias and 1/4 duty.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 485
LCD Direct Drive
VDD
COM0 1/2 VDD
VDD
VDD
VDD
SEG1 1/2 VDD
0
t0 t1 t2 t3
One Frame
VDD
Segment On:
0 VRMS = 0.661 VDD
COM0 -SEG0
-VDD
VDD
VDD
COM1 -SEG0 0
Segment On:
VRMS = 0.661 VDD
-VDD
VDD
COM1 -SEG1 0 Segment Off:
VRMS = 0.433 VDD
-VDD
t0 t1 t2 t3
Discrimination ratio:
Segment is On D = 0.661/0.433 = 1.527
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 486
LCD Direct Drive
VDD
COM0 1/2 V DD
VDD
COM1 1/2 V DD
VDD
SEG0 1/2 V DD
VDD
SEG1 1/2 V DD
0
t0 t1 t2 t3
One Frame
VDD
COM0 -SEG0 Segment On:
0 VRMS = 0.661 VDD
-VDD
VDD
COM0 -SEG1 0 Segment Off:
VRMS = 0.433 VDD
-VDD
VDD
COM1 -SEG0 Segment On:
0
VRMS = 0.661 VDD
-VDD
VDD
COM1 -SEG1 Segment Off:
0
VRMS = 0.433 VDD
-VDD
t0 t1 t2 t3
Discrimination ratio:
Segment is On D = 0.661/0.433 = 1.527
Segment is Off
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 487
LCD Direct Drive
VDD
COM0 2/3 V DD
1/3 V DD
0
VDD
2/3 V DD
COM1
1/3 V DD
0
VDD
2/3 V DD
SEG0
1/3 V DD
0
VDD
SEG1 2/3 V DD
1/3 V DD
0
t0 t1 t2 t3
One Frame
VDD
Segment On:
COM0 -SEG0
0 VRMS = 0.577 V DD
-VDD
VDD
COM0 -SEG1 0 Segment Off:
VRMS = 0.333 V DD
-VDD
VDD
COM1 -SEG0 Segment On:
0
VRMS = 0.577 V DD
-VDD
VDD
Discrimination ratio:
Segment is On D = 0.577/0.333 = 1.732
Segment is Off
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 488
LCD Direct Drive
VDD
COM0 2/3 V DD
1/3 V DD
0
VDD
2/3 V DD
COM1
1/3 V DD
0
VDD
2/3 V DD
SEG0
1/3 V DD
0
VDD
SEG1 2/3 V DD
1/3 V DD
0
t0 t1 t2 t3
One Frame
VDD
Segment On:
COM0 -SEG0 0 VRMS = 0.577 V DD
-VDD
VDD
COM0 -SEG1 0 Segment Off:
VRMS = 0.333 V DD
-VDD
VDD
VDD
Discrimination ratio:
Segment is On D = 0.577/0.333 = 1.732
Segment is Off
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 489
LCD Direct Drive
The effective RMS voltage for ON and OFF segments can be calculated easily using these equations:
V 2
2B – 2 + 2M – 1 V
RMS OFF = ----------------------------------------------------x ------------
DRV
2M B
Equation 35-1
V 2
2B + 2 M – 1 V
RMS ON = --------------------------------------x ------------
DRV
2M B
Equation 35-2
Where B is the bias and M is the duty (number of COMs).
For example, if the number of COMs is four, the resulting discrimination ratios (D) for 1/2 and 1/3 biases are 1.528 and 1.732,
respectively. 1/3 bias offers better discrimination ratio in two and three COM drives also. Therefore, 1/3 bias offers better con-
trast than 1/2 bias and is recommended for most applications. 1/4 bias is available only in high-speed operation of the LCD.
They offer better discrimination ratio especially when used with high COM designs (more than four COMs).
When the low-speed operation of LCD is used, the PWM signal is derived from the 32-kHz CLK_LF. To drive a low-capaci-
tance display with acceptable ripple and rise/fall times using a 32-kHz PWM, additional external series resistances of 100 k-
1 M should be used. External resistors are not required for PWM frequencies greater than ~1 MHz. The ideal PWM fre-
quency depends on the capacitance of the display and the internal ITO resistance of the ITO routing traces.
The 1/2 bias mode has the advantage that PWM is only required on the COM signals; the SEG signals use only logic levels,
as shown in Figure 35-2 and Figure 35-3.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 490
LCD Direct Drive
VDD
COM0
VDD
COM1
VDD
SEG0
VDD
SEG1
0
t0 t1 t2 t3
One Frame
VDD
Segment On:
COM0 -SEG0 0 VRMS = 0.791 V DD
-VDD
VDD
COM0 -SEG1 0 Segment Off:
VRMS = 0.612 V DD
-VDD
VDD
COM1 -SEG0 Segment On:
0
VRMS = 0.791 V DD
-VDD
VDD
Discrimination ratio:
Segment is On D = 0.791/0.612 = 1.291
Segment is Off
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 491
LCD Direct Drive
VDD
COM0
VDD
COM1
VDD
SEG0
VDD
SEG1
0
t0 t1 t2 t3
One Frame
VDD
Segment On:
COM0 -SEG0 0 VRMS = 0.791 V DD
-VDD
VDD
COM0 -SEG1 0 Segment Off:
VRMS = 0.612 V DD
-VDD
VDD
COM1 -SEG0 Segment On:
0
VRMS = 0.791 V DD
-VDD
VDD
Discrimination ratio:
Segment is On D = 0.791/0.612 = 1.291
Segment is Off
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 492
LCD Direct Drive
The RMS voltage applied to on and off segments can be calculated as follows:
V
M – 1
RMS OFF = ------------------x V DD
2M
V
2 + M – 1
RMS ON = ----------------------------x V DD
2M
Where B is the bias and M is the duty (number of COMs). This leads to a discrimination ratio (D) of 1.291 for four COMs.
Digital correlation mode also has the ability to drive 3-V displays from 1.8-V VDD.
VDD
COM0 2/3 VDD
1/3 VDD
0
VDD
COM1 2/3 VDD
1/3 VDD
0
VDD
2/3 VDD
SEG0
1/3 VDD
0
VDD
SEG1 2/3 VDD
1/3 VDD
0
t0 t1 t2 t3 dt t0 t1 t2 t3 dt
Dead-Time
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 493
LCD Direct Drive
High-Speed (HS)
LCD Master
High-Frequency Generator
Clock, CLK_PERI
HS COM Signals
AHB
AHB HS SEG Signals COM
interface Signals LCD com[0]
HSIO
HS Sub Frame Data LCD seg[0]
Active SEG Matrix
Power Domain Signals
Deep Sleep Multiplexer
Low-Speed (LS)
Power Domain LCD Master LCD com[1]
Generator
Sub Frame HSIO
LS COM Signals Data LCD seg[1] Matrix
Low Frequency LS SEG Signals LCD
Clock, CLK_LF Pin
(32 kHz) Logic
LS Sub Frame Data
LCD Mode
Select
(HS/LS)
Config & Control
Registers
The LCD controller block contains two generators, one with 35.3.1 High-Speed and Low-Speed
a high-speed clock source CLK_PERI and the other with a
Master Generators
low-speed clock source (32 kHz) derived from the CLK_LF.
These are called high-speed LCD master generator and The high-speed and low-speed master generators are simi-
low-speed LCD master generator, respectively. Both the lar to each other. The only exception is that the high-speed
generators support PWM and digital correlation drive version has larger frequency dividers to generate the frame
modes. PWM drive mode with low-speed generator requires and sub-frame periods. The high-speed generator is in the
external resistors, as explained in PWM Drive on page 484. active power domain and the low-speed generator is in the
Deep Sleep power domain. A single set of configuration reg-
The multiplexer selects one of these two generator outputs
isters is provided to control both high-speed and low-speed
to drive LCD, as configured by the firmware. The LCD pin
blocks. Each master generator has the following features
logic block routes the COM and SEG outputs from the gen-
and characteristics:
erators to the corresponding I/O matrices. Any GPIO can be
used as either COM or SEG. This configurable pin assign- ■ Register bit configuring the block for either Type A or
ment for COM or SEG is implemented in GPIO and I/O Type B drive waveforms (LCD_MODE bit in LCD0_-
matrix; see High-Speed I/O Matrix. These two generators CONTROL register).
share the same configuration registers. These memory ■ Register bits to select the number of COMs (COM_NUM
mapped I/O registers are connected to the system bus field in LCD0_CONTROL register).
(AHB) using an AHB interface. ■ Operating mode configuration bits enabled to select one
The LCD controller works in three device power modes: of the following:
Active, Sleep, and Deep Sleep. High-speed operation is ❐ Digital correlation
supported in Active and Sleep modes. Low-speed operation ❐ PWM 1/2 bias
is supported in Active, Sleep, and Deep Sleep modes. The
LCD controller is unpowered in Hibernate mode. ❐ PWM 1/3 bias
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 494
LCD Direct Drive
❐ PWM 1/4 bias (not supported in low-speed genera- ration and control register. The LCD pin logic uses the sub-
tor) frame signal from the multiplexer to choose the display data.
❐ Off/disabled. Typically, one of the two generators will This pin logic will be replicated for each LCD pin.
be configured to be Off
OP_MODE and BIAS fields in LCD0_CONTROL bits 35.3.3 Display Data Registers
select the drive mode. Each LCD segment pin is part of an LCD port with its own
■ A counter to generate the sub-frame timing. The SUB- display data register, LCD0_DATAx. The device has eight
FR_DIV field in the LCD0_DIVIDER register determines such LCD ports. Note that these ports are not real pin ports
the duration of each sub-frame. If the divide value written but the ports/connections available in the LCD hardware for
into this counter is C, the sub-frame period is 4 × (C+1). mapping the segments to commons. Each LCD segment
The low-speed generator has an 8-bit counter. This configured is considered as a pin in these LCD ports. The
counter generates a maximum half sub-frame period of LCD0_DATAxx registers are 32-bit wide and store the ON/
8 ms from the 32-kHz CLK_LF. The high-speed genera- OFF data for all SEG-COM combination enabled in the
tor has a 16-bit counter. design. For example, LCD0_DATA0x holds SEG-COM data
■ A counter to generate the dead time period. These for COM0 to COM3 and LCD0_DATA1x holds SEG-COM
counters have the same number of bits as the sub-frame data for COM4 to COM7. The bits [4i+3:4i] (where ‘i’ is the
period counters and use the same clocks. DEAD_DIV pin number) of each LCD0_DATAxx register represent the
field in the LCD0_DIVIDER register controls the dead ON/OFF data for Pin[i], as shown in Table 35-2. The
time period. LCD0_DATAxx register should be programmed according to
the display data of each frame. The display data registers
are Memory Mapped I/O (MMIO) and accessed through the
35.3.2 Multiplexer and LCD Pin Logic AHB slave interface. See the PSoC 61 datasheet/PSoC 62
The multiplexer selects the output signals of either high- datasheet for the pin connections.
speed or low-speed master generator blocks and feeds it to
the LCD pin logic. This selection is controlled by the configu-
Table 35-2. SEG-COM Mapping Example of LCD0_DATA00 Register (each SEG is a pin of the LCD port)
BITS[31:28] = PIN_7[3:0] BITS[27:24] = PIN_6[3:0]
PIN_7-COM3 PIN_7-COM2 PIN_7-COM1 PIN_7-COM0 PIN_6-COM3 PIN_6-COM2 PIN_6-COM1 PIN_6-COM0
BITS[23:20] = PIN_5[3:0] BITS[19:16] = PIN_4[3:0]
PIN_5-COM3 PIN_5-COM2 PIN_5-COM1 PIN_5-COM0 PIN_4-COM3 PIN_4-COM2 PIN_4-COM1 PIN_4-COM0
BITS[15:12] = PIN_3[3:0] BITS[11:8] = PIN_2[3:0]
PIN_3-COM3 PIN_3-COM2 PIN_3-COM1 PIN_3-COM0 PIN_2-COM3 PIN_2-COM2 PIN_2-COM1 PIN_2-COM0
BITS[7:3] = PIN_1[3:0] BITS[3:0] = PIN_0[3:0]
PIN_1-COM3 PIN_1-COM2 PIN_1-COM1 PIN_1-COM0 PIN_0-COM3 PIN_0-COM2 PIN_0-COM1 PIN_0-COM0
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 495
Section E: Analog Subsystem
Programmable Analog
Temperature
Sensor
Boundary Scan
Color Key:
Power Modes and
Domains
System
DeepSleep Mode
System
Hibernate Mode
Backup
Domain
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 496
36. Analog Reference Block
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The Analog Reference block (AREF) generates highly accurate reference voltage and currents needed by the programmable
analog subsystem (PASS) and CapSense (CSD) blocks.
36.1 Features
■ Provides accurate bandgap references for PASS and CSD subsystems
■ 1.2-V voltage reference (VREF) generator
■ Option to output alternate voltage references routed from SRSS or from an external pin
■ Zero dependency to absolute temperature (IZTAT) flat current reference generation, which is independent of temperature
variations
■ Option to generate IZTAT from SRSS generated current reference
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 497
Analog Reference Block
36.2 Architecture
Figure 36-1. AREF Block Diagram
External reference
input pin (VREF) or
SRSS Current Reference Scale (x4) bypass capacitor for
(250 nA) Current IZTAT To SAR ADC
MUX
internal reference
Mirror and CapSense
IZTAT IZTAT
Generator 1 uA
MUX
To
Filter VREF
SAR ADC
VDDA/2 Buffer VDDA
SRSS Voltage Reference (0.8 V) Core
PASS_AREF_AREF_CTRL.
VREF_SEL
Figure 36-1 shows the architecture of the Analog Reference (AREF) block. It consists of a bandgap reference circuit, which generates 1.2 V voltage reference (VREFBG). Options
for the voltage reference include 0.8 V reference from the SRSS block and an external reference from a dedicated pin (see the PSoC 61 datasheet/PSoC 62 datasheet for pin
number). Application use cases of the selected voltage reference (VREF) include setting the reference SAR ADC, and CapSense blocks.
The AREF block also generates zero-temperature coefficient IZTAT reference current (1 µA), which remains stable over temperature. The other option for IZTAT reference is the
1 µA current derived from the 250-nA reference current from SRSS. Selected IZTAT reference current is used in SAR ADC, and CapSense blocks.
Current mirror circuits are used to generate multiple current references to drive to different analog blocks.
The following sections explain the configurations in detail.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 498
Analog Reference Block
The AREF block is enabled by writing ‘1’ into the ENABLED bit of the PASS_AREF_AREF_CTRL register.
AREF_MODE Description
0 (NORMAL) Normal startup mode
1 (FAST_START) Fast startup mode
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 499
Analog Reference Block
36.3 Registers
Table 36-5. List of AREF Registers
Register Comment Features
PASS_AREF_AREF_CTRL AREF control register Reference selection, startup time, and low-power mode.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 500
37. Low-Power Comparator
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
PSoC 6 MCUs have two Low-Power comparators, which can perform fast analog signal comparison of internal and external
analog signals in all system power modes. Low-Power comparator output can be inspected by the CPU, used as an interrupt/
wakeup source to the CPU when in CPU Sleep mode, used as a wakeup source to system resources when in System Deep
Sleep or Hibernate mode, or fed to GPIO or trigger multiplexer (see Trigger Multiplexer Block chapter on page 294) as an
asynchronous or synchronous signal (level or pulse).
37.1 Features
The PSoC 6 MCU comparators have the following features:
■ Configurable input pins
■ Programmable power and speed
■ Ultra low-power mode support
■ Each comparator features a one-sided hysteresis option
■ Rising edge, falling edge, combined rising and falling edge detection at the comparator output
■ Local reference voltage generation
■ Wakeup source from low-power modes
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 501
Low-Power Comparator
37.2 Architecture
Figure 37-1 shows the block diagram for the Low-Power comparator.
Figure 37-1. Low-Power Comparator Block Diagram
Routing
Switches Comparator0
inp0 edge + pulse dsi_comp0
IP0 + Sync (To HSIOM or trigger
Sync
Sync
P0A P0B AP0 BP0 multiplexer)
inn0
IN0 -
P1A P1B AN0 BN0 VN0
out0
out_wk0
Edge
Comparator1 Detector
inp1
IP1 + Interrupt to
P2A P2B AP1 BP1 combine &
CPU
inn1 mask
IN1 - Subsystem
P3A P3B AN1 BN1 VN1
out_wk1
AA_SL AA_SR
AMUXBUS B
Switches To MMIO
Wake up signals to
System Resources Sub-System
The following sections describe the operation of the PSoC 6 uses the AMUXBUS for the connection. See the I/O
MCU Low-Power comparator, including input configuration, System chapter on page 261 for more details on connecting
power and speed modes, output and interrupt configuration, the GPIO to AMUXBUS A/B or setting up the GPIO for
hysteresis, and wakeup from low-power modes. comparator input.
Refer to the LPCOMP_CMP0_SW, LPCOMP_CMP1_SW,
37.2.1 Input Configuration LPCOMP_CMP0_SW_CLEAR, and
Low-Power comparators can operate with the following input LPCOMP_CMP1_SW_CLEAR registers in the registers
options: TRM to understand how to control the internal routing
switches shown in Figure 37-1.
■ Compare two voltages from external pins.
■ Compare a voltage from an external pin against an If the inverting input of a comparator is routed to a local
internally generated analog-signal (through AMUXBUS). voltage reference, the LPREF_EN bit in the
LPCOMP_CONFIG register must be set to enable the
■ Compare two internal voltages through AMUXBUS-A/ voltage reference.
AMUXBUS-B.
■ Compare internal and external signals with a locally- 37.2.2 Output and Interrupt Configuration
generated reference voltage. Note that this voltage is not
a precision reference and can vary from 0.45 V–0.75 V. Both Comparator0 and Comparator1 have hardware outputs
available at dedicated pins. See the PSoC 61 datasheet/
See the PSoC 61 datasheet/PSoC 62 datasheet for detailed
PSoC 62 datasheet for the location of comparator output
specifications of the Low-Power comparator.
pins.
Note that AMUXBUS connections are not available in Deep
Sleep and Hibernate modes. If Deep Sleep or Hibernate
operation is required, the Low-Power comparator must be Firmware readout of Comparator0 and Comparator1 outputs
connected to the dedicated pins. This restriction also are available at the OUT0 and OUT1 bits of the
includes routing of any internally-generated signal, which LPCOMP_STATUS register (Table 37-1). The output of each
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 502
Low-Power Comparator
comparator is connected to a corresponding edge detector interrupt. Alternatively, COMP0_MASK bit and
block. This block determines the edge that triggers the COMP1_MASK bit of the LPCOMP_INTR_MASK register
interrupt. The edge selection and interrupt enable is can be used to mask the Comparator0 and Comparator1
configured using the INTTYPE0 and INTTYPE1 bitfields in interrupts to the CPU. Only the masked interrupts will be
the LPCOMP_CMP0_CTRL and LPCOMP_CMP1_CTRL serviced by the CPU. After the interrupt is processed, the
registers for Comparator0 and Comparator1, respectively. interrupt should be cleared by writing a ‘1’ to the COMP0
Using the INTTYPE0 and INTTYPE1 bits, the interrupt type and COMP1 bits of the LPCOMP_INTR register in firmware.
can be selected to disabled, rising edge, falling edge, or If the interrupt to the CPU is not cleared, it stays active
both edges, as described in Table 37-1. regardless of the next compare events and interrupts the
CPU continuously. Refer to the Interrupts chapter on
Each comparator’s output can also be routed directly to a
page 56 for details.
GPIO pin through the HSIOM. See the I/O System chapter
on page 261 for more details. LPCOMP_INTR_SET register bits [1:0] can be used to
assert an interrupt for firmware debugging.
During an edge event, the comparator will trigger an
interrupt. The interrupt request is registered in the COMP0 In Deep Sleep mode, the wakeup interrupt controller (WIC)
bit and COMP1 bit of the LPCOMP_INTR register for can be activated by a comparator edge event, which then
Comparator0 and Comparator1, respectively. Both wakes up the CPU. Similarly in Hibernate mode, the
Comparator0 and Comparator1 share a common interrupt LPCOMP can wake up the system resources sub-system.
signal output (see Figure 37-1), which is a logical OR of the Thus, the LPCOMP has the capability to monitor a specified
two interrupts and mapped as the Low-Power comparator signal in low-power modes. See the Power Supply and
block’s interrupt in the CPU NVIC. Refer to the Monitoring chapter on page 218 and the Device Power
Interrupts chapter on page 56 for details. If both the Modes chapter on page 225 for more details.
comparators are used in a design, the COMP0 and COMP1
bits of the LPCOMP_INTR register must be read in the
interrupt service routine to know which one triggered the
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 503
Low-Power Comparator
The power or speed setting for Comparator0 is configured using the MODE0 bitfield of the LPCOMP_CMP0_CTRL register.
Similarly, the power or speed setting for Comparator1 is configured using the MODE1 bitfield of the LPCOMP_CMP1_CTRL
register. The power consumption and response time vary depending on the selected power mode; power consumption is
highest in fast mode and lowest in ultra-low-power mode, response time is fastest in fast mode and slowest in ultra-low-power
mode. Refer to the PSoC 61 datasheet/PSoC 62 datasheet for specifications for the response time and power consumption
for various power settings.
The comparators can also be enabled or disabled using these bitfields, as described in Table 37-2.
Note: The output of the comparator may glitch when the power mode is changed while comparator is enabled. To avoid this,
disable the comparator before changing the power mode.
Additionally, the entire Low-Power comparator system can be enabled or disabled globally using the LPCOMP_CONFIG[31]
bit. See the registers TRM for details of these bitfields.
37.2.4 Hysteresis
For applications that compare signals close to each other and slow changing signals, hysteresis helps to avoid oscillations at
the comparator output when the signals are noisy. For such applications, a fixed hysteresis may be enabled in the comparator
block. See the PSoC 61 datasheet/PSoC 62 datasheet for the hysteresis voltage range.
The hysteresis level is enabled/disabled by using the HYST0 and HYST1 bitfields in the LPCOMP_CMP0_CTRL and
LPCOMP_CMP1_CTRL registers for Comparator0 and Comparator1, as described in Table 37-3.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 504
Low-Power Comparator
Register Function
LPCOMP_CONFIG LPCOMP global configuration register
LPCOMP_INTR LPCOMP interrupt register
LPCOMP_INTR_SET LPCOMP interrupt set register
LPCOMP_INTR_MASK LPCOMP interrupt request mask register
LPCOMP_INTR_MASKED LPCOMP masked interrupt output register
LPCOMP_STATUS Output status register
LPCOMP_CMP0_CTRL Comparator0 configuration register
LPCOMP_CMP1_CTRL Comparator1 configuration
LPCOMP_CMP0_SW Comparator0 switch control
LPCOMP_CMP1_SW Comparator1 switch control
LPCOMP_CMP0_SW_CLEAR Comparator0 switch control clear
LPCOMP_CMP1_SW_CLEAR Comparator1 switch control clear
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 505
38. SAR ADC
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
The PSoC 6 MCU has a 12-bit successive approximation register analog-to-digital converter (SAR ADC). The 12-bit, 1-Msps
SAR ADC is designed for applications that require moderate resolution and high data rate.
38.1 Features
■ Maximum sample rate of 1 Msps
■ Sixteen individually configurable logical channels that can scan eleven unique input channels. Each channel has the fol-
lowing features:
❐ Input from eight dedicated pins (eight single-ended mode or four differential inputs) or internal signals (AMUXBUS or
temperature sensor)
❐ Each channel may choose one of the four programmable acquisition times to compensate for external factors (such as
high input impedance sources with long settling times)
❐ Single-ended or differential measurement
❐ Averaging and accumulation
❐ Double-buffered results
■ Result may be left- or right-aligned, or may be represented in 16-bit sign extended
■ Scan can be triggered by firmware, trigger from other peripherals or pins
❐ One-shot – periodic or continuous mode
■ Hardware averaging support
❐ First order accumulate
❐ Supports 2, 4, 8, 16, 32, 64, 128, and 256 samples (powers of 2)
■ Selectable voltage references
❐ Internal VDDA and VDDA/2 references
❐ Internal 1.2-V reference with buffer
❐ External reference
■ Interrupt generation
❐ End of scan
❐ Saturation detect and over-range (configurable) detect for every channel
❐ Scan results overflow
❐ Collision detect
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 506
SAR ADC
38.2 Architecture
Figure 38-1. Block Diagram
External Reference or Bypass Capacitor
VREF Buffer
for Internal Reference
1.2V from AREF
Pin 0 VDDA
VDDA / 2
Pin 1
Pin 2
SAR_CTRL
Pin 3
Pins of SARMUX Port
Pin 4
VREF
Pin 5 VPLUS SAR_CHAN_WORK_UPDATED SAR_CHAN_RESULT_UPDATED
Accumulate /
SARMUX
Pin 6 Average /
SAR ADC SAR_CHAN_WORK0 SAR_CHAN_RESULT0
Pin 7 VMINUS Align / to to
Sign extend SAR_CHAN_WORK15 SAR_CHAN_RESULT15
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 507
SAR ADC
Figure 38-1 shows the simplified block diagram of PSoC 6 To get a single-ended conversion with 12 bits, you must con-
MCU SAR ADC system, with important registers shown in nect VREF to the negative input of the SAR ADC; then, the
blue. Preceding the SAR ADC is the SARMUX, which can input range can be from 0 to 2 × VREF.
route external pins and internal signals (AMUXBUS A/
AMUXBUS B or temperature sensor output) to the internal Note that temperature sensor can only be used in single-
channels of SAR ADC. The sequencer controller (SARSEQ) ended mode.
is used to control SARMUX and SAR ADC to do an auto-
matic scan on all enabled channels without CPU interven- 38.2.1.2 Input Range
tion. SARSEQ also performs pre-processing such as
All inputs should be in the range of VSSA to VDDA. Input volt-
averaging and accumulating the output data.
age range is also limited by VREF. If voltage on negative
The result from each channel is double-buffered and a com- input is Vn and the ADC reference is VREF, the range on the
plete scan may be configured to generate an interrupt at the positive input is Vn ± VREF. This criterion applies for both
end of the scan. The sequencer may also be configured to single-ended and differential modes. In single-ended mode,
flag overflow, collision, and saturation errors that can be Vn is connected to VSSA, VREF or an external input.
configured to assert an interrupt.
Note that Vn ± VREF should be in the range of VSSA to VDDA.
For example, if negative input is connected to VSSA, the
38.2.1 SAR ADC Core range on the positive input is 0 to VREF, not –VREF to VREF.
This is because the signal cannot go below VSSA. Only half
The PSoC 6 MCU SAR ADC core is a 12-bit SAR ADC. The
of the ADC range is usable because the positive input signal
maximum sample rate for this ADC is 1 Msps. The SAR
cannot swing below VSS, which effectively only generates
ADC core has the following features:
an 11-bit result.
■ Fully differential architecture; also supports single-ended
mode
■ 12-bit resolution
■ Four programmable acquisition times
■ Seven programmable power levels
■ Supports single and continuous conversion mode
SAR_CTRL register contains the bitfields that control the
operation of SAR ADC core. See the registers TRM for more
details of this register.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 508
SAR ADC
2 x VDD
5
VREF = V DD
Usable Range
Usable
Range
VREF = V DD / 2
Range
VREF = V DD
2 2 2
VREF = V DD / 2
-Vin
VREF = 1.2
-Vin
-Vin
VREF = V DD / 2
1 1 1
VREF = V DD
VREF = 1.2
VREF = 1.2
0 0 0
-1 -1 -1
Unusable
Unusable Unusable Range
Range Range
-2 -2 -2
-VDD
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 509
SAR ADC
mode voltage.
Note that single-ended conversions with VMINUS connected to the pins with SARMUX connectivity are electrically equivalent
to differential mode. However, when the odd pin of each differential pair is connected to the common alternate ground, these
conversions are 11-bit because measured signal value (SARMUX.vplus) cannot go below ground.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 510
SAR ADC
tACQ
SWACQ
ADC
Clocks
The acquisition time should be sufficient to charge the internal hold capacitor of the ADC through the resistance of the routing
path, as shown in Figure 38-3. The recommended value of acquisition time is:
Tacq >= 9 × (Rsrc + Rmux + Racqsw) × Csh
Where:
■ Rsrc = Source resistance
■ Rmux = SARMUX switch resistance
■ Racqsw = Sample and hold switch
■ Rmux + Racqsw ~= 1000 ohms
■ Csh ~= 10pF
This depends on the routing path (see Analog Routing on page 513 for details).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 511
SAR ADC
SARADC CLK
trigger
SOC
sample
18 clock cycles
EOC
Next
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 512
SAR ADC
38.2.2 SARMUX
SARMUX is an analog dedicated programmable multiplexer. The main features of SARMUX are:
■ Controlled by sequencer controller block (SARSEQ) or firmware
■ Internal temperature sensor
■ Multiple inputs:
❐ Analog signals from pins (port 2)
❐ Temperature sensor output (settling time for the temperature sensor is about 1 µs)
❐ AMUXBUS A/AMUXBUS B
Pin 0
MUX_FW_P0_VMINUS MUX_FW_P0_VPLUS
Pin 1
MUX_FW_P1_VMINUS MUX_FW_P1_VPLUS
Pin 2
MUX_FW_P2_VMINUS MUX_FW_P2_VPLUS
Pin 3
MUX_FW_P3_VMINUS MUX_FW_P3_VPLUS
Pins of SARMUX Port
Pin 4
MUX_FW_P4_VMINUS MUX_FW_P4_VPLUS
Pin 5
MUX_FW_P5_VMINUS MUX_FW_P5_VPLUS
Pin 6
MUX_FW_P6_VMINUS MUX_FW_P6_VPLUS
Pin 7
MUX_FW_P7_VMINUS MUX_FW_P7_VPLUS
MUX_FW_TEMP_VPLUS
VSSA_KELVIN
MUX_FW_VSSA_VMINUS
Enable
VPLUS
Temp Temperature VSSA
Sensor SAR ADC
VMINUS
SARMUX
Sequencer control: In the sequencer control mode, the SARMUX switches are controlled by the SARSEQ block. After con-
figuring each channel’s analog routing, it enables multi-channel, automatic scan in a round-robin fashion, without CPU inter-
vention. Not every switch in analog routing can be controlled by the sequencer, as Figure 38-5 shows.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 513
SAR ADC
SAR_MUX_SWITCH_SQ_CTRL register can be used to enable/disable SARSEQ control of SARMUX switches. See section
19.3.4 SARSEQ for more details of sequencer control.
Firmware control: In firmware control, registers are written by the firmware to connect required signals to VPLUS/VMINUS
terminals before starting the scan. Firmware can control every switch in SARMUX, as Figure 38-5 shows. However, firmware
control needs continuous CPU intervention for multi-channel scans. The SAR_MUX_SWITCH0 register can be used by the
firmware to control SARMUX switches. Note that additional register writes may be required to connect blocks outside the
SARMUX.
The PSoC 6 MCU analog interconnection is very flexible. SAR ADC can be connected to multiple inputs via SARMUX, includ-
ing both external pins and internal signals. It can also connect to non-SARMUX ports through AMUXBUS A/AMUXBUS B, at
the expense of scanning performance (more parasitic coupling, longer RC time to settle).
38.2.3 SARREF
The main features of the SAR reference block (SARREF) are:
■ Reference options: VDDA, VDDA/2, 1.2-V bandgap, and external reference
■ Reference buffer and bypass capacitor to enhance internal reference drive capability
The external VREF pin is also used to bypass the internal references. The VREF_SEL bitfield in the SAR_CTRL register can be
used to select which one of these references is connected to the SAR ADC.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 514
SAR ADC
SAR performance varies with the mode of reference and the VDDA supply.
Table 38-3. Reference Modes
Maximum SAR ADC
Reference Mode Maximum Sample Rate
Clock Frequency
External Reference 18 MHz 1 Msps
Internal reference without bypass capacitor 1.8 MHz 100 ksps
Internal reference with bypass capacitor 18 MHz 1 Msps
VDDA as reference 18 MHz 1 Msps
Reference buffer startup time varies with different bypass capacitor size. Table 38-4 lists two common values for the bypass
capacitor and its startup time specification. If reference selection is changed between scans or when scanning after device
low-power modes in which the ADC is not active (see the Device Power Modes chapter on page 225), make sure the refer-
ence buffer is settled before the SAR ADC starts sampling.
Table 38-4. Bypass Capacitor Values vs Startup Time
Capacitor Value Startup Time
Internal reference with bypass capacitor (50 nF) 120 µs
Internal reference with bypass capacitor (100 nF) 210 µs
Internal reference without bypass capacitor 10 µs
38.2.3.3 Input Range versus Reference ❐ One of four programmable acquisition times
❐ Result averaging and accumulation
All inputs should be between VSSA and VDDA. The ADCs
input range is limited by VREF selection. If negative input is ■ Scan triggering
Vn and the ADC reference is VREF, the range on the positive ❐ One-shot, periodic, or continuous mode
input is Vn ± VREF. These criteria applies for both single- ❐ Triggered by any digital signal or input from GPIO pin
ended and differential modes as long as both negative and ❐ Triggered by internal block
positive inputs stay within VSSA to VDDA. ❐ Software triggered
■ Hardware averaging support
38.2.4 SARSEQ ❐ First order accumulate
SARSEQ is a dedicated control block that automatically ❐ 2, 4, 8, 16, 32, 64, 128, or 256 samples averaging
sequences the input mux from one channel to the next while (powers of 2)
placing the result in an array of registers, one per channel. ❐ Results in 16-bit representation
SARSEQ has the following functions:
■ Double buffering of output data
■ Controls SARMUX analog routing automatically without
CPU intervention ❐ Left or right adjusted results
■ Controls SAR ADC core such as selecting acquisition ❐ Results in working register and result register
times ■ Interrupt generation
■ Receives data from SAR ADC and pre-process (aver- ❐ Finished scan conversion
age, range detect) ❐ Channel saturation detection
■ Results are double-buffered; therefore, the CPU can ❐ Range (configurable) detection
safely read the results of the last scan while the next
❐ Scan results overflow
scan is in progress.
❐ Collision detect
The features of SARSEQ are:
■ Sixteen channels can be individually enabled as an 38.2.4.1 Channel Configuration
automatic scan without CPU intervention that can scan
The SAR_CHAN_CONFIGx register contains the following
eleven unique input channels
bitfields, which control the behavior of respective channels
■ Each channel has the following features: during a SARSEQ scan:
❐ Single-ended or differential mode ■ POS_PORT_ADDR and POS_PIN_ADDR select the
❐ Input from external pin or internal signal (AMUXBUS/ connection to VPLUS terminal of the ADC
temperature sensor)
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 515
SAR ADC
■ NEG_ADDR_EN, NEG_PORT_ADDR, and kable range detect interrupt (RANGE_INTR). The following
NEG_PIN_ADDR select the connection to VMINUS termi- conditions can be selected:
nal of the ADC 0: result < RANGE_LOW (below the range)
■ SAMPLE_TIME_SEL selects the acquisition time for the
channel 1: RANGE_LOW result < RANGE_HIGH (inside the
range)
■ AVG_EN enables the hardware averaging feature
■ DIFFERENTIAL_EN selects single-ended/differential 2: RANGE_HIGH result (above the range)
mode 3: result < RANGE_LOW || RANGE_HIGH result (outside
SAR_CHAN_EN contains the enable bits that can be used range)
to include or exclude a channel for the next SARSEQ scan. See Range Detection Interrupts on page 517 for details.
38.2.4.3 Range Detection This section describes each interrupt in detail. These inter-
rupts have an interrupt mask in the SAR_INTR_MASK reg-
The SARSEQ supports range detection to allow automatic ister. By making the interrupt mask low, the corresponding
detection of result values compared to two programmable interrupt source is ignored. The SAR interrupt is generated if
thresholds without CPU involvement. Range detection is the interrupt mask bit is high and the corresponding interrupt
defined by the SAR_RANGE_THRES register. The source is pending.
RANGE_LOW field in the SAR_RANGE_THRES register
When servicing an interrupt, the interrupt service routine
defines the lower threshold and RANGE_HIGH field defines
(ISR) can clear the interrupt source by writing a ‘1’ to the
the upper threshold of the range.
corresponding interrupt bit in the SAR_RANGE_INTR regis-
The RANGE_COND bitfield in the SAR_RANGE_COND ter, after reading the data.
register define the condition that triggers a channel mas-
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 516
SAR ADC
The SAR_INTR_MASKED register is the logical AND set the collision interrupt, which is intended for debug and
between the interrupts sources and the interrupt mask. This verification.
register provides a convenient way for the firmware to deter-
mine the source of the interrupt. 38.2.5.4 Range Detection Interrupts
For verification and debug purposes, a set bit (such as Range detection interrupt flag can be set after averaging,
EOS_SET in the SAR_INTR_SET register) is used to trigger alignment, and sign extension (if applicable). This means it
each interrupt. This action allows the firmware to generate is not required to wait for the entire scan to complete to
an interrupt without the actual event occurring. determine whether a channel conversion is over-range. The
threshold values need to have the same data format as the
38.2.5.1 End-of-Scan Interrupt (EOS_INTR) result data.
After completing a scan, the end-of-scan interrupt Range detection interrupt for a specified channel can be
(EOS_INTR) is raised. Firmware should clear this interrupt masked by setting the SAR_RANGE_INTR_MASK register
after picking up the data from the RESULT registers. specified bit to ‘0’. Register SAR_RANGE_INTR_MASKED
reflects a bitwise AND between the interrupt request and
EOS_INTR can be masked by making the EOS_MASK bit 0
mask registers. If the value is not zero, then the SAR inter-
in the SAR_INTR_MASK register. EOS_MASKED bit of the
rupt signal to the NVIC is high.
SAR_INTR_MASKED register is the logic AND of the inter-
rupt flags and the interrupt masks. Writing a ‘1’ to EOS_SET SAR_RANGE_INTR_SET can be used for debug/verifica-
bit in SAR_INTR_SET register can set the EOS_INTR, tion. Write a ‘1’ to set the corresponding bit in the interrupt
which is intended for debug and verification. request register; when read, this register reflects the inter-
rupt request register.
38.2.5.2 Overflow Interrupt
There is a range detect interrupt for each channel
If a new scan completes and the hardware tries to set the (RANGE_INTR and INJ_RANGE_INTR).
EOS_INTR and EOS_INTR is still high (firmware does not
clear it fast enough), then an overflow interrupt (OVER- 38.2.5.5 Saturate Detection Interrupts
FLOW_INTR) is generated by the hardware. This usually
The saturation detection is always applied to every conver-
means that the firmware is unable to read the previous
sion. This feature detects if a sample value is equal to the
results before the current scan completes. In this case, the
minimum or maximum value and sets a maskable interrupt
old data is overwritten.
flag for the corresponding channel. This action allows the
OVERFLOW_INTR can be masked by making the OVER- firmware to take action, such as discarding the result, when
FLOW_MASK bit 0 in SAR_INTR_MASK register. OVER- the SAR ADC saturates. The sample value is tested right
FLOW_MASKED bit of SAR_INTR_MASKED register is the after conversion, before averaging. This means that the
logic AND of the interrupt flags and the interrupt masks, interrupt is set while the averaged result in the data register
which are for firmware convenience. Writing a ‘1’ to the is not equal to the minimum or maximum.
OVERFLOW_SET bit in SAR_INTR_SET register can set
Saturation interrupt flag is set immediately to enable a fast
OVERFLOW_INTR, which is intended for debug and verifi-
response to saturation, before the full scan and averaging.
cation.
Saturation detection interrupt for specified channel can be
masked by setting the SAR_SATURATE_INTR_MASK reg-
38.2.5.3 Collision Interrupt
ister specified bit to ‘0’. SAR_SATURATE_INTR_MASKED
It is possible that a new trigger is generated while the register reflects a bit-wise AND between the interrupt
SARSEQ is still busy with the scan started by the previous request and mask registers. If the value is not zero, then the
trigger. Therefore, the scan for the new trigger is delayed SAR interrupt signal to the NVIC is high.
until after the ongoing scan is completed. It is important to
SAR_SARTURATE_INTR_SET can be used for debug/veri-
notify the firmware that the new sample is invalid. This is
fication. Write a ‘1’ to set the corresponding bit in the inter-
done through the collision interrupt, which is raised any time
rupt request register; when read, this register reflects the
a new trigger, other than the continuous trigger, is received.
interrupt request register.
The collision interrupt for the firmware trigger (FW_COLLI-
SION_INTR) allows the firmware to identify which trigger 38.2.5.6 Interrupt Cause Overview
collided with an ongoing scan.
INTR_CAUSE register contains an overview of all the pend-
The collision interrupts can be masked by making the corre- ing SAR interrupts. It allows the ISR to determine the cause
sponding bit ‘0’ in the SAR_INTR_MASK register. The corre- of the interrupt. The register consists of a mirror copy of
sponding bit in the SAR_INTR_MASKED register is the logic SAR_INTR_MASKED. In addition, it has two bits that aggre-
AND of the interrupt flags and the interrupt masks. Writing a gate the range and saturate detection interrupts of all chan-
‘1’ to the corresponding bit in SAR_INTR_SET register can nels. It includes a logical OR of all the bits in
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 517
SAR ADC
38.2.6 Trigger
A scan can be triggered in the following ways:
■ A firmware or one-shot trigger is generated when the
firmware writes to the FW_TRIGGER bit of the
SAR_START_CTRL register. After the scan is com-
pleted, the SARSEQ clears the FW_TRIGGER bit and
goes back to idle mode waiting for the next trigger. The
FW_TRIGGER bit is cleared immediately after the SAR
is disabled.
■ Trigger from other peripherals through the trigger multi-
plexer (see the Trigger Multiplexer Block chapter on
page 294 for more details).
■ A continuous trigger is activated by setting the CONTIN-
UOUS bit in SAR_SAMPLE_CTRL register. In this
mode, after completing a scan the SARSEQ starts the
next scan immediately; therefore, the SARSEQ is
always BUSY. As a result, all other triggers are essen-
tially ignored. Note that FW_TRIGGER will still get
cleared by hardware on the next completion.
For firmware continuous trigger, it takes only one SAR ADC
clock cycle before the sequencer tells the SAR ADC to start
sampling (provided the sequencer is idle).
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 518
SAR ADC
38.3 Registers
Name Description
SAR_CTRL Global configuration register. Analog control register
SAR_SAMPLE_CTRL Global configuration register. Sample control register
SAR_SAMPLE_TIME01 Global configuration register. Sample time specification ST0 and ST1
SAR_SAMPLE_TIME23 Global configuration register. Sample time specification ST2 and ST3
SAR_RANGE_THRES Global range detect threshold register
SAR_RANGE_COND Global range detect mode register
SAR_CHAN_EN Enable bits for the channels
SAR_START_CTRL Start control register (firmware trigger)
SAR_CHAN_CONFIGx Channel configuration register. There are 16 such registers with x = 0 to 15
SAR_CHAN_WORKx Channel working data register. There are 16 such registers with x = 0 to 15
SAR_CHAN_RESULTx Channel result data register. There are 16 such registers with x = 0 to 15
SAR_CHAN_WORK_UPDATED Channel working data register: updated bits
SAR_CHAN_RESULT_UPDATED Channel result data register: updated bits
SAR_STATUS Current status of internal SAR registers (for debug)
SAR_AVG_STAT Current averaging status (for debug)
SAR_INTR Interrupt request register
SAR_INTR_SET Interrupt set request register
SAR_INTR_MASK Interrupt mask register
SAR_INTR_MASKED Interrupt masked request register
SAR_SATURATE_INTR Saturate interrupt request register
SAR_SATURATE_INTR_SET Saturate interrupt set request register
SAR_SATURATE_INTR_MASK Saturate interrupt mask register
SAR_SATURATE_INTR_MASKED Saturate interrupt masked request register
SAR_RANGE_INTR Range detect interrupt request register
SAR_RANGE_INTR_SET Range detect interrupt set request register
SAR_RANGE_INTR_MASK Range detect interrupt mask register
SAR_RANGE_INTR_MASKED Range interrupt masked request register
SAR_INTR_CAUSE Interrupt cause register
SAR_MUX_SWITCH0 SARMUX firmware switch controls
SAR_MUX_SWITCH_CLEAR0 SARMUX firmware switch control clear
SAR_MUX_SWITCH_SQ_CTRL SARMUX switch sequencer control
SAR_MUX_SWITCH_STATUS SARMUX switch status
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 519
39. Temperature Sensor
This PSoC 6 MCU technical reference manual (TRM) provides comprehensive and detailed information about the
functions of the PSoC 6 MCU device hardware. It is divided into two books: architecture TRM and registers TRM. The
TRM is not recommended for those new to the PSoC 6 MCU, nor as a guide for developing PSoC 6 MCU applications.
Use these documents instead:
■ PSoC 61 datasheet, PSoC 62 datasheet
■ Peripheral Driver Library (PDL) documentation
■ Application notes
■ Code examples
PSoC 6 MCUs have an on-chip temperature sensor that is used to measure the internal die temperature. The sensor consists
of a transistor connected in diode configuration.
39.1 Features
■ Measures device temperature
■ Voltage output can be internally connected to SAR ADC for digital readout
■ Factory calibrated parameters
39.2 Architecture
The temperature sensor consists of a single bipolar junction transistor (BJT) in the form of a diode. The transistor is biased
using a reference current IREF from the analog reference block (see the Analog Reference Block chapter on page 497 for
more details). Its base-to-emitter voltage (VBE) has a strong dependence on temperature at a constant collector current and
zero collector-base voltage. This property is used to calculate the die temperature by measuring the VBE of the transistor
using the SAR ADC, as shown in Figure 39-1.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 520
Temperature Sensor
IREF
SAR_MUX_SWITCH0.MUX
_FW_TEMP_VPLUS
vplus
Temperature
Sensor
SAR ADC CPU
12 bit
vminus
SARMUX
vssa_kelvin
1.2 V
Vssa Vssa
The analog output from the sensor (VBE) is measured using the SAR ADC. Die temperature in °C can be calculated from the
ADC results as given in the following equation:
10
Temp = A SAR out + 2 B + T adjust
Equation 39-1
■ Temp is the slope compensated temperature in °C represented as Q16.16 fixed point number format.
■ ‘A’ is the 16-bit multiplier constant. The value of A is determined using the PSoC 6 MCU characterization data of two point
slope calculation. It is calculated as given in the following equation.
100C – – 40C
A = signed int 2 --------------------------------------------------------
16
SAR 100C – SAR – 40C Equation 39-2
Where,
SAR100C = ADC counts at 100 °C
SAR–40C = ADC counts at –40 °C
Constant ‘A’ is stored in a register SFLASH_SAR_TEMP_MULTIPLIER. See the registers TRM for more details.
■ ‘B’ is the 16-bit offset value. The value of B is determined on a per die basis by taking care of all the process variations
and the actual bias current (IREF) present in the chip. It is calculated as given in the following equation.
6 A SAR 100C
B = unsigned int 2 x100C – --------------------------------
-
2
10
Equation 39-3
Where,
SAR100C = ADC counts at 100 °C
Constant ‘B’ is stored in a register SFLASH_SAR_TEMP_OFFSET. See the registers TRM for more details.
■ Tadjust is the slope correction factor in °C. The temperature sensor is corrected for dual slopes using the slope correction
factor. It is evaluated based on the result obtained without slope correction, which is given by the following equation:
10
T initial = A SAR OUT + 2 B
Equation 39-4
If Tinitial is greater than the center value (15 °C), then Tadjust is given by the following equation.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 521
Temperature Sensor
0.5C
T adjust = ----------------------------------- 100C 2 – T initial
16
100C – 15C Equation 39-5
If Tinitial is less than center value, then Tadjust is given by the following equation.
0.5C
T adjust = -------------------------------- 40C 2 + T initial
16
40C + 15C Equation 39-6
Figure 39-2. Temperature Error Compensation
Temperature
Error
Compensation curve
0.5 °C
Tadjust
0 °C
-0.5 °C
Sensor Error Curve
Actual Temperature
-40 °C 15 °C 100 °C
Note: A and B are 16-bit constants stored in flash during factory calibration. These constants are valid only with a specific
SAR ADC configuration. See 39.3 SAR ADC Configuration for Measurement for details.
39.4 Algorithm
1. Get the digital output from the SAR ADC.
2. Fetch ‘A’ from SFLASH_SAR_TEMP_MULTIPLIER and ‘B’ from SFLASH_SAR_TEMP_OFFSET.
3. Calculate the die temperature using the following equation:
10
Temp = A SAR OUT + 2 B + T ADJUST
For example, let A = 0xBC4B and B = 0x65B4. Assume that the output of SAR ADC (VBE) is 0x595 at a given tempera-
ture. Firmware does the following calculations:
a. Multiply A and VBE: 0xBC4B × 0x595 = (–17333)10 × (1429)10 = (–24768857)10
b. Multiply B and 1024: 0x65B4 × 0x400 = (26036)10 × (1024)10 = (26660864)10
c. Add the result of steps 1 and 2 to get Tinitial: (–24768857)10 + (26660864)10 = (1892007)10 = 0x1CDEA7
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 522
Temperature Sensor
d. Calculate Tadjust using Tinitial value: Tinitial is the upper 16 bits multiplied by 216, that is, 0x1C00 = (1835008)10. It is
greater than 15°C (0x1C - upper 16 bits). Use Equation 4 to calculate Tadjust. It comes to 0x6B1D = (27421)10
e. Add Tadjust to Tinitial: (1892007)10 + (27421)10 = (1919428)10 = 0x1D49C4
f. The integer part of temperature is the upper 16 bits = 0x001D = (29)10
g. The decimal part of temperature is the lower 16 bits = 0x4B13 = (0.18884)10
h. Combining the result of steps f and g, Temp = 29.18884 °C ~ 29.2°C
39.5 Registers
Name Description
SFLASH_SAR_TEMP_MULTIPLIER Multiplier constant 'A' as defined in Equation 39-1.
SFLASH_SAR_TEMP_OFFSET Constant 'B' as defined in Equation 39-1.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 523
40. CapSense
The CapSense system can measure the self-capacitance of an electrode or the mutual capacitance between a pair of
electrodes. In addition to capacitive sensing, the CapSense system can function as an ADC to measure voltage on any GPIO
pin that supports the CapSense functionality.
The CapSense touch sensing method in PSoC 6 MCUs, which senses self-capacitance, is known as CapSense Sigma Delta
(CSD). Similarly, the mutual-capacitance sensing method is known as CapSense Cross-point (CSX). The CSD and CSX
touch sensing methods provide the industry’s best-in-class signal-to-noise ratio (SNR), high touch sensitivity, low-power
operation, and superior EMI performance.
CapSense touch sensing is a combination of hardware and firmware techniques. Therefore, use the CapSense component
provided by the ModusToolbox IDE to implement CapSense designs. See the PSoC 4 and PSoC 6 MCU CapSense Design
Guide for more details.
PSoC 6 MCU: CY8C6xx8, CY8C6xxA Architecture TRM, Document No. 002-24529 Rev. *I 524