Flash-based board card online upgrading method

By using a flash-based online upgrade method for DSP boards, the problem of inconvenient upgrades for the GD32F4xx series DSP boards in packaging equipment is solved. This method enables online upgrades without the need for an emulator, providing a flexible upgrade solution.

CN121364877APending Publication Date: 2026-01-20TIANJIN JINHANG COMP TECH RES INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511458450.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-13
Publication Date
2026-01-20

AI Technical Summary

Technical Problem

In the existing technology, upgrading the GD32F4xx series DSP board requires inserting an emulator or programming tool into the board, which makes upgrading in the packaged device inconvenient.

Method used

Design a flash-based online upgrade method for circuit boards. By creating a boot program, an application bin file, and using a host computer tool, online upgrades can be achieved without inserting an emulator. The method includes steps such as initializing GPIO, serial port settings, interrupt reception, DMA module processing, and Flash programming module configuration.

Benefits of technology

Online upgrades for the GD32F4xx series DSP boards have been implemented, resolving upgrade difficulties caused by site or equipment issues and providing a flexible upgrade solution.

✦ Generated by Eureka AI based on patent content.
Patent Text Reader

Abstract

The invention belongs to the technical field of AD simulation data application programs under a DSP system, and discloses a flash-based board card online upgrading method which comprises the following steps: S1, creating a boot program; s2, creating a bin file of the application program; and S3, upgrading the application program by using an upper computer tool. According to the method, a scheme is provided for solving the online upgrading problem of DSP types, upgrading can be achieved according to different choices of users, and the problem that upgrading is difficult due to site or equipment problems is effectively solved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of AD analog data application program under the DSP system, and aims at the characteristics of the DSP board card and the characteristics of the flash and serial port in the application scene of the system for dsp, and designs a kind of board card online upgrading method based on flash. BACKGROUND

[0002] The GD32F4xx series device is a 32-bit general-purpose microcontroller based on ARM® Cortex™-M4 processor. The ARM® Cortex™-M4 processor includes three AHB buses, which are called I-CODE bus, D-Code bus and system bus. All memory accesses of the Cortex™-M4 processor are performed on the three buses according to different purposes and target memory spaces. The organization of the memory adopts the Harvard structure, the pre-defined memory mapping and the storage space up to 4 GB, which fully guarantees the flexibility and scalability of the system.

[0003] Due to the integration characteristics of the chip module, the upgrading of the GD32F4xx series device usually needs to insert the emulator or the burning tool into the board card to complete. In the control system, the device is usually packaged, and it is not convenient for the technician to operate when upgrading. SUMMARY

[0004] (I) Invention purpose The purpose of the application is to provide a kind of board card online upgrading method based on flash, solve the online problem of GD32F4xx series DSP board card under embedded system.

[0005] (II) Technical scheme In order to solve the above technical problems, the application provides a kind of board card online upgrading method based on flash, which includes the following steps: S1: creating boot program; S2: creating application program bin file; S3: upgrading application program using host computer tool.

[0006] Further, step S1 includes the following sub-steps: S1.1 initializes the on-off quantity GPIOA15 of the board card; S1.2 initializes the serial port setting of the boot program receiving serial port data burning; S1.3 interrupt receiving serial port data; S1.4 handles the dma module interrupt; S1.5 configures Flash burning module; S1.6 gets the selection of host computer user; S1.7 Set the card according to user selection.

[0007] Further, step S1.1 includes the following sub-steps: S1.1.1 Enable the clock of the group where the switch quantity is located using the library function rcu_periph_clock_enable; S1.1.2 Set the sequence number gpio in the group as an input direction using the library function gpio_mode_set.

[0008] Further, step S1.2 includes the following sub-steps: S1.2.1 Enable the clock of the group where the switch quantity used by the serial port is located using the library function; S1.2.2 Enable the clock of the serial port using the library function; S1.2.3 Configure the serial port receiving and transmitting pins GPIOA9 and GPIOA10 using the library function gpio_af_set; S1.2.4 Set the transmitting and receiving pins as a multiplexing function mode GPIO_MODE_AF using the library function gpio_mode_set; S1.2.5 Set the receiving and transmitting pins using the library function gpio_output_option_set; S1.2.6 Disable the selected serial port receiving data USRAR0; S1.2.7 Set the baud rate, check bit, data length, and stop bit of the serial port; S1.2.8 Enable the receiving and transmitting functions of the serial port; S1.2.9 Enable the serial port.

[0009] Further, step S1.3 includes the following sub-steps: S1.3.1 Determine whether the interrupt identifier is reset, if so, exit the process, otherwise proceed to the next step; S1.3.2 Use the library function usart_data_receive to obtain the serial port received data and store it in the receiving array USART_RX, and increase the receiving count count; S1.3.3 Determine whether the first received data is 0x7F, if so, proceed to the next step, otherwise jump to step S1.3.6; S1.3.4 Use the library function usart_data_transmit to send 0x79 to the upper computer; S1.3.5 Use the library function usart_flag_get to wait for the sending completion identifier USART_FLAG_TC to be set to 1, if set, proceed to the next step, otherwise continue to wait; S1.3.6 judge whether the first byte of the receiving array is 0x11 and the second byte is 0xee, if yes, go to next step, otherwise jump to step S1.3.8; S1.3.7 judge whether the count is 2, if yes, go to next step, otherwise repeat steps S1.3.4 and S1.3.5; S1.3.8 judge whether the count is 7, if yes, go to next step, otherwise jump to step S1.3.10; S1.3.9 get data from the 3rd, 4th, 5th and 6th positions of the receiving array and write them into the start address start_addr; S1.3.10 get the check sum check_sum from the 7th position of the receiving array; S1.3.11 check whether the check sum check_sum is correct, if yes, repeat steps S1.3.4 and S1.3.5, otherwise go to next step; S1.3.12 judge whether the count is 9, if yes, go to next step, otherwise jump to step S1.3.18; S1.3.13 get the number of reading memory read_mem_num from the 8th position of the receiving array and get the check sum check_sum from the 9th position; S1.3.14 judge whether the check sum check_sum is successful, if yes, repeat steps S1.3.4 and S1.3.5, otherwise go to next step; S1.3.15 read the data of the start address start_addr and store them in the read_mem_data array; S1.3.16 send the read_mem_data data out through the library function usart_data_transmit; S1.3.17 clear the receiving identifier using the library function usart_rx_clear; S1.3.18 judge whether the first byte and the second byte of the receiving array are 0x06 and 0xf9, if yes, go to next step, otherwise jump to step S1.3.26; S1.3.19 repeat steps S1.3.4 and S1.3.5; S1.3.20 send 0x04 data to the host computer using the library function usart_data_transmit; S1.3.21 repeat step S1.3.5; S1.3.22 read the FMC_PID register using the function read_fmc_pid and put it into the array read_mem_data; S1.3.23 transmit the value in the array read_mem_data to the host computer using the library function usart_data_transmit; S1.3.24 repeat steps S1.3.4 and S1.3.5; S1.3.25 clear the reception flag and the reception count count using the library function usart_rx_clear; S1.3.26 check whether the first byte of the reception array USART_RX is 0 and the second byte is 0xff, if so, proceed to the next step, otherwise jump to step S1.3.33; S1.3.27 repeat steps S1.3.4 and S1.3.5; S1.3.28 transmit 0x0B representing the data length to the host computer and repeat step S1.3.5; S1.3.29 transmit 0x22 to the host computer and repeat step S1.3.5; S1.3.30 transmit the supported command array command_data to the host computer; S1.3.31 repeat steps S1.3.4 and S1.3.5; S1.3.32 clear the reception flag and the reception count count; S1.3.33 check whether the first byte of the reception array USART_RX is 0x44 and the second byte is 0xbb, if so, proceed to the next step, otherwise jump to step 40; S1.3.34 check whether the reception count count is 2, if so, proceed to steps S1.3.4 and S1.3.5, otherwise proceed to the next step; S1.3.35 check whether the reception count is 7, if so, obtain the number of sectors sector_num written from positions 5 and 6 of the reception array USART_RX and the checksum check_sum from the seventh position; S1.3.36 check whether the checksum is correct, if so, proceed to the next step, otherwise jump to step S1.3.38; S1.3.37 erase the sector_num region using the fmc library function, and repeat steps S1.3.4 and S1.3.5; S1.3.38 transmit 0xff to the host computer and repeat step S1.3.5; S1.3.39 clear the receive flag, clear the receive count count; S1.3.40 check if the 1st and 2nd bytes of the receive array USART_RX are 0x31 and 0xCE, if yes, go to next step, otherwise jump to step S1.3.52; S1.3.41 check if the receive count count is 2, if yes, repeat steps S1.3.4, S1.3.5, otherwise go to next step; S1.3.42 check if the receive count count is 7, if yes, get the write address from the 3rd, 4th, 5th and 6th bytes of the receive array, get the check sum check_sum from the 7th byte of the receive array, and go to next step, otherwise jump to step S1.3.44; S1.3.43 check if the check sum is correct, if yes, repeat steps S1.3.4, S1.3.5, otherwise go to next step; S1.3.44 check if the receive count count is 8, if yes, go to next step, otherwise jump to step S1.3.52; S1.3.45 clear the receive count count; S1.3.46 get the number of data num_of_data_write to be written this time from the 8th byte of the receive array; S1.3.47 configure the number of data parameter needed to be sent by the DMA module using the value of num_of_data_write; S1.3.48 configure the serial port receive enable using the library function usart_dma_receive_config; S1.3.49 enable the receive interrupt of the serial port; S1.3.50 enable the 2nd channel of the DMA module; S1.3.51 clear the receive flag; S1.3.52 check if the 1st and 2nd bytes of the receive array USART_RX are 0x21 and 0xDE, if yes, go to next step, otherwise exit the process; S1.3.53 check if the receive count count is 2, if yes, repeat steps S1.3.4, S1.3.5, otherwise go to next step; S1.3.54 check if the receive count count is 7, if yes, go to next step, otherwise exit the process; S1.3.55 clear the receive count count; S1.3.56 get the check sum check_sum from the 7th byte of the receive array; S1.3.57 judge whether the check sum is legal, if yes, repeat S1.3.4, S1.3.5, otherwise go to next step; S1.3.58 clear the receiving flag; S1.3.59 perform system reset operation.

[0010] Further, step S1.4 includes the following sub-steps: S1.4.1 use library function dma_flag_get to get the sending flag of the DMA module, if yes, go to next step, otherwise exit the process; S1.4.2 use library function dma_interrupt_flag_clear to clear the DMA interrupt flag; S1.4.3 disable the channel of the DMA module; S1.4.4 assign the number of data to be written num_of_data_write minus 1 to the first byte of the DMA receiving array rxbuffer, i.e. rxbuffer[0]; S1.4.5 judge whether the check sum of the rxbuffer array is qualified, if yes, go to next step, otherwise exit the process; S1.4.6 use library function FLASH_Program to write the data from memory address start_addr, starting from rxbuffer[1], the total number of data is num_of_data_write plus 1; S1.4.7 judge whether the result of step S1.4.6 is failure, if yes, exit the process, otherwise go to next step; S1.4.8 wait for the serial port sending flag to be ready; S1.4.9 use the serial port to send 0x79; S1.4.10 configure the receiving function of the DMA module to be disabled; S1.4.11 open the receiving interrupt of the serial port to wait for the next data packet.

[0011] Further, step S1.5 includes the following sub-steps: S1.5.1 use library function fmc_unlock to unlock the region of Flash erasing and writing; S1.5.2 use library function fmc_flag_clear to clear all waiting signals; S1.5.3 get the address of writing into the flash; S1.5.4 judge whether the current writing address Address is less than the sum of the writing address write_start_addr and the size of writing data size, if yes, go to next step, otherwise jump to step S1.5.l; S1.5.5 Write data pointed by data array pointer using library function fmc_word_program; S1.5.6 Read data content content in Address; S1.5.7 Compare data content content with data pointed by data array pointer, if same, go to next step, otherwise, exit the process and return failure; S1.5.8 Move data array pointer one position forward; S1.5.9 Move Address four positions; S1.5.10 Clear flag using library function fmc_flag_clear; S1.5.11 Jump to step S1.5.4; S1.5.12 Lock flash erase module using library function fmc_lock; S1.5.13 Return success flag.

[0012] Further, step S1.6 comprises the following sub-steps: S1.6.1 Enter query loop; S1.6.2 Initialize delay count count; S1.6.3 Get state of switch value of upgrade flag using library function gpio_inout_bit_get; S1.6.4 If switch value is low, return 1 indicating that upgrade is needed, otherwise, go to next step; S1.6.5 Delay 100 ms; S1.6.6 Decrease delay count count by 1; S1.6.7 Judge if delay count is greater than 0, if yes, adjust to step S1.6.3, otherwise, go to next step; S1.6.8 Return 0 indicating that upgrade is not needed.

[0013] Further, step S1.7 comprises the following process: If user selects online upgrade, then the following steps are performed: S1.7.1 Initialize DMA function of board card S1.7.1.1 Initialize clock function of DMA module using library function rcu_periph_clock_enable; S1.7.1.2 Disable channel of DMA module using library function dma_deinit; S1.7.1.3 Set the initialization parameters of the dma module, including the external array of memory address data copy, the number of channels, the loop mode, the vector address, the data width, the priority; S1.7.1.4 Use the library function dma_single_data_mode_init to initialize the DMA channel using the parameters; S1.7.1.5 Use the library function dma_circulation_disable to set the channel; S1.7.1.6 Use the library function dma_channel_subperpheral_select to configure the channel mode; S1.7.1.7 Use the library function dma_interrupt_enable to enable the DMA interrupt; S1.7.2 Reset the serial port; S1.7.2.1 Use the library function usart_dma_receive_config to set the serial port receive disable; S1.7.2.2 Use the library function usart_interrupt_enable to set the serial port interrupt enable; S1.7.2.3 Use the library function usart_enable to enable the serial port; S1.7.3 Configure the interrupt of the board card serial port and DMA module; S1.7.3.1 Use the library function nvic_irq_enale to enable the interrupt of the serial port, the interrupt number is USART0_IRQn, that is, the selected serial port usart is interrupt received; S1.7.3.2 Use the library function nvic_irq_enale to enable the interrupt of the DMA, the interrupt number is DMA1_Channel2_IRQn, and the selected channel 2 of the DMA module is interrupt received; If the user selects to run the application directly, the following steps are performed: S1.7.4 Determine whether the result of the bitwise AND operation between the application address pointer ApplicationAddress and 0x2ffe0000 is 0x20000000, if so, proceed to the next step, otherwise print error information; S1.7.5 Use the library function usart_disable to disable the serial port; S1.7.6 Get the result of the offset of 4 addresses of the application address pointer ApplicationAddress, and store the result in the jump address JumpAddress; S1.7.7 convert the jump address JumpAddress into a stack pointer Jump_To_Application; S1.7.8 set the application address pointer ApplicationAddress to the address of the new program reset interrupt function; S1.7.9 execute the application program using the stack pointer Jump_To_Application of the jump address.

[0014] Further, step S2 includes the following sub-steps: S2.1 open the program project to be upgraded in the kerl tool; the BOOT program occupies a space of 0x08000000~0x08002000, and the offset nvic_vector_table_set(NVIC_VECTTAB_FLASH, 0x2000) is added in main, and the offset is modified according to application requirements; S2.2 open the project file to set the IROM1 region of the application program, the start address is 0x08000000, and the size is 0x2000; Set the running option RUN#1 under the User option, and the compilation instruction is: fromelf --bin --output.\Output\Project.bin.\Output\Project.axf; S2.3 after the setting is successful, the project.bin file suitable for the IAP host computer is generated under the output folder of the project when the project is compiled; Step S3 includes the following sub-steps: S3.1 burn the boot program to the board through a burning tool; S3.2 connect the serial port, set the serial port baud rate and check code of the host computer tool, and perform burning after the handshake is successful.

[0015] (Three) beneficial effects The flash-based board online upgrading method provided by the above technical solution provides a solution for the online upgrading problem of the DSP type, and can realize upgrading according to different choices of users, effectively solving the problem of upgrading difficulty caused by site or equipment problems. DETAILED DESCRIPTION

[0016] In order to make the purpose, content and advantages of the present application clearer, the specific embodiments of the present application will be further described in combination with examples.

[0017] The flash-based board online upgrading method of the present embodiment includes the following steps: S1: create a boot program S1.1 Initialize the board's switch quantity GPIOA15 settings. The specific steps are as follows: S1.1.1 Use the library function rcu_periph_clock_enable to enable the clock of the group containing the switch quantity; S1.1.2 Use the library function gpio_mode_set to enable the index gpio in the group as the input direction; S1.2 Initialize the boot program to receive serial port data and program the serial port settings. The specific steps are as follows: S1.2.1 Use library functions to enable the clock of the group containing the switch values ​​used for serial port reception and transmission; S1.2.2 Enable the serial port clock using library functions; S1.2.3 Use the library function gpio_af_set to configure the serial port receive and transmit pins GPIOA9 and GPIOA10; S1.2.4 Use the library function gpio_mode_set to set the transmit and receive pins to the multiplexed function mode GPIO_MODE_AF; S1.2.5 Use the library function gpio_output_option_set to set the receive and transmit pins; S1.2.6 Disable the selected serial port USRAR0 for receiving data; S1.2.7 Set the baud rate, parity, data length, and stop bits for the serial port; S1.2.8 Enables the serial port's receive and transmit functions; S1.2.9 Enable serial port; S1.3 interrupt for receiving serial port data, the specific steps are as follows: S1.3.1 Determine if the interrupt flag has been reset. If yes, exit the process; otherwise, proceed to the next step. S1.3.2 Use the library function usart_data_receive to obtain the data received from the serial port and store it in the receive array USART_RX, and increment the receive count; S1.3.3 Determine if the first received data is 0x7F. If it is, proceed to the next step; otherwise, jump to step S1.3.6. S1.3.4 Use the library function usart_data_transmit to send 0x79 to the host computer; S1.3.5 Use the library function usart_flag_get to wait for the USART_FLAG_TC flag to be set to 1. If it is set, proceed to the next step; otherwise, continue waiting. S1.3.6 judge whether the first byte of the receiving array is 0x11 and the second byte is 0xee, if yes, go to next step, otherwise jump to step S1.3.8; S1.3.7 judge whether the count is 2, if yes, go to next step, otherwise repeat steps S1.3.4 and S1.3.5; S1.3.8 judge whether the count is 7, if yes, go to next step, otherwise jump to step S1.3.10; S1.3.9 get data from the 3rd, 4th, 5th and 6th positions of the receiving array and write into start_addr; S1.3.10 get check_sum from the 7th position of the receiving array; S1.3.11 judge whether the check_sum is correct, if yes, repeat steps S1.3.4 and S1.3.5, otherwise go to next step; S1.3.12 judge whether the count is 9, if yes, go to next step, otherwise jump to step S1.3.18; S1.3.13 get read_mem_num from the 8th position and check_sum from the 9th position of the receiving array; S1.3.14 judge whether the check_sum is correct, if yes, repeat steps S1.3.4 and S1.3.5, otherwise go to next step; S1.3.15 read data in start_addr and store in read_mem_data; S1.3.16 send read_mem_data by library function usart_data_transmit; S1.3.17 clear the receiving flag by library function usart_rx_clear; S1.3.18 judge whether the first byte and the second byte of the receiving array are 0x06 and 0xf9, if yes, go to next step, otherwise jump to step S1.3.26; S1.3.19 repeat steps S1.3.4 and S1.3.5; S1.3.20 send 0x04 to the host computer by library function usart_data_transmit; S1.3.21 repeat step S1.3.5; S1.3.22 Read the FMC_PID register using the function read_fmc_pid and put it into the array read_mem_data; S1.3.23 Transmit the value in the read_mem_data array to the host computer using the library function usart_data_transmit; S1.3.24 Repeat steps S1.3.4 and S1.3.5; S1.3.25 Clear the receive flag and the receive count using the library function usart_rx_clear; S1.3.26 Determine whether the first byte of the receive array USART_RX is 0 and the second byte is 0xff. If so, proceed to the next step. Otherwise, jump to step S1.3.33; S1.3.27 Repeat steps S1.3.4 and S1.3.5 (this step is the confirmation mechanism with the host computer); S1.3.28 Transmit 0x0B to the host computer (the transmitted content represents the data length) and repeat step S1.3.5; S1.3.29 Transmit 0x22 to the host computer (this identifies the version of the boot program) and repeat step S1.3.5; S1.3.30 Transmit the supported command array command_data to the host computer; S1.3.31 Repeat steps S1.3.4 and S1.3.5; S1.3.32 Clear the receive flag and the receive count; S1.3.33 Determine whether the first byte of the receive array USART_RX is 0x44 and the second byte is 0xbb. If so, proceed to the next step. Otherwise, jump to step 40; S1.3.34 Determine whether the receive count is 2. If so, proceed to steps S1.3.4 and S1.3.5. Otherwise, proceed to the next step; S1.3.35 Determine whether the receive count is 7. If so, obtain the sector number sector_num from positions 5 and 6 of the receive array USART_RX and the checksum check_sum from the seventh position; S1.3.36 Determine whether the checksum is correct. If so, proceed to the next step. Otherwise, jump to step S1.3.38; S1.3.37 Erase the sector_num region using the fmc library function and repeat steps S1.3.4 and S1.3.5; S1.3.38 Transmit 0xff to the host computer and repeat step S1.3.5; S1.3.39 clear the receive flag, clear the receive count count; S1.3.40 check if the 1st and 2nd bytes of the receive array USART_RX are 0x31 and 0xCE, if yes, go to next step, otherwise jump to step S1.3.52; S1.3.41 check if the receive count count is 2, if yes, repeat steps S1.3.4, S1.3.5, otherwise go to next step; S1.3.42 check if the receive count count is 7, if yes, get the write address from the 3rd, 4th, 5th and 6th bytes of the receive array, get the check sum check_sum from the 7th byte of the receive array, and go to next step, otherwise jump to step S1.3.44; S1.3.43 check if the check sum is correct, if yes, repeat steps S1.3.4, S1.3.5, otherwise go to next step; S1.3.44 check if the receive count count is 8, if yes, go to next step, otherwise jump to step S1.3.52; S1.3.45 clear the receive count count; S1.3.46 get the number of data num_of_data_write to be written this time from the 8th byte of the receive array; S1.3.47 configure the number of data parameter that the DMA module needs to send using the value of num_of_data_write; S1.3.48 configure the serial port receive enable using the library function usart_dma_receive_config; S1.3.49 enable the receive interrupt of the serial port; S1.3.50 enable the second channel of the DMA module; S1.3.51 clear the receive flag; S1.3.52 check if the 1st and 2nd bytes of the receive array USART_RX are 0x21 and 0xDE, if yes, go to next step, otherwise exit the process; S1.3.53 check if the receive count count is 2, if yes, repeat steps S1.3.4, S1.3.5, otherwise go to next step; S1.3.54 check if the receive count count is 7, if yes, go to next step, otherwise exit the process; S1.3.55 clear the receive count count; S1.3.56 get the check sum check_sum from the 7th byte of the receive array; S1.3.57 judge whether the check sum is legal, if yes, repeat S1.3.4, S1.3.5, otherwise, go to next step; S1.3.58 clear the receiving flag; S1.3.59 perform system reset operation; S1.4 process the DMA module interrupt, the specific steps are as follows: S1.4.1 use the library function dma_flag_get to get whether the sending flag of the DMA module is completed, if yes, go to next step, otherwise, exit the process; S1.4.2 use the library function dma_interrupt_flag_clear to clear the DMA interrupt flag; S1.4.3 disable the channel of the DMA module; S1.4.4 assign the number of data written num_of_data_write minus 1 to the first byte of the DMA receiving array rxbuffer, rxbuffer[0]; S1.4.5 judge whether the check sum of the rxbuffer array is qualified, if yes, go to next step, otherwise, exit the process; S1.4.6 use the library function FLASH_Program to write the data after rxbuffer[1] from the memory address start_addr, the total number is num_of_data_write plus 1; S1.4.7 judge whether the result of S1.4.6 step is failed, if yes, exit the process, otherwise, go to next step; S1.4.8 wait for the serial port sending flag to be ready; S1.4.9 use the serial port to send 0x79; S1.4.10 configure the receiving function of the DMA module to be disabled; S1.4.11 open the receiving interrupt of the serial port to wait for the next data packet; S1.5 configure the Flash burning module, the specific steps are as follows: S1.5.1 use the library function fmc_unlock to unlock the region of Flash erasing; S1.5.2 use the library function fmc_flag_clear to clear all waiting signals; S1.5.3 get the address of writing into the flash; S1.5.4 judge whether the current writing address Address is less than the sum of the writing address write_start_addr and the writing data size size, if yes, go to next step, otherwise, jump to S1.5.1 step; S1.5.5 Write data pointed by data array pointer using library function fmc_word_program; S1.5.6 Read data content content in Address; S1.5.7 Compare data content content with data pointed by data array pointer, if same, go to next step, otherwise, exit the process and return failure; S1.5.8 Move data array pointer one position forward; S1.5.9 Move Address four positions; S1.5.10 Clear flag using library function fmc_flag_clear; S1.5.11 Jump to step S1.5.4; S1.5.12 Lock flash erase module using library function fmc_lock; S1.5.13 Return success flag; S1.6 Get user selection from host computer, the specific steps are as follows: S1.6.1 Enter query loop; S1.6.2 Initialize delay count count; S1.6.3 Get state of switch value of upgrade flag using library function gpio_inout_bit_get; S1.6.4 If switch value is low, return 1 indicating that upgrade is needed, otherwise, go to next step; S1.6.5 Delay 100 ms; S1.6.6 Decrease delay count count by 1; S1.6.7 Judge whether delay count is greater than 0, if yes, adjust to step S1.6.3, otherwise, go to next step; S1.6.8 Return 0 indicating that upgrade is not needed; S1.7 Set up board card according to user selection; If user selects online upgrade, the following steps are performed: S1.7.1 Initialize DMA function of board card S1.7.1.1 Initialize clock function of DMA module using library function rcu_periph_clock_enable; S1.7.1.2 Disable channel of DMA module using library function dma_deinit; S1.7.1.3 Set the initialization parameters of the dma module, including the external array of memory address data copy, the number of channels, the loop mode, the vector address, the data width, the priority; S1.7.1.4 Use the library function dma_single_data_mode_init to initialize the DMA channel using the parameters; S1.7.1.5 Use the library function dma_circulation_disable to set the channel; S1.7.1.6 Use the library function dma_channel_subperpheral_select to configure the channel mode; S1.7.1.7 Use the library function dma_interrupt_enable to enable the DMA interrupt; S1.7.2 Reset the serial port; S1.7.2.1 Use the library function usart_dma_receive_config to set the serial port receive disable; S1.7.2.2 Use the library function usart_interrupt_enable to set the serial port interrupt enable; S1.7.2.3 Use the library function usart_enable to enable the serial port; S1.7.3 Configure the interrupt of the board card serial port and DMA module; S1.7.3.1 Use the library function nvic_irq_enale to enable the interrupt of the serial port, the interrupt number is USART0_IRQn, that is, the selected serial port usart is interrupt received; S1.7.3.2 Use the library function nvic_irq_enale to enable the interrupt of the DMA, the interrupt number is DMA1_Channel2_IRQn, and the selected channel 2 of the DMA module is interrupt received; If the user selects to run the application directly, the following steps are performed: S1.7.4 Determine whether the result of the bitwise AND operation between the application address pointer ApplicationAddress and 0x2ffe0000 is 0x20000000, if so, proceed to the next step, otherwise print error information; S1.7.5 Use the library function usart_disable to disable the serial port; S1.7.6 Get the result of the offset of 4 addresses of the application address pointer ApplicationAddress, and store the result in the jump address JumpAddress; S1.7.7 Convert the jump address JumpAddress into a stack pointer Jump_To_Application; S1.7.8 Set the application address pointer ApplicationAddress to the address of the new program reset interrupt function; S1.7.9 Execute the application using the stack pointer Jump_To_Application of the jump address; S2: Create an application bin file S2.1 Open the program project to be upgraded in the kerl tool, since the space occupied by the example BOOT program is 0x08000000 ~ 0x08002000, so add an offset nvic_vector_table_set (NVIC_VECTTAB_FLASH, 0x2000) in main, here the offset can be modified according to the application requirements; S2.2 Open the project file to set the IROM1 area of the application, for example: the starting address is 0x08000000, and the size is 0x2000; Set the running option RUN#1 under User option, and the compilation instruction is: fromelf --bin --output.\Output\Project.bin.\Output\Project.axf; S2.3 After setting successfully, the project.bin file suitable for the IAP host computer will be generated under the output folder of the project when the project is compiled; S3: Upgrade the application using the host computer tool S3.1 Burn the boot program to the board through the burning tool; S3.2 Connect the serial port, set the serial port baud rate and check code of the host computer tool, and perform burning after successful handshake.

[0018] The above only describes the preferred embodiments of the present application, and it should be noted that for ordinary skilled persons in the technical field, several improvements and modifications can be made without departing from the technical principles of the present application, and these improvements and modifications should also be considered as the protection scope of the present application.

Claims

1. A method for online upgrade of circuit boards based on flash memory, characterized in that, Includes the following steps: S1: Create the boot program; S2: Create the application's bin file; S3: Upgrade the application using the host computer tool.

2. The flash-based online upgrade method for circuit boards as described in claim 1, characterized in that, Step S1 includes the following sub-steps: S1.1 Initialize the board's switch quantity GPIOA15 settings; S1.2 Initialize the boot program to receive serial port data and program the serial port settings; S1.3 interrupts the reception of serial port data; S1.4 handles interrupts in the DMA module; S1.5 is equipped with a Flash programming module; S1.6 Obtains user selections from the host computer; S1.7 Configure the board according to the user's selection.

3. The flash-based online upgrade method for circuit boards as described in claim 2, characterized in that, Step S1.1 includes the following sub-steps: S1.1.1 Use the library function rcu_periph_clock_enable to enable the clock of the group containing the switch quantity; S1.1.2 Use the library function gpio_mode_set to enable the index gpio in the group as the input direction.

4. The flash-based online upgrade method for circuit boards as described in claim 3, characterized in that, Step S1.2 includes the following sub-steps: S1.2.1 Use library functions to enable the clock of the group containing the switch values ​​used for serial port reception and transmission; S1.2.2 Enable the serial port clock using library functions; S1.2.3 Use the library function gpio_af_set to configure the serial port receive and transmit pins GPIOA9 and GPIOA10; S1.2.4 Use the library function gpio_mode_set to set the transmit and receive pins to the multiplexed function mode GPIO_MODE_AF; S1.2.5 Use the library function gpio_output_option_set to set the receive and transmit pins; S1.2.6 Disable the selected serial port USRAR0 for receiving data; S1.2.7 Set the baud rate, parity, data length, and stop bits for the serial port; S1.2.8 Enables the serial port's receive and transmit functions; S1.2.9 Enable serial port.

5. The flash-based online upgrade method for circuit boards as described in claim 4, characterized in that, Step S1.3 includes the following sub-steps: S1.3.1 Determine if the interrupt flag has been reset. If yes, exit the process; otherwise, proceed to the next step. S1.3.2 Use the library function usart_data_receive to obtain the data received from the serial port and store it in the receive array USART_RX, and increment the receive count; S1.3.3 Determine if the first received data is 0x7F. If it is, proceed to the next step; otherwise, jump to step S1.3.

6. S1.3.4 Use the library function usart_data_transmit to send 0x79 to the host computer; S1.3.5 Use the library function usart_flag_get to wait for the USART_FLAG_TC flag to be set to 1. If it is set, proceed to the next step; otherwise, continue waiting. S1.3.6 Determine if the first byte of the received array is 0x11 and the second byte is 0xee. If so, proceed to the next step; otherwise, jump to step S1.3.

8. S1.3.7 Determine if the number of received items count is 2. If it is, proceed to the next step; otherwise, repeat steps S1.3.4 and S1.3.

5. S1.3.8 Determine if the number of received items (count) is 7. If it is, proceed to the next step; otherwise, jump to step S1.3.

10. S1.3.9 Retrieves data from positions 3, 4, 5, and 6 of the receiving array and writes it to the starting address start_addr; S1.3.10 retrieves the checksum from the 7 positions of the received array; S1.3.11 Check if the checksum is correct. If it is correct, repeat steps S1.3.4 and S1.3.5; otherwise, proceed to the next step. S1.3.12 Determine if the number of received items count is 9. If it is, proceed to the next step; otherwise, jump to step S1.3.

18. S1.3.13 Get the number of memory reads in this operation, read_mem_num, from the eighth position of the receive array, and get the checksum, check_sum, from the ninth position; S1.3.14 Determine if the checksum was successfully read. If it was, repeat steps S1.3.4 and S1.3.5; otherwise, proceed to the next step. S1.3.15 Reads the data from the memory at the starting address start_addr and stores it in the read_mem_data array; S1.3.16 The read_mem_data data is sent out through the library function usart_data_transmit; S1.3.17 Use the library function usart_rx_clear to clear the receive flag; S1.3.18 Determine if the first and second bytes of the received array are 0x06 and 0xf9 respectively. If they are, proceed to the next step; otherwise, jump to step S1.3.

26. S1.3.19 Repeat steps S1.3.4 and S1.3.5; S1.3.20 uses the library function usart_data_transmit to send 0x04 data to the host computer; S1.3.21 Repeat step S1.3.5; S1.3.22 Use the function read_fmc_pid to read the FMC_PID register and put it into the array read_mem_data; S1.3.23 Use the library function usart_data_transmit to send the values ​​in the read_mem_data array to the host computer; S1.3.24 Repeat steps S1.3.4 and S1.3.5; S1.3.25 Use the library function usart_rx_clear to clear the receive flag and the count of received data. S1.3.26 Determine if the first byte of the receive array USART_RX is 0 and the second byte is 0xff. If so, proceed to the next step; otherwise, jump to step S1.3.

33. S1.3.27 Repeat steps S1.3.4 and S1.3.5; S1.3.28 Send 0x0B, representing the data length, to the host computer, and repeat step S1.3.5; S1.3.29 Send 0x22 to the host computer, and repeat step S1.3.5; S1.3.30 Sends the supported command array command_data to the host computer; S1.3.31 Repeat steps S1.3.4 and S1.3.5; S1.3.32 Clear the receive flag and clear the receive count; S1.3.33 Determine whether the first byte of the receive array USART_RX is 0x44 and the second byte is 0xbb. If yes, proceed to the next step; otherwise, jump to step 40. S1.3.34 Determine if the number of received items (count) is 2. If it is, proceed to steps S1.3.4 and S1.3.5; otherwise, proceed to the next step. S1.3.35 Determine if the number of received data is 7. If so, obtain the number of written sector regions (sector_num) from positions 5 and 6 of the received array USART_RX, and obtain the checksum (check_sum) from position 7. S1.3.36 Determine if the checksum is correct. If it is, proceed to the next step; otherwise, jump to step S1.3.

38. S1.3.37 Use the fmc library function to erase the region where sector_num is located, and repeat steps S1.3.4 and S1.3.5; S1.3.38 Send 0xff to the host computer, and repeat step S1.3.5; S1.3.39 Clear the receive flag and reset the receive count; S1.3.40 Determine if positions 1 and 2 of the receive array USART_RX are 0x31 and 0xCE. If they are, proceed to the next step; otherwise, jump to step S1.3.

52. S1.3.41 Determine if the number of received items (count) is 2. If it is, repeat steps S1.3.4 and S1.3.5; otherwise, proceed to the next step. S1.3.42 Determine if the number of received items count is 7. If it is, obtain the memory address to be written from positions 3, 4, 5, and 6 of the received array, obtain the checksum check_sum from position 7 of the array, and proceed to the next step. Otherwise, jump to step S1.3.

44. S1.3.43 Check if the checksum is correct. If it is, repeat steps S1.3.4 and S1.3.

5. Otherwise, proceed to the next step. S1.3.44 Determine if the number of accepted items count is 8. If it is, proceed to the next step; otherwise, jump to step S1.3.

52. S1.3.45 Clear the count of received data to zero; S1.3.46 Obtain the number of data items written this time, num_of_data_write, from the eighth position of the receive array; S1.3.47 Use the value of num_of_data_write to configure the number of data to be sent by the DMA module; S1.3.48 Use the library function usart_dma_receive_config to configure serial port receive enable; S1.3.49 Enables the serial port receive interrupt; S1.3.50 Enables the second channel of the DMA module; S1.3.51 Clear the receive identifier; S1.3.52 Determine if the first and second bytes of the receive array USART_RX are 0x21 and 0xDE. If they are, proceed to the next step; otherwise, exit the process. S1.3.53 Determine if the number of received items (count) is 2. If it is, repeat steps S1.3.4 and S1.3.5; otherwise, proceed to the next step. S1.3.54 Determine if the number of received items (count) is 7. If it is, proceed to the next step; otherwise, exit the process. S1.3.55 Clear the count of received items; S1.3.56 Obtain the checksum from the 7th position of the received array; S1.3.57 Determine if the checksum is valid. If it is, repeat steps S1.3.4 and S1.3.5; otherwise, proceed to the next step. S1.3.58 Clear the receiver identifier; S1.3.59 performs a system reset operation.

6. The flash-based online upgrade method for circuit boards as described in claim 5, characterized in that, Step S1.4 includes the following sub-steps: S1.4.1 Use the library function dma_flag_get to get whether the DMA module's transmission flag is complete. If yes, proceed to the next step; otherwise, exit the process. S1.4.2 Use the library function dma_interrupt_flag_clear to clear the DMA interrupt flag; S1.4.3 Disable the DMA module channels; S1.4.4 Subtract 1 from the number of writes num_of_data_write and assign the result to the first byte rxbuffer[0] of the DMA receive array rxbuffer; S1.4.5 Determine if the checksum of the rxbuffer array is valid. If it is, proceed to the next step; otherwise, exit the process. S1.4.6 The library function FLASH_Program is used to write data starting from memory address start_addr after rxbuffer[1]. The total number of data is num_of_data_write plus 1. S1.4.7 Determine whether the result of step S1.4.6 is a failure. If it is, exit the process; otherwise, proceed to the next step. S1.4.8 Waiting for the serial port send flag to be ready; S1.4.9 uses the serial port to send 0x79; S1.4.10 Configure the DMA module to disable the receive function; S1.4.11 Enables the serial port's receive interrupt to wait for the next data packet.

7. The flash-based online upgrade method for circuit boards as described in claim 6, characterized in that, Step S1.5 includes the following sub-steps: S1.5.1 Use the library function fmc_unlock to unlock the Flash erasing / writing area; S1.5.2 Use the library function fmc_flag_clear to clear all waiting signals; S1.5.3 Obtain the address to be written to flash; S1.5.4 Determine if the current write address is less than the sum of the write address write_start_addr and the write data size. If so, proceed to the next step; otherwise, jump to step S1.5.

1. S1.5.5 uses the library function fmc_word_program to write the data pointed to by the pointer data of the data array to be written; S1.5.6 Read back the data content (content) within the Address address; S1.5.7 compares the data content with the data pointed to by the array pointer data. If they match, proceed to the next step; otherwise, exit the process and return failure. S1.5.8 Move the pointer to the data array to be written forward by one position; S1.5.9 moves the Address by four positions; S1.5.10 uses the library function fmc_flag_clear to clear the flag; S1.5.11 Jump to step S1.5.4; S1.5.12 Use the library function fmc_lock to lock the flash erase / write module; S1.5.13 returns a success flag.

8. The flash-based online upgrade method for circuit boards as described in claim 7, characterized in that, Step S1.6 includes the following sub-steps: S1.6.1 Enter the query loop; S1.6.2 Initialize the delay count; S1.6.3 Use the library function gpio_inout_bit_get to get the status of the upgrade flag's switch value; S1.6.4 If the switch value is low, return 1 to indicate that an upgrade is needed; otherwise, proceed to the next step. S1.6.5 latency is 100ms; S1.6.6 Delay count is reduced by 1; S1.6.7 Determine if the delay count is greater than 0. If it is, proceed to step S1.6.3; otherwise, proceed to the next step. S1.6.8 returns 0, indicating that no upgrade is needed.

9. The flash-based online upgrade method for circuit boards as described in claim 8, characterized in that, Step S1.7 includes the following process: If the user chooses to upgrade online, proceed with the following steps: S1.7.1 Initialize the board's DMA function S1.7.1.1 Initialize the clock function of the DMA module using the library function rcu_periph_clock_enable; S1.7.1.2 Use the library function dma_deinit to disable the DMA module's channels; S1.7.1.3 Set the initialization parameters of the DMA module, including the external array for memory address data copying, number of channels, loop mode, vector address, data width, and priority; S1.7.1.4 Use the library function dma_single_data_mode_init to initialize the DMA channel with parameters; S1.7.1.5 Use the library function dma_circulation_disable to set the channel; S1.7.1.6 uses the library function dma_channel_subperpheral_select to configure the channel mode; S1.7.1.7 uses the library function dma_interrupt_enable to enable DMA interrupts; S1.7.2 Reset the serial port; S1.7.2.1 Use the library function usart_dma_receive_config to disable serial port reception; S1.7.2.2 Use the library function usart_interrupt_enable to enable serial port interrupts; S1.7.2.3 Use the library function usart_enable to enable the serial port; S1.7.3 Configure the interrupts for the board's serial port and DMA module; S1.7.3.1 Use the library function nvic_irq_enale to enable the serial port interrupt, with the interrupt number USART0_IRQn, that is, select the USART serial port as the interrupt reception; S1.7.3.2 Use the library function nvic_irq_enale to enable DMA interrupts, with interrupt number DMA1_Channel2_IRQn, and select channel 2 of the DMA module as interrupt reception; If the user chooses to run the application directly, proceed with the following steps: S1.7.4 Determine if the result of a bitwise AND operation between the application address pointer ApplicationAddress and 0x2ffe0000 is 0x20000000. If yes, proceed to the next step; otherwise, print an error message. S1.7.5 uses the library function usart_disable to disable the serial port; S1.7.6 Obtain the result after offsetting the application address pointer ApplicationAddress by 4 addresses, and store the result in the jump address JumpAddress; S1.7.7 converts the jump address JumpAddress to the stack pointer Jump_To_Application; S1.7.8 Set the application address pointer ApplicationAddress to the address of the new program's reset interrupt function; S1.7.9 uses the stack pointer to the jump address, Jump_To_Application, to execute the application.

10. The flash-based online upgrade method for circuit boards as described in claim 9, characterized in that, Step S2 includes the following sub-steps: S2.1 Open the program project that needs to be upgraded in the kerl tool; the space occupied by the BOOT program is 0x08000000 ~0x08002000. Add the offset nvic_vector_table_set(NVIC_VECTTAB_FLASH, 0x2000) to main. Modify the offset according to the application requirements. S2.2 Open the project file and set the application's IROM1 area, starting address 0x08000000, size 0x2000; Under the User options, set the run option to RUN#1, and the compilation command is: fromelf --bin --output .\Output\Project.bin .\Output\Project.axf; After successful S2.3 setup, the compiled project will generate a project.bin file suitable for the IAP host computer in the project output folder; Step S3 includes the following sub-steps: S3.1 uses a programming tool to program the boot program onto the board; Connect the S3.2 serial port, set the serial port baud rate and checksum in the host computer tool, and perform the programming after a successful handshake.