📄 bootldr.txt
字号:
PIC18Fxxx BOOT LOADER/DOWNLOADER Copyright (C)2002 HI-TECH Software.Freely distributable.Included in this package is an implementation of a boot loader forthe PIC18 flash devices.Introduction############The Microchip PIC18Fxxx processors are able to write to their own program memory while executing from it. By taking advantage of this fact, a bootloader program can be designed to accept new code via the serial port (or other method) and re-program itself.On startup the bootloader code is the first to execute. The bootloader willtransmit a count-down on the serial port. At this time the bootloader isawaiting to recieve a byte on the serial port. Sending a character to the serial port, during the count-down will indicate to the device that the userintends to download a new program into the device. A prompt will be displayed,and the file may now be transferred to the device via the serial connection.If the user does not respond to the processor before the count-down expires,the processor will begin execution of the program previously installed.How it Works############So as to maximize the amount of available program memory, the bootloader has been designed to occupy less than 200H bytes. Another reason for doing this is because the address range 0-1FFH has special write-protection features.The bootloader code executes before any user program. If it is given a program todownload during its execution, it will write the program code to the device's flashmemory. It is assumed that the program code being downloaded is an INTEL hex filewhich avoids the address range 0-200H.The hex file is read by the bootloader program and stores the data in the accordingmemory region. These regions can include; program memory, EEPROM data memory,device configuration registers and user ID locations.Microchip PIC18Fxxx memory map with the bootloader installed Address 0 |--------------------------| | Interrupt redirection | <--- Interrupts redirected to 0020 |--------------------------| user's interrupt routine | Bootloader code | <--- Bootloader program | | 01FF |--------------------------| | | | | | | | | | Program space | | available for | <--- Available space for user programs | downloaded programs | | | | | | | | | | | | | Flash | | TOP |--------------------------| <--- Top of flash memory is device specific ~ ~ 200000 |--------------------------| | ID locations | <--- User's IDLOC data 200008 |--------------------------| ~ ~ 300000 |--------------------------| | Configuration words | <--- Device's configuration settings 3FFFFF |--------------------------| 0 |--------------------------| | | | Data EEPROM | <--- Data EEPROM size is device specific EEPROM | | TOP |--------------------------|Any program locatations of the downloaded program that correspond to locationsin the bootloader, will be ignored. This ensures that program data being received cannot overwrite any bootloader code.Compiling the Bootloader#######################The source code for the bootloader must be compiled prior to download into thetarget device. Note that full optimization must be applied and the 4000boundary errata workaround must be disabled.A typical command line used to compile the bootloader is:picc18 -18f452 bootldr.c --opt=all --errata=default,-4000orpicc18 -18f458 bootldr.c --opt=all -DVERBOSE --debugger=ICD2 --ide=MPLABto put the bootloader in verbose mode and compile for Microchip ICD2.Verbose mode:The bootloader can be put into a mode that is more verbose, if the symbol VERBOSEis defined when compiling the bootloader source code. However Using thebootloader in this mode will consume more program memory.Note: If compiling the bootloader for the 18Fxx2 or 18Fxx8 family of devices, youshould also add the -noerrata option. The bootloader code is not susceptibleto the hardware bugs listed in the errata document for this family of devices,and therefore the compiler should be told not to add any errata specific fixesinto the code. Failure to add the -noerrata option will result in an error.Compiling Programs for Download############################### Except for the fact that there are 200H bytes less space available, nothing special has to be done in the design of downloadable programs. The only thingthat must be done is to make sure the program doesn't use any program space where the bootloader resides. By default, the bootloader occupies the programspace from 0-0x01FF. To avoid these locations use the compiler switch--codeoffset=200.If the program to be downloaded is to begin at an address other than 0x0200,the -A option will be adjusted accordingly. So too, the definition of PROG_STARTwill need to be adjusted in bootldr.h.If the bootloader is compiled for verbose mode, this requires more resourcesso the program memory range (0-2FF) must be avaoided. A program to bedownloaded using the verbose bootloader will need to use a --codeoffset=300 option.Downloading Programs####################Once the bootloader itself has been downloaded into the processor, there is nospecial program required to operate this bootloader. Any basic serialcommunications program (such as HyperTerminal) will be sufficient.By default the data trasfer rate is 9600 Bits per second. This again can bechanged, by modifying the BAUD definition in bootldr.h.Once the connection has been established with the microcontroller (containingbootloader), the connection can be verified by running the bootloader program.A countdown should appear in the communication terminal window.To commence a download, the countdown needs to be interrupted with a keypress,before the it expires. The bootloader will acknoledge this by printinga colon, which indicates it is now ready to recieve the compiled hex file ofthe download application. If using HyperTerminal, choose Transfer > "Send TextFile..." then set "Files of type" to [All files (*.*)] and choose your .hexfile.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -