CPU implicit initialization method

Through the implicit CPU initialization method, the initialization function address is output to an independent segment using the ARMGCC compiler, which realizes implicit initialization of the GD32 system, solves the problem of high coupling between APP and underlying programs, and improves system flexibility and maintenance sex.

CN119225831APending Publication Date: 2024-12-31TIANJIN JINHANG COMP TECH RES INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411470757.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-21
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

During the GD32 startup process, the APP program and the underlying program are seriously coupled, resulting in the modification or deletion of the underlying peripheral module, which requires corresponding modification of the application, resulting in complex and inflexible initialization operations.

Method used

Using the implicit CPU initialization method, using typedef to define function pointers, output the initialization function address to an independent segment through the ARMGCC compiler instruction, and run the initialization function through the segment start and end addresses to realize the implicit call and sequential execution of the function. .

Benefits of technology

It realizes the system initialization without modifying the main function, reduces the coupling between the APP and the underlying program, and improves the flexibility and maintenance of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119225831A_ABST
    Figure CN119225831A_ABST
Patent Text Reader

Abstract

The invention discloses a CPU implicit initialization method. The method comprises the following steps: defining an initialization function; outputting an address of an initialization function to an independent section, and arranging the address according to a set sequence; mapping the initialization function pointers into the corresponding segments; the mapping information is checked; defining a function inistartFunc for searching a starting position of the segment; a function iniendfunc is defined and used for judging the end position of the segment; the method comprises the following steps of: mapping an address of a function inistartFunc into a segment'inifn.0 ', mapping an address of the iniendFunc into the segment'inifn.0', and mapping an address of the iniendFunc into a segment'inifn.z '; and performing address self-increasing operation, traversing to take out pointer data in a section area, copying the pointer data to the Funcptrnum, and running the function in a function addressing mode. According to the method, an initialization function address is output to an independent segment through an ARMGCC compiler instruction, a starting address and an ending address are marked through an null function address, a function between the starting address and the ending address of the operation segment is traversed in a main function, and operation work of the initialization function is completed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of computer control and relates to a CPU implicit initialization method. Background Art

[0002] ARM CPU software initialization First, the system clock needs to be configured. The clock system in the ARM CPU is the core of the entire system and provides clock signals for other peripherals and functions. Next, configure the clocks of each peripheral as needed. The normal operation of the peripherals depends on the clock signal. GPIO (general purpose input and output) is one of the most commonly used peripherals in the ARM CPU and is used to connect and control external devices. Therefore, it is necessary to correctly configure the pin mode, output type and other parameters of the GPIO. Interrupts are an important mechanism for STM32 to handle external events. By configuring interrupt priorities and interrupt service routines, you can ensure that the system can respond quickly to external events. In addition to GPIO and interrupts, other peripherals may also need to be configured to meet specific application requirements. After completing all necessary configurations, start running the user's application logic. Summary of the invention

[0003] 1. Technical issues to be resolved

[0004] During the startup of GD32, the onboard peripherals need to be initialized in the main function. Usually, the initialization functions of different peripherals are called sequentially. These peripheral initialization functions are called in the APP file, and the initialization functions belong to the underlying functions. In this way, the APP program and the underlying program are severely coupled together. If the underlying peripheral interface function is modified or a peripheral module is deleted, the application program needs to be modified accordingly.

[0005] (II) Technical solution

[0006] In order to solve the above technical problems, the present invention provides a CPU implicit initialization method, comprising the following steps:

[0007] S1: Use the typedef keyword to define the function pointer init_func to define the initialization function. The parameters and return values ​​of the function pointer are both void types.

[0008] The defined initialization functions include: network initialization function ini_wlan_fun, ARINC 1553B bus initialization function, command line SHELL initialization function ini_shell_func.

[0009] S2: Use the ARMGCC compiler directive __attribute__((section("name"))) to output the address of a function into a separate section and arrange them in the set order.

[0010] Replace x in the compiler with the segment name priority in the form of macro definition, such as replacing x with "ini_fn" rank, where rank is the level number 1, 2, 3 and so on. For example, the x parameter is represented by "ini_fn" "1", "ini_fn" "2", "ini_fn" "3" to represent the level. The smaller the value, the compiler will put the corresponding function in the front position of the segment table.

[0011] S3: The ARMGCC compiler instruction __attribute__((used)) instruction maps the initialization function pointer to the corresponding segment.

[0012] Set the network initialization function ini_wlan_fun to level 1 priority and map it to segment .ini_fn.1". Set the ARINC 1553B bus initialization function ini_1553b_func to level 2 priority and map it to segment .ini_fn.2". Set the command line SHELL initialization function ini_shell_func to level 3 priority and map it to segment .ini_fn.3".

[0013] S4: After the compilation is complete, check in .map and find the mapping information in the Image Symbol Table area.

[0014] The mapping information includes:

[0015] (1) The symbol name of the network initialization function is ini_wlan_fun, the symbol address value is 0x200002c8, the symbol type is Data, the storage size is 4, and the network initialization function is mapped in the segment .ini_fn.1.

[0016] (2) The symbol name is the ARINC 1553B bus initialization function ini_1553b_func, the symbol address value is 0x200002cc, the symbol type is Data, the storage size is 4, and the ARINC 1553B bus initialization function is mapped in the segment .ini_fn.2.

[0017] (3) The symbol name is command line SHELL initialization function ini_shell_func, the symbol address value is 0x200002d0, the symbol type is Data, the storage size size is 4, and the command line SHELL initialization function is mapped in segment .ini_fn.3.

[0018] S5: Use the init_func function pointer defined in step S1 to define a function ini_start_func, which does not perform any operation and is used to find the start position of the segment; and define a function ini_end_func, which is used to determine the end position of the segment and does not perform any operation.

[0019] S6: Use the ARMGCC compiler __attribute__((section("name"))) directive and __attribute__((used)) directive to map the address of the function ini_start_func to the segment "ini_fn.0", the address of ini_end_func to the segment "ini_fn.0", and the address of ini_end_func to the segment "ini_fn.z".

[0020] S7: Define the function pointer variable funcptrnum in step S1, assign the initial value to the address of the function ini_start_func, perform the address self-increment operation, traverse and take out the pointer data in the section area and copy it to funcptrnum, and run this function through the function addressing mode.

[0021] (III) Beneficial effects

[0022] The CPU implicit initialization method provided by the above technical solution outputs the initialization function address to an independent segment through the ARMGCC compiler instruction, and marks the start address and end address through the empty function address, traverses the functions between the start address and the end address of the running segment in the main function, and completes the running of the initialization function. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 This is a flow chart of the CPU implicit initialization method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0024] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.

[0025] Reference Figure 1 As shown, the CPU implicit initialization method of this embodiment includes the following steps:

[0026] S1: Use the typedef keyword to define the function pointer init_func to define the initialization function. The parameters and return values ​​of the function pointer are both void types.

[0027] The defined initialization functions include: network initialization function ini_wlan_fun, ARINC 1553B bus initialization function, command line SHELL initialization function ini_shell_func.

[0028] S2: Use the ARMGCC compiler directive __attribute__((section("name"))) to output the address of a function into a separate section and arrange them in the set order.

[0029] Replace x in the compiler with the segment name priority in the form of macro definition, such as replacing x with "ini_fn" rank, where rank is the level number 1, 2, 3 and so on. For example, the x parameter is represented by "ini_fn" "1", "ini_fn" "2", "ini_fn" "3" to represent the level. The smaller the value, the compiler will put the corresponding function in the front position of the segment table.

[0030] S3: The ARMGCC compiler instruction __attribute__((used)) directive maps the initialization function pointer to the corresponding segment.

[0031] Set the network initialization function ini_wlan_fun to level 1 priority and map it to segment .ini_fn.1". Set the ARINC 1553B bus initialization function ini_1553b_func to level 2 priority and map it to segment .ini_fn.2". Set the command line SHELL initialization function ini_shell_func to level 3 priority and map it to segment .ini_fn.3".

[0032] S4: After the compilation is complete, check in .map and find the mapping information in the Image Symbol Table area.

[0033] The mapping information includes:

[0034] (1) The symbol name of the network initialization function is ini_wlan_fun, the symbol address value is 0x200002c8, the symbol type is Data, the storage size is 4, and the network initialization function is mapped in the segment .ini_fn.1.

[0035] (2) The symbol name is the ARINC 1553B bus initialization function ini_1553b_func, the symbol address value is 0x200002cc, the symbol type is Data, the storage size is 4, and the ARINC 1553B bus initialization function is mapped in the segment .ini_fn.2.

[0036] (3) The symbol name is command line SHELL initialization function ini_shell_func, the symbol address value is 0x200002d0, the symbol type is Data, the storage size size is 4, and the command line SHELL initialization function is mapped in segment .ini_fn.3.

[0037] S5: Use the init_func function pointer defined in step S1 to define a function ini_start_func, which does not perform any operation and is used to find the start position of the segment; and define a function ini_end_func, which is used to determine the end position of the segment and does not perform any operation.

[0038] S6: Use the ARMGCC compiler __attribute__((section("name"))) directive and __attribute__((used)) directive to map the address of the function ini_start_func to the segment "ini_fn.0", the address of ini_end_func to the segment "ini_fn.0", and the address of ini_end_func to the segment "ini_fn.z".

[0039] S7: Define the function pointer variable funcptrnum in step S1, assign the initial value to the address of the function ini_start_func, perform the address self-increment operation, traverse and take out the pointer data in the section area and copy it to funcptrnum, and run this function through the function addressing mode.

[0040] section adds all the initialization functions to the defined input segment in advance, and then takes out the initialization functions in this input segment one by one in the main function, so that the system initialization can be completed without modifying the main function.

[0041] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A CPU implicit initialization method, characterized in that: The following steps are involved: S1: Use the typedef keyword to define the function pointer init_func to define the initialization function; S2: Use the ARMGCC compiler directive __attribute__((section("name"))) to output the address of an initialization function to a separate section and arrange them in the set order; S3: The ARMGCC compiler instruction __attribute__((used)) directive maps the initialization function pointer to the corresponding segment; S4: After the compilation is completed, check in .map and find the mapping information in the Image Symbol Table area; S5: using the init_func function pointer defined in step S1, define a function ini_start_func to find the start position of the segment; and define a function ini_end_func to determine the end position of the segment; S6: Use the ARMGCC compiler __attribute__((section("name"))) and __attribute__((used)) instructions to map the address of the function ini_start_func to the segment "ini_fn.0", the address of ini_end_func to the segment "ini_fn.0", and the address of ini_end_func to the segment "ini_fn.z". S7: Define the function pointer variable funcptrnum in step S1, assign the initial value to the address of the function ini_start_func, perform the address self-increment operation, traverse and take out the pointer data in the section area and copy it to funcptrnum, and run this function through the function addressing mode.

2. The CPU implicit initialization method according to claim 1, characterized in that: In step S1, the parameters and return values ​​of the function pointer are both of void type.

3. The CPU implicit initialization method according to claim 2, characterized in that: In step S1, the defined initialization functions include: a network initialization function ini_wlan_fun, an ARINC 1553B bus initialization function, and a command line SHELL initialization function ini_shell_func.

4. The CPU implicit initialization method according to claim 3, characterized in that: In step S2, the x in the compiler is replaced with the segment name priority in the form of macro definition, and x is replaced with the "ini_fn" rank form, where rank is the level number 1, 2, 3 and so on. The x parameter is represented by "ini_fn" "1", "ini_fn" "2", "ini_fn" "3". The smaller the value, the closer the corresponding function is to the front of the segment table.

5. The CPU implicit initialization method according to claim 4, characterized in that: In step S3, the network initialization function ini_wlan_fun is set to level 1 priority and mapped to segment .ini_fn.1", the ARINC 1553B bus initialization function ini_1553b_func is set to level 2 priority and mapped to segment .ini_fn.2", and the command line SHELL initialization function ini_shell_func is set to level 3 priority and mapped to segment .ini_fn.3".

6. The CPU implicit initialization method according to claim 5, characterized in that: In step S3, the mapping information includes: a symbolic name network initialization function ini_wlan_fun, a symbolic name ARINC 1553B bus initialization function ini_1553b_func, and a symbolic name command line SHELL initialization function ini_shell_func.

7. The CPU implicit initialization method according to claim 6, characterized in that: In step S3, in the symbolic name network initialization function ini_wlan_fun, the symbolic address value is 0x200002c8, the symbolic type is Data, the storage size size is 4, and the network initialization function is mapped in the segment .ini_fn.

1.

8. The CPU implicit initialization method according to claim 7, characterized in that: In step S3, in the symbol name ARINC1553B bus initialization function ini_1553b_func, the symbol address value is 0x200002cc, the symbol type is Data, the storage size size is 4, and the ARINC 1553B bus initialization function is mapped in segment .ini_fn.

2.

9. The CPU implicit initialization method according to claim 8, characterized in that: In step S3, in the symbolic name command line SHELL initialization function ini_shell_func, the symbolic address value is 0x200002d0, the symbolic type is Data, the storage size size is 4, and the command line SHELL initialization function is mapped in the segment .ini_fn.

3.

10. The CPU implicit initialization method according to claim 9, characterized in that: In step S7, section adds all initialization functions to the defined input section in advance, and then takes out the initialization functions in the input section in turn in the main function, completing the initialization of the system without modifying the main function.