Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Converting CY7C630XX/1XX Designs to the CY7C637XX

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

when the external capacitor is charged up to nominal 2.75V Voltage Regulator


(45%–65% of VCC) by the external resistor. The duration The CY7C637xx has a built in 3.3V regulator that is designed
between successive wake-ups is controlled by the RC to drive the USB D- pull-up resistor. This regulator supplies a
constant of the external resistor and capacitor. small amount of current and should not be used as a
general-purpose regulator. The output resistance of this
Introduction to the CY7C637xx regulator is 200Ω, which necessitates a 1.3-kΩ resistor as a
The CY7C637xx is an 8-bit RISC microcontroller with an pull-up on the D- line to create the 1.5-kΩ resistor required by
integrated USB SIE. The architecture executes general the USB specification.
purpose instructions that are optimized for USB applications. The VREG pin is automatically turned off by the SIE during
The CY7C637xx has a built-in clock oscillator and timers as USB data transmission, so this pin should not be used as a
well as programmable drive strength and pull-up resistors on general purpose voltage reference.
each I/O line. High-performance, low-cost human-interface- When disabled, the VREG pin can act as an input and is read
type computer peripherals can be implemented with a via the Port 2 Data Register
minimum of external components and firmware effort.

Clock Circuit The Hardware Differences


The CY7C637xx has a crystalless internal oscillator circuit that Clocking
eliminates the need for an external resonator or crystal. This
also frees up an additional input on the XTALIN line. At The CY7C630xx/1xx requires an external oscillator. The
power-up the internal oscillator operates within 5% of nominal feedback capacitors and bias resistor are integrated into the
6 MHz. Then as USB traffic starts up, the internal oscillator will chip. Therefore, the CY7C630xx/1xx requires no external
tune itself to within 1.5% of the 6 MHz. An external oscillator components other than a 6MHz resonator.
can be used if the application demands standalone clock The CY7C637xx gives the users the options to operate with
accuracy. In either mode, an internal clock doubler provides 12 the internal on chip oscillator or an external oscillator. At reset,
MHz for the RISC core. the CY7C637xx begins operation using the internal clock by
default. The internal clock is set to a nominal frequency of
USB SIE 6 MHz and requires no external components. The user can
The internal SIE simplifies the interface to the USB bus for the choose to operate from an external oscillator by setting bit 0 of
user. In the receive mode, USB packet decode and data the Clock Configuration Register to 1. Once this bit is set, the
transfer to the endpoint FIFO are automatically done by the internal clock is halted, disabled, and the external oscillator is
SIE. The SIE then generates an interrupt request to invoke the enabled. In the external clock mode, there are no on-chip
service routine after a packet is unpacked. In the transmit capacitors, so the capacitors must be provided externally with
mode, data transfer from the endpoint and the assembly of the the 6-MHz oscillator.
USB packet are handled automatically by the SIE. While in external clock mode, the chip can be switched to the
General Purpose I/O internal clock when waking from suspend mode. Clearing bit
0 of the Clock Configuration Register will not reenable the
The CY7C637xx is available with 10 or 16 GPIO pins divided internal clock until suspend mode is entered. In the internal
into two ports: Port 0 and Port 1. clock mode, firmware must set the Precision USB Clocking
A GPIO pin can have two selectable drive strengths: CMOS Enable bit of the Clock Configuration Register at address 0xF8
and resistive. CMOS mode is a general purpose mode used to allow the internal clock to precisely tune itself to USB timing
for driving logic and other relatively fast signaling. In resistive requirements (6 MHz ±1.5%).
mode, the pin is pulled up internally via a 14-kΩ resistor.
Memory Organization
The CY7C637xx also has three sink modes including a super
strong 50-mA mode for driving hard-to-drive components such The memory in the CY7C630xx/1xx and CY7C637xx is
as optics. It should be noted that this microcontroller has a organized into user program memory in EPROM space and
current sink limit of 70-mA total on all I/O pins at one time. data memory in SRAM space.
In addition to these output modes, the CY637xx has two user The CY7C630xx/1xx includes 128 bytes of data RAM. The
selectable input thresholds for interfacing with TTL and CMOS upper 16 bytes of the RAM from address 0x70 to 0x7F are
level signaling. used for Endpoint 0 and Endpoint 1 FIFOs. The rest of the data
RAM from address 0x00 to 0x6F are used for the Program
If the CY7C637xx operates in the internal clock mode, the Stack Pointer (PSP), Data Stack Pointer (DSP), and
XTALIN pin can act as an input. user-defined variables.
When the VREG output is disabled, the VREG pin may also The CY7C637xx includes 256 bytes of RAM. The upper 24
act as an input. The state of the VREG pin can be read at the bytes of the data RAM from address 0xE8 to 0xFF are used
Port 2 Data Register. The D+ and D- pins are normally used for Endpoint 0, Endpoint 1, and Endpoint 2 FIFOs. The rest of
for the USB interface. However, these pins can optionally be the lower-data RAM is used for PSP, DSP, and user-defined
configured in Hi-Z mode or with internal pull up resistors to variables. Figure 1 below shows the organization of the data
support PS/2 interface. This means that USB and PS/2 can RAM for the CY7C630xx/1xx and CY7C637xx.
coexist on the same signal pins.

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

GPIO Table 4. CPU B Instructions Only


The CY7C630xx/1xx is available in 20- or 24-pin packages. Instruction Opcode Description
The 20-pin package has 12 GPIOs, and the 24-pin package
has 16 GPIOs. CALL 5xh Call address from lower 4K to
upper 4 KB of ROM
The CY7C637xx is available in 18- and 24-pin packages. The
18-pin package features 10 GPIOs, and the 24-pin package CALL 9xh Call address from lower 4K to
features 16 GPIOs. If the chip operates in the internal clock lower 4 KB of ROM
mode, the XTALIN pin at Port 2 can be used as input port. DI 70h Disable Interrupts
Each GPIO pin of the CY7C630xx/1xx is integrated with an EI 72h Enable Interrupts
Isink DAC for sink current capability. The user can select 16
levels of current sink by setting the Isink bits of the Port Isink MOV X,A 40h Move A into X
Register. MOV A,X 41h Move X into A
The CY7C637xx does not have the DAC feature. Instead, Port MOV PSP,A 60h Move A into Program Stack
Mode Registers are implemented to determine the driving Pointer
state of each pin. RETI 73h Return from Interrupt
The driving state of each GPIO pin of the CY7C630xx/1xx is
determined by the state of its associated Port Pull-up Register The interrupt enable/disable mechanism was revised in CPU
bit and Data Register bit. The DAC on Port 0 can sink up to B. The mechanism combines hardware and software control
1.5 mA, and Port 1 can sink up to 24 mA. without writing over the Global Interrupt Enable register
(0x20), thus eliminating the need to restore its contents prior
The driving state of each GPIO pin of the CY7C637xx depends
to returning from the ISR (required for CPU A). The hardware
on its associated Data Register bit and its Port Mode bits.
control disables interrupt when an interrupt is acknowledged
Depending on the mode, the CY7C637xx can sink 2, 8, or up
and enables interrupts when the ‘RETI’ instruction is executed
to 50 mA.
at the end of an ISR.
Vreg Interrupts can be enabled by the ‘EI’ instruction or disabled by
For device detection purposes, the USB specification requires the ‘DI’ instruction. While interrupts are automatically disabled
low-speed devices to have a 1.5 KΩ resistor connected when entering an ISR, they can be reenabled before the end
between D- and Vreg of approximately 3.3V, or equivalent. of the ISR with an ‘EI’ instruction if desired.
The CY7C637xx has an integrated voltage regulator which The ‘CALL’ instruction allows the firmware to call subroutines
can be used to pull up D-. Since the Vreg output pin has an in the upper 4K of ROM.
internal series resistance of approximately 200Ω, the external The added ‘MOV’ instructions allow more flexible usage of the
pull-up resistor needed is 1.3 KΩ. ‘X’ register, and the ‘MOV PSP, A’ instruction allows the
firmware to initialize the program stack pointer.
CPU Version
The CY7C630xx/1xx contains CPU version A while the Endpoint
CY7C637xx contains CPU version B. The differences The CY7C630xx/1xx has two endpoints: Endpoint 0 for control
between CPU A and CPU B are in their instruction sets. The transfer and Endpoint 1 for interrupt transfer. There are three
below tables show the differences in the instruction set. registers used to control communication to/from the endpoints:
the USB Endpoint RX Register, USB Endpoint TX Register,
Table 2. CPU A and B Instructions That Are Different and USB Status and Control Register.
Instruction Opcode Description The CY7C637xx has three endpoints: endpoint 0 for control
RET 3Fh Return transfer, Endpoint 1 and 2 for interrupt transfers. Communi-
(flags handled differently as cation to/from the endpoints is controlled by three registers:
explained below) USB Endpoint Mode Register, USB Endpoint Counter
Register, and USB and Status Control Register.
CPU A restores the C and Z flags from stack when ‘RET’ is
executed. CPU B does not alter the C and Z flags when ‘RET’ SIE
is executed. The SIE is integrated in both of the CY7C630/1xx and
CY7C637xx. The SIE’s responsibility is to simplify the
Table 3. CPU A Instructions Only interface between the USB bus and the microcontrollers.
Instruction Opcode Description Some of the responsibilities of the SIE are:
IPRET 1Eh I/O write, pop, return • Detects new incoming transaction, determines its type
(set-up, IN, or OUT) and flags the microcontrollers.
The IPRET instruction combines three instructions which are • For received data, translates the encoded received data and
IOWR GLOBAL_INTERRUPT, POP A, and RET to ensure the data toggle state from the bus and stores them in the
stacks are restored at the end of interrupt service before endpoint’s buffer and data toggle bit in the microcontroller.
another interrupt can occur.
• For transmitted data, translates data in the endpoint’s buffer
to a format used by the USB bus. Sends data toggle bit with
the data onto the bus.

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

Table 5. The Differences between CY7C630xx/1xx and CY7C637xx (continued)


Item CY7C630xx/1xx CY7C637xx
Global Interrupt Enable All interrupts are masked by the GIER, Endpoint interrupts are masked by Endpoint Interrupt
Register (GIER) including endpoint interrupts Enable Register. Other interrupts are masked by the
GlER
Vreg No Vreg. 7.5K Ohms is connected between Vreg is integrated on chip. 1.3KΩ connected from D-
Vcc and D- as a work-around solution to Vreg is required to pull D- up
CPU CPU version A CPU version B
Endpoint Two endpoints Three endpoints
Additional features of N/A SPI, 12 bit Capture Timers, PS/2
CY7C637xx

Suggested Firmware Changes either microcontrollers. Using the CY7C637xx framework,


developers must ensure that no user variables accidentally fall
It is strongly recommended that developers use the in the lower first 32 bytes memory block assigned to the DSP
CY7C637xx framework as a starting point when migrating their and PSP. Because of this difference, developers might have to
designs. The CY7C637xx framework provides a clean USB reorganize the RAM allocation in the design.
enumeration firmware; therefore, starting with the framework
ensures that the developers start with a known enumerated The CY7C630/1xx has two 8-byte endpoint FIFOs starting
device and avoid migrating the bulky enumeration code. from address 0x70 to 0x7F in the data RAM. The CY7C637xx
Contact us at www.cypress.com/support for the framework. In has three 8-byte endpoint FIFOs starting from address 0xE8
this application note, the CY7C63000 mouse reference design to 0xFF. These FIFOs serve as buffers to send or receive data
firmware is used as an example. from the host. In the CY7C63000 mouse reference design
particularly, endpoint 1 is configured as an IN endpoint. When
In the sample firmware below, the old CY7C630xx/1xx mouse the device detects any movement or button clicks, it loads the
code is always commented out with a “;Cy630/1xx” label. new data into endpoint 1 FIFO to report to the host through
The “;CY637xx” labels signal the beginning of the substitution three variables, namely button_position, horiz_position, and
code for the old CY7C630xx/1xx. The “;CY630/1xx and vert_position. The values of these variables correspond to the
CY637xx” labels mean the code stays unchanged because addresses of endpoint 1 FIFO. Since the CY7C630/1xx and
they work for both the CY7C630xx/1xx and CY7C637xx. And CY7C637xx endpoint FIFO locations are different, any
the “;CY637xx only” labels mean that the code is specific to variables associated with the endpoint FIFO locations should
the CY7C637xx family only. be changed to ensure data is loaded to the correct CY7C637xx
Initialization endpoint FIFOs in the RAM space. Below is an example.
;CY630/1xx 78h is the starting address of the
Almost all of the CY7C630xx/1xx registers are located at
;endpoint 1 FIFO.
different locations in the CY7C637xx. In addition, there are
some I/O registers that are available in the CY7C630xx/1xx ;button_position: equ 78h
but not in the CY7C637xx such as the USB Endpoint TX
Configuration Register, USB Endpoint RX Register, Cext
Register, Port Pull-up Register, and Port Isink Register. Some ;CY637xx. F0h is the location of the first byte
of the I/O registers are specially available in the CY7C637xx ;in the CY7C637xx endpoint 1 FIFO.
such as Port Mode Registers, Endpoint Counter Registers, button_position: equ F0h
Endpoint Mode Registers, Endpoint Interrupt Enable Register,
;In the CY7C630xx mouse design, the same
Clock Configuration Register.
;changes are needed for horiz_position and
There are some bits in the I/O registers that both the ;vert_position
CY7C630xx/1xx and the CY7C637xx use in the USB commu-
nication such as DATA_VALID, BUS_ACTIVITY, Reset Routine
DATA_TOGGLE bits,...etc. The locations of these bits in the The CY7C630xx/1xx supports three types of resets: POR,
CY7C637xx registers are different, so they should be taken USB Bus Reset, and WDR. The CY7C637xx also supports
into consideration when migrating the code. three types of reset: LVR, BOR, and WDR. One of the big
The CY7C637xx framework includes the header file that differences between these families of microcontrollers is that
defines the definitions of the CY7C637xx bits and registers. As the CY7C637xx treats an USB Bus Reset as an interrupt while
a result, starting with the CY7C637xx framework helps avoid the CY7C630xx/1xx considers a USB Bus Reset as another
any errors caused by the above mentioned differences. hardware reset, which puts all the registers into their default
The CY7C630xx/1xx sample firmware chooses the end of the state. Figure 3. below summarizes how resets are handled in
user defined variable memory block at address 0x70 as the the CY7C63000 mouse reference design and its suggested
starting point for the DSP. The CY7C637xx framework, on the CY7C637xx conversion. Note that, in these diagrams, inter-
other hand, reserves the first lower 32 bytes of the data RAM rupts are not shown except the USB Bus Reset interrupt of the
from address 0x00 to 0x20 for the DSP and PSP (some appli- CY7C637xx.
cations might need a bigger stack size). Either way works for

6
Converting CY7C630XX/1XX Designs to the CY7C637XX

POR LVR
Partial
Suspend Suspend

USB Bus Reset After Tstart


or D- is LOW
POR LVR
!Bus Reset Reset
Reset Bus Reset or
POR, or WDR
WDR
USB Bus
WDR or
Wait Initialization Reset Interrupt
Bus Rst
Was a USB Was not a USB
Bus Reset Bus Reset
USB Bus Reset
Interrupt
Bus Reset EP 1 has not
been configured Wait
EP 1 hasn’t
EP1 has been EP 1 has been configured USB Bus Reset
configured been configured Interrupt.
Bus Reset Interrupt (Enable Vreg,
enable USB Address
reset PSP, ...)
Main Task Loop

CY7C63000 Mouse CY7C637xx Converted Version

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

As mentioned above, the CY7C637xx treats the USB Bus


;CY7C637xx. LED_Current_mode0 = 01h, and Reset as an interrupt. Because of this difference, the flow of
;LED_Current_mode1 = 01h. This sets Port 1 pin the converted CY7C637xx firmware should be changed as
;1 to mode 11 which is capable of sinking 50 mA follows.
;for the LED and other pins in Port 1 to mode 1. Initializes variables.
;00 which is Hi-Z
2. Enables USB Device Address and Vreg.
mov A, LED_Current_mode0
3. Stays in a loop and waits for endpoint 1 to be configured.
iowr Port1_Mode0
4. Jumps to the “main” function as soon as endpoint 1 is
mov A, LED_Current_mode1 enabled (enumeration process is done).
iowr Port1_Mode1 In the CY7C637xx, the USB Bus Reset interrupt is masked by
;turn on the LED on Port 1 bit[0] bit 0 of the Global Interrupt Enable Register. The interrupt will
stay as a pending interrupt and will not generate an interrupt
mov A, 0feh request until the USB Bus Reset bit (bit 0) of the Global
iowr Port1_Data Interrupt Enable Register is set to ‘1’. At the end of the USB
Reset ISR, there is a “jmp” instruction to a reset routine.
All the variable initializations should stay unchanged since Because the USB Bus Reset ISR does not perform a “ret” or
they are not affected by the types of microcontrollers used. “reti” at the end of the ISR, firmware must reset the PSP to
The CY7C630xx/1xx USB Device Address Register at remove the two bytes program counter that the hardware
address 0x12 contains a 7-bit USB address that the host automatically pushes onto the PSP stack as part of servicing
assigns the device. The most significant bit, bit 7, is unused. the interrupt.
The CY7C637xx USB Device Address Register at address
0x10 has the same functionality, but the 7th bit is used to Interrupt Service Routines
enable/disable this register. The CY7C637xx firmware must Due to the differences in architectures and some new added
set this bit to ‘1’ for the SIE to respond to any USB traffic to this features of the CY7C637xx, the interrupt vectors of the
address. Below is the code that enables the CY7C637xx USB CY7C637xx and the CY7C630/1xx are different. The
Device Address. CY7C637xx has some additional interrupts such as USB Bus
;CY637xx. Enabling the USB Device Address Reset interrupt, Endpoint 2 interrupt, and Capture Timer A/B
interrupts. While converting firmware, the user should ensure
mov A, ADDRESS_ENABLE
that all the CY7C637xx firmware includes all the interrupts in
iowr USB_Device_Address a correct order. Unused interrupts should be serviced by a
The CY7C637xx features an integrated voltage regulator set “DoNothing_ISR” interrupt service routine which does nothing
at approximately 3.3V for pulling D- up in USB applications. In but return with interrupts enabled.
order to utilize this feature, the firmware must set the VREG In the CY7C630xx/1xx, all interrupts are masked by the Global
Enable bit of the USB Status and Control Register (address Interrupt Enable Register, including endpoint interrupts. The
0x1F) to ‘1’ to allow the 3.3V output voltage to appear on the CY7C637xx separates endpoint interrupts with others by
Vreg pin of the chip. Below is the code that enables Vreg. having the Endpoint Interrupt Enable Register specially
;CY7C637xx. Enable Vreg pin. designed for masking endpoint 0, endpoint 1, and endpoint 2
interrupts. Other CY7C637xx interrupts are masked by the
mov A, VREG_ENABLE Global Interrupt Enable Register. Therefore, modifying the
iowr USB_Status_Control CY7C630/1xx Global Interrupt Enable Register is equivalent
to modifying both the Endpoint Interrupt Enable Register and
In the CY7C63000 mouse reference design, when a reset Global Interrupt Enable Register of the CY637xx as the
occurs, the firmware performs the following routines: example below illustrates.
1. Initializes variables and I/O registers. ;CY7C630/1xx. Enable 1ms and endpoint 0
2. Determines what type of reset has occurred by reading the ;interrupts by writing to the Global Interrupt
bits in the Status and Control Register, and takes appro- ;Enable Register.
priate reaction. ;mov A, 1MS_INT_AND_EP0_INT
;mov [interrupt_mask],A
a. If a USB Bus Reset has occurred, the firmware stays in
;iowr Global_Interrupt
a loop and waits for endpoint 1 to be configured. The
1-ms_interrupt and enpoint0_interrupt are enabled to
respond to the enumeration process happening at ;CY7C637xx. Enable 1ms Interrupt in the Global
endpoint 0. ;Interrupt Enable Reg and EP0 interrupt in the
;Endpoint Interrupt Register
b. If a WDR has occurred, the firmware stays in an infinite
loop and waits for a USB Bus Reset. The 1-ms_interrupt mov A, 1MS_INT
is enabled to put the chip into the sleep mode if there is iowr Global_Interrupt
no bus activity in 3 ms.
mov A, EP0_INT
c. Otherwise, the firmware puts the microcontroller into
suspend mode by writing 0x09 to the Status and Control iowr Endpoint_Interrupt
Register. ei
3. Jumps to the “main” function as soon as endpoint 1 is
enabled (enumeration process is done).

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

;If packet has been sent, the mode should


;have been changed to NAK_IN.
;CY630/1xx and CY637xx. Code unchanged.
cmp A, ACK_IN ;If it received a new idle
mov A,[new_idle_flag]
jz Nosend
;Period 4 ms before the previous one
cmp A,0
;Cy630/1xx and CY637xx. Codes unchanged.
;Loading new data to endpoint 1 FIFO ;Counted finishes, need to upgrade
mov A, [horizontal] jz reset_idle_period_counter
mov [horiz_position], A mov A,[new_idle_period]
mov A, [vertical] mov [idle_period],A
mov [vert_position], A mov A,0
mov A, [buttons] mov [new_idle_flag],A
mov [button_position], A jmp reset_idle_period_counter
reset_idle_period_counter:
;CY630/1xx. Load Data Toggle, set to send 3 mov A,0
;bytes. mov [idle_period_counter],A
;iord USB_EP1_TX_Config
;Keep the data 0/1 bit mov [horizontal], A
;and A, DataToggle mov [vertical], A
;Enable transmit 3 bytes
mov [button_flag], A

;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

You might also like