2026-01-13 6:19 AM
Hello,
I am trying to get the audio data from ADF1. Therefore I use the GPDMA as shown in this example: https://github.com/STMicroelectronics/STM32CubeU5/tree/main/Projects/STM32U575I-EV/Examples/MDF/ADF_AudioRecorder. I am developing on a B-U585I-IOT02A.
My problem is, that I seem to receive only 0x7FFF. I am not sure I do not receive valid or realistic values. Unlike in the example I want to put the received data in a TX_Queue later and handle them in another task.
Please find my code attached below. I would be very grateful for hints and suggestions.
Thank You!
K.S.
MDF_HandleTypeDef AdfHandle0;
MDF_FilterConfigTypeDef AdfFilterConfig0;
DMA_HandleTypeDef handle_GPDMA1_Channel10;
MDF_DmaConfigTypeDef DMAConfig;
int16_t RecBuff[REC_BUFF_SIZE * 2U];
volatile uint32_t DmaRecHalfBuffCplt = 0;
volatile uint32_t DmaRecBuffCplt = 0;
extern DMA_QListTypeDef ADFQueue;
void SystemClock_Config(void);
static void SystemPower_Config(void);
static void MX_GPIO_Init(void);
static void MX_GPDMA1_Init(void);
static void MX_ADF1_Init(void);
static void MX_ICACHE_Init(void);
static void MDF_DMAConfig();
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the System Power */
SystemPower_Config();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_GPDMA1_Init();
MX_ADF1_Init();
MX_ICACHE_Init();
MX_ADFQueue_Config();
HAL_DMAEx_List_LinkQ(&handle_GPDMA1_Channel10, &ADFQueue);
MDF_DMAConfig();
memset(RecBuff, 0x00, sizeof(RecBuff));
if (HAL_MDF_AcqStart_DMA(&AdfHandle0, &AdfFilterConfig0, &DMAConfig) != HAL_OK)
{
Error_Handler();
}
while (1)
{
if (DmaRecHalfBuffCplt == 1)
{
int16_t a = RecBuff[0]; // RecBuff full of 0x7FFF
/**
* Here I want to push data from first half of RecBuff into TX_Queue
*/
DmaRecHalfBuffCplt = 0;
}
if (DmaRecBuffCplt == 1)
{
int16_t a = RecBuff[128]; // RecBuff full of 0x7FFF
/**
* Here I want to push second half of RecBuff into TX_Queue
*/
DmaRecBuffCplt = 0;
}
}
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI|RCC_OSCILLATORTYPE_MSIK;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;
RCC_OscInitStruct.MSIKClockRange = RCC_MSIKRANGE_4;
RCC_OscInitStruct.MSIKState = RCC_MSIK_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV4;
RCC_OscInitStruct.PLL.PLLM = 3;
RCC_OscInitStruct.PLL.PLLN = 10;
RCC_OscInitStruct.PLL.PLLP = 32;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 1;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_PCLK3;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief ADF1 Initialization Function
* @PAram None
* @retval None
*/
static void MX_ADF1_Init(void)
{
/**
AdfHandle0 structure initialization and HAL_MDF_Init function call
*/
AdfHandle0.Instance = ADF1_Filter0;
AdfHandle0.Init.CommonParam.ProcClockDivider = 1;
AdfHandle0.Init.CommonParam.OutputClock.Activation = ENABLE;
AdfHandle0.Init.CommonParam.OutputClock.Pins = MDF_OUTPUT_CLOCK_0;
AdfHandle0.Init.CommonParam.OutputClock.Divider = 4;
AdfHandle0.Init.CommonParam.OutputClock.Trigger.Activation = DISABLE;
AdfHandle0.Init.SerialInterface.Activation = ENABLE;
AdfHandle0.Init.SerialInterface.Mode = MDF_SITF_NORMAL_SPI_MODE;
AdfHandle0.Init.SerialInterface.ClockSource = MDF_SITF_CCK0_SOURCE;
AdfHandle0.Init.SerialInterface.Threshold = 31;
AdfHandle0.Init.FilterBistream = MDF_BITSTREAM0_FALLING;
if (HAL_MDF_Init(&AdfHandle0) != HAL_OK)
{
Error_Handler();
}
AdfFilterConfig0.DataSource = MDF_DATA_SOURCE_BSMX;
AdfFilterConfig0.Delay = 0;
AdfFilterConfig0.CicMode = MDF_ONE_FILTER_SINC4;
AdfFilterConfig0.DecimationRatio = 64;
AdfFilterConfig0.Gain = 0;
AdfFilterConfig0.ReshapeFilter.Activation = DISABLE;
AdfFilterConfig0.HighPassFilter.Activation = DISABLE;
AdfFilterConfig0.SoundActivity.Activation = DISABLE;
AdfFilterConfig0.AcquisitionMode = MDF_MODE_ASYNC_CONT;
AdfFilterConfig0.FifoThreshold = MDF_FIFO_THRESHOLD_NOT_EMPTY;
AdfFilterConfig0.DiscardSamples = 0;
}
/**
* @brief GPDMA1 Initialization Function
* @PAram None
* @retval None
*/
static void MX_GPDMA1_Init(void)
{
/* Peripheral clock enable */
__HAL_RCC_GPDMA1_CLK_ENABLE();
/* GPDMA1 interrupt Init */
HAL_NVIC_SetPriority(GPDMA1_Channel10_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(GPDMA1_Channel10_IRQn);
handle_GPDMA1_Channel10.Instance = GPDMA1_Channel10;
handle_GPDMA1_Channel10.InitLinkedList.Priority = DMA_LOW_PRIORITY_HIGH_WEIGHT;
handle_GPDMA1_Channel10.InitLinkedList.LinkStepMode = DMA_LSM_FULL_EXECUTION;
handle_GPDMA1_Channel10.InitLinkedList.LinkAllocatedPort = DMA_LINK_ALLOCATED_PORT0;
handle_GPDMA1_Channel10.InitLinkedList.TransferEventMode = DMA_TCEM_LAST_LL_ITEM_TRANSFER;
handle_GPDMA1_Channel10.InitLinkedList.LinkedListMode = DMA_LINKEDLIST_CIRCULAR;
if (HAL_DMAEx_List_Init(&handle_GPDMA1_Channel10) != HAL_OK)
{
Error_Handler();
}
if (HAL_DMA_ConfigChannelAttributes(&handle_GPDMA1_Channel10, DMA_CHANNEL_NPRIV) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(&AdfHandle0, hdma, handle_GPDMA1_Channel10);
}
static void MDF_DMAConfig()
{
DMAConfig.Address = (uint32_t)&RecBuff[0];
DMAConfig.DataLength = (REC_BUFF_SIZE * 4U);
DMAConfig.MsbOnly = ENABLE;
}
void HAL_MDF_AcqHalfCpltCallback(MDF_HandleTypeDef* hmdf)
{
DmaRecHalfBuffCplt = 1;
}
void HAL_MDF_AcqCpltCallback(MDF_HandleTypeDef* hmdf)
{
DmaRecBuffCplt = 1;
}
HAL_StatusTypeDef MX_ADFQueue_Config(void)
{
HAL_StatusTypeDef ret = HAL_OK;
/* DMA node configuration declaration */
DMA_NodeConfTypeDef pNodeConfig;
/* Set node configuration ################################################*/
pNodeConfig.NodeType = DMA_GPDMA_LINEAR_NODE;
pNodeConfig.Init.Request = GPDMA1_REQUEST_ADF1_FLT0;
pNodeConfig.Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST;
pNodeConfig.Init.Direction = DMA_PERIPH_TO_MEMORY;
pNodeConfig.Init.SrcInc = DMA_SINC_FIXED;
pNodeConfig.Init.DestInc = DMA_DINC_INCREMENTED;
pNodeConfig.Init.SrcDataWidth = DMA_SRC_DATAWIDTH_HALFWORD;
pNodeConfig.Init.DestDataWidth = DMA_DEST_DATAWIDTH_HALFWORD;
pNodeConfig.Init.SrcBurstLength = 1;
pNodeConfig.Init.DestBurstLength = 1;
pNodeConfig.Init.TransferAllocatedPort = DMA_SRC_ALLOCATED_PORT0|DMA_DEST_ALLOCATED_PORT0;
pNodeConfig.Init.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER;
pNodeConfig.TriggerConfig.TriggerPolarity = DMA_TRIG_POLARITY_MASKED;
pNodeConfig.DataHandlingConfig.DataExchange = DMA_EXCHANGE_NONE;
pNodeConfig.DataHandlingConfig.DataAlignment = DMA_DATA_RIGHTALIGN_ZEROPADDED;
pNodeConfig.SrcAddress = 0;
pNodeConfig.DstAddress = 0;
pNodeConfig.DataSize = 0;
/* Build NodeADFRx Node */
ret |= HAL_DMAEx_List_BuildNode(&pNodeConfig, &NodeADFRx);
/* Insert NodeADFRx to Queue */
ret |= HAL_DMAEx_List_InsertNode_Tail(&ADFQueue, &NodeADFRx);
ret |= HAL_DMAEx_List_SetCircularMode(&ADFQueue);
return ret;
}