SPI Interrupts Secretly Halting Program in Debug Mode

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

SPI Interrupts Secretly Halting Program in Debug Mode

跳至解决方案
1,486 次查看
dave_harmonjr
Contributor III

I am using an MKE04Z1284 mcu. I have a program that I wrote to try and get SPI coms working between it and another processor. The MKE04 is a slave fyi. The code right now runs all the init functions, then it turns a gpio on to flag to the other processor it wants to send a message via spi. Just before it does that, it runs the function "SPI_SlaveTransferNonBlocking" to load up the spi register for the incoming clock signals from the master to get the byte. This causes SPI1_DriverIRQHandler to go off. When it does this the program halts at SPI1_DriverIRQHandler and does not continue unless I press the pause debugger button and manually step it through. Even stranger it seems to do this for literally every function in the custom spi send function I have because spi interrupts keep going off throughout the function. This is causing it to be impossible to debug. It wasn't doing this previously and I have no idea what I could have done to cause it and I have spent hours researching this and haven't gotten anywhere.

Other notes: There are no breakpoints at all. I have tried both PEMicro and JLinks. Also have restarted the pc, restarted the program, rebuilt, cleaned, restarted the debugger interfaces etc..

 

If I build it as release and use the flash programmer to program on the release version it runs perfectly fine with no halting.

 

I have attached the project.

0 项奖励
回复
1 解答
1,466 次查看
dave_harmonjr
Contributor III

I solved the issue. A stray strand of wire was bridging the CS line to ground which was causing that SPI Interrupt to go off relentlessly. Once I removed that it stopped getting jammed up after calling the spi transfer function once.

在原帖中查看解决方案

3 回复数
1,476 次查看
myke_predko
Senior Contributor III

Hi @dave_harmonjr ,

What is the size of your stack?  I think you might have blown the stack and it is pointing to Non-SRAM memory which is why it's halting.  

I'm not familiar with the MKE04Z1284, but if it was in the K22 family, I would expect to get a semi-host hardfault (which you might be getting but there isn't a handler for it).  

What happens if you single step out of the ISR?  If my suspicion is correct, the code will jump to somewhere outside of the Flash memory range.

Good luck,

myke

0 项奖励
回复
1,474 次查看
dave_harmonjr
Contributor III

My stack size is 512B. I opened up the stack/heap monitor and stepped through and it never exceeded 29% usage. After stepping through more I can see it really just looks like SPI interrupts are halting the program. The weird thing is the debugger shows it still running, but when I press pause on it it is always in the same spi interrupt function and steps through normally. 

 

Another bizzare note: if I flash the chip (no debugger attached) while it is running, it will actually run normally. If I reset that chip it doesn't seem to boot up. But if I flash it again with the same firmware it starts running.

 

 

 

The picture below is what the stack looks like when I press pause to see where it is halting on its own.

dave_harmonjr_0-1600950885262.png

 

0 项奖励
回复
1,467 次查看
dave_harmonjr
Contributor III

I solved the issue. A stray strand of wire was bridging the CS line to ground which was causing that SPI Interrupt to go off relentlessly. Once I removed that it stopped getting jammed up after calling the spi transfer function once.