AnsweredAssumed Answered

Problem with macros in mk22f51212.h from SDK

Question asked by Keith Smith on Sep 5, 2018
Latest reply on Sep 7, 2018 by Keith Smith

Attached is my copy of mk22f51212.h from the Kinetis SDK for K22F Freedom board, v2.3.1.

 

Structures defining various base register types, such as SIM_Type or  RTC_Type, etc. are properly defined.

 

The macros that are used to extract bit fields from these structures seem to be wrong.

The intent appears to be to move the bit field in the low order bits of uint32_t variable.

 

However, the shift operator << should be >>.

 

Am I missing something? Is there some big endian/little endian issue I don't understand?

 

Example:

 

#define SIM_SOPT1_RAMSIZE_MASK (0xF000U)
#define SIM_SOPT1_RAMSIZE_SHIFT (12U)
#define SIM_SOPT1_RAMSIZE(x) (((uint32_t)(((uint32_t)(x)) << SIM_SOPT1_RAMSIZE_SHIFT)) & SIM_SOPT1_RAMSIZE_MASK)

 

===================================================================

#include "MK22F51212.h"

 

SIM_Type *pSIM = (SIM_Type*)SIM_BASE;

uint32_t ram_size = SIM_SOPT1_RAMSIZE(pSIM->SOPT1);

============================================================================

 

ram_size returns zero as the bit field is shifted the wrong direction.

Attachments

Outcomes