2024-11-01 09:09 PM
HI there, i m using F410 Nucleo, and i keep getting these errors when using USART2, as I declare in 2 separe files i.e. main.c and buffer. could anyone advise how to resolve this?
error: multiple definition of `huart2';
//main.c
..
/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart2;
..
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
// buffer.c
#include "buffer.h"
#include <string.h>
/**** define the UART ****/
UART_HandleTypeDef huart2; // woldes
#define uart &huart2
..
2024-11-01 10:55 PM
Your question is about basics of C programming; it's not related to STM32.The whole program may contain only a single definition of a symbol. Define the huart2 in one module only (maybe buffer.c - it's already defined there), put its declaration as extern in buffer.h:
extern UART_HandleTypeDef huart2;
Include buffer.h in main.c.