Skip to main content
Associate II
January 12, 2026
Question

HAL_UART_Transmit_DMA 使用 HAL_UART_AbortReceive 後異常

  • January 12, 2026
  • 2 replies
  • 353 views

Dear @YutinhLin ,

Post Edited by ST moderator to apply source code formatting and translate from Chinese to English to comply with the community rule:

Best regards,

Gyessine

 

晶片型號 : STM32H723VGTx

RX 與 TX Buffer 都已配置到 D2 區塊

使用狀況 :

第一次執行 HAL_UART_Transmit_DMA 正常

執行 HAL_UART_AbortReceive() -> HAL_UARTEx_ReceiveToIdle_DMA() 後

再執行 HAL_UART_Transmit_DMA 無法正常工作

請問這樣的使用方式是否正確

或是需要另外的設定動作才能再正常使用

Chip model: STM32H723VGTx

Both the RX and TX buffers are allocated in the D2 domain.

Usage scenario:

The first execution of HAL_UART_Transmit_DMA operates correctly.

After executing HAL_UART_AbortReceive() followed by HAL_UARTEx_ReceiveToIdle_DMA(), subsequent execution of HAL_UART_Transmit_DMA does not function as expected.



 

2 replies

Technical Moderator
January 12, 2026

Hello @YutinhLin 
Can you provide more details about your case. Expected behavior, current behavior, IOC config, your code?

You can see How to write your question to maximize your chances to find a solution for best results.

Also: How to insert source code

BR
Gyessine

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
YutinhLinAuthor
Associate II
January 13, 2026

我想要達到的程式效果是

DMA receive buffer index 每次接收都可從 0 開始

因此會一直去 reset DMA 設定
modbus_send_package 最後的 HAL_UART_Transmit_DMA  function 內錯誤點 

if (huart->gState == HAL_UART_STATE_READY) 的 huart->gState 內容值為 0x33

 

void CO_DMA_CRL(FunctionalState state)
{
 if(state==DISABLE)
 {
 if(HAL_OK==HAL_UART_AbortReceive(CO_INFO.channel))
 CO_INFO.dma_status=DISABLE;
 }
 else
 {
 CO_INFO.RX.data = (uint8_t *)co_dma_rx_data;
 if(HAL_OK==HAL_UARTEx_ReceiveToIdle_DMA(CO_INFO.channel,(uint8_t*)CO_INFO.RX.data,CO_UART_BUF_LENGTH))
 CO_INFO.dma_status=ENABLE;
 }
}

void modbus_send_package(uint8_t dev_addr, uint8_t fun_id, uint8_t reg, uint16_t reg_count, uint16_t *send_data)
{
 uint16_t crc=0;
 uint16_t data_tmp;
 uint8_t send_len=0;

 CO_INFO.send_func_id = fun_id;
 CO_INFO.read_start_reg = reg;
 CO_INFO.read_reg_count = reg_count;
 CO_INFO.send_data = send_data[0];

 co_dma_tx_data[0]=dev_addr;
 co_dma_tx_data[1]=fun_id;
 if(fun_id == MODBUS_FUN_ID_READ_INFO)//read holding register
 {
 co_dma_tx_data[2]=(reg>>8)&0xFF; //start register address High byte
 co_dma_tx_data[3]=reg&0xFF; //start register address Low byte
 co_dma_tx_data[4]=(reg_count>>8)&0xFF; //register read count High byte
 co_dma_tx_data[5]=reg_count&0xFF; //register read count Low byte
 crc=MODBUS_CRC16(co_dma_tx_data,6);
 co_dma_tx_data[6]=(crc>>8)&0xFF; //crc Low byte
 co_dma_tx_data[7]=crc&0xFF; //crc High byte
 send_len=8;
 }
 else if(fun_id == MODBUS_FUN_ID_WRITE_SINGLE) //write single register
 {
 co_dma_tx_data[2]=(reg>>8)&0xFF; //register address High byte
 co_dma_tx_data[3]=reg&0xFF; //register address Low byte
 data_tmp=send_data[0];
 co_dma_tx_data[4]=(data_tmp>>8)&0xFF; //write data High byte
 co_dma_tx_data[5]=data_tmp&0xFF; //write data Low byte
 crc=MODBUS_CRC16(co_dma_tx_data,6);
 co_dma_tx_data[6]=(crc>>8)&0xFF; //crc Low byte
 co_dma_tx_data[7]=crc&0xFF; //crc High byte
 send_len=8;
 }
 else if(fun_id == MODBUS_FUN_ID_WRITE_MULTI) //write multiple register
 {
 co_dma_tx_data[2]=(reg>>8)&0xFF; //start register address High byte
 co_dma_tx_data[3]=reg&0xFF; //start register address Low byte
 co_dma_tx_data[4]=(reg_count>>8)&0xFF; //register write count High byte
 co_dma_tx_data[5]=reg_count&0xFF; //register write count Low byte
 co_dma_tx_data[6]=reg_count*2; //byte count
 for(uint16_t i=0;i<reg_count;i++)
 {
 data_tmp=send_data[i];
 co_dma_tx_data[7+i*2]=(data_tmp>>8)&0xFF; //write data High byte
 co_dma_tx_data[8+i*2]=data_tmp&0xFF; //write data Low byte
 }
 crc=MODBUS_CRC16(co_dma_tx_data,7+reg_count*2);
 co_dma_tx_data[7+reg_count*2]=(crc>>8)&0xFF; //crc Low byte
 co_dma_tx_data[8+reg_count*2]=crc&0xFF; //crc High byte
 send_len=9+reg_count*2;
 }
 else
 {
 CO_INFO.send_func_id=0;
 CO_INFO.read_start_reg=0;
 CO_INFO.read_reg_count=0;
 CO_INFO.send_data = 0;
 return;
 }

 if(HAL_OK != HAL_UART_Transmit_DMA(CO_INFO.channel, co_dma_tx_data, send_len))
 {
 DEBUG_PRINT("CO MODULE SEND DATA ERROR!!\r\n");
 }
}

 

Technical Moderator
January 12, 2026

Hello @YutinhLin 

What is the issue exactly that you are encountering? What is the return value of HAL_UART_Transmit_DMA?

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question.Saket_Om"
YutinhLinAuthor
Associate II
January 13, 2026

HAL_UART_Transmit_DMA  function 內錯誤點 

if (huart->gState == HAL_UART_STATE_READY) 的 huart->gState 內容值為 0x33