Skip to main content
Visitor II
August 20, 2025
Question

STM32U535 using GPDMA and TIM2 to output a WAV file to the DAC

  • August 20, 2025
  • 1 reply
  • 349 views

I have been struggling with this chip for a few days now.  I have code up for the STM32F072, and the STM32F100 series chips, but the GPDMA in the STM32U535 is baffling me.  And no, I am not a big fan of the product notes for the GPDMA, while I've gone through them, I couldn't find much to help.

Here's the challenge; the chip fails immediately with a DMA_FLAG_DTE error, with the trigger overrun flag being set in the CSR.  No idea why or where to go next after 2 days of trying to troubleshoot this.  Here is the MXCube configuration:

clock config.jpgTIM2 config.jpgDAC config1.jpggpdma config.jpg

In the code, there is a simple 8Khz WAV file stored in the "tinkles" array.  Using the standard generated code from MXCube, I have attempted to just play it out the DAC with the following calls:

HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t*)tinkles_wav, tinkles_wav_len, DAC_ALIGN_8B_R);
HAL_TIM_Base_Start(&htim2); 

It *is* an 8-bit array, and I am not sure if that may be part of this.  Here is the code:

extern unsigned int shot_wav_len, tinkles_wav_len;
extern unsigned char shot_wav[], tinkles_wav[];
/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void HALDelayDontWork(uint32_t t) {
uint32_t s;
for (s = 0; s < t * 32222; s++) {
}
}

void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac) {
// while (1) {
GPIOB->ODR ^= 0x0100; //ground the bit - to turn the LED on
HALDelayDontWork(100);
GPIOB->ODR |= 0x0100; //Turn off the PCB LED
HALDelayDontWork(100);
// }
}
/* USER CODE END 0 */

/**
 * @brief The application entry point.
 * @retval int
 */
int main(void)
{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */
 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_GPDMA1_Init();
 MX_DAC1_Init();
 MX_FLASH_Init();
 MX_RTC_Init();
 MX_TIM1_Init();
 MX_TIM2_Init();
 MX_USB_DRD_FS_PCD_Init();
 MX_FileX_Init();
 MX_ICACHE_Init();
 MX_SPI1_Init();
 /* USER CODE BEGIN 2 */
GPIOB->ODR |= 0x0100; //Turn off the PCB LED
GPIOB->ODR |= 0x0200; //Turn off the USB LED

HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t*)tinkles_wav, tinkles_wav_len, DAC_ALIGN_8B_R);
HAL_TIM_Base_Start(&htim2); 

 /* USER CODE END 2 */

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
while (1) {
 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */
}
 /* USER CODE END 3 */
}
And of course it is in the HAL_DAC_ErrorCallbackCh1 that we immediately wind up after a single interrupt to the GPDMA1_Channel0_IRQHandler, and a subsequent interrupt to DAC1_IRQHandler.  
 
What am I missing?
 
-D
 
 
Edited by ST Moderator to apply source code formatting. Please see the tips on how to properly insert code: How to write your question to maximize your chances to find a solution.
    This topic has been closed for replies.

    1 reply

    Visitor II
    August 27, 2025

    Figured it out.  The DMA_FLAG_DTE error is thrown when the source and destination address in the DAC_Start_DMA call is not expressed as a 32-bit pointer.

    Technical Moderator
    August 27, 2025

    Hello,

    If you solved your issue please accept your answer as solution.

    Thank you.