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.
Hi Keith:
The macro is used to write a value into a register. Not for reading.
For example, if the ram size is 512.
Then with macro SIM_SOPT1_RAMSIZE, you can set the relative bit field to 512.
Regards
Daniel
Thank you. I knew I was missing something.