Professional Documents
Culture Documents
Converting CY7C630XX/1XX Designs To The CY7C637XX: Clock Circuit
Converting CY7C630XX/1XX Designs To The CY7C637XX: Clock Circuit
Introduction Writing a “0” to the Data Register will drive the output low and
allow it to sink current. Instead of supporting a fixed output
This application note describes the differences between the drive, the CY7C630xx/1xx allows the user to select an output
CY7C630xx/1xx and the CY7C637xx and how to convert current level for each I/O line. The sink current of each output
designs using the CY7C630xx/1xx Universal Serial Bus is controlled by a dedicated 8-bit Isink Register. The lower
(USB) controller to the CY7C637xx USB microcontroller. The four bits of this register allow the developers to select one of
document starts with an introduction to the CY7C630xx/1xx 16 sink current levels. The upper four bits are reserved and
and the CY7C637xx USB controllers, followed by the must be written as 0s. The output sink current levels of the
Hardware Differences section, and ending with the two GPIO ports are different. For Port 0 outputs, the lowest
Suggested Firmware Changes section. drive strength (0000) is about 0.2 mA and the highest drive
This application note assumes that the reader is familiar with strength (1111) is about 1.0 mA. Port 1 outputs are specially
the CY7C630xx/1xx USB controller and the USB. The designed to drive high-current applications such as LEDs.
CY7C630xx/1xx and CY7C637xx data sheets are available Each Port 1 output is much stronger than their Port 0 counter
from the Cypress web site at www.cypress.com. USB parts at the same drive level setting. The lowest and highest
documentation can be found at the USB Implementers Forum drive for Port 1 pins are 3.2 mA and 16 mA, respectively.
web site at www.usb.org. Each GPIO is capable of generating an interrupt to the RISC
core. Interrupt polarity is selectable on a per bit basis using
Introduction to the CY7C630xx/1xx the Port Pull-up Register. Setting a Port Pull-up Register bit
The CY7C630xx/1xx is an 8-bit RISC microcontroller with an to “1” selects a rising edge trigger for the corresponding GPIO
integrated USB Serial Interface Engine (SIE). The archi- line. Conversely, setting a Port Pull-up Register bit to “0”
tecture implements 34 commands. The CY7C630xx/1xx has selects a falling edge trigger. The interrupt triggered by a
built-in clock oscillator and timers as well as programmable GPIO line is individually enabled by a dedicated bit in the Port
current drivers, and pull-up resistors at each I/O line. Interrupt Enable Registers. All GPIO interrupts are further
masked by the Global GPIO Interrupt Enable Bit in the Global
Clock Circuit Interrupt Enable Register.
The CY7C630xx/1xx has a built-in clock oscillator and The Port Pull-up Registers are located at I/O address 0x08
PLL-based frequency doubler. This circuit allows a 6MHz and 0x09 for Port 0 and Port 1, respectively. The Port 0 and
ceramic resonator to be used externally while the on-chip Port 1 Data Registers are located at address 0x00 and 0x01
RISC core runs at 12 MHz. respectively. The Port 0 and Port 1 Interrupt Enable Registers
are at addresses 0x04 and 0x05, respectively.
USB Serial Interface Engine
Wake-up Interrupt
The internal SIE simplifies the interface to the USB bus for the
user. In the receive mode, USB packet decode and data Power management is paramount in many USB applications.
transfer to the endpoint FIFO are automatically done by the To conserve power, the CY7C630xx/1xx supports an exter-
SIE. The SIE then generates an interrupt request to invoke a nally programmable interrupt input to wake up the microcon-
service routine after a packet is unpacked. troller from the suspend mode. The suspend mode causes
the microcontroller to shut down most of its functions such as
In the transmit mode, data transfer from the endpoint and the the RISC core, the timer, and part of the SIE. In the mouse
assembly of the USB packet are handled automatically by the application, a high percentage of the power is consumed by
SIE. the LEDs. Therefore, the CY7C630xx/1xx should be
General Purpose I/O programmed to power off the LEDs before entering the
suspend mode. With the LEDs powered off, the
The CY7C630xx/1xx has up to 12 general purpose I/O CY7C630xx/1xx can no longer detect any mouse movements
(GPIO) lines divided into two ports: Port 0 and Port 1. Each although button closures are still recognized because
GPIO can be configured in current sink mode, resistive, or pressing a button could cause a GPIO interrupt to wake up
Hi-Z mode as shown in Table 1. the microcontroller. Upon wakening, the device can check for
any changes and return to suspend mode if desired.
Table 1. Programmable Output State
The wake-up interrupt can be implemented by connecting the
Port Data Bit Port Pull-up Bit Output State CEXT pin to VCC with a resistor and to GND with a capacitor.
0 X sink current “0” Before the firmware puts the microcontroller into the suspend
mode, it writes a 0 to the Cext register at address 0x22 to
1 0 pull-up resistor “1”
discharge the external capacitor. Then, to start timing, a 1 is
1 1 High-Z written to the Cext register to allow the RC circuit to begin
charging. A wake-up interrupt is generated to the RISC core
Cypress Semiconductor Corporation • 3901 North First Street • San Jose, CA 95134 • 408-943-2600
October 30, 2003, rev. 0.A
Converting CY7C630XX/1XX Designs to the CY7C637XX
2
Converting CY7C630XX/1XX Designs to the CY7C637XX
This TSTART delay timer gives Vcc time to stabilize before begin
Bottom of RAM Top of RAM
(address 00h) (CY630xx/1xx: 7Fh executing code. After a TSTART delay, the microcontroller starts
CY637xx: 0xFF) executing code from the ROM address 0x00.
In addition to the LVR, the CY7C637xx features a BOR which
Program Stack Pointer (PSP), Data Stack Pointer Endpoint is automatically turned on when LVR is disabled. In suspend
(DSP), and user-defined variables FIFOs
mode, only BOR is active, giving a reset if Vcc drops below
approximately 2.5V. In this mode, the chip consumes very little
power. Since the device is suspended and code is not
Start of FIFO executing, this lower voltage is safe for retaining the state of
(CY630xx/1xx: 0x70 all registers and memory.
CY637xx: 0xE8)
The CY7C630xx/1xx USB Bus Reset occurs when a Single
Figure 1. Data Memory (RAM) Organization Ended Zero (SE0) condition persists for 8 to 16 µs. The
CY7C630xx/1xx treats the USB Bus Reset as a hard reset
The CY7C630xx/1xx is available with 4 Kbytes of EPROM. where it resets all the internal registers to their default values
The first lower 16 bytes of the EPROM from address 0x0000 and executes code from address 0x00.
to 0x0010 are reserved for interrupt vectors, and the rest of the
EPROM is used for storing program code. The The CY7C637xx treats the USB Bus Reset as an interrupt.
CY7C630xx/1xx program memory begins at address 0x0011. Whenever the host sends an USB Bus Reset, the CY7C637xx
USB Bus Reset interrupt is generated. This interrupt stays as
The CY7C637xx is available with 8 Kbytes of EPROM. The a pending interrupt and will be serviced when the USB Bus
first lower 24 bytes of the EPROM from address 0x0000 to Reset Interrupt bit is enabled in the Global Interrupt Enable
0x0018 are reserved for interrupt vectors. Due to some added Register at address 0x20.
features, the CY7C637xx supports more interrupts than the
CY7C630xx/1xx. The CY7C637xx program memory begins at The CY7C630xx/1xx and CY7C637xx Watchdog Resets are
address 0x0019. Figure 2 below shows the organization of the similar. A WDR occurs whenever the internal Watchdog Timer
EPROM for the CY7C630xx/1xx and CY7C637xx. rolls over. Writing any value to the Watchdog Reset Register
clears the timer.
After Reset Top of EPROM
(address 00h)
Wake-up Circuitry
Wake-up interrupt is used to perform periodic checks on any
changes to the device while the microcontroller is placed in the
Interrupt On-chip program Memory suspend mode.
Vectors
The CY7C630xx/1xx uses an external RC timing circuit to
trigger a wake-up interrupt at the Cext pin. By changing the
Program memory starts values of the external resistor and capacitor, the user can tune
(CY630xx/1xx: 0x0011 the rate of these interrupt events.
CY637xx: 0x0019)
The CY7C637xx has a wake-up timer integrated. This timer
Figure 2. Program Memory (EPROM) Organization generates periodical interrupts when it is activated. The rate of
these wake-up interrupts can be adjusted by the user through
Reset the Wake-up Timer Adjust bits in the Clock Configuration
When a reset occurs, all registers are restored to their default Register. The wake-up timer functions as the RC Cext circuit
states, the USB device address is set to 0, all interrupts are of the CY7C630xx/1xx with no external parts needed.
disabled, and both the CY7C630xx/1xx and CY7C637xx Power-up
microcontrollers resume execution from address 0x00.
When the CY7C630xx/1xx is first powered up, the POR
The CY7C630xx/1xx supports three types of resets: automatically puts the chip into the suspended mode. The chip
Power-On Reset (POR), USB Bus Reset, and Watchdog stays suspended until a USB Bus Reset, or USB Bus activity,
Reset (WDR). or an external interrupt occurs.
The CY7C637xx supports three types of resets: Low-Voltage When the CY7C637xx is switched on LVR automatically puts
Reset (LVR), Brown-Out Reset (BOR), and Watchdog Reset the chip into the partial suspended mode for a TSTART ms
(WDR). (24 ms < Tstart < 60 ms). After this TSTART period, the micro-
The CY7C630xx/1xx POR is triggered every time the device controller begins execution from ROM address 0x0000.
is switched on. At the end of POR, the CY7C630xx/1xx is
automatically placed in suspend mode and waits for a USB Suspend
Bus Reset, or USB bus activities (D- is LOW) to terminate the While in the suspended mode, the CY7C630xx/1xx can only
suspend mode; the microcontroller then begins execution from be awaken by external events such as a GPIO interrupt, USB
ROM address 0x00. activity, or Cext interrupt.
When the CY637xx is switched on, the LVR is triggered. This In suspend mode, the CY7C637xx can be awaken by either
LVR stays asserted until Vcc rises above Vlvr (3.5V < Vlvr < the internal wake-up timer, or an external event such as a
4.0V). At this point, the CY7C637xx automatically enters a GPIO interrupt or USB activity (D- LOW).
partial suspend state for TSTART ms (24 ms < TSTART< 60ms).
3
Converting CY7C630XX/1XX Designs to the CY7C637XX
4
Converting CY7C630XX/1XX Designs to the CY7C637XX
• Calculates the CRC error checking bits upon receiving or whenever their contents have been updated by the SIE. This
transmitting data and flags the microcontroller if erroneous is usually the result of the host sending a new set-up, IN, or
data is received. OUT packet to the device. Performing an ‘IORD’ to these
• Sends handshake packets (ACK, NAK, STALL) to the host. registers will un-lock them. The purpose of performing this
‘IORD’ is to ensure that the device has acknowledged the
• Triggers interrupts. update and avoid new set-up data being over written.
The CY7C630/1xx SIE’s responses to the USB transactions
depend on the contents of the USB Endpoint RX Registers, Additional Features of The CY7C637xx
Endpoint TX Configuration Registers, and USB Status and The CY7C637xx has some additional features that the
Control Register. For example, setting the INEN bit (bit 7 in the CY7C630xx/1xx does not have. Because the main purpose of
Endpoint TX Register) enables the SIE to respond to IN this application note is to provide help on migrating the
packets. CY7C630xx/1xx designs to the CY7C637xx, these added
The CY7C637xx SIE’s responses to the USB packets depend features will not be discussed in detail.
on the Endpoint Mode Register and Endpoint Counter • Serial Peripheral Interface (SPI)
Register. The Mode Bits, Bits[3:0] in the USB Endpoint Mode The CY7C637xx is SPI compatible. SPI circuit supports
Registers (address 0x12, 0x14 and 0x16) are crucial bits that byte serial transfer in either Master or Slave mode.
put the endpoints in different modes which determine how the
endpoints respond to USB packets sent from the host. Details • Capture timers
about the CY7C637xx Endpoint Modes can be obtained from The CY7C637xx Capture Timer Registers can be used to
the USB Mode Tables of the CY7C637xx data sheet. mark the time at which GPIO events occur.
An advanced feature of the CY7C637xx’s SIE is the Register Table 5 below summarizes the differences.
Locking Function. The CY7C637xx Endpoint 0 Mode and
Counter Registers are locked from CPU write operations
Table 5. The Differences between CY7C630xx/1xx and CY7C637xx
Item CY7C630xx/1xx CY7C637xx
Clocking External Clock required. The Xtalin pin cannot External or Internal Clock. Xtalin is available as input
be used as input if the chip is in internal clock mode
Memory Organization 128 Bytes RAM/Up to 4 KBytes ROM 256 Bytes RAM/Up to 8 Kbytes ROM
Reset POR, WDR, and USB Bus Reset LVR, BOR, WDR (USB Bus Reset is treated as an
interrupt)
Wake-up Circuitry External R-C timing circuit generates Cext Internal Wake-up Timer is programmed to wake the
interrupts microcontroller periodically
Power-Up At power-up, POR puts the chip in suspend At power-up, LVR puts the microcontroller in a partial
mode. D- LOW wakes the chip up suspend mode for a TSTART ms. After this TSTART
delay, the chip starts executing from address 0x00
Suspend An external event wakes the chip An external event or an internal wake-up interrupt
wakes the chip
GPIO Sink Current Less output configuration choices. DAC is Different drive strengths, pull-up resistances and
implemented. Depending on the Port, 16 modes. No DAC. Depending on the mode, Isink
levels of sink current ranging from 0.2 to ranges from 2 to 50 mA
24-mA
GPIO Source Current Pull-up with Rup resistor only Pull-up with 14K or 2-mA source current
SIE The SIE’s responses to USB packets depend The SIE’s responses to USB packets are determined
on the contents of the USB Endpoint RX and by the endpoint modes. Register locking function is
TX Registers. No register locking function implemented
Interrupts The first lower 16 bytes of EPROM are The first lower 24 bytes of EPROM are reserved for
reserved for interrupt vector. Cext interrupt is interrupt vector. Additional interrupts such as SPI
replaced with Wake-up interrupt interrupt, Bus Reset Interrupt, Capture Timer A/B
When servicing an interrupt, hardware interrupts and Endpoint 2 interrupt with different
disables all interrupts by clearing the Global priority order
Interrupt Enable Register (GIER). When servicing an interrupt, the hardware disables
“ipret” instruction is used to exit ISR with inter- interrupts by clearing bit 2 in the Processor Status and
rupts reenabled. Control Register; the contents of GIER stay
unchanged.
DI, EI, RETI instructions are used to enable/disable
interrupts.
5
Converting CY7C630XX/1XX Designs to the CY7C637XX
6
Converting CY7C630XX/1XX Designs to the CY7C637XX
POR LVR
Partial
Suspend Suspend
Figure 3. Resets in The CY7C63000 Mouse Design and Its Converted CY7C637xx
Upon reset, DSP and PSP are reset to 0x00. The DSP grows suspend mode. The below example sets the microcontroller to
down with a predecrement, while the PSP grows upward with operate with the internal oscillator and this setting should be
post-increment. The user’s firmware must set the DSP to an done by firmware at reset as below.
appropriate address to avoid DSP overwriting the endpoint ;CY7C637xx only. Set for use with internal
FIFO. As discussed above, in the CY7C630/1xx designs, the ;oscillator. Wake-up Adjust Bits are used to
firmware may set the DSP to the start of endpoint 0 FIFO while ;programmed the internal wake-up interrupt.
in the CY7C637xx, the first lower bytes of RAM are normally
used for the DSP and PSP and the user selects the starting mov A, (WakeUp_Adjust2 | WakeUp_Adjust0 |
address for the DSP. In the example below, 0x1F is chosen to INTERNAL_CLK | CLK_PRECISION_ENABLE)
be the starting address for the DSP, allocating 32 bytes for the iowr Clock_Config
stacks. In other words, 0x00 to 0x1F of data RAM are now
reserved for the DSP and PSP. The GPIO configurations are usually being done at reset. The
CY7C630xx/1xx uses the Port Pull-up Register and Port Data
Reset: Register to configure each GPIO pin as an input or output. The
;CY630/1xx, DSP is set to the start of CY7C630xx/1xx driving capability of each GPIO pin is
;endpoint 0 and swap to avoid dsp writing programmed by setting the Isink bits of the Port Isink Register.
;over endpoint 1 FIFO In the CY7C637xx, the Port Pull-up Register, Port Data
;mov A, endpoint_0 Register, and Port Isink Register are not implemented and
;swap A, dsp should be commented out from the code. On the other hand,
the CY7C637xx features Port Mode Registers and Port Data
Registers to configure each GPIO pin. Note that the DAC is
;CY637xx. In this example DSP is set to 1Fh. not implemented on the CY7C637xx. Below is an example of
mov A, 1Fh how to set Port 1 pin 1 to sink up to 50mA for the LED.
;CY630/1xx. LED_Current equals 0x0f which is
swap A, dsp
;maximum current drive
At power-up, the CY7C637xx runs in the internal clock mode
;mov A, LED_Current.
by default. Firmware can enable/disable the output of the
internal oscillator at the XTALOUT pin, or run with an external ;iowr Port1_Isink0
oscillator by setting the Clock Configuration Register at ;Port Pull up Registers are not implemented on
address 0xF8. Note that the Precision USB Clocking Enable ;the CY637xx, and should be commented out from
bit must be set to ‘1’ to cause the internal clock to automatically ;the converted CY637xx codes.
precisely tune to USB timing requirements (6 MHz ±1.5%).
The Wake-up Timer Adjust Bits are used to program the ;mov A, 0h
periodical wake-up interval when the microcontroller goes into ;iowr Port1_Pullup
7
Converting CY7C630XX/1XX Designs to the CY7C637XX
8
Converting CY7C630XX/1XX Designs to the CY7C637XX
The CY7C630xx/1xx is a type A CPU. When servicing an Endpoint 0 ISR is primarily responsible for the enumeration
interrupt, the CY7C630xx/1xx hardware first disables all inter- and configuration of the device. The endpoint 0 ISR parses
rupts by clearing all the bits in the Global Interrupt Enable set-up packets and determines how to respond to these
Register. As a result, in order to restore the interrupts that were control transfer requests. Starting with the CY7C637xx
enabled before entering the ISR, the CY7C630xx/1xx framework, developers do not need to convert the enumer-
firmware usually keeps a shadow of the Global Interrupt ation code because it has already been done in the framework.
Enable Register and writes this shadow to the Global Interrupt The USB_EP1_ISR interrupt service routine handles most of
Enable Register to reenable interrupts when necessary. The the USB communications at endpoint 1. In the
CY7C637xx, on the other hand, is a type B CPU, which CY7C630xx/1xx mouse design, this interrupt is generated
handles interrupts differently. When servicing an interrupt, the after the mouse has transmitted a packet from endpoint 1 and
CY7C637xx hardware disables all interrupts by clearing the has received an ACK from the host. In the CY7C637xx, this
internal interrupt enable control bit (or Interrupt Enable Sense interrupt is generated even if the device is in NAK_IN mode
bit). The state of this bit can be read at bit 2 of the Processor and has NAKed the IN request from the host. Therefore, in the
Status and Control Register (0xFF). This internal Interrupt CY7C637xx design, the endpoint 1 ISR should only update the
Enable Sense bit is a read-only bit. Therefore, writing over this Data Toggle bit when the interrupt is a result of a successful
bit has no effects. Instructions ‘DI’, ‘EI’, and ‘RETI’ are used to ACK transaction. In this example, the data to be sent is loaded
manipulate this bit to enable/disable the interrupts in the into the endpoint 1 FIFO outside of the ISR, so this routine
Global Interrupt Enable Register and Endpoint Interrupt mainly updates the Data Toggle bit for the next packet. It is
Enable Register. Below is an example of an interrupt service recommended that developers use the endpoint 1 ISR in the
routine which does nothing but returns with interrupts CY7C637xx framework and migrate necessary code.
reenabled.
The 1-ms interrupt service routine is the place to enter
DoNothing_ISR:
suspend mode if there is no bus activity in 3 ms. Most of this
;CY7C630/1xx. Return with interrupts enabled. code stays unchanged because this routine mainly manipu-
;interrupt_mask is used to keep a copy of the lates data RAM variables which are not processor specific.
;Global Interrupt Enable Reg. Firmware should Developers should only migrate what is necessary for their
;reenable interrupts before leaving the ISR. specific applications.
;“ipret” instruction is used in type A CPU only
The Wake-up interrupt is used to force the host to resume due
;push A to a mouse movement or a button press. The CY7C630xx/1xx
;mov A, [interrupt_mask] mouse reference design uses Cext and an RC circuit to wake
the part up from sleep mode and sends a resume request to
;ipret Global_Interrupt the host if there are changes at the GPIOs. The CY7C637xx
is implemented with a wake-up timer which internally wakes
the part up periodically. When converting the firmwares, Cext
;CY637xx. Return with interrupts enabled.
and its related variables should be commented out from the
;In type B CPU, when servicing an interrupt, code. Note that the frequency of the wake up interrupts in the
;the bits in the Global Interrupt Enable CY7C637xx is set by the Wake-up Adjust bits in the Clock
Configuration Register.
;Register are not cleared. “reti” sets bit 2
;of the Processor Status and Control Register Main Routine
;to “1” which enables interrupts. The “main” routine of the CY7C630xx/1xx mouse reference
design calls ReadButtons, CheckHorizontal, and CheckVer-
reti tical subroutines to update any button press or movement of
The CY7C637xx has a register locking feature that is not the mouse. These subroutines are not processor specific, so
available in the CY7C630xx/1xx. The Endpoint 0 Mode and no changes are required. The “main” routine then calls
Endpoint 0 Counter Registers are locked from CPU write send_packet subroutine to send any new data to the host.
operations whenever their bits have been updated by the SIE. Because the CY7C630xx/1xx uses the TX and RX Registers
This is usually the result of the host sending a new while the CY7C637xx uses the Endpoint Mode and Endpoint
set-up/IN/OUT packet to the device. Performing an ‘IORD’ to Counter Registers to control the endpoint’s responses to USB
these registers will unlock them. The purpose of doing this traffic, the send_packet needs to be modified. Below is an
‘IORD’ is to ensure that the device has acknowledged the example of the modified send_packet function.
update and avoid new data being over written. When migrating send_packet:
firmware, writing to the CY7C630xx/1xx RX and TX Registers
;CY630/1xx. Check if previous packet has
is equivalent to updating the CY7C637xx Mode and Counter
;been sent. If not, return to main routine.
Registers, and because of the locking feature at Endpoint 0
;iord USB_EP1_TX_Config
Mode and Counter Registers, the CY7C637xx firmware
;and A, 80h
should carefully handle the locking mechanism on the control
;cmp A, 80h
endpoint. An example of how to handle the Endpoint 0 Mode
;jz Nosend
and Counter Registers locking mechanism is included in the
CY7C637xx framework.
;CY637xx. Check if previous packet has been
;sent. If not, return to main routine.
iord Endpoint1_Mode
and A, 0fh
9
Converting CY7C630XX/1XX Designs to the CY7C637XX
;or A, 93h
;iowr USB_EP1_TX_Config Nosend:
jmp main
;CY637xx. Load Data Toggle, set to send 3
;bytes. Conclusions
iord Endpoint1_Count The CY7C630xx/1xx and CY7C637xx are functionally similar,
;Load Data Toggle Bit. This bit is updated but the CY7C637xx incorporates many useful features such
;in EP1_ISR as crystal-less oscillator, a “brown-out” detector, embedded
3.3V regulator, and integrated wake-up circuitry. This appli-
and A, DataToggle cation note together with the CY3654 + P05 development tool
;Set to send 3 bytes (for a mouse) will simplify the task of migrating the CY7C630xx/1xx designs
to the CY7C637xx to utilize additional useful features of the
or A, 3h
CY7C637xx.
iowr Endpoint1_Count
;Set the mode to ACK_IN to send data when
;the host issues an IN. After data has been All product and company names mentioned in this document are the trademarks of their
respective holders.
;sent, the SIE changes the mode to NAK_IN.
mov A, ACK_IN Approved AN074 10/30/03 kkv
iowr Endpoint1_Mode
10