Skip to main content
Raymond Buck
Senior
June 26, 2026
Solved

Can't compile code due to strange error messages STM32CubdIDE

  • June 26, 2026
  • 2 replies
  • 14 views

When I compile my code, I get strange errors that make no sense.

#define ADC_BUFFER 1000 gives error "expected declaration specifiers or '...' before numeric constant"
even though the line above it #define ADC_HIGH_THRESHOLD 3500 doesn't generate an error.

HAL_TIM_Base_Start(&htim3); and HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buffer, ADC_BUFFER); both generate "Syntax error".

The TIM and ADC Start errors expanded error message is:  error: expected declaration specifiers or '...' before '&' token

 

/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
#include "globals.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define ADC_HIGH_THRESHOLD 3500
#define ADC_BUFFER 1000
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

DMA_HandleTypeDef hdma_adc1;
ADC_HandleTypeDef hadc1;
TIM_HandleTypeDef htim3;

UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */
volatile uint8_t bit_ready_flag = 0;
volatile uint8_t counter = 0, bitcount = 0;
volatile uint8_t analysis_ready = 0;
uint16_t adc_buffer[ADC_BUFFER]; // DMA will automatically fill this array

int zoneoffset = -7; // *********************TEMP TESTING*****************************
uint8_t IsValid(void);
uint8_t seccount = 0, newbit = 0, oldbit = 0, tempbit = -1;
bool is_synced = false;

typedef struct {
uint8_t hour; // 0-23
uint8_t minute; // 0-59
uint16_t doy; // Day of Year (1 - 366)
uint8_t year; // 2-digit year (e.g., 26 for 2026)
} local_t;
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_ADC1_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_TIM3_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
HAL_TIM_Base_Start(&htim3);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buffer, ADC_BUFFER);
/* USER CODE END 0 */

/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
int wwvb_bit;
uint8_t chkvalid = 0, onetime = 0, bootcount = 0;
uint16_t synccount = 0;
uint32_t final_high_duration_ms = 0;
uint8_t is_pulse_valid = 0;
/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_USART1_UART_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */

while(HAL_GPIO_ReadPin(WWVB_IN_GPIO_Port, WWVB_IN_Pin) == GPIO_PIN_SET); // wait for pin to go low if it is high
while(HAL_GPIO_ReadPin(WWVB_IN_GPIO_Port, WWVB_IN_Pin) == GPIO_PIN_RESET); // wait for pin to go high
HAL_GPIO_WritePin(OB_LED_GPIO_Port, OB_LED_Pin, 0);
// this starts timer2 so it aligns with the start of a new WWVB second
__HAL_TIM_SET_COUNTER(&htim3, 0); // clear timer counter
// __HAL_TIM_CLEAR(&htim2, TIM_UPDATE); // clear interrupt flag - safety measure - it should already be cleared
HAL_TIM_Base_Start(&htim3); // timer is now aligned to edge of WWVB low going signal

SyncStart();
HAL_GPIO_WritePin(OB_LED_GPIO_Port, OB_LED_Pin, 0);

while (1)
{

I have done a Project → Clean but no change. I must be missing something.

Best answer by Raymond Buck

Dummy me! 

I didn’t have the two Start calls inside a function. That also caused the #define error message.

Sometimes you can’t see the forest for the trees.

2 replies

David Littell
Senior II
June 27, 2026

First guess is your “ADC_BUFFER” conflicts with something else named “ADC_BUFFER”.  Try renaming yours and see if you get different (!) error messages.  Good luck.

Raymond Buck
Raymond BuckAuthorBest answer
Senior
June 27, 2026

Dummy me! 

I didn’t have the two Start calls inside a function. That also caused the #define error message.

Sometimes you can’t see the forest for the trees.