×
单片机 > 单片机程序设计 > 详情

A FLASH Bootloader for PIC16 and PIC18 Devices--硬译(五)

发布时间:2024-05-02 发布时间:
|

Author: Ross M. Fosler and
Rodger Richey
Microchip Technology Inc.

译者: 逐影Linux


WRITING CODE
The bootloader operates as a separate entity, which means that an application can be developed with very
little concern about what the bootloader is doing. This is as it should be; the bootloader should be
dormant code until an event initiates a boot operation. Under ideal circumstances, bootloader code should
never be running during an application’s intended normal operation.
Bootloader运行作为一个单独的实体, 这意味着应用程序可以被开发,而不必太关心bootloader做了
什么。它应该是这样,bootloader休眠的代码直到事件发起一个启动操作。(译者注:休眠时,启动操
作会从Bootloader开始运行)。在理想的情况下,bootloader代码在应用程序的预期正常运行时不会
被运行。
When developing an application with a resident bootloader, some basic principles must be kept in mind(牢记):
当开发常驻在bootloader的一个应用程序,一些基本原则必须牢记:

Writing in Assembly 汇编代码编写
When writing in assembly, the boot block and new vectors must be considered. For modular code, this is
generally just a matter of changing the linker script file for the project. An example is given in Appendix
D.If an absolute address is assigned to a code section, the address must point somewhere above the boot
block. For those who write absolute assembly, all that is necessary is to remember that for PIC18F devices,
the new RESET vector is at 200h, and the interrupt vectors are at 208h and 218h. For PIC16F87XA devices, the
RESET vector is at 100h and the interrupt vector is at 104h. No code, except the bootloader, should reside
in the boot block.
用汇编编写时,引导块和新向量必须被考虑。对模块化的代码,这是一般只需改变项目的链接器脚本文件。
附录D中给出了一个例子。如果一个绝对地址被分配给一个代码部分,地址必须指向引导块。对于那些写
汇编代码的,所需做的只是记住,对PIC18F器件,新的复位向量在200H,中断向量在208H和218H。除了
引导装载程序,没有代码,应该驻留在引导块。

Writing in C C代码编写
When using the MPLAB® C18 C compiler to develop PIC18F firmware for an application, the standard start-up
object (c018.o or c018i.o) must be rebuilt with the new RESET vector. Like modular assembly, the linker file
must be changed to incorporate the protected boot block and new vectors. Appendix D shows an example linker
file. For users of other compilers, for either PIC16F87XA or PIC18F devices, check with the compiler’s
software user guide to determine how to change the start-up code and vectors.
当使用MPLAB® C18 C编译器开发PIC18F固件对于一个应用程序,必须用新的复位向量必须重建标准的启
动对象(c018。o或c018i.o)。像模块化组装,链接器文件必须改变并合并保护引导块和新向量。附录D显
示了一个示例连接器文件。用户的其他编译器,PIC16F87XA或PIC18F器件,需要用编译器的软件用户
指南检查来决定如何改变启动代码和向量。
Bootloader Re-Entry
If the need exists to re-enter Boot mode from the application (and it usually does), the last location of
the data memory must be set to FFh. The code in Example 1 demonstrates how this might be done in an application
on a PIC18F device. Since the bootloader assumes RESET conditions, a RESET instruction should be initiated
after setting the last location.


如果需要重新进入启动模式的存在是为了从应用程序(和它通常都会),最后一个位置的数据内存必须设置为
FFH。示例1中的代码演示了在PIC18F器件的一个应用程序如何可以做到这一点。bootloader假定复位的
情况下,一个复位指令应该在最后的位置设置后启动。

Debugging 调试
For most situations, it is not necessary to have the bootloader firmware in memory to do debugging of an
application with either the MPLAB ICD 2 or ICE devices. However, branch statements must be inserted at the
hardware vectors to get to the new designated vectors. It may also be useful to have the start-up timing
match exactly to the bootloader entry. When development of the application is finished, either remove the
branches and rebuild the project, or export only the memory above the boot block. This code can then be
distributed to those who are updating their firmware.
对于大多数情况下,用MPLAB ICD 2或者ICE器件没有必要有bootloader固件在内存中去调试一个应用程序,。
然而,分支语句必须插入到固件向量来获取新指定的向量。它也可能是启动时间精确匹配bootloader
入口有用。当开发应用程序完成后,要么删除分支和重建工程,或者只是输出引导块上的内存。


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
8051单片机的函数发生器的设计