cancel
Showing results for 
Search instead for 
Did you mean: 

Structure confusion DMA_HandleTypeDef vs __DMA_HandleTypeDef

T J
Lead

This code is from STM32H7xx_hal_dma.h

what is __DMA_HandleTypeDef describing ?

is it weak ? for what purpose ?

typedef struct __DMA_HandleTypeDef
{
  void                            *Instance;                   /*!< Register base address                       */
  DMA_InitTypeDef                  Init;                /*!< DMA communication parameters   */
  HAL_LockTypeDef                 Lock;             /*!< DMA locking object                             */
  __IO HAL_DMA_StateTypeDef       State;  /*!< DMA transfer state                */
  void                            *Parent;                     /*!< Parent object state                 */
.
.
.

Now please, the confusion;

What is DMA_HandleTypeDef describing ?

how is it different ?

.
.
.
DMAMUX_RequestGenStatus_TypeDef  *DMAmuxRequestGenStatus;  /*!< DMAMUX request generator Status Address       */
 uint32_t                         DMAmuxRequestGenStatusMask;   /*!< DMAMUX request generator Status mask          */
}DMA_HandleTypeDef;

11 REPLIES 11

Nothing is thrown away. The naming convention may be helping to confuse you. After the structure has been fully defined, there are 2 ways to reference the structure, both are equivalent:

struct __DMA_HandleTypeDef hdma1;  // Using "struct" with the structure name
DMA_HandleTypeDef hdma2;  // Using the typedef name without "struct"

Both hdma1 and hdma2 are the same structure, and the compiler will (should?) treat them as identical types. To use the name that starts with underscores you always need the "struct" before it. To use the name that does not start with underscores, you never need (and cannot use) the "struct". That is what the "typedef" does - gives you an alias name for "struct whatever" for all of us lazy programmer who don't want to type any more than we have to 🙂

Maybe if the structure were defined this way it might make it clearer:

typedef struct dummyname {
   int  avar;
   //... more variables
  struct dummyname *mydmahandle;
} DMA_HandleTypeDef;

Now "struct dummyname" and "DMA_HandleTypeDef" both refer to the same structure.

Gudgel.boB
Senior

Bob, thank you ! I now understand this issue clear as day !

I knew about 1/4 of this but my understanding is MUCH better now !

Consternation turned to lucidation

boB (spelled backwards to avoid confusion)

=)