Macros in TivaWare logo

Macros in TivaWare

Free

Direct register access macros for Tiva microcontrollers without driverlib conflicts

FreeFree tier
Type
Open Source
Company
Texas Instruments

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

Macros for 32-bit, 16-bit, and 8-bit register access (HWREG, HWREGH, HWREGB)
Bit-banding macros for atomic bit manipulation (HWREGBITW, HWREGBITH, HWREGBITB)
Prevents redefinition warnings when mixing direct register and driverlib code
Enables low-level hardware control while staying within TivaWare ecosystem
Defined in standard TivaWare header `hw_types.h`

Pros & Cons

Pros
  • 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
Cons
  • 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

Best For

Direct register programming on Tiva LaunchPad microcontrollersReplacing driverlib function calls with faster inline register accessEnabling peripheral clocks using bit-banding (e.g., SysCtlPeripheralEnable equivalent)Setting GPIO output pins (e.g., LED control via HWREG on PORTF)Reading/writing configuration registers where driverlib abstraction is unnecessary

FAQ

What is HWREG in TivaWare?
HWREG is a macro that performs a direct 32-bit read/write to a memory address, typically used for accessing microcontroller registers.
How do HWREGBITW macros work?
HWREGBITW takes a register base address and a bit number, then uses the ARM bit-banding mechanism to atomically modify just that single bit.
Can I mix driverlib and direct register macros in the same project?
Yes, using the TivaWare macros (from hw_types.h) avoids the redefinition warnings that occur when you include both the raw chip header and driverlib headers.
Where can I find these macros?
They are defined in the file 'hw_types.h' inside the 'inc' folder of your TivaWare installation.