How to improve Arduino Portenta H7 ADC Sampling Rate

I am trying to test the ADC sampling rate of Arduino Portenta H7. Using this basic code I can get 250 KSample / sec

// ARDUINO H7 ADC TEST 
// test adc reading sampling rate on a floating pin 

/* DEFINE */
// how many samples to combine 
#define SAMPLES (1000)  

/* INIT */
int analogPin = A0; 
long val = 0;
long dataSum = 0;
long dataAvg = 0;
long timeStart = 0;
long timeElapsed = 0;
int nn = 0;

/* SETUP */
void setup(){
  Serial.begin(115200);
  // set analog read resolution
  analogReadResolution(12); 
  Serial.println(" Test Arduino Portenta H7 ADC samplig rate ");
  }

/* LOOP */
void loop(){
  // record time start 
  timeStart = millis();
  
  // averaging samples
  for (int i = 0; i < SAMPLES; i++){
    val = analogRead(analogPin); 
    dataSum += val;
    nn++;
  }
  // time elapsed in msec
  timeElapsed = millis() - timeStart;
  // data average 
  dataAvg = dataSum / nn;
  
  // print sampling rate 
  Serial.print(" # KSamples/sec: ");
  Serial.print(nn/timeElapsed);

  // print time elapsed
  Serial.print(" Time elapsed msec: ");
  Serial.print(timeElapsed);

  // print adc data average 
  Serial.print( " ADC data average: "); 
  Serial.println(dataAvg);
  
  // reset counter
  nn = 0;
  dataSum = 0;
  delay(2000);
}

But Arduino Portenta ADC tech specs shows:
ADC: 3× ADCs with 16-bit max. resolution up to 36 channels, up to 3.6 MSPS
which is defintely higher than the one I have obtained

How can I improve the ADC sampling rate ?

Hello macromauro,

Maybe taking a look at this PDF could help:

and this one too:

HTH,
John W.

Hello jwestmoreland,

many many thanks for sharing these resources, it helps !!!
because I am very new to STM32 world, can you please suggest a basic resources to start to play with ADC and DMA ?

Is there any way to improve my simple code using arduino programming language ?

many thanks