0

In a STM32G4, I was able to setup the DAC DMA such that I could use a regular variable (ie. a uint8_t array). However, when I tried porting my code over to an H723, the DAC DMA would not work unless it's with a constant variable (ie. a const uint8_t array) that is set before runtime. My application requires runtime changes to the array. A pointer initialization of the array does not seem to work. I was wondering if there is a way to remedy this? Am I stuck with the constant variable? Thank you!

EDIT1: Current Setup of DAC DMA and 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 Config:

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 Config:

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);

}

in the main function:

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);
}

This setup does not work, but just by initialzing dac_data1 as const uint8_t and predefining it, the DMA works.

Rudy Montoya
  • 85
  • 1
  • 7
  • DMA would be quite useless if it was unable to fetch data from RAM. There is probably some error in your configuration. You need to give more details. – Tagli Apr 10 '21 at 07:21
  • 3
    Some STM32 parts have different memory banks, core-coupled-memory (CCM) is usable by the processor but not DMA. Check the address against the reference manual to see which bank it corresponds to. – Tom V Apr 10 '21 at 09:22
  • From the build analyzer, `dac_data1` is on RAM (0x2000002c). ITCMRAM, RAM_D1, RAM_D2 and RAM_D3 are all empty. In the reference manual (RM0468 for H723), I can't find any reference to "CCM," "core-coupled-memory," or "CCMRAM". Is there a datasheet or webpage dedicated to CCM for h723? All of the links I could find online are all from third-party sites and/or different target MCU's. Thanks again! – Rudy Montoya Apr 10 '21 at 17:33
  • @TomV All RAMS **are** accesible by DMA in H7 family. It is a piece of false information. It has 3 DMA controllers and you need to chain two to access some memories. But it is doable - I did it myself when I familiarizing H7 family. – 0___________ Apr 10 '21 at 20:46
  • I said "some STM32 parts" not H7 specifically. What I said is correct but not a direct answer the question which is why I made it a comment. Still, it helped the OP find his own answer. – Tom V Apr 10 '21 at 21:19

1 Answers1

0

Ok, Thanks to Tom V for the insight on the Different Memory Banks. In my case, dac_data1 is placed on RAM, also known as DTCMRAM on the reference manual. DTCMRAM is not accessible to DMA but is chosen to be the default memory location for runtime operations on the H7. A modification in the linker files (In my case, both ..._FLASH.ld and ..._RAM.ld) were needed. I changed the .bss, .data and ._user_heap_stack memory location from RAM to RAM_D1. This was taken directly from: https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices

Rudy Montoya
  • 85
  • 1
  • 7
  • No problem! You should mark the green tick next to your own answer if the question is now solved. – Tom V Apr 10 '21 at 21:22