Delay loops gone crazy

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

Delay loops gone crazy

跳至解决方案
604 次查看
ve3id
Contributor III

I'm picking up a project that I put aside 7 months ago.  It involves using SPI to communicate with a Nordic Semiconductor nRF24l01 module from a FRDM-K64F using MCUExpresso24.12(Build148) IDE.

.  
When I left it, it happily wrote sign-on and copyright banners and then went to handling RF.

While it still sends RF, it is painfully slow sending two screens of data to the HD44870 2x16 display.   Like 3 seconds per character.

As I am using an LCD daughter card designed for the Arduino, it does not have the  BUSY bit wired from the LCD, so I am using delay loops.

But nothing should have been changed in the program, sitting on the shelf!  As of the last time I ran it, the screen update was like a flash, as is evidenced by one FRDM-K64F that still had the old version of the program in it.

I have tried stepping through all delay loops, they have the expected number of cycles.  I have tried trapping unwanted interrupts, even turning of interrupts, no change.  I suspected maybe an update to gcc has an optimisation flag set/no set, but that would have the opposite effect, speeding up the display and getting garbage due to not waiting long enough.  The last working version was compiled with the same version of MCUExpresso.  I am not aware of any updates.

It stays slow whether it is connected to the PC's IDE connection using Linkserver or standalone!

The LCD is not going to be in the final product, it's just for debugging, but this strange anomaly is driving me crazy and I need to get it fixed.

Any help really appreciated, I'm hoping somebody has seen something like this and has an answer!

Thanks in advance,

Cheers,

Nigel

 

 

 

0 项奖励
回复
1 解答
555 次查看
bobpaddock
Senior Contributor III
GCC when set to build the 'Small' model with -Os can be aggressive about removing code, breaking busy loops that have no side effects.  I always put nop() that has the proper guards into my loops. Odd delay behavior in this case indicates a missing volatile somewhere.

Early AVR-LIBC implementations requires passing a float to the delay functions. Compiler coercions turned it into the required number of cycles. Failing to do that got strange delays. Modern implementations take an unsigned int.

That you can single step does seem to negate those.


static inline void nop( void )
{
__asm__ __volatile__ ("nop");
}

在原帖中查看解决方案

0 项奖励
回复
2 回复数
556 次查看
bobpaddock
Senior Contributor III
GCC when set to build the 'Small' model with -Os can be aggressive about removing code, breaking busy loops that have no side effects.  I always put nop() that has the proper guards into my loops. Odd delay behavior in this case indicates a missing volatile somewhere.

Early AVR-LIBC implementations requires passing a float to the delay functions. Compiler coercions turned it into the required number of cycles. Failing to do that got strange delays. Modern implementations take an unsigned int.

That you can single step does seem to negate those.


static inline void nop( void )
{
__asm__ __volatile__ ("nop");
}

0 项奖励
回复
537 次查看
ve3id
Contributor III
Thanks, Bob,
I did find one missing volatile in another loop that had previously raised my eyebrows but not important enough to tackle until I had fixed the main problem, however I still have the same problem. But now I am seeing stray interrupts, so that is where I will spend the next little while
0 项奖励
回复
%3CLINGO-SUB%20id%3D%22lingo-sub-2255470%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E7%96%AF%E7%8B%82%E7%9A%84%E5%BB%B6%E8%BF%9F%E5%BE%AA%E7%8E%AF%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2255470%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E6%88%91%E6%AD%A3%E5%9C%A8%E9%87%8D%E6%8B%BE%207%20%E4%B8%AA%E6%9C%88%E5%89%8D%E6%90%81%E7%BD%AE%E7%9A%84%E4%B8%80%E4%B8%AA%E9%A1%B9%E7%9B%AE%E3%80%82%20%E5%AE%83%E6%B6%89%E5%8F%8A%E4%BD%BF%E7%94%A8%20SPI%20%E4%BD%BF%E7%94%A8%20MCUExpresso24.12%20(Build148)%20%E4%B8%8E%20FRDM-K64F%20%E4%B8%AD%E7%9A%84%E5%8C%97%E6%AC%A7%E5%8D%8A%E5%AF%BC%E4%BD%93%20nRF24L01%20%E6%A8%A1%E5%9D%97%E9%80%9A%E4%BF%A1IDE.%3C%2FP%3E%3CP%3E.%20%3CBR%20%2F%3E%E5%BD%93%E6%88%91%E7%A6%BB%E5%BC%80%E5%AE%83%E6%97%B6%EF%BC%8C%E5%AE%83%E5%BE%88%E9%AB%98%E5%85%B4%E5%9C%B0%E5%86%99%E4%BA%86%E7%99%BB%E5%BD%95%E5%92%8C%E7%89%88%E6%9D%83%E6%A0%87%E8%AF%AD%EF%BC%8C%E7%84%B6%E5%90%8E%E5%B0%B1%E5%8E%BB%E5%A4%84%E7%90%86%20RF%20%E4%BA%86%E3%80%82%3C%2FP%3E%3CP%3E%E8%99%BD%E7%84%B6%E5%AE%83%E4%BB%8D%E8%83%BD%E5%8F%91%E9%80%81%E5%B0%84%E9%A2%91%EF%BC%8C%E4%BD%86%E5%90%91%20HD44870%202x16%20%E6%98%BE%E7%A4%BA%E5%99%A8%E5%8F%91%E9%80%81%E4%B8%A4%E5%B1%8F%E6%95%B0%E6%8D%AE%E7%9A%84%E9%80%9F%E5%BA%A6%E6%85%A2%E5%BE%97%E6%83%8A%E4%BA%BA%E3%80%82%20%20%20%E6%AF%94%E5%A6%82%E6%AF%8F%E4%B8%AA%E8%A7%92%E8%89%B2%203%20%E7%A7%92%E9%92%9F%E3%80%82%3C%2FP%3E%3CP%3E%E7%94%B1%E4%BA%8E%E6%88%91%E4%BD%BF%E7%94%A8%E7%9A%84%E6%98%AF%E4%B8%93%E4%B8%BA%20Arduino%20%E8%AE%BE%E8%AE%A1%E7%9A%84%20LCD%20%E5%AD%90%E5%8D%A1%EF%BC%8C%E5%AE%83%E6%B2%A1%E6%9C%89%E4%BB%8E%20LCD%20%E8%BF%9E%E6%8E%A5%E7%9A%84%20BUSY%20%E4%BD%8D%EF%BC%8C%E5%9B%A0%E6%AD%A4%E6%88%91%E4%BD%BF%E7%94%A8%E4%BA%86%E5%BB%B6%E8%BF%9F%E5%9B%9E%E8%B7%AF%E3%80%82%3C%2FP%3E%3CP%3E%E4%BD%86%E6%98%AF%EF%BC%8C%E7%A8%8B%E5%BA%8F%E4%B8%AD%E7%9A%84%E4%BB%BB%E4%BD%95%E5%86%85%E5%AE%B9%E9%83%BD%E4%B8%8D%E5%BA%94%E8%AF%A5%E6%94%B9%E5%8F%98%EF%BC%8C%E9%83%BD%E5%BA%94%E8%AF%A5%E6%9D%9F%E4%B9%8B%E9%AB%98%E9%98%81%EF%BC%81%20%E5%9C%A8%E6%88%91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%A7%8D%E5%A5%87%E6%80%AA%E7%9A%84%E5%BC%82%E5%B8%B8%E7%8E%B0%E8%B1%A1%E5%BF%AB%E6%8A%8A%E6%88%91%E9%80%BC%E7%96%AF%E4%BA%86%EF%BC%8C%E6%88%91%E5%BF%85%E9%A1%BB%E6%8A%8A%E5%AE%83%E4%BF%AE%E5%A5%BD%E3%80%82%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%E5%B8%8C%E6%9C%9B%E6%9C%89%E4%BA%BA%E8%A7%81%E8%BF%87%E7%B1%BB%E4%BC%BC%E6%83%85%E5%86%B5%E5%B9%B6%E8%83%BD%E7%BB%99%E5%87%BA%E7%AD%94%E6%A1%88%EF%BC%81%3C%2FP%3E%3CP%3E%E6%8F%90%E5%89%8D%E6%84%9F%E8%B0%A2%EF%BC%81%3C%2FP%3E%3CP%3E%E5%B9%B2%E6%9D%AF%EF%BC%8C%3C%2FP%3E%3CP%3E%E5%A5%88%E6%9D%B0%E5%B0%94%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2256282%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Delay%20loops%20gone%20crazy%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2256282%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E8%B0%A2%E8%B0%A2%E4%BD%A0%EF%BC%8C%E9%B2%8D%E5%8B%83%EF%BC%8C%3CBR%20%2F%3E%EF%BC%8C%E6%88%91%E7%A1%AE%E5%AE%9E%E5%9C%A8%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%BE%AA%E7%8E%AF%E4%B8%AD%E5%8F%91%E7%8E%B0%E4%BA%86%E4%B8%80%E4%B8%AA%E7%BC%BA%E5%A4%B1%E7%9A%84%E6%B3%A2%E5%8A%A8%EF%BC%8C%E8%BF%99%E4%B8%AA%E9%97%AE%E9%A2%98%E4%B9%8B%E5%89%8D%E6%9B%BE%E5%BC%95%E8%B5%B7%E8%BF%87%E6%88%91%E7%9A%84%E6%B3%A8%E6%84%8F%EF%BC%8C%E4%BD%86%E5%9C%A8%E8%A7%A3%E5%86%B3%E4%B8%BB%E8%A6%81%E9%97%AE%E9%A2%98%E4%B9%8B%E5%89%8D%E8%BF%98%E4%B8%8D%E8%B6%B3%E4%BB%A5%E8%A7%A3%E5%86%B3%EF%BC%8C%E4%B8%8D%E8%BF%87%E6%88%91%E8%BF%98%E6%98%AF%E9%81%87%E5%88%B0%E4%BA%86%E5%90%8C%E6%A0%B7%E7%9A%84%E9%97%AE%E9%A2%98%E3%80%82%E4%BD%86%E7%8E%B0%E5%9C%A8%E6%88%91%E7%9C%8B%E5%88%B0%E7%9A%84%E6%98%AF%E6%9D%82%E6%95%A3%E4%B8%AD%E6%96%AD%EF%BC%8C%E6%89%80%E4%BB%A5%E6%8E%A5%E4%B8%8B%E6%9D%A5%E7%9A%84%E4%B8%80%E6%AE%B5%E6%97%B6%E9%97%B4%E6%88%91%E5%B0%86%E5%9C%A8%E8%BF%99%E9%87%8C%E5%BA%A6%E8%BF%87%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2256173%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Delay%20loops%20gone%20crazy%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2256173%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E5%BD%93GCC%E8%AE%BE%E7%BD%AE%E4%B8%BA%E4%BD%BF%E7%94%A8-Os%E7%89%88%E6%9C%AC%20%E2%80%9C%E5%B0%8F%E5%9E%8B%E2%80%9D%20%E6%A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E%B0%E5%A5%87%E6%80%AA%E7%9A%84%E5%BB%B6%E8%AF%AF%E3%80%82%E7%8E%B0%E4%BB%A3%E5%AE%9E%E7%8E%B0%E9%87%87%E7%94%A8%E6%97%A0%E7%AC%A6%E5%8F%B7%20int%E3%80%82%3CBR%20%2F%3E%3CBR%20%2F%3E%E4%BD%A0%E5%8F%AF%E4%BB%A5%E5%8D%95%E6%AD%A5%E8%B5%B0%E4%BC%BC%E4%B9%8E%E5%90%A6%E5%AE%9A%E4%BA%86%E8%BF%99%E4%B8%80%E7%82%B9%E3%80%82%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Estatic%20inline%20void%20nop(%20void%20)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E__asm__%20__volatile__%20(%22nop%22)%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E