“TI’s MSP430 series single-chip microcomputer is a product with high practical value, and it has been widely used in many fields, especially its ultra-low power consumption characteristic, which is unmatched by all other single-chip microcomputers. IAP (InApplication Programming) is the user’s own program to program some areas of the user’s Flash during the running process, the purpose is to easily update the firmware program in the product through the reserved communication port after the product is released.
TI’s MSP430 series single-chip microcomputer is a product with high practical value, and it has been widely used in many fields, especially its ultra-low power consumption characteristic, which is unmatched by all other single-chip microcomputers. IAP (InApplication Programming) is the user’s own program to program some areas of the user’s Flash during the running process, the purpose is to easily update the firmware program in the product through the reserved communication port after the product is released.
To realize the IAP function, it is usually necessary to write two project codes when designing the firmware program: the first project program does not perform normal functional operations, but only receives the program or through some communication channel (such as USB, USART, some wireless devices) Data (executable HEX file), execute the update to the second part of the code; the second project code is the real function code. The two parts of the project code are burned in the user’s Flash at the same time. When the chip is powered on, the first project code starts to run first, and then the second piece of code is updated.
According to the characteristics of IAP and the feature that the MSP430 series does not have its own IAP function, it is necessary to write an IAP program to burn the on-chip Flash, so as to achieve the purpose of upgrading. The following will introduce in detail how to carry out the IAP upgrade design.
The overall idea of the system design is to directly download the binary files that need to be upgraded to the corresponding address space through wireless means, and then let the microcontroller system automatically execute the IAP upgrade.
The key here is to write a “ant moving” code, because it is not running in the Flahs area of the MSP4 30F149 chip, but in the set RAM area. RAM space is limited, so it is written in assembly code (recommended, it can also be written in C language, and then reduced to assembly language), there is no stack operation, and the code cannot exceed 2 KB.
1 hardware design
(1) The internal structure of the main chip of the system
First, briefly introduce the internal memory address structure diagram of MSP430F149, as shown in Figure 1, which will help to upgrade the design of IAP.
It can be seen from Figure 1 that the ROM and RAM have the same address space, the addressing space is 64 KB, the von Neumann structure is adopted, and a set of address data buses are used, the address is 0000H～FFFFH, and the RAM address area is 0200H～09FFH , The code area ROM is 1000H～FFFF.
(2) Externally expanded Flash chip structure
In order to be able to save the file to be upgraded (usually after IAR is compiled and converted into a binary file by third-party software) in one place, the system must be expanded with 1 piece of Flash (of course it can also be other media). Since the MSP430F149 series of single-chip microcomputers have two SPI interfaces, a Flash chip with SPI interface is selected, such as SST25VF016 (16 Mb) series. The chip voltage is 2.7-3.6 V, which just meets the low-power voltage requirements of MSP series single-chip microcomputers, and the operating instructions are very simple. The block diagram of the externally expanded Flash hardware is shown in Figure 2. According to the requirements of saving data, it can be designed as multiple slices to make more storage space. When designing the software, design the first address for storing the upgrade file and the size of the file. In the MSP430F149 series, the file size is generally 64 KB.
(3) Storage space address division
For a detailed and clear description, you can save the HEX file at the beginning address of SST25VF016, that is, the address ranges from 0x000000 to 0x010000. Of course, you can customize the space address according to project requirements.
2 Communication transmission
For how to download the compiled executable file (BIN file) from the third party to the corresponding external storage space, here are several wireless remote upgrade solutions:
①The wireless GPRS scheme has the advantage of being able to remotely control downloads; the disadvantage is that GPRS requires a fee, and one card corresponds to one device (this may be the future development trend while the cost problem is about to be solved).
②Infrared scheme, many PDAs now have this function, add an infrared module to the system of the single-chip microcomputer, and write a small software on the PDA, you can easily download the upgrade file to the designated location of the expanded Flash ; The disadvantage is that it requires personnel to work on site.
③Bluetooth technology scheme. This technology is similar to infrared technology. The advantage is that data transmission has no directionality and the speed is much faster than infrared.
Others are not introduced one by one, I hope readers can have more upgrade plans. In order to briefly explain, the infrared solution is used as the media medium for downloading and upgrading the software. The principle of other wireless or wired media is the same, and readers can choose according to their own projects.
3 software design
First, suppose that the file to be upgraded has been downloaded to the corresponding externally expanded Flash. For the design of the entire IAP program, it is divided into two parts: First, write the “ant moving” program, that is, from byte to byte. Move the corresponding externally expanded Flash address (pre-defined) to the on-chip Flash (from 0x1100 to 0xFFFF); second, write the boot program (COPY program), copy the “ant move” program to the corresponding RAM In the space (0x0200), point the PC to 0x0200. The system upgrade procedure flow is shown as in Fig. 3.
Note: When copying from the off-chip Flash to the on-chip Flash, all 60 KB must be copied, otherwise the system will be abnormal. Finally, turn on the watchdog and reset, that is, the PC starts from 0x0000. The program flow of “Ant Moving” is shown in Figure 4.
Note in Figure 4:
①The entry address of the program must be fixed first, so that the boot program can copy it to RAM, and the size must be controlled within 2 KB.The program is relatively small, generally not
More than 2 KB.
②The Flash state must be locked, so that it is not easy to make mistakes when writing.
③After reading the 60 KB data, turn on the watchdog. The IAP upgrade system automatically resets and restarts the system based on the watchdog not feeding the dog.
As long as the user performs programming according to the above process, it is easy to achieve IAP upgrade (here is the key, but also a difficult point). The flow of the boot program is shown in Figure 5.
Figure 5 Description: Declare an entry function, which is convenient to call when the external program is upgraded. This boot procedure is relatively simple. Because it is executed on-chip, it is easy to import the ant moving program into RAM using assembly language (mov instruction).
Because the final file compiled by IAR is *. a43 file, it is recommended to use software similar to (HexToBin.exe) to transfer *. The a43 file is converted into a binary file and can be downloaded directly.
4 matters needing attention
This code must run in RAM, so SP is not used to “RET” for the time being. In other words, the CALL instruction cannot be used, and the stack processing (such as PUSH or POP instructions) cannot be used, so the stack area cannot be opened here. The code (BIN file) is executed by some wireless means, and then the executable code is downloaded and saved to the corresponding address space of the external Flash according to the custom wireless protocol, and finally the upgrade program is started. Finally, start the system by starting the watchdog and resetting.
Long-term practice has proved that this scheme has very high reliability. Although only the IAP upgrade method of the MSP430 series products are introduced here, the design ideas are the same for the upgrade of other microcontrollers that do not have their own IAP function. Here to remind the majority of development enthusiasts, for a series of binary file data, we should not be afraid; as long as we think independently, grasp the characteristics of the single-chip microcomputer, and apply it flexibly, there is nothing we can think of but nothing we can’t do. I wish you all progress together!