Author: Ross M. Fosler and
Rodger Richey
Microchip Technology Inc.
譯者: 逐影Linux
硬譯目的說(shuō)明:我是想看看如何寫bootloader的。
注意:要想在微控制器中實(shí)現(xiàn)BootLoader,首先要求單片機(jī)具有IAP功能,或者是可以對(duì)其自身的FLASH
進(jìn)行擦除、 寫入的功能。其次要考慮FLASH的大小。
辨識(shí): 1、在一般芯片出廠時(shí),廠商會(huì)燒寫了一個(gè)bootloader到rom中,一次性燒寫不可更改。
2、功能較強(qiáng)大的單片機(jī)如PIC16和PIC18系列或者stm32單片機(jī),我們用戶可更換bootloader ,
通過(guò)串口軟件來(lái)擦除微控制器的flash,可設(shè)置為運(yùn)行程序時(shí)只讀的,作為boot區(qū),用來(lái)代替上述
rom作用,但可編程的,即相當(dāng)于EPROM(紫外線擦除)或者EEPROM(電子擦除)。
而用戶程序應(yīng)該是下載到SRAM區(qū),即靜態(tài)RAM區(qū),SRAM可掉電保存,即下載的程序可下次
再次開機(jī)運(yùn)行。還有一個(gè)是DRAM,即動(dòng)態(tài)RAM區(qū),用來(lái)加載程序的執(zhí)行(包括指令和數(shù)據(jù)的
刷新)(指令和數(shù)據(jù)本質(zhì)上都是二進(jìn)制0、1),這個(gè)就是通常所說(shuō)的內(nèi)存,而DDR RAM是
SDRAM一種類型。
3、flash可做為ROM用,也可作為RAM用,在做RAM用時(shí),執(zhí)行速度比RAM慢,所以可相當(dāng)于存
儲(chǔ)硬盤的作用。所以其實(shí)下載用戶程序和bootloader程序時(shí)區(qū)別在于flash地址不一樣,flash
分別NOR flash和NAND flash。下載后, 通過(guò)內(nèi)存加載的方式,加載到SDRAM中的執(zhí)行。如
果少了SDRAM,那么程序執(zhí)行起來(lái)速度就會(huì) 非常慢。
名詞全稱解釋:
USART: (Universal Synchronous/Asynchronous Receiver/Transmitter) 通用同步/異步串行接收/發(fā)送器
USART是一個(gè)全雙工通用同步/異步串行收發(fā)模塊,該接口是一個(gè)高度靈活的串行通信設(shè)備。
UART: 通用異步收發(fā)傳輸器(Universal Asynchronous Receiver/Transmitter)。
INTRODUCTION 說(shuō)明
Among the many features(特性) built into Microchip’s(微芯)Enhanced FLASH Microcontroller devices is
the capability (能力)of the program memory to self-program.
在內(nèi)置于Microchip增強(qiáng)式FLash 微控制器(應(yīng)該就叫單片機(jī)吧)器件中的眾多特性是支持程序存儲(chǔ)器
self-program功能。(譯者注:self-program(自編程),是指用Flash存儲(chǔ)器中的駐留的軟件或
程序?qū)lash存儲(chǔ)器進(jìn)行擦除/編程的方法。通過(guò)單片機(jī)的自編程功能,可以設(shè)計(jì)Bootloader程序,
通過(guò)串口等通信接口實(shí)現(xiàn)對(duì)產(chǎn)品重新編程、在線升級(jí)的功能。)
This very useful feature has been deliberately included to give the user the ability to perform bootloading
operations.
這個(gè)非常有用的特性是特意內(nèi)置的,給使用者能力去執(zhí)行bootloading 操作。
Devices like the PIC18F452 are designed with a designated(指定) “boot block”, a small section of
protectable program memory allocated specifically for bootload (引導(dǎo))firmware.
像PIC18F452 等一些器件專門為 bootload 固件設(shè)計(jì)了一個(gè)指定的“boot block”,一個(gè)很小的受保護(hù)的程序存儲(chǔ)分配區(qū)。
This application note demonstrates a very powerful bootloader implementation for the PIC16F87XA
and PIC18F families of microcontrollers.
這個(gè)應(yīng)用筆記演示了 PIC16F87XA 和 PIC18F系列等微控制器一個(gè)非常強(qiáng)大的bootloader實(shí)現(xiàn)。
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.
兩種器件系列的代碼略有不同,但是功能本質(zhì)是一樣的。該目標(biāo)實(shí)現(xiàn)的壓力在于爭(zhēng)取最大的性能和功能, 同時(shí)要求最少的代碼空間。
FIRMWARE Basic Operation(固件基礎(chǔ)操作)
Figure 1 summarizes (總結(jié))the essential firmware design of the bootloader.
圖1總結(jié)了bootloader的基本固件設(shè)計(jì)。
Data is received through the USART module, configured in Asynchronous mode for compatibility(兼容性)
with RS-232 and passed through the transmit/receive engine.
數(shù)據(jù)通過(guò)USART(串口)模塊接收,配置為異步模式,通過(guò)發(fā)送/接收引擎下載,比如RS232。
The engine filters and parses the data, storing the information into a data buffer in RAM.
引擎過(guò)濾并解析數(shù)據(jù), 然后存儲(chǔ)信息到在RAM的數(shù)據(jù)緩沖區(qū)中。
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?).
命令解釋器評(píng)估在緩沖區(qū)的命令信息來(lái)確定應(yīng)該做什么。(比如:該數(shù)據(jù)是在存儲(chǔ)單元以寫進(jìn)去的,
還是數(shù)據(jù)從該存儲(chǔ)單元讀取?固件版本是否需要讀取?)
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.
一旦操作方式被確定,被傳遞到發(fā)送/接收引擎的數(shù)據(jù)會(huì)被返送到宿主機(jī),并關(guān)閉軟件流控制回路。
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模塊被用于接收和傳送數(shù)據(jù),它被確定用于UART去兼容與RS-232的通信。
The device can be set up in an application to bootload from a computer through its standard serial interface.
該器件能夠通過(guò)它的標(biāo)準(zhǔn)串口從電腦引導(dǎo)加載建立起一個(gè)應(yīng)用程序。
The following communications settings are used:
? 8 data bits
? No parity
? 1 STOP bit
下列通信設(shè)置將會(huì)被用到:
? 8個(gè)數(shù)據(jù)位
? 無(wú)校驗(yàn)位
? 1個(gè)停止位
The baud rate setting is variable depending on the application. Baud rate selection is discussed later.
波特率設(shè)置根據(jù)應(yīng)用程序是可變的。波特率的選擇稍后討論。
THE RECEIVE/TRANSMIT BUFFER( 接收和傳送緩沖區(qū))
All data is moved through a buffer (referred to as the Receive/Transmit Buffer).
所有的數(shù)據(jù)都是通過(guò)一個(gè)緩沖區(qū)移動(dòng)(稱為接收/發(fā)送緩沖區(qū))。
The buffer is a maximum of 255 bytes deep.
緩沖區(qū)大小的最大值為255字節(jié)。
This is the maximum packet length supported by the protocol.
這個(gè)最大包長(zhǎng)度有被協(xié)議支持。
However, some devices may not support the largest packet size due to memory limitations.
但是,一些器件由于內(nèi)存大小并不支持該最大包長(zhǎng)度。
Note: The actual packet length supported by a particular device depends on the size of its data memory.
注: 實(shí)際的包長(zhǎng)度所支持的 特定器件取決于它的數(shù)據(jù)存儲(chǔ)區(qū)的大小。
Figure 2 shows an example of the mapping of the buffer within the PIC18F452.
圖2 顯示了一個(gè)示例關(guān)于PIC18F452內(nèi)的緩沖區(qū)映射。
圖2
數(shù)據(jù)內(nèi)存在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.
接收/發(fā)送緩沖區(qū)的一個(gè)很有用的特性就是它的內(nèi)存保留在包之間,從而允許非常
快速重復(fù)和復(fù)制操作。也就是說(shuō), 如果一個(gè)空包被發(fā)送, 現(xiàn)有的數(shù)據(jù)在內(nèi)存中被收到將會(huì)很快被執(zhí)行。
COMMAND INTERPRETER( 命令解釋器)
The command interpreter decodes and executes ten different commands, seven base commands
and three special commands.
命令解釋器解碼并執(zhí)行10個(gè)不同的命令,7個(gè)基礎(chǔ)命令和3個(gè)特殊命令。
A complete list of the commands is provided in Appendix A.
一個(gè)完整的命令列表在附錄A中提供。
The base commands allow for read, write, and erase operations on all types of non-volatile memory.
最基礎(chǔ)的命令在非易失性內(nèi)存上允許讀、寫和擦除操作。
The other three commands are for special operations, such as repeating the last command, replicating
the data, and resetting the device.
其他三個(gè)命令為特殊操作,比如重復(fù)最后一個(gè)命令,拷貝其他數(shù)據(jù)或者是復(fù)位器件。
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有更大的訪問(wèn),和控制、存儲(chǔ)能力。比如PIC16F器件沒有訪問(wèn)并配置內(nèi)存, 因此
他們不得使用配置命令。
評(píng)論