This paper designs a novel Bootloader based on Microchip's MPLAB software development environment , and compiles a PC-side host computer interface program. Its features are flexible control, convenient use, and safe and reliable system upgrades.
1 Bootloader Implementation
1.1 Bootloader Operation Mode
The bootloader runs after the microcontroller is powered on/reset and before the user program is run. After running, it determines whether it needs to enter the upgrade state. If it does not need to be upgraded, it will directly run the original program; if it needs to be upgraded, it will first erase the old program, then receive the user program from the serial port and write it to the Flash. The bootloader has two operating modes:
① Boot loading mode, also known as "kernel boot" mode. That is, the Bootloader loads the operating system from a solid-state storage device on the target machine into RAM for execution, and the entire process does not involve user intervention.
② Download mode. In this mode, the Bootloader on the target machine will download the operating system file from the host computer through the serial port, network connection or USB, and then save it to the Flash solid-state storage device on the target machine. This mode of Bootloader is usually used when the kernel and root file system are installed for the first time. In addition, future system updates will also use this working mode of Bootl-oader.
The Bootloader designed in this paper supports both working modes. It is in normal boot loading mode at the beginning, but does not immediately boot into the kernel. Instead, it prompts a delay of 3 seconds. If the host computer user sends some information to the target machine, it switches to download mode, otherwise it continues to boot the kernel.
1.2 Intel HEX File
Intel HEX files are ASCII text files consisting of lines of text that conform to the Intel HEX file format. In an Intel HEX file, each line contains a HEX record. These records consist of hexadecimal coded numbers corresponding to machine language codes and/or constant data. Each record contains 5 fields: the data length field, which represents the number of data bytes in the record; the address field, which represents the starting address of the data in the record; the field representing the HEX record type; the data field, which represents a byte of data. A record can have many data bytes. The number of data bytes in the record must match the number specified in the data length field; the checksum field, which represents the checksum of the record. The checksum is calculated by adding the values corresponding to all the hexadecimal coded numbers in the record and dividing them modulo 256. The two's complement of the remainder is the checksum.
1.3 Bootloader Design
The compiler used in the Bootloader program designed in this paper is the mcc18 compiler of the MPLAB software development environment, and the upgrade file format is Intel HEX format. According to the format of the Intel HEX file, each line of the file content is encapsulated into a frame, and a frame header and a frame footer are added to ensure the reliability of data transmission, and a half-duplex communication mode is used to retransmit the error frame.
The main program code is as follows:
[page]
The main program flow is shown in Figure 1. The program flow for downloading the system image file and writing it into the program memory is shown in Figure 2.
1.4 Design of PC operation interface
The PC operation interface is mainly used to realize the following functions:
①Serial port parameter settings: Set the serial port channel number, data bit number, baud rate and other parameters.
② User login. Enter the user name and password to verify with the lower computer.
③Select the system image file. Select the system image HEX file, read it line by line and send it to the lower computer through the serial port. If there is an error, reselect it.
④Prompt the user that the system update is complete (or failed). Display the system update progress and prompt the user the system update result.
2 Several key technologies and considerations in design
① If all the data in the HEX file is sent to the target chip through the serial port at one time, if a byte is transmitted incorrectly during the communication process, all the data will need to be resent; and the relationship between the chip's Flash write processing speed and the serial port rate must also be considered, otherwise the received data will be lost. In order to enhance the reliability of communication and the variability of the serial port rate, the Bootloader designed in this article uses a half-duplex communication mode to communicate with the host computer: one line of the HEX file is used as a frame of data, and reply data is sent to the host computer after each frame of data verification is completed. The host computer determines the correctness of the sent data frame based on the reply data and chooses to resend or continue to send the next frame; and before upgrading, communicate with the host computer to verify the username and password to ensure that the current upgrade operation is not an erroneous operation.
②When writing to the program memory of the PIC18 series, each time an 8-byte block is written, the unit of program Flash writing can only be changed from 1 to 0. However, the content of the HEX file is not generated as needed. The data length of each frame can be different, and the content of the address field of adjacent frames can also be different. For this reason, when writing to the program memory, the data field content needs to be merged into data blocks in units of 8 bytes according to the content of the address field, and those less than 8 bytes need to be filled with 0xFF. The Bootloader program designed in this article uses a circular Buffer structure to implement this operation:
③The default interrupt vector of the chip starts at 0x08 and 0x18, which cannot be changed. To change the interrupt vector entry address, you need to add jump instructions at these two address locations to jump to the interrupt vector entry address of the user program. Some address areas of the program memory of the PIC18 series are write-protected. To prevent the Bootloader program outside this area from being erased or rewritten, it is necessary to judge the content of the address field of the received data. If it is less than the starting address of the user program, it is necessary to reply to the host computer with "write address error" and discard the current data frame.
Conclusion
Experiments have shown that the Bootloader designed in this paper is stable and easy to control, and can be flexibly changed according to user needs. For example, adding a system reset mechanism to the user program can realize online upgrades, and adding a network download module to the PC operation interface can realize remote control system upgrades, which is extremely important for the release and software upgrade of embedded products.
Previous article:Design of non-magnetic water meter based on MSP430FW427
Next article:Application of Freescale MCU in battery management system
Recommended ReadingLatest update time:2024-11-16 19:35
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Smart Kitchen] Unboxing - STM32F750
- Is it feasible to automatically turn off the backlight under the key switch?
- 4~20mA current loop acquisition circuit
- Several common communication protocols for microcontrollers
- 使用SVN保持 封装库 同步的方法【轉載】
- Resenas E1 downloads HEX to the R5F51115 chip
- BearPi-Hongmeng-BearPi-HM Nano 3 + Results from LED lighting experiment
- FAQ|Molex and TTI Live: Smaller, faster, more reliable connectors drive new developments in IoT applications
- MSP430F5529 and common matrix keyboard
- BlueNRG-LP HID KEYBOARD example PC side can not be used normally