STM32F4 using DMA and ADC with LL
Hello,
I'm working with a nucleo F401RE board and the LL drivers, I have set up the ADC in DMA mode, checking into the DMA register all seems right, but when I start the ADC it converts only one value and than it stop, the ADC is triggered from an EXTI line.
The idea is that at each rising edge on the EXTI line the ADC start a conversion burst.
Can someone help me to check if I am missing something?
main, I already configured the DMA transfer for the USART and it works fine.
/* ADC variables */
uint16_t ADCbuf[ADCbuf_size] = {0};
int main(void)
{
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
/* Configure the system clock */
SystemClock_Config();
/* Initialise all configured peripherals */
MX_DMA_Init();
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_ADC1_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
#if DEBUG
sendDebugString("DBG: DMR decoder start, DEBUG mode ENABLE\n");
sendDebugString("CODE_CHECK: MX_DMA_Init() must be called before the other Init functions\n");
#endif
/* USART DMA initialisation */
LL_DMA_DisableStream(DMA1, LL_DMA_STREAM_6);
LL_DMA_EnableIT_TC(DMA1, LL_DMA_STREAM_6);
/* 1st TX USART must be free no need to check */
USART_DMA_Tx(mex.welcomeMex, sizeof(mex.welcomeMex));
/* ADC DMA initialisation */
LL_DMA_DisableStream(DMA2, LL_DMA_STREAM_0);
/* Set DMA transfer addresses of source and destination */
LL_DMA_ConfigAddresses(DMA2, LL_DMA_STREAM_0, (uint32_t) &ADC1->DR, (uint32_t) &ADCbuf, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
/* Set length to be transmitted */
LL_DMA_SetDataLength(DMA2, LL_DMA_STREAM_0, ADCbuf_size);
/* Enable IT conversion complete */
LL_DMA_EnableIT_TC(DMA2, LL_DMA_STREAM_0);
/* End DMA initialisation */
LL_DMA_EnableStream(DMA2, LL_DMA_STREAM_0);
/* Start ADC */
LL_ADC_Enable(ADC1);
/* Wait */
while(USARTbusy == 1) { __asm("nop;"); }
USART_DMA_Tx(mex.initCompleteMex, sizeof(mex.initCompleteMex));
while (1)
{
}
}
__STATIC_FORCEINLINE uint8_t USART_DMA_Tx(const char string[], uint32_t stringLength) {
/* No TX in progress */
if(USARTbusy == 0) {
/* Lock the USART */
USARTbusy = 1;
/* Configure address to be transmitted by DMA */
LL_DMA_ConfigAddresses(DMA1, LL_DMA_STREAM_6, (uint32_t) string, (uint32_t) &USART2->DR, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
/* Set length to be transmitted */
LL_DMA_SetDataLength(DMA1, LL_DMA_STREAM_6, stringLength);
/* Start TX */
LL_USART_ClearFlag_TC(USART2);
LL_DMA_EnableStream(DMA1, LL_DMA_STREAM_6);
LL_USART_EnableDMAReq_TX(USART2);
return 0;
}else { return -1; }
}Interrupts
void EXTI15_10_IRQHandler(void)
{
if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_11) != RESET)
{
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_11);
#if DEBUG
sendDebugString("DBG: EXTI LINE 11 interrupt fired\n");
#endif
}
}
void DMA2_Stream0_IRQHandler(void)
{
LL_DMA_ClearFlag_TC0(DMA2);
#if DEBUG
sendDebugString("DBG: ADC DMA conversion complete\n");
#endif
}DMA and ADC config