问题描述
我目前正在 STM32F302VB 上进行开发,我需要执行软件重置.在我之前的所有项目(使用 STM32F427 和 STM32F030C8)中,我一直成功地使用了 NVIC_SystemReset() 函数.但由于某种原因,它不适用于该芯片.实现在CMSIS core_cm4.h中,如下:
I'm currently developing on a STM32F302VB and I need to perform a software reset. On all my previous projects (with STM32F427 and STM32F030C8), I've always used the NVIC_SystemReset() function successfully. But for some reason it won't work with this chip.The implementation is in CMSIS core_cm4.h and is as follows:
__STATIC_INLINE void NVIC_SystemReset(void)
{
__DSB(); /* Ensure all outstanding memory accesses included buffered write are completed before reset */
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
(SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */
__DSB(); /* Ensure completion of memory access */
while(1); /* wait until reset */
}
该函数被调用并执行了所有指令,但它卡在了while循环中,并且从未发生过reset.然后我必须通过 JTAG 将其重置以使其退出该状态.
The function is called and all instructions are executed, but it gets stuck in the while loop, and reset never happens. I then have to reset it via JTAG to get it out of that state.
我查看了编程手册,实现似乎很好(这并不奇怪,因为它在 F4 和 F0 上运行完美).
I checked the programming manual and the implementation seems fine (not surprising since it works perfectly on F4 and F0).
我真的不知道可能是什么问题,有人知道发生了什么吗?
I really don't know what the problem might be, does someone have an idea what's going on?
该功能仍然无法正常工作,但作为一种解决方法,在该功能卡住后,我将 nRST 引脚拉低,然后再拉高.这很丑陋,但它现在有效.不过,我更愿意用软件来做这一切.
The function is still not working but as a workaround, after the function gets stuck, I pull down the nRST pin and then up. It's ugly, but it works for now. I would rather do it all in software though.
推荐答案
Tony K 在他的评论中是正确的,由于布线错误,nRST 引脚确实被外部拉高了.
Tony K was right in his comment, the nRST pin was indeed being pulled high externally, because of a routing mistake.
与我的想法相反,即使在软件重置中也会考虑 nRST 引脚:参考手册说:[重置] 源作用于 NRST 引脚,并且在延迟阶段始终保持低电平",所以我应该知道!
And contrary to what I thought, the nRST pin is taken into account even in a software reset: the reference manual says: "[Reset] sources act on the NRST pin and it is always kept low during the delay phase", so I should have known!
去掉上拉就成功了,NVIC_SystemReset() 函数现在可以正常工作了!
Removing the pull-up did the trick, the NVIC_SystemReset() function now works as expected!
非常感谢!
这篇关于NVIC_SystemReset() 卡在 while 循环中 (STM32F302VB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!