AnsweredAssumed Answered

Accessing HAL TIM struct fields pointers inside other structs correctly.

Question asked by Eugenia Suarez on Apr 25, 2017
Latest reply on Apr 27, 2017 by Eugenia Suarez

I have the following structs (from a library I'm using) with some fields and I would like to assign with OR operation a new value. But I'm debugging and I can't see how anything is writing there:

typedef struct {   
TIM_TypeDef             
*Instance;     /*!< Register base address  */  
TIM_Base_InitTypeDef    
Init;          /*!< TIM Time Base required parameters */  
HAL_TIM_ActiveChannel   
Channel;       /*!< Active channel                    */  
DMA_HandleTypeDef       
*hdma[7];      /*!< DMA Handlers array This array is accessed by a @ref DMA_Handle_index */
HAL_LockTypeDef          Lock;          /*!< Locking object                    */  
__IO HAL_TIM_StateTypeDef  
State;         /*!< TIM operation state               */
}TIM_HandleTypeDef;

typedef struct
{ 
__IO
uint32_t CR1;         /*!< TIM control register 1,                   Address offset: 0x00 */ 
__IO
uint32_t CR2;         /*!< TIM control register 2,                   Address offset: 0x04 */ 
__IO
uint32_t SMCR;        /*!< TIM slave mode control register,          Address offset: 0x08 */ 
__IO
uint32_t DIER;        /*!< TIM DMA/interrupt enable register,        Address offset: 0x0C */ 
__IO
uint32_t SR;          /*!< TIM status register,                      Address offset: 0x10 */ 
__IO
uint32_t EGR;         /*!< TIM event generation register,            Address offset: 0x14 */ 
__IO
uint32_t CCMR1;       /*!< TIM capture/compare mode register 1,      Address offset: 0x18 */ 
__IO
uint32_t CCMR2;       /*!< TIM capture/compare mode register 2,      Address offset: 0x1C */ 
__IO
uint32_t CCER;        /*!< TIM capture/compare enable register,      Address offset: 0x20 */ 
__IO
uint32_t CNT;         /*!< TIM counter register,   
...                  
} TIM_TypeDef;

I have a part of code where I defined:

 TIM_HandleTypeDef  TIMER_Struct;

And I would like to access the field "CR1" of TIM_TypeDef struct that is "*Instance" field of TIM_HandleTypeDef. So I have done it by this way in a function:

 void DRV_TIMER_init(void) 
{ 
... 
TIMER_Struct.Instance = TIMx;//TIM7
TIMER_Struct
.Init.Period            = 100 - 1; 
TIMER_Struct
.Init.Prescaler         = uwPrescalerValue; 
TIMER_Struct
.Init.ClockDivision     = 0; // these accesses work  
TIMER_Struct
.Instance -> CR1 |= 0x01 << 3; // this no works 
...
}

Even if I write directly:

 TIMER_Struct.Instance -> CR1 = 0xFFFFFFFF; 

It stills without having effect.

I think It could be a fact that I'm not controlling appropiately the pointer access or similar. But I don't see how can I access and modify the content of the commented field. Since I can see (debug mode) how the rest of struct fields updates are writen correctly.

Any correction suggested here?

TIMER_Struct.Instance -> CR1 = 0xFFFFFFFF; 

I try different ways to get it with no success. I need new ideas. How would you do if you want write there?

Thanks in advance.

Outcomes