cancel
Showing results for 
Search instead for 
Did you mean: 

How do I convert __HAL_LINKDMA() to ''register language''?

arnold_w
Senior
Posted on March 21, 2016 at 10:49

I am working with the Discovery Development Board and I have written some code on top of the HAL-layer, but I don't like it and would like to get rid of it and write to the registers directly. I'm not sure how I to convert the__HAL_LINKDMA-macro:

typedef struct __DMA_HandleTypeDef
{
DMA_Stream_TypeDef *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 */ 
void (* XferCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete callback */
void (* XferHalfCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA Half transfer complete callback */
void (* XferM1CpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete Memory1 callback */
void (* XferErrorCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer error callback */
__IO uint32_t ErrorCode; /*!< DMA Error code */
}DMA_HandleTypeDef;
typedef struct __SPI_HandleTypeDef
{
SPI_TypeDef *Instance; /* SPI registers base address */
SPI_InitTypeDef Init; /* SPI communication parameters */
uint8_t *pTxBuffPtr; /* Pointer to SPI Tx transfer Buffer */
uint16_t TxXferSize; /* SPI Tx transfer size */
uint16_t TxXferCount; /* SPI Tx Transfer Counter */
uint8_t *pRxBuffPtr; /* Pointer to SPI Rx transfer Buffer */
uint16_t RxXferSize; /* SPI Rx transfer size */
uint16_t RxXferCount; /* SPI Rx Transfer Counter */
DMA_HandleTypeDef *hdmatx; /* SPI Tx DMA handle parameters */
DMA_HandleTypeDef *hdmarx; /* SPI Rx DMA handle parameters */
void (*RxISR)(struct __SPI_HandleTypeDef * hspi); /* function pointer on Rx ISR */
void (*TxISR)(struct __SPI_HandleTypeDef * hspi); /* function pointer on Tx ISR */
HAL_LockTypeDef Lock; /* SPI locking object */
__IO HAL_SPI_StateTypeDef State; /* SPI communication state */
__IO uint32_t ErrorCode; /* SPI Error code */
}SPI_HandleTypeDef;
DMA_HandleTypeDef hdma_spi2_rx;
SPI_HandleTypeDef hspi2;

__HAL_LINKDMA(&hspi2, hdmarx, hdma_spi2_rx);

#define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \
do{ \
(__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
(__DMA_HANDLE__).Parent = (__HANDLE__); \
} while(0)

Can someone please help me?
2 REPLIES 2
Posted on March 21, 2016 at 11:16

This macro has nothing to do with the peripherals themselves, but with the way how things are ''organized'' in Cube. Each peripheral has assigned a structure in RAM, which maintains its ''state'' for Cube. This macro links the DMA structure to the SPI structure.

Thus, you don't convert this to register manipulation. Normally, peripheral access code does not need to maintain this kind of structure as the peripheral-to-peripheral assignments are implicit.

JW

Walid FTITI_O
Senior II
Posted on March 21, 2016 at 14:23

Hi arnold_w,

If you are coding with ''register direct access'', there is no requirement to convert the __HAL_LINKDMA-macro since it is related to the Cube's architecture and the Link between peripheral instance and DMA instance to get the state machine working correctly.

-Hannibal-