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 CCS Technical Support

Bootloaded firmware has missing instructions at ISR [Solved]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

Bootloaded firmware has missing instructions at ISR [Solved]
PostPosted: Thu Aug 11, 2022 3:23 pm     Reply with quote

I created an USB bootloader for a PIC18F67J50 and it works ok but a couple of instructions are missing on the compilation of the bootloaded program and seems to affect the USB port of the main (bootloaded) program.

Here a couple of pictures to compare the same program compiled to start at 0x0000 and the bootloaded version that start at 0x3000.







I'm using this to redirect the ISR

Code:

#define LOADER_END 0x2FFF
#int_global
void isr()
{
   jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}


The ISR vectors created on the bootloader firmware seems to be OK.



Why the ISR vector is so different between the normal 0x0000 and the 0x3000 bootloaded version of the same firmware?

What I'm doing wrong or missing?
_________________
Electric Blue


Last edited by E_Blue on Fri Aug 12, 2022 11:19 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Aug 11, 2022 10:39 pm     Reply with quote

Post the build line used for the bootloaded program.
It is this that sets up how the ISR is created in this program, not the
bootloader.

The bytes at 4 though do nothing. They are just unused garbage. The
interrupts jump to address 8 or 18 on a PIC18. Not 4.

0000 boot vector
0008 high priority/default interrupt
0018 low priority interrupt if priorities are enabled

What is wrong with the USB?. How are your fuses/clock set in the bootloader
and main program?.
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Fri Aug 12, 2022 7:07 am     Reply with quote

Are you talking about this?

Code:

#include<18F67J50.h>
#fuses none

#define BOOTLOADER_AT_START 0x3000
#define LOADER_END 0x2FFF
#include <bootloader.h>


Fuses in the USB bootloader are this.


Code:
#include <18F67J50.h>
#fuses INTRC_PLL,PLL2,NOCPUDIV,NOIESO,NOFCMEN,STVREN,CCP2E7,NOWDT,WDT2048,PROTECT //WDT8Seg. No crystal

#use delay(clock=48M)
#use fast_io(ALL)

#define _BOOTLOADER
#define LOADER_END 0x2FFF
#define MaxRom 65532
#include <bootloader.h>

The USB starts ok and start to be every second more "clumsy" and slow until the desktop app get halted.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Fri Aug 12, 2022 9:56 am     Reply with quote

This part:
Code:

#include<18F67J50.h>
#fuses none
#use delay(clock=48M) //must have this

#define BOOTLOADER_AT_START 0x3000
#define LOADER_END 0x2FFF
#include <bootloader.h>


Compiled code always needs a clock statement. Otherwise any delays in
the code will/may have the wrong values coded in them.
This may be what is making the USB code hiccup. The delays may be
excessive.
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Fri Aug 12, 2022 10:31 am     Reply with quote

It works! Thank you a lot! 🙏

You just saved me.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Fri Aug 12, 2022 10:56 am     Reply with quote

That makes total sense. I'd have to compile and test to see what the
default clock value is if you don't specify. Either too slow (so the delays
are shorter than needed), or too fast so delays are longer.
Definitely a 'FYI' one!...

Glad it worked. Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Sat Aug 13, 2022 6:08 am     Reply with quote

I thought I'd test and see what the compiler does without a clock statement.
I'm actually amazed it does compile. Everything I tried had it complaining,
unless the clock was specified.
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Mon Sep 12, 2022 8:09 pm     Reply with quote

That's not all, the compiled code without clock definition runs ok the UART at 115200 as expected, but not the USB module. I don't know how the UART library solve it and the USB library don't.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Tue Sep 13, 2022 3:36 am     Reply with quote

Your code must be getting a clock statement from somewhere. UART setup
calls all fail if they don't have a clock statement.
Possibly getting it somewhere after the USB library is loaded....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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