Method and chip for downloading firmware

By reusing IO ports on the chip, automatic selection of SWD and ISP download modes is realized, which solves the problem of IO resource waste in the existing technology and improves the resource utilization of the MCU platform.

CN111758088BActive Publication Date: 2024-10-01SHENZHEN GOODIX TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202080001498.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-02-07
Publication Date
2024-10-01
Estimated Expiration
2040-02-07

AI Technical Summary

Technical Problem

When existing chips support serial port download and emulator download modes, they need to reserve multiple IO ports, resulting in a waste of IO resources, especially on MCU platforms where IO resources are precious.

Method used

By designing the chip to use only two IO ports, the SWCLK and SWDIO interfaces in SWD download mode can be reused as the RX and TX interfaces in ISP download mode, or vice versa, to automatically select serial port download mode or emulator download mode to avoid IO resources waste.

Benefits of technology

It achieves the compatibility of serial port download and emulator download mode without adding IO ports, saves the IO resources of the chip, and improves the resource utilization of the MCU platform.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111758088B_ABST
    Figure CN111758088B_ABST
Patent Text Reader

Abstract

The embodiment of the present application relates to a method and a chip for downloading firmware from a chip, the chip comprising two IO interfaces, the two IO interfaces being configured to support a serial port download mode and an emulator download mode, the method comprising: determining whether the chip is connected to the communication device via an emulator, the emulator being used for the emulator download mode; and determining whether to adopt the serial port download mode or the emulator download mode to download the firmware of the application from the communication device according to whether the chip is connected to the communication device via the emulator. The method and the chip for downloading firmware from a chip in the embodiment of the present application can save the number of IO interfaces in the chip and avoid waste.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of chips, and in particular to a method and a chip for downloading firmware to a chip. Background Art

[0002] There are two basic ways to download firmware via wired connection for microcontroller units (MCUs). One is to download via a serial port, such as in-system programming (ISP) download; the other is to download via an emulator, and the commonly used interfaces for emulator downloads include the Serial Wire Debug (SWD) interface. Both methods require the MCU to reserve two input / output (In / Out, IO) ports.

[0003] That is to say, if developers want to support the above two burning methods in their products, they must sacrifice 5 IO ports, of which 2 IO ports are the serial clock (Serial Wire clock, SWCLK) interface and serial data IO (Serial Wire data IO, SWDIO) interface of SWD download mode; 2 IO ports are the receive (receive, RX) interface and transmit (transport, TX) interface of ISP mode, and another IO interface is used to select between different download modes. On the MCU platform where IO resources are very precious, this method is very wasteful of IO resources. Summary of the invention

[0004] The present application provides a method and a chip for downloading firmware on a chip, which can save the number of IO interfaces in the chip and avoid waste.

[0005] In a first aspect, a method for downloading firmware from a chip is provided, wherein the chip comprises two IO interfaces, and the two IO interfaces are configured to support a serial port download mode and an emulator download mode. The method comprises: determining whether the chip is connected to the communication device via an emulator, the emulator being used for the emulator download mode; and determining whether to adopt the serial port download mode or the emulator download mode to download the firmware of the application from the communication device according to whether the chip is connected to the communication device via the emulator.

[0006] Therefore, in the method for downloading firmware on a chip of an embodiment of the present application, two IO ports are set on the chip, and the SWD download mode and the ISP download mode can reuse these two IO ports. In other words, the two IO ports SWCLK and SWDIO that are implemented in the SWD download mode in the chip design can be reused as the two interfaces RX and TX in the ISP download mode, so that the chip can automatically select the serial port download mode or the emulator download mode when downloading firmware, that is, the chip can support both the serial port download mode and the emulator download mode through only two IO ports.

[0007] In combination with the first aspect, in an implementation method of the first aspect, determining whether to adopt the serial port download mode or the emulator download mode to download the firmware of the application from the communication device based on whether the chip is connected to the communication device through the emulator includes: if the chip is connected to the communication device through the emulator, determining to adopt the emulator download mode to download the firmware from the communication device.

[0008] In combination with the first aspect and its above-mentioned implementation method, in another implementation method of the first aspect, the use of the emulator download mode to download the firmware from the communication device includes: detecting the startup information of the application; if the detected startup information is erroneous, downloading the firmware from the communication device through the emulator.

[0009] In combination with the first aspect and the above-mentioned implementation method, in another implementation method of the first aspect, the method also includes: if the chip is connected to the communication device through the emulator, the two IO interfaces of the chip are respectively set to the IO interfaces corresponding to the emulator download mode.

[0010] In combination with the first aspect and its above-mentioned implementation method, in another implementation method of the first aspect, the determination of using the serial port download mode or the emulator download mode to download the firmware of the application from the communication device is based on whether the chip is connected to the communication device through the emulator, including: if the chip is not connected to the communication device through the emulator, determining to use the serial port download mode to download the firmware from the communication device.

[0011] In combination with the first aspect and the above-mentioned implementation method, in another implementation method of the first aspect, the use of the serial port download mode to download the firmware from the communication device includes: if a target command sent by the communication device is received, according to the target command, using the serial port download mode to download the firmware from the communication device, wherein the target command is used to indicate the serial port download mode.

[0012] In combination with the first aspect and the above-mentioned implementation method, in another implementation method of the first aspect, the use of the serial port download mode to download the firmware from the communication device includes: if the target command sent by the communication device is not received, detecting the startup information of the application, wherein the target command is used to indicate the serial port download mode; if the detected startup information is erroneous, using the serial port download mode to download the firmware from the communication device.

[0013] In combination with the first aspect and the above-mentioned implementation manner, in another implementation manner of the first aspect, the method further includes: if the chip is not connected to the communication device through the emulator, starting a timer; before the timer times out, determining whether the target command is received.

[0014] In combination with the first aspect and the above-mentioned implementation method, in another implementation method of the first aspect, before adopting the serial port download mode to download the firmware from the communication device, the method also includes: setting the two IO interfaces of the chip to the IO interfaces corresponding to the serial port download mode respectively.

[0015] In combination with the first aspect and the above implementation manner, in another implementation manner of the first aspect, the method is applied after the chip is reset.

[0016] In combination with the first aspect and its above-mentioned implementation manner, in another implementation manner of the first aspect, the chip includes a reset pin, and if the reset pin receives a low level output by the receive flow control RTS pin in the serial port board controlled by the communication device, the chip is reset; and / or, if the reset pin receives a reset signal output by the reset pin of the emulator controlled by the communication device, the chip is reset.

[0017] In combination with the first aspect and the above-mentioned implementation manner, in another implementation manner of the first aspect, the serial port download mode is an online system programming (ISP) download mode, and the emulator download mode is a serial debugging (SWD) download mode.

[0018] In combination with the first aspect and the above-mentioned implementation manner, in another implementation manner of the first aspect, the IO interface corresponding to the ISP download mode includes a receiving RX interface and a sending TX interface.

[0019] In combination with the first aspect and the above implementation manner, in another implementation manner of the first aspect, the IO interface corresponding to the SWD download mode includes a serial data input and output SWDIO interface and a serial clock SWCLK interface.

[0020] In a second aspect, a chip is provided, which is used to execute the method in the first aspect or any possible implementation of the first aspect. Specifically, the chip includes a unit for executing the method in the first aspect or any possible implementation of the first aspect.

[0021] In a third aspect, a chip is provided, comprising: a storage unit and a processor, the storage unit being used to store instructions, the processor being used to execute the instructions stored in the memory, and when the processor executes the instructions stored in the memory, the execution causes the processor to execute the method in the first aspect or any possible implementation of the first aspect.

[0022] According to a fourth aspect, a computer-readable medium is provided for storing a computer program, wherein the computer program comprises instructions for executing the method in the first aspect or any possible implementation of the first aspect.

[0023] In a fifth aspect, a computer program product including instructions is provided, and when a computer runs the instructions of the computer program product, the computer executes the method for downloading firmware to a chip in the first aspect or any possible implementation of the first aspect. Specifically, the computer program product can be run on the chip of the second aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 It is a schematic flowchart of a method for chip downloading firmware according to an embodiment of the present application.

[0025] Figure 2 is a schematic block diagram of a chip according to an embodiment of the present application.

[0026] Figure 3 is another schematic block diagram of a chip according to an embodiment of the present application.

[0027] Figure 4 is another schematic flow chart of a method for downloading firmware to a chip according to an embodiment of the present application.

[0028] Figure 5 It is a schematic diagram of the connection relationship between the chip and the communication device according to an embodiment of the present application.

[0029] Figure 6 It is a partial flow chart of the method for chip downloading firmware according to an embodiment of the present application.

[0030] Figure 7 This is another partial flow chart of the method for downloading firmware on a chip according to an embodiment of the present application.

[0031] Figure 8 It is a schematic flowchart of a communication device downloading firmware for a chip according to an embodiment of the present application.

[0032] Fig. 9 is another schematic block diagram of a chip according to an embodiment of the present application. DETAILED DESCRIPTION

[0033] The technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0034] Figure 1 FIG. 1 is a schematic flow chart of a method 100 for downloading firmware to a chip according to an embodiment of the present application. The method 100 can be applied to a chip, for example, the chip can be Figure 2 Specifically, the chip 200 includes two IO interfaces, namely Figure 2 The first interface 210 and the second interface 220 shown in the figure, the chip 200 supports the serial port download mode and the emulator download mode, or the two IO interfaces of the chip 200 are configured to support the serial port download mode and the emulator download mode. For example, the chip 200 can be an MCU chip, or it can also be other types of chips, and the chip can be used in various devices, such as various terminal devices such as headphones, mobile phones, and smart door locks, which is not limited in this embodiment.

[0035] like Figure 1 As shown, the method 100 includes: S110, determining whether the chip is connected to the communication device through an emulator, and the emulator is used for the emulator download mode; S120, according to whether the chip is connected to the communication device through the emulator, determining whether to use the serial port download mode or the emulator download mode to download the firmware of the application from the communication device.

[0036] It should be understood that the serial port download mode in the embodiment of the present application may refer to any serial port download mode. For example, the present application mainly describes the serial port download mode as the ISP download mode, but the embodiment of the present application is not limited to this. In addition, the ISP download mode requires software implementation. For example, if the chip supports the ISP download mode, the chip can be integrated with a corresponding ISP download program and a matching tool end. The IO interface corresponding to the ISP download mode includes an RX interface and a TX interface.

[0037] The simulator download mode in the embodiment of the present application may refer to any simulator download mode. For example, the present application mainly describes the simulator as a Jlink simulator and the simulator download mode as a SWD download mode, but the embodiment of the present application is not limited to this. In addition, the SWD download mode adopts a standard download protocol, which generally does not require software implementation. As long as the chip supports the SWD download mode, it can be downloaded normally using the Jlink download tool. The IO interface corresponding to the SWD download mode includes a SWDIO interface and a SWCLK interface.

[0038] Therefore, in the method for downloading firmware on a chip of an embodiment of the present application, two IO ports are set on the chip, and the SWD download mode and the ISP download mode can reuse the two IO ports. In other words, the two IO ports SWCLK and SWDIO that are implemented in the SWD download mode in the chip design can be reused into the two interfaces RX and TX in the ISP download mode. It can also be said that the two interfaces RX and TX in the ISP download mode in the chip can be reused into the two IOs SWCLK and SWDIO that are implemented in the SWD download mode, so that the chip can support both the serial port download mode and the emulator download mode through only two IO ports.

[0039] Figure 4 A schematic flow chart of another chip download firmware method 300 according to an embodiment of the present application is shown. The method 300 is a possible implementation of the method 100. Figure 4 The illustrated method 300 describes the method 100 in detail.

[0040] It should be understood that the method 100 of the embodiment of the present application can be applied to download firmware for a chip. For example, if there is no firmware corresponding to a certain application in the chip, or the chip fails to start a certain application, the chip may need to download the firmware, and the method 100 of the embodiment of the present application can be executed. In addition, the method 100 of the embodiment of the present application can occur after the chip is reset, that is, after the chip is reset, the boot program is entered to start downloading the firmware, that is, to start executing the method 100. For example, Figure 4 As shown, the method 300 may include: S301, the boot program starts, that is, the chip enters the boot program for downloading firmware. For example, the boot program may be entered after the chip is reset.

[0041] Specifically, when the chip needs to download firmware of one or more applications from the communication device, or when the communication device needs to download firmware of one or more applications to the chip, the chip is reset, for example, the chip can be reset by controlling the communication device. Figure 3 As shown, Figure 2 The chip 200 shown may also include Figure 3 The reset pin 230 is shown, and the reset pin 230 is used to reset the chip 200 .

[0042] It should be understood that the communication device in the embodiments of the present application may refer to a personal computer or a personal computer (PC), or may also refer to other devices capable of downloading firmware for a chip. Among them, there are many types of personal computers, such as traditional desktop computers, laptops, tablet computers, all-in-one computers, ultrabooks, handheld computers, embedded computers, etc.

[0043] Optionally, the communication device can control the chip to reset in a variety of ways. For example, assuming that the communication device and the chip use the ISP download mode to download the firmware, the communication device can control the Request To Send (RTS) pin in the serial board to output a low level, so that the reset pin in the chip triggers the chip reset. Specifically, Figure 5 A schematic diagram showing the connection between the MCU and the PC in the embodiment of the present application is shown in FIG. Figure 5 As shown, it is assumed here that the chip of the embodiment of the present application is an MCU, the communication device is a PC, and the MCU is connected to the PC through a serial port board. The PC may also include an ISP tool, which is used in the ISP download mode of the MCU, and the PC may be connected to the serial port board through a USB interface. The serial port board may include an RTS interface, and the reset pin of the MCU is connected to the RTS interface of the serial port board. When the PC controls the RTS interface of the serial port board to output a low level through the USB interface, the reset pin of the MCU detects that the RTS interface of the serial port board outputs a low level, so that the MCU is reset, thereby entering a boot program to start downloading firmware, that is, start executing method 100.

[0044] For another example, assuming that the SWD download mode is adopted between the communication device and the chip to download the firmware, the communication device can reset the chip by controlling the reset signal output by the reset pin of the emulator. Specifically, it is also assumed that the chip of the embodiment of the present application is an MCU, the communication device is a PC, and the PC is connected to the MCU through the emulator. The emulator includes a reset pin, and the reset pin of the emulator is connected to the reset pin of the MCU. When the reset pin of the PC control emulator outputs a reset signal, the reset pin of the MCU can receive the reset signal so that the MCU is reset, thereby entering the boot program to start downloading the firmware, that is, start executing method 100.

[0045] Optionally, the boot program entered by the chip in the embodiment of the present application may be a cold boot program. Specifically, since firmware download is usually performed in a cold boot program, and firmware download is not performed in a warm boot program, method 100 may also be applied to a cold boot program. Figure 4As shown, the method 300 may further include: S302, whether it is a cold boot, that is, determining whether the program started by the chip is a cold boot, if not, then continue to execute S303, if yes, then continue to execute S304. Figure 4 As shown, S303 performs a hot boot, that is, when the boot program started by the chip is not a cold boot, for example, warm boot is started, then the warm boot program is executed, and the firmware download will not be performed. However, the embodiment of the present application is not limited to this. For example, steps S302 and S303 may not be performed, and S304 may be performed directly from S301. At this time, both the cold boot program and the warm boot program can perform firmware download. However, the method of performing firmware download in the cold boot program saves more power consumption.

[0046] Optionally, the method 100 of the embodiment of the present application may not be applied after the chip is reset, that is, the chip may also start to execute the method 100 in other situations to start downloading firmware. For example, if the communication device and the chip use the ISP download mode to download the firmware, the method 100 is usually executed after the chip is reset to start downloading the firmware; if the communication device and the chip use the SWD download mode to download the firmware, then in addition to executing the method 100 after the chip is reset, the method 100 can also be executed in any situation where the chip is not reset to download the firmware.

[0047] Corresponding to S110 in method 100, as Figure 4 As shown, the method 300 may include: S304, whether to connect the emulator, for example, the emulator may be Jlink, that is, determining whether the chip is connected to the communication device through the Jlink emulator, so as to determine whether to use the serial port download mode or the emulator download mode to download the firmware of the application from the communication device according to whether the chip is connected to the communication device through the Jlink emulator.

[0048] Optionally, if the chip is connected to the communication device through the emulator, it is possible to continue to determine whether to use the emulator download mode for firmware download, for example, to continue to execute S305 to download the firmware from the communication device; if the chip is not connected to the communication device through the emulator, it is possible to continue to determine whether to use other download modes for download estimation, for example, to continue to execute S308.

[0049] Specifically, if the chip is connected to the communication device through the emulator, the startup information of the application program may be detected first, for example, Figure 4As shown, the method 300 includes: S305, detecting boot information (boot info). If the detected boot information is correct, continue to execute S306; if it is wrong, continue to execute S307.

[0050] Optionally, if the detected startup information is correct, the corresponding application is started, for example, Figure 4 As shown, the method 300 includes: S306, starting the application program. That is, the chip has already downloaded the firmware of the application program, so the chip can start the corresponding application program without downloading the firmware again, and repeated downloading of the firmware can also be avoided.

[0051] On the contrary, if the detected startup information is wrong, then the emulator download mode can be used to download the firmware from the communication device, for example, Figure 4 As shown, the method 300 includes: S307, using the SWD download mode. Since the chip and the communication device are connected via an emulator, the emulator download mode can be used to download the firmware.

[0052] Optionally, after step S304, if the chip has been connected to the communication device through the emulator, in addition to executing the above steps S305-S307, other processing methods may be used. Figure 6 As shown, for step S304, when it is determined that the chip has been connected to the communication device through the emulator, the application can be directly started. If the application can be successfully started, it means that the firmware of the application has been downloaded in the chip, so the chip can start the corresponding application without downloading the firmware. However, if the application cannot be successfully started, or the startup fails, then the firmware download can be performed, and since the chip is connected to the communication device through the emulator, the emulator download mode can be used for firmware download. For another example, after executing S304, if the chip has been connected to the communication device through the emulator, the emulator download mode can be directly used for firmware download.

[0053] It should be understood that no matter which of the above situations, if the chip determines to use the emulator download mode for firmware download, the two IO interfaces of the chip can be set as the IO interfaces corresponding to the emulator download mode respectively. Figure 2The first interface 210 and the second interface 220 of the chip 200 shown are set to the SWDIO interface and the SWCLK interface corresponding to the SWD download mode. Specifically, setting the two IO interfaces of the chip to the SWDIO interface and the SWCLK interface corresponding to the SWD download mode includes: setting the relevant parameters of the interface, etc. For example, if the two IO interfaces of the chip are currently set to the IO interfaces corresponding to the emulator download mode, then the emulator download mode can be directly executed through the two IO interfaces; but if the two IO interfaces of the chip are currently the IO interfaces corresponding to the serial port download mode, then the two interfaces need to be switched to the IO interfaces corresponding to the emulator download mode, and then the emulator download mode is executed through the two IO interfaces.

[0054] Optionally, if the chip is not connected to the communication device through the emulator, that is, the emulator download mode may not be used between the chip and the communication device, then other download modes may be used for estimated downloading, for example, the serial port mode may also be used for firmware downloading. Specifically, when the chip is not connected to the communication device through the emulator, it may be directly determined to use the serial port download mode for firmware downloading; or, it may also be determined whether to use the serial port download mode for firmware downloading based on whether a special command sent by the communication device is received, wherein the special command is referred to as a target command in the embodiment of the present application, and the target command is used to indicate the serial port download mode, for example, the target command may be used to indicate the ISP download mode.

[0055] Specifically, if a target command sent by a communication device is received, the serial port download mode is adopted to download the firmware from the communication device according to the target command; conversely, if the target command sent by the communication device is not received, it can be determined whether to adopt the serial port download mode to download the firmware from the communication device by detecting the startup information of the application.

[0056] Optionally, it can be determined whether the target command is received according to a preset time length. Figure 4 As shown, the method 300 includes: S308, starting the timer, that is, starting the timer when the chip and the communication device are not connected through the emulator; S309, whether the target command is received, that is, determining whether the target command is received before the timer times out, if received, continue to execute S310, if not received, continue to execute S311.

[0057] It should be understood that the duration of the timer can be set according to the actual application and can be set to any value. Specifically, if the communication device and the chip need to download firmware through the ISP download mode, then Figure 5As shown, when the communication device outputs a low level through the RTS interface of the serial port board, it will also send a target command to the MUC chip. For example, the communication device can continue to send the target command at a certain period to instruct the MCU to use the ISP download mode for firmware download. Then the duration of the timer should be greater than or equal to the period value. For example, the communication device can set the target command sending period to 10ms, then correspondingly, the timer duration is greater than 10ms, for example, it can be set to 200ms, but the embodiments of the present application are not limited to this.

[0058] like Figure 4 As shown, the method 300 includes: S310, using the ISP download mode, that is, if the target command is received before the timer times out, the chip determines that the serial port download mode can be used to download the firmware from the communication device.

[0059] On the contrary, Figure 4 As shown, the method 300 includes: S311, detecting boot information (boot info). If the detected boot information is correct, continue to execute S312; if it is wrong, continue to execute S313.

[0060] Optionally, if the detected startup information is correct, the corresponding application is started, for example, Figure 4 As shown, the method 300 includes: S312, starting the application, that is, the chip has already downloaded the firmware of the application, so the chip can start the corresponding application without downloading the firmware again, thus avoiding repeated downloading of the firmware.

[0061] On the contrary, if the detected startup information is wrong, then the serial port download mode can be used to download the firmware from the communication device, for example, Figure 4 As shown, the method 300 includes: S313, using the ISP download mode, even if the target command is not received, the ISP download mode can still be used to download the firmware.

[0062] Optionally, after S311, in the case of detecting a startup information error, in addition to executing the firmware download using the ISP download mode as described in S313, other processing methods may be used. For example, considering that the target command is not received at this time, it may be impossible to use the ISP download mode to download the firmware. In the case of detecting a startup information error, the firmware download may also be unable to be executed. In this case, it can be considered that the firmware download has failed, that is, the firmware download process is terminated.

[0063] Optionally, after step S309, if the chip does not receive the target command before the timer times out, in addition to executing the above steps S311-S313, other processing methods may be used. Figure 7As shown, for step S309, before the timer times out, if the target command is not received, the application can be started directly. If the application can be successfully started, it means that the firmware of the application has been downloaded to the chip, so the chip can start the corresponding application without downloading the firmware. However, if the application cannot be successfully started, or the startup fails, the ISP download mode can be used to perform firmware download. At this time, the timer does not receive the target command, but the ISP download mode can still be used to download the firmware.

[0064] It should be understood that no matter which of the above situations, if the chip determines to use the serial port download mode for firmware download, the two IO interfaces of the chip can be set as IO interfaces corresponding to the serial port download mode respectively. Figure 2 The first interface 210 and the second interface 220 of the chip 200 shown are set as the TX interface and the RX interface corresponding to the ISP download mode. Specifically, setting the two IO interfaces of the chip as the TX interface and the RX interface corresponding to the ISP download mode may include: if the current first interface 210 and the second interface 220 are the SWDIO interface and the SWCLK interface corresponding to the SWD download mode, then the SWDIO interface and the SWCLK interface originally set to the SWD download mode need to be switched to the TX interface and the RX interface corresponding to the ISP download mode, and this switching may include: switching to the relevant parameters of the TX interface and the RX interface in the ISP download mode, etc.; on the contrary, if the current first interface 210 and the second interface 220 are the TX interface and the RX interface corresponding to the ISP download mode, then there is no need to switch, and the TX interface and the RX interface corresponding to the ISP download mode are directly used to perform the firmware download in the ISP download mode.

[0065] Optionally, the method 100 may further include: when it is determined that the ISP download mode is not adopted, or after the firmware download is completed in the ISP download mode, the two IO interfaces of the chip may be switched to the SWDIO interface and SWCLK interface corresponding to the SWD download mode.

[0066] Therefore, in the method for downloading firmware on a chip of an embodiment of the present application, two IO ports are set on the chip, and the SWD download mode and the ISP download mode can reuse these two IO ports. In other words, the two IO ports SWCLK and SWDIO that are implemented in the SWD download mode in the chip design can be reused as the two interfaces RX and TX in the ISP download mode, so that the chip can automatically select the serial port download mode or the emulator download mode when downloading firmware, that is, the chip can support both the serial port download mode and the emulator download mode through only two IO ports.

[0067] Combined with the above Figures 1 to 7 The method for downloading firmware from a chip according to an embodiment of the present application is described in detail from the perspective of the chip. Figure 8 , describes the method of chip downloading firmware according to an embodiment of the present application from the perspective of a communication device.

[0068] Figure 8 FIG. 4 is a schematic flow chart showing a method 400 for a communication device to download firmware to a chip according to an embodiment of the present application. Figure 8 As shown, here, a communication device adopts the ISP download mode to download firmware for a chip as an example for description, but the embodiments of the present application are not limited to this.

[0069] It should be understood that the communication device in the method 400 may include an ISP tool. For example, the communication device may be Figure 5 The PC shown includes an ISP tool that can be used to download firmware to the chip via ISP.

[0070] like Figure 8 As shown, the method 400 includes: S401, determining to use ISP to download firmware, that is, the ISP tool in the communication device determines to download firmware, downloads firmware of a certain application for the chip, and continues to execute S402.

[0071] like Figure 8 As shown, the method 400 includes: S402, RTS outputs a low level, that is, the communication device controls the RTS interface of the serial port board connected thereto to output a low level, for example, the communication device is a PC, the PC can be connected to the serial port board via USB, and controls the RTS interface of the serial port board to output a low level. In this way, when the reset pin connected to the RTS interface of the serial port board in the chip detects a low level, it will trigger the chip to reset, that is, the chip will start the boot program, for example, the chip can be used to execute the above method 100 or the above method 300.

[0072] like Figure 8 As shown, the method 400 includes: S403, sending a target command indicating the ISP download mode, that is, the communication device can send a target command to the chip after the control chip is reset, and the target command is used to indicate the ISP download mode, so that after the chip receives the target command, it selects the ISP download mode for firmware download.

[0073] Optionally, the communication device may send the target command multiple times, for example, the communication device may send the target command cyclically at a certain period, wherein the period may be set according to actual application, for example, may be set to 10 ms, but the embodiments of the present application are not limited thereto.

[0074] like Figure 8As shown, the method 400 includes: S404, whether a response to the target command is received, after sending the target command once or multiple times, the communication device waits for the chip to send a response to the target command, for example, waiting for the chip to send a command in response to the target command, to determine whether the response is received. If the communication device receives the response, continue to execute S406, if no response is received, it corresponds to S405.

[0075] Optionally, a timer can be set to determine whether a response to the target command is received before the timer times out. For example, the timer can be turned on when the target command is sent, or the timer can be turned on after sending the target command once or multiple times, or the timer can be turned on at a suitable time according to the actual application. If no response is received before the timer times out, it is determined that no response is received, and S405 is continued; if a response is received before the timer times out, the timer can be stopped and S406 is continued. Among them, the duration of the timer can be set to any value according to the actual application, and the embodiments of the present application are not limited to this.

[0076] like Figure 8 As shown, the method 400 includes: S405, download fails. If the communication device does not receive a response to the target command sent by the chip, it is determined that the firmware download has failed.

[0077] like Figure 8 As shown, the method 400 includes: S406, sending firmware. If the communication device receives a response to the target command, the chip and the communication device need to use the ISP download mode to download the firmware. The communication device needs to send the firmware to the chip to complete the firmware download, which corresponds to S407.

[0078] like Figure 8 As shown, the method 400 includes: S407, downloading is successful, that is, the communication device successfully downloads the firmware for the chip, and the firmware download is completed.

[0079] It should be understood that the method 400 uses the communication device to select the ISP download mode to download the firmware for the chip. Similarly, if the communication device selects the SWD download mode to download the firmware for the chip, a similar method can also be used. For the sake of brevity, it will not be repeated here. For example, if the communication device and the chip download the firmware via SWD, the communication device and the chip are connected via an emulator, and the communication device can control the chip reset via the reset pin of the emulator. The chip resets to enter the boot program. When the chip is connected to the communication device via the emulator, according to the above methods 100 and 300, it can be seen that the chip will automatically select the SWD download mode to download the firmware.

[0080] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0081] Combined with the above Figures 1 to 8 , describes in detail the method for downloading firmware on a chip according to an embodiment of the present application, and will now be combined with Fig. 9 , describing a chip according to an embodiment of the present application.

[0082] like Fig. 9 As shown, the chip 500 according to the embodiment of the present application includes: a processing unit 510 and two IO interfaces 520, wherein the two IO interfaces 520 are configured to support a serial port download mode and an emulator download mode; the processing unit 510 is used to: determine whether the chip 500 is connected to the communication device through an emulator, and the emulator is used for the emulator download mode; according to whether the chip 500 is connected to the communication device through the emulator, determine whether to use the serial port download mode or the emulator download mode to download the firmware of the application from the communication device.

[0083] Optionally, the processing unit 510 may also be referred to as a processor.

[0084] Optionally, as an embodiment, the processing unit 510 is used to: if the chip 500 is connected to the communication device through the emulator, determine to adopt the emulator download mode to download the firmware from the communication device.

[0085] Optionally, as an embodiment, the processing unit 510 is used to: detect startup information of the application; if the detected startup information is wrong, download the firmware from the communication device through the emulator.

[0086] Optionally, as an embodiment, the processing unit 510 is used for: if the chip 500 is connected to the communication device through the emulator, configuring the two IO interfaces 520 of the chip 500 as IO interfaces corresponding to the emulator download mode.

[0087] Optionally, as an embodiment, the processing unit 510 is used to: if the chip 500 is not connected to the communication device through the emulator, determine to adopt the serial port download mode to download the firmware from the communication device.

[0088] Optionally, as an embodiment, the processing unit 510 is used for: if a target command sent by the communication device is received, according to the target command, adopting the serial port download mode to download the firmware from the communication device, wherein the target command is used to indicate the serial port download mode.

[0089] Optionally, as an embodiment, the processing unit 510 is used to: if the target command sent by the communication device is not received, detect the startup information of the application, wherein the target command is used to indicate the serial port download mode; if the detected startup information is erroneous, adopt the serial port download mode to download the firmware from the communication device.

[0090] Optionally, as an embodiment, the processing unit 510 is further used to: if the chip 500 is not connected to the communication device through the emulator, start a timer; and before the timer times out, determine whether the target command is received.

[0091] Optionally, as an embodiment, before the processing unit 510 adopts the serial port download mode to download the firmware from the communication device, the processing unit 510 is used to: configure the two IO interfaces 520 of the chip 500 as IO interfaces corresponding to the serial port download mode.

[0092] Optionally, as an embodiment, the processing unit 510 downloads the firmware after the chip 500 is reset.

[0093] Optionally, as an embodiment, the chip 500 also includes a reset pin 530. If the reset pin 530 receives a low level output by the receive flow control RTS pin in the serial port board controlled by the communication device, the chip 500 is reset; and / or, if the reset pin 530 receives a reset signal output by the reset pin of the emulator controlled by the communication device, the chip 500 is reset.

[0094] Optionally, as an embodiment, the serial port download mode is an online system programming (ISP) download mode, and the emulator download mode is a serial debugging (SWD) download mode.

[0095] Optionally, as an embodiment, the IO interface corresponding to the ISP download mode includes a receiving RX interface and a sending TX interface.

[0096] Optionally, as an embodiment, the IO interface corresponding to the SWD download mode includes a serial data input and output SWDIO interface and a serial clock SWCLK interface.

[0097] It should be understood that the chip 500 according to the embodiment of the present application may be corresponding to the method 100 and the method 300 in the embodiment of the present application. For example, the chip 500 may be as follows: Figure 2 The above and other operations and / or functions of the various units in the chip 200 and the chip 500 are respectively implemented Figures 1 to 8 For the sake of brevity, the corresponding processes of the chip in each method are not repeated here.

[0098] Therefore, the chip of the embodiment of the present application is provided with two IO ports, and the SWD download mode and the ISP download mode can reuse these two IO ports. In other words, the two IO ports SWCLK and SWDIO that are implemented in the SWD download mode in the chip design can be reused as the two interfaces RX and TX in the ISP download mode, so that the chip can automatically select the serial port download mode or the emulator download mode when downloading the firmware, that is, the chip can support both the serial port download mode and the emulator download mode through only two IO ports.

[0099] Optionally, the chip in the embodiment of the present application may further include a memory. The processing unit may call and run a computer program from the memory to implement the method in the embodiment of the present application. The memory may be a separate device independent of the processing unit or may be integrated in the processing unit.

[0100] It should be understood that the processing unit or processor of the embodiment of the present application may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method embodiment can be completed by the hardware integrated logic circuit or software instructions in the processor. The above processor can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or the hardware and software modules in the decoding processor are combined and performed. The software module can be located in a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, and other mature storage media in the art. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.

[0101] It can be understood that the memory in the embodiments of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM bus random access memory (DR RAM). It should be noted that the memory of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0102] It should be understood that the above-mentioned memory is exemplary but not restrictive. For example, the memory in the embodiments of the present application may also be static random access memory (static RAM, SRAM), dynamic random access memory (dynamic RAM, DRAM), synchronous dynamic random access memory (synchronous DRAM, SDRAM), double data rate synchronous dynamic random access memory (double data rate SDRAM, DDR SDRAM), enhanced synchronous dynamic random access memory (enhanced SDRAM, ESDRAM), synchronous link dynamic random access memory (synch link DRAM, SLDRAM) and direct memory bus random access memory (Direct Rambus RAM, DR RAM), etc. That is to say, the memory in the embodiments of the present application is intended to include but not limited to these and any other suitable types of memory.

[0103] An embodiment of the present application also provides a computer-readable storage medium for storing a computer program.

[0104] Optionally, the computer-readable storage medium can be applied to the chip in the embodiments of the present application, and the computer program enables the computer to execute the corresponding processes implemented by the chip in the various methods of the embodiments of the present application. For the sake of brevity, they are not repeated here.

[0105] An embodiment of the present application also provides a computer program product, including computer program instructions.

[0106] Optionally, the computer program product can be applied to the chip in the embodiments of the present application, and the computer program instructions enable the computer to execute the corresponding processes implemented by the chip in the various methods of the embodiments of the present application. For the sake of brevity, they are not repeated here.

[0107] The embodiment of the present application also provides a computer program.

[0108] Optionally, the computer program can be applied to the chip in the embodiments of the present application. When the computer program runs on a computer, the computer executes the corresponding processes implemented by the chip in the various methods of the embodiments of the present application. For the sake of brevity, they are not described here.

[0109] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0110] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0111] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0112] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0113] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0114] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage media include: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks or optical disks.

[0115] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for downloading firmware to a chip, characterized in that: The chip includes two IO interfaces, and the two IO interfaces are configured to support a serial port download mode and an emulator download mode. The method includes: determining whether the chip is connected to a communication device via an emulator, the emulator being used in the emulator download mode; Determine whether to adopt the serial port download mode or the emulator download mode to download the firmware of the application from the communication device according to whether the chip is connected to the communication device through the emulator; If the chip is not connected to the communication device through the emulator, determine to adopt the serial port download mode to download the firmware from the communication device; If a target command sent by the communication device is received, download the firmware from the communication device in the serial port download mode according to the target command, wherein the target command is used to indicate the serial port download mode; The serial port download mode is an online system programming (ISP) download mode, and the emulator download mode is a serial debugging (SWD) download mode.

2. The method according to claim 1, characterized in that The step of determining whether to adopt the serial port download mode or the emulator download mode to download the firmware of the application from the communication device according to whether the chip is connected to the communication device through the emulator comprises: If the chip is connected to the communication device through the emulator, it is determined to adopt the emulator download mode to download the firmware from the communication device.

3. The method according to claim 2, characterized in that The adopting the simulator download mode to download the firmware from the communication device comprises: Detecting startup information of the application; If the detected startup information is wrong, the firmware is downloaded from the communication device through the emulator.

4. The method according to claim 3, characterized in that The method further comprises: If the chip is connected to the communication device through the emulator, the two IO interfaces of the chip are respectively set as IO interfaces corresponding to the download mode of the emulator.

5. The method according to claim 1, characterized in that The adopting the serial port download mode to download the firmware from the communication device includes: If the target command sent by the communication device is not received, detecting the startup information of the application, wherein the target command is used to indicate the serial port download mode; If the detected startup information is wrong, the serial port download mode is adopted to download the firmware from the communication device.

6. The method according to claim 5, characterized in that The method further comprises: If the chip is not connected to the communication device through the emulator, starting a timer; Before the timer times out, it is determined whether the target command is received.

7. The method according to any one of claims 1 to 5, characterized in that Before downloading the firmware from the communication device in the serial port download mode, the method further includes: The two IO interfaces of the chip are respectively set as IO interfaces corresponding to the serial port download mode.

8. The method according to any one of claims 1 to 5, characterized in that The method is applied after the chip is reset.

9. The method according to claim 8, characterized in that The chip includes a reset pin, If the reset pin receives a low level output by the receive flow control RTS pin in the serial port board controlled by the communication device, the chip is reset; and / or If the reset pin receives a reset signal output by the reset pin of the emulator controlled by the communication device, the chip is reset.

10. The method according to claim 1, characterized in that The IO interface corresponding to the ISP download mode includes a receiving RX interface and a sending TX interface.

11. The method according to claim 10, characterized in that The IO interface corresponding to the SWD download mode includes a serial data input and output SWDIO interface and a serial clock SWCLK interface.

12. A chip, characterized in that: The chip includes two IO interfaces and a processing unit. The two IO interfaces are configured to support serial port download mode and emulator download mode; The processing unit is used for: determining whether the chip is connected to a communication device via an emulator, the emulator being used in the emulator download mode; Determine whether to adopt the serial port download mode or the emulator download mode to download the firmware of the application from the communication device according to whether the chip is connected to the communication device through the emulator; If the chip is not connected to the communication device through the emulator, determine to adopt the serial port download mode to download the firmware from the communication device; If a target command sent by the communication device is received, download the firmware from the communication device in the serial port download mode according to the target command, wherein the target command is used to indicate the serial port download mode; The serial port download mode is an online system programming (ISP) download mode, and the emulator download mode is a serial debugging (SWD) download mode.

13. The chip according to claim 12, characterized in that: The processing unit is used for: If the chip is connected to the communication device through the emulator, it is determined to adopt the emulator download mode to download the firmware from the communication device.

14. The chip according to claim 13, characterized in that: The processing unit is used for: Detecting startup information of the application; If the detected startup information is wrong, the firmware is downloaded from the communication device through the emulator.

15. The chip according to claim 14, characterized in that: The processing unit is used for: If the chip is connected to the communication device through the emulator, the two IO interfaces of the chip are configured as IO interfaces corresponding to the emulator download mode.

16. The chip according to claim 12, characterized in that: The processing unit is used for: If the target command sent by the communication device is not received, detecting the startup information of the application, wherein the target command is used to indicate the serial port download mode; If the detected startup information is wrong, the serial port download mode is adopted to download the firmware from the communication device.

17. The chip according to claim 16, characterized in that: The processing unit is also used for: If the chip is not connected to the communication device through the emulator, starting a timer; Before the timer times out, it is determined whether the target command is received.

18. The chip according to any one of claims 12 to 16, characterized in that: Before the processing unit adopts the serial port download mode to download the firmware from the communication device, the processing unit is used to: The two IO interfaces of the chip are configured as IO interfaces corresponding to the serial port download mode.

19. The chip according to any one of claims 12 to 16, characterized in that: The processing unit downloads the firmware after the chip is reset.

20. The chip according to claim 19, characterized in that The chip also includes a reset pin, If the reset pin receives a low level output by the receive flow control RTS pin in the serial port board controlled by the communication device, the chip is reset; and / or If the reset pin receives a reset signal output by the reset pin of the emulator controlled by the communication device, the chip is reset.

21. The chip according to claim 12, characterized in that: The IO interface corresponding to the ISP download mode includes a receiving RX interface and a sending TX interface.

22. The chip according to claim 21, characterized in that: The IO interface corresponding to the SWD download mode includes a serial data input and output SWDIO interface and a serial clock SWCLK interface.