cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WPAN extern variable error

KlemenPfce
Associate III

Hi,

 

I am using a custom PCB with SM32WB5MM module. I am reading a temperature sensor and I want to update its value to the advertising package in "a_AdvData".

For this I made a "shared_variable" in my main.c (for now its just defined to 10, later it wil lstore the temperature reading from sensor).

Then I made a "extern int shared_variable;" definition in main.h.

Then in app_ble.c I assign this data to the struct of "a_AdvData" package.

Main.h

 

 

 

 

 

/* Includes ------------------------------------------------------------------*/
#include "stm32wbxx_hal.h"
#include "app_conf.h"
#include "app_entry.h"
#include "app_common.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
extern int shared_variable;
/* USER CODE END ET */

/* Exported constants -----

 

 

 

 

 

main.c

 

 

 

 

 

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_RF_Init();
  MX_GPIO_Init();
  MX_RTC_Init();
  MX_I2C3_Init();
  /* USER CODE BEGIN 2 */

  int shared_variable = 10;

/*
  uint8_t	status;
  VL53LMZ_Configuration 	Dev;
  VL53LMZ_ResultsData 	Results;

 

 

 

 

 

app_ble.c (line 28)

 

 

 

 

 

static void Adv_Request(APP_BLE_ConnStatus_t NewStatus)
{
  tBleStatus ret = BLE_STATUS_INVALID_PARAMS;

  BleApplicationContext.Device_Connection_Status = NewStatus;
  /* Start Fast or Low Power Advertising */
  ret = aci_gap_set_discoverable(ADV_TYPE,
                                 CFG_FAST_CONN_ADV_INTERVAL_MIN,
                                 CFG_FAST_CONN_ADV_INTERVAL_MAX,
                                 CFG_BLE_ADDRESS_TYPE,
                                 ADV_FILTER,
                                 0,
                                 0,
                                 0,
                                 0,
                                 0,
                                 0);
  if (ret != BLE_STATUS_SUCCESS)
  {
    APP_DBG_MSG("==>> aci_gap_set_discoverable - fail, result: 0x%x \n", ret);
  }
  else
  {
    APP_DBG_MSG("==>> aci_gap_set_discoverable - Success\n");
  }

/* USER CODE BEGIN Adv_Request_1*/ 								//Here the values for advertising package are entered
  a_AdvData[23] = shared_variable;
/* USER CODE END Adv_Request_1*/

  /* Update Advertising data */
  ret = aci_gap_update_adv_data(sizeof(a_AdvData), (uint8_t*) a_AdvData);
  if (ret != BLE_STATUS_SUCCESS)
  {
      APP_DBG_MSG("==>> Start Fast Advertising Failed , result: %d \n\r", ret);
  }
  else
  {
      APP_DBG_MSG("==>> Success: Start Fast Advertising \n\r");
  }
  return;
}

 

 

 

 

 

  When I assign a value(instead of using "sahred_variable") to the struct inside the app_ble.c, the correct value appears in advertising package. But when I use the attached code, I get error:

./STM32_WPAN/App/app_ble.c:1030: undefined reference to `shared_variable'

So now I am confused, is there a problem that I don't see with my extern definitions or is there some linker problems?

 

My project explorer:

KlemenPfce_0-1739349093588.png

 

1 REPLY 1
KlemenPfce
Associate III

Figured it out, made a function in main.c, that return the extern variable, then call it from app_ble.c. 

 

 

int update_data(void){
	return shared_variable;
}