CALL instruction not working
I'm using a PIC24EP512GP806 and I'm writing some ASM30 code in the auxiliary flash section but I'm having a lot of trouble with the CALL instruction.
Code:
CALL sub_error
BSET led_lat, #led_lat_bit
GOTO $
; Subroutine error
sub_error:
BSET led_lat, #led_lat_bit
BSET led2_lat, #led2_lat_bit
GOTO $
When this code is run from auxiliary flash, as soon as it gets to the CALL instruction, the chip appears to reset (neither LED lights up).
If I use BRA instead of CALL then it works as expected.
If I run the above code from the normal area of flash then it works.
I've confirmed it's at least getting to the CALL instruction.
Watchdog is disabled.
I believe there may be some issue with the CALL instruction handling large addresses. sub_error is located at 0x7FC10E but the Programmer's Reference Manual says it can handle 23-bit addresses.
There are no compiler errors or warnings to suggest there's anything wrong with the code. I've also checked the errata sheet for this chip and can't see anything that could cause this issue.
I've tried Googling but I can't find anything remotely useful and I'm at a loss for what to try next.
Re: CALL instruction not working
Where is your RETURN statement in the routine "sub_error"?
Re: CALL instruction not working
For the purpose of testing I just had it go into an endless loop in the subroutine.
I've just added one in after "GOTO $" to rule that out but it's still resetting.
Re: CALL instruction not working
Are you sure, that you set up correct offset?
Try to add hard coded address instead label.
As I assume that flash adr 0 is not PC adr 0. Or I missed something?
I'm also interested in your HW setup.
1 Attachment(s)
Re: CALL instruction not working
I've spent a bit of time trying to get the debugger to work. I'm using an ICD3 but the dsPIC33E/PIC24E firmware seems to be quite buggy when using it as a debugger.
It turns out that there was a bug in my custom compiler that was setting __SP_init and __SPLIM_init to 0. The PIC was correctly erroring because of a stack overflow.
I've fixed the bug and it's all working now!
@pedja089
The main flash and auxiliary flash are both in the same flash space with the auxiliary section starting at 0x7FC000.
The PC accesses both areas as if they are just 1 big area of flash so PC 0 would always be the start of the main flash.
For the hardware, I'm using a custom PCB with the PIC24EP512GP806, an ENC28J60 with an RJ45 socket and a bunch of headers.
It's currently plugged into a breadboard which gives me 2 LEDs that I've been using to "debug" the code
I've uploaded a picture of the board if you're interested
Attachment 9016
Re: CALL instruction not working
I assume that you had PIC18 connected with external flash.
I totally missed your first sentence in first post. Sorry about that.