I am trying to write some code in C to do a mass erase and program of the flash for a 9S12X.
I have declared a pointer to the flash:
typedef uint16_t * far Flash_TAddress;
During the process I increment this address to point to the next block. The Code W\rrior compiler treats it as a 14-bit effective address, so when I try to add 0x4000 to it it effectively adds 0 and produces no code. This is presumable becuse it teats the address as an effective address used with the PPAGE register.
I have done some experiments to see what code the compiler produces, and it seems to use a mixture of GPAGE and PPAGE, as shown in the following snippet:
static uint32_t * far dq;
dq = (Flash_TAddress)0xE0;
*dq = 12;
dq = dq + 0x4000L;
*dq = 23;
The compiler assembly output for this is:
228: dq = (Flash_TAddress)0xE0;
0001 c6e0 [1] LDAB #224
0003 87 [1] CLRA
0004 7c0000 [3] STD dq:1
0007 7a0000 [3] STAA dq
229:
230: *dq = 12;
000a fe0000 [3] LDX dq:1
000d f60000 [3] LDAB dq
0010 5b10 [2] STAB /*GPAGE*/16
0012 c7 [1] CLRB
0013 186c00 [3] GSTD 0,X
0016 c60c [1] LDAB #12
0018 186c02 [3] GSTD 2,X
231:
232: dq = dq + 0x4000L;
233:
234: *dq = 23;
001b c7 [1] CLRB
001c 186c00 [3] GSTD 0,X
001f c617 [1] LDAB #23
0021 186c02 [3] GSTD 2,X
So it uses GPAGE for assigning the pointer and storing the 12, but assumes PPAGE when I add 0x4000 to it.
How do I get the compiler o incremement the address and automatically increment PPAGE, or can I not do this? If not, how do I do what I am trying to do, i.e. erase the flash?
The compiler version is Code WArrior of rS12X version 4.7, with command line compiler chc12 version 5.0.35 build 8093.
Thanks