Author: Ross M. Fosler and
Rodger Richey
Microchip Technology Inc.
译者: 逐影Linux
硬译目的说明:我是想看看如何写bootloader的。
注意:要想在微控制器中实现BootLoader,首先要求单片机具有IAP功能,或者是可以对其自身的FLASH
进行擦除、 写入的功能。其次要考虑FLASH的大小。
辨识: 1、在一般芯片出厂时,厂商会烧写了一个bootloader到rom中,一次性烧写不可更改。
2、功能较强大的单片机如PIC16和PIC18系列或者stm32单片机,我们用户可更换bootloader ,
通过串口软件来擦除微控制器的flash,可设置为运行程序时只读的,作为boot区,用来代替上述
rom作用,但可编程的,即相当于EPROM(紫外线擦除)或者EEPROM(电子擦除)。
而用户程序应该是下载到SRAM区,即静态RAM区,SRAM可掉电保存,即下载的程序可下次
再次开机运行。还有一个是DRAM,即动态RAM区,用来加载程序的执行(包括指令和数据的
刷新)(指令和数据本质上都是二进制0、1),这个就是通常所说的内存,而DDR RAM是
SDRAM一种类型。
3、flash可做为ROM用,也可作为RAM用,在做RAM用时,执行速度比RAM慢,所以可相当于存
储硬盘的作用。所以其实下载用户程序和bootloader程序时区别在于flash地址不一样,flash
分别NOR flash和NAND flash。下载后, 通过内存加载的方式,加载到SDRAM中的执行。如
果少了SDRAM,那么程序执行起来速度就会 非常慢。
名词全称解释:
USART: (Universal Synchronous/Asynchronous Receiver/Transmitter) 通用同步/异步串行接收/发送器
USART是一个全双工通用同步/异步串行收发模块,该接口是一个高度灵活的串行通信设备。
UART: 通用异步收发传输器(Universal Asynchronous Receiver/Transmitter)。
INTRODUCTION 说明
Among the many features(特性) built into Microchip’s(微芯)Enhanced FLASH Microcontroller devices is
the capability (能力)of the program memory to self-program.
在内置于Microchip增强式FLash 微控制器(应该就叫单片机吧)器件中的众多特性是支持程序存储器
self-program功能。(译者注:self-program(自编程),是指用Flash存储器中的驻留的软件或
程序对Flash存储器进行擦除/编程的方法。通过单片机的自编程功能,可以设计Bootloader程序,
通过串口等通信接口实现对产品重新编程、在线升级的功能。)
This very useful feature has been deliberately included to give the user the ability to perform bootloading
operations.
这个非常有用的特性是特意内置的,给使用者能力去执行bootloading 操作。
Devices like the PIC18F452 are designed with a designated(指定) “boot block”, a small section of
protectable program memory allocated specifically for bootload (引导)firmware.
像PIC18F452 等一些器件专门为 bootload 固件设计了一个指定的“boot block”,一个很小的受保护的程序存储分配区。
This application note demonstrates a very powerful bootloader implementation for the PIC16F87XA
and PIC18F families of microcontrollers.
这个应用笔记演示了 PIC16F87XA 和 PIC18F系列等微控制器一个非常强大的bootloader实现。
The coding for the two device families is slightly different; however, the functionality is essentially
the same. The goals of this implementation stress a maximum performance and functionality,
while requiring a minimum of code space.
两种器件系列的代码略有不同,但是功能本质是一样的。该目标实现的压力在于争取最大的性能和功能, 同时要求最少的代码空间。
FIRMWARE Basic Operation(固件基础操作)
Figure 1 summarizes (总结)the essential firmware design of the bootloader.
图1总结了bootloader的基本固件设计。
Data is received through the USART module, configured in Asynchronous mode for compatibility(兼容性)
with RS-232 and passed through the transmit/receive engine.
数据通过USART(串口)模块接收,配置为异步模式,通过发送/接收引擎下载,比如RS232。
The engine filters and parses the data, storing the information into a data buffer in RAM.
引擎过滤并解析数据, 然后存储信息到在RAM的数据缓冲区中。
The command interpreter evaluates the command information within the buffer to determine what
should be done (i.e., Is the data written into a memory unit? Is data read from a memory unit?
Does the firmware version need to be read?).
命令解释器评估在缓冲区的命令信息来确定应该做什么。(比如:该数据是在存储单元以写进去的,
还是数据从该存储单元读取?固件版本是否需要读取?)
Once the operation is performed, data is passed back to the transmit/receive engine to be transmitted
back to the source, closing the software flow control loop.
一旦操作方式被确定,被传递到发送/接收引擎的数据会被返送到宿主机,并关闭软件流控制回路。
COMMUNICATIONS (通信)The microcontroller’s USART module is used to receive and transmit data; it is configured as a UART to
be compatible with RS-232 communications.
微控制器的USART模块被用于接收和传送数据,它被确定用于UART去兼容与RS-232的通信。
The device can be set up in an application to bootload from a computer through its standard serial interface.
该器件能够通过它的标准串口从电脑引导加载建立起一个应用程序。
The following communications settings are used:
• 8 data bits
• No parity
• 1 STOP bit
下列通信设置将会被用到:
• 8个数据位
• 无校验位
• 1个停止位
The baud rate setting is variable depending on the application. Baud rate selection is discussed later.
波特率设置根据应用程序是可变的。波特率的选择稍后讨论。
THE RECEIVE/TRANSMIT BUFFER( 接收和传送缓冲区)
All data is moved through a buffer (referred to as the Receive/Transmit Buffer).
所有的数据都是通过一个缓冲区移动(称为接收/发送缓冲区)。
The buffer is a maximum of 255 bytes deep.
缓冲区大小的最大值为255字节。
This is the maximum packet length supported by the protocol.
这个最大包长度有被协议支持。
However, some devices may not support the largest packet size due to memory limitations.
但是,一些器件由于内存大小并不支持该最大包长度。
Note: The actual packet length supported by a particular device depends on the size of its data memory.
注: 实际的包长度所支持的 特定器件取决于它的数据存储区的大小。
Figure 2 shows an example of the mapping of the buffer within the PIC18F452.
图2 显示了一个示例关于PIC18F452内的缓冲区映射。
图2
数据内存在PIC18F452的利用
A useful feature of the receive/transmit buffer is that it retains its memory between packets, thus
allowing very fast repeat and replication operations. That is, if an empty packet is sent, the data
currently in memory will be executed as if it were just received.
接收/发送缓冲区的一个很有用的特性就是它的内存保留在包之间,从而允许非常
快速重复和复制操作。也就是说, 如果一个空包被发送, 现有的数据在内存中被收到将会很快被执行。
COMMAND INTERPRETER( 命令解释器)
The command interpreter decodes and executes ten different commands, seven base commands
and three special commands.
命令解释器解码并执行10个不同的命令,7个基础命令和3个特殊命令。
A complete list of the commands is provided in Appendix A.
一个完整的命令列表在附录A中提供。
The base commands allow for read, write, and erase operations on all types of non-volatile memory.
最基础的命令在非易失性内存上允许读、写和擦除操作。
The other three commands are for special operations, such as repeating the last command, replicating
the data, and resetting the device.
其他三个命令为特殊操作,比如重复最后一个命令,拷贝其他数据或者是复位器件。
Note that the PIC18F devices have greater access to, and control of, memory than PIC16F devices. For
example, PIC16F devices do not have access to the configuration memory, thus they do not use the
configuration commands. Therefore, not all instructions are available in the PIC16F bootloader.
注意,PIC18F器件比PIC16F有更大的访问,和控制、存储能力。比如PIC16F器件没有访问并配置内存, 因此
他们不得使用配置命令。
评论
查看更多