cancel
Showing results for 
Search instead for 
Did you mean: 

ADC1/2 not working over DMA on NUCLEO-H7A3ZI-Q (+Azure RTOS)

tuduce
Associate II

Dear community,

I have a NUCLEO-H7A3ZI-Q board with CAN, USART, USB Device and 4 analog inputs. My application is structured using the Azure RTOS, but for ADC testing purposes I am not calling MX_ThreadX_Init() anymore. With the AZRTOS initiated is the same ADC behavior.

The example at https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Projects/NUCLEO-H7A3ZI-Q/Examples/ADC/ADC_DMA_Transfer works, but they only use 1 channel. The board and at least ADC_Channel11 works.

I attached my IOC file, but basically I am using ADC2 (also tried with ADC1) in continuous conversion, DMA circular mode.

I also attached the main.c file. The gist of it:

ALIGN_32BYTES (static uint16_t ADC_VAL[4]);
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
if (hadc == &hadc2) {
ADCfinished = 1; // Set the flag to indicate conversion is complete
}
}

// in main()...
if (HAL_ADC_Start_DMA(&hadc2, (uint32_t *) ADC_VAL, 4) != HAL_OK)
{
Error_Handler();
}

while (1)
{
if (ADCfinished) {
// print the ADC_VAL array
printf("ADC Values: %u, %u, %u, %u\n",
(unsigned int) ADC_VAL[0],
(unsigned int) ADC_VAL[1],
(unsigned int) ADC_VAL[2],
(unsigned int) ADC_VAL[3]);
ADCfinished = 0; // Reset the flag
} // end if
HAL_Delay(250); // Delay for 1 second to allow ADC to stabilize
} // end while

The defined interrupt handler never gets invoked. (If I turn off DMA and use HAL_ADC_Start_IT(), the interrupt is getting called)

By tracing and using some AI magic, I found out that the register DMA1->S0CR->EN is 0 (not enabled). In the HAL_ADC_Start_DMA() function, the call to HAL_DMA_Start_IT() sets this register. However, the very next call (LL_ADC_REG_StartConversion(hadc->Instance);) disables the register.

Can anyone please take a look and tell me what am I missing? What combination of settings are disabling the DMA? Any help is greatly appreciated!

 

Best regards,

Cristian.

 

1 ACCEPTED SOLUTION

Accepted Solutions
tuduce
Associate II

I found the solution using https://community.st.com/t5/stm32-mcus/dma-is-not-working-on-stm32h7-devices/ta-p/49498

The buffer (ADC_VAL[]) was in the DTCMRAM, where the DMA1 can't access it. When moving the buffer to RAM (starting at 0x24000000) DMA works as expected.

 

Cheers,
Cristian

View solution in original post

4 REPLIES 4
Karl Yamashita
Principal

You main.c is missing code for MX_ADC2_Init()

I can't seem to import your IOC file? It imports only as a Project, but no IOC file to view any settings.

Who turned off the lights?

Open Source CAN bus analyzer

Hi,

thanks for looking into this!

The call to

MX_ADC2_Init();

is after

MX_GPIO_Init();
MX_DMA_Init();
MX_USART2_UART_Init();

 I don't know what to say about the IOC file. If I download the attached IOC and look at it with a text editor, it looks like an IOC-file.

 

Cheers,

Cristian.

tuduce
Associate II

I found the solution using https://community.st.com/t5/stm32-mcus/dma-is-not-working-on-stm32h7-devices/ta-p/49498

The buffer (ADC_VAL[]) was in the DTCMRAM, where the DMA1 can't access it. When moving the buffer to RAM (starting at 0x24000000) DMA works as expected.

 

Cheers,
Cristian


@tuduce wrote:

Hi,

thanks for looking into this!

The call to

MX_ADC2_Init();

is after

MX_GPIO_Init();
MX_DMA_Init();
MX_USART2_UART_Init();

 I don't know what to say about the IOC file. If I download the attached IOC and look at it with a text editor, it looks like an IOC-file.

 

Cheers,

Cristian.


For some reason, my STM32CubeIDE 1.18.1 which I've been using for weeks, started having issues today, even when creating new projects. An IOC file is never created. I just now upgraded to 1.19.0 and it opens the IOC file correctly.

But that's good that you've found a fix.

Who turned off the lights?

Open Source CAN bus analyzer