A method for remotely upgrade C8051F041 program based on CAN bus network

. The CAN bus is a serial communication network using the CAN protocol. The microcontroller of C8051F041 is a highly integrated mixed-signal system-on-a-chip with an integrated CAN bus controller. The article describes in detail how to implement remote update of all MCU Flash under the same CAN bus network. The result shows that all MCU Flash in the same bus network can be remotely updated. Only CAN bus is needed for update and no additional Connected. Program maintenance and maintenance costs can be effectively reduced in industrial control networks.


Introduction
CAN bus is a low-cost, high-utilization industrial control bus, which has a wide range of applications in industrial control and automotive electronics.
The C8051F041 uses a high-speed, pipelined 8051-compatible CIP-51 core. The internal PLL can be multiplied to 25MIPS. It has two universal asynchronous receiver/transmitter (UART), integrated CAN bus controller, 64KB of system-programmable flash memory, 4352 (4K +256) byte of on-chip RAM and include on-chip JTAG debug circuitry. The function fully meets the conditions for implementing the system remote online program upgrade. STM32F103ZET6 (STM32) is single-chip microcomputer which is based on ARM Cortex-M3. The maximum working frequency is 72 MHz. It also integrates two UART and two CAN bus controllers. It can complete the online update of C8051F041 internal Flash program through the host computer through this module.
The realization of remote online program upgrade in a dedicated network system has obvious advantages, which not only greatly facilitates system maintenance, but also saves a lot of manpower and financial resources. This paper introduces in detail the design ideas and methods for implementing the remote online program upgrade of C8051F041 through CAN bus realized in a monitoring system.

Design idea
The network topology of the system based on CAN bus is shown in Figure 1. Under normal working conditions, the management center monitors all the subordinate stations through the CAN bus. When the management center needs to upgrade the firmware version, it is updated one by one according to the corresponding ID of the subordinate station.

Remote update system frameworks
The remote update system consists of the host computer software, STM32 burning board, and multiple C8051F041 sub-nodes, as shown in Figure 2. The host computer software will send the updated code to the STM32 burning board through UART, and the STM32 burning board will decode the C8051F sub-node through the CAN bus. The 64KB flash memory of the C8051F041 is divided into three areas, 0x0000-0x6fff as the normal program memory area, 0x8000-0xffff as the memory area to be updated from the CAN bus, and 0x7000-0x7fff as the storage area of the loader. There are no other special requirements for writing a running program except that the size can't exceed 28k byte.
The normal running program receives the program update command from the host computer (implemented by the user-defined communication protocol), erases the updated memory area, and starts receiving data, then writes data into updated memory area. Until the reception is completed in the area, the main program judges whether the received data is complete and valid. If it is completed and valid, it jumps to the loader program, and the loader completes the work of updating the program.

Design and implementation of loader program
The loader consists of erasing flash, writing flash, reading flash, copying flash, and system reset for the C8051F041. When the updated program is written to the updated memory area, the program update state is entered, the stored program in the normal memory area is erased, and then the data in the updated memory area is sequentially copied to the normal memory area, and then the C8051F041 is restarted by software reset. The storage location of the loader program can be easily implemented in load memory area when using software program development of Keil.

Load memory area
Normal memory area Updated memory area 0x0000 0x6fff 0x7fff 0xfe00 Reserved 0xf000 Fig. 3. Flash address space allocation.

Program software diagram
This needs to add a C8051F loader program module to the compiled project, including all flash handles. In the link option, it needs to specify this loader program to point to the load memory area.
The STM32 software project needs to add an loader program module that contains various instruction operations for the C8051F, including instructions for erasing C8051F, reading and writing C8051F data instructions, and code copying instructions.
During the program update process, the code update instruction is firstly sent to the STM32 through the UART. After receiving the instruction, the STM32 sends a flash erase command to the C0851F. At this time, the loader program module erases the updated memory area of flash and returns the erase completed flag.
Then, through the UART, the updated code is sent to the STM32. After receiving the updated code, the STM32 sends the code to the C8051F through the CAN bus in turn, and the loader program stores the received code once in the updated memory area.
After the updated code is sent, the STM32 sends a code copying instruction through the CAN bus. After receiving the instruction, the C8051F erases the normal memory area,

CSCNS2019
MATEC Web of Conferences 309, 02009 (2020) . . https://doi org/10 1051/matecconf/202030 902009 copies the code of updated memory area to the normal memory area, and then resets the C8051F to complete the update.
When the C8051F040 is used for the first time, it needs to be programmed through the JTAG debug port, and the program in the loader memory area cannot be modified. In the process of flash handles, the interrupt needs to be turned off.
Write to area 0x8000-0xefff

Summary
The methods of implementing software update technology through CAN bus is completely usable and has strong anti-interference ability. It has been successfully applied to the program update of each module in the radar network system based on CAN bus.