Common Macro Definitions in C for STM32
In embedded development, utilizing common macro definitions can enhance project compatibility and portability across various platforms.
Prevent Header Files from Being Redefined
Custom Data Types
Defining custom data types is essential to ensure consistency in the byte sizes of types across different platforms and compilers. This approach also facilitates portability.
typedef unsigned char boolean; /* Boolean value type. */
typedef unsigned long int uint32; /* Unsigned 32-bit value */
typedef unsigned short uint16; /* Unsigned 16-bit value */
typedef unsigned char uint8; /* Unsigned 8-bit value */
typedef signed long int int32; /* Signed 32-bit value */
typedef signed short int16; /* Signed 16-bit value */
typedef signed char int8; /* Signed 8-bit value */
Accessing a Word or Byte at a Specified Address
Finding the Maximum / Minimum Value
Determining the Number of Elements in an Array
Converting the First Letter to Uppercase
Checking if a Character is a Decimal Digit
Checking if a Character is a Hexadecimal Digit
#define HEXCHK(c) (((c) >= '0' && (c) <= '9') ||\
((c) >= 'A' && (c) <= 'F') ||\
((c) >= 'a' && (c) <= 'f'))
References and Acknowledgments
Original: https://wiki-power.com/
This post is protected by CC BY-NC-SA 4.0 agreement, should be reproduced with attribution.This post is translated using ChatGPT, please feedback if any omissions.