Skip to main content
SA V.1
Associate III
April 20, 2023
Solved

ADC conversion data to DMA without any DMA interrupt ??

  • April 20, 2023
  • 10 replies
  • 4218 views

Hello team am Receving 16bit ADC conversion data to DMA in STM32H745i Disco in CubeIDE software. Here DMA interrupt is generating by default in software (i am disabled the interrupt in programming after that program counter is out of control) I dont want any ADC/DMA interrupt . DMA sholud receives the data contineously without any interrupt any solution for this ?

This topic has been closed for replies.
Best answer by Kamil Duljas

About point 2:

mentioned functions are implemented as _weak:

__weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

{

 /* Prevent unused argument(s) compilation warning */

 UNUSED(hadc);

 /* NOTE : This function Should not be modified, when the callback is needed,

      the HAL_ADC_ConvCpltCallback could be implemented in the user file

  */

}

so you can omit their exist.

10 replies

Senior III
April 20, 2023

I try to understand. Do you want disable interrupt from DMA for ADC during conversion?

Dudo
SA V.1
SA V.1Author
Associate III
April 20, 2023

Thank you for your reply sir ,

 ADC driver can be used among three modes:

1. polling 2.interruption 3.transfer by DMA.

eleminate 1 and 2 . Am preferred 3.transfer by DMA

Here ,  (1) ADC conversion with transfer by DMA:

     (+++) Activate the ADC peripheral and start conversions

        using function HAL_ADC_Start_DMA()

     (2) Wait for ADC conversion completion by call of function

        HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback()

        (these functions must be implemented in user program)

     (3) Conversion results are automatically transferred by DMA into

        destination variable address.

     (4) Stop conversion and disable the ADC peripheral

        using function HAL_ADC_Stop_DMA()

The 2nd point is must and should ha or is there any option to skip and move to 3rd point (because here DMA half/full conversion interrupt will be genetated so i dont need any interrupt ) is there any solution it would be very helpful .

Senior III
April 20, 2023

If you use CubeMx you can uncheck options "Force DMA channels Interrupts":


_legacyfs_online_stmicro_images_0693W00000biUOYQA2.png 

Dudo
Senior III
April 20, 2023

Also you can uncheck in ADCx settings but first you must uncheck as above "Force DMA channels Interrupts":


_legacyfs_online_stmicro_images_0693W00000biUPbQAM.png

Dudo
SA V.1
SA V.1Author
Associate III
April 20, 2023

Thank you sir it could be very helpful . Am using CubeIDE i will check and i hope CubeIDE and MX nothing Much difference .

Senior III
April 20, 2023

paste your code please

Dudo
SA V.1
SA V.1Author
Associate III
April 20, 2023

i am talking about point 3. bellow my code is here please can you check and guide what i am doing wrong .

/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file : main.c
 * @brief : Main program body
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2023 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
 
#ifndef HSEM_ID_0
#define HSEM_ID_0 (0U) /* HW semaphore 0*/
#endif
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
#define ADC_BUFFER_SIZE 10
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
 ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;
 
/* USER CODE BEGIN PV */
uint32_t ADC_Value[ADC_BUFFER_SIZE];
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_ADC1_Init(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
/**
 * @brief The application entry point.
 * @retval int
 */
int main(void)
{
 /* USER CODE BEGIN 1 */
 
 /* USER CODE END 1 */
/* USER CODE BEGIN Boot_Mode_Sequence_0 */
 int32_t timeout;
/* USER CODE END Boot_Mode_Sequence_0 */
 
 /* Enable I-Cache---------------------------------------------------------*/
 SCB_EnableICache();
 
 /* Enable D-Cache---------------------------------------------------------*/
 SCB_EnableDCache();
 
/* USER CODE BEGIN Boot_Mode_Sequence_1 */
 /* Wait until CPU2 boots and enters in stop mode or timeout*/
 timeout = 0xFFFF;
 while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0));
 if ( timeout < 0 )
 {
 Error_Handler();
 }
/* USER CODE END Boot_Mode_Sequence_1 */
 /* MCU Configuration--------------------------------------------------------*/
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* USER CODE BEGIN Init */
 
 /* USER CODE END Init */
 
 /* Configure the system clock */
 SystemClock_Config();
/* USER CODE BEGIN Boot_Mode_Sequence_2 */
/* When system initialization is finished, Cortex-M7 will release Cortex-M4 by means of
HSEM notification */
/*HW semaphore Clock enable*/
__HAL_RCC_HSEM_CLK_ENABLE();
/*Take HSEM */
HAL_HSEM_FastTake(HSEM_ID_0);
/*Release HSEM in order to notify the CPU2(CM4)*/
HAL_HSEM_Release(HSEM_ID_0,0);
/* wait until CPU2 wakes up from stop mode */
timeout = 0xFFFF;
while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) == RESET) && (timeout-- > 0));
if ( timeout < 0 )
{
Error_Handler();
}
/* USER CODE END Boot_Mode_Sequence_2 */
 
 /* USER CODE BEGIN SysInit */
 
 /* USER CODE END SysInit */
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_DMA_Init();
 MX_ADC1_Init();
 /* USER CODE BEGIN 2 */ ********** Am tried here and inside while also ********
 // HAL_ADC_Start_DMA(&hadc1,(uint32_t*)ADC_Value, ADC_BUFFER_SIZE);
 /* USER CODE END 2 */
 
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */
	 HAL_ADC_Start_DMA(&hadc1,(uint32_t*)ADC_Value, ADC_BUFFER_SIZE);
 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}
 
/**
 * @brief System Clock Configuration
 * @retval None
 */
void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
 /** Supply configuration update enable
 */
 HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY);
 
 /** Configure the main internal regulator output voltage
 */
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
 
 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
 
 /** Macro to configure the PLL clock source
 */
 __HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_PLLSOURCE_HSI);
 
 /** Initializes the RCC Oscillators according to the specified parameters
 * in the RCC_OscInitTypeDef structure.
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
 RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
 RCC_OscInitStruct.PLL.PLLM = 4;
 RCC_OscInitStruct.PLL.PLLN = 25;
 RCC_OscInitStruct.PLL.PLLP = 2;
 RCC_OscInitStruct.PLL.PLLQ = 4;
 RCC_OscInitStruct.PLL.PLLR = 4;
 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
 RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
 RCC_OscInitStruct.PLL.PLLFRACN = 0;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
 
 /** Initializes the CPU, AHB and APB buses clocks
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV2;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
 
 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
 {
 Error_Handler();
 }
}
 
/**
 * @brief ADC1 Initialization Function
 * @param None
 * @retval None
 */
static void MX_ADC1_Init(void)
{
 
 /* USER CODE BEGIN ADC1_Init 0 */
 
 /* USER CODE END ADC1_Init 0 */
 
 ADC_MultiModeTypeDef multimode = {0};
 ADC_ChannelConfTypeDef sConfig = {0};
 
 /* USER CODE BEGIN ADC1_Init 1 */
 
 /* USER CODE END ADC1_Init 1 */
 
 /** Common config
 */
 hadc1.Instance = ADC1;
 hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
 hadc1.Init.Resolution = ADC_RESOLUTION_16B;
 hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
 hadc1.Init.LowPowerAutoWait = DISABLE;
 hadc1.Init.ContinuousConvMode = ENABLE;
 hadc1.Init.NbrOfConversion = 1;
 hadc1.Init.DiscontinuousConvMode = DISABLE;
 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
 hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;
 hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
 hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
 hadc1.Init.OversamplingMode = DISABLE;
 if (HAL_ADC_Init(&hadc1) != HAL_OK)
 {
 Error_Handler();
 }
 
 /** Configure the ADC multi-mode
 */
 multimode.Mode = ADC_MODE_INDEPENDENT;
 if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
 {
 Error_Handler();
 }
 
 /** Configure Regular Channel
 */
 sConfig.Channel = ADC_CHANNEL_0;
 sConfig.Rank = ADC_REGULAR_RANK_1;
 sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
 sConfig.SingleDiff = ADC_SINGLE_ENDED;
 sConfig.OffsetNumber = ADC_OFFSET_NONE;
 sConfig.Offset = 0;
 sConfig.OffsetSignedSaturation = DISABLE;
 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN ADC1_Init 2 */
 if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED) != HAL_OK)
 {
 Error_Handler();
 }
 
 /* USER CODE END ADC1_Init 2 */
 
}
 
/**
 * Enable DMA controller clock
 */
static void MX_DMA_Init(void)
{
 
 /* DMA controller clock enable */
 __HAL_RCC_DMA1_CLK_ENABLE();
 
}
 
/**
 * @brief GPIO Initialization Function
 * @param None
 * @retval None
 */
static void MX_GPIO_Init(void)
{
 
 /* GPIO Ports Clock Enable */
 __HAL_RCC_GPIOH_CLK_ENABLE();
 __HAL_RCC_GPIOA_CLK_ENABLE();
 
}
 
/* USER CODE BEGIN 4 */
 
/* USER CODE END 4 */
 
/**
 * @brief This function is executed in case of error occurrence.
 * @retval None
 */
void Error_Handler(void)
{
 /* USER CODE BEGIN Error_Handler_Debug */
 /* User can add his own implementation to report the HAL error return state */
 __disable_irq();
 while (1)
 {
 }
 /* USER CODE END Error_Handler_Debug */
}
 
#ifdef USE_FULL_ASSERT
/**
 * @brief Reports the name of the source file and the source line number
 * where the assert_param error has occurred.
 * @param file: pointer to the source file name
 * @param line: assert_param error line source number
 * @retval None
 */
void assert_failed(uint8_t *file, uint32_t line)
{
 /* USER CODE BEGIN 6 */
 /* User can add his own implementation to report the file name and line number,
 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

Kamil DuljasBest answer
Senior III
April 20, 2023

About point 2:

mentioned functions are implemented as _weak:

__weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

{

 /* Prevent unused argument(s) compilation warning */

 UNUSED(hadc);

 /* NOTE : This function Should not be modified, when the callback is needed,

      the HAL_ADC_ConvCpltCallback could be implemented in the user file

  */

}

so you can omit their exist.

Dudo
Senior III
April 20, 2023
  1. Add HAL_ADC_Start_DMA before while
  2. Try below settings for adc1
  3. uint16_t ADC_Value[ADC_BUFFER_SIZE]; because data with in DMA is set to HALF_WORD

hadc1.Instance = ADC1;
 hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
 hadc1.Init.Resolution = ADC_RESOLUTION_16B;
 hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
 hadc1.Init.LowPowerAutoWait = ENABLE;
 hadc1.Init.ContinuousConvMode = ENABLE;
 hadc1.Init.NbrOfConversion = 1;
 hadc1.Init.DiscontinuousConvMode = DISABLE;
 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
 hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;
 hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
 hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
 hadc1.Init.OversamplingMode = DISABLE;

Dudo
SA V.1
SA V.1Author
Associate III
April 20, 2023

Thank you for" your HELP" i made the changes above and checked no output . I thought we Can't get WIthout the DMA interrupt . Can you discuss with your collegue or those who have highly known about this topic and Reconfirm about this please ??

Senior III
April 20, 2023

I don't understand why you mix two topics: interrupts dma and receiving data from ADC. What's your target ? Receiving data or disabling interrupts from dma?

Dudo
Senior III
April 20, 2023

I also don't see init DMA in your code:

void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
{
 
 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
 if(adcHandle->Instance==ADC1)
 {
 /* USER CODE BEGIN ADC1_MspInit 0 */
 
 /* USER CODE END ADC1_MspInit 0 */
 
 /** Initializes the peripherals clock
 */
 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC;
 PeriphClkInitStruct.PLL2.PLL2M = 2;
 PeriphClkInitStruct.PLL2.PLL2N = 12;
 PeriphClkInitStruct.PLL2.PLL2P = 4;
 PeriphClkInitStruct.PLL2.PLL2Q = 2;
 PeriphClkInitStruct.PLL2.PLL2R = 2;
 PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3;
 PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOMEDIUM;
 PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
 PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
 
 /* ADC1 clock enable */
 __HAL_RCC_ADC12_CLK_ENABLE();
 
 __HAL_RCC_GPIOA_CLK_ENABLE();
 /**ADC1 GPIO Configuration
 PA1_C ------> ADC1_INP1
 */
 HAL_SYSCFG_AnalogSwitchConfig(SYSCFG_SWITCH_PA1, SYSCFG_SWITCH_PA1_OPEN);
 
 /* ADC1 DMA Init */
 /* ADC1 Init */
 hdma_adc1.Instance = DMA1_Stream1;
 hdma_adc1.Init.Request = DMA_REQUEST_ADC1;
 hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
 hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
 hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
 hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
 hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
 hdma_adc1.Init.Mode = DMA_CIRCULAR;
 hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
 hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
 if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
 {
 Error_Handler();
 }
 
 __HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc1);
 
 /* USER CODE BEGIN ADC1_MspInit 1 */
 
 /* USER CODE END ADC1_MspInit 1 */
 }
}

Dudo
SA V.1
SA V.1Author
Associate III
April 21, 2023

I have this section of code in my program in msp.c file bellow i am attached .My target is to receive ADC conversion Data to DMA i achived this Succesfully but the thing is while Achiving this DMA will enable the interrupt to indicate half/full conversion is complete . i dont need any indication by interrupting half/full conversion is completed that should do that work backend whenever i want i will access that data hope you undestood my point .

And one more dout while initializing Functions for Example

1. MX_GPIO_Init();

2.HAL_ADC_MspInit();

Above are function but MX ,Msp whats that can you give more info about this ??

/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file stm32h7xx_hal_msp.c
 * @brief This file provides code for the MSP Initialization
 * and de-Initialization codes.
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2023 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */
 
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
extern DMA_HandleTypeDef hdma_adc1;
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
 
/* USER CODE END TD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
 
/* USER CODE END Define */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
 
/* USER CODE END Macro */
 
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
 
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
 
/* USER CODE END ExternalFunctions */
 
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
/**
 * Initializes the Global MSP.
 */
void HAL_MspInit(void)
{
 /* USER CODE BEGIN MspInit 0 */
 
 /* USER CODE END MspInit 0 */
 
 __HAL_RCC_SYSCFG_CLK_ENABLE();
 
 /* System interrupt init*/
 
 /* USER CODE BEGIN MspInit 1 */
 
 /* USER CODE END MspInit 1 */
}
 
/**
* @brief ADC MSP Initialization
* This function configures the hardware resources used in this example
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
 if(hadc->Instance==ADC1)
 {
 /* USER CODE BEGIN ADC1_MspInit 0 */
 
 /* USER CODE END ADC1_MspInit 0 */
 
 /** Initializes the peripherals clock
 */
 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC;
 PeriphClkInitStruct.PLL2.PLL2M = 4;
 PeriphClkInitStruct.PLL2.PLL2N = 12;
 PeriphClkInitStruct.PLL2.PLL2P = 8;
 PeriphClkInitStruct.PLL2.PLL2Q = 2;
 PeriphClkInitStruct.PLL2.PLL2R = 2;
 PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3;
 PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;
 PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
 PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
 
 /* Peripheral clock enable */
 __HAL_RCC_ADC12_CLK_ENABLE();
 
 __HAL_RCC_GPIOA_CLK_ENABLE();
 /**ADC1 GPIO Configuration
 PA0_C ------> ADC1_INP0
 */
 HAL_SYSCFG_AnalogSwitchConfig(SYSCFG_SWITCH_PA0, SYSCFG_SWITCH_PA0_OPEN);
 
 /* ADC1 DMA Init */
 /* ADC1 Init */
 hdma_adc1.Instance = DMA1_Stream0;
 hdma_adc1.Init.Request = DMA_REQUEST_ADC1;
 hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
 hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
 hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
 hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
 hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
 hdma_adc1.Init.Mode = DMA_CIRCULAR;
 hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
 hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
 if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
 {
 Error_Handler();
 }
 
 __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
 
 /* USER CODE BEGIN ADC1_MspInit 1 */
 
 /* USER CODE END ADC1_MspInit 1 */
 }
 
}
 
/**
* @brief ADC MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
{
 if(hadc->Instance==ADC1)
 {
 /* USER CODE BEGIN ADC1_MspDeInit 0 */
 
 /* USER CODE END ADC1_MspDeInit 0 */
 /* Peripheral clock disable */
 __HAL_RCC_ADC12_CLK_DISABLE();
 
 /* ADC1 DMA DeInit */
 HAL_DMA_DeInit(hadc->DMA_Handle);
 /* USER CODE BEGIN ADC1_MspDeInit 1 */
 
 /* USER CODE END ADC1_MspDeInit 1 */
 }
 
}
 
/* USER CODE BEGIN 1 */
 
/* USER CODE END 1 */

Thank you

Best Regardas

Sharath A V

Senior III
April 21, 2023

Ok, so achieved your target with DMA. Interrupts You can still disable in the nvic label if you want:


_legacyfs_online_stmicro_images_0693W00000biYqqQAE.png 

You say about this fuction:

1. MX_GPIO_Init();

2.HAL_ADC_MspInit();

what's problem with their?

Dudo
Senior III
April 20, 2023

Some example:


_legacyfs_online_stmicro_images_0693W00000biV0rQAE.png

Dudo
LCE
Principal II
April 21, 2023

You will learn a lot when reading the reference manual and the registers, then looking into the HAL functions to see what's going on.

So you might check what's going on in:

HAL_ADC_Start_DMA() shows you that DMA interrupts are enabled.

And the callback functions ADC_DMAHalfConvCplt() and ADC_DMAConvCplt() are set for DMA interrupt callbacks. Which do some housekeeping and then call the HAL ADC callbacks... (which shows us that this might not be the fastest solution...)

HAL_DMA_IRQHandler() which is called at each DMA interrupt.

It's mostly error handling, but also resetting (half-) transfer complete flags, and calling the (half-) transfer complete callback functions.

So all that might give you the hint that you need the DMA interrupts for that ADC DMA stream.

What you do in the HAL ADC callbacks is your thing.

Maybe set a flag to show that new data is available?

Anyway, when using ADC with DMA you do NOT need that ADC_get_value_whatever function, DMA is writing the ADC values directly into the specified buffer at DMA start.

Stop relying on CubeMX and HAL stuff alone. Start learning and thinking!