cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WL55 & SubGHz_Phy_PingPong - UART Communication

SiaTP
Associate

Hi,

I had an issue with UART communication in the SubGHz_Phy_PingPong middleware. The problem is that I can't receive any characters and the callback function never gets called to read the incoming bytes. Also, I figured it out from the ISR routine even the RXNE flag would set randomly. And if I use this function  HAL_UART_RxCpltCallback(&huart2); it just keeps calling the callback function and the registered task associated with the callback function even if there are no incoming bytes from UART. Now wondering if there is any configuration in CuebMX or any function to call to receive characters properly and on time. I've checked other libraries for exmaple SigFox AT-Slave and implemented the same code, but didn't work.

/*
 * app_radio.c
 *
 */


#include "app_radio.h"

extern UART_HandleTypeDef huart2;

static volatile uint8_t arr_comPortRxBuff[COM_PORT_BUFF_SIZE];
static volatile uint8_t arr_comPortTxBuff[COM_PORT_BUFF_SIZE];

static void _init_gpio( void );

/**
  * @brief  CNotifies the upper layer that a character has been received
  */
static void (*NotifyCb)(void);

/**
 * @brief  It schedules the Virtual Com task
 * @PAram  None
 * @retval None
 */
static void CmdProcessNotify(void);

static void _init_COMPort(void (*CmdProcessNotify)(void));
static void COMPortRxCallBack(uint8_t *data, uint16_t length, uint8_t error);

static UTIL_ADV_TRACE_Status_t COMPortSend( const uint8_t *pData, uint16_t Length);

static void BroadcastData( void );

void _init_radio( void )
{
	_init_gpio();
	_init_COMPort(CmdProcessNotify);
	COMPortSend( "Hello from Radio:\r\n", sizeof("Hello from Radio:\r\n"));

	for(uint8_t cnt = 0; cnt < 10; cnt++)
	{
		HAL_GPIO_TogglePin( LED1_GPIO_Port, LED1_Pin);
		HAL_Delay(50);
		HAL_GPIO_TogglePin( LED1_GPIO_Port, LED1_Pin);
		HAL_Delay(50);
	}
}

//
static void _init_gpio( void )
{
	GPIO_InitTypeDef GPIO_InitStruct = {0};

	__HAL_RCC_GPIOB_CLK_ENABLE();

	/*Configure GPIO pin Output Level */
	HAL_GPIO_WritePin(GPIOB, LED1_Pin, GPIO_PIN_RESET);

	/*Configure GPIO pins : PBPin */
	GPIO_InitStruct.Pin = LED1_Pin;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}

static void _init_COMPort(void (*CmdProcessNotify)(void))
{
	volatile int8_t status;

	status = UTIL_ADV_TRACE_StartRxProcess(COMPortRxCallBack);

	if (status == HAL_OK) {
	    COMPortSend("UTIL_ADV_TRACE_StartRxProcess succeeded.\r\n", sizeof("UTIL_ADV_TRACE_StartRxProcess succeeded.\r\n"));
	}
	else {
		COMPortSend("UTIL_ADV_TRACE_StartRxProcess failed.\r\n", sizeof("UTIL_ADV_TRACE_StartRxProcess failed.\r\n"));
	}

	/* register call back*/
	if (CmdProcessNotify != NULL)
	{
		NotifyCb = CmdProcessNotify;
		HAL_UART_RxCpltCallback(&huart2);
	}

	UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_Vcom), UTIL_SEQ_RFU, BroadcastData);
}

// COMPOrt receive callback
static void COMPortRxCallBack(uint8_t *data, uint16_t length, uint8_t error)
{
	// You can now process each received byte
	arr_comPortRxBuff[0] = *data;

	NotifyCb();
}



static UTIL_ADV_TRACE_Status_t COMPortSend( const uint8_t *pData, uint16_t Length)
{
	return UTIL_ADV_TRACE_Send( pData, Length);
}

//
static void BroadcastData( void )
{
	while (1 != UTIL_ADV_TRACE_IsBufferEmpty())
	{
		/* Wait that all printfs are completed*/
	}
	COMPortSend( "Here is your message: ", sizeof("Here is your message: "));
	//HAL_UART_RxCpltCallback(&huart2);		
	COMPortSend( arr_comPortRxBuff, 1);
	//HAL_GPIO_TogglePin( LED1_GPIO_Port, LED1_Pin);
	//HAL_Delay(50);
}

static void CmdProcessNotify(void)
{
  /* USER CODE BEGIN CmdProcessNotify_1 */

  /* USER CODE END CmdProcessNotify_1 */
  UTIL_SEQ_SetTask(1 << CFG_SEQ_Task_Vcom, CFG_SEQ_Prio_0);
  /* USER CODE BEGIN CmdProcessNotify_2 */

  /* USER CODE END CmdProcessNotify_2 */
}


Thank you.


0 REPLIES 0