cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Transmit_DMA

NSing.5
Senior

i'veA question related to transmission using DMA. i'm facing a strange situation.

  1. it works perfectly when i use "HAL_UART_Transmit_DMA(&huart1, TxBuf, 5);" in the main program.
  2. However in my project i've crated a separate file for my application program, which i include in the main program, and when i call "HAL_UART_Transmit_DMA(&huart1, TxBuf, 5);" from my application program, only first two bytes are transferred as per my data rest all bytes are corrupted.

5 REPLIES 5
Aymen ABBES
ST Employee

Hello @NSing.5​ ,

Thanks for sharing this issue. 

To further analyze your problem could you please provide:

  • The MCU you are using
  • The CubeMx and you IDE versions
  • The project you are working on or your *.ioc file if it is possible

Kind regards,

Aymen

gbm
Lead III

Show the declaration of TxBuf (where exactly is it declared?) and check its usage (timing). You cannot write a new value to TxBuf until the transfer is finished.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

The project file is attached with for your reference. i'm working on STM32F730

TxBuf is declared as local variable in the function that calls HAL_UART_Transmit_DMA(&huart1, TxBuf, 5); as follows:

void mstr_digno(uint8_t Device_address,uint16_t sub_code)
{
      uint8_t TxBuf[25];
      uint16_t crc_value=0;
      TxBuf[0] = Device_address;
      TxBuf[1] = 0x08;                 //operation code
      convert_I_To_Byte(sub_code);
      TxBuf[2] = IntegerToByte.high_byte;
      TxBuf[3] = IntegerToByte.low_byte;
      convert_I_To_Byte(Device_address);
      TxBuf[4] = IntegerToByte.high_byte;
      TxBuf[5] = IntegerToByte.low_byte;
      crc_value = CRC_Cal_Value(TxBuf,5);
      crc_value = crc_value&0xFFFF;
      convert_I_To_Byte(crc_value);
      TxBuf[6]=IntegerToByte.low_byte;
      TxBuf[7]=IntegerToByte.high_byte;
      //HAL_UART_Transmit_DMA(&huart1, TxBuf, 10);
      HAL_UART_Transmit(&huart1, TxBuf, 10,10);
}

i'm writing new data to it after 2 seconds.