2025-01-21 03:03 AM - last edited on 2025-01-22 02:02 AM by Andrew Neil
Hello,
I am using the STM32H7S78-DK board and STM32CubeIDE for development. In my application, I am working with UART communication between UART4 and UART7.
Despite implementing HAL_UARTEx_ReceiveToIdle_IT, I am still unable to receive any response from UART7.
Here is my code for reference,
/* USER CODE BEGIN PV */
#define RX_BUFFER_SIZE 20
#define RX_BUFFER_SIZE_7 50
uint8_t rxBuffer[RX_BUFFER_SIZE] = {0}; // Buffer to store received data
uint8_t rxBuffer7[RX_BUFFER_SIZE_7] = {0}; // Buffer to store received data
osThreadId_t uartTaskHandle;
const osThreadAttr_t uartTask_attributes =
{
.name = "uartTask",
.priority = (osPriority_t)osPriorityNormal,
.stack_size = 512 * 4,
};
void UART_Print(const char* message)
{
// Transmit the string data over UART
HAL_UART_Transmit(&huart4, (uint8_t*)message, strlen(message), HAL_MAX_DELAY);
}
void SendDataOnUART7(uint8_t *pData)
{
uint8_t TxData[20];
uint16_t length = (uint16_t)pData[0];
memcpy(TxData, &pData[1],length);
// Transmit the string data over UART
HAL_UART_Transmit(&huart7,TxData, length, HAL_MAX_DELAY);
}
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
if (huart->Instance == huart7.Instance)
{
// Transmit the string data over UART
printf("Received data on uart7: %s\n\r", rxBuffer7);
HAL_UARTEx_ReceiveToIdle_IT(&huart7, rxBuffer7, RX_BUFFER_SIZE_7);
}
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == huart4.Instance)
{
// Print received message
printf("Received: %s\n\r", rxBuffer);
SendDataOnUART7(rxBuffer);
memset(rxBuffer, 0, RX_BUFFER_SIZE);
// Re-enable UART interrupt for the full buffer to receive more data
HAL_UART_Receive_IT(&huart4, rxBuffer, RX_BUFFER_SIZE);
}
}
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MPU Configuration--------------------------------------------------------*/
MPU_Config();
/* Enable the CPU Cache */
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache---------------------------------------------------------*/
SCB_EnableDCache();
/* MCU Configuration--------------------------------------------------------*/
/* Update SystemCoreClock variable according to RCC registers values. */
SystemCoreClockUpdate();
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
MX_GPIO_Init();
MX_HPDMA1_Init();
MX_LTDC_Init();
MX_CRC_Init();
MX_DMA2D_Init();
MX_JPEG_Init();
MX_FLASH_Init();
MX_I2C1_Init();
MX_GPU2D_Init();
MX_ICACHE_GPU2D_Init();
MX_UART4_Init();
MX_UART7_Init();
UART_Print("Start...TouchGFX...Project\n\r");
printf("Hello_STM32H7S78-DK!\n\r");
/* Enable UART4 interrupt mode */
//Make sure that the data sent is exactly 20 bytes, as the RX_BUFFER_SIZE is set to 20. If the data is not 20 bytes, it will not work properly!
HAL_UART_Receive_IT(&huart4, rxBuffer, RX_BUFFER_SIZE);
HAL_UARTEx_ReceiveToIdle_IT(&huart7, rxBuffer7, RX_BUFFER_SIZE_7);
MX_TouchGFX_Init();
/* Call PreOsInit function */
MX_TouchGFX_PreOSInit();
osKernelInitialize();
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* creation of TouchGFXTask */
TouchGFXTaskHandle = osThreadNew(TouchGFX_Task, NULL, &TouchGFXTask_attributes);
uartTaskHandle = osThreadNew(UART_Task, NULL, &uartTask_attributes);
/* Start scheduler */
osKernelStart();
while (1)
{
}
/* USER CODE END 3 */
}
I would appreciate any guidance or example code to resolve this issue.
Best regards,
Mehul
2025-01-21 12:33 PM
I can't seem to find the original post. I was searching for a subject that was related, but didn't find one. Way too many posts/replies to open and read all of them.
I started a new project for the Nucleo-H723 and have the code ready to test UART7, along with UART5 and VCP. However, I didn't get a chance to test it during the holiday. I will try to remember to test it tonight.
2025-01-21 01:03 PM
2025-01-22 01:14 AM - last edited on 2025-01-22 01:34 AM by Andrew Neil
Duplicate - merged
Hello Community,
I am using receive interrupts for UART4 and UART7 on stm32h7s78 board. So, in this UART7 interrupt is not working. So, anyone have the solution for this.
Is UART7 is capable for rx interrupt?
Please share your inputs on this. It will be appreciated.
Thank you,
Harsh
2025-01-22 01:40 AM
Do your UART7 interrupts work alone? ie, without UART4 ?
This seems very similar:
And this seems to be the same question:
2025-01-22 01:42 AM
Yess it is the same issue we are facing
2025-01-22 01:50 AM
You haven't said what hardware you're using - ST board(s)? 3rd-party board(s)? custom board(s) - nor how you have this all connected up.
Please see: How to write your question to maximize your chances to find a solution.
@harshpanchal_6 wrote:WIFI/BLE module will send the response to UART-7 but I am not getting the UART-7 callback.
How have you verified that the WIFI/BLE module does actually send the response?
And that the response actually arrives at the UART7 RX pin?
@harshpanchal_6 wrote:But if I do the debugging with USB-to-TTL and EMC3080-P module I am receiving the expected response from the module.
What do you mean by "do the debugging" here ?
Show full details of the two setups - with diagrams.
Is it the same setup as this ?
2025-01-22 01:56 AM
Yes
2025-01-22 01:58 AM
@harshpanchal_6 wrote:Yess it is the same issue we are facing
OK - I've merged them
2025-01-22 03:20 AM
Hi @Andrew Neil ,
Can you explain this behaviour that my UART4 and UART7 are not works together any specific reason?
If I use Ethernet instead of UART4 to send/receive cmd i am able to get UART7 interrupt.
Here is my code for your reference,
// Callback function to handle received data from Ethernet
void handle_received_data(uint8_t *data, uint16_t size)
{
// Transmit the string data over UART7
HAL_UART_Transmit(&huart7, data, size, HAL_MAX_DELAY);
}
// Recived data over UART7
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == huart7.Instance)
{
// send Recived response to to Ethernet
udp_send_uart7_data(rxBuffer7,sizeof(rxBuffer7));
memset(rxBuffer7, 0, RX_BUFFER_SIZE_7);
// Ready to get new data
HAL_UART_Receive_IT(&huart7, rxBuffer7, RX_BUFFER_SIZE_7);
}
}
This code works as expected but somehow my response comes incomplete after sending AT cmd.
Like this ,
When I send the command AT+UART? for the first time, I receive the complete response. However, when I send the same command AT+UART? again, I only receive a partial response. On the third attempt, I receive the complete response of the second command, while the response for the third command remains incomplete."
Can you explain why this behavior is occurring and suggest a solution to fix it
And please explain this also,
Can you explain this behaviour that my UART4 and UART7 are not works together any specific reason?
Thanks,
/Mehul
2025-01-22 03:29 AM - edited 2025-01-22 03:58 AM
@Mehulrana511 wrote:Can you explain this behaviour that my UART4 and UART7 are not works together any specific reason?
See my earlier reply:
Note the suggestion about ring buffers
@Mehulrana511 wrote:This code works as expected but somehow my response comes incomplete after sending AT cmd.
So it is not working as expected!
In this case, have you monitored the hardware connection between UART7 and the WIFI/BLE module, and confirmed that everything on the wire is still correct.
@Mehulrana511 wrote:When I send the command AT+UART? for the first time, I receive the complete response. However, when I send the same command AT+UART? again, I only receive a partial response. On the third attempt, I receive the complete response of the second command, while the response for the third command remains incomplete
That could be your AT Command handler getting out-of-sync?
In that case, pay particular attention to your handling of CR and LF ...
Are you properly handling the command-response sequence, or are you just relying on arbitrary, "blind" delays?
PS:
This doesn't look good:
// Recived data over UART7 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if (huart->Instance == huart7.Instance) { // send Recived response to to Ethernet udp_send_uart7_data(rxBuffer7,sizeof(rxBuffer7)); memset(rxBuffer7, 0, RX_BUFFER_SIZE_7); // Ready to get new data HAL_UART_Receive_IT(&huart7, rxBuffer7, RX_BUFFER_SIZE_7); } }
With that, the UART receive will only compete when it has received exactly RX_BUFFER_SIZE_7 characters.
But your replies from the BLE/WiFi module are of different sizes - they are not RX_BUFFER_SIZE_7 characters long.
So you will be receiving partial messages, and/or (parts of) multiple messages at each interrupt.
Again, see the comments on ring buffers.