Forums

Banked EEPROM/RAM with 68HC12A4 & Codewarrior

Started by levijunkert August 22, 2005
Hardware/Software Preface: Currently we are using an Axiom CMD12-Rev
A development board (HC12A4 with Expanded Wide Memory). This board
has 64K external EEPROM and 512k external RAM (we added in the RAM our
selves). This memory runs in a 16bit wide data bus. That means that
there are two chips for EEPROM (2x32k) and RAM (2x256k). We are using
Metroworks Codewarrior IDE version 5.5.1272 and Metroworks Codewarrior
V3.1. We are also using a P&E Multilink USB BDM. We have both a
revision A and many revision B's.

The Problem: We are trying to load our code and data into banked
memory using our hardware and software listed above. Currently we
have a small program that blinks an LED on and off every second. This
code is listed below:

*****************************************************************************

#include <hidef.h> /* common defines and macros */
#include <mc68hc812a4.h> /* derivative information */

#define TOBOOL(x) (!(!(x)))
#define BitSet(arg, posn) ((arg) |= (1L << (posn)))
#define BitClr(arg, posn) ((arg) &= (~(1L << (posn))))
#define BitFlp(arg, posn) ((arg) ^= (1L << (posn)))
#define BitTst(arg, posn) TOBOOL((arg) & (1L << (posn)))

#pragma LINK_INFO DERIVATIVE "hc12a4"

int counter;

void main(void) {
char garbage[6] = "blah\r\n";

/* Initialize the timer overflow interrupt */
BitSet(TSCR, 7); /* Enable Timer */
BitSet(TMSK2, 7); /* Enable Timer Overflow Interrupt */
counter = 0;

/* Set LED low to turn on by default */
BitSet(DDRJ, 1);
BitClr(PORTJ, 1);

EnableInterrupts;
while(1) {} /* wait forever */
}

/* 8Mhz clock causes interrupt about every 8-9ms */
#pragma CODE_SEG NON_BANKED
interrupt void TimerOverflow(void)
{
counter++;

/* Reset counter */
if(counter >= 125){
counter = 0;
if(!BitTst(PORTJ, 1))
BitSet(PORTJ, 1);
else
BitClr(PORTJ, 1);
}

/* Reset the timer overflow flag */
BitSet(TFLG2, 7);
TCNT = 0x0000;
}
#pragma CODE_SEG DEFAULT

****************************************************************************

If we remove the CODE_SEG pragma, use a normal linker file, and load
in small mode (using onboard EEPROM and RAM) this LED code above works
fine. But when we try to load it using Banked mode we get random
errors from the loader and debugger. Below is a list of what we have
tried and what errors we get:

1. Failed to get communications speed.
2. Restart BDM by unplugging it and reset dev board by power cycling.
3. Loads fine, but when clicking "Start/Continue Program" the debugger
goes off into "space" and is lost. When clicking "Halt" the
"Procedure/Data:1/Data:2/Source" windows all become blank. It seems
that we have lost where the program is running on the chip. Also
while its running the LED is not blinking.
4. Restart BDM/Dev hardware again and try to reload by closing the
True-Time Simulator & Real-Time Debugger and restarting it from inside
Codewarrior.
5. Seems to load fine again, but still no LED and the debugger gets
lost if we hit "Halt".

Below is our linker file that we have built. We are using the default
Start12.c that came with Codewarrior to start the initialization of
the software on the chip. We are currently going through this file
and reading/dissecting how it works. We are not sure where to go from
here and have been stuck here for about a week. Any help would be
greatly appreciated.

Here is our linker file:
****************************************************************************

NAMES END

SEGMENTS
//EPAGE_RAM = READ_WRITE 0x0400 TO 0x07FF;
INT_RAM = READ_WRITE 0x0800 TO 0x0BFF;

EEPROM = READ_ONLY 0x1000 TO 0x1FFF; // for expanded mode

RAM_PAGE_0 = READ_WRITE 0x307000 TO 0x307FFF;
RAM_PAGE_1 = READ_WRITE 0x317000 TO 0x317FFF;
RAM_PAGE_2 = READ_WRITE 0x327000 TO 0x327FFF;
RAM_PAGE_3 = READ_WRITE 0x337000 TO 0x337FFF;
RAM_PAGE_4 = READ_WRITE 0x347000 TO 0x347FFF;
RAM_PAGE_5 = READ_WRITE 0x357000 TO 0x357FFF;
RAM_PAGE_6 = READ_WRITE 0x367000 TO 0x367FFF;
RAM_PAGE_7 = READ_WRITE 0x377000 TO 0x377FFF;
RAM_PAGE_8 = READ_WRITE 0x387000 TO 0x387FFF;
RAM_PAGE_9 = READ_WRITE 0x397000 TO 0x397FFF;
RAM_PAGE_A = READ_WRITE 0x3A7000 TO 0x3A7FFF;
RAM_PAGE_B = READ_WRITE 0x3B7000 TO 0x3B7FFF;
RAM_PAGE_C = READ_WRITE 0x3C7000 TO 0x3C7FFF;
RAM_PAGE_D = READ_WRITE 0x3D7000 TO 0x3D7FFF;

/* banked FLASH ROM each is 16k here is 16 but there is 256*/
PAGE_30 = READ_ONLY 0x108000 TO 0x10BFFF;
PAGE_31 = READ_ONLY 0x118000 TO 0x11BFFF;
PAGE_32 = READ_ONLY 0x128000 TO 0x12BFFF;
PAGE_33 = READ_ONLY 0x138000 TO 0x13BFFF;
PAGE_34 = READ_ONLY 0x148000 TO 0x14BFFF;
PAGE_35 = READ_ONLY 0x158000 TO 0x15BFFF;
PAGE_36 = READ_ONLY 0x168000 TO 0x16BFFF;
PAGE_37 = READ_ONLY 0x178000 TO 0x17BFFF;
PAGE_38 = READ_ONLY 0x188000 TO 0x18BFFF;
PAGE_39 = READ_ONLY 0x198000 TO 0x19BFFF;
PAGE_3A = READ_ONLY 0x1A8000 TO 0x1ABFFF;
PAGE_3B = READ_ONLY 0x1B8000 TO 0x1BBFFF;
PAGE_3C = READ_ONLY 0x1C8000 TO 0x1CBFFF;
PAGE_3D = READ_ONLY 0x1D8000 TO 0x1DBFFF;

END PLACEMENT

_PRESTART, /* Used in HIWARE format: jump to
_Startup at the code start */
STARTUP, /* startup data structures */
ROM_VAR, /* constant variables */
STRINGS, /* string literals */
VIRTUAL_TABLE_SEGMENT, /* C++ virtual table segment */
NON_BANKED, /* runtime routines which must not be
banked */
COPY, /* copy down information: how to
initialize variables */
/* in case you want to use ROM_4000
here as well, make sure
that all files (incl. library
files) are compiled with the
option: -OnB=b */
INTO EEPROM;

DEFAULT_ROM INTO
PAGE_30,PAGE_31,PAGE_32/*,PAGE_33 */,PAGE_34,PAGE_35,PAGE_36,PAGE_37,

PAGE_38,PAGE_39,PAGE_3A,PAGE_3B,PAGE_3C,PAGE_3D;

CodeForcedToPPage33 INTO PAGE_33;

DEFAULT_RAM INTO INT_RAM;

RAM_PAGES INTO
RAM_PAGE_0, RAM_PAGE_1,RAM_PAGE_2,RAM_PAGE_3,RAM_PAGE_4,RAM_PAGE_5,
RAM_PAGE_6,RAM_PAGE_7,RAM_PAGE_8,RAM_PAGE_9,RAM_PAGE_A,RAM_PAGE_B,
RAM_PAGE_C,RAM_PAGE_D; END

STACKSIZE 0x100

VECTOR 0 _Startup
VECTOR ADDRESS 0xFFDE TimerOverflow

****************************************************************************