CN113885910A - Software upgrading method based on domestic singlechip GD32 - Google Patents

Software upgrading method based on domestic singlechip GD32 Download PDF

Info

Publication number
CN113885910A
CN113885910A CN202111126036.0A CN202111126036A CN113885910A CN 113885910 A CN113885910 A CN 113885910A CN 202111126036 A CN202111126036 A CN 202111126036A CN 113885910 A CN113885910 A CN 113885910A
Authority
CN
China
Prior art keywords
data
value
bus
function
flash
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111126036.0A
Other languages
Chinese (zh)
Inventor
王雨龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tianjin Jinhang Computing Technology Research Institute
Original Assignee
Tianjin Jinhang Computing Technology Research Institute
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tianjin Jinhang Computing Technology Research Institute filed Critical Tianjin Jinhang Computing Technology Research Institute
Priority to CN202111126036.0A priority Critical patent/CN113885910A/en
Publication of CN113885910A publication Critical patent/CN113885910A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • G06F8/654Updates using techniques specially adapted for alterable solid state memories, e.g. for EEPROM or flash memories

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses a software upgrading method based on a domestic singlechip GD32, which uses an IAP upgrading method based on a CAN bus to connect all equipment to be upgraded on the bus, and uses a YMODEM protocol to carry out simple and rapid batch upgrading. The invention hangs all the devices to be upgraded on the CAN bus, and sends the upgrade files to all the devices to be upgraded by the YMODEM protocol.

Description

Software upgrading method based on domestic singlechip GD32
Technical Field
The invention belongs to the technical field of computer control, and relates to a software upgrading method based on a domestic singlechip GD 32.
Background
Software in the field of industrial control generally needs to be upgraded again after being deployed for the first time, after the software is used for a period of time, due to the occurrence of a BUG, the demand of a user increases, the performance of a module needs to be upgraded, and the like, the software in a chip needs to be written again, and software upgrading methods comprise an ISP (programming in a system) method and an IAP (programming in an application) method.
The ISP upgrading method generally carries out software upgrading through an emulator, is used less at present, and has the defects of high time cost and economic cost due to the fact that equipment needs to be disassembled and the emulator needs to be connected.
The current mainstream method is an IAP upgrade method, traditionally, serial ports are usually used for upgrading, and when a system enters BootLoader, an upgrade file is written into FLASH through the serial ports and jumps are performed.
The common singlechip software upgrading comprises upgrading by using an emulator and upgrading by using an IAP (integrated access point), the domestic singlechip GD32 can also upgrade by using the emulator or upgrade by using the IAP, a special burning emulator needs to be connected each time for the method (burning by using JTag or SWD) for upgrading by using the emulator, an independent upgrading interface circuit needs to be designed for product design, and only one device can be upgraded each time.
Disclosure of Invention
Objects of the invention
The purpose of the invention is: the software upgrading method based on the domestic singlechip GD32 is characterized in that the equipment to be upgraded is connected to a bus by using an IAP (integrated access protocol) upgrading method based on a CAN (controller area network) bus, and simple and rapid batch upgrading is carried out by using a YMODEM (multiple-mode active multimedia subsystem) protocol.
(II) technical scheme
In order to solve the technical problem, the invention provides a software upgrading method based on domestic singlechip GD32, which comprises the following steps:
(1) designing a CAN bus communication application layer protocol, designing a CAN message structure CAN _ RECV _ DATA in a CAN DATA processing process, and configuring a 29-bit extended frame of a CAN bus.
(2) Initializing the single chip microcomputer system, configuring clock information and interrupt information, configuring bus communication rate information, mask value and filter value of bus ID, and defining used variables and ping-pong buffer.
(3) In the CAN bus interrupt callback function CAN0_ RX0_ IRQHandler, the received CAN bus data are sequentially stored in a ping-pong buffer.
(4) According to the step 1, a CAN bus communication protocol is defined to analyze CAN bus data, an ID value of an acquired data frame is assigned to a receiving frame identification variable RecvID, the length of the acquired data is assigned to a receiving frame length variable RecvDLC, and at most 8 acquired data values are assigned to a receiving data pointer RecvData.
(5) Analyzing the received CAN bus data in the main function, extracting the analyzed data, and writing the updated firmware information into Flash by using a write Flash function Writeflash (); reading an application program starting address APP _ ADDR _ FLASH and judging whether the highest bit of data stored in the address is 1, wherein 1 represents that the firmware is successfully written into FLASH.
(6) Obtaining the value stored by the offset of APP _ ADDR _ FLASH address by 4 byte addresses and converting the value into a function pointer type, and using an initialization stack pointer function: a set _ MSP () function with parameters of APP _ ADDR _ FLASH to initialize the stack pointer of the user; and (5) operating an entity pointed by the pFaction function pointer to perform program jump, completing jump from the starting program to the application program, and completing program upgrading.
(III) advantageous effects
The software upgrading method based on the domestic single chip microcomputer GD32 provided by the technical scheme is characterized in that all the devices to be upgraded are hung on the CAN bus, and the upgrading files are sent to the devices to be upgraded through the YMODEM protocol.
Drawings
Fig. 1 is a flowchart of a software upgrading method based on a domestic single chip microcomputer GD32 in an embodiment of the present invention.
Detailed Description
In order to make the objects, contents and advantages of the present invention clearer, the following detailed description of the embodiments of the present invention will be made in conjunction with the accompanying drawings and examples.
Referring to fig. 1, the software upgrading method based on the domestic single chip microcomputer GD32 in the embodiment includes the following steps:
s1: a CAN bus communication application layer protocol is defined, and the protocol comprises a two-byte frame header, two-byte frame length, a one-byte destination address, a one-byte source address, a one-byte upgrade file total frame number, a one-byte current frame number, 1K-byte YMODEM protocol upgrade file content and two-byte CRC (Cyclic redundancy check). The two bytes of the header are 0x55 and 0xAA respectively.
Designing a CAN message structure CAN _ RECV _ DATA in the DATA processing process, wherein the structure comprises (i) an extended frame ID value ExtID and the type is unsigned long shaping; data length DLC, type is short shaping without symbol; ③ the Data group has a length of 8 and a type of unsigned character.
And configuring the 29-bit extended frame ID of the CAN bus, wherein 8 bits from 14 th bit to 21 th bit are used as a CAN bus source node domain, and 8 bits from 22 th bit to 29 th bit are used as a CAN bus node domain. And defining the ID value of a source node of the CAN bus as SRCID and the ID value of a destination node as DSTID, and respectively assigning the SRCID value and the DSTID value to a destination node domain and a source node domain of the CAN bus.
S2: the basic function initialization operation is carried out on the GD32 board card by using an initialization function SystemInit () provided by an official library, the configuration process comprises the steps of carrying out initialization operation on a system clock by using a system clock configuration function SetSysClock () function, enabling an off-chip high-speed clock HSE, configuring clock frequency division factors (including an AHB high-speed bus frequency division factor APB1 low-speed bus frequency division factor APB2 low-speed bus frequency division factor), opening a phase-locked loop (PLL) clock and configuring an interrupt vector NVIC. And carrying out initialization setting on the CAN bus, wherein the baud rate is set to be 1M, and the frame type is set to be an extension frame. The CAN bus interrupt is enabled. Setting a Mask value (CAN _ Mask) of the CAN device to 0x1FE00000 (high 8-bit values are all set to 1), setting a Filter value (CAN _ Filter) of the CAN device to SRCID, and setting a frame type to a data frame.
A ping-pong Buffer Rx _ CAN _ Buffer is defined, the Buffer is a two-dimensional array, the type is an unsigned character type, the number of rows of the array is the number of ping-pong buffers (set to 2), the number of columns is the length Buffer _ Size of the Buffer (length is designed to 2096), and Rx _ CAN _ Ptr is defined, the position for writing the data in the Buffer is defined, and the initial value is set to 0. The current frame length Cur _ Len is defined, the initial value is set to 0, the reception completion Flag Recv _ Flag is set, and the initial value is set to 0.
S3: in the CAN bus interrupt callback function CAN0_ RX0_ IRQHandler, a variable recvdi is defined, the type is unsigned integer, a variable recvdc is defined, the type is unsigned character type, a variable RecvData is defined, the type is unsigned character array type, and the length is 8. The data received on the CAN bus is obtained by using the CAN _ message _ receive () function in the GD32 standard library, and the parameters are CAN0 (representing the first way CAN) and CAN _ FIFO0 (the first way FIFO buffer). And assigning the ID value of the acquired data frame to RecvID, assigning the acquired data length to RecvDLC, and assigning at most 8 acquired data values to RecvData.
A CAN message structure body (CAN _ RECV _ DATA) variable CANData is defined, an extended frame ID value in the CANData is assigned to RecvID, a DATA length DLC is assigned to RecvDLC, and the length needing to be assigned in the DATA array is determined according to the DATA length DLC and is assigned.
And sequentially storing the data received by each interruption into Rx _ CAN _ Buffer [ i ], wherein the initial value of i is 0, the value of the data i received each time is sequentially increased, and the value of Rx _ CAN _ Ptr of the number of the data stored in the Buffer area is automatically increased by the data length DLC. And updates the value of Rx _ CAN _ Ptr.
S4: defining the current data length Cur _ Len, setting the type to be unsigned short shaping, defining a receiving completion Flag Recv _ Flag, circularly judging the value of Rx _ CAN _ Ptr in a main function, taking out a third byte and a fourth byte when the length is more than or equal to 8 bytes, wherein the third byte and the fourth byte are short shaping data, and assigning the value to the Cur _ Len. It is determined whether the value of Rx _ CAN _ Ptr at this time is equal to or greater than the value of Cur _ Len. If the conditions are met, taking out the current data, performing CRC (cyclic redundancy check) on the bytes from the first byte to Cur _ Len-2, and if the CRC is successful, analyzing the YMODEM main body data; if not, then the frame data is discarded.
S5: and analyzing the received data in the main function, extracting the data, and setting a receiving completion Flag Recv _ Flag to be 1 after the receiving is completed. And reading the firmware information in the Flash by using a Flash reading function ReadFlash () in a standard library, and performing printing prompt. The updated firmware information is written into Flash using the write Flash function WriteFlash (). Reading an application program starting address APP _ ADDR _ FLASH (the setting value of the example is 0x8002000), judging whether the highest bit of data stored in the address is 1, and if the highest bit of the data is 1, indicating that the firmware is successfully written into the FLASH.
S6: defining a function pointer pFanction, wherein the parameter and the return value type of the function pointed by the pointer are both null type (void), restoring the default value of the external device, waiting for 3s, acquiring the value stored by the offset of 4 byte addresses of the APP _ ADDR _ FLASH address, converting the value into the pFanction type, and initializing the stack pointer of the user by using an initialization stack pointer function __ set _ MSP () function and the parameter is APP _ ADDR _ FLASH. And (5) operating an entity pointed by the pFaction function pointer to perform program jump, completing jump from the starting program to the application program, and completing program upgrading.
The above description is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, several modifications and variations can be made without departing from the technical principle of the present invention, and these modifications and variations should also be regarded as the protection scope of the present invention.

Claims (10)

1. A software upgrading method based on a domestic singlechip GD32 is characterized by comprising the following steps:
s1: designing a CAN bus communication application layer protocol, designing a CAN message structure CAN _ RECV _ DATA in a DATA processing process, and configuring a 29-bit extended frame ID of a CAN bus;
s2: initializing the single chip microcomputer system, configuring clock information and interrupt information, configuring bus communication rate information, a mask value and a filter value of a bus ID, and defining used variables and a ping-pong buffer area;
s3: in a CAN bus interrupt callback function CAN0_ RX0_ IRQHandler, sequentially storing received CAN bus data into a ping-pong buffer area;
s4: according to the step 1, a CAN bus communication protocol is defined to analyze CAN bus data, an ID value of an acquired data frame is assigned to a receiving frame identification variable RecvID, the length of the acquired data is assigned to a receiving frame length variable RecvDLC, and at most 8 acquired data values are assigned to a receiving data pointer RecvData;
s5: analyzing the received CAN bus data in the main function, extracting the analyzed data, and writing the updated firmware information into Flash by using a write Flash function Writeflash (); reading an application program starting address APP _ ADDR _ FLASH and judging whether the highest bit of data stored in the address is 1, wherein if the highest bit of the data is 1, the upgrading of the identifier successfully written into FLASH by the firmware is indicated;
s6: acquiring a value stored by an APP _ ADDR _ FLASH address offset 4 byte addresses, converting the value into a function pointer type, and initializing a stack pointer function set _ MSP () function with parameters of an APP _ ADDR _ FLASH to initialize a stack pointer of a user; and (5) operating an entity pointed by the pFaction function pointer to perform program jump, completing jump from the starting program to the application program, and completing program upgrading.
2. The software upgrading method based on the domestic single chip microcomputer GD32 as claimed in claim 1, wherein in step S1, the CAN bus communication application layer protocol includes two bytes of frame header, two bytes of frame length, one byte of destination address, one byte of source address, one byte of total frame number of upgrading file, one byte of current frame number, 1K byte of YMODEM protocol upgrading file content, two bytes of CRC check; the two bytes of the header are 0x55 and 0xAA respectively.
3. The software upgrading method based on the domestic single-chip microcomputer GD32 of claim 2, wherein in step S1, the CAN message structure CAN _ RECV _ DATA includes (i) an extended frame ID value ExtID, the type is unsigned long shaping; data length DLC, type is short shaping without symbol; ③ the Data group has a length of 8 and a type of unsigned character.
4. The domestic single-chip microcomputer GD 32-based software upgrading method as claimed in claim 3, wherein in step S1, 8 bits from 14 th to 21 th in 29-bit extended frame ID of CAN bus are used as CAN bus source node domain, and 8 bits from 22 th to 29 th are used as CAN bus destination node domain; and defining the ID value of a source node of the CAN bus as SRCID and the ID value of a destination node as DSTID, and respectively assigning the SRCID value and the DSTID value to a destination node domain and a source node domain of the CAN bus.
5. The method for upgrading software based on the domestic single-chip microcomputer GD32 as claimed in claim 4, wherein in step S2, the GD32 board card is initialized with the initialization function SystemInit (), and the configuration process includes initializing the system clock with the system clock configuration function SetSysClock (), enabling the off-chip high-speed clock HSE, configuring the clock frequency division factor, opening the PLL clock, and configuring the interrupt vector NVIC; carrying out initialization setting on the CAN bus, wherein the Baud rate is set to be 1M, and the frame type is set to be an extended frame; enabling CAN bus interruption, setting a Mask value CAN _ Mask of CAN equipment to be 0x1FE00000, setting a Filter value CAN _ Filter of the CAN equipment to be SRCID, and setting a frame type to be a data frame; the clock frequency division factors comprise an AHB high-speed bus frequency division factor, an APB1 low-speed bus frequency division factor and an APB2 low-speed bus frequency division factor.
6. The domestic-single-chip-microcomputer GD 32-based software upgrading method as claimed in claim 5, wherein in step S2, the ping-pong Buffer Rx _ CAN _ Buffer is a two-dimensional array with type of unsigned character, the number of rows of the array is the number of ping-pong buffers, the number of columns is the length Buffer _ Size of the Buffer, and Rx _ CAN _ Ptr is defined to write the location of the Buffer data with initial value set to 0; the current frame length Cur _ Len is defined, the initial value is set to 0, the reception completion Flag Recv _ Flag is set, and the initial value is set to 0.
7. The software upgrading method based on the domestic single-chip microcomputer GD32, as claimed in claim 6, wherein in the CAN bus interrupt callback function CAN0_ RX0_ IRQHandler in step S3, a variable RecvID is defined, the type is unsigned integer, a variable RecvDLC is defined, the type is unsigned character type, a variable RecvData is defined, the type is unsigned character array type, and the length is 8; acquiring data received on the CAN bus by using a CAN _ message _ receive () function in a GD32 standard library, wherein parameters are CAN0 and CAN _ FIFO 0; assigning the ID value of the acquired data frame to RecvID, assigning the acquired data length to RecvDLC, and assigning at most 8 acquired data values to RecvData;
defining a CAN message structure CAN _ RECV _ DATA variable CANData, assigning the ID value of an extended frame in the CANData to RecvID, assigning the DATA length DLC to RecvDLC, determining the length needing to be assigned in the DATA array according to the DATA length DLC, and assigning;
and sequentially storing the data received by each interruption into Rx _ CAN _ Buffer [ i ], wherein the initial value of i is 0, the value of the data i received each time is sequentially increased, the value of Rx _ CAN _ Ptr of the number of the data stored in the Buffer area is automatically increased by the data length DLC, and the value of Rx _ CAN _ Ptr is updated.
8. The method for upgrading software based on the domestic single-chip microcomputer GD32 as claimed in claim 7, wherein in step S4, the current data length Cur _ Len is defined, the type is set to unsigned short shaping, the receiving completion Flag Recv _ Flag is defined, the value of Rx _ CAN _ Ptr is circularly judged in the master function, when the length is greater than or equal to 8 bytes, the third byte and the fourth byte are taken out, the third byte and the fourth byte are short shaping data, and the value is assigned to Cur _ Len; judging whether the value of Rx _ CAN _ Ptr is larger than or equal to the value of Cur _ Len or not, if so, taking out the current data, performing CRC (cyclic redundancy check) on bytes from the first byte to Cur _ Len-2, and if so, analyzing the YMODEM main body data; if not, then the frame data is discarded.
9. The software upgrading method based on the domestic single chip microcomputer GD32 as claimed in claim 8, wherein in step S5, the received data is parsed in the master function, the data is extracted, and after the reception is completed, the reception completion Flag Recv _ Flag is set to 1; reading out the firmware information in Flash by using a Flash reading function ReadFlash () in a standard library, and carrying out printing prompt; writing the updated firmware information into Flash by using a write Flash function Writeflash (); reading an application program starting address APP _ ADDR _ FLASH, and judging whether the highest bit of data stored in the address is 1, wherein 1 indicates that the firmware is successfully written into FLASH.
10. The software upgrading method based on the domestic single-chip microcomputer GD32 as claimed in claim 9, wherein in step S6, a function pointer pFunction is defined, the type of the parameter and the return value of the function pointed by the pointer are both null, the default value recovery is performed on the peripheral, after waiting 3S, the value stored by shifting the address of APP _ ADDR _ FLASH by 4 byte addresses is obtained and converted into the pFunction type, the initialization stack pointer function __ set _ MSP () function is used, and the parameter is the stack pointer of APP _ ADDR _ FLASH initialization user; and (5) operating an entity pointed by the pFaction function pointer to perform program jump, completing jump from the starting program to the application program, and completing program upgrading.
CN202111126036.0A 2021-09-24 2021-09-24 Software upgrading method based on domestic singlechip GD32 Pending CN113885910A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111126036.0A CN113885910A (en) 2021-09-24 2021-09-24 Software upgrading method based on domestic singlechip GD32

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111126036.0A CN113885910A (en) 2021-09-24 2021-09-24 Software upgrading method based on domestic singlechip GD32

Publications (1)

Publication Number Publication Date
CN113885910A true CN113885910A (en) 2022-01-04

Family

ID=79006596

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111126036.0A Pending CN113885910A (en) 2021-09-24 2021-09-24 Software upgrading method based on domestic singlechip GD32

Country Status (1)

Country Link
CN (1) CN113885910A (en)

Similar Documents

Publication Publication Date Title
CN109842629B (en) Method for realizing self-defined protocol based on protocol analysis framework
US6526446B1 (en) Hardware only transmission control protocol segmentation for a high performance network interface card
US20080288708A1 (en) Multiple virtual usb devices with virtual hub implemented using one usb device controller
CN115102780B (en) Data transmission method, related device, system and computer readable storage medium
CN112463662B (en) Method and terminal for user mode control of I2C equipment
CN111935081B (en) Data packet desensitization method and device
US9934120B2 (en) Method and apparatus for updating a system on chip (SOC) image from a host computer system without using DMA
CN114817114B (en) MIPI interface, control method, device and medium thereof
CN110445585A (en) Based on PPP information frame framing and frame decoding hardware accelerator
US6567859B1 (en) Device for translating medium access control dependent descriptors for a high performance network
CN114995878A (en) Method for automatically generating network data forwarding plane driver code
CN114327975A (en) System on chip
CN116909639B (en) Mounting system, method, cluster and storage medium
CN113885910A (en) Software upgrading method based on domestic singlechip GD32
CN114915499B (en) Data transmission method, related device, system and computer readable storage medium
CN109144853B (en) Software defined radio SoC chip debugging system
CN112667538B (en) Method, system, equipment and medium for obtaining network card identification number
CN109814816A (en) Increase the system and method for print log in CAN bus
CN112187935B (en) Information identification method and read-only memory
CN108304358A (en) Based on the land data analysis method of inertial navigation product SDCard storage devices
US7457881B2 (en) Method and apparatus for sending data from one protocol layer to another
CN115604070A (en) Message transmission method, device, equipment and medium based on MCTP (Multi-function peripheral protocol)
CN114510259A (en) Method and device for importing and exporting BIOS configuration based on BMC
CN114466087A (en) Data transmission method, device, equipment and storage medium
CN114362880A (en) Reconfigurable telemetering mining and editing universal protocol design method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination