cancel
Showing results for 
Search instead for 
Did you mean: 

F410: multiple definition of `huart2';

HMSEdinburge
Visitor

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
..

 

 

 

1 REPLY 1
gbm
Lead III

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.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice