Configuration updating method and device on single-chip microcomputer, equipment and medium

By assigning a unique identifier key to the microcontroller configuration definition file and generating a mapping table, the problem of old versions being unable to use new versions during microcontroller configuration updates is solved, enabling a secure configuration update process and avoiding system anomalies.

CN122064359APending Publication Date: 2026-05-19HANGZHOU MAITANG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HANGZHOU MAITANG TECH CO LTD
Filing Date
2026-02-27
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

During the microcontroller configuration update process, the increased length of the structure type makes it impossible for the old version configuration to directly use the new version configuration, and the existing method may cause program loading errors.

Method used

By obtaining the configuration definition file, a preset data parsing engine is used to assign unique identifier keys to the fields in the schema file, generating a target mapping table. The JSON file is then packaged into a configuration update file and written to the microcontroller's Flash partition. The configuration is then updated by matching the identifier keys with the historical mapping table.

Benefits of technology

It enables selective compatibility updates between old and new versions of configuration, avoiding system anomalies caused by code updates and reducing complexity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122064359A_ABST
    Figure CN122064359A_ABST
Patent Text Reader

Abstract

The invention discloses a configuration updating method and device on a single-chip microcomputer, equipment and a medium, and relates to the technical field of single-chip microcomputers, and the method comprises the steps: obtaining a configuration definition file corresponding to a target single-chip microcomputer; distributing a unique identification key for each field in the Schema file, calculating a target position of each field in the memory according to the configuration definition file, and generating a target mapping table according to each identification key and the corresponding target position; packaging a json file into a configuration updating file based on the target mapping table, and writing the configuration updating file into a Flash partition of the single-chip microcomputer; and reading the configuration updating file from the Flash partition by using the target single-chip microcomputer to obtain each identification key in the configuration updating file, and matching each identification key with a local historical mapping table of the single-chip microcomputer to complete configuration updating. The identification key in the file is matched with the historical mapping table, so that the complexity is reduced, and meanwhile, the exception caused by code updating is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of microcontroller technology, and in particular to a configuration update method, apparatus, device, and medium for a microcontroller. Background Technology

[0002] Because struct types allow adding elements to types with the same name, the actual type length increases. If a configuration type is defined as a struct type, its length may increase in subsequent iterations. In this case, a struct cache generated in later versions cannot be directly used by earlier versions.

[0003] Currently, the method for configuring a microcontroller is to change the configuration and code together. This method may cause problems when the program reloads the configuration the next time. Summary of the Invention

[0004] In view of this, the purpose of this invention is to provide a configuration update method, apparatus, device, and medium for a microcontroller, which can match the identifier key in a file with a history mapping table, thereby reducing complexity and avoiding anomalies caused by updating the code. The specific solution is as follows:

[0005] Firstly, this application provides a configuration update method for a microcontroller, including:

[0006] Obtain the configuration definition file corresponding to the target microcontroller; wherein, the configuration definition file includes a schema file and a corresponding JSON file, the schema file includes the structure definition of the target configuration items, and the JSON file includes the specific values ​​of the target configuration items;

[0007] A preset data parsing engine is used to assign a unique identifier key to each field in the schema file. The target location of each field in memory is calculated according to the configuration definition file. A target mapping table is generated based on each identifier key and the corresponding target location. The target mapping table includes the correspondence between each identifier key and the corresponding target location.

[0008] Based on the target mapping table, the JSON file is packaged into a configuration update file, and the configuration update file is written to the Flash partition of the target microcontroller;

[0009] The target microcontroller reads the configuration update file from the Flash partition to obtain each of the identification keys in the configuration update file, and matches each of the identification keys with the local historical mapping table of the target microcontroller. If any identification key exists in the historical mapping table, the data value corresponding to any identification key in the configuration update file is written to the corresponding target location in memory to complete the configuration update operation of the target microcontroller.

[0010] Optionally, before assigning unique identifier keys to each field in the Schema file using a preset data parsing engine, the method further includes:

[0011] Based on the structure definition in the Schema file, determine whether the Schema file matches the JSON file. If the Schema file matches the JSON file, proceed to the step of assigning a unique identifier key to each field in the Schema file using a preset data parsing engine.

[0012] Optionally, calculating the target location in memory for each field according to the configuration definition file includes:

[0013] The field length and field type corresponding to each field, as well as the arrangement order of each field in the configuration definition file, are determined according to the configuration definition file.

[0014] Calculate the target positions in memory for each field based on its length, type, and arrangement order.

[0015] Optionally, before packaging the JSON file into a configuration update file based on the target mapping table, the method further includes:

[0016] Based on the configuration definition file and the target mapping table, configuration access interface code is generated, and the configuration access interface code is integrated into the program code of the target microcontroller so that the target microcontroller can read the configuration update file according to the interface code.

[0017] Optionally, packaging the JSON file into a configuration update file based on the target mapping table includes:

[0018] Based on the target mapping table, the identifier key, field length, and bytes corresponding to each field in the JSON file are concatenated sequentially to generate the configuration update file.

[0019] Optionally, before writing the configuration update file to the Flash partition of the target microcontroller, the method further includes:

[0020] Write the configuration update file into the memory of the target microcontroller, and determine whether there is missing data in the configuration update file in the memory of the target microcontroller. If there is no missing data in the configuration update file, proceed to the step of writing the configuration update file into the Flash partition of the target microcontroller.

[0021] Optionally, the configuration update method on the microcontroller further includes:

[0022] If any identifier key does not exist in the historical mapping table, the original value of the field corresponding to the identifier key in memory is retained, and the next identifier key is matched with the historical mapping table.

[0023] Secondly, this application provides a configuration update device on a microcontroller, comprising:

[0024] The file acquisition module is used to acquire the configuration definition file corresponding to the target microcontroller; wherein, the configuration definition file includes a schema file and a corresponding JSON file, the schema file includes the structure definition of the target configuration items, and the JSON file includes the specific values ​​of the target configuration items;

[0025] The mapping table generation module is used to assign a unique identifier key to each field in the Schema file using a preset data parsing engine, calculate the target location in memory corresponding to each field according to the configuration definition file, and generate a target mapping table according to each identifier key and the corresponding target location; wherein, the target mapping table includes the correspondence between each identifier key and the corresponding target location;

[0026] The file packaging module is used to package the JSON file into a configuration update file based on the target mapping table, and write the configuration update file into the Flash partition of the target microcontroller;

[0027] The configuration update module is used to read the configuration update file from the Flash partition using the target microcontroller to obtain each of the identification keys in the configuration update file, and match each of the identification keys with the local historical mapping table of the target microcontroller. If any identification key exists in the historical mapping table, the data value corresponding to the identification key in the configuration update file is written to the corresponding target location in memory to complete the configuration update operation of the target microcontroller.

[0028] Thirdly, this application provides an electronic device, comprising:

[0029] Memory, used to store computer programs;

[0030] A processor is used to execute the computer program to implement the aforementioned configuration update method on a microcontroller.

[0031] Fourthly, this application provides a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the aforementioned configuration update method on a microcontroller.

[0032] This application first obtains the configuration definition file corresponding to the target microcontroller. The configuration definition file includes a schema file and a corresponding JSON file. The schema file includes the structural definition of the target configuration items, and the JSON file includes the specific values ​​of the target configuration items. Then, a preset data parsing engine is used to assign a unique identifier key to each field in the schema file. The target location in memory corresponding to each field is calculated based on the configuration definition file, and a target mapping table is generated based on each identifier key and the corresponding target location. The target mapping table includes the correspondence between each identifier key and the corresponding target location. Then, based on the target mapping table, the JSON file is packaged into a configuration update file, and the configuration update file is written to the Flash partition of the target microcontroller. Finally, the target microcontroller reads the configuration update file from the Flash partition to obtain each identifier key in the configuration update file, and matches each identifier key with the target microcontroller's local historical mapping table. If any identifier key exists in the historical mapping table, the data value corresponding to that identifier key in the configuration update file is written to the corresponding target location in memory to complete the configuration update operation for the target microcontroller. Therefore, this application achieves a unified update carrier by packaging specific values ​​into a single configuration update file and writing it to the storage through the mapping table. By matching the identifier key in the file with the device's local historical mapping table, data writing operations are only performed on the fields that match successfully, achieving selective compatibility updates between the old and new configuration versions. This allows the old configuration to safely identify and apply the known parts of the new configuration, thereby avoiding updating the configuration and code together. This reduces complexity and avoids system anomalies caused by updating the code. Attached Figure Description

[0033] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0034] Figure 1This is a schematic flowchart of a configuration update method on a microcontroller disclosed in this application.

[0035] Figure 2 This is a schematic diagram of the input and output of a Phython parsing engine disclosed in this application;

[0036] Figure 3 This is a schematic diagram of the configuration update device on a microcontroller disclosed in this application;

[0037] Figure 4 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation

[0038] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0039] Current methods for configuring microcontrollers have the problem that exceptions may occur when the program reloads the configuration. To address this, this application provides a configuration update method for microcontrollers.

[0040] See Figure 1 As shown, this embodiment of the invention discloses a configuration update method on a microcontroller, including:

[0041] Step S11: Obtain the configuration definition file corresponding to the target microcontroller; wherein, the configuration definition file includes a Schema file and a corresponding JSON file, the Schema file includes the structure definition of the target configuration item, and the JSON file includes the specific value of the target configuration item.

[0042] In this embodiment, the data input into the Phython parsing engine is as follows: Figure 2 As shown, this includes a configuration definition file, a structure definition template file, a configuration interface template file, and a configuration update template file. In this embodiment, the configuration definition file of the target microcontroller needs to be obtained first.

[0043] 1. Input:

[0044] (a) Configuration definition file: This file is used to describe and define a configuration. Here, json-Schema + json is used to construct the definition of a configuration. For example:

[0045] {

[0046] "$id": "http: / / example.com / schemas / config.schema.json",

[0047] "$schema": "http: / / json-schema.org / draft-07 / schema#",

[0048] "flag":"config",

[0049] "type": "object",

[0050] "properties": {

[0051] "name": {

[0052] "$ref": "type.schema.json# / definitions / CommonBuff",

[0053] "description": "Name";

[0054] },

[0055] "age": {

[0056] "$ref": "type.schema.json# / definitions / Age",

[0057] "description": "Age";

[0058] },

[0059] "address": {

[0060] "$ref": "type.schema.json# / definitions / CommonBuff",

[0061] "description": "User's address information";

[0062] },

[0063] "moduele": {

[0064] ​​​​​

[0066] },

[0067] "nodeinfo":{

[0068] "$ref": "type.schema.json# / definitions / TestNodeTag",

[0069] "description": "ddd";

[0070] }

[0071] }}

[0072] In json-Schema (i.e., Schema file), each property is a separate configuration. For the sake of neatness, this example puts the type definitions in type.schema.json, as follows:

[0073] "CommonBuff":{

[0074] "type":"string",

[0075] "pattern": "^[0-9a-zA-Z]{1,9}$",

[0076] "maxLength": 16;

[0077] },

[0078] "TestNode":{

[0079] "type":"object",

[0080] "additionalProperties": false,

[0081] "properties": {

[0082] "name": {

[0083] "$ref": "# / definitions / CommonBuff";

[0084] },

[0085] "value": {

[0086] "$ref": "# / definitions / uint32_t";

[0087] },

[0088] "is_enable": {

[0089] "$ref": "# / definitions / IsEnable";

[0090] }

[0091] },

[0092] "required": ["name", "value", "is_enable"];

[0093] },

[0094] "TestNodeArray":{

[0095] "type": "array",

[0096] "items": {

[0097] "$ref": "# / definitions / TestNode";

[0098] },

[0099] "maxItems": 10

[0100] },

[0101] "TestNodeTag":{

[0102] "type":"object",

[0103] "additionalProperties": false,

[0104] "properties": {

[0105] "item_len":{

[0106] "$ref": "# / definitions / uint8_t";

[0107] },

[0108] "item": {

[0109] "$ref": "# / definitions / TestNodeArray";

[0110] },

[0111] "res":{

[0112] "$ref": "# / definitions / uint32_t";

[0113] }

[0114] },

[0115] "required": ["item_len", "item", "res"];

[0116] },

[0117] The code example above shows the definition of the TestNodeTag configuration. As you can see, it's an object type containing three elements: item_len, item, and res. Here, item is an array of objects. This example uses json-Schema to define the configuration data structure. The configuration values ​​still need to be defined using specific JSON, as follows:

[0118] {

[0119] "name":"hello",

[0120] "age":66,

[0121] "nodeinfo":

[0122] {

[0123] "item_len":3,

[0124] "item":[

[0125] {

[0126] "name":"123",

[0127] "value":12,

[0128] "is_enable":true;

[0129] },

[0130] {

[0131] "name":"456",

[0132] "value":36,

[0133] "is_enable":false;

[0134] },

[0135] {

[0136] "name":"789",

[0137] "value":69,

[0138] "is_enable":true;

[0139] } ]

[0141] }}

[0142] In this JSON file, this example assigns values ​​to specific configurations according to the definitions in the schema. At this point, the definition of the configuration file is complete.

[0143] (b) Structure definition template file: This template file is written in Jinja and is used to convert the configuration definition (object type) in the Schema into the structure in C code.

[0144] #ifndef {{ header_guard}}

[0145] #define {{ header_guard}}

[0146] #include<stdint.h>

[0147] #include<stdbool.h>

[0148] #ifdef __cplusplus

[0149] extern "C" {

[0150] #endif

[0151] #define NULL_POINTER (1)

[0152] #define EXE_OK (0)

[0153] #define VALUE_INEXIST (2)

[0154] #define SYSTEM_ERROR (3)

[0155] #define NON_SUPPORT (4)

[0156] #define UNKNOW_ERRPR (5)

[0157] #define DB_WRITE_ERROR (6)

[0158] #define TYPE_ERROR (7)

[0159] #define KEY_NOT_EXIST (8)

[0160] #define VALUE_LEN_ERROR (9)

[0161] typedef int32_t (*TUniverInterface)(uint8_t *addr, int32_t len);

[0162] / * Auto-generated defines * /

[0163] {% for key, value in macros.items() -%}

[0164] #define {{ key}} ({{ value}}U)

[0165] {% endfor %}

[0166] / **

[0167] * @brief enum key;

[0168] * /

[0169] enum TElementKeyTag

[0170] {

[0171] {% for items in enum_key.valus -%}

[0172] {{items.name.ljust(enum_key.max_define_len + 10)}} ={{(items.enum + ",").ljust(enum_key.max_field_len + 10)}} / / / < json keyfor {{items.descrip}}

[0173] {% endfor %}

[0174] };

[0175] typedef enum TElementKeyTag TElementKey;

[0176] / * Auto-generated enums * /

[0177] {% for enum in enums %}

[0178] / **

[0179] * @brief {{ enum.top_des}};

[0180] * /

[0181] enum T{{ enum.name}}Tag

[0182] {

[0183] {%- for value in enum.enum_values %}

[0184] k{{ enum.prefix}}{{ value.ljust(enum.max_type_len + 10)}} = {{(enum.eunm_value[value] + ",").ljust(enum.max_fields_len + 10)}} / / / < {{enum.description[value]}}

[0185] {%- endfor %}

[0186] };

[0187] {% endfor %}

[0188] #pragma pack(1) / / 指定按 1 字节对齐

[0189] / * Auto-generated type define * /

[0190] {% for type in type_define %}

[0191] {% if 'tag_name' in type -%}

[0192] {% set struct = type -%}

[0193] / **

[0194] * @brief {{ struct.description}};

[0195] /

[0196] struct T{{ struct.name}}Tag

[0197] {

[0198] {%- for field in struct.fields %}

[0199] {{ field.type.ljust(struct.max_type_len + 10)}} {{ (field.name +";").ljust(struct.max_fields_len + 10)}} / / / < {{field.des}}

[0200] {%- endfor %}

[0201] };

[0202] {% else -%}

[0203] {{type.full_name}};

[0204] {% endif -%}

[0205] {% endfor -%}

[0206] #pragma pack()

[0207] #ifdef __cplusplus

[0208] }

[0209] #endif

[0210] #endif / * {{ header_guard}} * /

[0211] As you can see, in addition to the structure, an enumeration type is also defined. You only need to render the specific data through this template to get the structure configuration definition in the C code.

[0212] (c) Configuration Interface Template File: This file is written in Jinja and is used to generate the specific configuration access interface, as follows:

[0213] enum T{{interface_infos.title}}ItemKeyTag

[0214] {

[0215] {% for item in interface_infos.inter_list -%}

[0216] k{{interface_infos.title}}Item{{item.last_name}},

[0217] {% endfor %}

[0218] };

[0219] typedef enum T{{interface_infos.title}}ItemKeyTag T{{interface_infos.title}}ItemKey;

[0220] / **

[0221] * @brief Initialize;

[0222] * /

[0223] void T{{interface_infos.title}}Init(void);

[0224] {% for item in interface_infos.inter_list -%}

[0225] / **

[0226] * @brief Get the read pointer of {{ item.description}};

[0227] * @param Error code;

[0228] * @return NULL: Failure, non-NULL: Success;

[0229] * /

[0230] const {{item.type}}* T{{interface_infos.title}}Get{{item.last_name}}Rptr(int32_t *len, int32_t *err);

[0231] / ** <* @brief retrieves the write pointer to {{ item.description}};

[0233] * @param len: Write cache length;

[0234] * @param Error code;

[0235] * @return NULL: failure, non-NULL: success;

[0236] /

[0237] {{item.type}}* T{{interface_infos.title}}Get{{item.last_name}}Wptr(int32_t *len, int32_t *err);

[0238] / **

[0239] * @brief sets {{ item.description}};

[0240] * @param Type: {{ item.type}};

[0241] * @return = 0 indicates success, < 0 indicates failure;

[0242] /

[0243] int32_t T{{interface_infos.title}}Set{{item.last_name}}({{item.type}}*value);

[0244] {% endfor %}

[0245] After importing the specific configuration data, you can directly obtain the configured access interface (read / write).

[0246] (b) Configuration update template file: This template file is also written in Jinja and is used to generate the index file for configuration updates, as follows:

[0247] #define UPLOAD_BUFF_SIZE (1024)

[0248] #define UPLOAD_SINGLE_COUNT (1)

[0249] #define HIT (1)

[0250] #define UNHIT (0)

[0251] / / / key_info

[0252] {% for name, lists in c_info.key_info.items() -%}

[0253] {% set offset_list = [] -%}

[0254] {% set len_list = [] %}

[0255] #define {{interface_info.interface_infos.title.upper()}}_{{name.upper()}}_LEN ({{lists|length}})

[0256] const TKeyInfo {{interface_info.interface_infos.title.lower()}}_{{name.lower()}}_[{{interface_info.interface_infos.title.upper()}}_{{name.upper()}}_LEN] =

[0257] {

[0258] {% for item in lists -%}

[0259] {.key_ = {{item.key}}, .offset_ = {{item.offset}}, .len_ ={{item.len}}, .min_ = {{item.min}}, .max_ = {{item.max}}, .is_unsigned_ ={{item.is_unsigned}}, .re_id_ = {{item.re_id}}, .jump_key_ = {{item.jump_key}}},

[0260] {% set _ = offset_list.append(item.offset) -%}

[0261] {% set _ = len_list.append(item.len) -%}

[0262] {% endfor %}

[0263] };

[0264] static uint8_t {{interface_info.interface_infos.title.lower()}}_{{name.lower()}}_hit[{{interface_info.interface_infos.title.upper()}}_{{name.upper()}}_LEN];

[0265] {% endfor %}

[0266] typedef struct T{{interface_info.interface_infos.title}}ItemTag T{{interface_info.interface_infos.title}}Item;

[0267] struct T{{interface_info.interface_infos.title}}ItemTag

[0268] {

[0269] const TKeyInfo *key_array_;

[0270] const int32_t key_array_count_;

[0271] int32_t w_size_;

[0272] uint8_t *hit_array_;

[0273] T{{interface_info.interface_infos.title}}ItemKey item_key_;

[0274] };

[0275] #define {{interface_info.interface_infos.title.upper()}}_ITEM_COUNT({{interface_info.interface_infos.inter_list|length}})

[0276] static T{{interface_info.interface_infos.title}}Item {{interface_info.interface_infos.title.lower()}}_item[{{interface_info.interface_infos.title.upper()}}_ITEM_COUNT] =

[0277] {

[0278] {% for name, lists in c_info.key_info.items() -%}

[0279] {

[0280] .key_array_ = {{interface_info.interface_infos.title.lower()}}_{{name.lower()}}_,

[0281] .key_array_count_ = {{interface_info.interface_infos.title.upper()}}_{{name.upper()}}_LEN,

[0282] .w_size_ = 0,

[0283] .hit_array_ = {{interface_info.interface_infos.title.lower()}}_{{name.lower()}}_hit,

[0284] {% set parts = name.split('_') -%}

[0285] {% set capitalized_parts = parts|map('lower')|map('capitalize') -%}

[0286] {% set result = capitalized_parts|join('') -%}

[0287] .item_key_ = k{{interface_info.interface_infos.title}}Item{{result}}

[0288] },

[0289] {% endfor %}

[0290] }

[0291] Step S12: Assign a unique identifier key to each field in the Schema file using a preset data parsing engine, calculate the target location in memory corresponding to each field according to the configuration definition file, and generate a target mapping table based on each identifier key and the corresponding target location; wherein, the target mapping table includes the correspondence between each identifier key and the corresponding target location.

[0292] In this embodiment, before assigning unique identifier keys to each field in the schema file using a preset data parsing engine, the method further includes:

[0293] Based on the structure definition in the Schema file, determine whether the Schema file matches the JSON file. If the Schema file matches the JSON file, proceed to the step of assigning a unique identifier key to each field in the Schema file using a preset data parsing engine.

[0294] In addition, the above-mentioned calculation of the target positions of each field in memory according to the configuration definition file includes: determining the field length and field type of each field according to the configuration definition file, as well as the arrangement order of each field in the configuration definition file; and calculating the target positions of each field in memory according to the field length, field type and arrangement order of each field.

[0295] The specific functions of the Python parsing engine (the default data parsing engine) mentioned above are as follows:

[0296] a) Configuration parsing sub-engine: The input to this sub-engine is the configuration definition file, namely the json-Schema and json file mentioned above. The functions of this engine are:

[0297] i. Determine if the Schema and JSON match, because the Schema defines the data type, scope, etc. of each configuration item, and the definition of the configuration entity in the JSON must be within the scope of the Schema, so a matching check is required between the two.

[0298] ii. Parse the schema data and JSON data to obtain two data sources for subsequent template rendering.

[0299] iii. When parsing the schema, assign a unique key (i.e., identifier key) to each item according to the hierarchical relationship, and store it in key_db.json, as follows:

[0300] "nodeinfo": {

[0301] "point": 30072,

[0302] "remain": 288,

[0303] "items": {

[0304] "nodeinfo.item_len": 30040,

[0305] "nodeinfo.item.items_0.name": 30041,

[0306] "nodeinfo.item.items_0.value": 30042,

[0307] "nodeinfo.item.items_0.is_enable": 30043,

[0308] "nodeinfo.item.items_1.name": 30044,

[0309] "nodeinfo.item.items_1.value": 30045,

[0310] "nodeinfo.item.items_1.is_enable": 30046,

[0311] "nodeinfo.item.items_2.name": 30047,

[0312] "nodeinfo.item.items_2.value": 30048,

[0313] "nodeinfo.item.items_2.is_enable": 30049,

[0314] "nodeinfo.item.items_3.name": 30050,

[0315] "nodeinfo.item.items_3.value": 30051,

[0316] "nodeinfo.item.items_3.is_enable": 30052,

[0317] "nodeinfo.item.items_4.name": 30053,

[0318] "nodeinfo.item.items_4.value": 30054,

[0319] "nodeinfo.item.items_4.is_enable": 30055,

[0320] "nodeinfo.item.items_5.name": 30056,

[0321] "nodeinfo.item.items_5.value": 30057,

[0322] "nodeinfo.item.items_5.is_enable": 30058,

[0323] "nodeinfo.item.items_6.name": 30059,

[0324] "nodeinfo.item.items_6.value": 30060,

[0325] "nodeinfo.item.items_6.is_enable": 30061,

[0326] "nodeinfo.item.items_7.name": 30062,

[0327] "nodeinfo.item.items_7.value": 30063,

[0328] "nodeinfo.item.items_7.is_enable": 30064,

[0329] "nodeinfo.item.items_8.name": 30065,

[0330] "nodeinfo.item.items_8.value": 30066,

[0331] "nodeinfo.item.items_8.is_enable": 30067,

[0332] "nodeinfo.item.items_9.name": 30068,

[0333] "nodeinfo.item.items_9.value": 30069,

[0334] "nodeinfo.item.items_9.is_enable": 30070,

[0335] "nodeinfo.res": 30071

[0336] }

[0337] },

[0338] Meanwhile, since the structure is stored contiguously in memory, given the position, length, and data type of an item, the offset (i.e., the target position) of that item in the structure can be calculated. The offsets of all items are calculated and saved. In the schema, the object type corresponds to the structure type, and the storage order is the arrangement order.

[0339] iv. When parsing the JSON data file, it relies on the key_db.json mentioned above and packages the JSON data file into a bin file according to the structure of |key|len|bytes|. This bin file is the configuration update file.

[0340] That is, the JSON file is packaged into a configuration update file based on the target mapping table, including: based on the target mapping table, the identifier key, field length and bytes corresponding to each field in the JSON file are concatenated in sequence to generate the configuration update file.

[0341] b) Structure Template Rendering Engine: This engine renders the data source obtained from the Schema into the structure template, resulting in the structure definition in C code, as follows:

[0342] typedef uint8_t uint8_t_array[UINT8_T_ARRAY_MAXLENGTH];

[0343] typedef uint8_t CommonBuff[COMMONBUFF_MAXLENGTH];

[0344] typedef uint8_t Age;

[0345] typedef uint32_t CanId;

[0346] / **

[0347] * @brief;

[0348] /

[0349] struct TMatrixTag

[0350] {

[0351] uint8_t bus;

[0352] CanId id;

[0353] uint8_t len;

[0354] StartBit start_bit;

[0355] uint8_t tolerance_val;

[0356] };

[0357] / **

[0358] * @brief;

[0359] /

[0360] struct TUdsMatrixTag

[0361] {

[0362] uint8_t bus;

[0363] UdsName name;

[0364] CanId phy_req_id;

[0365] CanId phy_resp_id;

[0366] };

[0367] This file can be directly compiled and accessed by the code.

[0368] c) Interface template rendering engine: Renders the data source obtained from the JSON data file into the interface template to obtain the configured access interface, as follows:

[0369] / **

[0370] * @brief Gets the name read pointer;

[0371] * @param Error code;

[0372] * @return NULL: failure, non-NULL: success;

[0373] /

[0374] const CommonBuff* TConfigGetNameRptr(int32_t *len, int32_t *err);

[0375] / **

[0376] * @brief Gets the write pointer to the name;

[0377] * @param len: Write cache length;

[0378] * @param Error code;

[0379] * @return NULL: failure, non-NULL: success;

[0380] /

[0381] CommonBuff* TConfigGetNameWptr(int32_t *len, int32_t *err);

[0382] / **

[0383] * @brief Set name;

[0384] * @param Type: CommonBuff;

[0385] * @return = 0 indicates success, < 0 indicates failure;

[0386] /

[0387] int32_t TConfigSetName(CommonBuff *value);

[0388] / **

[0389] * @brief Gets the age read pointer;

[0390] * @param Error code;

[0391] * @return NULL: failure, non-NULL: success;

[0392] /

[0393] const Age* TConfigGetAgeRptr(int32_t *len, int32_t *err);

[0394] / **

[0395] * @brief Gets the age write pointer;

[0396] * @param len: Write cache length;

[0397] * @param Error code;

[0398] * @return NULL: failure, non-NULL: success;

[0399] /

[0400] Age* TConfigGetAgeWptr(int32_t *len, int32_t *err);

[0401] Applications can directly access the corresponding configuration information through these interfaces.

[0402] d) Update the template rendering engine: Render the index information, item offset, and item length information from key_db.json into the updated template to obtain a flattened structure of item information, as follows:

[0403] #define CONFIG_NODEINFO_LEN (32)

[0404] const TKeyInfo config_nodeinfo_[CONFIG_NODEINFO_LEN] =

[0405] {

[0406] {.key_ = KjkconfignodeinfoitemLen, .offset_ = 0, .len_ = 1, .min_ =0, .max_ = 0, .is_unsigned_ = 1, .re_id_ = -1, .jump_key_ = -2},

[0407] {.key_ = Kjkconfignodeinfoitemitems0Name, .offset_ = 1, .len_ = 16,.min_ = 0, .max_ = 0, .is_unsigned_ = 0, .re_id_ = 0, .jump_key_ =Kjkconfignodeinfores},

[0408] {.key_ = Kjkconfignodeinfoitemitems0Value, .offset_ = 17, .len_ = 4,.min_ = 0, .max_ = 0, .is_unsigned_ = 1, .re_id_ = -1, .jump_key_ = -1},

[0409] {.key_ = Kjkconfignodeinfoitemitems0IsEnable, .offset_ = 21, .len_ =1, .min_ = 0, .max_ = 1, .is_unsigned_ = 1, .re_id_ = -1, .jump_key_ = -1},

[0410] {.key_ = Kjkconfignodeinfoitemitems1Name, .offset_ = 22, .len_ = 16,.min_ = 0, .max_ = 0, .is_unsigned_ = 0, .re_id_ = 0, .jump_key_ =Kjkconfignodeinfores},

[0411] {.key_ = Kjkconfignodeinfoitemitems1Value, .offset_ = 38, .len_ = 4,.min_ = 0, .max_ = 0, .is_unsigned_ = 1, .re_id_ = -1, .jump_key_ = -1},

[0412] {.key_ = Kjkconfignodeinfoitemitems1IsEnable, .offset_ = 42, .len_ =1, .min_ = 0, .max_ = 1, .is_unsigned_ = 1, .re_id_ = -1, .jump_key_ = -1},

[0413] {.key_ = Kjkconfignodeinfoitemitems2Name, .offset_ = 43, .len_ = 16, .min_ = 0, .max_ = 0, .is_unsigned_ = 0, .re_id_ = 0, .jump_key_ =Kjkconfignodeinfores},

[0414] {.key_ = Kjkconfignodeinfoitemitems2Value, .offset_ = 59, .len_ = 4, .min_ = 0, .max_ = 0, .is_unsigned_ = 1, .re_id_ = -1, .jump_key_ = -1},

[0415] };

[0416] static uint8_t config_nodeinfo_hit[CONFIG_NODEINFO_LEN];

[0417] The key_ in the code above is the key in key_db.json.

[0418] Step S13: Based on the target mapping table, package the JSON file into a configuration update file and write the configuration update file into the Flash partition of the target microcontroller.

[0419] In this embodiment, before packaging the JSON file into a configuration update file based on the target mapping table, the method further includes: generating configuration access interface code based on the configuration definition file and the target mapping table, and integrating the configuration access interface code into the program code of the target microcontroller so that the target microcontroller can read the configuration update file according to the interface code.

[0420] The process of generating the access interface described above has been explained in detail in the preceding steps and will not be repeated here. By generating the configuration access interface code, the configuration access interface code is integrated into the program code of the target microcontroller, so that the target microcontroller can read the configuration update file according to the interface code.

[0421] In addition, before writing the configuration update file to the target microcontroller's Flash partition, the following steps are also included:

[0422] Write the configuration update file to the memory of the target microcontroller, and determine whether there is any missing data in the configuration update file in the memory of the target microcontroller. If there is no missing data in the configuration update file, proceed to the step of writing the configuration update file to the Flash partition of the target microcontroller.

[0423] It should be noted that in this implementation, the configuration update file is first written into the memory of the target microcontroller. The memory is then checked to see if the configuration update file is missing after the data transmission. If it is not missing, the configuration update file is written into the Flash partition of the target microcontroller. If it is missing, it indicates that there is an abnormality in the system, and the configuration update operation on the microcontroller is stopped accordingly.

[0424] Step S14: Use the target microcontroller to read the configuration update file from the Flash partition to obtain each of the identification keys in the configuration update file, and match each of the identification keys with the local historical mapping table of the target microcontroller. If any identification key exists in the historical mapping table, write the data value corresponding to the identification key in the configuration update file into the corresponding target location in memory to complete the configuration update operation of the target microcontroller.

[0425] The upgrade process in this embodiment is as follows:

[0426] a) Preliminary preparation: Use a Python parsing engine to parse the configuration JSON file, obtain the address offset information of key_db.json and the structure, and then synchronously record the configured key, offset, len and other information in the read-only code space.

[0427] b) Upgrade Process: The configuration upgrade file, packaged by the Python parsing engine, is downloaded to the microcontroller's Flash partition. After downloading, the application reads from the corresponding partition, retrieving configuration sub-items from the Flash according to the structure |key|len|bytes|, and updating them in the application's memory area (the code has a pre-set key table through the parsing engine for key matching). Simultaneously, a validity check is performed. After the upgrade, the code performs an integrity check based on the pre-set key table (i.e., the historical mapping table) to check for any missing keys. If no keys are missing, the new configuration has been updated to the system (the new configuration can be synchronized to the Flash for persistence).

[0428] Additionally, if any identifier key does not exist in the history mapping table, the original value of the field corresponding to that identifier key in memory is retained, and the next identifier key is matched against the history mapping table.

[0429] To make the process of this embodiment easier to understand, the update process of this solution will be illustrated with a set of specific examples below:

[0430] Suppose the microcontroller has a configuration structure used to store device parameters (such as temperature threshold, sampling period, etc.). The initial version of this structure is:

[0431] struct Config {

[0432] int temp_max; / / Maximum temperature;

[0433] int interval; / / Sampling interval;

[0434] };

[0435] During subsequent upgrades, a new field (such as bool enable_log) needs to be added to the structure, which changes the structure length. If the new configuration data is directly used to overwrite the old version, the old program will not be able to recognize the new field, resulting in memory misalignment and configuration read errors.

[0436] In this embodiment, the binary configuration update file is written to the microcontroller's Flash memory. During system startup:

[0437] Read each key from the binary file;

[0438] Find the offset of the corresponding field by matching the key with the preset key-value table;

[0439] Only write bytes of data to the corresponding offset in memory;

[0440] Ignore keys that do not exist in the key-value table (for example, if the original history mapping table does not have the field bool enable_log, then when updating the configuration, the value corresponding to the newly added bool enable_log field in the configuration update file will be automatically ignored, thus avoiding update errors when adding new configuration items).

[0441] Therefore, this application achieves a unified update carrier by packaging specific values ​​into a single configuration update file and writing it to the storage through the mapping table. By matching the identifier key in the file with the device's local historical mapping table, data writing operations are only performed on the fields that match successfully, achieving selective compatibility updates between the old and new configuration versions. This allows the old configuration to safely identify and apply the known parts of the new configuration, thereby avoiding updating the configuration and code together. This reduces complexity and avoids system anomalies caused by updating the code.

[0442] See Figure 3 As shown, an embodiment of the present invention discloses a configuration update device on a microcontroller, comprising:

[0443] The file acquisition module 11 is used to acquire the configuration definition file corresponding to the target microcontroller; wherein, the configuration definition file includes a schema file and a corresponding JSON file, the schema file includes the structure definition of the target configuration item, and the JSON file includes the specific value of the target configuration item;

[0444] The mapping table generation module 12 is used to assign a unique identifier key to each field in the Schema file using a preset data parsing engine, calculate the target position corresponding to each field in memory according to the configuration definition file, and generate a target mapping table according to each identifier key and the corresponding target position; wherein, the target mapping table includes the correspondence between each identifier key and the corresponding target position;

[0445] The file packaging module 13 is used to package the JSON file into a configuration update file based on the target mapping table, and write the configuration update file into the Flash partition of the target microcontroller;

[0446] The configuration update module 14 is used to read the configuration update file from the Flash partition using the target microcontroller to obtain each of the identification keys in the configuration update file, and match each of the identification keys with the local historical mapping table of the target microcontroller. If any identification key exists in the historical mapping table, the data value corresponding to the identification key in the configuration update file is written into the corresponding target location in memory to complete the configuration update operation of the target microcontroller.

[0447] In some specific embodiments, the mapping table generation module 12 further includes:

[0448] The file judgment unit is used to determine whether the Schema file matches the JSON file based on the structure definition in the Schema file. If the Schema file matches the JSON file, the process jumps to the step of assigning a unique identifier key to each field in the Schema file using a preset data parsing engine.

[0449] In some specific embodiments, the mapping table generation module 12 may specifically include:

[0450] The sequence determination unit is used to determine the field length and field type corresponding to each field, as well as the arrangement order of each field in the configuration definition file, according to the configuration definition file.

[0451] The position calculation unit is used to calculate the target positions in memory corresponding to each field according to the field length, field type and arrangement order of each field.

[0452] In some specific embodiments, the file packaging module 13 further includes:

[0453] An interface generation unit is used to generate configuration access interface code based on the configuration definition file and the target mapping table, and integrate the configuration access interface code into the program code of the target microcontroller so that the target microcontroller can read the configuration update file according to the interface code.

[0454] In some specific embodiments, the file packaging module 13 may specifically include:

[0455] The configuration update file generation unit is used to concatenate the identifier key, field length, and bytes corresponding to each field in the JSON file based on the target mapping table to generate the configuration update file.

[0456] In some specific embodiments, the file packaging module 13 further includes:

[0457] The step jump unit is used to write the configuration update file into the memory of the target microcontroller, and to determine whether there is missing data in the configuration update file in the memory of the target microcontroller. If there is no missing data in the configuration update file, the jump unit proceeds to the step of writing the configuration update file into the Flash partition of the target microcontroller.

[0458] In some specific embodiments, the configuration update device on the microcontroller further includes:

[0459] The identifier key matching unit is used to retain the original value of the field corresponding to any identifier key in memory if any identifier key does not exist in the historical mapping table, and to match the next identifier key with the historical mapping table.

[0460] Furthermore, embodiments of this application also disclose an electronic device, Figure 4 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.

[0461] Figure 4 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the configuration update method on the microcontroller disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0462] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0463] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0464] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the configuration update method on the microcontroller executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.

[0465] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned configuration update method on a microcontroller. The specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.

[0466] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0467] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0468] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0469] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0470] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A configuration update method on a microcontroller, characterized in that, include: Obtain the configuration definition file corresponding to the target microcontroller; wherein, the configuration definition file includes a schema file and a corresponding JSON file, the schema file includes the structure definition of the target configuration items, and the JSON file includes the specific values ​​of the target configuration items; A preset data parsing engine is used to assign a unique identifier key to each field in the schema file. The target location of each field in memory is calculated according to the configuration definition file. A target mapping table is generated based on each identifier key and the corresponding target location. The target mapping table includes the correspondence between each identifier key and the corresponding target location. Based on the target mapping table, the JSON file is packaged into a configuration update file, and the configuration update file is written to the Flash partition of the target microcontroller; The target microcontroller reads the configuration update file from the Flash partition to obtain each of the identification keys in the configuration update file, and matches each of the identification keys with the local historical mapping table of the target microcontroller. If any identification key exists in the historical mapping table, the data value corresponding to any identification key in the configuration update file is written to the corresponding target location in memory to complete the configuration update operation of the target microcontroller.

2. The configuration update method on a microcontroller according to claim 1, characterized in that, Before assigning unique identifier keys to each field in the Schema file using a preset data parsing engine, the process also includes: Based on the structure definition in the Schema file, determine whether the Schema file matches the JSON file. If the Schema file matches the JSON file, proceed to the step of assigning a unique identifier key to each field in the Schema file using a preset data parsing engine.

3. The configuration update method on a microcontroller according to claim 1, characterized in that, The step of calculating the target location in memory for each field according to the configuration definition file includes: The field length and field type corresponding to each field, as well as the arrangement order of each field in the configuration definition file, are determined according to the configuration definition file. Calculate the target positions in memory for each field based on its length, type, and arrangement order.

4. The configuration update method on a microcontroller according to claim 1, characterized in that, Before packaging the JSON file into a configuration update file based on the target mapping table, the process also includes: Based on the configuration definition file and the target mapping table, configuration access interface code is generated, and the configuration access interface code is integrated into the program code of the target microcontroller so that the target microcontroller can read the configuration update file according to the interface code.

5. The configuration update method on a microcontroller according to claim 1, characterized in that, The step of packaging the JSON file into a configuration update file based on the target mapping table includes: Based on the target mapping table, the identifier key, field length, and bytes corresponding to each field in the JSON file are concatenated sequentially to generate the configuration update file.

6. The configuration update method on a microcontroller according to claim 1, characterized in that, Before writing the configuration update file to the Flash partition of the target microcontroller, the method further includes: Write the configuration update file into the memory of the target microcontroller, and determine whether there is missing data in the configuration update file in the memory of the target microcontroller. If there is no missing data in the configuration update file, proceed to the step of writing the configuration update file into the Flash partition of the target microcontroller.

7. The configuration update method on a microcontroller according to any one of claims 1 to 6, characterized in that, Also includes: If any identifier key does not exist in the historical mapping table, the original value of the field corresponding to the identifier key in memory is retained, and the next identifier key is matched with the historical mapping table.

8. A configuration update device on a microcontroller, characterized in that, include: The file acquisition module is used to acquire the configuration definition file corresponding to the target microcontroller; wherein, the configuration definition file includes a schema file and a corresponding JSON file, the schema file includes the structure definition of the target configuration items, and the JSON file includes the specific values ​​of the target configuration items; The mapping table generation module is used to assign a unique identifier key to each field in the Schema file using a preset data parsing engine, calculate the target location in memory corresponding to each field according to the configuration definition file, and generate a target mapping table according to each identifier key and the corresponding target location; wherein, the target mapping table includes the correspondence between each identifier key and the corresponding target location; The file packaging module is used to package the JSON file into a configuration update file based on the target mapping table, and write the configuration update file into the Flash partition of the target microcontroller; The configuration update module is used to read the configuration update file from the Flash partition using the target microcontroller to obtain each of the identification keys in the configuration update file, and match each of the identification keys with the local historical mapping table of the target microcontroller. If any identification key exists in the historical mapping table, the data value corresponding to the identification key in the configuration update file is written to the corresponding target location in memory to complete the configuration update operation of the target microcontroller.

9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the configuration update method on a microcontroller as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, Used to store a computer program, which, when executed by a processor, implements the configuration update method on a microcontroller as described in any one of claims 1 to 7.