Implementation of BootLoader for C8051F410 MCU

Publisher:朱雀Latest update time:2014-08-13 Source: 21icKeywords:C8051F410 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

BootLoader is a small boot program that is executed first after the microcontroller is reset. This program can be used to initialize the hardware and update the "user program". This article mainly discusses the dynamic update of the "user program" through BootLoader.

In the process of using single-chip microcomputers for product development and use, the problem of updating programs is inevitable. Normal program download is achieved by connecting the single-chip microcomputer emulator to the special I/O port of the single-chip microcomputer. In the development stage of the product, program download and debugging can be achieved through the emulator. After the product development is completed, since the single-chip microcomputer has been encapsulated inside the product, if you want to update it, you need to reopen the product shell and connect the data cable. This is almost impossible when the product has been mass-produced or even in the hands of the end user. On the one hand, this is because it is very inefficient and costly, and on the other hand, it also brings a great negative impact on the overall performance of the product to users.

1 Flash operation and program storage area structure and function division

1.1 Flash basic operations and storage structure

C8051F410 only supports 0 operation for Flash, so the sector should be erased before writing data (erasing can only be done on the entire page, and each bit is 1 after the operation is completed). Software writing and erasing FLASH is protected by the FLASH lock and key code function. Before performing FLASH operations, the key code must be written to the FLASH lock and key code register (FLKEY) in sequence: 0xA5, 0xF1. The timing of writing the key code is not important, but it must be written in sequence.

To implement BootLoader, we must first understand the Flash structure of the program storage, as shown in Table 1. C8051F410 has a total of 32k Flash program memory, which is divided into 512 sectors (pages) and can be programmed in the system (IAP). This provides the necessary and sufficient prerequisites for implementing the BootLoader function.

Implementation of BootLoader for C8051F410 MCU

1.2 Functional division of storage area

The BootLoader program and the "user program" are stored in different areas of the Flash, which are divided as follows in this article: The BootLader program occupies addresses 0x6000 to 0x7FFF, of which page 0x7C00 is used to save the entry address of the user program, so that the size of the real BootLoader program cannot exceed 7k (0x6000 to 0x7A00). The "user program" occupies addresses 0x0000 to 0x5FFF, so there are no other special requirements for the writing of the "user program" except that the size cannot exceed 24k.

Implementation of BootLoader for C8051F410 MCU

1.3 Locating the Storage Location of BootLoader

It is very easy to locate the program when developing it using Keil software. Here is the easiest way to do it. Just enter the address range of the program in the BL51 Locate panel of the BootLoader project's settings window, as shown in the figure below.

Implementation of BootLoader for C8051F410 MCU

2 BootLoader program workflow description

2.1 Key process description

Power-on reset: After reset, the microcontroller first executes the jump instruction at address 0x0000 to jump to the entry address of the BootLoader program and performs operations such as turning off the watchdog, setting the crystal frequency, and setting the UART serial port baud rate. In order to make the program update faster, the system clock frequency in this application sets a larger communication baud rate of 115200bps.

Upgrade handshake: According to the pre-defined handshake rules, some data is exchanged with the host computer (usually a computer) through URAT. After receiving the correct reply, the handshake is considered successful, and an indication of readiness to receive data is sent through the serial port. If it is unsuccessful, the user program jump operation is performed.

User program judgment: If it exists, jump to the user program entry address immediately (this is also the most common normal startup process).

Jump to the user program entry: The BootLoader task is completed, and the control of the MCU is handed over to the user program until the next reset to re-enter the BootLoader.

Receiving data: No interrupt function is used in BootLoader, which reduces the remapping operation of the interrupt vector and increases the stability of the program. The query method is used here to realize data reception.

Instruction type analysis: The data frame sent by the host computer has multiple functions. The protocol is specified by the developer of the BootLoader. The main instruction types include: writing data, reading data and uploading, and ending the data transmission process.

Send "xxxx" prompt: Send some operation result information to the host computer through UART, such as "operation successful", "operation failed", etc., to inform the host computer how to proceed to the next step.

2.2 BootLoader Flowchart

Implementation of BootLoader for C8051F410 MCU

3. Program processing of key operations

Data reception: Do not use interrupt functions in the BootLoader program, as this will cause the same interrupt processing function of the "user program" to become invalid. Therefore, the query method is used here to implement UART serial port data reception.

Saving the BootLoader program entry address: After the microcontroller is reset, it always starts execution from the 0x0000 address of the Flash storage area. Here, 3 bytes are used to save a jump instruction. The content of address 0x0000 is 0x02, which is the jump instruction of the machine code. The following two bytes save the address value to jump to. In order to ensure that it can jump to the BootLoader area correctly, it is necessary to save the jump address value before erasing this page, and rewrite these 3 bytes after the erasure is completed. The implementation code is as follows:

BootAddr[0]=FlASH_ByteRead(0x0001);

BootAddr[1]=FLASH_ByteRead(0x0002);

FLASH_PageErase(0X0000); // Erase page 0

FLASH_ByteWrite(0x0000,0x02);//jump instruction 0x02

FLASH_ByteWfite (0x0001, BootAddr [0]); //Write the start address of the bootloader

FLASH_ByteWrite(0x0002, BootAddr[1]);

Saving of the "user program" entry address: The "user program" entry address is marked in the program file and saved in the first 3 address bytes of the program. It is displayed in the generated program Hex file as:

:03000000021ECC11

:0C1ECC00787FE4F6D8FD7581700216A046

The content in the first line indicates that the content in the address 0x0000 and the next two bytes is 0x02ECCC, which means it will jump to the Flash address 0x1ECC to execute the first instruction of the "user program". Here we need to save this address so that the BootLoader program can jump here to run the "user program" after execution. That is, save the 3 bytes originally pointing to the address 0x0000~0x0002 in the "user program" file to a page specified by the BootLoader and save it separately. In this application, it is saved to the first 3 bytes of the 0x7A00 page. The implementation code is as follows:

#define APP_ADDR_PAGE 0x7C00L ∥Entry address of user program...

startAddr=RecData[2]*256+RecData[3];

if((startAddr+i==0)‖(startAddr+i==1)‖(startAddr+i==2))

FLASH_ByteWrite(APP_ADDR_PAGE+i, RecData[5+i]);

startAddr is the address where the data specified in the data frame sent by the host computer should be saved

Protection of BootLoader program area: When updating the "user program", it is necessary to prevent the data sent by the host computer from containing the address segment that is repeated with the address of the BootLoader program storage area. If the BootLoader area is overwritten, the boot program will not be executed correctly after the next reset. The protection of the boot area is achieved through the following program segments:

if(startAddr>=0x6000)//Conflict with BootLoader

SendString("Code overflow! ");

Absolute address jump: When the upgrade is completed or the host computer does not respond to the upgrade handshake after reset, the program jumps to the entry address of the "user program", which is saved at 0x7C00 in Flash.

4. Host computer software development

In order to cooperate with the function realization of BootLoader in the single-chip microcomputer, it is necessary to write a corresponding download program on the computer side to complete the firmware upgrade together. According to the communication protocol of BootLoader, the host computer service program is developed using Delphi. The program is mainly aimed at serial port operations, completing the handshake protocol, user program file reading and packaging in a fixed format, downloading and progress monitoring, etc. The running interface of the program is shown in Figure 4.

Implementation of BootLoader for C8051F410 MCU

5 Conclusion

BootLoader is a basic function that a complete product should have, and it provides a good solution for product program upgrades based on microcontrollers.

The practical application and reliability of the method described in this paper have been well verified through the actual product use of the C8051F410 microcontroller core. At the same time, this method is also applicable to other microcontrollers with similar structures.

When the program has important confidentiality requirements, you can consider encrypting the original Hex file and decrypting it according to the encryption rules during the download process to make the program upgrade more secure and universal.

In order to make the program function more complete, the old version of the "user program" in the microcontroller should be downloaded and saved before updating the program, and then updated. When the newly upgraded program cannot be used, it can be restored to the old version.

Keywords:C8051F410 Reference address:Implementation of BootLoader for C8051F410 MCU

Previous article:Design of safety warning system based on infrared radiation technology
Next article:Anti-interference design of pedometer based on MMA8452Q sensor

Recommended ReadingLatest update time:2024-11-16 23:58

KEIL-51 MCU implements custom bootloader for program update
Original author of this article: Shao Zhanyu Dashen About the implementation of 8051 bootloader 1. Basic hardware requirements To realize the IAP function, the 51 microcontroller needs to be able to modify the Flash of the code space in the program, or at least be able to modify the Flash of the user program area. M
[Microcontroller]
KEIL-51 MCU implements custom bootloader for program update
Simulating I2C communication of PIC microcontroller
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ;                      Copyright (C) 1997 by Innovatus ; This code may be distributed and used freely provided that this ; copyright notice stays intact and that any modifications are noted. ; For more information about Innovatus: http://www.in
[Microcontroller]
What is the difference between MCU and ARM
1. Software 1) Convenience. This is mainly reflected in the later development, that is, developing applications directly on the operating system. Unlike a single-chip microcomputer , everything needs to be rewritten. The early operating system transplantation work still needs to be done by professionals. 2) Security.
[Microcontroller]
What is the difference between MCU and ARM
A detailed explanation of the hardware design principles of single-chip microcomputers
  The following is a summary of some issues that should be paid attention to in the design, and the hardware design principles of the switching power supply module microcontroller. I hope everyone can read it.   (1) In terms of component layout, related switching power supply module components should be placed as cl
[Microcontroller]
Three methods of single chip microcomputer button
Three ways to share microcontroller buttons method one: #include reg52.h typedef unsigned int uInt16;sbit LED1 = P2^0; sbit KEY1 = P3^4; sbit KEY2 = P3^5; void DelayMS(uInt16 ValMS) {         uInt16 uiVal,ujVal;         for(uiVal = 0; uiVal ValMS; uiVal++)                 for(ujVal = 0; ujVal 113; ujVal++); }//Fun
[Microcontroller]
51 MCU IO port simulation serial communication 5
/******************************************************************* *A serial port is simulated on the microcontroller, using P2.1 as the transmitter *Send the data stored in the microcontroller through P2.1 as the serial port TXD *This program comes from "MCU IO port simulation serial port program (send + receive)"
[Microcontroller]
GigaDevice Launches GD32A490 Series Automotive-Grade MCUs
GigaDevice (stock code 603986), an industry-leading semiconductor device supplier, announced today the official launch of the new GD32A490 series of high-performance automotive-grade MCUs. With its advantages such as high main frequency, large capacity, high integration and high reliability, it closely meets th
[Automotive Electronics]
Design of wireless transceiver system based on nRF905 module and 51 single chip microcomputer
Preface In a closed-loop drilling system, it is required to transmit the underground information to the ground in real time for manual monitoring. Usually, this task is completed by the mud pressure pulse generator in the MWD. ​​When using a downhole power drill assembly, the near-bit sensor and the MWD are se
[Microcontroller]
Design of wireless transceiver system based on nRF905 module and 51 single chip microcomputer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号