XA-H4 Stack location

Question:
My system has a 128kB Flash on CS0 and 512kB RAM on CS1. According to the XA-H4 data sheet, the system stack has to be located in the first page of memory (0x0000 – 0xFFFF). Since I have flash at those addresses, where do I locate my stack.

Answer:
There are two possible solutions. The first, and easiest, solution would be to run your system with the Harvard Architecture. You would program CS0 as code space only. CS1 would be programmed as data space only. Both chip selects would be based at 0x0000. The following register values implement this approach:
B0AM = 0x00; // CS0 based at 0x0000
B0CFG = 0x89; // Code space only, 128k 8-bit Flash
B1AM = 0x00; // CS1 based at 0x0000
B1CFG = 0x4b; // Data space only, 512k 8-bit SRAM

The second, and more difficult, solution would be to copy the flash to SRAM at startup and then perform the CS0/CS1 swap function. This would leave you with 512kB of system RAM at 0x0000 that could be used for both code and data space.

For both of these methods, it is important to perform the Chip Select setup in the ‘C’ startup file before any variable initialization takes place. For the Tasking compiler, this file is called START.SRC.