1
\$\begingroup\$

I have two MCUs, first one is STM32F070F6P6 which sends data over USART2 TX DMA and second one is STM32H755ZIT6 which receives data over USART2 RX DMA.

Also notice that STM32F070F6P6's TX Pin connected to the STM32H755ZIT6's RX Pin.

this is STM32F070F6P6's USART2 DMA setup: enter image description here enter image description here enter image description here and this is source code of STM32F070F6P6's UART transmitting

// Global variables
volatile u8 uart_dma_tx_done_ = 0x01U;
u8 dma[8] = {0, 1, 2, 3, 4, 5, 6, 7};

// Interrupts
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
   if(huart->Instance == huart2.Instance)
   {
      uart_dma_tx_done_ = 0x01U;
   }
}
 
// Inside main function
while (1)
{
   if(uart_dma_tx_done_ = 0x01U)
   {
       err = HAL_UART_Transmit_DMA(&huart2, dma, 8);
   }
}

I've checked it with Logic Analyzer and it sends data over uart.

Here is STM32H755ZIT6's UART configuration: enter image description here enter image description here enter image description here and the source code for STM32H755ZIT6:

  // Global variables
  u8 dma[8];
  volatile u8 uart_dma_rx_done_ = 0x01U;

  // Interrupt
  void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
  {
    if(huart->Instance == huart2.Instance)
    {
    
       uart_dma_rx_done_ = 0x01U;
    }
  }

  // Inside main function
  while (1)
  {
    if(uart_dma_rx_done_ == 0x01U)
    {
      err = HAL_UART_Receive_DMA(&huart2, dma, 8);
      uart_dma_rx_done_ = 0x00U;
    }
  }

The problem is that I do not receive data via DMA, u8 dma[8] array is empty(all zeroes). I've tried different DMA streams but did not work. Also it works without DMA e.g Polling method.

Also u8 dma[8]; array is not allocated in DTCRAM because address is 0x24000304, so DMA can access to it.

Also I have overrun error often, but clearing this flag does not helps. Sometimes it never enters RX callback after first or several times.

What else can I do?

\$\endgroup\$
12
  • \$\begingroup\$ You do not show initialization. Check that clocks for both UART and DMA are running and both are initialized. Using debugger check UART and DMA register. Most probably or one of them report error, or you will notice something strange, like all regs zero, wrong pointers value or other issue. \$\endgroup\$
    – Misaz
    Feb 12 at 16:06
  • \$\begingroup\$ MX_GPIO_Init(); MX_DMA_Init(); MX_USART2_UART_Init(); this is the initialization code for both MCU. Are you saying that UART and DMA clocks speed must be equal? if so how can I set DMA clock speed? \$\endgroup\$
    – Alatriste
    Feb 12 at 16:23
  • \$\begingroup\$ What about the D-Cache? Is it enabled? If yes, then temporarly disable it and check if it solves your issue. You have to set up the MPU (Memory Protection Unit) such that the Cache is bypassed when reading the memory region where your DMA variable stays. Another option would be to check if the DMA is reporting any error. The information is stored somewhere in the HAL dma struct. The error code is also stored in a register in the DMA peripheral \$\endgroup\$
    – Mau5
    Feb 12 at 20:38
  • \$\begingroup\$ @Mau5 I enabled D-Cache but did not help, then I disabled it, also did not help. Also configured MPU, by stetting u8 dma[8] buffer address .. I do no have any DMA error, only UART errors: noise error, frame error and overrrun error. \$\endgroup\$
    – Alatriste
    Feb 13 at 10:06
  • \$\begingroup\$ ok so then cache is not a problem. what about your DMA config? on the CubeMX screenshot for the H7 we can see the DMA request is created for UART_TX (not RX) and correspondingly the direction is memory to peripheral and not peripheral to memory. Change that and check again \$\endgroup\$
    – Mau5
    Feb 13 at 17:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.