Skip to main content
JZaya.1
Associate II
July 6, 2023
Question

STM32CubeMX basics: 10.10 STM32Cube HAL labs UART - Lab UART IT

  • July 6, 2023
  • 2 replies
  • 1001 views

Hello,

I am following tutorial and the file does not compile, what is wrong? https://www.youtube.com/watch?v=5i-Gw7OC7oo&list=PLnMKNibPkDnGtuIl5v0CvC81Am7SKpj02&index=48

/* USER CODE BEGIN PV */
uint8_t buffer_tx[10] = {10,11,12,13,14,15,16,17,18,19};
uint8_t buffer_rx[10];
/* USER CODE END PV */

/* USER CODE BEGIN 0 */
HAL_UART_Receive_IT(&huart1, buffer_rx, 10);
HAL_UART_Transmit_IT(&huart1, buffer_tx, 10);
/* USER CODE END 0 */

/* USER CODE BEGIN 4 */
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){
 
}
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
while (1);
}
/* USER CODE END 4 */
 
 
../Core/Src/main.c:60:21: error: expected declaration specifiers or '...' before '&' token
60 | HAL_UART_Receive_IT(&huart1, buffer_rx, 10);
| ^
../Core/Src/main.c:60:30: error: expected declaration specifiers or '...' before 'buffer_rx'
60 | HAL_UART_Receive_IT(&huart1, buffer_rx, 10);
| ^~~~~~~~~
../Core/Src/main.c:60:41: error: expected declaration specifiers or '...' before numeric constant
60 | HAL_UART_Receive_IT(&huart1, buffer_rx, 10);
| ^~
../Core/Src/main.c:61:22: error: expected declaration specifiers or '...' before '&' token
61 | HAL_UART_Transmit_IT(&huart1, buffer_tx, 10);
| ^
../Core/Src/main.c:61:31: error: expected declaration specifiers or '...' before 'buffer_tx'
61 | HAL_UART_Transmit_IT(&huart1, buffer_tx, 10);
| ^~~~~~~~~
../Core/Src/main.c:61:42: error: expected declaration specifiers or '...' before numeric constant
61 | HAL_UART_Transmit_IT(&huart1, buffer_tx, 10);

 

    This topic has been closed for replies.

    2 replies

    Graduate II
    July 6, 2023

    Hello. Insert these lines:

    HAL_UART_Receive_IT(&huart1, buffer_rx, 10);
    HAL_UART_Transmit_IT(&huart1, buffer_tx, 10);

    Inside of some function (main for example). Now these are treated as function prototypes since they seems to be missplaced.

    KDJEM.1
    ST Technical Moderator
    July 6, 2023

    Hello @JZaya.1 ,

    I advise you to take a look at this wiki: Getting started with UART

    This article explains what is UART and how to use it through examples using  NUCLEO-L476RG boards

    • Simple UART communication in polling mode
    • UART with Interrupt
    • UART with DMA

    This wiki can help you to set up UART and generate code with STM32CubeIDE and to use HAL functions.

    Thank you.

    Kaouthar

    To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.