Register writes - 32 bits at a time only?

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

Register writes - 32 bits at a time only?

563 Views
elijahbrown
Contributor III

I'm doing a bare metal project and was configuring the PWM peripheral when I ran across a strange bug.  I'm using the imx6 bare metal SDK register definitions, which are produced by the IOMUX tool.  Every time I wrote HW_PWM_PWMSAR(instance).B.SAMPLE, it wouldn't take effect.  I would read it back and it was still the old value.  (This is how it's done in the PWM example in the SDK, so beware)  Looking through the assembly, the compiler was generating a strh which only writes the lower 16 bits of the register - exactly what it should do given the register is defined as:

typedef union _hw_pwm_pwmsar

{

    reg32_t U;

    struct _hw_pwm_pwmsar_bitfields

    {

        unsigned SAMPLE : 16; //!< [15:0] Sample Value.

        unsigned RESERVED0 : 16; //!< [31:16] These are reserved bits and writing a value will not affect the functionality of PWM and are always read as zero.

    } B;

} hw_pwm_pwmsar_t;

I switched to using HW_PWM_PWMSAR(instance).U which winds up doing a str into the address, writing all 32 bits and now it works just fine.  So if you write 16 bits of the register, it doesn't work.  If you write all 32 bits, it does.  This makes me very wary of using the structure bitfields, which are used all over the place in the IOMUX register definitions.  Is this an error in the PWM hardware specifically or do all registers need to be written 32 bits at a time?

Labels (3)
0 Kudos
2 Replies

458 Views
igorpadykov
NXP Employee
NXP Employee

HI Elijah

you are right PWM registers should be accessed as 32 bit

registers only:

1.jpg

Best regards

igor

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos

458 Views
elijahbrown
Contributor III

Ok.  The bare metal SDK should be fixed then, there are tons of 32 bit registers being accessed this way. 

0 Kudos