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