View previous topic :: View next topic |
Author |
Message |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
Bootloaded firmware has missing instructions at ISR [Solved] |
Posted: Thu Aug 11, 2022 3:23 pm |
|
|
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
|
|
Posted: Thu Aug 11, 2022 10:39 pm |
|
|
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
|
|
Posted: Fri Aug 12, 2022 7:07 am |
|
|
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
|
|
Posted: Fri Aug 12, 2022 9:56 am |
|
|
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
|
|
Posted: Fri Aug 12, 2022 10:31 am |
|
|
It works! Thank you a lot! 🙏
You just saved me. _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Aug 12, 2022 10:56 am |
|
|
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. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Aug 13, 2022 6:08 am |
|
|
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
|
|
Posted: Mon Sep 12, 2022 8:09 pm |
|
|
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
|
|
Posted: Tue Sep 13, 2022 3:36 am |
|
|
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.... |
|
|
|