Kinetis K53 write to SIM_SOPT1CFG causes bus fault

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

Kinetis K53 write to SIM_SOPT1CFG causes bus fault

跳至解决方案
1,834 次查看
kfranz
Contributor III

I am trying to modify SIM_SOPT1CFG.

Either line of 'C' code causes a bus fault:

SIM_SOPT1CFG |= (SIM_SOPT1CFG_URWE_MASK);

or

*(unsigned long *)0x40047004 |= (0x1000000u);

 

When at either line of code above I can use a JTAG debugger and manually set the bit. So, I know the register can be accessed via the JTAG debugger when at that line of code.

What am I missing? Why can't I do this?

0 项奖励
回复
1 解答
1,805 次查看
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @kfranz,

please try it this way instead;

SIM->SOPT1CFG |= SIM_SOPT1CFG_URWE_MASK;

 As this is the way you can access the register now. Hope it helps!

Best regards, Julian

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,802 次查看
bobpaddock
Senior Contributor III

Is there any clocks that need turned on to access this register?
The debugger could have different clocking systems going on.

Also do you really need to read the register with '|='?
NXP frequently shows these in examples where only simple assignment '=' should be used.

0 项奖励
回复
1,797 次查看
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @bobpaddock,

The '|=' operators are a simple way to access a register without overwriting it, this way, the configuration you add will be additional and will not affect any other bits.

Best regards, Julian

0 项奖励
回复
1,789 次查看
bobpaddock
Senior Contributor III

The |= is a Read-Modify-Write operation that at best wastes time when
used, where an assignment is appropriate.

At its worst using |= can unintentionally clear unexpected bits,
causing interrupts to be lost, when assignment was the intention on
status registers that have Write-1-To-Clear (W1C) bits.

It is simply bad practice to use |= when it is not needed.

Sadly the NXP documentation and example code is full of this bad
practice, and it harms people new to Embedded System development by
setting a bad precedent of coding style.

 

0 项奖励
回复
1,806 次查看
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @kfranz,

please try it this way instead;

SIM->SOPT1CFG |= SIM_SOPT1CFG_URWE_MASK;

 As this is the way you can access the register now. Hope it helps!

Best regards, Julian

0 项奖励
回复