2024-07-27 04:12 AM
Hi,
I'm using the Lorawan_End_Node. I wrote a function in lora_app.c file and declared the same in lora_app.h file.
But when I use the same in the main file I get undefined reference to.
2024-07-27 04:20 AM
Show the exact log with the error.
The .h must be included.
The .c must be in your project and be compiled.
The compiler output .o of the .c must be linked.
Mixing C and C++ may cause trouble.
hth
KnarfB
2024-07-27 05:11 AM
Thanks for the reply @KnarfB
My main.c file
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
#include "app_lorawan.h"
#include "tim.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "sys_app.h"
#include "queue.h"
#include "lora_app.h"
#include "stdio.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
extern QueueHandle_t txQueue;
extern QueueHandle_t rxQueue;
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void MX_FREERTOS_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* 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_TIM1_Init();
/* USER CODE BEGIN 2 */
MX_LoRaWAN_Init();
txQueue = xQueueCreate(10, sizeof(LoRaWANMessage_t));
rxQueue = xQueueCreate(10, sizeof(LoRaWANMessage_t));
xTaskCreate(LoRaWANSendTask, "LoRaWANSendTask", 2048, NULL, 2, NULL);
xTaskCreate(LoRaWANReceiveTask, "LoRaWANReceiveTask", 2048, NULL, 2, NULL);
/* USER CODE END 2 */
/* Init scheduler */
// osKernelInitialize();
/* Call init function for freertos objects (in cmsis_os2.c) */
// MX_FREERTOS_Init();
/* Start scheduler */
// osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
// printf("check ! \n");
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure LSE Drive Capability
*/
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK3|RCC_CLOCKTYPE_HCLK
|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.AHBCLK3Divider = RCC_SYSCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
switch (GPIO_Pin)
{
case BUT1_Pin:
/* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */
APP_LOG(TS_OFF, VLEVEL_M, "Button 1 Pressed\r\n");
start_motor_forward();
break;
case BUT2_Pin:
APP_LOG(TS_OFF, VLEVEL_M, "Button 2 Pressed\r\n");
stop_motor();
break;
case BUT3_Pin:
APP_LOG(TS_OFF, VLEVEL_M, "Button 3 Pressed\r\n");
start_motor_reverse();
break;
default:
break;
}
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
while (1)
{
}
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
lora_app.h
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file lora_app.h
* @author MCD Application Team
* @brief Header of application of the LRWAN Middleware
******************************************************************************
* @attention
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LORA_APP_H__
#define __LORA_APP_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdint.h>
#include "FreeRTOS.h"
#include "queue.h"
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* LoraWAN application configuration (Mw is configured by lorawan_conf.h) */
#define ACTIVE_REGION LORAMAC_REGION_IN865
/* USER CODE BEGIN EC_CAYENNE_LPP */
/*!
* CAYENNE_LPP is myDevices Application server.
*/
/*#define CAYENNE_LPP*/
/* USER CODE END EC_CAYENNE_LPP */
/*!
* Defines the application data transmission duty cycle. 10s, value in [ms].
*/
#define APP_TX_DUTYCYCLE 10000
/*!
* LoRaWAN User application port
* @note do not use 224. It is reserved for certification
*/
#define LORAWAN_USER_APP_PORT 2
/*!
* LoRaWAN Switch class application port
* @note do not use 224. It is reserved for certification
*/
#define LORAWAN_SWITCH_CLASS_PORT 3
/*!
* LoRaWAN default class
*/
#define LORAWAN_DEFAULT_CLASS CLASS_C
/*!
* LoRaWAN default confirm state
*/
#define LORAWAN_DEFAULT_CONFIRMED_MSG_STATE LORAMAC_HANDLER_UNCONFIRMED_MSG
/*!
* LoRaWAN Adaptive Data Rate
* @note Please note that when ADR is enabled the end-device should be static
*/
#define LORAWAN_ADR_STATE LORAMAC_HANDLER_ADR_ON
/*!
* LoRaWAN Default Data Rate
* @note Please note that LORAWAN_DEFAULT_DATA_RATE is used only when LORAWAN_ADR_STATE is disabled
*/
#define LORAWAN_DEFAULT_DATA_RATE DR_0
/*!
* LoRaWAN Default Tx output power
* @note LORAWAN_DEFAULT_TX_POWER must be defined in the [XXXX_MIN_TX_POWER - XXXX_MAX_TX_POWER] range,
else the end-device uses the XXXX_DEFAULT_TX_POWER value
*/
#define LORAWAN_DEFAULT_TX_POWER TX_POWER_0
/*!
* LoRaWAN default activation type
*/
#define LORAWAN_DEFAULT_ACTIVATION_TYPE ACTIVATION_TYPE_OTAA
/*!
* LoRaWAN force rejoin even if the NVM context is restored
* @note useful only when context management is enabled by CONTEXT_MANAGEMENT_ENABLED
*/
#define LORAWAN_FORCE_REJOIN_AT_BOOT true
/*!
* User application data buffer size
*/
#define LORAWAN_APP_DATA_BUFFER_MAX_SIZE 242
/*!
* Default Unicast ping slots periodicity
*
* \remark periodicity is equal to 2^LORAWAN_DEFAULT_PING_SLOT_PERIODICITY seconds
* example: 2^4 = 16 seconds. The end-device will open an Rx slot every 16 seconds.
*/
#define LORAWAN_DEFAULT_PING_SLOT_PERIODICITY 4
/*!
* Default response timeout for class b and class c confirmed
* downlink frames in milli seconds.
*
* The value shall not be smaller than RETRANSMIT_TIMEOUT plus
* the maximum time on air.
*/
#define LORAWAN_DEFAULT_CLASS_B_C_RESP_TIMEOUT 8000
/*Send*/
#define CFG_APP_LORA_PROCESS_NAME "LORA_SEND_PROCESS"
#define CFG_APP_LORA_PROCESS_ATTR_BITS (0)
#define CFG_APP_LORA_PROCESS_CB_MEM (0)
#define CFG_APP_LORA_PROCESS_CB_SIZE (0)
#define CFG_APP_LORA_PROCESS_STACK_MEM (0)
#define CFG_APP_LORA_PROCESS_PRIORITY osPriorityNone
#define CFG_APP_LORA_PROCESS_STACK_SIZE 1024
/*Store Context*/
#define CFG_APP_LORA_STORE_CONTEXT_NAME "LORA_STORE_CONTEXT"
#define CFG_APP_LORA_STORE_CONTEXT_ATTR_BITS (0)
#define CFG_APP_LORA_STORE_CONTEXT_CB_MEM (0)
#define CFG_APP_LORA_STORE_CONTEXT_CB_SIZE (0)
#define CFG_APP_LORA_STORE_CONTEXT_STACK_MEM (0)
#define CFG_APP_LORA_STORE_CONTEXT_PRIORITY osPriorityNone
#define CFG_APP_LORA_STORE_CONTEXT_STACK_SIZE 1024
/*Stop Join*/
#define CFG_APP_LORA_STOP_JOIN_NAME "LORA_STOP_JOIN"
#define CFG_APP_LORA_STOP_JOIN_ATTR_BITS (0)
#define CFG_APP_LORA_STOP_JOIN_CB_MEM (0)
#define CFG_APP_LORA_STOP_JOIN_CB_SIZE (0)
#define CFG_APP_LORA_STOP_JOIN_STACK_MEM (0)
#define CFG_APP_LORA_STOP_JOIN_PRIORITY osPriorityNone
#define CFG_APP_LORA_STOP_JOIN_STACK_SIZE 1024
/*LM Handler*/
#define CFG_LM_HANDLER_PROCESS_NAME "LM_HANDLER_PROCESS"
#define CFG_LM_HANDLER_PROCESS_ATTR_BITS (0)
#define CFG_LM_HANDLER_PROCESS_CB_MEM (0)
#define CFG_LM_HANDLER_PROCESS_CB_SIZE (0)
#define CFG_LM_HANDLER_PROCESS_STACK_MEM (0)
#define CFG_LM_HANDLER_PROCESS_PRIORITY osPriorityNone
#define CFG_LM_HANDLER_PROCESS_STACK_SIZE 1024
/* USER CODE BEGIN EC */
typedef struct {
uint8_t port;
uint8_t buffer[256];
uint8_t bufferSize;
} LoRaWANMessage_t;
extern QueueHandle_t txQueue;
extern QueueHandle_t rxQueue;
/* USER CODE END EC */
/* Exported macros -----------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/**
* @brief Init Lora Application
*/
void LoRaWAN_Init(void);
/* USER CODE BEGIN EFP */
void init_lorawan(void);
void LoRaWANSendTask(void *pvParameters);
void LoRaWANReceiveTask(void *pvParameters);
void send_message(uint8_t *data, uint8_t size, uint8_t port);
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /*__LORA_APP_H__*/
lora_app.c
/*
* lora_app1.c
*
* Created on: Jul 26, 2024
* Author: harshahegde
*/
#include "lora_app.h"
#include "stm32wlxx_hal.h"
#include "stm32wlxx_hal_rtc.h"
#include "stm32wlxx_nucleo.h"
#include "LoRaMac.h"
#include "Commissioning.h"
#include "NvmDataMgmt.h"
#include "LmhPackage.h"
#include "LmHandler.h"
#include "sys_app.h"
#include "utilities_def.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "main.h"
QueueHandle_t txQueue;
QueueHandle_t rxQueue;
void init_lorawan(void) {
// Initialize LoRaWAN stack
LmHandlerInit();
// Configure LoRaWAN parameters
LmHandlerParams_t params;
params.ActiveRegion = LORAMAC_REGION_EU868;
params.AdrEnable = LORAWAN_ADR_ON;
params.TxDatarate = DR_0;
params.PublicNetworkEnable = true;
params.DutyCycleEnabled = false;
LmHandlerConfigure(¶ms);
// Join the LoRaWAN network
LmHandlerJoin();
// Wait for the join to succeed
while (!LmHandlerJoinStatus()) {
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void LoRaWANSendTask(void *pvParameters) {
LoRaWANMessage_t message;
while (1) {
if (xQueueReceive(txQueue, &message, portMAX_DELAY) == pdPASS) {
// Send message
LmHandlerAppData_t appData;
appData.Port = message.port;
appData.BufferSize = message.bufferSize;
appData.Buffer = message.buffer;
LmHandlerSend(&appData, LORAWAN_CONFIRMED_MSG);
}
}
}
void LoRaWANReceiveTask(void *pvParameters) {
LoRaWANMessage_t message;
LmHandlerAppData_t appData;
while (1) {
// Wait for a message
if (LmHandlerReceive(&appData)) {
// Copy received data into message structure
message.port = appData.Port;
message.bufferSize = appData.BufferSize;
memcpy(message.buffer, appData.Buffer, appData.BufferSize);
// Send the message to the RX queue
xQueueSend(rxQueue, &message, portMAX_DELAY);
}
vTaskDelay(pdMS_TO_TICKS(1000)); // Check for messages every second
}
}
void send_message(uint8_t *data, uint8_t size, uint8_t port) {
LoRaWANMessage_t message;
message.port = port;
message.bufferSize = size;
memcpy(message.buffer, data, size);
xQueueSend(txQueue, &message, portMAX_DELAY);
}
Error:
/workspace_1.15.1/LoRaWAN_End_Node/Core/Src/main.c:121: undefined reference to `txQueue'
A detailed error image is attached.
Thanks!!
2024-07-27 06:05 AM
Linker (ld) error.
Check that lora_app.c is in the list of source files.
hth
KnarfB
2024-07-27 06:47 AM
Thanks for the reply @KnarfB
Sorry to ask this(I'm new to STM32CubeIde). where can I find the list of source files?
Is it in the project settings --> Tool settings --> MCU GCC compiler?
Then it the folder is included here.
-mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WL55xx -c -I../../Core/Inc -I../../LoRaWAN/App -I../../LoRaWAN/Target -I../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../Utilities/trace/adv_trace -I../../Utilities/misc -I../../Utilities/timer -I../../Utilities/lpm/tiny_lpm -I../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../Middlewares/Third_Party/LoRaWAN/Mac -I../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../Middlewares/Third_Party/SubGHz_Phy -I../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../Drivers/CMSIS/Include -I../../Drivers/BSP/STM32WLxx_Nucleo -I../../Middlewares/Third_Party/FreeRTOS/Source/include -I../../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 -I../../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3 -Og -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity --specs=nano.specs -mfloat-abi=soft -mthumb
is there any place apart from here?