Author Topic: what this stm32 HAL statement does?  (Read 2563 times)

0 Members and 1 Guest are viewing this topic.

Offline jeet55Topic starter

  • Contributor
  • Posts: 19
what this stm32 HAL statement does?
« on: April 27, 2021, 11:59:03 am »
so I was implementing a DMA interrupt on stm32g031k8 Nucleo but whenever I enabled interrupt the debug always ended up in a hard fault.
Code: [Select]
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);this statement gave me the error.  So I looked into code generated using MX cube there was one difference I didn't call this statement
Code: [Select]
__HAL_LINKDMA(&ADC1_Handle,DMA_Handle,DMA1Channel1_Handle); so can anyone explain what this statement does and when to use it?
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6247
  • Country: es
Re: what this stm32 HAL statement does?
« Reply #1 on: April 28, 2021, 02:49:55 am »
Go to the macro declaration and see yourself, it's only 1 line! :P
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: newbrain

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15341
  • Country: fr
Re: what this stm32 HAL statement does?
« Reply #2 on: April 28, 2021, 05:08:19 pm »
As with the other thread, we can't guess what you wrote - in particular, we absolutely don't know how you set up the corresponding DMA channel. The second line suggests you want to link it to the ADC1 peripheral, but it's almost certain you are not setting things up correctly.


 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6247
  • Country: es
Re: what this stm32 HAL statement does?
« Reply #3 on: April 28, 2021, 06:23:14 pm »
Code: [Select]
/**
  * @brief  ADC handle Structure definition
  */
#if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
typedef struct __ADC_HandleTypeDef
#else
typedef struct
#endif
{
  ADC_TypeDef                   *Instance;                   /*!< Register base address */

  ADC_InitTypeDef               Init;                        /*!< ADC required parameters */

  __IO uint32_t                 NbrOfCurrentConversionRank;  /*!< ADC number of current conversion rank */

  DMA_HandleTypeDef             *DMA_Handle;                 /*!< Pointer DMA Handler */

  HAL_LockTypeDef               Lock;                        /*!< ADC locking object */

  __IO uint32_t                 State;                       /*!< ADC communication state */

  __IO uint32_t                 ErrorCode;                   /*!< ADC Error code */
#if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc);              /*!< ADC conversion complete callback */
  void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc);          /*!< ADC conversion DMA half-transfer callback */
  void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc);      /*!< ADC analog watchdog 1 callback */
  void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc);                 /*!< ADC error callback */
  void (* InjectedConvCpltCallback)(struct __ADC_HandleTypeDef *hadc);      /*!< ADC group injected conversion complete callback */
  void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc);               /*!< ADC Msp Init callback */
  void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc);             /*!< ADC Msp DeInit callback */
#endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
}ADC_HandleTypeDef;


Code: [Select]
#define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__)               \
                        do{                                                      \
                              (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
                              (__DMA_HANDLE__).Parent = (__HANDLE__);             \
                          } while(0U)


Code: [Select]
__HAL_LINKDMA(&ADC1_Handle,DMA_Handle,DMA1Channel1_Handle);
It sets up everything for the HAL.
So when the ADC code handles the ADC, it will use ADC1_Handle.DMA_Handle for configuring the DMA.
And when the DMA interrupt happens, it will check the Parent.
It does exactly this:

Code: [Select]
ADC1_Handle.DMA_Handle = &DMA1Channel1_Handle;
DMA1Channel1_Handle.Parent = &ADC1_Handle;


It doesn't touch the hardware in any way.
I'm pretty sure it's only internal, for the HAL, and you're not supposed to use it.
« Last Edit: April 28, 2021, 06:25:44 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf