使用ESP32 ISR中的首选项
当触发中断时,我正在尝试使用首选项库将该值存储在ESP32中。
Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1)
Core 1 register dump:
PC : 0x4008867a PS : 0x00060034 A0 : 0x80087a9b A1 : 0x3ffbe860
A2 : 0x3ffb7e0c A3 : 0x3ffb8074 A4 : 0x00000001 A5 : 0x00000001
A6 : 0x00060023 A7 : 0x00000000 A8 : 0x3ffb8074 A9 : 0x3ffb8074
A10 : 0x00000001 A11 : 0x00000001 A12 : 0x00000020 A13 : 0x0000ff00
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x0000001e EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
Core 1 was running in ISR context:
EPC1 : 0x40085d07 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x4008867a
ELF file SHA256: 0000000000000000
Backtrace: 0x4008867a:0x3ffbe860 0x40087a98:0x3ffbe880 0x400860cf:0x3ffbe8a0 0x400e2f42:0x3ffbe8e0 0x400e300a:0x3ffbe900 0x40083cad:0x3ffbe920 0x400840c4:0x3ffbe940 0x400e7b01:0x3ffbe990 0x400e5f66:0x3ffbe9b0 0x400e629e:0x3ffbe9d0 0x400e5a92:0x3ffbea50 0x400e4a77:0x3ffbeac0 0x400e4e55:0x3ffbeb10 0x400d1fa4:0x3ffbeb30 0x40080ecd:0x3ffbeb50 0x40080f19:0x3ffbeb70 0x40083969:0x3ffbeb90 0x40081b46:0x3ffb1e00 0x400826ef:0x3ffb1e20 0x40081183:0x3ffb1e40 0x400811a7:0x3ffb1e60 0x400d1cb7:0x3ffb1e80 0x400d1c85:0x3ffb1ea0 0x400d1c30:0x3ffb1ec0 0x400ebb35:0x3ffb1ee0 0x400ebbfe:0x3ffb1f00 0x400d1795:0x3ffb1f30 0x400d18da:0x3ffb1f70 0x400d1b47:0x3ffb1f90 0x400d33e9:0x3ffb1fb0 0x40086295:0x3ffb1fd0
Core 0 register dump:
PC : 0x40086729 PS : 0x00060034 A0 : 0x80086bd6 A1 : 0x3ffbc020
A2 : 0x3ffbdf74 A3 : 0xb33fffff A4 : 0x00060023 A5 : 0x003fffff
A6 : 0x00060021 A7 : 0x00000000 A8 : 0x0000abab A9 : 0x0000cdcd
A10 : 0x0000abab A11 : 0x00060023 A12 : 0x00060021 A13 : 0x3ffbc0d0
A14 : 0x00000003 A15 : 0x00060b23 SAR : 0x00000013 EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
ELF file SHA256: 0000000000000000
Backtrace: 0x40086729:0x3ffbc020 0x40086bd3:0x3ffbc050 0x40088524:0x3ffbc070 0x400884da:0x3ffbc090 0x400893fb:0x00000000
Rebooting...
但是当触发中断时,我会遇到此错误。请帮助我解决这个问题
I am trying to store the value in esp32 using preferences library when an interrupt is triggered.
Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1)
Core 1 register dump:
PC : 0x4008867a PS : 0x00060034 A0 : 0x80087a9b A1 : 0x3ffbe860
A2 : 0x3ffb7e0c A3 : 0x3ffb8074 A4 : 0x00000001 A5 : 0x00000001
A6 : 0x00060023 A7 : 0x00000000 A8 : 0x3ffb8074 A9 : 0x3ffb8074
A10 : 0x00000001 A11 : 0x00000001 A12 : 0x00000020 A13 : 0x0000ff00
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x0000001e EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
Core 1 was running in ISR context:
EPC1 : 0x40085d07 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x4008867a
ELF file SHA256: 0000000000000000
Backtrace: 0x4008867a:0x3ffbe860 0x40087a98:0x3ffbe880 0x400860cf:0x3ffbe8a0 0x400e2f42:0x3ffbe8e0 0x400e300a:0x3ffbe900 0x40083cad:0x3ffbe920 0x400840c4:0x3ffbe940 0x400e7b01:0x3ffbe990 0x400e5f66:0x3ffbe9b0 0x400e629e:0x3ffbe9d0 0x400e5a92:0x3ffbea50 0x400e4a77:0x3ffbeac0 0x400e4e55:0x3ffbeb10 0x400d1fa4:0x3ffbeb30 0x40080ecd:0x3ffbeb50 0x40080f19:0x3ffbeb70 0x40083969:0x3ffbeb90 0x40081b46:0x3ffb1e00 0x400826ef:0x3ffb1e20 0x40081183:0x3ffb1e40 0x400811a7:0x3ffb1e60 0x400d1cb7:0x3ffb1e80 0x400d1c85:0x3ffb1ea0 0x400d1c30:0x3ffb1ec0 0x400ebb35:0x3ffb1ee0 0x400ebbfe:0x3ffb1f00 0x400d1795:0x3ffb1f30 0x400d18da:0x3ffb1f70 0x400d1b47:0x3ffb1f90 0x400d33e9:0x3ffb1fb0 0x40086295:0x3ffb1fd0
Core 0 register dump:
PC : 0x40086729 PS : 0x00060034 A0 : 0x80086bd6 A1 : 0x3ffbc020
A2 : 0x3ffbdf74 A3 : 0xb33fffff A4 : 0x00060023 A5 : 0x003fffff
A6 : 0x00060021 A7 : 0x00000000 A8 : 0x0000abab A9 : 0x0000cdcd
A10 : 0x0000abab A11 : 0x00060023 A12 : 0x00060021 A13 : 0x3ffbc0d0
A14 : 0x00000003 A15 : 0x00060b23 SAR : 0x00000013 EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
ELF file SHA256: 0000000000000000
Backtrace: 0x40086729:0x3ffbc020 0x40086bd3:0x3ffbc050 0x40088524:0x3ffbc070 0x400884da:0x3ffbc090 0x400893fb:0x00000000
Rebooting...
But I am getting this error when the interrupt is triggered. Please help me to resolve this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难确定,因为您没有共享任何代码,但是...您不应该从 an isr更新首选项。实际上,除非您真的真的知道自己在做什么,否则您应该在ISR内部尽可能少地做。
中断发生了不可预测的……它们实际上会中断CPU上正在执行的任何代码。这意味着该代码当前正在更改的任何数据结构都可能处于不一致的状态。从中断处理程序中调用一个使用这些数据结构的功能将导致数据损坏并可能崩溃。
除非您编写要打电话的代码,否则您不知道它叫什么。因此,您可能会说“没关系,我不使用ISR之外的首选项”,但您不知道其他功能首选项调用了哪些功能。
您可能会很幸运,有时可能会起作用...而且它也可能只是随机崩溃。
同样,除非您真的真的知道自己在做什么,否则很少有函数可以安全地在ISR内进行调用。这些通常是明确指定为安全的弗雷托函数。
中断处理程序还阻止了CPU做需要做的其他事情,因此(除非您真的知道自己在做什么),则应最大程度地减少在处理程序中的时间。
对于大多数没有经验写作中断处理程序(尤其是用Arduino Core编码的人)的人来说,最好的工作是最小的工作,并设置一个标志,该标志
loop()
检查和检查,并且在loop()
中进行工作。重要的是要用
挥发性
关键字来声明标志,以便编译器知道其值可以意外更改。同样重要的是,用
iram_attr
声明中断处理程序,以告诉系统将其代码保留在指令RAM中,以便在需要时可用。否则,如果尚未从闪存中获取中断处理程序的代码,则您的程序将崩溃。例如:
It's difficult to be sure as you didn't share any code, but... you should not update Preferences from an ISR. In fact unless you really really know what you're doing, you should do as little as possible inside an ISR.
Interrupts happen unpredictably... they literally interrupt whatever code is currently executing on the CPU. That means that any data structures the code is currently changing can be in an inconsistent state. Calling a function from the interrupt handler that uses those data structures will lead to data corruption and likely a crash.
Unless you wrote the code you're calling, you don't know what it calls. So you may say "it's okay, I'm not using Preferences outside the ISR" but you don't know what other functions Preferences calls.
You may get lucky and it may work at times... and it may also just crash randomly.
Again, unless you really really know what you're doing, there are very few functions that are safe to call inside an ISR. These are generally FreeRTOS functions that are explicitly designated as safe.
Interrupt handlers also block the CPU from doing other things it needs to do, so (unless you really really know what you're doing) you should minimize the amount of time you spend in the handler.
For most people who don't have experience writing interrupt handlers (especially people coding with the Arduino core), the best thing to do is the minimal work possible and set a flag that
loop()
inspects, and do the work inloop()
.It's important that the flag be declared with the
volatile
keyword so that the compiler knows that its value can be changed unexpectedly.It's also important that the interrupt handler be declared with
IRAM_ATTR
, to tell the system to keep its code loaded in instruction RAM so that it will be available when needed. Otherwise your program will crash if the code for the interrupt handler hasn't already been fetched from flash memory.For instance: