Flash driver in NE64

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

Flash driver in NE64

2,754 Views
DiegoNunes
Contributor I
Hi, I'm trying to write some configuration at Flash memory, but it's not working.
I implement a version of AN2720, with DoOnStack wirtten in C and/or assembler, but it's not work.
 
I've been using ethernet feature, my PLL is 2/10, so bus clock is at 5Mhz (xtal = 25Mhz)
It's attached my source file.
 
In debug step-by-step mode it's work, but in runtime it's not.
 
It breaks in   FSTAT = FSTAT_CBEIF_MASK; from DoOnStack function
 
In main, I call:
 
Flash_Init();
Flash_Erase_Sector(0x006000); // erase 512 bytes
Flash_Write_Word(0x006000, 0x0102);
Flash_Write_Word(0x006002, 0x0304);
.......
Flash_Finish();
Labels (1)
0 Kudos
6 Replies

512 Views
kef
Specialist I
1) FDIVCLK value init value should be derived from xtal (25MHz), not from bus clock (5MHz). Your divider is too small. But your code hangs because of :
 
2) DoOnStack, as name suggests, should be executed from stack or at least from RAM. I don't see how do you copy it to RAM. Be sure it can't execute from flash block being programmed/erased.
 
0 Kudos

512 Views
DiegoNunes
Contributor I
I tryed before using:
FCLKDIV = 16 | FCLKDIV_PRDIV8_MASK;  // 25000 / 8 / (16 + 1) = 183 KHz
and DoOnStack.asm (exactly from AN2720), but it halt then bit CBEIF of FSTAT was cleared.
I'll try now copy the function to RAM (not stack).
0 Kudos

512 Views
imajeff
Contributor III
 DiegoNunes wrote:
> I'll try now copy the function to RAM (not stack).

Hi,
I hope you understood that if you are executing it on stack already, then you are executing it in RAM already. The question is, can you show how you were executing it on stack?

0 Kudos

512 Views
DiegoNunes
Contributor I
Now it works fine.
Thanks for all replies.
Below, I post my flash driver. To use it, reseve lesat 24 bytes of RAM in PRM file... In my case, I used address 0x2300 to 0x2320.
 
Diego.
0 Kudos

512 Views
JimDon
Senior Contributor III
Diego,
Very nice code.
I do have one suggestion though.

If you declare a byte array in RAM and copy it there instead, the compiler and linker will "know" about it and prevent possible overlap of ram areas in the future (long after you have forgotten about it).




0 Kudos

512 Views
kef
Specialist I


I tryed before using:
FCLKDIV = 16 | FCLKDIV_PRDIV8_MASK;  // 25000 / 8 / (16 + 1) = 183 KHz

Above is correct (provided FCLKDIV_PRDIV8_MASK is 0x40).
 


and DoOnStack.asm (exactly from AN2720), but it halt then bit CBEIF of FSTAT was cleared.

Not true. AN2720SW DoOnStack is defined in Do_On_Stack.asm file. DoOnStack function copies SpSub function from flash to RAM, then calls a copy of SpSub on stack (in RAM).
C DoOnStack routine in your file is correct, but it needs to be copied and executed in RAM.

 
0 Kudos