Skip to main content
Visitor II
March 16, 2025
Question

How to configure GPDMA in STM32H563ZI for USART

  • March 16, 2025
  • 2 replies
  • 825 views

I am using Nucleo-H563ZI in this. I was configuring USART6 in DMA mode, but for this controller instead of DMA, there was GPDMA1/2. Currently, I have configured it in GPDMA1. The module is EC200. I am transmitting AT but am not getting the response that it is OK. Therefore, I am not sure whether the USART is correctly configured or not

Shubham08_0-1742092615394.png

Shubham08_1-1742092687622.png

Shubham08_2-1742092740710.png

Shubham08_3-1742092793406.png

Shubham08_4-1742092809933.png

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <string.h>
#include <stdio.h>
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define EC200_RX_SIZE 16
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

COM_InitTypeDef BspCOMInit;

UART_HandleTypeDef huart4;
UART_HandleTypeDef huart6;
DMA_HandleTypeDef handle_GPDMA1_Channel1;
DMA_HandleTypeDef handle_GPDMA1_Channel0;

/* USER CODE BEGIN PV */
uint8_t EC200_TX[] = "AT\r\n";
uint8_t EC200_RX[16] = {0};

volatile uint8_t TxComplete = 0; // Separate flag for TX
volatile uint8_t RxComplete = 0; // Flag for RX

int isSent = 1;
int countloop =0;
int countinterrupt = 0;
//uint8_t RxComplete = 0;

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_GPDMA1_Init(void);
static void MX_UART4_Init(void);
static void MX_ICACHE_Init(void);
static void MX_USART6_UART_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
//void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
//{
////	isSent = 1;
//	countinterrupt++;
//	HAL_UART_Receive_DMA(&huart6, EC200_RX, 4);
//}
//
//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
//{
// // Set flag to indicate reception complete
// RxComplete = 1;
// // Ready to send next command
// isSent = 1;
//}

// 3. In your TX callback, use the consistent buffer size:
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
 if(huart == &huart6)
 {
 TxComplete = 1;
 countinterrupt++;

 // Start receiving with consistent buffer size
 HAL_UART_Receive_DMA(&huart6, EC200_RX, EC200_RX_SIZE);
 }
}

// 4. Add debug output in your RX callback
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
 if(huart == &huart6)
 {
 RxComplete = 1;


 // Toggle LED for visual confirmation
 BSP_LED_Toggle(LED_YELLOW);

 // Set flag to send next command after a delay
 isSent = 1;
 }
}

// Add error callback to catch DMA errors
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
 if(huart == &huart6)
 {
 // Toggle RED LED rapidly to indicate error
 for(int i=0; i<10; i++) {
 BSP_LED_Toggle(LED_RED);
 HAL_Delay(100);
 }

 // Reset flags
 isSent = 1;
 }
}
/* USER CODE END 0 */

/**
 * @brief The application entry point.
 * @retval int
 */
int main(void)
{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */
 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_GPDMA1_Init();
 MX_UART4_Init();
 MX_ICACHE_Init();
 MX_USART6_UART_Init();
 /* USER CODE BEGIN 2 */
 HAL_UART_Receive_DMA(&huart6, EC200_RX, 10);
 /* USER CODE END 2 */

 /* Initialize leds */
 BSP_LED_Init(LED_GREEN);
 BSP_LED_Init(LED_YELLOW);
 BSP_LED_Init(LED_RED);

 /* Initialize USER push-button, will be used to trigger an interrupt each time it's pressed.*/
 BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);

 /* Initialize COM1 port (115200, 8 bits (7-bit data + 1 stop bit), no parity */
 BspCOMInit.BaudRate = 115200;
 BspCOMInit.WordLength = COM_WORDLENGTH_8B;
 BspCOMInit.StopBits = COM_STOPBITS_1;
 BspCOMInit.Parity = COM_PARITY_NONE;
 BspCOMInit.HwFlowCtl = COM_HWCONTROL_NONE;
 if (BSP_COM_Init(COM1, &BspCOMInit) != BSP_ERROR_NONE)
 {
 Error_Handler();
 }

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {

 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */
//	 if(isSent == 1)
//	 {
//		 HAL_UART_Transmit_DMA(&huart6, EC200_TX, strlen((char*)EC200_TX));
//		 isSent = 0;
//	 }

	 if(isSent == 1)
	 {
		 	 TxComplete = 0;
			 RxComplete = 0;

			 memset(EC200_RX, 0, sizeof(EC200_RX));


	 // Send AT command
	 if (HAL_UART_Transmit_DMA(&huart6, EC200_TX, strlen((char*)EC200_TX)) == HAL_OK)
	 {
	 isSent = 0;
	 }
	 else
	 {
	 // If DMA transmission fails, show error
	 for(int i=0; i<5; i++) {
	 BSP_LED_Toggle(LED_YELLOW);
	 HAL_Delay(200);
	 }
	 }
	 }

//	 if(RxComplete == 1)
//	 {
//	 // Process received data - should be "OK\r\n"
//	 // Ensure null termination for string functions
//	 EC200_RX[4] = '\0';
//
//	 // Forward to debug port
////	 BSP_COM_Write(COM1, EC200_RX, 4);
//
//	 // Reset flag after processing
//	 RxComplete = 0;
//	 }

	 BSP_LED_Toggle(LED_RED);
	 HAL_Delay(500);
	 countloop++;

 }
}

 

 

 

    This topic has been closed for replies.

    2 replies

    Visitor II
    March 17, 2025

    Try to enable FIFO mode on USART.   

    ST Employee
    March 17, 2025

    Hi @Shubham08 

    You could also try to declare isSent variable as volatile (as used in both main and interrupt routines). Depending on your code optimizations options, it could help.
    Another comment : in your code your mentioned COM_WORDLENGTH_8B : 8B is nb of data + parity, so as no parity check is enabled, it means 8B data, not 7 (nb of stop bits is not part of Wordlength.
    regards