DAVE build issue

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Yalcin_Haksoz
Level 2
Level 2
First like received 10 replies posted 10 questions asked

I am having a compile issue with my DAVE project. I simplified my code so it is easy to see the problem.
The attached project gives the error during build. Nothing shows up as a mistake in the individual files. If the "functions" file is removed from the project then it builds fine.
Any help to identify the issue would be very much appreciated.

0 Likes
1 Solution
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @yalcin-haksoz ,

Please make the following changes in declarations.h file.

Pradeep_PN_0-1707296216716.png

It is always recommended to use extern while declaration.

Please initialize the array globally instead of locally.

If you initialize the array locally the values won't reflect when you try to access this array from different file.

The parameters.c file should look like this.

Pradeep_PN_1-1707296364473.png

This will resolve your errors.

Hope this helps and let me know if you have any further queries.

Best Regards
Pradeep.

 

 

View solution in original post

8 Replies
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @Yalcin_Haksoz ,

I went through your project.

I see that the error is multiple definition of 'SWper'

The reason to the above is if you are defining functions or initializing variables in the header file it's possible to get a linker error since the same function is defined in more than one module.

So be sure to put the declaration in the header file and definition in the source file.

So please change the declarations.h as below :

Pradeep_PN_0-1707215825939.png

The functions.c as below :

Pradeep_PN_1-1707215854529.png

This will resolve your error.

You can also try defining the variables as below : 

Pradeep_PN_2-1707216216481.png

You can use any of the above two methods which will help you resolve the build errors.

Hope this helps and let me know if you have nay further queries.

Best Regards
Pradeep.

yalcin-haksoz
Employee
Employee
5 replies posted First like given 25 sign-ins

Great help, works now. Thank you very much.

0 Likes
lock attach
Attachments are accessible only for community members.
yalcin-haksoz
Employee
Employee
5 replies posted First like given 25 sign-ins

Hi Pradeep, in line with your recommendation, I separated declarations from the  definitions of variables and now my program works fine. However, now I am having another issue with my real project. I have an array which I have declared in declarations file and defined the values in parameters file and it is giving me trouble. My project file is attached. I would really appreciate it if you could help me identify the problem.

Thank you,

YH

0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @yalcin-haksoz ,

Please make the following changes in declarations.h file.

Pradeep_PN_0-1707296216716.png

It is always recommended to use extern while declaration.

Please initialize the array globally instead of locally.

If you initialize the array locally the values won't reflect when you try to access this array from different file.

The parameters.c file should look like this.

Pradeep_PN_1-1707296364473.png

This will resolve your errors.

Hope this helps and let me know if you have any further queries.

Best Regards
Pradeep.

 

 

Excellent, everything works. Thank you.

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I'm new to DAVE.

But being an old programmer, I feel uncomfortable seeing real definition in ".h" file,

as in each of including ".c" files, different instance of the variable will be allocated and could couse confilicts.

So I modified some files as follows.

declarations.h

#ifndef DECLARATIONS_H_
#define DECLARATIONS_H_


#include"XMC4200.h"
#include<stdint.h>
#include <stdbool.h>

extern	uint16_t SWper;	//Switching period in clock cycles. 1600 for fs=50kHz. 1250 for 64kHz. QuarterSine table must be changed accordingly.
extern	uint16_t Gain;	//PeakOfSine/InputDC, 1000 for 1. Do not use values above 1.
extern	uint8_t Ipklim;

extern	uint8_t Step;	//0 to 250, 0: Zero crossing
extern	bool Polarity;	//0: negative half cycle, 1: positive half cycle. Start with 0 to ensure fast leg bootstrap capacitor precharge.
extern	bool CountDir;	//1: Count up, 0: Count down. Start with 0 to ensure slow leg bootstrap capacitor precharge.
extern	bool G3state;	//Current state of G3
extern	bool G4state;	//Current state of G4


extern	uint16_t QuarterSine[];

#endif /* DECLARATIONS_H_ */

parameter.c

#include <declarations.h>

uint16_t SWper = 1250;	//Switching period in clock cycles. 1600 for fs=50kHz. 1250 for 64kHz. QuarterSine table must be changed accordingly.
uint16_t Gain = 222;	//PeakOfSine/InputDC, 1000 for 1. Do not use values above 1.
uint8_t  Ipklim = 6;
uint8_t  Step = 0;	//0 to 250, 0: Zero crossing
bool     Polarity = 0;	//0: negative half cycle, 1: positive half cycle. Start with 0 to ensure fast leg bootstrap capacitor precharge.
bool     CountDir = 0;	//1: Count up, 0: Count down. Start with 0 to ensure slow leg bootstrap capacitor precharge.
bool     G3state;	//Current state of G3
bool     G4state;	//Current state of G4

//Quarter sine for fs=64kHz: 0 to 1250, 251 steps and unity gain. Use the Excel file to generate tables for other switching frequencies.
uint16_t QuarterSine[] = {
	0,7,15,23,31,39,47,54,62,70,78,86,94,101,109,117,125,133,141,148,156,164,172,180,187,195,203,211,218,226,234,241,249,257,265,272,280,287,295,303,310,
	318,326,333,341,348,356,363,371,378,386,393,401,408,416,423,430,438,445,452,460,467,474,481,489,496,503,510,517,525,532,539,546,553,560,567,574,581,588,
	595,602,609,615,622,629,636,643,649,656,663,669,676,682,689,696,702,709,715,721,728,734,741,747,753,759,766,772,778,784,790,796,802,808,814,820,826,832,
	838,844,849,855,861,867,872,878,883,889,894,900,905,911,916,921,927,932,937,942,947,953,958,963,968,973,977,982,987,992,997,1001,1006,1011,1015,1020,
	1024,1029,1033,1038,1042,1046,1051,1055,1059,1063,1067,1071,1075,1079,1083,1087,1091,1095,1099,1102,1106,1110,1113,1117,1120,1124,1127,1131,1134,1137,
	1140,1144,1147,1150,1153,1156,1159,1162,1165,1167,1170,1173,1176,1178,1181,1183,1186,1188,1191,1193,1195,1198,1200,1202,1204,1206,1208,1210,1212,1214,
	1216,1218,1219,1221,1223,1224,1226,1227,1229,1230,1232,1233,1234,1235,1236,1238,1239,1240,1241,1242,1242,1243,1244,1245,1245,1246,1247,1247,1248,1248,
	1248,1249,1249,1249,1249,1249,1249,1250
};

main() in main.c

int main(void)
{

  DAVE_Init();           //Initialization of DAVE APPs


  PORT1->IOCR0 |= 0x800000;	//P1.2 is setup for loop timing. Bit23 set to 1 for push-pull output.
  CCU80_CC82->PRS = SWper;	//Change switching frequency. App setting is ignored for fsw. But ensure dead times are set correctly in the app.

//  Parameters(); // removed on 8-Feb-2024

  while(1U)
  {
	  PORT1->OMR |= 0x40004;	//P1.2 is toggled at each loop cycle. Setting OMR bits 2 and 18 high for toggle. Pin switches at high frequency except during interrupt handling.
  }
}

 

I could compile this in my environment, but as I don't have the hardware I could not test if it works.

moto

P.S. Sorry for being wordy and picky.

 

Works in the real board. Thank you.

Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @MotooTanaka ,

Using the "extern" keyword is indeed the best way when declaring the variables in header files.

Your code will definitely work without any issues.

"extern" changes the linkage. With the keyword, the function / variable is assumed to be available somewhere else and the resolving is deferred to the linker.

Thanks for the tip.

Best Regards
Pradeep.