Jump to content

Compiler Errors


jackchaos
 Share

Recommended Posts

Earlier today a spent a long time trying to figure out why everything in my application started to go haywire.

I was given a "...used only once" error when compiling and at the time I was unable to find the problem.

Whats worse, my application started behaving wierd.

I feard that I may have reached my RAM memory limit so I began looking for places to optimize.

I was able to completely remove a 32 element array and the compiler message below went away.

From then on, everything started to work again unit I saw the error again. This time, I was able to pinpoint the line in the source that produce the error... but I cannot determine why I get the error.

Below is the output of make.bat with the compiler message:

C:\MATRIX~1\MIOSAP~1\MATRIX~1>make
Makefile generated.
Makefile.bat generated.
Assembling MIOS SDCC wrapper
==========================================================================
Compiling pic18f452.c
Processor: 18F452
==========================================================================
Compiling main.c
Processor: 18F452
        MOVFF   PREINC1, r0x00
pcoderegs.c:367: removing reg r0x00 because it is used only once
==========================================================================
Linking project
==========================================================================
Converting to project.syx
Block 003000-0033FF allocated - Checksum: 1A
Block 003400-0037FF allocated - Checksum: 22
Block 003800-003BFF allocated - Checksum: 55
Block 003C00-003FFF allocated - Checksum: 54
Block 004000-0043FF allocated - Checksum: 1D
Block 004400-0047FF allocated - Checksum: 04
Block 004800-004BFF allocated - Checksum: 24
Block 004C00-004FFF allocated - Checksum: 24
Block 005000-0053FF allocated - Checksum: 1D
Block 005400-0057FF allocated - Checksum: 2C
Block 005800-005BFF allocated - Checksum: 2B
Block 005C00-005FFF allocated - Checksum: 2D
Block 006000-0063FF allocated - Checksum: 3E
Block 006400-0067FF allocated - Checksum: 5A
Block 006800-006BFF allocated - Checksum: 6C
Block 006C00-006FFF allocated - Checksum: 7D
==========================================================================
SUCCESS!
Here is the segment of code that created the error.
	case 2: // LFO2 Select

		Selected_LFO = 1;

		// set the LED
               MIOS_DOUT_PinSet(ButtonConfigMap[pin].dout_pin, DIN_STATE_ON);  // <----  THIS LINE
		//MIOS_DOUT_PinSet(ButtonConfigMap[pin].dout_pin, (MIOS_DOUT_PinGet(pin)== DIN_STATE_ON) ? DIN_STATE_OFF : DIN_STATE_ON);

		// toggle the other buttons				
		MIOS_DOUT_PinSet(ButtonConfigMap[0].dout_pin,DIN_STATE_OFF);
		Update_LFO_LED_Status();

	break;					

Now, if I comment out that line, and uncomment the line below, it compiles without the error.

P.S.

I'll  be posting some photos of my work in progress today in the HUI forum.

Link to comment
Share on other sites

Hi,

I think your problem is the variable access by an array index inside a function call (SDCC-related restriction):

http://www.midibox.org/dokuwiki/doku.php?id=c_tips_and_tricks_for_pic_programming#array_access

MIOS_DOUT_PinSet(ButtonConfigMap[pin].dout_pin, DIN_STATE_ON);

best regards,

Michael

Link to comment
Share on other sites

I found that wiki earlier today but there isn't a lot there to describe the problem.

Am I right to believe it's an unpredictable/intermittent problem?.. because I do access variables in arrays accross functions elsewhere.

I was about to post a question: "How can I tell how much memory I have available?" or "Will the compiler give me an error when I use up all available ram?".

Then I realized I could test this myself.

in main.c I initialized these one by one:

unsigned char memorytest1[MEMSIZE];

unsigned char memorytest2[MEMSIZE];

unsigned char memorytest3[MEMSIZE];

then in Init() I did this:

unsigned char i;
	for(i=0;i<MEMSIZE;i++) {
		memorytest1[i] = 2;
		memorytest2[i] = 2;
		memorytest3[i] = 2;		
	}

memtest1 and 2 compiled fine but after adding memtest3 I got:

"error: no target memory available for section "udata_main_22"

So this tells me I have at least 512 bytes of available ram according to the compiler?

Link to comment
Share on other sites

Am I right to believe it's an unpredictable/intermittent problem?

Especially the combination of array + structure as parameter of a function call seems odd.

From the Wiki: "Sometimes the transfer of an array between modules does not work properly"

Have you seen the paranthesis-tipp? This could be related too!

I found that wiki earlier today but there isn't a lot there to describe the problem.

Well, someone found out that this makes problems, now it's in the tipps section. Of course, you could start reading the SDCC sourcecode to find out why it behaves this way and add a detailed explanation to the wiki, but I think for most people (incl. me) it's sufficient to say: "be aware, there could be a problem!"

Now, instead of finding out how much RAM you have*, you could have tried if the solution about the array access solves your problem or not. So to say, normally there wouldn't be a compile error about this. It would be helpful to stay at the source of your problem and not drifting away...

Your RAM-code does not help in this issue, esp. your conclusion of 512 bytes seems to be a result of the "Large Arrays" Problem which is described just below the "Array Access" Problem :-\

Anyway.

After trying if the previous suggestion helps, it could be interesting for you to additionally read the following, if you're interested in the PIC specifications:

-> the PIC Datasheet (Wiki Link)

-> the MIOS Document Download Section -> MIOS RAM Handling.txt

-> http://www.midibox.org/forum/index.php?topic=5962.0

* from the PIC Datasheet:

PIC18F452

On-Chip Program Memory: 32K (FLASH), 16384 Single Word Instructions

On-Chip RAM (bytes): 1536

Data EEPROM (bytes): 256

Regards,

Michael

Link to comment
Share on other sites

Especially the combination of array + structure as parameter

Well, now at least I know where to look when this happens again.

I'm wondering if the compiler will always give me the message "MOVFF PREINC1 ... used only once" when this problem comes up? If so, then I can work with that and be sure to work around it like the WIKI suggests.

I was able to work around my error mention in my 1st post on this topic by by moving the code between the case: break: into a function of its own.

About the memory test post: I forgot to include that I initialized the arrays at 256 elements each: #define MEMSIZE 256.

I got memory errors after initializing the 3rd array of 256 elements.

I'm aware of the large array issue and I've been working around it.

I didn't need to know its available RAM... I wanted to know how much RAM I had available after MIOS and my application were loaded and running.

I'll definitely need to go through all the source and make the necessary changes to avoid the compiler and array errors... I don't want to spend another 4 hours tracking down things like this :).

Thanks for the help!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...