I write in C language serial bootloader of dsPIC single-chip microcomputer

Source: Internet
Author: User

  Hyperbootloader_dspic

Hyperbootloader_dspic is my C language implementation of serial bootloader, applicable to DsPIC30, dsPIC33, the same applies to PIC24. Single-chip terminal bootloader is compiled with XC16, computer-side communication software is--hyperterminal with HyperTerminal.

  DSPIC30 and DSPIC33 program memory

DSPIC30,DSPIC33, the PIC24 Program memory architecture is the same, only the size, and the vector location is different. Shown are the DSPIC30 and dsPIC33 program memory, and the placement of the Hyperbootloader. Hyperbootloader_dspic is placed outside the page of the ivt/aivt interrupt vector, so IVT/AIVT does not need to make any changes.

  

As shown, for dsPIC30, the ROM range for hyperbootloader_dspic is 0X400~0XBFF, and for dsPIC33, the Hyperbootloader_dspic ROM range is 0x100~0x5ff.

  ROM Range Settings

The following is an example of dspic33fj256gp710a, detailing how to set the Rom Range. When compiling the hyperbootloader_dspic, you need to add the P33fj256gp710a.gld file to the project directory and modify the following places for it.

Program (XR): ORIGIN = 0x400, LENGTH = 0x0800/*2a9fe*/
__code_base = 0x400;
__code_length = 0x0800; /*2aa00;*/

This completes the setup of the Rom range for the hyerbootloader_dspic. In addition, the application needs to be burned to the 0xc00 of the dspic33fj256gp710a ROM. So when compiling the application, you also need to add the P33fj256gp710a.gld file to the project directory and modify the following to complete the ROM setup.

Program (XR): ORIGIN = 0xc00, LENGTH = 0x02a000/*2a9fe*/
__code_base = 0xc00;
__code_length = 0x02a000; /*2aa00;*/

  Main code Snippet

Hyperbootloader_dspic uses the program word burning, the specific implementation code snippet is as follows.

         for(;;) {             while(U1rxreg! =':');  while(!u1stabits.trmt); U1txreg=':'; Cksum= Bcount = ByteCount =Getxbyte (); //Addresssourceaddr.v[1] =Getxbyte (); sourceaddr.v[0] =Getxbyte (); Sourceaddr.val>>=1; RecType=Getxbyte (); Switch(rectype) { Caselinear_address:sourceaddr.v[3] =Getxbyte (); sourceaddr.v[2] =Getxbyte ();                Checksum ();  Break;  CaseDATA: while(bytecount--) {Buffer[incrbyte++] =Getxbyte ();                } Checksum (); if(Sourceaddr.val >=Cm_start) {                    //Nvmcon = cm_word_write;Clearbuffdata ();  Break; }                Else{Nvmcon=Pm_word_write; }                 for(ix =0; IX <Bcount;) {PData.byte. LB = buffer[ix+0]; PData.byte. HB = buffer[ix+1]; PData.byte. UB = buffer[ix+2]; PData.byte. MB = buffer[ix+3]; Tblpag=SourceAddr.word.HW; if(Sourceaddr.val = =0) {PData.word.LW= Boot_start;//Reset VectorPData.word.HW =0x0004;//Goto Boot_start} __builtin_tblwtl (SourceAddr.word.LW, PData.word.LW);                    __builtin_tblwth (SourceAddr.word.LW, PData.word.HW); ASM ("DISI #16");//Disable interrupts for few Instru__BUILTIN_WRITE_NVM ();                    Nop ();  while(NVMCONBITS.WR); RData.word.HW=__builtin_tblrdh (SourceAddr.word.LW); RData.word.LW=__builtin_tblrdl (SourceAddr.word.LW); if((Rdata.val! = pdata.val))//&& (Sourceaddr.val < Cm_start)){putsUART1 (unsignedint*)"error\r\n"); Rconbits.swdten=1;//Use WTD to reset device                         while(1); } IX+=4; Sourceaddr.val+=2;                } clearbuffdata (); Nvmconbits.wren=0;  Break;  Caseend:checksum (); U1mode=0x0; U1sta=0x0110; (*((void(*) (void)) (Prog_start))) ;  Break; }        }    

How to use

  1. use XC16 to compile the Hyperbootloader_dspic or Hyperbootloader_dspic ( before compiling, you need to modify the GLD file, see "ROM Range Settings").

  2. use Pickit3 to burn the hyperbootloader_dspic hex file to the target board.

  3. Unplug the pickit3 burner, connect the target board with the PC's serial port, open HyperTerminal, set as follows:115200-8-none-1-none, line Delay-20ms .

  4. Restart the target board, the HyperTerminal will appear booting ... Words.

  5. within 6 seconds, pressing any key on the keyboard in the HyperTerminal window will cause ">" (no keystrokes within 6 seconds and will automatically jump to the user's application).

  6. Open the Send Text file dialog box and select the application hex file that you want to burn (before compiling, you need to modify the GLD file, see "ROM Range Settings"), click OK, Hyperbootloader will transmit the received data back to the computer HyperTerminal and burn the data to the correct location on the target Board program memory.

  7. Restart the target board again, HyperTerminal displays the booting ..., automatically jumps into the application, the target board starts to run the application normally.

Each time you update the application, just repeat steps 4 ~ 7.

  Key Features

Hyperbootloader_dspic has the following key features

  1. written in C language, XC16 compiled.

  2. very easy to transplant, support dsPIC30, dsPIC33, PIC24.

  3. Support Flash Burn Write

  4. EEPROM Burn-write is not supported.

  5. support config Bits/idloc burn write.

  If you have any questions, or are interested in learning more about bootloader C language implementation, please add me QQ: 1273623966 ( please fill in the verification information Bootloader or Cnblogs).

Want to know PIC18 bootloader please read my essay, "I write PIC18 SCM serial bootloader" in C language.

Want to know PIC16 bootloader please read my essay, "I write PIC16 SCM serial bootloader" in C language.

  

I write in C language serial bootloader of dsPIC single-chip microcomputer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.