Freescale Semiconductor Application Note AN3216 Rev. 0, 2/2006 Interfacing HCS12 Microcontrollers to the MFR4200 FlexRay Controller by: David Paterson MCD Applications, East Kilbride 1 Introduction Freescale Semiconductor offers a range of standalone FlexRay communication controllers (MFR4xxx) that can be interfaced with 16-bit and 32-bit microcontrollers (MCU). This application note describes the hardware, software, and timing considerations necessary for reliable communication between the MFR4200 controller and the HCS12 family of MCUs. 2 Table of Contents 1 2 3 4 5 6 7 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Hardware Design . . . . . . . . . . . . . . . . . . . . . . . . . 3.1 Selecting the HCS12 Mode . . . . . . . . . . . . . . 3.2 Paged Mode and Unpaged Mode . . . . . . . . . Timing Considerations . . . . . . . . . . . . . . . . . . . . . Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1 Mode Configuration and EBI Operation. . . . . 5.2 Placement of MFR4200 in Memory Map . . . . Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 2 2 2 6 7 7 8 8 8 Objective The aim of the document is to demonstrate the simplicity of the hardware interface between the MFR4200 and the HCS12, and to provide an example of the software used to configure the HCS12 for operation. The information contained can help you quickly design a fully functional FlexRay node based on the HCS12 family of MCUs. Evaluation boards with software are available from Freescale to assist in the development of FlexRay applications. (See http://www.freescale.com/flexray.) Note: In this document, active-low signals are indicated by a “#” at the end of the signal name, e.g. “IRQn#”. © Freescale Semiconductor, Inc., 2006. All rights reserved. Hardware Design 3 Hardware Design The MFR4200 FlexRay controller has two separate controller host interfaces (CHI) on board — an HCS12 interface, for direct connection to Freescale’s HCS12 family of microcontrollers, and an asynchronous memory interface (AMI) for asynchronous connection to all other microcontrollers. The HCS12 interface clock signal, used to synchronize the data transfer, can run at a maximum rate of 8 MHz. Chip selection for the HCS12 interface is generated internally using the following signals: • The expanded address signals XADDR[14:19] input values (HCS12 is in the Paged or Unpaged mode of its External Bus Interface (EBI)) are compared with the logical 0’s. • The six most significant bits of the demultiplexed address bus, PAD[10:15], are compared with the pattern set up externally on the address chip select pins, ACS[0:5]. PAD10 is compared with ACS0, PAD11 with ACS1, …PAD15 with ACS5. NOTE The address decoding phase of a read/write operation is passed if all the comparisons described above are passed. The devices can be connected together without additional glue logic, thereby simplifying the design and reducing the system cost. 3.1 Selecting the HCS12 Mode There are two modes of operation for the controller host interface (CHI), the AMI mode and the HCS12 mode. The HCS12 mode is used to interface to the HCS12 Family of microcontrollers. To select the HCS12 mode, IF_SEL1 must be at the logic high level and IF_SEL0 must be at the logic low level. When using 3.3 V VDDIO, for example, IF_SEL1 must be pulled high using a 16 kΩ pullup resistor, and IF_SEL0 must be pulled low using a 47 kΩ pulldown resistor. (Similarly, at 3.3 V VDDIO, INT_CC# must be held high by a 16 kΩ pullup resistor.) 3.2 Paged Mode and Unpaged Mode There are two modes of operation that can be used when interfacing the HCS12 and MFR4200 microcontrollers — paged and unpaged mode. Figure 1 and Figure 2 show block diagrams with all the EBI connections that are necessary for each mode of operation. Table 1 provides a description of each signal and pin that must be connected to interface the MFR4200 to a typical HCS12 MCU, the MC9S12DP256B in a 112-pin LQFP package. Interfacing HCS12 Microcontrollers to the MFR4200 FlexRay Controller, Rev. 0 2 Freescale Semiconductor Hardware Design ADDR/DATA0 … … PAD0 … … ADDR/DATA15 MFR4200 PAD15 VDDIO ACS5 ACS4 VDDIO ACS3 … … … … … VDDIO ACS0 ECLK ECLK_CC R/W# RW_CC# LSTRB LSTRB XADDR14 … XADDR14 … … … … … XADDR19 XADDR19 EBI VDDIO IRQn# INT_CC# VDDIO HCS12 TO THE PHY IF_SEL1/TXD_BG1/TXD_485 TO THE PHY IF_SEL0/BGT/DBG2 Figure 1. Connecting MFR4200 to HCS12 with Page Mode Support Interfacing HCS12 Microcontrollers to the MFR4200 FlexRay Controller, Rev. 0 Freescale Semiconductor 3 Hardware Design ADDR/DATA0 … … … … PAD0 … … ADDR/DATA15 MFR4200 PAD15 VDDIO ACS5 … … … … … VDDIO ACS0 ECLK ECLK_CC R/W# RW_CC# LSTRB LSTRB 6 XADDR[14:19] EBI VDDIO IRQn# INT_CC# VDDIO HCS12 TO THE PHY IF_SEL1/TXD_BG1/TXD_485 TO THE PHY IF_SEL0/BGT/DBG2 Figure 2. Connecting MFR4200 to HCS12 with Unpaged Mode Support Interfacing HCS12 Microcontrollers to the MFR4200 FlexRay Controller, Rev. 0 4 Freescale Semiconductor Hardware Design Table 1. Interface Signal Description HCS12 to MFR4200 Connection MC9S12DP256B (112-Pin LQFP) MFR200 Comments Signal Pin Signal Pin ADDR0/DATA0/PB0 24 D15/PAD0 10 HCS12 data/address bus (LSB) ADDR1/DATA1/PB1 25 D14/PAD1 7 HCS12 data/address bus ADDR2/DATA2/PB2 26 D13/PAD2 6 HCS12 data/address bus ADDR3/DATA3/PB3 27 D12/PAD3 5 HCS12 data/address bus ADDR4/DATA4/PB4 28 D11/PAD4 4 HCS12 data/address bus ADDR5/DATA5/PB5 29 D10/PAD5 3 HCS12 data/address bus ADDR6/DATA6/PB6 30 D9/PAD6 2 HCS12 data/address bus ADDR7/DATA7/PB7 31 D8/PAD7 62 HCS12 data/address bus PA0/ADDR8/DATA8 57 D7/PAD8 61 HCS12 data/address bus PA1/ADDR9/DATA9 58 D6/PAD9 58 HCS12 data/address bus PA2/ADDR10/DATA10 59 D5/PAD10 57 HCS12 data/address bus PA3/ADDR11/DATA11 60 D4/PAD11 56 HCS12 data/address bus PA4/ADDR12/DATA12 61 D3/PAD12 55 HCS12 data/address bus PA5/ADDR13/DATA13 62 D2/PAD13 51 HCS12 data/address bus PA6/ADDR14/DATA14 63 D1/PAD14 40 HCS12 data/address bus PA7/ADDR15/DATA15 64 D0/PAD15 39 HCS12 data/address bus XADDR14/PK0 8 A6/XADDR14 17 Extended addresses (page mode) XADDR15/PK1 7 A5/XADDR15 15 Extended addresses (page mode) XADDR16/PK2 6 A4/XADDR16 14 Extended addresses (page mode) XADDR17/PK3 5 A3/XADDR17 13 Extended addresses (page mode) XADDR18/PK4 20 A2/XADDR18 12 Extended addresses (page mode) XADDR19/PK5 19 A1/XADDR19 11 Extended addresses (page mode) ECLK/PE4 39 ECLK_CC 52 HCS12 clock input R/W#/PE2 54 WE#/RW_CC# 30 HCS12 read/write select signal LSTRB/TAGL0/PE3 53 CE#/LSTRB 29 HCS12 low-byte strobe signal GPIO (or PU/PD) ACS0–ACS5 18, 21, 22, 27, 28, 34 HCS12 address select inputs GPIO RESET# 16 Hardware reset input INT_CC# 64 Controller interrupt output BGT/DBG2/IF_SEL0 32 Host interface selection = LOW (HCS12 mode) TXD_BG1/TXD1_485/IF_SEL1 41 Host interface selection = HIGH (HCS12 mode) PE1/IRQ# 55 Interfacing HCS12 Microcontrollers to the MFR4200 FlexRay Controller, Rev. 0 Freescale Semiconductor 5 Timing Considerations 4 Timing Considerations For the HCS12 and the MFR4200 communication controller to communicate reliably, the timing between the HCS12 and the MFR4200 must be matched. There is a requirement for the addition of stretch cycles1 to match the timing characteristics. Refer to Section 8, “MFR4200 HCS12 Timing Specifications” for specific timing diagrams. A minimum of one stretch cycle must be inserted when running with an 8 MHz external clock. Table 3 summarizes the read and write timing for one stretch cycle, which is required for successful operation. The number of stretch cycles that can be added is controlled in the Miscellaneous System Control Register (MISC). Refer to the Module Mapping Control (MMC) section of the user manual. The available options are shown in Table 2. Table 2. Stretch Cycle Selection External Access Stretch Bit Definition EXSTR[1:0] Number of E Clocks Stretched 00 0 cycles 01 1 cycle 10 2 cycles 11 3 cycles Table 3. HCS12 to MFR4200 Timing Parameters with One Stretch Cycle Specified Num 1 Wait Rating Min Max Measured Comment 1 Pulse width, ECLK low 25 — 685 PASS 2 Pulse width, ECLK high 114 — 190 PASS 3, 11 Address valid time to E rise 11 — 54 PASS 4 Write data delay time — 7 4 PASS 5 ECLK rise to write data invalid 71 — 184 PASS Write data hold time 2 — 2 PASS 6 (4) 7 RW delay time — 7 0 PASS 8 RW valid time to ECLK rise 14 — 56 PASS 9 RW hold time 2 — 2 PASS 10 Data hold to address 2 — 54 PASS 12 Multiplexed address hold time 2 — 64 PASS 13 ECLK high access time (ECLK high to read data valid) 50 75 70 PASS 14 Read data setup time 13 — 120 PASS 15 Read data hold time 0 — 97 PASS 1. When accessing on-chip peripherals and memories, the HCS12 performs 8-bit and 16-bit core accesses in a single cycle. However, when the core accesses locations on the external bus using the expanded modes, the accesses are stretched and take more than a single cycle to complete. The minimum amount of stretching is one additional bus cycle, but can be increased. See Table 2 for details. Interfacing HCS12 Microcontrollers to the MFR4200 FlexRay Controller, Rev. 0 6 Freescale Semiconductor Software 5 Software The software setup is concerned mainly with selection of the correct MCU operating mode, configuration of the HCS12 for communication with the MFR4200, and linking into the correct area of the memory map. 5.1 Mode Configuration and EBI Operation As already stated, the HCS12 must be configured into normal expanded mode to enable the bus interface. In this mode, ports A and B are configured for the data/address bus, and port E is configured for the control signals. During initialization, the EBI is configured, and the mode is set to normal expanded wide (BDM allowed) mode by writing MODC = 1, MODB = 1, and MODA = 1 in the MODE register. The EBI must be initialized to use the correct chip select and to select the correct number of stretch cycles. See Section 4, “Timing Considerations” for specific details. Figure 3 shows the steps required to configure the HCS12 MCU for communication with the MFR4200 controller. Set up ports Set up ACS signals (ACS[5:0] = 100000) Enable the EBI and control signals Enable stretch clock and number of stretch cycles Set normal expanded wide mode Figure 3. Initialization Flow Diagram Interfacing HCS12 Microcontrollers to the MFR4200 FlexRay Controller, Rev. 0 Freescale Semiconductor 7 Conclusions 5.2 Placement of MFR4200 in Memory Map The global address, associated with each chip select signal, is generated by a concatenation of the HCS12 local address [15:0] with the global page index register, where the page index bits are effectively used to select which of the 128 x 64 Kbyte pages is to be accessed. In order to access global addressing, specific global instructions must be used. For example: GLDD — Load double accumulator D (A:B) from global memory. GSTAA — Store the contents of accumulator A into global memory In Metrowerks CodeWarrior, the FAR qualifier is used to tell the compiler to use the global instructions included in the HCS12 CPU. An example of how to place the MFR4200 registers into the memory map is shown below. Example: #define BASE_ADDRESS 0x8000 #define MNR (*(volatile unsigned int* far)(0x000 + BASE_ADDRESS)) #define MVR (*(volatile unsigned int* far)(0x002 + BASE_ADDRESS)) #define MCR0 (*(volatile unsigned int* far)(0x004 + BASE_ADDRESS)) In this option, the placement of the memory map can be changed by modifying the BASE_ADDRESS. The selected BASE_ADDRESS of 8000 is in the CS2# address range.1 6 Conclusions The FlexRay controller can be connected to the HCS12 Family of MCUs, with a maximum interface clock frequency (to synchronize data transfer) of 8 MHz. Due to this specific interface between the HCS12 microcontrollers and MFR4200 FlexRay controller, no glue logic required. Software configuration is also straightforward, the peripheral being simply memory-mapped into the global address space. 7 References 1. MC9S12DP256B Data Sheet 2. MFR4200 FlexRay Communication Controller Data Sheet These documents are available on the Freescale Semiconductor web site at http://www.freescale.com. More information on FlexRay and FlexRay products can be found at http://www.freescale.com/flexray 1. Many alternative methods of defining the MFR4200 register exist. Interfacing HCS12 Microcontrollers to the MFR4200 FlexRay Controller, Rev. 0 8 Freescale Semiconductor References Interfacing HCS12 Microcontrollers to the MFR4200 FlexRay Controller, Rev. 0 Freescale Semiconductor 9 How to Reach Us: Home Page: www.freescale.com E-mail: [email protected] USA/Europe or Locations Not Listed: Freescale Semiconductor Technical Information Center, CH370 1300 N. Alma School Road Chandler, Arizona 85224 +1-800-521-6274 or +1-480-768-2130 [email protected] Europe, Middle East, and Africa: Freescale Halbleiter Deutschland GmbH Technical Information Center Schatzbogen 7 81829 Muenchen, Germany +44 1296 380 456 (English) +46 8 52200080 (English) +49 89 92103 559 (German) +33 1 69 35 48 48 (French) [email protected] Japan: Freescale Semiconductor Japan Ltd. Headquarters ARCO Tower 15F 1-8-1, Shimo-Meguro, Meguro-ku, Tokyo 153-0064 Japan 0120 191014 or +81 3 5437 9125 [email protected] Asia/Pacific: Freescale Semiconductor Hong Kong Ltd. Technical Information Center 2 Dai King Street Tai Po Industrial Estate Tai Po, N.T., Hong Kong +800 2666 8080 [email protected] For Literature Requests Only: Freescale Semiconductor Literature Distribution Center P.O. Box 5405 Denver, Colorado 80217 1-800-441-2447 or 303-675-2140 Fax: 303-675-2150 [email protected] AN3216 Rev. 0, 2/2006 Information in this document is provided solely to enable system and software implementers to use Freescale Semiconductor products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document. Freescale Semiconductor reserves the right to make changes without further notice to any products herein. Freescale Semiconductor makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does Freescale Semiconductor assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. “Typical” parameters that may be provided in Freescale Semiconductor data sheets and/or specifications can and do vary in different applications and actual performance may vary over time. All operating parameters, including “Typicals”, must be validated for each customer application by customer’s technical experts. Freescale Semiconductor does not convey any license under its patent rights nor the rights of others. Freescale Semiconductor products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the Freescale Semiconductor product could create a situation where personal injury or death may occur. Should Buyer purchase or use Freescale Semiconductor products for any such unintended or unauthorized application, Buyer shall indemnify and hold Freescale Semiconductor and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that Freescale Semiconductor was negligent regarding the design or manufacture of the part. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2006. All rights reserved.