The USB module in the PIC18F14K50 requires that all USB related data be put in RAM at addresses between 0x200 and 0x2FF. I've written a light-weight USB stack before, but I ended up using SDCC's absolute addressing syntax of:
Obviously, specifying the address of every variable related to USB is pretty clunky. Instead, I would like to tell the compiler which databank to put those variables in and let the linker do its job.
In the SDCC manual, on page 73, it shows an example of doing this. However, I haven't gotten it to successfully work. Here's my modified linker script. All I changed was adding the "SECTION" line at the bottom.
And here's my basic program using the pragma syntax from the SDCC manual.
Code:
void main()
{
#pragma udata bank2 a
unsigned char a;
unsigned char* pa = &a;
print16bitVal((int)pa);
while(1);
}
It appears the #pragma isn't doing anything. Based on the printed value of (int)pa, the location of "a" appears to be in gpr0 with or without the #pragma. Incidentally, if I specify the absolute address using the __at command, then printing (int)pa gives me the correct value. So I know my pointers and print statement are working. Any ideas what I'm doing wrong?
misterT,
Clever workaround. I did end up figuring out the problem, though. I was trying to instantiate the variable as local to main(). For the variable to be located in the gpr2 databank, I needed to make it a global. Once I moved the instantiation outside of main(), it worked fine.
Ian Rogers,
I've actually done a lot of projects lately using the pic16 port on SDCC and haven't run into any real problems yet. Specifically, I wrote a USB stack (the project I'm improving on right now, actually) and a mini TCP/IP stack. Both pretty complex programs. What kind of instabilities have you encountered? Maybe I'm just not noticing them.
The web site tells me its unstable.... I'd love to start using SDCC for pic's.... As you are experiencing few problems I may start using it..... It has always done me well for the MCS51 port.
misterT,
Clever workaround. I did end up figuring out the problem, though. I was trying to instantiate the variable as local to main(). For the variable to be located in the gpr2 databank, I needed to make it a global. Once I moved the instantiation outside of main(), it worked fine.
Good if you got it working. It is better to let the compiler (linker) place the variable in the right memory location. That way the memory is actually allocated for the variables. My way just writes to an unallocated memory.. there is a risk that the compiler places other variables to the same memory location.