cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-G431KB help with DMA GPIO Output

etheory
Senior II

Hi there!

I've just started working with STM32CubeIDE and after a bit of a vertical learning curve I'm slowly getting to grips with most aspects of it.

I want to DMA to GPIO and there doesn't appear to be any way to do this through the .ioc GUI interface. GPIO ports can't be targeted as a peripheral by the DMA interface, and when you select a MemToMem option in the DMA section, the code that is generated by STM32CubeIDE doesn't have any user sections, and is hence effectively not able to be edited by the user.

The other issue is that the MemToMem DMA option doesn't expose the most useful options like "circular" mode (it only exposes "normal") and doesn't give the option to provide any triggers either.

Have I hit the limits of what STM32CubeIDE is able to do already? or is there some way to achieve this through the STM32CubeIDE interface that I haven't yet seen?

BTW FWIW I'm using the very very latest release of STM32CubeIDE.

Thanks,

Luke

24 REPLIES 24

A quick follow up....

The following code actually works:

  RCC->AHB1ENR |= RCC_AHB1ENR_DMAMUX1EN | RCC_AHB1ENR_DMA1EN | RCC_AHB1ENR_DMA2EN;
 
  RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;
  RCC->APB2ENR |= RCC_APB2ENR_TIM8EN;
 
  DMA2_Channel6->CMAR = (uint32_t)gpio_data;
  DMA2_Channel6->CPAR = (uint32_t)&GPIOA->BSRR;
  DMA2_Channel6->CNDTR = GPIO_DATA_LENGTH;
  DMA2_Channel6->CCR =
      DMA_CCR_MSIZE_1 | // memory data size 32 bits
      DMA_CCR_PSIZE_1 | // peripheral data size 32 bits
      DMA_CCR_CIRC    | // circular mode
      DMA_CCR_MINC    | // increment memory pointer
      DMA_CCR_DIR     | // direction memory to peripheral
      DMA_CCR_EN      | // enable channel
      0;
 
  DMAMUX1_Channel11->CCR = (DMA_REQUEST_TIM8_UP << DMAMUX_CxCR_DMAREQ_ID_Pos);
  TIM8->PSC = 0;
  TIM8->EGR = TIM_EGR_UG; // required to load the prescaler
  TIM8->ARR = 525 - 1;
  TIM8->BDTR = TIM_BDTR_MOE; // required on advanced timers
  TIM8->SR = 0; // clear status after TIM_EGR_UG
  TIM8->DIER = TIM_DIER_UDE; // enable DMA on timer update (overflow)
  TIM8->CR1 = TIM_CR1_CEN; /// start the timer

The trick was to use DMA2, and the correct MUX entry (turns out DMAMUX1 channels 0-5 are only for DMA1 and 6-11 only for DMA2).

Also only DMA2 seems to work with GPIO, which is not what R0440 suggests (it shows a dense connection, but that's not the case).

I AM SO RELIEVED THIS IS FINALLY WORKING!

Thank you again @berendi​ for your exhaustive assistance!

etheory
Senior II

OK managed to back-port this solution into the HAL also, like so:

  if (HAL_DMA_Start(&hdma_tim8_up, (uint32_t)gpio_data, (uint32_t)&GPIOA->BSRR, GPIO_DATA_LENGTH) != HAL_OK)
  {
    Error_Handler();
  }
 
  __HAL_TIM_ENABLE_DMA(&htim8, TIM_DMA_UPDATE);
  if (HAL_TIM_Base_Start(&htim8) != HAL_OK)
  {
    Error_Handler();
  }

The trick is to note that the HAL never defines:

__HAL_TIM_ENABLE_DMA(&htim8, TIM_DMA_UPDATE);

Which effectively sets:

TIM8->DIER = TIM_DIER_UDE; // enable DMA on timer update (overflow)

Which makes it all work.

Thanks for coming back with the solution.

> The trick was to use DMA2, and the correct MUX entry (turns out DMAMUX1 channels 0-5 are only for DMA1 and 6-11 only for DMA2).

This clearly contradicts to RM0440:

0690X00000DYYNsQAP.png

Probably this info has to be split according to the cathegory of the devices.

@Imen DAHMEN​  can this please be fixed in RM0440.

@Vincent Onde​  in https://www.st.com/en/microcontrollers-microprocessors/STM32G431VB.html# folder I can't see any AN related to DMA, yet alone to DMAMUX, where this information ought to be detailed, too.

Can you please also confirm this:

> Also only DMA2 seems to work with GPIO, which is not what R0440 suggests (it shows a dense connection, but that's not the case).

Thanks,

JW

Hello Jan,

Thanks for your highlight. I put a request for changing RM0440.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hello,

RM0440 Rev 4, is available with update and correction on "13.3.2 DMAMUX mapping" section following the feedback reported on this thread.

Thank you for your contribution.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hello @Imen DAHMEN​ ,

RM0440 Rev 4 is still not available from the product webpage e.g. here, clicking the link downloads Rev 3 instead. I have already reported it in this thread 9 days ago.

Imen.D
ST Employee

Hello @berendi​ ,

Thank you for your feedback.

I have raised this point internally, so that it could be resolved.

I will keep you informed as soon as it was fixed.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hello,

Sorry for this delay to answer you.

The problem is fixed and RM0440 Rev 4 is now available from the product web page.

 We are sorry for the inconvenience and thank you for your comprehension. 

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Thanks @Imen DAHMEN​ but the link on the page appears to be broken.

I've been unable to view or download: https://www.st.com/resource/en/reference_manual/dm00355726-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf

Which is the link that the RM0440 Rev 4 on the page: https://www.st.com/en/microcontrollers-microprocessors/stm32g431kb.html#resource points to.

I'm not sure where the issue is, if it's on your end or my end.

Thanks,

Luke

Hi @etheory​ ,

I suggest to clean your cache and try again.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen