Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
Fujitsu Semiconductor Design (Chengdu) Co., Ltd. Setup Guide
MCU-AN-500096-E-11
F²MC-8FX FAMILY 8-BIT MICROCONTROLLER
MB95310/370 SERIES
MAIN CR TRIMMNG BOARD
SETUP GUIDE
Main CR Trimming Board Setup Guide V1.1 Revision History
MCU-AN-500096-E-11 – Page 1
Revision History
Date Author Change of Records 2010-6-18 Jane Li V1.0, First draft 2011-03-18 Jane Li V1.1, modified some remark
This manual contains 25 pages.
© 2010 Fujitsu Semiconductor Design (Chengdu) Co., Ltd.
2. The products described in this manual and the specifications thereof may be changed without prior notice. To obtain up-to-date information and/or specifications, contact your Fujitsu sales representative or Fujitsu authorized dealer.
3. Fujitsu will not be liable for infringement of copyright, industrial property right, or other rights of a third party caused by the use of information or drawings described in this manual.
4. The contents of this manual may not be transferred or copied without the express permission of Fujitsu.
5. The products contained in this document are not intended for use with equipment which require extremely high reliability such as aerospace equipment, undersea repeaters, nuclear control systems or medical equipment for life support.
6. Some of the products described in this manual may be strategic materials (or special technology) as defined by the Foreign Exchange and Foreign Trade Control Law. In such cases, the products or portions theory must not be exported without permission as defined under the law.
Main CR Trimming Board Setup Guide V1.1 CONTENTS
CONTENTS
REVISION HISTORY .............................................................................................................. 1 CONTENTS ............................................................................................................................ 2 1 PRODUCT OVERVIEW ................................................................................................... 3 2 TRIMMING BOARD DESCRIPTION ............................................................................... 4 3 TRIMMING DESCRIPTION ............................................................................................. 5
3.1 Trimming Register ..................................................................................................... 5
3.2 Trimming Method ...................................................................................................... 6
3.3 Trimming Flow Chart ................................................................................................. 7
4 SAMPLE CODE MANUAL .............................................................................................. 8 4.1 Project Structure ....................................................................................................... 8
4.2 Source Code File Description ................................................................................... 9
4.2.1 _f2mc8fx_a.asm .......................................................................................... 9
4.2.2 startup.asm ................................................................................................. 9
4.2.3 MAIN.asm ................................................................................................. 10
4.3 Sample Code Description ....................................................................................... 11
4.3.1 ERASE_FLASH_Drive Function ............................................................... 11
4.3.2 ERASE_FlahAS0AS3 Function ................................................................. 12
4.3.3 RENEW_SA0StartAddress Function ........................................................ 13
4.3.4 Trimm_API Function ................................................................................. 14
4.3.5 Bi_Section Function .................................................................................. 16
4.3.6 Trimm_Out Function ................................................................................. 17
4.3.7 Trimm_FlashWrite Function ...................................................................... 18
4.3.8 WRITE_FLASH_Drive Function ................................................................ 19
4.3.9 LED_Contr Function .................................................................................. 20
4.3.10 _Uart_Interrupt Function ........................................................................... 21
4.3.11 _uart_init Function ..................................................................................... 23
4.3.12 _uart_send Function ................................................................................. 24
4.3.13 __main Function ........................................................................................ 24
MCU-AN-500096-E-11 – Page 2
Main CR Trimming Board Setup Guide V1.1 Chapter 1 Product Overview
1 Product Overview
MAIN CR trimming board is mainly used for MCU trimming and programming.
The trimming board includes sample code which supplies main CR trimming and programming by different modes. When pull P52 low, the system will enter into trimming mode and finish trimming work. When P52 is low, pulling P53 to low, the system will enter into programming mode, receive all program data from host, and then write all data to flash.
In following chapters, the trimming will be described in detail.
MCU-AN-500096-E-11 – Page 3
Main CR Trimming Board Setup Guide V1.1 Chapter 2 Trimming Board Description
2 Trimming Board Description
This chapter introduces the hardware connection.
The MAIN CR trimming board supports pin to select work mode, UART to receive and send data, trimming clock input.
Following figure describes the hardware connection.
P11
P10
P52
P53
UART output
UART input
Trimming select
Programming select
100Hz
GND
VCC
P51
Following table describes the mode condition. Mode Condition Pin Status
User mode P52 high
Trimming mode P52 low
Programming mode P52 low and P53 low
MCU-AN-500096-E-11 – Page 4
Main CR Trimming Board Setup Guide V1.1 Chapter 3 Trimming Description
3 Trimming Description
This chapter introduces the trimming method.
Trimming is adjusting main CR clock and making it more precise.
3.1 Trimming Register There are two registers “CRTH” and “CRTL” which can adjust the main CR by low 11 bits. And there are two flash addresses “0xFFBC” and “0xFFBD” to record these two registers values. After a reset, the register CRTH value is reloaded from flash 0xFFBC and the register CRTL value is reloaded from 0xFFBD.
Following picture listed these registers.
Note: These 11 bits CRTL0~CRTL5 and CRTH0~CRTH4 adjust the main CR.
MCU-AN-500096-E-11 – Page 5
Main CR Trimming Board Setup Guide V1.1 Chapter 3 Trimming Description
3.2 Trimming Method Trimming is finished by writing 0 or 1 to adjust bits, and trimming is validated by timer counter and external inputting clock.
Following steps describe the trimming method:
1. Set initial SREG [11:0] = 11111_000000 ; CRTL0~CRTL5 and CRTH0~CRTH4
2. Clear SREG [11] = 1. ; SREG [11] = CRTH4
3. If CLK_1M_PIN >= 1MHz, set SREG [11].
4. Repeat step (2) to (3) for SREG [10:7].
5. Set SREG [6] = 1. ; SREG [6] = CRTL5
6. If CLK_1M_PIN < 1MHz, clear SREG [6].
7. Repeat step (5) to (6) for SREG [5:0].
Note: The counter value is bigger than setting value (0x2710 for 100Hz clock input and main CR is 1MHz), which indicates the CLK_1M_PIN>1MHz.
The counter value is smaller than setting value (0x2710 for 100Hz clock input and main CR is 1MHz), which indicates the CLK_1M_PIN<1MHz.
MCU-AN-500096-E-11 – Page 6
Main CR Trimming Board Setup Guide V1.1 Chapter 3 Trimming Description
3.3 Trimming Flow Chart For detailed trimming method, please refer to following flow chart.
MCU-AN-500096-E-11 – Page 7
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4 Sample Code Manual
4.1 Project Structure There is a project MAIN_CR.prj for MAIN CR trimming sample code.
The following structure describes the flow chart of this project, as shown in Figure 4-1.
Figure 4-1: Project Structure
MCU-AN-500096-E-11 – Page 8
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.2 Source Code File Description Eight drive files are available in this project shown below.
Figure 4-2: Source Code Files
4.2.1 _f2mc8fx_a.asm Every MCU register is defined in this function.
4.2.2 startup.asm This function define reset address, watch dog, set stack address, set interrupt input level and call main function.
MCU-AN-500096-E-11 – Page 9
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.2.3 MAIN.asm In this function, all trimming, flash operations and UART operations are finished.
Following table lists all function names. Function Name Description
ERASE_FLASH_Drive: Driver for flash erase
ERASE_FlahAS0AS3: Erase flash sector0(0xC000~0xFFFF) and sector3(0x2000~0x3FFF)
RENEW_SA0StartAddress: Because sector0 has been erased, the start address and other define had been erased. So user need to renew the start address and other define, such as interrupt and watchdog
Trimm_API: Trimming application function which call Bi-section to realize trimming
Bi_Section: Test the trimmed main CR is bigger or smaller than 1MHz
Trimm_Out: If user want to see the main CR, the function can be called to output main CR
Trimm_FlashWrite: Write trimming value to flash 0xFFBC and 0xFFBD
WRITE_FLASH_Drive: Use flash write command to realize one byte write
LED_Contr If flash write error the function will be called to Let p14 pull low
_Uart_Interrupt: UART interrupt to receive host programming data
_uart_init: Initialize UART register
_uart_send UART send one byte out
__main Main function to call all functions
MCU-AN-500096-E-11 – Page 10
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3 Sample Code Description In following item the sample code will be described in detail.
4.3.1 ERASE_FLASH_Drive Function
ERASE_FLASH_Drive:
SETB FSR:1
MOV SWRE0,#03FH ;write all flash sector
MOV A,#0AAH ;1st write cycle
MOV 0FAAAH,A
MOV A,#055H ;2nd write cycle
MOV 0A554H,A
MOV A,#080H ;3rd write cycle
MOV 0FAAAH,A
MOV A,#0AAH ;4th write cycle
MOV 0FAAAH,A
MOV A,#055H ;5th write cycle
MOV 0A554H,A
MOVW A,#00H
MOVW A,Erase_Addr
MOVW EP, A
MOV A, #030h
MOV @EP, A
nop
nop
WaitErase:
BBC FSR:4,WaitErase
CLRB FSR:1 ; write disable
RET
MCU-AN-500096-E-11 – Page 11
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3.2 ERASE_FlahAS0AS3 Function .3.2 ERASE_FlahAS0AS3 Function
ERASE_FlahAS0AS3:
MOVW A,#SA0
MOVW Erase_Addr,A
CALL ERASE_FLASH_Drive
MOVW A,#SA3
MOVW Erase_Addr,A
CALL ERASE_FLASH_Drive
RET
MCU-AN-500096-E-11 – Page 12
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3.3 RENEW_SA0StartAddress Function .3.3 RENEW_SA0StartAddress Function
RENEW_SA0StartAddress:
MOVW A,#0FFBEH ;WATCH DOG
MOVW Addr_Flash,A
MOV A,#0A5H ;0xA596 to flash
MOV _UARTREC,A
CALL WRITE_FLASH_Drive
MOVW A,#0FFBFH
MOVW Addr_Flash,A
MOV A,#096H
MOV _UARTREC,A
CALL WRITE_FLASH_Drive
MOVW A,#0FFF2H ;UART INTERRUPT INTER
MOVW Addr_Flash,A
MOVW A, #_Uart_Interrupt
SWAP
MOV _UARTREC,A
CALL WRITE_FLASH_Drive
MOVW A,#0FFF3H
MOVW Addr_Flash,A
MOVW A,#_Uart_Interrupt
MOV _UARTREC,A
CALL WRITE_FLASH_Drive
MOVW A,#0FFFDH ;MAIN CR output set
MOVW Addr_Flash,A
MOV A,#40H
MOV _UARTREC,A
CALL WRITE_FLASH_Drive
MOVW A,#0FFFEH ;-start
MOVW Addr_Flash,A
MOVW A, #__start
SWAP
MOV _UARTREC,A
CALL WRITE_FLASH_Drive
MOVW A,#0FFFFH
MOVW Addr_Flash,A
MOVW A,#__start
MOV _UARTREC,A
CALL WRITE_FLASH_Drive
RET
MCU-AN-500096-E-11 – Page 13
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3.4 Trimm_API Function .3.4 Trimm_API Function
MOV CRTH_RAM,#08FH ;nvrm=1/1MHz/SREG[11:7]=10000b
MOV CRTL_RAM,#001H ;tsel=00/SREG[6:1]=000000b
CALL Bi_Section ;1st measurement & comparison with 1MHz
BC SKIP1 ;branch out if < 1MHz counter value
SETB CRTH_RAM:4 ;make SREG[11] = 0
1:
CLRB CRTH_RAM:3 ;set SREG[10] = 1 for 2nd measurement
CALL Bi_Section ;2nd measurement & comparison with 1MHz
BC SKIP2 ;branch out if < 1MHz counter value
SETB CRTH_RAM:3 ;make SREG[10] = 0
2:
CLRB CRTH_RAM:2 ;set SREG[9] = 1 for 3rd measurement
CALL Bi_Section ;3rd measurement & comparison with 1MHz
BC SKIP3 ;branch out if < 1MHz counter value
SETB CRTH_RAM:2 ;make SREG[9] = 0
3:
CLRB CRTH_RAM:1 ;set SREG[8] = 1 for 4th measurement
CALL Bi_Section ;4th measurement & comparison with 1MHz
BC SKIP4 ;branch out if < 1MHz counter value
SETB CRTH_RAM:1 ; make SREG[8] = 0
4:
CLRB CRTH_RAM:0 ;set SREG[7] = 1 for 5th measurement
CALL Bi_Section ;5th measurement & comparison with 1MHz
BC SKIP5 ;branch out if < 1MHz counter value
SETB CRTH_RAM:0 ;make SREG[7] = 0
R_SETTING:
MOV A,#00EH ;falling-counter-clear /1xMCLK/IFE=0
MOV T00CR0,A
MOV T00CR1,#00H ;interrupt disable, output disable
MOV A,#1CH
MOV TMCR0,A ;16-bit mode, timer01 not used
mm_API:
MOV SYCC2,#0E5H ;change to MAIN CR; sub-CR off
AIT:
BBS SYCC2:6,MCRWAIT ;loop until main CR is stable and ched
MCU-AN-500096-E-11 – Page 14
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
SKIP5:
MOV A,CRTH_RAM ;increment SREG[11:7] to make sure > 1MHz
DECW A
MOV CRTH_RAM,A
SETB CRTL_RAM:5 ;set SREG[6] = 1 for 6th measurement
CALL Bi_Section ;6th measurement & comparison with 1MHz
BNC SKIP6 ;branch out if >= 1MHz counter value
CLRB CRTL_RAM:5 ;make SREG[6] = 0
SKIP6:
SETB CRTL_RAM:4 ;set SREG[5] = 1 for 7th measurement
CALL Bi_Section ;7th measurement & comparison with 1MHz
BNC SKIP7 ;branch out if >= 1MHz counter value
CLRB CRTL_RAM:4 ;make SREG[5] = 0
SKIP7:
SETB CRTL_RAM:3 ;set SREG[4] = 1 for 8th measurement
CALL Bi_Section
BNC SKIP8 ;branch out if >= 1MHz counter value
CLRB CRTL_RAM:3
SKIP8:
SETB CRTL_RAM:2 ;set SREG[3] = 1 for 9th measurement
CALL Bi_Section
BNC SKIP9 ;branch out if >= 1MHz counter value
CLRB CRTL_RAM:2
SKIP9:
SETB CRTL_RAM:1 ;set SREG[2] = 1 for 10th measurement
CALL Bi_Section
BNC SKIP10 ;branch out if >= 1MHz counter value
CLRB CRTL_RAM:1
SKIP10:
SETB CRTL_RAM:0 ;set SREG[1] = 1 for 11th measurement
CALL Bi_Section
BNC SKIP11 ;branch out if >= 1MHz counter value
CLRB CRTL_RAM:0
SKIP11:
MOV A,CRTH_RAM
MOV CRTH,A
MOV A,CRTL_RAM
MOV CRTL,A
MOVW A,#00068H ;wait 104 cycles for stabalization
LOOP1:
DECW A
BGE LOOP1
CALL Trimm_FlashWrite
RET
MCU-AN-500096-E-11 – Page 15
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3.5 Bi_Section Function .3.5 Bi_Section Function
BGE LOOP2
SETB T00CR1:7 ;enable counter
LOOP3:
BBC T00CR1:4,LOOP3 ;loop until IR=1
CLRB T00CR1:4 ;ignore 1st value (not complete cycle)
LOOP4:
BBC T00CR1:4,LOOP4
MOV A,T01DR ;move counter value to A
SWAP
MOV A,T00DR
CLRB T00CR1:4
CLRB T00CR1:7 ;stop timer
XCHW A,T ;T = measured value (16-bit)
MOVW EP,#02710H
XCHW A,EP
CLRC
SUBCW A ;A = T - 2710h
RET
Bi_Section:
MOV A,CRTH_RAM
MOV CRTH,A ;write frequency/current trim
MOV A,CRTL_RAM
MOV CRTL,A ;write cap trim
MOVW A,#00068H ;wait 104 cycles for stabalization
LOOP2: ;(6 machine cycles per loop)
DECW A ;(=320us if CLK_1M_PIN=2MHz)
MCU-AN-500096-E-11 – Page 16
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3.6 Trimm_Out Function .3.6 Trimm_Out Function
Trimm_Out:
SETB PDR6:2
SETB DDR6:2
MOV A,#080H
MOV LCDCE1,A
RET
MCU-AN-500096-E-11 – Page 17
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3.7 Trimm_FlashWrite Function .3.7 Trimm_FlashWrite Function
MOV A,CRTL_RAM ;store CRTL_RAM value to AH
MOV _UARTREC,A
CALL WRITE_FLASH_Drive
CALL RENEW_SA0StartAddress
RET
Trimm_FlashWrite:
MOVW A,#0FFBCH
MOVW Addr_Flash,A ;load CRTH flash address to EP
MOV A,CRTH_RAM ;store CRTH_RAM value to AH
OR A,#01100000B ;***** change 1MHz to 8MHz *****
MOV _UARTREC,A
CALL ERASE_FlahAS0AS3
CALL WRITE_FLASH_Drive ;write trim value to flash
MOVW A,Addr_Flash
INCW A ;increment to CRTL flash address at EP
MOVW Addr_Flash,A
MCU-AN-500096-E-11 – Page 18
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3.8 WRITE_FLASH_Drive Function .3.8 WRITE_FLASH_Drive Function
BNE WRITE_FLASH_NG
JMP WRITE_FLASH_END
WRITE_FLASH_NG:
CALL LED_Contr
WRITE_FLASH_END:
RET
WRITE_FLASH_Drive:
SETB FSR:1
MOV SWRE0,#03FH ;write all flash sector
CMP _UARTREC,#0FFH ;skip writing to flash if <> FFh
BZ WRITE_FLASH_END
MOV A,#0AAH ;1st write cycle
MOV 0FAAAH,A
MOV A,#055H ;2nd write cycle
MOV 0A554H,A
MOV A,#0A0H ;3rd write cycle
MOV 0FAAAH,A
MOVW A,#00H
MOVW A,Addr_Flash
CLRC
ADDC A,FlashAdrrOffs
MOVW EP, A
MOV A, _UARTREC
MOV @EP, A
MOVW A,#27B6H ;wait 6100us (spec prog time max)
LOOPF3:
DECW A
BNE LOOPF3
MOV A,_UARTREC
CMP A,@EP
MCU-AN-500096-E-11 – Page 19
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3.9 LED_Contr Function .3.9 LED_Contr Function
CLRB PDR1:4 ;CLRB PDR1:4
RET
LED_Contr: ;ERROR
SETB DDR1:4 ;OUTPUT DIRECT
MCU-AN-500096-E-11 – Page 20
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3.10 _Uart_Interrupt Function .3.10 _Uart_Interrupt Function
MOV Addr_Flash,A
JMP INTEND
LOOPU2:
CMP FlagProgram,#02H
BNZ LOOPU3
MOV A,Addr_Flash
SWAP
CLRC
ADDC A,_UARTREC
MOVW Addr_Flash,A
MOV FlagProgram,#3H
JMP INTEND
_Uart_Interrupt:
WaitRec:
CLRC
BBC SSR0:2,WaitRec ;RECEIVE REGISTER FULL
MOV A,RDR0
MOV _UARTREC,A
CMP FlagProgram,#00h ;_UARTREC,#051H
BNZ LOOPU1 ;NOT ==
CMP _UARTREC,#051H
BNZ TOEND
MOV FlagProgram,#1H
TOEND:
JMP INTEND
LOOPU1:
CMP FlagProgram,#01H
BNZ LOOPU2
MOV FlagProgram,#2H
MOV A,_UARTREC
MCU-AN-500096-E-11 – Page 21
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
LOOPU3:
CMP FlagProgram,#03H
BNZ LOOPU4
MOV FlagProgram,#4H
MOVW A,#0000H
MOV A,_UARTREC
MOV Length_Flash,A
JMP INTEND
LOOPU4:
CMP FlagProgram,#04H
BNZ LOOPU5
MOV A,Length_Flash
SWAP
CLRC
ADDC A,_UARTREC
MOV Length_Flash,A
MOV FlagProgram,#5H
JMP INTEND
LOOPU5:
CMP FlagProgram,#05H
BNZ INTSUM
CALL WRITE_FLASH_Drive
MOVW A,#00H
MOV A,Sum_Writ
ADDC A,_UARTREC
MOV Sum_Writ,A
MOV A,FlashAdrrOffs
INCW A
MOV FlashAdrrOffs,A
MOV A,Length_Flash
CLRC
DECW A
MOV Length_Flash,A
CMP Length_Flash,#00H
BNZ INTEND
MOV FlagProgram,#6H
JMP INTEND
MCU-AN-500096-E-11 – Page 22
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
4.3.11 _uart_init Function
INTSUM:
CMP FlagProgram,#06H
BNZ INTEND
MOV FlagProgram,#0H
MOV A,_UARTREC
CMP A,Sum_Writ
BZ SendACK
call LED_Contr
JMP INTEND
SendACK:
call _uart_send
call 2000H ;call programming content
INTEND:
RETI
_uart_init:
MOV A,CRTH
AND A,#09FH
OR A,#060H
MOV CRTH,A ;CHANGE MAIN CR TO 8MHZ
MOV A,#0cH
MOV SMC10,A
MOV A,#0dcH
MOV SMC20,A
CLRB SSR0:1
CLRB PUL1:0
CLRB PUL1:1
MOV A,#00H
MOV ILSR,A
MOV A,#05H ;BAUD RATE SET
MOV PSSR0,A
MOVW A,#0D0H
MOV BRSR0,A /*******
baud rate = mclk/ (4*pssr0*brsr0)=8/(4*2*208)=4800
********/
MOV A,#0FCH
MOV ILR1,A ;INTERRUPT LEVEL TO 00
MOV FlashAdrrOffs,#0H
RET
MCU-AN-500096-E-11 – Page 23
Main CR Trimming Board Setup Guide V1.1 Chapter 4 Sample Code Manual
MCU-AN-500096-E-11 – Page 24
4.3.12 _uart_send Function .3.12 _uart_send Function
_uart_send:
LoopTran:
BBC SSR0:0,LoopTran
mov A, #00H ; ACK normal
mov TDR0, A
RET
4.3.13 __main Function 4.3.13 __main Function __main:
SETI
MOV FlagProgram,#0H
MOV FlashAdrrOffs,#00H ;initialize it
MOV Sum_Writ,#00H
CLRB DDR5:2
CLRB DDR5:3
BBS PDR5:3,UserMode
call Trimm_Out
call Trimm_API
WAITUART:
BBS PDR5:2,WAITUART
call _uart_init
UserMode:
jmp $
RET
MCU-AN-500096-E-10
FUJITSU SEMICONDUCTOR LIMITED • SUPPORT SYSTEM
F2MC-8FX Family MB95310/370 Series
MAIN CR Trimming Board
SETUP GUIDE
Jun. 2010 the first edition
Published FUJITSU SEMICONDUCTOR LIMITED
Edited Strategic Business Development Dept