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器件沒有訪問并配置內存, 因此
他們不得使用配置命令。
評論
查看更多