OTP, which stands for "One-time programmable bytes", has the property that this region can be programmed * once *. APM32F4 has a total of 16 data blocks and a locking control block. The size of each block is 32 bytes, so there are 512 bytes in total. The address areas are: 0x1FFF7800-0x1FFF79FF.
This means that we can save 512 bytes of content on the APM32F4 that will not be modified after we write to the region, including easer all the internal space on the chip and re-downloading the program.
2、 The role of the OTP regionIt can store some important data that cannot be changed during the use of our product. For example:
2.1 Calibration values of external devices
Our products are usually connected to some sensors, such as temperature sensors, gas sensors, etc., or some devices like frequency generators. One thing that these devices have in common requires some calibration, a process that we can put on the production line. On the production line, our products can burn the calibration firmware specifically, complete the calibration of external instruments in the standard process of the production line (the interval in the standard environment), and obtain the corresponding calibration value to save in the OTP area. We then download the release firmware to use these parameters, so that we can be sure that our parameters will not be lost due to firmware upgrades or other dangerous operations on Flash.
2.2 Preservation of sequence numbers
For our product application, we will also have a requirement for a product serial number. Since the coding rules of chip UID will not be given to our application side, and we also need something similar to the product number (for example, APM32F4 will be applied to two different products A and B), the chip UID does not meet our use requirements.So one important feature of our product ID is that it's not allowed to change. Then the OTP area of APM32F4 meets our needs very well.
2.3 Product Encryption
We can use the unique UID of the APM32 chip, and then cooperate with a certain encryption algorithm to obtain an information string bound to the chip UID and save it in the OTP area, and calibrate our UID and information string each time the product runs.
3 How to use the OTP areaThe general use Programming in code, ISP programming, simulation download programming and so on.
3.1 programming mode
The implementation process of the specific code is also very simple, that is, unlock Flash, program OTP, lock Flash.
The result is:
3.2 ISP download programming
When burning firmware in production, one of the burning methods we usually use in production line is ISP burning. APM32F4 also provides the corresponding burning method, here I also demonstrate the use of ISP mode for OTP area programming.
We are here to choose very sea provide DFUProgrammer [https://geehy.com/uploads/tool/DFUProgrammer.msi] upper machine, after the corresponding driver installed on the PC, we carried out in accordance with the following steps to OTP programming.
1. Connect BOOT0 high and BOOT1 low of the chip. Makes the chip enter ISP mode.
2. Use USB cable to connect to our products (PA11/PA12);
Search for a connected device in DFUProgrammer;
4. In the "Read chip" interface, set the read address to 0x1FFF7800, the size to 0x210, and the display mode to 32bit. To display the OTP area;
5. Modify a bin file to hold what we want to write, here 0x00120059;
6. Select our download file in the "Firmware Upgrade" interface, select 0x1FFF7804, click "Start firmware Update", and get a success prompt window;
7. Read the contents of the OTP area again to see if the program was successful.
3.3 Simulation download programming
In most use cases, we usually use burners or programmers to program our chips. There are many kinds of burning tools in the production line, but they are the same. Most of the burning tools use SWD/JTAG interface to program the chip.I would like to share with you a way to use J-Link programming in daily development.
1. Add apm32f4xx_otp.s file to our project.
2. Modify the apm32f4xx_otp.s file to the values we need, as shown below.
3. Add APM32F4's OTP download algorithm to our project.
4. Build the project and download it.
5. Check the contents of OTP area in the simulation interface to see whether the programming is successful.
Comments
Please log in or sign up to comment.