AnsweredAssumed Answered

Inconsistent Register Behavior (Inaccessible PWM structure Registers)

Question asked by Steve Janisch on Apr 23, 2013
Latest reply on Apr 24, 2013 by Martin Kojtal

I am porting workable code developed in Processor Expert to MQX 4.0.  I am using the TWR-MCF5441X Tower.

 

I started by reproducing PE macros setReg16, getReg16, clrReg16Bits, and setReg8Bits.

 

I then replace the register definitions in PE with the board pointer (pX).

 

What I am seeing is that certain registers are accessible this way, and others are not.

 

For example, the GPIO structure IS accessible and I can toggle an LED on the board with this code:

  clrReg16Bits( pX->GPIO.PCR_G, 0x03U ) ;   // G0: 0x03 : 10 Pull-Enabled, 01 Pull-Up

  setReg8Bits(  pX->GPIO.PODR_G,  0x01U ) ; // Set Port G.0 high, all others low

  setReg8Bits(  pX->GPIO.PDDR_G,  0x01U ) ; // Configure G.0 as output          


The PWM structure, on the other hand IS NOT accessible.  When I read the registers back all values return 0xFFFF.

  setReg16( pX->PWM.PWM_SM0INIT,  0xFF00U ) ; // Initial - Start/Minimum/Reset Count

  setReg16( pX->PWM.PWM_SM0VAL0,  0x0000U ) ; // Value 0 - middle point of PWM period

  setReg16( pX->PWM.PWM_SM0VAL1,  0x0100U ) ; // Value 1 - End/Maximum/Modulo/Counter Reload


Since I am trying to build a driver for the mcPWM module, this is a problem.

 

Can anyone shed light on why I can access certain registers but not others this way?

Is it feasible there are some code enables deep within the BSP that are preventing these registers from being read or written (I would suspect the access problem is two-way since the registers all appear to be 0xFFFF on boot while from the PE example they are zero).

 

 

 

Full Example Code

// Macros from processor expert.................................................

#define setReg16(RegName, val)          (RegName = (uint_16)(val))

#define getReg16(RegName)               (RegName)

#define clrReg16Bits(RegName, ClrMask)  (RegName &= (uint_16)(~(uint_16)(ClrMask)))

#define setReg8Bits(RegName, SetMask)   (RegName |= (uint_8)(SetMask))


 

 

// Board pointer and test variable..............................................

VMCF5441_STRUCT_PTR  pX   = _PSP_GET_IPSBAR() ;

uint_16              nVal = 0 ;


 

 

void test( void )

{

  // Turn on LED1===============================================================

  // This is just an easily verifiable initial test to ensure understanding of code

  // Direct Access through pointer to GPIO Register... WORKS

  // (Verified by seeing LED illuminate and reading back register values)

  clrReg16Bits( pX->GPIO.PCR_G, 0x03U ) ;   // G0: 0x03 : 10 Pull-Enabled, 01 Pull-Up

  setReg8Bits(  pX->GPIO.PODR_G,  0x01U ) ; // Set Port G.0 high, all others low

  setReg8Bits(  pX->GPIO.PDDR_G,  0x01U ) ; // Configure G.0 as output          

 

 

  nVal = pX->GPIO.PCR_G ;

  nVal = pX->GPIO.PODR_G ;

  nVal = pX->GPIO.PDDR_G ;

 

  // PWM Configuration==========================================================

  // Direct Access through pointer to PWM Structure... DOES NOT WORK

  // (Reading back register values denotes 0xFFFF in every register)

  setReg16( pX->PWM.PWM_SM0INIT,  0xFF00U ) ; // Initial - Start/Minimum/Reset Count

  setReg16( pX->PWM.PWM_SM0VAL0,  0x0000U ) ; // Value 0 - middle point of PWM period

  setReg16( pX->PWM.PWM_SM0VAL1,  0x0100U ) ; // Value 1 - End/Maximum/Modulo/Counter Reload

 

 

  // All reads return 0xFFFF

  nVal = pX->PWM.PWM_SM0INIT ;

  nVal = pX->PWM.PWM_SM0VAL0 ;

  nVal = pX->PWM.PWM_SM0VAL1 ;

}

Outcomes