CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pic18F87J94 bootloader. Downloaded firmware doesn't work.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jul 13, 2018 2:50 pm     Reply with quote

OK I don't use that PIC and ..
Mr. T . may be onto something...

however this caught my eye.
...
unsigned int1 EstadoPuertoPulsador;
unsigned int1 EstadoPuertoPulsadorAnt;
unsigned int1 FlancoBajadaPulsador;
unsigned int1 FlancoSubidaPulsador;
unsigned int1 IncCont100ms;
unsigned int1 IncCont1seg;
unsigned int1 SalSirena;
unsigned int8 NumeroPantalla;

...
uses 7 bits. I would add a 'dummy' 8th bit just to 'tidy' up the use of RAM.
Maybe it doesn't matter, but in the past we've seen 'boundary issues' when bytes don't line up neatly. I assume the compiler would assign those 7 bits to one byte and the listing would show what the compiler did.

That PIC has LOTS of RAM so 'space' shouldn't be the issue, but perhaps the implementation is or the assignements of the RAM themselves.
isgoy



Joined: 29 Mar 2012
Posts: 13
Location: Spain

View user's profile Send private message

PostPosted: Fri Jul 13, 2018 3:38 pm     Reply with quote

Originally I used structures of 8 bits declared in a library to some flags in the code. To reduce them and to don't use this libraries, I have declared this "unsigned int1" variables.
I don't think this could be a problem. If I don't declare big arrays it runs ok. If I do, it fails.

It seems that it is a compiler problem. I will report it to ccs
Thanks!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat Jul 14, 2018 4:56 am     Reply with quote

That compiler is over fifty versions out of date....
CCS are hardly going to be interested in an issue that they have probably fixed long ago.
2014 compiler..... Sad
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jul 14, 2018 5:29 am     Reply with quote

One way to narrow down this problem is to create a simple program that just reserves a portion of RAM as an array and fill it with data.
Make the array say 64 bytes long, fill and see if it works.
If that works, make it say, 255 bytes long and retest.
Keep increasing and testing until it fails.
If one huge array works, then create 2 arrays and repeat the process.
Your program has 5 or 6, 100 byte arrays and fails ,so really these tests of mine should fail quickly.
If these test programs do NOT fail, it's probably not a compiler/array problem, rather something in your code is causing it to fail.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat Jul 14, 2018 1:58 pm     Reply with quote

There was an issue with structures sometimes being placed into the same RAM as other variables. Fixed about 5.030. A couple of other minor PIC18 memory management issues also that have been fixed since.
isgoy



Joined: 29 Mar 2012
Posts: 13
Location: Spain

View user's profile Send private message

PostPosted: Thu Jul 19, 2018 12:29 am     Reply with quote

I am talking with CCS. We have analyzed generated LST files and it seems that all is correct.
I have done some test and it fails when the variables are in another bank of RAM different to 0. It seems that it doesn't make correctly the change of the BSR to access them or, it some conditions, it lost BSR value.
If I declare this arrays at the end of the code it runs ok because used variables are in bank 0.
We have analyzed LST file and it seems that it saves BSR when an interrupt appears.
In bootloader is put NOXINST fuse. I have put also in main code but nothing.

One friend has compiled me the code with 5.076 version and it fails.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jul 19, 2018 3:46 am     Reply with quote

Try one simple/silly thing.

Declare your arrays as 128 entries each not 100.
I know it'll use more RAM, but see if the problem disappears.

I remember an issue several years ago, where a user was having an array getting corrupted. It did seem to only happen when the array size was a multiple of 100!.
isgoy



Joined: 29 Mar 2012
Posts: 13
Location: Spain

View user's profile Send private message

PostPosted: Fri Jul 20, 2018 1:47 am     Reply with quote

It also fails with array of 128.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Jul 20, 2018 3:18 am     Reply with quote

Fair enough.
It was worth the test.

Have you tried the experiment of building the code located at 0x2000, with just the re-vector parts, but no actual bootloader?.

I must admit your problem is 'odd' One person only reported a similar problem in the last few years, and that with a very early V5 compiler. I've built code with KB of RAM in use, and never seen anything causing problems whether loaded with a bootloader or not. Once the code is booted, the bootloader should make no difference at all.

Have you tried with more than one chip?.
One obvious 'difference' with the bootloader used, is that the code will be sitting much higher in the ROM. This is why the test without the bootloader, but with the code still positioned at the higher location is potentially 'informative'. It is possible that the ROM may have a faulty cell, which just happens to be hit when the code it located higher. Adding the arrays does add some extra code to handle these so these may just be triggering a hardware fault....
isgoy



Joined: 29 Mar 2012
Posts: 13
Location: Spain

View user's profile Send private message

PostPosted: Mon Jul 23, 2018 1:12 am     Reply with quote

I have tried with another pic and it also fails.
It is strange because original whole code uses variables in a lot of blocks of RAM and it doesn't fail
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Mon Jul 23, 2018 2:46 am     Reply with quote

Yes. I must admit to finding myself thinking 'outside the box' on what is actually going on. Thoughts like a ground loop when the bootloader is connected resulting in corrupted writes. Or possibly corrupted execution (are you disconnecting the bootloader connection when testing?).
Seriously too many thousands of pieces of code have been written and used with CCS and the bootloader for there to really be an issue. Hence something else needs to be going wrong. Problem is 'what'?....
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 23, 2018 8:39 am     Reply with quote

Sounds like it's time to go back to a 'flashing LED' program and see if it works. If so, then allocate say a 64 byte buffer, loop to fill and test. If that works, keep doubling buffer,fill, test, repeat until it does fail.
'something' is weird... your real program works if 'burned' in, the bootloader should be solid,sigh...
Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Tue Jul 24, 2018 6:03 am     Reply with quote

OK
Quote:

I tried to disable
#use fast_io(ALL)
and in this case it also runs ok

This seems to imply that something the booloader is doing to the I/O is preventing the pin used as the input from working right.
Now the TRIS settings in ConfigurarPuertos look right, so the obvious thought is that somehow this function is not actually getting called.

Now I'm having trouble working out the actual load 'sequence'. Your main file has:
Code:

#include <SAR714.h>
#ifdef CON_BOOTLOADER
    #include <usb_bootloader.h>
#endif


Is the SAR714.h the '.h' file you list?.

If so, this is your problem. You have not got the bootloader relocation applied when you load the file....
Code:

#ifdef CON_BOOTLOADER
    #include <usb_bootloader.h>
#endif
#include <SAR714.h>


The bootloader relocation needs to be before all code/variable declarations. Otherwise the wrong segment can be used....
#ORG controls the function's RAM allocation as well as the ROM used. You are declaring the variables, then changing the codes RAM allocation afterwards....

Honestly better to put this:
Code:

#ifdef CON_BOOTLOADER
    #include <usb_bootloader.h>
#endif


into the SAR714.h file immediately after the fuses and clock setup, but before anything else.

If you look at the example, this is where the bootloader include is loaded in this.
isgoy



Joined: 29 Mar 2012
Posts: 13
Location: Spain

View user's profile Send private message

PostPosted: Wed Jul 25, 2018 3:04 am     Reply with quote

Thank you Ttlemah.
It doesn't work.
I have to do another test like temtronic says and with your suggestion.
I will say you my conclusions.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group