[Introduction]Starting from some models of STM32F0, such as STM32F04x and STM32F09x, more and more models of STM32 have the Empty Check function. In the past, the startup of STM32 was determined by BOOT0 and BOOT1. After the introduction of the empty chip detection function, in the case of BOOT0=0, there are two cases:
First, if the code already exists inside, it will be started from the user storage area;
Second, if it is an empty chip, start from the system storage area and execute the internal Bootloader.
What good does it bring? If the customer is an empty on-chip board, without jumping the BOOT0 pin, they can directly use the internal Bootloader for serial port or other communication ports for code programming, which is very convenient. However, this also brings a very big risk to the design of GPIO. Attention should be paid to the circuit design and corresponding measures should be taken.
Origin of the problem
A customer uses STM32G0B1RET6 in the design of its product. One day, when a customer engineer was testing the current, he accidentally found a situation and said, “There is a strange situation, when the STM32G0B1 does not have the code programmed, the current will be tens of milliseconds more than that with the programmed code. Ann.” According to our past knowledge, if there is no burning code, there is no operation, this should not happen. So what’s the situation?
problem analysis
Measure the level of the GPIO of the STM32G0B1 when it is not programmed, and it can be found that some GPIOs are high, such as PA2/PA3 and PA9/PA10. The customer connected an external drive circuit to the PA9, which is driven by a high level, so the high level of the PA9 drives the work of this part of the circuit, resulting in an increase in current.
From the GPIO chapter of the reference manual RM0444, we know that the GPIO of the STM32G0 should be in an analog state after power-on, so these GPIOs that show high levels are a bit strange.
Suddenly remembered that the STM32F091 and other models already have the empty chip detection function, I continued to check the “Memory and bus architecture” chapter of the STM32G0 reference manual RM0444. Sure enough, I found that the STM32G0 series also has the empty chip detection function. That is to say, STM32G0B1 goes to the system storage area to execute the internal Bootloader without burning the code.
At this point, you need to open the application note AN2606 “STM32 Microcontroller System Memory Bootstrap Mode” to learn about the GPIO status of the STM32G0B1 under the system Bootloader.
Since it has been detected that PA2/PA3 and PA9/PA10 are high levels, these two pin pairs are just the GPIO pins corresponding to USART1 and USART2 used in the Bootloader. So, check its configuration status in Bootloader, please refer to Figure 1.
Figure 1 Port status of USART1/2 under system Bootloader
It can be seen from Figure 1 that PA2/PA3/PA9/PA10 are configured as multiplexed push-pull structures with pull-up resistors. Among them, PA10/PA3 is the input port, and PA2/PA9 is the output port.
Use a 1kΩ resistor to measure the port status of PA9/PA10 to determine the source of its high level. The voltage of system VDD is 3.22V.
Before measuring, you need to understand the structure of GPIO, as shown in Figure 2.
Figure 2 Structure of I/O in Multiplexed Function Configuration
As can be seen from Figure 2, when used as an output, the high level presented on the port comes from VDDIOX on the P-MOS; when used as an input, the high level presented on the port comes from VDDIOX on the pull-up resistor. Let’s test it for verification.
First measure the output port PA9, use a 1kΩ resistor in series between PA9 and VSS, and connect an ammeter in series, the measured current is 3.22mA. According to the U=I·R formula, it is just right, the total resistance R = U / I = 3.22V ÷ 3.22mA = 1kΩ. That is to say, the high level of PA9 is provided by the VDDIOX connected by the P-MOS in the push-pull structure, and there is no internal resistance.
Then measure the input port PA10, use a 1kΩ resistor in series between PA10 and VSS, and connect an ammeter in series, and the measured current is 85.4uA. The total resistance R = U / I = 3.22V ÷ 85.4uA = 37.7kΩ is greater than the 1kΩ resistor connected in series externally. That is to say, the high level of PA10 comes from the VDDIOX connected to the pull-up resistor, and the internal pull-up resistor RPU = 37.7kΩ – 1kΩ = 36.7kΩ.
One more step to confirm the input port PA10 again. This time, instead of using a 1kΩ resistor, directly connect the ammeter to the VSS in series with the PA10, and the current value is 87.7uA. Internal pull-up resistor RPU = U / I = 3.22V ÷ 87.7uA = 36.7kΩ, which is the same as the test above. It also conforms to the range of internal pull-up resistors in the STM32G0B1 data sheet, as shown in Figure 3.
Figure 3 I/O pull-up and pull-down resistor parameters
risk
At this point, it is clear that when there is no code programmed in the user memory area, the STM32 will start to enter the system Bootloader, and PA9 is set to multiplex output and output a high level, thereby increasing the current generated by the external circuit. But we should dig deeper into this issue. The customer’s situation is relatively good, and it is connected to a drive circuit, which will not cause damage.
Imagine if in the customer’s application, PA9 is used as an input port to connect the interrupt output of a sensor, such as connecting the INT1/2 pins of a 3-axis MEMS accelerometer LIS2DH12. Looking at the data sheet of LIS2DH12, it can be known that the initial state of the INT1 and IN2 pins is to output a low level, as shown in Figure 4.
Figure 4 Initial state of INT1/INT2 pins of LIS2DH
Since the initial state of the INT pin of LIS2DH12 is push-pull output and output low level, if it is directly connected to PA9, and the user intends to solder the blank chip to the user board first, and then program the code, then when the power is turned on , the INT pin of LIS2DH12 outputs a low level, and after the STM32G0B1 enters the internal Bootloader, the PA9 outputs a high level, a direct connection will cause a short circuit, and the current flows from the VDDIOX inside the PA9 of the STM32G0B1 through the P-MOS, out from the PA9 pin, and after the connection The line reaches the INT pin of LIS2DH12, and flows from the internal M-MOS to VSS. There is no resistance in the middle and a short circuit is caused, which is likely to cause damage to the chip. So be careful!
As a multiplexing input function, PA10 does not have this risk.
in conclusion
Due to the existence of the empty chip detection function, when the STM32 model with this function is started with an empty chip, it will enter the system storage area and execute the internal Bootloader. The internal Bootloader will set some GPIOs as multiplexed function output pins and output high level or low level. If this pin is connected to the output pin of the external chip as an input pin in the user application, then the STM32 blank chip will be used beforehand. When soldering on the user board, power-on may bring great risks. If you encounter STM32 with empty chip detection function in GPIO design, you must pay attention to this.
Solution
Two solutions are available for users to choose from.
1) A resistor is inserted in series in the connection of the two chips for protection. The current flowing through this resistor must be lower than the injection current of the GPIO, and it must also ensure that the high and low level recognition on both sides is not affected.
2) In the case of using the STM32 model with the empty chip detection function, the multiplexed function output pins used and configured by the Bootloader described in AN2606 should be checked in advance in the hardware design, and the GPIO design should be avoided in the user application. as an input pin.
The above two methods, the second method is recommended, which is simpler and more secure.
Source: STM32 microcontroller
The Links: LM150X04-TL01 7MBR150VN120-50