Disclosure of Invention
In order to solve the problem that software upgrading of a system on chip fails due to reasons such as inconsistent Windows versions of current PCs or failed installation of drivers, the embodiment of the application provides a method and a system for upgrading off-line downloaded software.
In a first aspect, an embodiment of the present application provides a method for downloading a software upgrade offline, including:
the off-line upgrading system periodically detects whether the first interface is inserted into the storage card; when the first interface is detected to be inserted into the memory card, executing the subsequent steps;
a green light connected with the off-line upgrading system is turned on;
and opening the off-line upgrading configuration file in the memory card, entering an automatic upgrading mode if the opening is successful, loading the file in the memory card if the opening is failed, and entering a key selection upgrading mode.
Wherein, if the opening fails, loading the file in the memory card, and entering a key selection upgrading mode, including:
opening the file in the memory card by using the appointed file names in sequence, adding the current file name into the list whenever the return is successful, and finishing the loading of the file when the return is failed;
the loaded files are stored in a list according to the sequence of the dictionary order, the input command is received through a key, and a seven-segment digital tube connected with the offline upgrading system is displayed in a flashing mode to show that the files are being selected;
receiving a command of selecting a file through a determination key, displaying a seven-segment digital tube in a normally-on mode to indicate that the file is selected, wherein the numerical value displayed by the seven-segment digital tube indicates the number of the files in the list;
the method comprises the steps that a command for starting upgrading is received through a starting key, the offline upgrading system is connected with a target platform through an SWD interface, after the command for starting upgrading is received, a file is written into a fixed 0x08000000 position, a green LED flashes quickly in the upgrading process, the upgrading is stopped when an error occurs in the process, the target platform is reset, and red LED is used for indicating according to an error code.
Wherein, the opening the off-line upgrade configuration file in the memory card, and if the opening is successful, entering an automatic upgrade mode, includes:
reading the programming rule in the offline upgrade configuration file line by line, checking whether the read programming rule is correct, including whether the length of the file name is less than 15 characters, whether the written address value is in the range of 0x08000000 to 0x0801ffff, storing the correct programming rule in a linked list, if the linked list is not empty, waiting to receive a start instruction, connecting the SWD with a target platform, starting upgrading according to the programming rule, if the programming address in the programming rule is equal to 0x08000000, erasing a chip, and then writing the file into the address, otherwise, directly writing the file into the specified address in the programming rule.
Wherein, still include: and the green LED flashes quickly in the upgrading process, the upgrading is stopped when an error occurs in the process, the target platform is reset, and the red LED is used for indicating according to the error code.
Wherein, still include: after writing, if an error exists, the red LED is normally lighted for 1 second, and then flickers for a plurality of times according to an error code at the frequency of 200 milliseconds; and if the writing is normal, the green LED lamp is normally on.
The upgrading process comprises the following steps:
sending 51 '1's for resetting SWD, switching JTAG to SWD, reading the value of a debugging port identification register (DPIDR), and if the return value is not 0, successfully connecting with the system on chip;
setting the STKCMPCLR, STKERRCLR, WDERRCLR, ORUNERRCLR bit of an ABORT register (ABORT), clearing the state, ensuring that a CTRL/STAT register is selected in a DPBANKSEL, sending a system power-on request, waiting for a response, and stopping the program if the response is not responded after the time is out;
enabling the system on chip to enter a reset programming mode, downloading a programming algorithm to an SRAM and initializing;
reading 1024 bytes of data from the upgrade file in a circulating manner, programming the data to FLASH by using pages, and filling and aligning the data of the last page, wherein the size of the data of the last page is smaller than 1024 by using 0;
reading data from the first page and the last page of the FLASH programming according to the file size, and comparing the data with the upgrading file data, wherein if the data are the same, the upgrading is successful;
and resetting the system on the chip in a soft mode, and releasing the SWD interface.
In a second aspect, the present application provides a system for downloading a software upgrade offline, comprising: an offline upgrade system to:
periodically detecting whether the first interface is inserted into the memory card; when the first interface is detected to be inserted into the memory card, executing the subsequent steps;
controlling a green light connected with the off-line upgrading system to be turned on;
and opening the off-line upgrading configuration file in the memory card, entering an automatic upgrading mode if the opening is successful, loading the file in the memory card if the opening is failed, and entering a key selection upgrading mode.
The first interface is an SPI interface, and the storage card is a TF card.
The off-line upgrading system is connected with the matrix keyboard and the functional keys through GPIO interfaces, the off-line upgrading system is connected with the LED and the seven-segment digital tube through the GPIO interfaces, and the off-line upgrading system is connected with the target platform through an SWD interface.
Wherein the offline upgrade system is configured to:
opening the file in the memory card by using the appointed file names in sequence, adding the current file name into the list whenever the return is successful, and finishing the loading of the file when the return is failed;
the loaded files are stored in a list according to the sequence of the dictionary order, the input command is received through a key, and a seven-segment digital tube connected with the offline upgrading system is displayed in a flashing mode to show that the files are being selected;
receiving a command of selecting a file through a determination key, displaying a seven-segment digital tube in a normally-on mode to indicate that the file is selected, wherein the numerical value displayed by the seven-segment digital tube indicates the number of the files in the list;
the method comprises the steps that a command for starting upgrading is received through a starting key, the offline upgrading system is connected with a target platform through an SWD interface, after the command for starting upgrading is received, a file is written into a fixed 0x08000000 position, a green LED flashes quickly in the upgrading process, the upgrading is stopped when an error occurs in the process, the target platform is reset, and red LED is used for indicating according to an error code. .
The method and the system for upgrading the off-line downloaded software have the following beneficial effects:
the method for upgrading the off-line download software comprises the following steps: the off-line upgrading system periodically detects whether the first interface is inserted into the storage card; when detecting that the first interface is inserted into the memory card, executing the subsequent steps; a green light connected with the off-line upgrading system is turned on; and opening an off-line upgrading configuration file in the memory card, entering an automatic upgrading mode if the opening is successful, loading the file in the memory card if the opening is failed, and entering a key selection upgrading mode.
The invention can get rid of dependence on huge PC computers, and makes the upgrade platform easier to deploy when manufacturers produce in batches. The requirements on computer knowledge and professional knowledge of users are reduced, software upgrading of different platforms is simple and easy to achieve, the problem that software upgrading of the system on chip fails due to reasons of inconsistent windows versions of the PC or failure in drive installation is solved, the software upgrading of the system on chip is the same as copying an upgrading file to a U disk, and developers who just touch the system on chip can concentrate on software development.
Detailed Description
The present application is further described with reference to the following figures and examples.
In the following description, the terms "first" and "second" are used for descriptive purposes only and are not intended to indicate or imply relative importance. The following description provides embodiments of the invention, which may be combined or substituted for various embodiments, and this application is therefore intended to cover all possible combinations of the same and/or different embodiments described. Thus, if one embodiment includes feature A, B, C and another embodiment includes feature B, D, then this application should also be considered to include an embodiment that includes one or more of all other possible combinations of A, B, C, D, even though this embodiment may not be explicitly recited in text below.
The following description provides examples, and does not limit the scope, applicability, or examples set forth in the claims. Changes may be made in the function and arrangement of elements described without departing from the scope of the disclosure. Various examples may omit, substitute, or add various procedures or components as appropriate. For example, the described methods may be performed in an order different than the order described, and various steps may be added, omitted, or combined. Furthermore, features described with respect to some examples may be combined into other examples.
The invention is a device with small volume, portability and low manufacturing cost, which is connected with the system-on-chip through the SWD interface to carry out software upgrading, so that the software upgrading of the system-on-chip is simple, the problem of software upgrading failure of the system-on-chip caused by inconsistent windows versions of PCs or failure of drive installation and the like can be solved, an upgrading platform is easier to deploy when manufacturers produce in batches, the software upgrading of the system-on-chip is just like copying an upgrading file to a U disk, and developers just contacting the system-on-chip can concentrate on software development.
As shown in fig. 1 to 3, a method for downloading a software upgrade offline according to the present application includes: step S101, an off-line upgrading system periodically detects whether a first interface is inserted into a memory card; when detecting that the first interface is inserted into the memory card, executing the subsequent steps; s103, turning on a green light connected with the offline upgrading system; s105, opening the off-line upgrading configuration file in the memory card, entering an automatic upgrading mode if the opening is successful, loading the file in the memory card if the opening is failed, and entering a key selection upgrading mode. Each step is described below.
Step S101, an off-line upgrading system periodically detects whether a first interface is inserted into a memory card; when the first interface is detected to be inserted into the memory card, the following steps are executed. And S103, turning on a green light connected with the offline upgrading system.
FIG. 3 is a system framework diagram for offline download, as shown in FIG. 3: the system uses an FATFS file system to read and write TF card, and comprises 10 digital keys, 1 start key, 1 confirmation key as human-computer interaction input, STM32 as logic master control, 3 7-segment nixie tubes for displaying selected file numbers, 1 red LED lamp and 1 green LED lamp as result information indication, and an SWD interface for connecting with a system on chip.
Most of the processing units of the system on chip in the market are ARM architectures, and the main stream debugging and downloading interfaces of the ARM architectures at present mainly include: 1. JTAG (Joint Test Action Group) is an international standard protocol, and is mainly used for chip internal Test. At present, the JTAG protocol is supported by products of most chip manufacturers, and the standard JTAG interface is 4 lines: TMS, TCK, TDI, TDO are mode select, clock, data input and data output, respectively. 2. The SWD (Serial Wire Debug) only uses two interfaces 3 of SWDIO and SWCLK, and the RDI (Remote Debug Interface) is a standard Debug Interface proposed by ARM company, and is mainly used for simulation of ARM chips. At present, many IDE manufacturers gradually adopt standard RDI as a debugging interface of an ARM emulator, so that cross-platform hardware debugging is possible.
The difference between the SWD and the traditional debugging downloading mode is as follows: SWD mode is more reliable than JTAG in high speed mode. The JTAG download procedure may fail in the case of a large data volume, but the probability of SWD occurrence is much smaller. In the case of the emulation mode using basically JTAG, the SWD mode can be directly used. Compared with the traditional debugging download, the SWD uses fewer communication lines, so that the space used for designing the PCB is less, and the volume of a product is smaller.
The SWD interface uses a single bidirectional data connection (SWDIO) and a single clock-synchronous transfer of data (SWDCLK). The operation on the wire comprises two to three phases:
1: and when the request of the data packet is received, the external host debugger sends the request to the debugging port. The debug port is the target of the request and when the target receives a packet request from the debug host, it must respond immediately by entering the validation phase.
2: and the target machine sends a response to the external host machine in response to the data packet.
3: a data transmission phase, which only exists in two cases: a. a data read or data write request is followed by a valid (OK) acknowledge response. CTRL/STAT, ORUNDETECT flags 0b 1.
The system is electrified and then continuously detects whether the TF card is inserted through the SPI interface, at the moment, the green light is in a normally-off state, and when the TF card is detected to be inserted, the green light is turned on.
S105, opening the off-line upgrading configuration file in the memory card, entering an automatic upgrading mode if the opening is successful, loading the file in the memory card if the opening is failed, and entering a key selection upgrading mode.
In some embodiments, if the opening fails, loading the file in the memory card, and entering a key selection upgrade mode, the method includes:
opening the file in the memory card by using the appointed file names in sequence, adding the current file name into the list whenever the return is successful, and finishing the loading of the file when the return is failed; the loaded files are stored in a list according to the sequence of the dictionary order, the input command is received through a key, and a seven-segment digital tube connected with an offline upgrading system is displayed in a flashing mode to show that the files are being selected; receiving a command of selecting a file through a confirming key, displaying the seven-segment digital tube in a normally-on mode to indicate that the file is selected, and displaying the numerical value of the seven-segment digital tube to indicate the number of the files in the list; the method comprises the steps that a command for starting upgrading is received through a starting key, an offline upgrading system is connected with a target platform through an SWD interface, after the command for starting upgrading is received, a file is written into a fixed 0x08000000 position, a green LED flashes quickly in the upgrading process, the upgrading is stopped when an error occurs in the process, the target platform is reset, and the red LED is used for indicating according to an error code.
Cfg files are opened by using f _ open, if the files return to be successful, an automatic upgrading mode is entered, otherwise, the files are opened by using the appointed file names in sequence, the current file name is added into the list when the files return to be successful, the files are loaded when the files return to be failed, and then the upgrading mode is selected by entering a key.
And (3) selecting an upgrading mode by a key: in the mode, file names are stored in a list according to the sequence of a dictionary sequence, a seven-segment digital tube is displayed in a flashing mode when a key is input to indicate that a file is being selected, the file is displayed in a normally bright mode when the key is pressed to indicate that the file is selected, a display value indicates the number of the files in the list, the SWD is used for being connected with a target platform to start writing the file into a fixed 0x08000000 position after a start key is pressed, a green LED flashes quickly in the upgrading process, the upgrading is stopped when an error occurs in the process, the target platform is reset, and a red LED is used for indicating according to an error code.
In some embodiments, opening the offline upgrade configuration file in the memory card, and if the opening is successful, entering an automatic upgrade mode includes:
reading the programming rule in an offline upgrade configuration file (offline.cfg) line by line, checking whether the read programming rule is correct, including whether the length of a file name is less than 15 characters, whether the written address value is in the range of 0x08000000 to 0x0801ffff, storing the correct programming rule in a linked list, if the linked list is not empty, starting upgrading according to the programming rule by using SWD after waiting for receiving a starting instruction, if the programming address in the programming rule is equal to 0x08000000, erasing a chip and then writing the file in the address, otherwise, directly writing the file in the specified address in the programming rule.
In some embodiments, the method for downloading a software upgrade offline further includes: and the green LED flashes quickly in the upgrading process, the upgrading is stopped when an error occurs in the process, the target platform is reset, and the red LED is used for indicating according to the error code.
In some embodiments, the method for downloading a software upgrade offline further includes: after writing, if an error exists, the red LED is normally lighted for 1 second, and then flickers for a plurality of times according to an error code at the frequency of 200 milliseconds; and if the writing is normal, the green LED lamp is normally on. The upgrade can continue to cycle through such a cycle after the start key is pressed.
The format of the upgrade rule command is: < opt > < file name > < addr > [ size ], where opt is the operation performed, 'w' denotes writing FLASH, 'r' denotes reading FLASH, 'file name' denotes the file name of the upgrade file, or the file name of the read content save, 'addr' denotes the FLASH address to be written or read, 'size' is optional, and is valid only when the operation is read, which denotes how many bytes of data need to be read.
The upgrading process comprises the following steps:
sending 51 '1's for resetting SWD, switching JTAG to SWD, reading the value of a debugging port identification register (DPIDR), and if the return value is not 0, successfully connecting with the system on chip;
setting the STKCMPCLR, STKERRCLR, WDERRCLR, ORUNERRCLR bit of an ABORT register (ABORT), clearing the state, ensuring that a CTRL/STAT register is selected in a DPBANKSEL, sending a system power-on request, waiting for a response, and stopping the program if the response is not responded after the time is out;
enabling the system on chip to enter a reset programming mode, downloading a programming algorithm to an SRAM and initializing;
reading 1024 bytes of data from the upgrade file in a circulating manner, programming the data to FLASH by using pages, and filling and aligning the data of the last page, wherein the size of the data of the last page is smaller than 1024 by using 0;
reading data from the first page and the last page of the FLASH programming according to the file size, and comparing the data with the upgrading file data, wherein if the data are the same, the upgrading is successful;
and resetting the system on the chip in a soft mode, and releasing the SWD interface.
The invention is characterized in that:
1. the method of off-line downloading may be determined by checking if an offline.
2. The off-line downloading method comprises the following steps: a. and (4) selecting a fixed upgrade file by a key to burn the upgrade file into the address 0x08000000 of the FLASH of the system on chip. b. Cfg through the upgrade rule file in the offline.
3. The format of the upgrade rule command is: < opt > < file name > < addr > [ size ], where opt is the operation performed, 'w' denotes writing FLASH, 'r' denotes reading FLASH, 'file name' denotes the file name of the upgrade file, or the file name of the read content save, 'addr' denotes the FLASH address to be written or read, 'size' is optional, and is valid only when the operation is read, which denotes how many bytes of data need to be read.
4. And a green LED lamp is used for indicating the success or failure of the upgrade, the green lamp flickers in the upgrade process, the green lamp is always on when the upgrade is successful, and the green lamp is always off when the upgrade is failed.
5. And a red LED lamp is used for indicating the upgraded error information, the red lamp is normally turned off when no error exists, and the red lamp is firstly turned on for one second when an error exists, and then flickers for a plurality of times at the speed of 200 milliseconds according to the error code. For example, when the error code is 3, the red light is first lit for one second and then blinks for 3 times, i.e. 1 long code plus 3 short codes.
6. With several error notification codes as follows:
(1) SWD connection failure
(2) Failure to erase the chip
(3) The length of the error FLASH address or file name is more than 15
(4) Cannot open the upgrade file
(5) Check failure
7. Connecting SWD with system on chip, downloading and upgrading, and reading and writing TF card by FATFS file system
8. Different data can be written into different FLASH addresses according to the upgrading rule, and the data in different FLASH addresses can be read out and stored in the TF card.
The application has the following effects: compared with the traditional online upgrading technology, the method can get rid of dependence on huge PC computers, so that the upgrading platform is easier to deploy when manufacturers produce in batches. The requirements on computer knowledge and professional knowledge of users are reduced, software upgrading of different platforms becomes simple and easy to operate, and the upgrading file can be written by one key by pressing a start key. The upgrading system can complete the deployment of the upgrading platform by using 5V power supply and several wire harnesses, so that the upgrading environment is safer and more reliable. The problem that software upgrading for the system on chip fails due to reasons such as inconsistency of windows versions of PCs or failure of driver installation is solved, software upgrading of the system on chip is the same as copying of an upgrading file to a USB flash disk, and developers just contacting the system on chip can concentrate on software development. Different FLASH addresses can be written according to the upgrading rule, so that the method and the device can be used for writing bootloaders, apps, encrypted data, product information and the like.
As shown in fig. 3, the system for downloading software upgrade offline in the present application includes: an offline upgrade system to: periodically detecting whether the first interface is inserted into the memory card; when detecting that the first interface is inserted into the memory card, executing the subsequent steps; controlling a green light connected with an offline upgrading system to light up; and opening an off-line upgrading configuration file in the memory card, entering an automatic upgrading mode if the opening is successful, loading the file in the memory card if the opening is failed, and entering a key selection upgrading mode.
The first interface is an SPI interface, and the storage card is a TF card. The off-line upgrading system is connected with the matrix keyboard and the functional keys through GPIO interfaces, the off-line upgrading system is connected with the LED and the seven-segment digital tube through the GPIO interfaces, and the off-line upgrading system is connected with the target platform through an SWD interface.
The offline upgrade system is used for: opening the file in the memory card by using the appointed file names in sequence, adding the current file name into the list whenever the return is successful, and finishing the loading of the file when the return is failed; the loaded files are stored in a list according to the sequence of the dictionary order, the input command is received through a key, and a seven-segment digital tube connected with an offline upgrading system is displayed in a flashing mode to show that the files are being selected; receiving a command of selecting a file through a confirming key, displaying the seven-segment digital tube in a normally-on mode to indicate that the file is selected, and displaying the numerical value of the seven-segment digital tube to indicate the number of the files in the list; the method comprises the steps that a command for starting upgrading is received through a starting key, an offline upgrading system is connected with a target platform through an SWD interface, after the command for starting upgrading is received, a file is written into a fixed 0x08000000 position, a green LED flashes quickly in the upgrading process, the upgrading is stopped when an error occurs in the process, the target platform is reset, and the red LED is used for indicating according to an error code.
In the present application, the system embodiment of the offline download software upgrade is basically similar to the method embodiment of the offline download software upgrade, and reference is made to the description of the method embodiment of the offline download software upgrade for relevant points.
It is clear to a person skilled in the art that the solution according to the embodiments of the invention can be implemented by means of software and/or hardware. The "unit" and "module" in this specification refer to software and/or hardware that can perform a specific function independently or in cooperation with other components, where the hardware may be, for example, an FPGA (Field-Programmable Gate Array), an IC (Integrated Circuit), or the like.
Each processing unit and/or module according to the embodiments of the present invention may be implemented by an analog circuit that implements the functions described in the embodiments of the present invention, or may be implemented by software that executes the functions described in the embodiments of the present invention.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described device embodiments are merely illustrative, for example, the division of the unit is only a logical functional division, and there may be other division ways in actual implementation, such as: multiple units or components may be combined, or may be integrated into another system, or some features may be omitted, or not implemented. In addition, the coupling, direct coupling or communication connection between the components shown or discussed may be through some interfaces, and the indirect coupling or communication connection between the devices or units may be electrical, mechanical or other forms.
All functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as one unit, or two or more units may be integrated into one unit; the integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.