Kinetis K53 write to SIM_SOPT1CFG causes bus fault

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Kinetis K53 write to SIM_SOPT1CFG causes bus fault

Jump to solution
826 Views
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 Kudos
1 Solution
797 Views
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

View solution in original post

0 Kudos
4 Replies
794 Views
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 Kudos
789 Views
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 Kudos
781 Views
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 Kudos
798 Views
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 Kudos