cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G431RB — ADC1 Interrupt and ADC2 DMA (7 Channels) with FreeRTOS — External Voltage Detection

AnnapoornaMV
Associate

 

Hello,

I am working on STM32 NUCLEO-G431RB using STM32CubeIDE and FreeRTOS (CMSIS-RTOS v2).

I am trying to implement the following requirement:

Requirement

  • ADC1 → 1 Channel using Interrupt
  • ADC2 → 7 Channels using DMA
  • Both should run simultaneously with FreeRTOS

ADC Configuration

ADC1 (Interrupt)

  • Single channel (PA0)
  • Using HAL_ADC_Start_IT()
  • Used for detecting external voltage

Expected Behavior:

  • When I connect external power supply to PA0
  • PA0 should show voltage value
  • Remaining 7 channels should show 0

Example:

 

 
PA0 = 2.5V (Interrupt)
PA1 = 0
PA6 = 0
PA7 = 0
PC0 = 0
PC1 = 0
PC2 = 0
PC3 = 0
 

 

 

ADC2 (DMA)

7 Channels:

  • PA1
  • PA6
  • PA7
  • PC0
  • PC1
  • PC2
  • PC3

Configuration:

  • Scan conversion enabled
  • Continuous conversion enabled
  • DMA circular mode
  • Using HAL_ADC_Start_DMA()

Expected Behavior:

If I connect external voltage to PA1

 

 
PA0 = 0
PA1 = 2.5V (DMA)
PA6 = 0
PA7 = 0
PC0 = 0
PC1 = 0
PC2 = 0
PC3 = 0
 
 

Similarly, if I connect external voltage to any ADC pin, only that pin should show voltage and others should show 0.


FreeRTOS

I am using:

  • ADC interrupt callback
  • DMA complete callback
  • FreeRTOS task
  • Semaphore for synchronization

My Questions

  1. Is it correct to use ADC1 Interrupt + ADC2 DMA simultaneously?
  2. Is this recommended for STM32G431RB?
  3. Any issues when using FreeRTOS + ADC + DMA together?
  4. Is this the correct architecture for this requirement?

Hardware

Board: STM32 NUCLEO-G431RB
IDE: STM32CubeIDE
RTOS: FreeRTOS (CMSIS-RTOS v2)
External Power Supply: 0-3.3V analog input


Any suggestions or recommended approach would be very helpful.

Thank you.

3 REPLIES 3
DigitalMonk123
Associate

Yes, using ADC1 (interrupt) + ADC2 (DMA) simultaneously is valid on STM32G431RB, but ensure both ADCs are properly clocked and not sharing conflicting resources. With FreeRTOS, it’s recommended to rely more on DMA (even for single channel) and use callbacks + queues instead of mixing interrupt-heavy logic for better stability and timing consistency.

Yes, understood. Could you please guide me on the required configuration in STM32CubeMX for using ADC1 with Interrupt and ADC2 with DMA simultaneously on STM32G431RB?

Also, could you please share a reference example or sample code for both CubeMX configuration and IDE implementation (HAL code with callbacks/queues if using FreeRTOS)?

This will help me ensure that both ADCs are properly clocked and no resources are conflicting while implementing the solution.

Hello @AnnapoornaMV 

Please refer to the examples below:

STM32CubeL4/Projects/NUCLEO-L452RE/Examples/ADC at master · STMicroelectronics/STM32CubeL4 · GitHub

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.
Saket_Om