资源预览内容
第1页 / 共31页
第2页 / 共31页
第3页 / 共31页
第4页 / 共31页
第5页 / 共31页
第6页 / 共31页
第7页 / 共31页
第8页 / 共31页
第9页 / 共31页
第10页 / 共31页
亲,该文档总共31页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Boot Loader A Key Technique for MCU Development 清华清华 Freescale MCU/DSP 应用开发研究中心应用开发研究中心Monitor/Debug or Boot Loader A basic residential program in MCU Initialize the MCU system Communication with people Download application program from outside and run Some debug utilities It is a basic development tool for Hardware and Software A Minimum MCU System A minimum MCU system is the BASIC hardware tool foe application development Basic hardware system includes: Power supply Reset circuit Clock circuit A communication port (in most case: RS-232)Tools for Hardware Test Power supplyMulti-meter Rest Multi-meter Clock circuitOscilloscope Be careful with the PCB design,reserve a oscillator module on the PCB RS-232Multi-meter Oscilloscope Need a program to test: Initial SCI Send out a ASCII loopNeed a tool to download program (BDM) anywayMonitor/Debug (Boot Loader) Initialize the MCU system Communication with people Download application program from outside and run Some debug utilitiesInitialize the MCU system Initial Stack Pointer SPLDS #STACK ; Init. Stack Pointer Initial SCI SCI need system clock, which maybe complicated Use external clock first Then the PLL initialInitial SCISC_Init LDAA #$0C ; Initial SCI STAA SCI0CR2 ; Enable T Use default Protocol STAA SCI0BDH ; 8b, No parity,1stop LDAA #$9C ; 9600 baud rate (clock related) STAA SCI0BDL SCI clock = baud rate x 16 = bus clock/dividerBus clock is from external clock OR PLL!May not needSCI Test and DebugWrite a program send: AAAAAAAAAAAAAAAAAAOUTCH LDB#A OUTCH1BRCLR SCI0SR1,#$80,* STABSCI0DRL;Write to SCI BRAOUTCH1Till now, we believe that IT WORKS! Only 9 lines ASM code!Then Replace the BRA to RTSInput char Test* INCHBRCLR SCI0SR1,$20,INCH ;Check status LDAB SCI0DRL BSR OUTCH BRA INCHThen Replace the BRA to RTSGet_CharINCH BRCLR SCI0SR1,$20,INCH; Without Echo LDAA SCI0DRL RTS * INCHE BSR INCH ; With Echo BRA OUTCHAssembler Example: OUTCH* Out space(s) Routine: OUT2S BSR OUT1S OUT1S LDAA #$20 ;ASCII Code for Space * OUTCH BRCLR SCI0SR1,#$80,* ; Check if TBF Empty? STAA SCI0DRL ; Out char. RTS * Print string PDATA: PRINT JSR OUTCH PDATA LDAA ,X+ CMPA #EOT BNE PRINT RTSBasic Functions of the Debug Initialize the MCU system Communication with people (Talk to CPU) Download program and run Some debug utilitiesDynamic and Static CPU Registers Image During IRQ or SWI, CPU registers are pushed into stack automatically That is dynamic CPU Register Image. A data structure in RAM, which has the same structure with above, it is called static image Get Static Image : Copy Dynamic to Static Let SP?Dynamic, then run SWI Stack Structure after SWICCRSP - 9Last Valid Data in the stackSPPCLSP - 1PCHSP - 2YLSP - 3YHSP - 4XLSP - 5XHSP - 6ASP - 7BSP - 8Stack free byteAfter IRQ/SWI SP=SP-9Before IRQ SPStack GrowthHigh AddressLow AddressRun Program In uC/OS-II a tasks context switch (CPU registers) is in the stack Move SP to the stack top run RTI Instruction to resume the task If we move the SP and let it points to the static Image and Run TRI, what happens? Display SP Initialed Here MRB RMB 1 ;SP + 1 MRA RMB 1 ;SP + 2 MRX RMB 2 ;SP + 3 MRY RMB 2 ;SP + 5 MRPC RMB 2 ;SP + 7 SPBUF RMB 2 ;SP + 9 See Page 374You can Use C (see: OS_CPU_C.C)void *OSTaskStkInit(void (*task)(void *pd), void *pdata, void *ptos, INT16U opt) INT16U *stk; stk= (INT16U *)ptos; / Load stack pointer *-stk = opt; / opt one byte blank *-stk = (INT16U)(task); / PC for use of opt in task *-stk = (INT16U)(task); / PC *-stk = (INT16U)(0x1122); / Y *-stk = (INT16U)(0x3344); / X (INT8U *)stk)-;/ One byte for A *(INT8U *)stk = (INT8U)(INT16U)pdata)8); / A (INT8U *)stk)-;/ One byte for B *(INT8U *)stk = (INT8U)(pdata); / B (INT8U *)stk)-;/ One byte for CCR *(INT8U *)stk = (INT8U)(0x00); / CCR (INT8U *)stk)-;/ One byte for PPAGE *(INT8U *)stk = *(INT8U *)pdata; / PPAGE return (void *)stk); Run ProgramGOLDS SPBUF ;Current SP LDX MRPC PSHX LDX MRY PSHX LSX MRX PSHX LDA MRB PSHA LDAA MRCC PSHA RTICommand Jump TableJMPTAB FCC E FDB ERSPLSH FCC D FDB MDUMP FCC G FDB GO FCC H FDB HELP FCC L FDB DWNLD FCC M FDB MEMCHG FCC R FDB REGDSP FCC Z FDB CLEARBP TBLEND EQU *Increment command One by OneNXTCMD JSR INCH LDX #JMPTAB NXTCHR CMPB 0,X ; According to the command BNE NEXT ; Jump to the corresponding routine LDX 1,X JSR 0,X BRA NXTCMD NEXTCMD INX INX INX C
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号