This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
Posted: Wed Sep 7, 2005 4:27 am
i hav trouble writting to to the page 3C with the function i obtained from the application note AN2720/D on metrework compiler.
(void)Flash_Write_Word( (unsigned int *far)(0x3CB000),0xCCDD);
The data 0xCCDD is written on the page 0x3DB000 instead of 0x3CB000.
i use the below prm file
NAMES
END
SECTIONS
RAM = READ_WRITE 0x3200 TO 0x3FFE; /* BUFMAP = 4 (1.5K) */
/* unbanked FLASH ROM */
ROM_4000 = READ_ONLY 0x4000 TO 0x7FFF; /* 16K */
ROM_C000 = READ_ONLY 0xC000 TO 0xF7FF;
/* banked FLASH ROM */
SECURITY = READ_ONLY 0xFF00 TO 0xFF0F;
ROM_FF10 = READ_ONLY 0xFF10 TO 0xFF7F;
PAGE_3D = READ_ONLY 0x3D8000 TO 0x3DBFFF;
PAGE_3C = READ_ONLY 0x3C8000 TO 0x3CBFFF;
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 */
NON_BANKED,
COPY INTO ROM_C000;
DEFAULT_ROM INTO PAGE_3C,PAGE_3D;
DEFAULT_RAM INTO RAM;
END
STACKTOP 0x3FFF
What might go wrong?
Thanks for the help.
Posted: Wed Sep 7, 2005 7:15 am
The AN2720/D title is:
"A Utility for Programming Single FLASH Array HCS12 MCUs, with Minimum RAM Overhead". You will surely have to adapt the source code to your silicon, to properly select flash blocks (if necessary) and program the correct flash page.
Regards,
Posted: Wed Sep 7, 2005 7:39 am
Now i am using the evaluation version of Metrework CodeWarrior 3.1 I am using the AN2720/D document.. I can sucessfully write to the unbanked area $4000 - $8000 and $C000 to $FFFF. i just find out i cannot concurently use the page 3C and page 3D...
PAGE_3D = READ_ONLY 0x3D8000 TO 0x3DBFFF;
PAGE_3C = READ_ONLY 0x3C8000 TO 0x3CBFFF;
if i set the prm file :
DEFAULT_ROM INTO PAGE_3C
when i try to write to page 0x3D
(void)Flash_Write_Word( (unsigned int *far)(0x3D8000),0xAAAA);
the data will be written to the page 0x3C.
Uder this setting, i have no problem to write to the page 0x3C
on the other hand if i set the prm file as below:
DEFAULT_ROM INTO PAGE_3D
when i try to write to page 0x3D
(void)Flash_Write_Word( (unsigned int *far)(0x3C8000),0xAAAA);
the data will be written to the page 0x3D .
i even try to hard code the ppage to 0x3C but it still go to page 0x3D
SpSub:
ldab $3C ; ldab SpSubEnd - SpSub+2, sp
stab PAGE
nop
nop
nop
tfr ccr, b ;get copy of ccr
orcc #$10 ;disable interrupts
staa FSTAT ;[PwO] register command
nop ;[0]
nop ;[0]
nop ;[0]
brclr FSTAT, CCIF, *
tfr b, ccr ;restore ccr and int condition
rtc ;back into DoOnStack in flash..
SpSubEnd:
Thanks..
Posted: Wed Sep 7, 2005 7:56 am
I can't see exactly what does your code. But for sure, you cannot program the flash with an application/function running from the same flash array/block. As the NE64 has one single flash array, make sure your flash handling functions are copied and executed from RAM.
Regards,
Posted: Wed Sep 7, 2005 8:09 am
I copy the code to the ram stack and executed from the ram..after the write / erase sucessfully it return back to the flash. For the code as below if i set the prm file as
DEFAULT_ROM INTO PAGE_3C;
Then the data 0xAABB and 0xCCDD will be written to page 0x3C, but i expect the data 0xAABB should go to page 0x3D instead of 0x3C.
main()
{
Flash_Init(25000); // 25MHz
(void)Flash_Write_Word( (unsigned int *far)(0x3CB002),0xCCDD);
(void)Flash_Write_Word( (unsigned int *far)(0x3DB000),0xAABB);
{
}
}
signed char Flash_Write_Word(unsigned int *far far_address, unsigned int data)
{
unsigned int* address;
address = (unsigned int*)far_address; // strip page off
FSTAT = ( FSTAT_PVIOL_MASK | FSTAT_ACCERR_MASK); //clear error
if( (unsigned int)address & 0x0001 )
{
return Flash_Odd_Access; //aligned word?
}
if(*far_address != 0xFFFF)
{
return Flash_Not_Erased; //is erased?
}
(*address) = data; //store desired data to address being programed.
FCMD = FLASH_WORD_PROGRAM; //0x20
HWD;
(void)DoOnStack(far_address); // jsut passed frp PPAGE
if (FSTAT_ACCERR )
{
return Access_Error;
}
if( FSTAT_PVIOL )
{
return Protection_Error;
}
return 1;
}
The below is my DoOnStack function.
XDEF DoOnStack
INCLUDE 'MC9S12NE64.inc'
MY_EXTENDED_RAM: SECTION
MyCode: SECTION
CBEIF EQU $80
FSTAT_TEMP EQU $105
FCMD_TEMP EQU $106
CCIF EQU $40
PAGE_ADDR EQU $30
DoOnStack:
pshb ; save B - PPAGE
ldx #SpSubEnd-2 ; point at last word to move to stack
SpmoveLoop: ldd 2, x- ; read from flash
pshd ; move onto stack
cpx #SpSub-2 ; past end?
bne SpmoveLoop ; loop till whole sub on stack
tfr sp, x ; point to sub on stack
ldaa #CBEIF ; preload mask to register command
call 0,x,00 ; execute the sub on the stack
leas SpSubEnd - SpSub, sp ; de- allocate space ussed by sub
pulb ; restore B
rtc ; to flash where DoOnStack was called
assume banked calling function
EVEN ; Make code start word aligned
SpSub:
ldab SpSubEnd - SpSub+2, sp ;get PPAGE back //testing
stab PAGE_ADDR ;Store the PPAGE address
tfr ccr, b ;get copy of ccr
orcc #$10 ;disable interrupts
staa FSTAT_TEMP ;[PwO] register
nop ;[0]
nop ;[0]
nop ;[0]
brclr FSTAT_TEMP, CCIF, * ;[rfPPP] wait for queued commands to finish
tfr b, ccr ;restore ccr and int condition
rtc ;back into DoOnStack in flash..
SpSubEnd:
Posted: Wed Sep 7, 2005 8:36 am
The .prm file setup has no relation with your programming location. What is setup in the .prm file is your project application location at download time to onchip flash.
The debugger actually programs to flash (by default, when the project is created with the Wizard) your application according to the Wizard generated .prm file. You don't even need to change the .prm file.
If now, you want that your application is able to flash some new data, you can use the AN runtimes to do so, but make sure to program to a blank location.
"(void)Flash_Write_Word( (unsigned int *far)(0x3CB002),0xCCDD);" programs 0xCCDD at location 0x3CB002, i.e. page 0x3C, address 0xB002 (flash bank window).
This place should therefore be empty.
IF you set "DEFAULT_ROM INTO PAGE_3C;", then make sure to program in page 0x3D, for example. page 0x3E is mirrored in0x4000-0x7FFF and page 0x3F is mirrored in 0xC000-0xFFFF, ranges that might be defined and used in the project/.prm for non banked code, like startup and ISR's.
Regards,
Posted: Wed Sep 7, 2005 8:57 am
I everytime make sure both the page 0x3d and page 0x3c is empty before i am
writting new data. I found out i hav banked memory problem of page 3D and page
3C. The NE64 should have 64k of flash (0x3C, 0x3D, 0x3E, 0x3F) to be used
right.. I do a testing with the following setting .I put the DEFAULT_ROM to
page 0x3C and STRINGS to page 0x3D. I go to view the memory map .I found out
actually the page 0x3D is all 0xFF the STRINGS data is not successfully written
to the page 0x3D.But The DEFAULT_ROM data is successfully go to page 0x3C.
It seem like i actually can't use the page 0x3C and page 0x3D concurrently.
The following is my prm file..
NAMES
END
SECTIONS
RAM = READ_WRITE 0x3200 TO 0x3FFE; /* BUFMAP = 4 (1.5K) */
/* unbanked FLASH ROM */
ROM_4000 = READ_ONLY 0x4000 TO 0x7FFF; /* 16K */
ROM_C000 = READ_ONLY 0xC000 TO 0xF7FF;
/* banked FLASH ROM */
SECURITY = READ_ONLY 0xFF00 TO 0xFF0F;
ROM_FF10 = READ_ONLY 0xFF10 TO 0xFF7F;
PAGE_3D = READ_ONLY 0x3D8000 TO 0x3DBFFF;
PAGE_3C = READ_ONLY 0x3C8000 TO 0x3CBFFF;
END
PLACEMENT
_PRESTART, /* Used in HIWARE format: jump to _Startup at
the code start */
STARTUP, /* startup data structures */
ROM_VAR, /* constant variables */
NON_BANKED, /* runtime routines which must not be banked */
COPY /* copy down information: how to initialize variables */
INTO ROM_C000;
STRINGS INTO PAGE_3C;
DEFAULT_ROM INTO PAGE_3D;
DEFAULT_RAM INTO RAM;
END
STACKTOP 0x3FFF
Posted: Wed Sep 7, 2005 9:55 am
The default placement is as below and places STRINGS in non banked above $C000.
If you want to locate exactly your STRINGS, I propose you to define:
ROM_STRINGS = READ_ONLY 0xC000 TO 0xCFFF;
ROM_D000 = READ_ONLY 0xD000 TO 0xFEFF;
Then replace in default .prm here below ROM_C000 by ROM_D000.
Then you can have, as placement: "STRINGS INTO ROM_STRINGS;"
Please check also the ".map" file generated in the "bin" folder of your project.
Regards,