WO2016127835A1 - Single chip microcomputer and online programming method therefor - Google Patents

Single chip microcomputer and online programming method therefor Download PDF

Info

Publication number
WO2016127835A1
WO2016127835A1 PCT/CN2016/072784 CN2016072784W WO2016127835A1 WO 2016127835 A1 WO2016127835 A1 WO 2016127835A1 CN 2016072784 W CN2016072784 W CN 2016072784W WO 2016127835 A1 WO2016127835 A1 WO 2016127835A1
Authority
WO
WIPO (PCT)
Prior art keywords
single chip
pin
processor
chip microcomputer
file
Prior art date
Application number
PCT/CN2016/072784
Other languages
French (fr)
Chinese (zh)
Inventor
郭睿
Original Assignee
深圳配天智能技术研究院有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳配天智能技术研究院有限公司 filed Critical 深圳配天智能技术研究院有限公司
Publication of WO2016127835A1 publication Critical patent/WO2016127835A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation

Definitions

  • the invention relates to the field of single chip development, in particular to a single chip microcomputer and a method for online programming thereof.
  • the following methods are generally used for the development of single-chip products: firstly, the simulation of hardware and software is performed by using the single-chip simulation device, and then the target code for debugging is solidified into the program memory of the single-chip microcomputer by the program programmer.
  • the program writer is an indispensable development tool, and the program writer is generally more expensive.
  • each time the source program is modified the MCU chip is taken out from the target board, and the updated target code is re-hardened into the MCU chip, so that the chip and the circuit are frequently inserted and removed due to the chip.
  • the board brings the corresponding physical damage.
  • the disadvantage of programming a microcontroller with a programmer is that the programming device is expensive, the programming operation is cumbersome, and it is not convenient to implement the system programming (ISP).
  • ISP system programming
  • the ISP is system in-line programmable, meaning that blank devices on the board can be programmed into the end user code without removing the device from the board. For devices that have already been programmed, they can also be erased or reprogrammed using ISP.
  • the advantage of ISP technology is that it can carry out the experiment and development of the single-chip microcomputer without the need of the programmer, which not only saves the cost of the single-chip development, but also eliminates the trouble of frequently inserting and removing the chip during debugging.
  • the serial mode which is the ISP mode.
  • Most ISP implementation methods use the AVR MCU emulator for program programming.
  • the ISP serial loading timing is simulated by changing the parallel interface of the PC.
  • the main processor uses the IO pin to simulate the loading timing of the MCU.
  • the microcontroller performs program loading.
  • the cost of the emulator can be neglected when the product is mass-produced, but for each board, the emulator is required to connect the MCU to the PC, and the programming software will be opened on the PC.
  • Loader writes This method is very cumbersome when the product is mass-produced, it takes a lot of time, and the emulator is programmed to be very slow, because the emulator does not know what frequency the clock is used by the microcontroller, so the emulator is used. Try to write down as low as possible. And it also requires cumbersome connections and time-consuming operations.
  • the timing of this mode is simulated by the IO pin, the reliability is not high, if other threads of the host computer Interruption or other reasons will affect the loading timing, and unpredictable errors will cause the microcontroller to fail to load or even destroy the Flash of the microcontroller.
  • the technical problem to be solved by the present invention is to provide a single chip microcomputer and a method for online programming thereof, which can reduce cost, increase speed, simplify operation, and have high reliability.
  • a technical solution adopted by the present invention is to provide a method for online programming of a single chip microcomputer, the method comprising the following steps: the processor reads in a firmware program file of the single chip to be loaded, and the firmware program file format of the single chip microcomputer For BIN files. The processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
  • the step of the processor writing the BIN file to the FLASH of the single chip microcomputer through the SPI interface further includes: the processor verifying the BIN file in the FLASH written to the single chip microcomputer.
  • the step of verifying, by the processor, the BIN file written in the FLASH of the single chip microcomputer further includes: the processor reading the written by using the SPI interface from the FLASH of the single chip microcomputer BIN file.
  • the processor compares whether the content of the read BIN file and the written BIN file are the same. If they are the same, it is determined that the loading is successful, and the loading is ended; if not, it is determined that the loading fails and is reloaded.
  • the microcontroller includes an ISP pin and a clock circuit pin.
  • the ISP pin includes: an RST pin, a MOSI pin, a MISO pin, and an SCK pin; the RST is an in-circuit programming input control pin; and the MOSI pin is a data pin of a host output/slave input.
  • the MISO pin is a data pin for the master input/slave output; the SCK pin is a serially programmed clock pin.
  • the clock circuit pin includes XTAL1 and XTAL2 pins;
  • the method Before the step of writing the BIN file into the FLASH of the single chip microcomputer through the SPI interface, the method includes: the single chip is powered on, the RST pin of the single chip is pulled high, and the XTAL1 and XTAL2 pins of the single chip are Connect a crystal between them; or, provide a 3MHz-163MHz clock on the XTAL1 pin and wait at least 10 ⁇ s.
  • the 1.5 pin executes the program enable command and then executes other programming commands.
  • the shift clock on the SCK/P1.7 pin of the single chip microcomputer is smaller than 1/16 of the processor.
  • the processor reads the written BIN file from the FLASH of the single-chip microcomputer through the SPI interface, and the processor reads the MISO/P 1.6 pin for verification.
  • the processor writes the BIN file into the FLASH of the single chip through the SPI interface, the BIN file is written in a one-byte mode; or is written in a one-page mode.
  • the processor compares whether the content of the read BIN file and the written BIN file are the same. If the same determination is that the loading is successful, and the step of ending the loading, the method further includes: pulling down the RST pin of the single chip, In order to operate the microcontroller in normal mode.
  • the method further includes: verifying whether the size of the firmware file of the MCU is correct, and if yes, entering the processor to pass the SPI interface The step of writing the BIN file of the firmware file of the MCU to the FLASH of the MCU.
  • the firmware file of the microcontroller to be loaded is placed on an SD card or NAND In Flash.
  • another technical solution adopted by the present invention is to provide a single chip microcomputer, the single chip microcomputer comprising a processor and a memory, wherein the processor is configured to perform the following method:
  • the processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
  • the processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
  • the processor is further configured to execute:
  • the processor verifies the BIN file written in the FLASH of the single chip microcomputer.
  • the processor is configured to execute:
  • the processor reads the written BIN file from the FLASH of the single chip microcomputer through the SPI interface;
  • the processor compares whether the content of the read BIN file and the written BIN file are the same. If they are the same, it is determined that the loading is successful, and the loading is ended; if not, it is determined that the loading fails and is reloaded.
  • the single chip microcomputer comprises an ISP pin and a clock circuit pin
  • the ISP pin includes: an RST pin, a MOSI pin, a MISO pin, and an SCK pin;
  • the RST is an in-circuit programming input control pin;
  • the MOSI pin is a data pin of a host output/slave input.
  • the MISO pin is a data pin of a master input/slave output;
  • the SCK pin is a serially programmed clock pin;
  • the clock circuit pin includes XTAL1 and XTAL2 pins
  • the processor is further configured to: before executing the step of writing the BIN file into the FLASH of the single chip through the SPI interface, the processor is further configured to:
  • the microcontroller is powered on, the RST pin of the single chip is pulled high, and a crystal oscillator is connected between the XTAL1 and XTAL2 pins of the single chip; or, a clock of 3 MHz-163 MHz is provided on the XTAL1 pin, and at least 10 ⁇ s is waited;
  • the program enable command is executed through the MOSI/P 1.5 pin of the microcontroller, and other programming commands are executed.
  • the shift clock on the SCK/P1.7 pin of the single chip microcomputer is smaller than 1/16 of the processor.
  • the processor reads the written BIN file from the FLASH of the single-chip microcomputer through the SPI interface, and the processor reads the MISO/P 1.6 pin for verification.
  • the processor writes the BIN file into the FLASH of the single chip through the SPI interface, the BIN file is written in a one-byte mode; or is written in a one-page mode.
  • the processor compares whether the content of the read BIN file and the written BIN file are the same, and if the same determination is that the loading is successful, and the step of ending the loading, the processor is further configured to: lower the The RST pin of the microcontroller is used to operate the microcontroller in normal mode.
  • the processor is further configured to: verify that the size of the firmware file of the microcontroller is correct, and if yes, enter the processing.
  • an electronic device the electronic device includes a single chip microcomputer, and the single chip microcomputer includes a processor and a memory, wherein the processor is configured to perform the following steps:
  • the processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
  • the processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
  • the online programming method of the present invention loads the single chip through the SPI interface, and the speed of the SPI interface is fast, and is not limited by the loading frequency of the emulator, so it can be realized. Very high loading speed.
  • the online programming method of the present invention is not as susceptible to other threads under the operating system as the loading mode implemented by the GPIO analog loading timing, so the success rate can be greatly improved, thus having higher reliability and lowering. Processor resource usage.
  • the method is automatically executed after the operating system is started, and does not require any connection (emulator or parallel port of the host computer), so it is convenient and fast, and is very suitable for program curing of the single chip microcomputer during mass production.
  • FIG. 1 is a flow chart of a first embodiment of a method for online programming of a single chip microcomputer according to the present invention
  • Figure 2 is a loading circuit diagram of the ISP loading mode of the AT89LS52 microcontroller
  • FIG. 3 is a timing diagram of the ISP loading mode of the AT89LS52 microcontroller
  • Figure 4 is a relationship diagram of the clock and sampling points of the four modes of the SPI
  • Figure 5 is a timing diagram of the complete SPI signals of mode 0 and mode 2 of Figure 4;
  • FIG. 6 is a flow chart of a second embodiment of a method for online programming of a single chip microcomputer according to the present invention.
  • FIG. 7 is a flow chart of step S22 of Figure 6;
  • Figure 8 is a flow chart of step S23 of Figure 6.
  • the method for online programming of the single chip of the invention is mainly for a single chip microcomputer supporting the system programming (ISP), such as an AT89S series single chip microcomputer.
  • ISP system programming
  • FIG. 1 is a flowchart of a first embodiment of a method for online programming of a single chip microcomputer according to the present invention.
  • the processor reads in the firmware file of the single chip to be loaded, and the firmware program file format of the single chip is a BIN file.
  • the processor passes SPI (Serial Peripheral)
  • the Interface interface writes the BIN file of the firmware file of the MCU to the FLASH of the MCU.
  • the BIN file can be written in a one-byte mode. Alternatively, it can be written in a one-page mode.
  • the time of a write cycle is generally less than 1ms.
  • the online programming method of the invention loads the single chip through the SPI interface and directly loads the BIN file.
  • the SPI interface speed can reach 50M, and generally can reach 30M, so the loading speed is very fast.
  • the HEX file is generated after being compiled in the emulator burning project. The file size is 10 KB, and the programming is completed and the verification is performed, which takes about half a minute. Because the general method is loaded by the emulator, the KEIL software only generates the HEX file. To burn the BIN file, you need to convert the HEX file to a BIN file. The converted BIN file size is 4 KB.
  • the invention can be programmed and verified in 10s by the loading mode of the SPI.
  • SPI is a self-contained peripheral for the processor.
  • the processor only needs to inform the SPI peripheral to send data now. As for the timing and actual transmission of the data, it is controlled by the SPI peripheral. Therefore, the processor is notified. After the SPI peripheral sends data or receives it, it can not participate in the specific process of sending or receiving data. The processor does not interfere with the actual sending process under normal circumstances.
  • the online programming method of the present invention loads the single chip through a dedicated interface (SPI interface), and the SPI interface is fast and is not limited by the loading frequency of the emulator, so that a high loading speed can be achieved.
  • the present invention is also less susceptible to other threads under the operating system than the loading mode implemented by the GPIO analog load timing, so the success rate can be greatly improved, thus having higher reliability and lower processor resource utilization.
  • the loading method is automatically executed after the operating system is started, and does not require any connection (emulator or parallel port of the host computer), so it is convenient and fast, and is very suitable for program curing of the single chip microcomputer during mass production.
  • FIG. 2 is a loading circuit diagram of the ISP loading mode of the AT89LS52 microcontroller.
  • Figure 3 is a timing diagram of the ISP loading mode of the AT89LS52 microcontroller.
  • Figure 4 is a plot of the clock and sample points for the four modes of the SPI.
  • Figure 5 is a timing diagram of the complete SPI signal for Mode 0 and Mode 2 of Figure 4.
  • the frequency of the SCK pin of the microcontroller cannot exceed 1/16 of the crystal frequency of the microcontroller.
  • the clock frequency of the MCU is 10MHz. Therefore, the frequency of the SCK cannot exceed 625KHz, and the source clock provided by the host computer for the SPI is 48MHz.
  • the communication clock of the SPI can also be divided, and the source clock is divided by 128 to obtain a clock frequency of 375 KHz, which is lower than the highest frequency required by SCK, and therefore, the DM8147 is used.
  • the SPI interface is feasible for loading the microcontroller.
  • FIG. 6 is a flowchart of a second embodiment of a method for online programming of a single chip microcomputer according to the present invention.
  • the AT89LS microcontroller includes an ISP pin and a clock circuit pin.
  • ISP pins There are four ISP pins: RST, MOSI, MISO, and SCK.
  • RST is the online programming input control terminal, which is kept high only during the ISP download process. When the system is working normally, this pin is the system reset terminal and keeps the low state.
  • MOSI is the data input of the master output/slave. When the system is working normally, this pin is the common I/OP1.5 port line.
  • MISO is the data side of the master input/slave output. When the system is working normally, this pin is a general-purpose I/OP1.6 port line.
  • SCK is the serial programming clock terminal that synchronizes the master and slave timings. When the system is working normally, this pin is a general-purpose I/OP1.7 port line.
  • the clock circuit pins include the XTAL1 and XTAL2 pins.
  • the upper computer of the single chip microcomputer is the DM8147
  • the DM8147 is a high performance, low power consumption processor of the DaVinci architecture of the TI company, which is the main controller of the system, and the single chip microcomputer is used as the control system. Part of it is mainly responsible for matrix button scanning, and two-way communication with the DM8147 through the serial port.
  • the DM8147 loads the program through the SPI interface.
  • the processor reads in the firmware file of the single chip to be loaded, and the firmware program file format of the single chip is a BIN file.
  • the MCU firmware program file can be placed on the SD card or NAND In Flash.
  • Nand-flash memory is a kind of flash memory, and its internal non-linear macro cell mode provides a cheap and effective solution for the realization of solid-state large-capacity memory.
  • the firmware file of the single chip is placed in the SD card, and the system reads the loaded file after booting from the SD card.
  • step S21 Verify that the size of the firmware file of the single chip is correct. If yes, proceed to step S22.
  • the processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
  • step S22 includes:
  • the single chip is powered on, the RST pin of the single chip is pulled high, and a crystal oscillator is connected between the XTAL1 and XTAL2 pins of the single chip; or a 3MHz-163MHz clock is provided on the XTAL1 pin, and at least waiting 10 ⁇ s.
  • step S221 passing the MOSI/P of the single chip microcomputer The 1.5 pin executes the program enable command and then executes other program commands; and the shift clock on the SCK/P1.7 pin of the microcontroller is less than 1/16 of the processor.
  • the program enable command is used as the leading command of other commands, and the program enable command must be executed first, and then other commands are executed.
  • the processor performs verification on the BIN file written in the FLASH of the single chip microcomputer.
  • step S23 further includes:
  • the processor reads the written BIN file from the FLASH of the single chip by using the SPI interface.
  • the processor performs verification by reading the MISO/P 1.6 pin. Any storage space can be read by reading MISO/P The 1.6 pin is used for verification, and the data in the address space is returned through this pin.
  • the processor compares whether the content of the read BIN file and the written BIN file are the same. If the same, it is determined that the loading is successful, and the loading is ended, and the process proceeds to step S24; if not, the loading is determined to be failed and reloaded. .
  • the online programming method of the present invention does not require any external connection, and only needs to be plugged in the SD card to power on the system, and the loading is automatically performed and verified.
  • the speed and reliability of the method of the present invention was further verified by testing the loading of fixed size files using the in-circuit programming method of the present invention. This test includes the complete process of writing, reading and verifying.
  • the loading speed is at least 20 times faster than the loading speed by the emulator (the emulator loading is only the pure loading time, not counting the emulator time), and can reach 375 KHz, and at this frequency,
  • the bit error rate is 0, that is, 700 times of loading, 100% success.
  • the method of online programming through the SPI interface of the invention has higher reliability and stability than the method of GPIO analog loading timing, because the SPI is a dedicated interface, and the loading timing of the single chip is realized by a hardware circuit.
  • any task is a thread for the operating system, the operating system controls the scheduling of the thread, the thread may be interrupted, the loading through the SPI interface may also be interrupted by other threads, through the SPI interface Loading, sending a byte of data is just an instruction, an instruction can not be interrupted, that is, loading through the SPI interface, it is impossible to be interrupted in the middle of transmitting a byte. Therefore, even if the load is interrupted, it will not affect the load timing.
  • the way GPIO is simulated will always occupy the processor until it is interrupted by other threads. Since the SPI is a self-contained peripheral for the processor, the processor only needs to inform the SPI peripheral that it is now sending data. As for the timing and actual transmission of the data, it is controlled by the SPI peripheral. Therefore, the processor is notified. After the SPI peripheral sends data or receives it, it can not participate in the specific process of sending or receiving data. The processor does not normally intervene in the actual transmission process unless an error occurs in the SPI peripheral.
  • the GPIO emulation requires the processor to control and complete the entire sequence, then the data is sent or received into a thread of the processor, and the thread is executed in a time-sharing manner, so the thread will be interrupted.
  • the invention also provides a single chip microcomputer, the single chip microcomputer comprises a processor and a memory, and the processor and the memory may be connected by a bus, and of course, other connection manners may also be adopted.
  • the processor is configured to perform a method for online programming, the method comprising the following steps:
  • the processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
  • the processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
  • the processor is further configured to execute:
  • the processor verifies the BIN file written in the FLASH of the single chip microcomputer.
  • the processor is configured to execute:
  • the processor reads the written BIN file from the FLASH of the single chip microcomputer through the SPI interface;
  • the processor compares whether the content of the read BIN file and the written BIN file are the same. If they are the same, it is determined that the loading is successful, and the loading is ended; if not, it is determined that the loading fails and is reloaded.
  • the single chip microcomputer comprises an ISP pin and a clock circuit pin
  • the ISP pin includes: an RST pin, a MOSI pin, a MISO pin, and an SCK pin;
  • the RST is an in-circuit programming input control pin;
  • the MOSI pin is a data pin of a host output/slave input.
  • the MISO pin is a data pin of a master input/slave output;
  • the SCK pin is a serially programmed clock pin;
  • the clock circuit pin includes XTAL1 and XTAL2 pins
  • the processor is further configured to: before executing the step of writing the BIN file into the FLASH of the single chip through the SPI interface, the processor is further configured to:
  • the microcontroller is powered on, the RST pin of the single chip is pulled high, and a crystal oscillator is connected between the XTAL1 and XTAL2 pins of the single chip; or, a clock of 3 MHz-163 MHz is provided on the XTAL1 pin, and at least 10 ⁇ s is waited;
  • the program enable command is executed through the MOSI/P 1.5 pin of the microcontroller, and other programming commands are executed.
  • the shift clock on the SCK/P1.7 pin of the single chip microcomputer is smaller than 1/16 of the processor.
  • the processor reads the written BIN file from the FLASH of the single-chip microcomputer through the SPI interface, and the processor reads the MISO/P 1.6 pin for verification.
  • the processor writes the BIN file into the FLASH of the single chip through the SPI interface, the BIN file is written in a one-byte mode; or is written in a one-page mode.
  • the processor compares whether the content of the read BIN file and the written BIN file are the same, and if the same determination is that the loading is successful, and the step of ending the loading, the processor is further configured to: lower the The RST pin of the microcontroller is used to operate the microcontroller in normal mode.
  • the processor is further configured to: verify that the size of the firmware file of the microcontroller is correct, and if yes, enter the processing.
  • the present invention also provides an electronic device, the electronic device including a single chip microcomputer, the single chip microcomputer includes a processor and a memory, wherein the processor is configured to perform the following method:
  • the processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
  • the processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
  • the single-chip microcomputer included in the electronic device is the single-chip microcomputer described in the foregoing embodiment.
  • the electronic device, the single chip computer and the online programming method thereof of the invention load the single chip through the SPI interface, realize high speed loading, improve the success rate and have high reliability.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Microcomputers (AREA)
  • Test And Diagnosis Of Digital Computers (AREA)

Abstract

Disclosed are a single chip microcomputer and an online programming method therefor. The method comprises the following steps: a processor reads in a single chip microcomputer firmware program file to be loaded, the format of the single chip microcomputer firmware program file being a BIN file (S10); and the processor writes the BIN file of the single chip microcomputer firmware program file into a FLASH of the single chip microcomputer through an SPI interface (S11).The online programming method loads the program file by using the SPI interface, and is thus not limited by a loading frequency of an emulator. The method can achieve a high loading speed, and is thus not likely to be influenced by other threads in an operating system. It can greatly increase the success ratio, has higher reliability, and has a lower CPU resource occupation rate. In addition, the online programming method does not need any connection, and is thus convenient and fast, and is very suitable for firming a program on a single chip microcomputer during mass-production.

Description

单片机及其在线编程的方法 Single chip microcomputer and its online programming method
【技术领域】[Technical Field]
本发明涉及单片机开发领域,特别是涉及单片机及其在线编程的方法。The invention relates to the field of single chip development, in particular to a single chip microcomputer and a method for online programming thereof.
【背景技术】 【Background technique】
目前,对于单片机产品的开发一般采用以下方法:首先利用单片机仿真设备进行硬件和软件的仿真调试,然后将调试通过的目标代码用程序烧写器固化到单片机的程序存储器中。在这个过程中,程序烧写器是必不可少的开发工具,而程序烧写器一般价格较昂贵。另外,以后每修改一次源程序就要将单片机芯片从目标板上取出,再将更新后的目标代码重新固化到单片机芯片中,这样调试时就会由于频繁地插拔单片机芯片而对芯片和电路板带来相应的物理损坏。借助程序烧写器进行单片机编程的缺点是烧写设备昂贵,烧写操作麻烦,不便于实现在系统编程(ISP)。At present, the following methods are generally used for the development of single-chip products: firstly, the simulation of hardware and software is performed by using the single-chip simulation device, and then the target code for debugging is solidified into the program memory of the single-chip microcomputer by the program programmer. In this process, the program writer is an indispensable development tool, and the program writer is generally more expensive. In addition, each time the source program is modified, the MCU chip is taken out from the target board, and the updated target code is re-hardened into the MCU chip, so that the chip and the circuit are frequently inserted and removed due to the chip. The board brings the corresponding physical damage. The disadvantage of programming a microcontroller with a programmer is that the programming device is expensive, the programming operation is cumbersome, and it is not convenient to implement the system programming (ISP).
为了克服上述缺点和局限性,一些新型兼容品在芯片内部设置了实现“串行编程接口逻辑”硬件功能,从而支持单片机芯片在系统编程(ISP)。ISP是系统在线可编程,指电路板上的空白器件可以编程写入最终用户代码,而不需要从电路板上取下器件,对于已经编程的器件也可以用ISP方式擦除或再编程。ISP技术的优势是不需要编程器也可以进行单片机的实验和开发,既节省了单片机开发的成本,又免去了调试时频繁插拔芯片的麻烦。单片机编程有两种模式:并联模式和串联模式。目前对于单片机加载,大部分都采用串联模式,也就是ISP模式,大部分ISP实现方法都是采用AVR的单片机仿真器进行程序烧写。还有部分是通过对PC的并行接口进行相应的改变来模拟实现ISP串行加载时序,另外,当单片机作为协处理器或控制系统的一部分时,主处理器利用IO管脚模拟单片机加载时序对单片机进行程序加载。In order to overcome the above shortcomings and limitations, some new compatible products are set inside the chip to implement the "serial programming interface logic" hardware function, thus supporting the microcontroller chip in system programming (ISP). The ISP is system in-line programmable, meaning that blank devices on the board can be programmed into the end user code without removing the device from the board. For devices that have already been programmed, they can also be erased or reprogrammed using ISP. The advantage of ISP technology is that it can carry out the experiment and development of the single-chip microcomputer without the need of the programmer, which not only saves the cost of the single-chip development, but also eliminates the trouble of frequently inserting and removing the chip during debugging. There are two modes of microcontroller programming: parallel mode and series mode. At present, for the MCU loading, most of them use the serial mode, which is the ISP mode. Most ISP implementation methods use the AVR MCU emulator for program programming. In addition, the ISP serial loading timing is simulated by changing the parallel interface of the PC. In addition, when the MCU is used as a coprocessor or a part of the control system, the main processor uses the IO pin to simulate the loading timing of the MCU. The microcontroller performs program loading.
直接用单片机仿真器进行加载,在进行产品量产的时候,仿真器的成本可以忽略,但是对于每一块板卡,都需要通过仿真器将单片机与PC连接起来,在PC端打开烧写软件将加载程序写入。在产品大量生产的时候,这种方法非常麻烦,将花费大量的时间,并且仿真器烧写的速度非常低,因为仿真器不知道单片机用的是什么频率的时钟,因此,仿真器都是使用尽量低的烧写频率。并且还需要繁琐的连接,耗时的操作。直接通过板卡上的微处理器的IO引脚来模拟单片机加载时序对单片机进行加载的方式,该方式的时序是通过IO引脚进行模拟的,可靠性不高,如果被上位机的其他线程打断或其他原因将会影响加载时序,发生不可预料的错误,将导致单片机加载失败甚至毁坏单片机的Flash。Directly loaded with the MCU emulator, the cost of the emulator can be neglected when the product is mass-produced, but for each board, the emulator is required to connect the MCU to the PC, and the programming software will be opened on the PC. Loader writes. This method is very cumbersome when the product is mass-produced, it takes a lot of time, and the emulator is programmed to be very slow, because the emulator does not know what frequency the clock is used by the microcontroller, so the emulator is used. Try to write down as low as possible. And it also requires cumbersome connections and time-consuming operations. Directly through the IO pin of the microprocessor on the board to simulate the loading mode of the microcontroller to load the microcontroller, the timing of this mode is simulated by the IO pin, the reliability is not high, if other threads of the host computer Interruption or other reasons will affect the loading timing, and unpredictable errors will cause the microcontroller to fail to load or even destroy the Flash of the microcontroller.
【发明内容】 [Summary of the Invention]
本发明主要解决的技术问题是提供一种单片机及其在线编程的方法,能够降低成本、提高速度、简化操作并且具有高可靠性。The technical problem to be solved by the present invention is to provide a single chip microcomputer and a method for online programming thereof, which can reduce cost, increase speed, simplify operation, and have high reliability.
为解决上述技术问题,本发明采用的一个技术方案是:提供一种单片机在线编程的方法,该方法包括以下步骤:处理器读入要加载的单片机固件程序文件,所述单片机的固件程序文件格式为BIN文件。所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中。In order to solve the above technical problem, a technical solution adopted by the present invention is to provide a method for online programming of a single chip microcomputer, the method comprising the following steps: the processor reads in a firmware program file of the single chip to be loaded, and the firmware program file format of the single chip microcomputer For BIN files. The processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
其中,所述处理器通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤之后还包括:所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验。The step of the processor writing the BIN file to the FLASH of the single chip microcomputer through the SPI interface further includes: the processor verifying the BIN file in the FLASH written to the single chip microcomputer.
其中,所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验的步骤进一步包括:所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件。所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同则判断为加载成功,并结束加载;若不同则判断为加载失败,并重新加载。The step of verifying, by the processor, the BIN file written in the FLASH of the single chip microcomputer further includes: the processor reading the written by using the SPI interface from the FLASH of the single chip microcomputer BIN file. The processor compares whether the content of the read BIN file and the written BIN file are the same. If they are the same, it is determined that the loading is successful, and the loading is ended; if not, it is determined that the loading fails and is reloaded.
其中,所述单片机包括ISP引脚和时钟电路引脚。所述ISP引脚包括:RST引脚、MOSI引脚、MISO引脚和SCK引脚;所述RST为在线编程输入控制引脚;所述MOSI引脚为主机输出/从机输入的数据引脚;所述MISO引脚为主机输入/从机输出的数据引脚;所述SCK引脚为串行编程的时钟引脚。所述时钟电路引脚包括XTAL1和XTAL2引脚;The microcontroller includes an ISP pin and a clock circuit pin. The ISP pin includes: an RST pin, a MOSI pin, a MISO pin, and an SCK pin; the RST is an in-circuit programming input control pin; and the MOSI pin is a data pin of a host output/slave input. The MISO pin is a data pin for the master input/slave output; the SCK pin is a serially programmed clock pin. The clock circuit pin includes XTAL1 and XTAL2 pins;
所述处理器通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤之前包括:所述单片机上电,所述单片机的RST引脚拉高,并在所述单片机XTAL1和XTAL2引脚之间连接晶振;或者,在XTAL1引脚提供一个3MHz-163MHz的时钟,并且至少等待10μs。通过所述单片机的MOSI/P 1.5引脚执行编程使能命令,再执行其它编程命令。Before the step of writing the BIN file into the FLASH of the single chip microcomputer through the SPI interface, the method includes: the single chip is powered on, the RST pin of the single chip is pulled high, and the XTAL1 and XTAL2 pins of the single chip are Connect a crystal between them; or, provide a 3MHz-163MHz clock on the XTAL1 pin and wait at least 10μs. Through the MOSI/P of the single chip microcomputer The 1.5 pin executes the program enable command and then executes other programming commands.
其中,所述单片机的SCK/P1.7引脚上的移位时钟小于所述处理器的1/16。The shift clock on the SCK/P1.7 pin of the single chip microcomputer is smaller than 1/16 of the processor.
其中,所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件的步骤中,所述处理器通过读MISO/P 1.6引脚来进行校验。The processor reads the written BIN file from the FLASH of the single-chip microcomputer through the SPI interface, and the processor reads the MISO/P 1.6 pin for verification.
其中,所述处理器通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤中,所述BIN文件以一次一字节的模式写入;或者以一次一页的模式写入。Wherein, the processor writes the BIN file into the FLASH of the single chip through the SPI interface, the BIN file is written in a one-byte mode; or is written in a one-page mode.
其中,所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同判断为加载成功,并结束加载的步骤之后,还包括:拉低所述单片机的RST引脚,以使所述单片机在正常模式工作。The processor compares whether the content of the read BIN file and the written BIN file are the same. If the same determination is that the loading is successful, and the step of ending the loading, the method further includes: pulling down the RST pin of the single chip, In order to operate the microcontroller in normal mode.
其中,所述处理器读入要加载的单片机固件程序文件的步骤之后,还包括:校验所述单片机固件程序文件的大小是否正确,若正确,则进入所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中的步骤。After the step of reading the firmware file of the MCU to be loaded by the processor, the method further includes: verifying whether the size of the firmware file of the MCU is correct, and if yes, entering the processor to pass the SPI interface The step of writing the BIN file of the firmware file of the MCU to the FLASH of the MCU.
其中,所述处理器读入要加载的单片机固件程序文件的步骤中,所述要加载的单片机固件程序文件放在SD卡或者NAND Flash中。Wherein the step of reading, by the processor, the firmware file of the microcontroller to be loaded, the firmware file of the microcontroller to be loaded is placed on an SD card or NAND In Flash.
为解决上述技术问题,本发明采用的另一个技术方案是:提供一种单片机,所述单片机包括处理器和存储器,其中所述处理器用于执行如下方法:In order to solve the above technical problem, another technical solution adopted by the present invention is to provide a single chip microcomputer, the single chip microcomputer comprising a processor and a memory, wherein the processor is configured to perform the following method:
处理器读入要加载的单片机固件程序文件,所述单片机的固件程序文件格式为BIN文件;The processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中。The processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
其中,所述处理器还用于执行:Wherein, the processor is further configured to execute:
所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验。The processor verifies the BIN file written in the FLASH of the single chip microcomputer.
其中,在所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验的步骤中,所述处理器用于执行:Wherein, in the step of the processor verifying the BIN file written in the FLASH of the single chip microcomputer, the processor is configured to execute:
所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件;The processor reads the written BIN file from the FLASH of the single chip microcomputer through the SPI interface;
所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同则判断为加载成功,并结束加载;若不同则判断为加载失败,并重新加载。The processor compares whether the content of the read BIN file and the written BIN file are the same. If they are the same, it is determined that the loading is successful, and the loading is ended; if not, it is determined that the loading fails and is reloaded.
其中,所述单片机包括ISP引脚和时钟电路引脚;Wherein, the single chip microcomputer comprises an ISP pin and a clock circuit pin;
所述ISP引脚包括:RST引脚、MOSI引脚、MISO引脚和SCK引脚;所述RST为在线编程输入控制引脚;所述MOSI引脚为主机输出/从机输入的数据引脚;所述MISO引脚为主机输入/从机输出的数据引脚;所述SCK引脚为串行编程的时钟引脚;The ISP pin includes: an RST pin, a MOSI pin, a MISO pin, and an SCK pin; the RST is an in-circuit programming input control pin; and the MOSI pin is a data pin of a host output/slave input. The MISO pin is a data pin of a master input/slave output; the SCK pin is a serially programmed clock pin;
所述时钟电路引脚包括XTAL1和XTAL2引脚;The clock circuit pin includes XTAL1 and XTAL2 pins;
所述处理器在执行所述通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤之前,所述处理器还用于执行:The processor is further configured to: before executing the step of writing the BIN file into the FLASH of the single chip through the SPI interface, the processor is further configured to:
所述单片机上电,所述单片机的RST引脚拉高,并在所述单片机XTAL1和XTAL2引脚之间连接晶振;或者,在XTAL1引脚提供一个3MHz-163MHz的时钟,并且至少等待10μs;The microcontroller is powered on, the RST pin of the single chip is pulled high, and a crystal oscillator is connected between the XTAL1 and XTAL2 pins of the single chip; or, a clock of 3 MHz-163 MHz is provided on the XTAL1 pin, and at least 10 μs is waited;
通过所述单片机的MOSI/P 1.5引脚执行编程使能命令,再执行其它编程命令。The program enable command is executed through the MOSI/P 1.5 pin of the microcontroller, and other programming commands are executed.
其中,所述单片机的SCK/P1.7引脚上的移位时钟小于所述处理器的1/16。The shift clock on the SCK/P1.7 pin of the single chip microcomputer is smaller than 1/16 of the processor.
其中,所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件的步骤中,所述处理器通过读MISO/P 1.6引脚来进行校验。The processor reads the written BIN file from the FLASH of the single-chip microcomputer through the SPI interface, and the processor reads the MISO/P 1.6 pin for verification.
其中,所述处理器通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤中,所述BIN文件以一次一字节的模式写入;或者以一次一页的模式写入。Wherein, the processor writes the BIN file into the FLASH of the single chip through the SPI interface, the BIN file is written in a one-byte mode; or is written in a one-page mode.
其中,在所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同判断为加载成功,并结束加载的步骤之后,所述处理器还用于执行:拉低所述单片机的RST引脚,以使所述单片机在正常模式工作。Wherein, the processor compares whether the content of the read BIN file and the written BIN file are the same, and if the same determination is that the loading is successful, and the step of ending the loading, the processor is further configured to: lower the The RST pin of the microcontroller is used to operate the microcontroller in normal mode.
其中,在所述处理器读入要加载的单片机固件程序文件的步骤之后,所述处理器还用于执行:校验所述单片机固件程序文件的大小是否正确,若正确,则进入所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中的步骤。After the step of the processor reading the firmware program file of the microcontroller to be loaded, the processor is further configured to: verify that the size of the firmware file of the microcontroller is correct, and if yes, enter the processing. The step of writing the BIN file of the firmware file of the single-chip microcomputer to the FLASH of the single-chip microcomputer through the SPI interface.
为解决上述技术问题,本发明采用的另一个技术方案是:提供一种电子设备,所述电子设备包括单片机,所述单片机包括处理器和存储器,其中所述处理器用于执行如下步骤:In order to solve the above technical problem, another technical solution adopted by the present invention is to provide an electronic device, the electronic device includes a single chip microcomputer, and the single chip microcomputer includes a processor and a memory, wherein the processor is configured to perform the following steps:
处理器读入要加载的单片机固件程序文件,所述单片机的固件程序文件格式为BIN文件;The processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中。The processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
本发明的有益效果是:区别于现有技术的情况,本发明的在线编程的方法通过SPI接口对单片机进行加载,SPI接口的速度快,并且还不受仿真器加载频率的限制,所以可以实现很高的加载速度。此外,本发明的在线编程的方法不像GPIO模拟加载时序实现的加载方式那样容易受到操作系统下其他线程的影响,因此成功率可以大大提高,因而具有较高的可靠性,并且有更低的处理器资源占用率。此外,该方法是在操作系统启动后自动执行,不需要任何连线(仿真器或者上位机并口等),因此方便快速,非常适合量产时对单片机进行程序固化。The beneficial effects of the present invention are: different from the prior art, the online programming method of the present invention loads the single chip through the SPI interface, and the speed of the SPI interface is fast, and is not limited by the loading frequency of the emulator, so it can be realized. Very high loading speed. In addition, the online programming method of the present invention is not as susceptible to other threads under the operating system as the loading mode implemented by the GPIO analog loading timing, so the success rate can be greatly improved, thus having higher reliability and lowering. Processor resource usage. In addition, the method is automatically executed after the operating system is started, and does not require any connection (emulator or parallel port of the host computer), so it is convenient and fast, and is very suitable for program curing of the single chip microcomputer during mass production.
【附图说明】 [Description of the Drawings]
图1是本发明单片机在线编程的方法第一实施例的流程图;1 is a flow chart of a first embodiment of a method for online programming of a single chip microcomputer according to the present invention;
图2是AT89LS52单片机的ISP加载模式的加载电路图;Figure 2 is a loading circuit diagram of the ISP loading mode of the AT89LS52 microcontroller;
图3是AT89LS52单片机的ISP加载模式的时序图;Figure 3 is a timing diagram of the ISP loading mode of the AT89LS52 microcontroller;
图4是SPI的四种模式的时钟及采样点的关系图;Figure 4 is a relationship diagram of the clock and sampling points of the four modes of the SPI;
图5是图4中模式0和模式2的完整SPI信号的时序图;Figure 5 is a timing diagram of the complete SPI signals of mode 0 and mode 2 of Figure 4;
图6是本发明单片机在线编程的方法第二实施例的流程图;6 is a flow chart of a second embodiment of a method for online programming of a single chip microcomputer according to the present invention;
图7是图6中步骤S22的流程图;Figure 7 is a flow chart of step S22 of Figure 6;
图8是图6中步骤S23的流程图。Figure 8 is a flow chart of step S23 of Figure 6.
【具体实施方式】【detailed description】
下面结合附图和实施例对本发明进行详细说明。The invention will now be described in detail in conjunction with the drawings and embodiments.
本发明的单片机在线编程的方法,主要是针对支持在系统编程(ISP)的单片机,例如AT89S系列单片机。The method for online programming of the single chip of the invention is mainly for a single chip microcomputer supporting the system programming (ISP), such as an AT89S series single chip microcomputer.
请参阅图1,是本发明单片机在线编程的方法第一实施例的流程图。Please refer to FIG. 1 , which is a flowchart of a first embodiment of a method for online programming of a single chip microcomputer according to the present invention.
本实施例的单片机在线编程的方法包括以下步骤:The method for online programming of the single chip of the embodiment includes the following steps:
S10、处理器读入要加载的单片机固件程序文件,所述单片机的固件程序文件格式为BIN文件。S10. The processor reads in the firmware file of the single chip to be loaded, and the firmware program file format of the single chip is a BIN file.
S11、所述处理器通过SPI (Serial Peripheral Interface)接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中。S11. The processor passes SPI (Serial Peripheral) The Interface interface writes the BIN file of the firmware file of the MCU to the FLASH of the MCU.
具体地,上述步骤中,BIN文件可以以一次一字节的模式写入。或者,也可以以一次一页的模式写入。一个写周期的时间一般小于1ms。Specifically, in the above steps, the BIN file can be written in a one-byte mode. Alternatively, it can be written in a one-page mode. The time of a write cycle is generally less than 1ms.
本发明的在线编程方法是通过SPI接口对单片机进行加载,直接加载BIN文件。目前SPI接口速度最高可以达到50M,一般都能达到30M,因而加载速度很快。现有技术中仿真器烧写工程中编译后生成的是HEX文件,该文件大小为10KB,烧写完成并读取校验,大概需要半分钟左右。因为一般的方式都是通过仿真器加载,因此KEIL软件只生成HEX文件,要想烧写BIN文件需要将HEX文件转换为BIN文件,转换出来的BIN文件大小为4KB。而本发明通过SPI的加载方式可以在10s内完成烧写以及校验。The online programming method of the invention loads the single chip through the SPI interface and directly loads the BIN file. At present, the SPI interface speed can reach 50M, and generally can reach 30M, so the loading speed is very fast. In the prior art, the HEX file is generated after being compiled in the emulator burning project. The file size is 10 KB, and the programming is completed and the verification is performed, which takes about half a minute. Because the general method is loaded by the emulator, the KEIL software only generates the HEX file. To burn the BIN file, you need to convert the HEX file to a BIN file. The converted BIN file size is 4 KB. The invention can be programmed and verified in 10s by the loading mode of the SPI.
此外,SPI对于处理器是一个自带的外设,处理器只需要通知SPI外设现在要发送数据,至于数据的时序以及实际发送都是由SPI外设来控制的,所以,处理器在通知完SPI外设发送数据或接收后就可以不参与具体的发送或接收数据过程,处理器正常情况下不干预实际的发送过程。In addition, SPI is a self-contained peripheral for the processor. The processor only needs to inform the SPI peripheral to send data now. As for the timing and actual transmission of the data, it is controlled by the SPI peripheral. Therefore, the processor is notified. After the SPI peripheral sends data or receives it, it can not participate in the specific process of sending or receiving data. The processor does not interfere with the actual sending process under normal circumstances.
区别于现有技术,本发明的在线编程的方法通过专用接口(SPI接口)对单片机进行加载,SPI接口速度快,并且不受仿真器加载频率的限制,因而可以实现很高的加载速度。本发明也不像GPIO模拟加载时序实现的加载方式那样容易受到操作系统下其他线程的影响,因此成功率可以大大提高,因而具有较高的可靠性,并且有更低处理器资源占用率。此外,该加载方法是在操作系统启动后自动执行,不需要任何连线(仿真器或者上位机并口等),因此方便快速,非常适合量产时对单片机进行程序固化。Different from the prior art, the online programming method of the present invention loads the single chip through a dedicated interface (SPI interface), and the SPI interface is fast and is not limited by the loading frequency of the emulator, so that a high loading speed can be achieved. The present invention is also less susceptible to other threads under the operating system than the loading mode implemented by the GPIO analog load timing, so the success rate can be greatly improved, thus having higher reliability and lower processor resource utilization. In addition, the loading method is automatically executed after the operating system is started, and does not require any connection (emulator or parallel port of the host computer), so it is convenient and fast, and is very suitable for program curing of the single chip microcomputer during mass production.
以下是对本发明通过SPI接口对单片机进行程序加载的可行性的分析:请参阅图2至图5,图2是AT89LS52单片机的ISP加载模式的加载电路图。图3是AT89LS52单片机的ISP加载模式的时序图。图4是SPI的四种模式的时钟及采样点的关系图。图5是图4中模式0和模式2的完整SPI信号的时序图。OL=0为模式0;POL=1为模式2。对比采样点和时钟的关系,再与AT89LS52单片机ISP加载模式的时序图(图3)对比,可以看到,单片机加载时所要求的时序图与SPI模式0的时序是兼容的。因此,用SPI接口为单片机加载程序在理论上是可行的。The following is an analysis of the feasibility of the program loading the microcontroller through the SPI interface: Please refer to FIG. 2 to FIG. 5, and FIG. 2 is a loading circuit diagram of the ISP loading mode of the AT89LS52 microcontroller. Figure 3 is a timing diagram of the ISP loading mode of the AT89LS52 microcontroller. Figure 4 is a plot of the clock and sample points for the four modes of the SPI. Figure 5 is a timing diagram of the complete SPI signal for Mode 0 and Mode 2 of Figure 4. OL = 0 is mode 0; POL = 1 is mode 2. Comparing the relationship between the sampling point and the clock, and comparing with the timing diagram of the ISP loading mode of the AT89LS52 microcontroller (Fig. 3), it can be seen that the timing diagram required when the microcontroller is loaded is compatible with the timing of the SPI mode 0. Therefore, it is theoretically feasible to load the program for the microcontroller with the SPI interface.
单片机SCK引脚的频率不能超过单片机晶振频率的1/16。系统中,单片机的时钟频率为10MHz,因此,SCK的频率不能超过625KHz,而上位机为SPI提供的源时钟为48MHz, 在SPI外设接口的配置寄存器中还可以为SPI的通信时钟进行分频,将源时钟进行128分频,可以得到375KHz的时钟频率,该频率小于SCK所要求的最高频率,因此,通过DM8147的SPI接口对单片机加载是可行的。The frequency of the SCK pin of the microcontroller cannot exceed 1/16 of the crystal frequency of the microcontroller. In the system, the clock frequency of the MCU is 10MHz. Therefore, the frequency of the SCK cannot exceed 625KHz, and the source clock provided by the host computer for the SPI is 48MHz. In the configuration register of the SPI peripheral interface, the communication clock of the SPI can also be divided, and the source clock is divided by 128 to obtain a clock frequency of 375 KHz, which is lower than the highest frequency required by SCK, and therefore, the DM8147 is used. The SPI interface is feasible for loading the microcontroller.
请参阅图6,是本发明单片机在线编程的方法第二实施例的流程图。Please refer to FIG. 6, which is a flowchart of a second embodiment of a method for online programming of a single chip microcomputer according to the present invention.
具体地,AT89LS单片机包括ISP引脚和时钟电路引脚。ISP引脚共有4个:RST、MOSI、MISO和SCK。各引脚的功能如下:RST为在线编程输入控制端,仅在ISP下载过程中保持高电平,在系统正常工作时该引脚为系统复位端,保持低电平状态。MOSI为主机输出/从机输入的数据端,系统正常工作时,该引脚为公用I/OP1.5口线。MISO为主机输入/从机输出的数据端。系统正常工作时,该引脚为通用I/OP1.6口线。SCK为串行编程的时钟端,可实现主、从机时序的同步。系统正常工作时,该引脚为通用I/OP1.7口线。时钟电路引脚包括XTAL1和XTAL2引脚。Specifically, the AT89LS microcontroller includes an ISP pin and a clock circuit pin. There are four ISP pins: RST, MOSI, MISO, and SCK. The function of each pin is as follows: RST is the online programming input control terminal, which is kept high only during the ISP download process. When the system is working normally, this pin is the system reset terminal and keeps the low state. MOSI is the data input of the master output/slave. When the system is working normally, this pin is the common I/OP1.5 port line. MISO is the data side of the master input/slave output. When the system is working normally, this pin is a general-purpose I/OP1.6 port line. SCK is the serial programming clock terminal that synchronizes the master and slave timings. When the system is working normally, this pin is a general-purpose I/OP1.7 port line. The clock circuit pins include the XTAL1 and XTAL2 pins.
举例而言,本实施例的系统中,单片机的上位机是DM8147,DM8147为TI公司的达芬奇架构的高性能,低功耗处理器,为系统的主控制器,单片机作为控制系统中的一部分,主要负责矩阵按键扫描,与DM8147通过串口进行双向通信,DM8147通过SPI接口对单片机进行程序加载。For example, in the system of the embodiment, the upper computer of the single chip microcomputer is the DM8147, and the DM8147 is a high performance, low power consumption processor of the DaVinci architecture of the TI company, which is the main controller of the system, and the single chip microcomputer is used as the control system. Part of it is mainly responsible for matrix button scanning, and two-way communication with the DM8147 through the serial port. The DM8147 loads the program through the SPI interface.
本系统环境:软件ARM :UbuntuThe system environment: software ARM: Ubuntu
DSP: SysbiosDSP: Sysbios
EZSDK EZSDK
本实施例的单片机在线编程的方法包括以下步骤:The method for online programming of the single chip of the embodiment includes the following steps:
S20、处理器读入要加载的单片机固件程序文件,所述单片机的固件程序文件格式为BIN文件。单片机固件程序文件可以放在SD卡或NAND Flash中。其中,Nand-flash内存是flash内存的一种,其内部采用非线性宏单元模式,为固态大容量内存的实现提供了廉价有效的解决方法。本实施例中,单片机固件程序文件放在SD卡中,系统从SD卡启动后,读取加载文件。S20. The processor reads in the firmware file of the single chip to be loaded, and the firmware program file format of the single chip is a BIN file. The MCU firmware program file can be placed on the SD card or NAND In Flash. Among them, Nand-flash memory is a kind of flash memory, and its internal non-linear macro cell mode provides a cheap and effective solution for the realization of solid-state large-capacity memory. In this embodiment, the firmware file of the single chip is placed in the SD card, and the system reads the loaded file after booting from the SD card.
S21、校验所述单片机固件程序文件的大小是否正确,若正确,则进入步骤S22。S21. Verify that the size of the firmware file of the single chip is correct. If yes, proceed to step S22.
S22、所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中。S22. The processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
具体地,请参阅图7,上述步骤S22包括:Specifically, referring to FIG. 7, the foregoing step S22 includes:
S220、所述单片机上电,所述单片机的RST引脚拉高,并在所述单片机XTAL1和XTAL2引脚之间连接晶振;或者,在XTAL1引脚提供一个3MHz-163MHz的时钟,并且至少等待10μs。S220, the single chip is powered on, the RST pin of the single chip is pulled high, and a crystal oscillator is connected between the XTAL1 and XTAL2 pins of the single chip; or a 3MHz-163MHz clock is provided on the XTAL1 pin, and at least waiting 10μs.
S221、通过所述单片机的MOSI/P 1.5引脚执行编程使能命令,再执行其它编程命令;且,所述单片机的SCK/P1.7引脚上的移位时钟小于所述处理器的1/16。本步骤S221中,编程使能命令作为其它命令的前导命令,必须先执行编程使能命令,再执行其他命令。S221, passing the MOSI/P of the single chip microcomputer The 1.5 pin executes the program enable command and then executes other program commands; and the shift clock on the SCK/P1.7 pin of the microcontroller is less than 1/16 of the processor. In this step S221, the program enable command is used as the leading command of other commands, and the program enable command must be executed first, and then other commands are executed.
S23、所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验。S23. The processor performs verification on the BIN file written in the FLASH of the single chip microcomputer.
请参阅图8,上述步骤S23进一步包括:Referring to FIG. 8, the above step S23 further includes:
S230、所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件。S230. The processor reads the written BIN file from the FLASH of the single chip by using the SPI interface.
具体地,处理器通过读MISO/P 1.6引脚来进行校验。任何一个存储空间都可以通过读MISO/P 1.6引脚来进行校验,通过该引脚返回该地址空间中的数据。Specifically, the processor performs verification by reading the MISO/P 1.6 pin. Any storage space can be read by reading MISO/P The 1.6 pin is used for verification, and the data in the address space is returned through this pin.
S231、所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同则判断为加载成功,并结束加载,进入步骤S24;若不同则判断为加载失败,并重新加载。S231, the processor compares whether the content of the read BIN file and the written BIN file are the same. If the same, it is determined that the loading is successful, and the loading is ended, and the process proceeds to step S24; if not, the loading is determined to be failed and reloaded. .
S24、拉低所述单片机的RST引脚,以使所述单片机在正常模式工作。S24. Pull down the RST pin of the single chip to enable the single chip to work in a normal mode.
通过本发明的在线编程方法不需要任何外部连线,只需要插上SD卡后将系统上电即可,加载会自动进行,并校验。The online programming method of the present invention does not require any external connection, and only needs to be plugged in the SD card to power on the system, and the loading is automatically performed and verified.
通过对使用本发明的在线编程的方法加载大小固定的文件的测试进一步验证了本发明的方法的快速和可靠性。该测试包括写,读并校验的完整过程。通过本发明的方法进行加载的速度要比通过仿真器加载的速度快至少20倍(仿真器加载只算纯加载时间,不算连接仿真器时间),可以达到375KHz,并且在该频率下,在加载700次(单片机Flash的擦写寿命为1000次)的情况下,误码率为0,也就是说700次的加载,100%成功。The speed and reliability of the method of the present invention was further verified by testing the loading of fixed size files using the in-circuit programming method of the present invention. This test includes the complete process of writing, reading and verifying. By the method of the present invention, the loading speed is at least 20 times faster than the loading speed by the emulator (the emulator loading is only the pure loading time, not counting the emulator time), and can reach 375 KHz, and at this frequency, When loading 700 times (the erasing life of the MCU Flash is 1000 times), the bit error rate is 0, that is, 700 times of loading, 100% success.
本发明的通过SPI接口进行在线编程的方法相比GPIO模拟加载时序的方法具有更高的可靠性和稳定性,因为SPI是专用接口,是通过硬件电路来实现单片机的加载时序的。在操作系统下,任何一段任务对于操作系统都是一个线程,操作系统来控制线程的调度,是线程就有可能被打断,通过SPI接口进行加载也可能被其他线程打断,通过SPI接口进行加载,发送一个byte的数据只是一个指令,一个指令不可能被打断,即,通过SPI接口进行加载,不可能在传输一个byte的中间被打断。因此,即使加载被打断也不会影响加载时序,其他线程执行完又返回到该加载线程时,可以继续在下一个地址加载下一个byte数据。而对于通过GPIO模拟的情况,加载一bit位数据就需要三条指令:时钟拉低、输出数据、时钟拉高。加载一个byte数据(8bit)就需要24条指令,很容易在加载一个byte中间被打断,将完全打乱如图3所要求的时序,就很可能造成加载失败。并且指令越多对处理器的占用就越高,这也是GPIO模拟加载相比通过SPI接口进行加载较弱的地方。通过SPI接口进行加载的方法,在发出传送一个byte指令后就释放处理器,直到该byte传完。而GPIO模拟的方式会一直占用处理器,直到被其他线程打断。由于SPI对于处理器是一个自带的外设,处理器只需要通知SPI外设现在要发送数据,至于数据的时序以及实际发送都是由SPI外设来控制的,所以,处理器在通知完SPI外设发送数据或接收后就可以不参与具体的发送或接收数据过程,处理器正常情况下不干预实际的发送过程,除非SPI外设发生错误。而GPIO模拟的情况需要处理器来控制并完成整个时序,那么数据的发送或接收就变成了处理器的一个线程,而线程都是分时执行的,因而该线程会被中断。The method of online programming through the SPI interface of the invention has higher reliability and stability than the method of GPIO analog loading timing, because the SPI is a dedicated interface, and the loading timing of the single chip is realized by a hardware circuit. Under the operating system, any task is a thread for the operating system, the operating system controls the scheduling of the thread, the thread may be interrupted, the loading through the SPI interface may also be interrupted by other threads, through the SPI interface Loading, sending a byte of data is just an instruction, an instruction can not be interrupted, that is, loading through the SPI interface, it is impossible to be interrupted in the middle of transmitting a byte. Therefore, even if the load is interrupted, it will not affect the load timing. When other threads finish executing and return to the load thread, they can continue to load the next byte data at the next address. For the case of GPIO emulation, loading one bit of data requires three instructions: the clock is pulled low, the output data, and the clock is pulled high. Loading a byte of data (8bit) requires 24 instructions, it is easy to interrupt in the middle of loading a byte, will completely disrupt the timing as shown in Figure 3, it is likely to cause loading failure. And the more instructions, the higher the occupation of the processor, which is also the weaker loading of GPIO analog loading compared to the SPI interface. The method of loading through the SPI interface releases the processor after issuing a byte instruction until the byte is transmitted. The way GPIO is simulated will always occupy the processor until it is interrupted by other threads. Since the SPI is a self-contained peripheral for the processor, the processor only needs to inform the SPI peripheral that it is now sending data. As for the timing and actual transmission of the data, it is controlled by the SPI peripheral. Therefore, the processor is notified. After the SPI peripheral sends data or receives it, it can not participate in the specific process of sending or receiving data. The processor does not normally intervene in the actual transmission process unless an error occurs in the SPI peripheral. The GPIO emulation requires the processor to control and complete the entire sequence, then the data is sent or received into a thread of the processor, and the thread is executed in a time-sharing manner, so the thread will be interrupted.
本发明还提供一种单片机,所述单片机包括处理器和存储器,处理器和存储器可以是通过总线连接的,当然也可以采用其它的连接方式。The invention also provides a single chip microcomputer, the single chip microcomputer comprises a processor and a memory, and the processor and the memory may be connected by a bus, and of course, other connection manners may also be adopted.
其中所述处理器用于执行一种在线编程的方法,该方法包括如下步骤:The processor is configured to perform a method for online programming, the method comprising the following steps:
处理器读入要加载的单片机固件程序文件,所述单片机的固件程序文件格式为BIN文件;The processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中。The processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
其中,所述处理器还用于执行:Wherein, the processor is further configured to execute:
所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验。The processor verifies the BIN file written in the FLASH of the single chip microcomputer.
其中,在所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验的步骤中,所述处理器用于执行:Wherein, in the step of the processor verifying the BIN file written in the FLASH of the single chip microcomputer, the processor is configured to execute:
所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件;The processor reads the written BIN file from the FLASH of the single chip microcomputer through the SPI interface;
所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同则判断为加载成功,并结束加载;若不同则判断为加载失败,并重新加载。The processor compares whether the content of the read BIN file and the written BIN file are the same. If they are the same, it is determined that the loading is successful, and the loading is ended; if not, it is determined that the loading fails and is reloaded.
其中,所述单片机包括ISP引脚和时钟电路引脚;Wherein, the single chip microcomputer comprises an ISP pin and a clock circuit pin;
所述ISP引脚包括:RST引脚、MOSI引脚、MISO引脚和SCK引脚;所述RST为在线编程输入控制引脚;所述MOSI引脚为主机输出/从机输入的数据引脚;所述MISO引脚为主机输入/从机输出的数据引脚;所述SCK引脚为串行编程的时钟引脚;The ISP pin includes: an RST pin, a MOSI pin, a MISO pin, and an SCK pin; the RST is an in-circuit programming input control pin; and the MOSI pin is a data pin of a host output/slave input. The MISO pin is a data pin of a master input/slave output; the SCK pin is a serially programmed clock pin;
所述时钟电路引脚包括XTAL1和XTAL2引脚;The clock circuit pin includes XTAL1 and XTAL2 pins;
所述处理器在执行所述通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤之前,所述处理器还用于执行:The processor is further configured to: before executing the step of writing the BIN file into the FLASH of the single chip through the SPI interface, the processor is further configured to:
所述单片机上电,所述单片机的RST引脚拉高,并在所述单片机XTAL1和XTAL2引脚之间连接晶振;或者,在XTAL1引脚提供一个3MHz-163MHz的时钟,并且至少等待10μs;The microcontroller is powered on, the RST pin of the single chip is pulled high, and a crystal oscillator is connected between the XTAL1 and XTAL2 pins of the single chip; or, a clock of 3 MHz-163 MHz is provided on the XTAL1 pin, and at least 10 μs is waited;
通过所述单片机的MOSI/P 1.5引脚执行编程使能命令,再执行其它编程命令。The program enable command is executed through the MOSI/P 1.5 pin of the microcontroller, and other programming commands are executed.
其中,所述单片机的SCK/P1.7引脚上的移位时钟小于所述处理器的1/16。The shift clock on the SCK/P1.7 pin of the single chip microcomputer is smaller than 1/16 of the processor.
其中,所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件的步骤中,所述处理器通过读MISO/P 1.6引脚来进行校验。The processor reads the written BIN file from the FLASH of the single-chip microcomputer through the SPI interface, and the processor reads the MISO/P 1.6 pin for verification.
其中,所述处理器通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤中,所述BIN文件以一次一字节的模式写入;或者以一次一页的模式写入。Wherein, the processor writes the BIN file into the FLASH of the single chip through the SPI interface, the BIN file is written in a one-byte mode; or is written in a one-page mode.
其中,在所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同判断为加载成功,并结束加载的步骤之后,所述处理器还用于执行:拉低所述单片机的RST引脚,以使所述单片机在正常模式工作。Wherein, the processor compares whether the content of the read BIN file and the written BIN file are the same, and if the same determination is that the loading is successful, and the step of ending the loading, the processor is further configured to: lower the The RST pin of the microcontroller is used to operate the microcontroller in normal mode.
其中,在所述处理器读入要加载的单片机固件程序文件的步骤之后,所述处理器还用于执行:校验所述单片机固件程序文件的大小是否正确,若正确,则进入所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中的步骤。After the step of the processor reading the firmware program file of the microcontroller to be loaded, the processor is further configured to: verify that the size of the firmware file of the microcontroller is correct, and if yes, enter the processing. The step of writing the BIN file of the firmware file of the single-chip microcomputer to the FLASH of the single-chip microcomputer through the SPI interface.
另外本发明还提供一种电子设备,所述电子设备包括单片机,所述单片机包括处理器和存储器,其中所述处理器用于执行如下方法:In addition, the present invention also provides an electronic device, the electronic device including a single chip microcomputer, the single chip microcomputer includes a processor and a memory, wherein the processor is configured to perform the following method:
处理器读入要加载的单片机固件程序文件,所述单片机的固件程序文件格式为BIN文件;The processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中。The processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
该电子设备包括的单片机即为前述实施例所描述的单片机,关于该单片机的结构和运行原理可参考前述实施例的描述,在此不再赘述。The single-chip microcomputer included in the electronic device is the single-chip microcomputer described in the foregoing embodiment. For the structure and operation principle of the single-chip microcomputer, reference may be made to the description of the foregoing embodiment, and details are not described herein again.
本发明的电子设备、单片机及其在线编程的方法通过SPI接口对单片机进行加载,实现了高速加载,且提高了成功率,具有较高的可靠性。The electronic device, the single chip computer and the online programming method thereof of the invention load the single chip through the SPI interface, realize high speed loading, improve the success rate and have high reliability.
以上所述仅为本发明的部分实施例,并非因此限制本发明的保护范围,凡是利用本发明说明书及附图内容所作的等效装置或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。The above description is only a part of the embodiments of the present invention, and is not intended to limit the scope of the present invention. Any equivalent device or equivalent process transformation made by using the description of the present invention and the contents of the drawings may be directly or indirectly applied to other related The technical field is equally included in the scope of patent protection of the present invention.

Claims (20)

  1. 一种单片机在线编程的方法,其特征在于,包括以下步骤:A method for online programming of a single chip microcomputer, characterized in that the method comprises the following steps:
    处理器读入要加载的单片机固件程序文件,所述单片机的固件程序文件格式为BIN文件;The processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
    所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中。The processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
  2. 根据权利要求1所述的方法,其特征在于,所述处理器通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤之后还包括:The method according to claim 1, wherein the step of the processor writing the BIN file to the FLASH of the single chip microcomputer through the SPI interface further comprises:
    所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验。The processor verifies the BIN file written in the FLASH of the single chip microcomputer.
  3. 根据权利要求2所述的方法,其特征在于,所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验的步骤进一步包括:The method according to claim 2, wherein the step of verifying, by the processor, the BIN file written in the FLASH of the single chip microcomputer further comprises:
    所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件;The processor reads the written BIN file from the FLASH of the single chip microcomputer through the SPI interface;
    所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同则判断为加载成功,并结束加载;若不同则判断为加载失败,并重新加载。The processor compares whether the content of the read BIN file and the written BIN file are the same. If they are the same, it is determined that the loading is successful, and the loading is ended; if not, it is determined that the loading fails and is reloaded.
  4. 根据权利要求3所述的方法,其特征在于,所述单片机包括ISP引脚和时钟电路引脚;The method of claim 3 wherein said microcontroller comprises an ISP pin and a clock circuit pin;
    所述ISP引脚包括:RST引脚、MOSI引脚、MISO引脚和SCK引脚;所述RST为在线编程输入控制引脚;所述MOSI引脚为主机输出/从机输入的数据引脚;所述MISO引脚为主机输入/从机输出的数据引脚;所述SCK引脚为串行编程的时钟引脚;The ISP pin includes: an RST pin, a MOSI pin, a MISO pin, and an SCK pin; the RST is an in-circuit programming input control pin; and the MOSI pin is a data pin of a host output/slave input. The MISO pin is a data pin of a master input/slave output; the SCK pin is a serially programmed clock pin;
    所述时钟电路引脚包括XTAL1和XTAL2引脚;The clock circuit pin includes XTAL1 and XTAL2 pins;
    所述处理器通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤之前包括:Before the step of writing the BIN file into the FLASH of the single chip microcomputer through the SPI interface, the processor includes:
    所述单片机上电,所述单片机的RST引脚拉高,并在所述单片机XTAL1和XTAL2引脚之间连接晶振;或者,在XTAL1引脚提供一个3MHz-163MHz的时钟,并且至少等待10μs;The microcontroller is powered on, the RST pin of the single chip is pulled high, and a crystal oscillator is connected between the XTAL1 and XTAL2 pins of the single chip; or, a clock of 3 MHz-163 MHz is provided on the XTAL1 pin, and at least 10 μs is waited;
    通过所述单片机的MOSI/P 1.5引脚执行编程使能命令,再执行其它编程命令。The program enable command is executed through the MOSI/P 1.5 pin of the microcontroller, and other programming commands are executed.
  5. 根据权利要求4所述的方法,其特征在于,所述单片机的SCK/P1.7引脚上的移位时钟小于所述处理器的1/16。The method of claim 4 wherein the shift clock on the SCK/P1.7 pin of the microcontroller is less than 1/16 of the processor.
  6. 根据权利要求5所述的方法,其特征在于,所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件的步骤中,所述处理器通过读MISO/P 1.6引脚来进行校验。The method according to claim 5, wherein said processor reads said written BIN file from said FLASH of said microcontroller through said SPI interface, said processor reading MISO/ P 1.6 pin for verification.
  7. 根据权利要求6所述的方法,其特征在于,所述处理器通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤中,所述BIN文件以一次一字节的模式写入;或者以一次一页的模式写入。The method according to claim 6, wherein the processor writes the BIN file into the FLASH of the single chip microcomputer through an SPI interface, and the BIN file is written in a one-byte mode; Or write in a one-page mode.
  8. 根据权利要求7所述的方法,其特征在于,所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同判断为加载成功,并结束加载的步骤之后,还包括:拉低所述单片机的RST引脚,以使所述单片机在正常模式工作。The method according to claim 7, wherein the processor compares whether the contents of the read BIN file and the written BIN file are the same, and if the same judgment is that the loading is successful, and the step of ending the loading is further included : Pull down the RST pin of the microcontroller to enable the microcontroller to operate in normal mode.
  9. 根据权利要求1所述的方法,其特征在于,所述处理器读入要加载的单片机固件程序文件的步骤之后,还包括:校验所述单片机固件程序文件的大小是否正确,若正确,则进入所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中的步骤。The method according to claim 1, wherein after the step of reading the firmware file of the microcontroller to be loaded by the processor, the method further comprises: verifying whether the size of the firmware file of the microcontroller is correct, if correct, The step of writing the BIN file of the firmware file of the single chip to the FLASH of the single chip by the processor through the SPI interface.
  10. 根据权利要求1所述的方法,其特征在于,所述处理器读入要加载的单片机固件程序文件的步骤中,所述要加载的单片机固件程序文件放在SD卡或者NAND Flash中。The method according to claim 1, wherein in the step of reading the firmware file of the microcontroller to be loaded by the processor, the firmware file of the microcontroller to be loaded is placed on an SD card or NAND. In Flash.
  11. 一种单片机,其特征在于,所述单片机包括处理器和存储器,其中所述处理器用于执行如下方法:A single chip microcomputer, characterized in that the single chip microcomputer comprises a processor and a memory, wherein the processor is configured to perform the following method:
    处理器读入要加载的单片机固件程序文件,所述单片机的固件程序文件格式为BIN文件;The processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
    所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中。The processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
  12. 根据权利要求11所述的单片机,其特征在于,所述处理器还用于执行:The single chip microcomputer according to claim 11, wherein the processor is further configured to:
    所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验。The processor verifies the BIN file written in the FLASH of the single chip microcomputer.
  13. 根据权利要求12所述的单片机,其特征在于,在所述处理器对所述写入到单片机的FLASH中的BIN文件进行校验的步骤中,所述处理器用于执行:The single chip microcomputer according to claim 12, wherein in the step of verifying, by the processor, the BIN file written in the FLASH of the single chip microcomputer, the processor is configured to execute:
    所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件;The processor reads the written BIN file from the FLASH of the single chip microcomputer through the SPI interface;
    所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同则判断为加载成功,并结束加载;若不同则判断为加载失败,并重新加载。The processor compares whether the content of the read BIN file and the written BIN file are the same. If they are the same, it is determined that the loading is successful, and the loading is ended; if not, it is determined that the loading fails and is reloaded.
  14. 根据权利要求13所述的单片机,其特征在于,所述单片机包括ISP引脚和时钟电路引脚;The single chip microcomputer according to claim 13, wherein said single chip microcomputer comprises an ISP pin and a clock circuit pin;
    所述ISP引脚包括:RST引脚、MOSI引脚、MISO引脚和SCK引脚;所述RST为在线编程输入控制引脚;所述MOSI引脚为主机输出/从机输入的数据引脚;所述MISO引脚为主机输入/从机输出的数据引脚;所述SCK引脚为串行编程的时钟引脚;The ISP pin includes: an RST pin, a MOSI pin, a MISO pin, and an SCK pin; the RST is an in-circuit programming input control pin; and the MOSI pin is a data pin of a host output/slave input. The MISO pin is a data pin of a master input/slave output; the SCK pin is a serially programmed clock pin;
    所述时钟电路引脚包括XTAL1和XTAL2引脚;The clock circuit pin includes XTAL1 and XTAL2 pins;
    所述处理器在执行所述通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤之前,所述处理器还用于执行:The processor is further configured to: before executing the step of writing the BIN file into the FLASH of the single chip through the SPI interface, the processor is further configured to:
    所述单片机上电,所述单片机的RST引脚拉高,并在所述单片机XTAL1和XTAL2引脚之间连接晶振;或者,在XTAL1引脚提供一个3MHz-163MHz的时钟,并且至少等待10μs;The microcontroller is powered on, the RST pin of the single chip is pulled high, and a crystal oscillator is connected between the XTAL1 and XTAL2 pins of the single chip; or, a clock of 3 MHz-163 MHz is provided on the XTAL1 pin, and at least 10 μs is waited;
    通过所述单片机的MOSI/P 1.5引脚执行编程使能命令,再执行其它编程命令。The program enable command is executed through the MOSI/P 1.5 pin of the microcontroller, and other programming commands are executed.
  15. 根据权利要求14所述的单片机,其特征在于,所述单片机的SCK/P1.7引脚上的移位时钟小于所述处理器的1/16。The microcontroller of claim 14 wherein the shift clock on the SCK/P1.7 pin of the microcontroller is less than 1/16 of the processor.
  16. 根据权利要求15所述的单片机,其特征在于,所述处理器通过所述SPI接口从所述单片机的FLASH中读取所述写入的BIN文件的步骤中,所述处理器通过读MISO/P 1.6引脚来进行校验。The single chip microcomputer according to claim 15, wherein the processor reads the written BIN file from the FLASH of the single chip microcomputer through the SPI interface, and the processor reads MISO/ P 1.6 pin for verification.
  17. 根据权利要求16所述的单片机,其特征在于,所述处理器通过SPI接口将所述BIN文件写入到单片机的FLASH中的步骤中,所述BIN文件以一次一字节的模式写入;或者以一次一页的模式写入。The single chip microcomputer according to claim 16, wherein the processor writes the BIN file into the FLASH of the single chip microcomputer through an SPI interface, and the BIN file is written in a one-byte mode; Or write in a one-page mode.
  18. 根据权利要求17所述的单片机,其特征在于,在所述处理器比较读取的BIN文件和写入的BIN文件的内容是否相同,若相同判断为加载成功,并结束加载的步骤之后,所述处理器还用于执行:拉低所述单片机的RST引脚,以使所述单片机在正常模式工作。The single chip microcomputer according to claim 17, wherein the processor compares whether the content of the read BIN file and the written BIN file are the same, and if the same judgment is that the loading is successful, and the step of loading is finished, The processor is further configured to: pull down the RST pin of the microcontroller to enable the microcontroller to operate in a normal mode.
  19. 根据权利要求18所述的单片机,其特征在于,在所述处理器读入要加载的单片机固件程序文件的步骤之后,所述处理器还用于执行:校验所述单片机固件程序文件的大小是否正确,若正确,则进入所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中的步骤。The single chip microcomputer according to claim 18, wherein after the step of the processor reading the firmware program file of the microcontroller to be loaded, the processor is further configured to: verify the size of the firmware file of the microcontroller Whether it is correct, if correct, enter the step of the processor writing the BIN file of the firmware file of the single chip to the FLASH of the single chip through the SPI interface.
  20. 一种电子设备,其特征在于,所述电子设备包括单片机,所述单片机包括处理器和存储器,其中所述处理器用于执行如下步骤:An electronic device, characterized in that the electronic device comprises a single chip microcomputer, the single chip microcomputer comprises a processor and a memory, wherein the processor is configured to perform the following steps:
    处理器读入要加载的单片机固件程序文件,所述单片机的固件程序文件格式为BIN文件;The processor reads in the firmware program file of the MCU to be loaded, and the firmware program file format of the MCU is a BIN file;
    所述处理器通过SPI接口将所述单片机固件程序文件的BIN文件写入到单片机的FLASH中。The processor writes the BIN file of the firmware file of the single chip to the FLASH of the single chip microcomputer through an SPI interface.
PCT/CN2016/072784 2015-02-11 2016-01-29 Single chip microcomputer and online programming method therefor WO2016127835A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510072752.3 2015-02-11
CN201510072752.3A CN104679559B (en) 2015-02-11 2015-02-11 The method of single-chip microcontroller online programming

Publications (1)

Publication Number Publication Date
WO2016127835A1 true WO2016127835A1 (en) 2016-08-18

Family

ID=53314656

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/072784 WO2016127835A1 (en) 2015-02-11 2016-01-29 Single chip microcomputer and online programming method therefor

Country Status (2)

Country Link
CN (1) CN104679559B (en)
WO (1) WO2016127835A1 (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109343870A (en) * 2018-12-06 2019-02-15 中电智能科技有限公司 Program burn writing equipment and program burn writing system
CN111352893A (en) * 2020-02-21 2020-06-30 烟台持久钟表有限公司 Communication method of FPGA and STM32 single chip microcomputer
CN111538488A (en) * 2020-04-17 2020-08-14 荏原冷热系统(中国)有限公司 Method and device for generating single-chip microcomputer driving program
CN112445540A (en) * 2020-11-10 2021-03-05 惠州市创荣发智能科技有限公司 Program operation method, system, terminal and storage medium

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104679559B (en) * 2015-02-11 2019-06-18 北京配天技术有限公司 The method of single-chip microcontroller online programming
CN105300720A (en) * 2015-11-16 2016-02-03 合肥美的电冰箱有限公司 Detection method and system of refrigerator and refrigerator
CN105808298B (en) * 2016-03-08 2019-02-12 大连楼兰科技股份有限公司 A kind of dynamic loading method of single-chip microcontroller lower module
CN110399596A (en) * 2019-07-26 2019-11-01 浪潮电子信息产业股份有限公司 A kind of file layout change-over method, system and associated component
CN111124456A (en) * 2019-12-26 2020-05-08 深圳市丰润达科技有限公司 Method and device for upgrading firmware of single chip microcomputer through master control and readable storage medium
CN111752589A (en) * 2020-06-24 2020-10-09 研祥智能科技股份有限公司 Method and device for upgrading burning codes of microcontroller on line
CN112905161A (en) * 2021-02-27 2021-06-04 深圳市博盛科电子有限公司 OBD-based automobile online programming method

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101042815A (en) * 2007-01-19 2007-09-26 华南理工大学 Single chip computer teaching experimental device based on on-line programmable logic device
CN202189493U (en) * 2011-05-05 2012-04-11 杭州电子科技大学 89S51 ISP singlechip modularized experiment development platform
CN102609286A (en) * 2012-02-10 2012-07-25 株洲南车时代电气股份有限公司 System for updating FPGA (Field Programmable Gate Array) configuration program from a long distance based on control of processor and method therefor
CN102945173A (en) * 2012-10-31 2013-02-27 青岛海信宽带多媒体技术有限公司 User program on-line upgrading system and method
CN104679559A (en) * 2015-02-11 2015-06-03 北京配天技术有限公司 Single chip microcomputer on-line programming method

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040076166A1 (en) * 2002-10-21 2004-04-22 Patenaude Jean-Marc Guy Multi-service packet network interface
CN102184741A (en) * 2011-02-28 2011-09-14 浪潮电子信息产业股份有限公司 Method for programming serial periphery interface (SPI) FLASH
CN103365873B (en) * 2012-03-28 2016-08-10 阿里巴巴集团控股有限公司 The method for pushing of business datum and device
CN202956753U (en) * 2012-11-05 2013-05-29 汕尾芯灵电子科技有限公司 Programming device and programming system of flash memory chip in embedded system
CN103034515B (en) * 2012-12-11 2015-11-25 北京遥测技术研究所 A kind of satellite navigation receiver FPGA rapid loading method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101042815A (en) * 2007-01-19 2007-09-26 华南理工大学 Single chip computer teaching experimental device based on on-line programmable logic device
CN202189493U (en) * 2011-05-05 2012-04-11 杭州电子科技大学 89S51 ISP singlechip modularized experiment development platform
CN102609286A (en) * 2012-02-10 2012-07-25 株洲南车时代电气股份有限公司 System for updating FPGA (Field Programmable Gate Array) configuration program from a long distance based on control of processor and method therefor
CN102945173A (en) * 2012-10-31 2013-02-27 青岛海信宽带多媒体技术有限公司 User program on-line upgrading system and method
CN104679559A (en) * 2015-02-11 2015-06-03 北京配天技术有限公司 Single chip microcomputer on-line programming method

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109343870A (en) * 2018-12-06 2019-02-15 中电智能科技有限公司 Program burn writing equipment and program burn writing system
CN109343870B (en) * 2018-12-06 2024-04-16 中电智能科技有限公司 Program programming device and program programming system
CN111352893A (en) * 2020-02-21 2020-06-30 烟台持久钟表有限公司 Communication method of FPGA and STM32 single chip microcomputer
CN111352893B (en) * 2020-02-21 2023-06-20 烟台持久钟表有限公司 Communication method of FPGA and STM32 singlechip
CN111538488A (en) * 2020-04-17 2020-08-14 荏原冷热系统(中国)有限公司 Method and device for generating single-chip microcomputer driving program
CN111538488B (en) * 2020-04-17 2023-05-02 荏原冷热系统(中国)有限公司 Method and device for generating single-chip microcomputer driver
CN112445540A (en) * 2020-11-10 2021-03-05 惠州市创荣发智能科技有限公司 Program operation method, system, terminal and storage medium
CN112445540B (en) * 2020-11-10 2023-05-09 惠州市创荣发智能科技有限公司 Program running method, system, terminal and storage medium

Also Published As

Publication number Publication date
CN104679559B (en) 2019-06-18
CN104679559A (en) 2015-06-03

Similar Documents

Publication Publication Date Title
WO2016127835A1 (en) Single chip microcomputer and online programming method therefor
CN110865971A (en) System and method for verifying SOC chip
WO2013174169A1 (en) Upgrade method for capacitive screen firmware of android mobile terminal
CN115184781B (en) Chip testing method and system
CN106773954A (en) A kind of operating mode control method in microcontroller chip
CN102520961A (en) Off-chip online programmable SOC (system on a chip) and control method for same
WO2024046362A1 (en) Verification system, verification method, electronic device, and storage medium
US20190271740A1 (en) Non-intrusive on-chip debugger with remote protocol support
WO2017075852A1 (en) Method and system for protecting working program of mcu
CN101814054B (en) Instruction tracing controller for debugging microcontroller
CN110888656A (en) Multifunctional programming device and programming method
CN110262349A (en) A kind of the remote online programmed method and system of C8051F series monolithic
CN109656604A (en) A kind of remote hardware upgrade method based on Ethernet
WO2013042972A2 (en) Flash memory storage unit capable of verifying reliability using a bypass path, and a system and method for verifying reliability of the flash memory storage unit using same
CN216848733U (en) Novel embedded debugging equipment
JPS6349851A (en) Simulation system
CN100455031C (en) Apparatus and method for carrying out random treatment to memory data
CN114253561B (en) System and method for automatically burning firmware
CN213814650U (en) USB function test board
CN107066301A (en) A kind of method for down loading of embedded computer firmware program
JP4484417B2 (en) Debug system
Liao et al. Design of reusable software for USB host driver in embedded system
Shilaskar et al. Post Silicon Validation for I2C (SMBUS) Peripheral
Liu et al. SLT Test Scheme Based on MCU
JP4084912B2 (en) Microprocessor system

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16748636

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16748636

Country of ref document: EP

Kind code of ref document: A1