Skip to main content
syoon.10
Associate
March 13, 2019
Question

STM32F769BI ADC_DMA interrupt causing debug stop

  • March 13, 2019
  • 4 replies
  • 1032 views

Hello, I am using the Stm32F769BI MCU.

I am receiving 3 ADC channels through DMA.

My problem is that debugging stops in the middle due to HAL_ADC_IRQHandler during debugging.

To debug again, I must press the Run button again.

I want to know why interrupts happen and stop. And I don't want to stop debugging in HAL_ADC_IRQHandler.

//adc 
 uint32_t air_adc_buf[3];
 uint32_t adc_val[3];
 
/* USER CODE END 0 */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
 //buffer clear
 for(int j = 0; j <=3; j++){
 air_adc_buf[j] = 0;
 }
 
 if(hadc->Instance == ADC3)
 {
 adc_val[0] = air_adc_buf[0];
 adc_val[1] = air_adc_buf[1];
 adc_val[2] = air_adc_buf[2];
 
 }
}
 
 HAL_ADC_Start_DMA(&hadc3, &air_adc_buf[0], 3);
 HAL_ADC_Start_IT(&hadc3);
 
 
while(1){
 //adc
 HAL_ADC_Start_IT(&hadc3);
 printf("pressure sensor1 = %d\r\n", adc_val[0]);
 printf("pressure sensor2 = %d\r\n", adc_val[1]);
 printf("pressure sensor3 = %d\r\n", adc_val[2]);
 printf("----------------\r\n");
 HAL_Delay(500);
 
}
 
 
///////////
 
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
 
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 if(hadc->Instance==ADC3)
 {
 /* USER CODE BEGIN ADC3_MspInit 0 */
 
 /* USER CODE END ADC3_MspInit 0 */
 /* Peripheral clock enable */
 __HAL_RCC_ADC3_CLK_ENABLE();
 
 __HAL_RCC_GPIOF_CLK_ENABLE();
 /**ADC3 GPIO Configuration 
 PF8 ------> ADC3_IN6
 PF9 ------> ADC3_IN7
 PF10 ------> ADC3_IN8 
 */
 GPIO_InitStruct.Pin = S_ADC_0_Pin|S_ADC_1_Pin|S_ADC_2_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
 
 /* ADC3 DMA Init */
 /* ADC3 Init */
 hdma_adc3.Instance = DMA2_Stream0;
 hdma_adc3.Init.Channel = DMA_CHANNEL_2;
 hdma_adc3.Init.Direction = DMA_PERIPH_TO_MEMORY;
 hdma_adc3.Init.PeriphInc = DMA_PINC_DISABLE;
 hdma_adc3.Init.MemInc = DMA_MINC_ENABLE;
 hdma_adc3.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
 hdma_adc3.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
 hdma_adc3.Init.Mode = DMA_CIRCULAR;
 hdma_adc3.Init.Priority = DMA_PRIORITY_LOW;
 hdma_adc3.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
 hdma_adc3.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
 hdma_adc3.Init.MemBurst = DMA_MBURST_SINGLE;
 hdma_adc3.Init.PeriphBurst = DMA_PBURST_SINGLE;
 if (HAL_DMA_Init(&hdma_adc3) != HAL_OK)
 {
 Error_Handler();
 }
 
 __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc3);
 
 /* ADC3 interrupt Init */
 HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(ADC_IRQn);
 /* USER CODE BEGIN ADC3_MspInit 1 */
 
 /* USER CODE END ADC3_MspInit 1 */
 }
 
}

This topic has been closed for replies.

4 replies

syoon.10
syoon.10Author
Associate
March 13, 2019

0690X0000087rXTQAY.png

syoon.10
syoon.10Author
Associate
March 13, 2019

0690X0000087rXdQAI.png0690X0000087rXYQAY.png

Mohamed Aymen HZAMI
ST Employee
March 15, 2019

Hello,

Try to remove the printf function.

Best regards,

Mohamed aymen.

Bob S
Super User
March 15, 2019

A few things:

(1) Your HAL_ADC_ConvCpltCallback() function is writing past the end of your air_adc_buf[] array. The array has 3 elements (0 to 2), but your for() loop goes from 0 to 3 (inclusive). Change "<= 3" to "< 3".

And a better (more maintainable) coding practice, make the array size a define and use that define everywhere. For example:

#define ADC_BUFFER_LEN 3
 
//adc 
 uint32_t air_adc_buf[ADC_BUFFER_LEN];
 uint32_t adc_val[ADC_BUFFER_LEN];

And later:

/* USER CODE END 0 */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
 //buffer clear
 for(int j = 0; j < ADC_BUFFER_LEN; j++){
 air_adc_buf[j] = 0;
 }

And still later:

 HAL_ADC_Start_DMA(&hadc3, &air_adc_buf[0], ADC_BUFFER_LEN);
 HAL_ADC_Start_IT(&hadc3);

(2) Why are you calling BOTH HAL_ADC_Start_DMA() and HAL_ADC_Start_IT()? Pick one or the other, I'm guessing the DMA version.

(3) Why do you clear air_adc_buf[] in the conversion complete callback, and then assign values from that array (which are zero) to adc_val[]? It seems you will always get zeros in adc_val[], no?