cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U545RE-Q: not getting ADC1 conversion data via GPDMA

cjb89
Associate II

Hello everyone, 

 

I'm currently trying to set up the two ADCs (ADC1, ADC4) on my NUCLEO-U545RE-Q for multi-channel continuous conversion via GPDMA (I've previously used an L4+, but intend to change to the U5 family for the final product and am using the NUCLEO board to test the migration).

 

I have - to the best of my knowledge - replicated the ADC and DMA settings I've used successfully on my L4P5CE on the U545RE's GPDMA and both ADCs, however ADC1 and ADC4 seem to have slightly different "architectures" (for lack of a better word), so I've - again, to the best of my knowledge - replicated the settings on both as best I can. 

However, while this works with ADC4, I'm not getting any data on ADC1.

Thing I have tried (without success - only ADC4_res_buffer is getting new data): 

- enabling/disabling the ADC and GPDMA interrupts

- different ADC clock frequencies

- Swapping the channels between the ADCs (ADC1 Ch1/2; ADC4 Ch3/4 or ADC1 Ch3/4, ADC4 Ch 1/2)

- enabling/disabling ADCEx Calibration, different calibration modes

- swapping the HAL_ADC_Start_DMA order

 

I'm really hoping you can help me here; I've attached both the .ioc file (where I've set the GPDMA and ADCx settings) and the main.c file. 

 

Best regards

Christoph

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi, 

I've found the issue: The "new" ADC1 has an additional field I wasn't familiar with: "Conversion Data Management Mode". This needs to be set to "DMA Circular Mode" instead of "Regular Conversion data stored in DR register only" - maybe it'd be a good idea for CubeIDE/CubeMX to warn the user when it detects that it's set to "DR only" while DMA is active for the ADC? Anyways, it now works as expected!

The ADC on the L4P5CE and ADC4 on the U545RE-Q does not have this option/field, so I didn't pay it too much attention, I guess. 

Best regards

Christoph

View solution in original post

6 REPLIES 6
Hl_st
ST Employee

Hello,

in debug mode, can you see in ADCx->DR register correct measured value? It seems to me, you should set also some periodic trigger to ADC. For example set ADC: External Trigger Conversion Source to Timer 15 Trigger Output event. Then set Timer 15 clock source as: Internal Clock and Trigger Output Parameters as Enable and Update Event. After calling function HAL_ADC_Start_DMA(), call HALL_TIM_Base_Star(&htim15) function. Now ADC will be periodically triggered by timer 15 reloading. Frequency of ADC triggered will be then defined by Timer 15 input frequency, its Prescaler and Autoreload register values. 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi, 

thank you for the reply. I've configured ADC1 as Regular Conversion Scan to alternate between IN1 and IN2 (PC0/PC1). I've connected one input to 3.3 V and the other to GND on the NUCLEO board I use for my tests and I can see the hadc1 DR toggle between ~27 and 16383 (I've used flywires, and the 3.3 V is probably the VDDD rail, so these values seem very much plausible), so it seems like the ADC is being triggered and does indeed convert the analog data on its inputs. 

As such, I think there is somehing wrong with how I set up the GPDMA? I've used the same settings for GPDMA Channel 0 (which transfers the data from ADC4, which works flawlessly) and GPDMA Channel 1 (which should transfer the data from ADC1, but doesn't seem to do anything). Is there anything I'm missing in how I've set it up in the .ioc file?

Best regards

Christoph

Hi, 

I've found the issue: The "new" ADC1 has an additional field I wasn't familiar with: "Conversion Data Management Mode". This needs to be set to "DMA Circular Mode" instead of "Regular Conversion data stored in DR register only" - maybe it'd be a good idea for CubeIDE/CubeMX to warn the user when it detects that it's set to "DR only" while DMA is active for the ADC? Anyways, it now works as expected!

The ADC on the L4P5CE and ADC4 on the U545RE-Q does not have this option/field, so I didn't pay it too much attention, I guess. 

Best regards

Christoph

Marc3
Associate III

Hello, 

 

I have the same nucleo board.

 

I would like to perform a similar application just as you do but my code gets stuck somewhere ...

 

I have two questions ...

- Could you please share the configuration of the LinkedList, Queue and Node?

- Could you explain why didnt you have to link the ADCs with the respective GPDMA1 channels as i did? 

 

Feel free to upload the whole project so i can take a look at it more carefully!

 

Heres the part of the code where i declare, start and link the ADCs:

 /* USER CODE BEGIN 2 */

  MX_ADC_Queue_Config();				// Configuration of Queue

  if(HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED)){	// ADC1 Calibration
  Error_Handler();
  }

  __HAL_LINKDMA(&hadc1, DMA_Handle, handle_GPDMA1_Channel8);

  if (HAL_DMAEx_List_LinkQ(&handle_GPDMA1_Channel8, &ADC_Queue) != HAL_OK){
  Error_Handler();
  }

  if (HAL_ADC_Start_DMA(&hadc1, (uint32_t *)ADC1_VALUES, (ADC1_BUFFER_SIZE)) != HAL_OK){
  Error_Handler();
  }

  if(HAL_ADCEx_Calibration_Start(&hadc4, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED)){	// ADC4 Calibration
  Error_Handler();
  }

  __HAL_LINKDMA(&hadc4, DMA_Handle, handle_GPDMA1_Channel10);

  if (HAL_DMAEx_List_LinkQ(&handle_GPDMA1_Channel10, &ADC_Queue) != HAL_OK){
  Error_Handler();
  }

  if (HAL_ADC_Start_DMA(&hadc4, (uint32_t *)ADC4_VALUES, (ADC4_BUFFER_SIZE)) != HAL_OK)
  {
  Error_Handler();
  }
  
  HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_1);



  /* USER CODE END 2 */

 

 

Hi Marc3, 

 

I've used the GPDMA in "Standard Request Mode", not "Linked List". In this mode, there is a "Request Configuration" section, which links the GPDMA channel to the peripheral (cf. attached picture).

 

As far as I know, Linked List is only required, if you want to do a sequence of events (like: read out ADC, push data to UART, send UART, repeat). Since I only want the ADC to continuously sample in the background, the Standard Request Mode seems sufficient; since I've not had the need to use Linked List Mode, I don't have any experience regarding the subject. 

 

Best regards

Christoph

Marc3
Associate III

Thank you so much!

 

I just got it working.

I have been two weeks asking and looking in forums how to set this multireading task and nobody answered.

 

Thank you!

Marc