Erase flash memory in 3 blocks.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Erase flash memory in 3 blocks.

5,880 Views
hdan
Contributor III
Hello,
I had to erase and program flash memory in 3 blocks.
I use an 9s12DP256 with code warrior 3.1 in C.
I begin with HCS12 and never use a controler with more than 4K of flash.


I read the AN 2720 and make a program. I can erase flash in four paged memory of the same block.
tested on one sector at @0x3CD000,@0x3DD000,@0x3ED000,@0x3FD000 .

What we have to do to tune the code of AN2720 to access at the adress @0x30D000, @0x31D000...

someone have done this?

Thanks for the help.
Labels (1)
0 Kudos
Reply
9 Replies

2,194 Views
hdan
Contributor III
Hello


i have done a mistake.

i have witten:it works.(at the adresse 0x3?D000)

and it works but at the addr 0x3?8000.

Sorry !
0 Kudos
Reply

2,194 Views
hdan
Contributor III
hello,


In the main, I use :

Flash_Init(16000); //osc freq

rval=Flash_Erase_Sector((unsigned int *__far)0x3CD000); // ok block0
rval=Flash_Erase_Sector((unsigned int *__far)0x3FD000); // ok rval=1

rval=Flash_Erase_Sector((unsigned int* __far)0x38D000); //no ok block1
rval=Flash_Erase_Sector((unsigned int* __far)0x3BD000); //no ok rval=253 : FSTAT_ACCERR = 1

rval=Flash_Erase_Sector((unsigned int* __far)0x34D000); //no ok block2
rval=Flash_Erase_Sector((unsigned int* __far)0x37D000); //no ok rval=253 : FSTAT_ACCERR = 1

rval=Flash_Erase_Sector((unsigned int* __far)0x30D000); //no ok block3
rval=Flash_Erase_Sector((unsigned int* __far)0x33D000); //no ok rval=253 : FSTAT_ACCERR = 1

I put result in comment.
my programm is at 0x3080XX.


Thanks for your response.
0 Kudos
Reply

2,194 Views
Sten
Contributor IV

The addresses 3?D000 do all access page 3F because the address D000 is in the unpaged area C000..FFFF which corresponds to page 3F. The page 3E can be accessed in the unpaged area at 4000..7fff; all other pages must be accessed through the page window at 8000..BFFF (the pages 3E and 3F can be accessed also trough this window). This means that you will get the access-error because the address you are writing to is in block 0 but the block selector bits in FCNFG points to some other block.

Try changing your long addresses to 3?9000 instead of 3?D000, and everything should work.

0 Kudos
Reply

2,194 Views
hdan
Contributor III
Very good,

it works.(at the adresse 0x3?D000)

I understand better now the flash memory map of the TFS256K block user guide.

thanks,
0 Kudos
Reply

2,194 Views
imajeff
Contributor III
hdan,

I'm concerned by reading your post, not sure if you know that 0x3?D000 is not valid. What you are addressing there is 0xD000, which is also the banked location 0x3f9000

Edited (was bank 3F not 3E)

Message Edited by imajeff on 2006-07-06 07:52 AM

0 Kudos
Reply

2,194 Views
hdan
Contributor III
Hello,

No one have an idea?
a sample code?
something to help me to programm flash in more than one block.

thanks.
0 Kudos
Reply

2,194 Views
Sten
Contributor IV

I haven't tested it, but it looks like your code should work. Note that the Flash_Erase_Sector function erases only one 512 byte sector (in one of the four 64 kbyte Flash banks). If you want to erase a complete 64 kb block you must call the function 128 times (or you could use the Mass Erase command (FCMD = 0x41)).

Which block (and sector) to erase is selected with the far address in the call to the function: Block 0 consists of pages 3C..3F, block 1 = 38..3B, block 2 = 34..37 and block 3 = pages 30..33. So to erase the first sector of block 3 you should call the function with address 0x308000. The next 512 byte sector starts at 0x308200, a.s.o. up to the last sector of page 0x30 that starts at 0x30BE00. Then continue with page 31, 32 and 33 and the block 3 should be erased.

0 Kudos
Reply

2,194 Views
hdan
Contributor III
Hello,

You're right.

my code (found somewhere) is :

signed char Flash_Erase_Sector(unsigned int *__far far_address)
{
unsigned int* address;
unsigned char i;
address = (unsigned int*)far_address;

for(i=0;i4;i++) {
FCNFG = i;
FSTAT = (FSTAT_ACCERR_MASK | FSTAT_PVIOL_MASK); // clear errors all banks
} /* */
if ((unsigned long)far_address >= 0x10000)
{
FCNFG = (unsigned char)((63-((unsigned long)far_address >> 16)) / 4);
}
else
{
FCNFG = 0x00;
}
FSTAT = (FSTAT_ACCERR | FSTAT_PVIOL); // clear errors
(*far_address) = 0xFFFF; /* Dummy store to page to be erased */

FCMD=0x40;
(void)DoOnStack(far_address);
if (FSTAT_ACCERR) {return Access_Error;}
if (FSTAT_PVIOL) {return Protection_Error;}
return 1;
}

And I can select 1 of the 4 banks of the block.
But what to do for the other block?

Thanks,
0 Kudos
Reply

2,194 Views
Lundin
Senior Contributor IV
Correct me if I'm wrong, but the code is that app note doesn't seem to have support for flash banks. I have looked through it and I can't see where they are writing to BKSEL the FCNFG register. So it will only work for bank 0..? It would be sort of strange since they brag about DP256 and it's many banks on the first page.

You need to select the correct bank in FCNFG before programming the flash.
0 Kudos
Reply