我把我的业务逻辑,初始化代码,全都注释掉
然后在 IAR 的 Linker 选项里添加:--redirect GPIO_PinModeSet=_wrap_GPIO_PinModeSet
将 GPIO_PinModeSet 重定向到我自己实现的 _wrap_GPIO_PinModeSet 函数里
然后在里面添加了打印 TAL_PR_DEBUG("call GPIO_PinModeSet(%d, %d, %d, %d)\n", port, pin, mode, out);
这样就可以监视所有的 GPIO_PinModeSet 调用
Code: Select all
void _wrap_GPIO_PinModeSet(GPIO_Port_TypeDef port,
unsigned int pin,
GPIO_Mode_TypeDef mode,
unsigned int out)
{
TAL_PR_DEBUG("call GPIO_PinModeSet(%d, %d, %d, %d)\n", port, pin, mode, out);
/* If disabling a pin, do not modify DOUT to reduce the chance of */
/* a glitch/spike (may not be sufficient precaution in all use cases). */
if (mode != gpioModeDisabled) {
if (out) {
GPIO_PinOutSet(port, pin);
} else {
GPIO_PinOutClear(port, pin);
}
}
/* There are two registers controlling the pins for each port. The MODEL
* register controls pins 0-7 and MODEH controls pins 8-15. */
if (pin < 8) {
GPIO->P[port].MODEL = (GPIO->P[port].MODEL & ~(0xFu << (pin * 4))) | (mode << (pin * 4));
} else {
GPIO->P[port].MODEH = (GPIO->P[port].MODEH & ~(0xFu << ((pin - 8) * 4))) | (mode << ((pin - 8) * 4));
}
if (mode == gpioModeDisabled) {
if (out) {
GPIO_PinOutSet(port, pin);
} else {
GPIO_PinOutClear(port, pin);
}
}
}
重新编译后,程序跑起来之后,log 会一直打印:
Code: Select all
[D] : call GPIO_PinModeSet(0, 5, 0, 1)
[D] : call GPIO_PinModeSet(0, 5, 4, 1)
[D] : call GPIO_PinModeSet(0, 5, 0, 1)
[D] : call GPIO_PinModeSet(0, 5, 4, 1)
[D] : call GPIO_PinModeSet(0, 5, 0, 1)
[D] : call GPIO_PinModeSet(0, 5, 4, 1)
[D] : call GPIO_PinModeSet(0, 5, 0, 1)
[D] : call GPIO_PinModeSet(0, 5, 4, 1)
[D] : call GPIO_PinModeSet(0, 5, 0, 1)
[D] : call GPIO_PinModeSet(0, 5, 4, 1)
[D] : call GPIO_PinModeSet(0, 5, 0, 1)
[D] : call GPIO_PinModeSet(0, 5, 4, 1)
[D] : call GPIO_PinModeSet(0, 5, 0, 1)
[D] : call GPIO_PinModeSet(0, 5, 4, 1)
[D] : call GPIO_PinModeSet(0, 5, 0, 1)
[D] : call GPIO_PinModeSet(0, 5, 4, 1
说明一直有某个逻辑在循环设置 gpio PA5 的模式
我的程序里的所有 GPIO_PinModeSet 和 tal_gpio_init 我都注释了,还是会这样