cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474 DMA cannot write to DAC_DHRx register

Shen
Associate II

Hi everyone,

I am using the NUCLEO-G474RE development board with STM32G474RE MCU

The ioc file is attached, and this is main function:

int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* 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);
 
  /* System interrupt init*/
  NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
 
  /* SysTick_IRQn interrupt configuration */
  NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),15, 0));
 
  /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
  */
  LL_PWR_DisableUCPDDeadBattery();
 
  /* 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_DMA_Init();
  MX_GPIO_Init();
  MX_TIM6_Init();
  MX_DAC1_Init();
  /* USER CODE BEGIN 2 */
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  uint16_t Data[2] = {0xFFF, 0x800};
  LL_DAC_Enable(DAC1, LL_DAC_CHANNEL_2);
  while (LL_DAC_IsActiveFlag_DAC2RDY(DAC1) == 0);
  LL_DMA_SetPeriphAddress(DMA1, LL_DMA_CHANNEL_3, (uint32_t) &DAC1->DHR12R2);
  LL_DMA_SetMemoryAddress(DMA1, LL_DMA_CHANNEL_3, (uint32_t) &Data);
  LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_3, 2);
  LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_3);
  LL_TIM_EnableDMAReq_UPDATE(TIM6);
  LL_TIM_EnableCounter(TIM6);
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

​I use TIM6 to generate a periodic DMA request and use it to send waveform data to "DAC_DHRx", but the DMA generates a transfer error (DMA TEIF flag is 1).

0693W00000Ly1LTQAZ.pngWhen I reset the DMA direction to "Peripheral to Memory" in CubeMX, DAC_DHRx can be sent to memory.

Besides that, I have ported this program to STM32L476G-DISCO and it also works fine.

What setting am I missing?

1 ACCEPTED SOLUTION

Accepted Solutions
Shen
Associate II

I solved the problem, I found the following information in the reference manual 12.4.6:

0693W00000Ly3d0QAB.pngAHB peripherals not supporting byte/half-word write transfers, so I change the data width to word, and it works fine.

View solution in original post

3 REPLIES 3
TDK
Guru

Is Data in a DMA-accessible location? Print out the DMA stream register information.

If you feel a post has answered your question, please click "Accept as Solution".
Shen
Associate II

Hi TDK,

Thank you for your reply, and here is my DMA setup:

0693W00000Ly3S7QAJ.png​It should be the DMA accessible location

Shen
Associate II

I solved the problem, I found the following information in the reference manual 12.4.6:

0693W00000Ly3d0QAB.pngAHB peripherals not supporting byte/half-word write transfers, so I change the data width to word, and it works fine.