Macros in TivaWare
FreeDirect register access macros for Tiva microcontrollers without driverlib conflicts
About Macros in TivaWare
Macros in TivaWare are a set of C preprocessor macros defined in hw_types.h (within the TivaWare inc folder) that enable direct register access on Texas Instruments Tiva microcontrollers without conflicting with the driver library headers. They include HWREG for 32-bit register access, HWREGH for 16-bit, HWREGB for 8-bit, and bit-banding variants HWREGBITW, HWREGBITH, and HWREGBITB for atomic bit manipulation. These macros allow embedded developers to bypass TivaWare's driverlib for performance-critical or low-level operations while avoiding redefinition warnings that occur when including both tm4c123gh6pm.h and driverlib headers. The tutorial on Luis Electronic Projects provides examples of using these macros to set GPIO outputs and enable peripheral clocks.
Key Features
Pros & Cons
- Eliminates redefinition conflicts between raw header and driverlib headers
- Bit-banding macros allow single-cycle atomic bit set/clear
- Supports multiple word widths to save memory on narrower registers
- Well-integrated into TivaWare; no external dependencies
- Lightweight and zero overhead compared to function calls
- Not fully equivalent to driverlib functions (e.g., missing assertion checks)
- Requires knowledge of register offsets and bit positions
- Less readable and more error-prone than high-level driverlib API
- Only applicable to Tiva (ARM Cortex-M4F) microcontrollers