|
|
View previous topic :: View next topic |
Author |
Message |
spilz
Joined: 30 Jan 2012 Posts: 219
|
|
Posted: Fri Dec 09, 2016 3:49 pm |
|
|
I'm not sure to understand what do you refer about PCM_programmer method.
My modification is only like adding my own board to usb_common file. it's only to build the bootloader, and being as close as possible to the original CCS USB Bootloader to facilitate trade in the forum, and delete possible issue of a modify bootloader.
For my program I'm doing like PCM_programmer I guess, or I misunderstand what you said.
I learn lot of thing with your help Ttelmah, thank for that. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
Posted: Fri Dec 09, 2016 7:37 pm |
|
|
Has anyone thought to try this?:
- load PIC using the two different methods, bootloader (faulty) and bootloader + program burned into PIC at same time
- use programmer to read contents of PIC to file for each method
- do a file compare |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 09, 2016 8:36 pm |
|
|
Yes I have done this. I compared two versions, one with
and the other with:
There are only two lines different between them.
if(delta >= 7) gives this:
Code: |
SUBLW 0x6
BC 0x212a
|
if(delta == 7) gives this:
Code: | SUBLW 0x7
BNZ 0x212a |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Sat Dec 10, 2016 3:06 am |
|
|
spilz wrote: | I'm not sure to understand what do you refer about PCM_programmer method.
My modification is only like adding my own board to usb_common file. it's only to build the bootloader, and being as close as possible to the original CCS USB Bootloader to facilitate trade in the forum, and delete possible issue of a modify bootloader.
For my program I'm doing like PCM_programmer I guess, or I misunderstand what you said.
I learn lot of thing with your help Ttelmah, thank for that. |
The point is that PCM_programmer's example, can be loaded and compiled 'as it stands'. No modification of files needed.
You are misunderstanding slightly what the files actually 'are'. There are drivers and code like the bootloader, and then there are 'examples'. The examples, are setup to run with specific hardware, to demonstrate how to use things. Now the problem is that you are taking an 'example' file (this is what the 'ex' means), and then tweaking this for your hardware, and not to run the example code. Now there are things in this that are specific to the example (the LED's for instance, are setup to drive the LED's on the example board). It means that we have to guess what hardware you actually have, and try to match the effect of your tweaks.
The 'example' files are designed for specific hardware. To run something different on your hardware, you should have either your own equivalent header file, or just include the lines into your code.
One of the old 'suggestions' here, has always been that when posting code, you should make it so we can load the code 'as posted', and test what happens. PCM_programmer's code is like this. You can compile it _as posted_ no tweaking of other files. That way we know that what we are compiling matches what he is compiling.
It's also 'pointless'. By trying to include your chip's settings into a CCS file, you increase the risk of something unexpected happening.
In this case, this is not the problem (since PCM_programmer has now posted simplified code showing the fault), but you are creating extra complexity, that makes it harder for us, and for _you_ to actually diagnose what is happening.... |
|
|
spilz
Joined: 30 Jan 2012 Posts: 219
|
|
Posted: Sat Dec 10, 2016 3:16 am |
|
|
Oh I see,
I was thinking that this small modification was simpler than giving all the code. My idea was : if you have the demo board, you don't need to modify the file, and can try directly.
I understand now, i will be careful about that next time I post a code.
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Sat Dec 10, 2016 4:21 am |
|
|
I suspect it is related to RAM bank switching.
I notice that the interrupt code always places it's reserved variables in the low memory.
With the array declared, the timer variables are sitting in bank 4.
When the array is smaller than about 220, the timer variables are in bank 0.
Now the code seems to have the correct bank switches present, so possibly something in the interrupt handler (looking now). #locating the array, means the timer variables can again be located in bank 0. Declaring the array after the timer variables has the same effect and also fixes the problem.
Accessing 'Seconds_flag', forces a bank switch.
The bank switching code is identical in chips compiled for address 0 builds, or 0x2000. I'm suspecting something in the bootloader interrupt relocation.
A look shows what is wrong.
At some point, the interrupt relocation in the USB bootloader, has been incorrectly modified.
It should read:
Code: |
#int_global
void isr(void)
{
jump_to_isr(APPLICATION_ISR);
}
|
It's been set to 'int_default'.....
Now this means that it is not correctly being programmed to relocate the interrupt handler. Won't show if your code doesn't use interrupts, and my own USB bootloader, had my own relocation code that handles this correctly.
So try this one change.
What causes the problem is that there is a double save and then 'half restore', this clears the BSR, as well as wasting time...
Ugh.
I have already posted details to CCS. |
|
|
spilz
Joined: 30 Jan 2012 Posts: 219
|
|
Posted: Sat Dec 10, 2016 9:40 am |
|
|
That seems to solve lot of thing !!
It seems the usb bootloader has an error.
Good job !!!
I'm not sure to understand all, does it change/solve bank stuff ?
Let see if PCM_programmer find something else.
Thanks again both for time spend on my question. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Sat Dec 10, 2016 10:09 am |
|
|
What happens is a bit complex.
#int_global, makes the code become the 'master' handler, without any save/restore.
#int_default, makes the code save all the registers then be called.
Now remember that the code already placed in the upper bank, saves and restores everything.
With #int_global, the hardware saves the W reg, BSR and status, then the code immediately jumps to the code in the upper bank, this then saves everything else, executes the handler, then restores everything and returns, and the return restores the W, BSR & status. What is wanted.
With #int_default, the code in the low memory saves everything, then _calls_ this as the interrupt handler, which then jumps to the upper handler. This call also updates the 'shadow registers, then saves the other registers again. Then jumps to the handler. Problem then is that the upper handler then uses RETFIE1 to return to the low handler. This restores the W, BSR & status back to the value from the low handler, and returns to the handler in the low memory. This calls RETFIE1 _again_. Since the shadow registers were updated by the call from #int_default, the W, BSR and status may have then been damaged. Problem.... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 11, 2016 12:02 am |
|
|
Thank you for solving this, Ttelmah. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Sun Dec 11, 2016 2:10 am |
|
|
Your simplified version was what allowed me to track what was happening.
I felt right at the start that it sounded like a BSR problem. This was why much earlier on in the thread, I asked what happened if the array was declared after the timer variables, but this was not tested.
With your version, the first thing was that the code was small enough, and 'complete', allowing me to take the time and make sure that it was correctly being 'relocated' at 2000. Compiled it both at address zero, and relocated, then compared the assembler and checked everything was OK. It was. This then pointed to the problem being in the bootloader, and (of course), except for a slight delay at initialisation, and some registers being changed, the only thing that entered the equation when the bootloader was used, was the interrupt relocation. A look at this code gave the 'ah ha' moment!... I then made a 'combined' file of bootloader and code, and (since USB is not used in the 'normal boot' path), could run this up in the simulator and see what actually happened. Team 'CCS users'. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Thu Dec 22, 2016 4:00 pm |
|
|
Just for information, this has now been fixed in compiler version 5.066. |
|
|
|
|
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
|