STM32H723- DMA DAC 仅适用于 const?

STM32H723- DMA DAC only works with const only?

在 STM32G4 中,我能够设置 DAC DMA,以便我可以使用常规变量(即 uint8_t 数组)。然而,当我尝试将我的代码移植到 H723 时,DAC DMA 将无法工作,除非它具有在运行前设置的常量变量(即 const uint8_t 数组)。我的应用程序需要对数组进行运行时更改。数组的指针初始化似乎不起作用。我想知道是否有办法解决这个问题?我坚持使用常量变量吗?谢谢!

EDIT1:DAC DMA 和 TIMER 的当前设置

static void MX_DAC1_Init(void){
  DAC_ChannelConfTypeDef sConfig = {0};
  hdac1.Instance = DAC1;
  if (HAL_DAC_Init(&hdac1) != HAL_OK){
    Error_Handler();
  }
  sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
  sConfig.DAC_Trigger = DAC_TRIGGER_T15_TRGO;
  sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE;
  sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_ENABLE;
  sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
  if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK)
  {
    Error_Handler();
  }
}

Timer15 配置:

static void MX_TIM15_Init(void)
{ TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};

  htim15.Instance = TIM15;
  htim15.Init.Prescaler = 55-1;
  htim15.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim15.Init.Period = 10-1;
  htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim15.Init.RepetitionCounter = 0;
  htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
  if (HAL_TIM_Base_Init(&htim15) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim15, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
}

DMA 配置:

static void MX_DMA_Init(void){
 __HAL_RCC_DMA1_CLK_ENABLE();

  HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn);
  /* DMAMUX1_OVR_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMAMUX1_OVR_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMAMUX1_OVR_IRQn);

}

在主函数中:

int main(void){
  MX_DAC1_Init();
  MX_TIM15_Init();
  MX_OPAMP2_Init();
  
  /* USER CODE BEGIN 2 */
  set_sine(dac_data1, NUM_DAC_POINTS) //Set a max amplitude uniformly over number of points, dac_data is initialized as uint8_t dac_data1[NUM_DAC_POINTS];
  HAL_TIM_Base_Start(&htim15); //Start the timer for DAC DMA Transfer
  HAL_DAC_Init(&hdac1);
  (HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_2, (uint32_t *)dac_data1, NUM_DAC_POINTS, DAC_ALIGN_8B_R);
}

此设置不起作用,但只需将 dac_data1 初始化为 const uint8_t 并预定义它,DMA 就可以工作。

好的,感谢 Tom V 对不同内存库的见解。在我的例子中,dac_data1 放在 RAM 上,在参考手册上也称为 DTCMRAMDTCMRAM 不可由 DMA 访问,但被选为 H7 上运行时操作的默认内存位置。需要修改链接器文件(在我的例子中,..._FLASH.ld 和 ..._RAM.ld)。我将 .bss、.data 和 ._user_heap_stack 内存位置从 RAM 更改为 RAM_D1。这直接取自:https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices