S12XDP512 non-banked FLASH

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

S12XDP512 non-banked FLASH

4,204 Views
K_p
Contributor I
Hi

I have had some trouble to write data to FLASH. The destination of catched data is in ROM_4000 and it lies in non-banked area. The fuctions that i use to write data works fine, if I use paged Flash. But this memory are is not good if I want to make bootloader for this device. I really don't know where to find answers to this problem.

I'm using CW for HC12 V4.6 and P&E Micro USB multilink.

the writer function looks like:

UBYTE PerformWriteWord(UDWORD Addr,UWORD Data)
{
     UBYTE err;
     getCCR_disI();                                  // Save CCR, disable interrupts
     FSTAT = 48;                                      // Clear PVIOL & ACERR flag


     if (FSTAT_CBEIF == 0){restoreCCR();return ERR_BUSY;} // Is command buffer full ?
     *(UWORD *far) Addr = Data;                       // Array address and program data
     FCMD = 0x20;                                     // Word program command
     FSTAT = 0x80;                                    // Clear flag command buffer empty
     asm CLRB;                                        // Jump to Wait in RAM code
     asm JSR WaitForFlash;
     asm STAB err;

     restoreCCR();                                    // Restore CCR
     if (err) return ERR_NOTAVAIL;                    // if error return error code
     if (*(UWORD *far) Addr != Data) return ERR_VALUE;// Check written data
     return ERR_OK;
}

some hints would be nice

Juha-Matti
Labels (1)
0 Kudos
8 Replies

1,227 Views
mke_et
Contributor IV
Kef is right. You have to EXECUTE from RAM, not go to it after you start. What some people don't realize is that once you start putting the FLASH into programming mode, the buffers for the ENTIRE BANK turn off for data access. That means you can't fetch the next opcode from the flash to decode and execute. So, either write your code so it executes from a page in another bank, or execute from RAM.

Also, remember that EVERYTHING in that bank goes away. That means Interrupt vectors as well if they sit in the same bank, as soon as ANY page in that bank changes to command mode.

One other thing... It can help sometimes to think 'generically', and not try to think of some flash as 'special' because it's in a special address. In my code, I always move the flash into the 'sliding window' to program it. It may not matter if there's only one area of flash you are trying to program, but it can help if you are programming multiple areas of your flash. Having one 'mindset' in how you write your program also helps to keep you head straight when you debug it to find wierd problems.

Mike

Message Edited by mke_et on 2008-01-15 09:05 AM
0 Kudos

1,227 Views
K_p
Contributor I
Hi

I relocated the executable code in EEPROM (0xc00), so it won't be affected FLASH routines. And still the data won't be stored in desired destonation in FLASH (0x4000 or 0xC000). I think this might have something to do with paged and non-banked configs. Because it still stores data in address 0xffbdd0 and it lies in paged area.

I debug writing by resbonding after wrtiting with CAN message which includes previously received data. When I use 0x4000 or 0xc000 address, the responding doesn't occur. But when I use that paged area, then theres no poroblem. So something funny occurs, when program tries to write non-banked area, and the program doesn't crash. I can stop/run executin normally in truetime debugger.

I'm still some kind of newbie in these things, but even my co-workers weren't able to help me.

Juha-Matti
0 Kudos

1,227 Views
kef
Specialist I
     *(UWORD *far) Addr = Data;                       // Array address and program data
Do you pass 0x4000 and 0xC000 in Addr and then cast it to (UWORD *far) ? Isn't it casted to global 0x4000 which points to the RAM?
 
Could you resolve all missing typedefs like UWORD and post compilable routine here, along with missing WaitForFlash routine? We could fix it then..
0 Kudos

1,227 Views
K_p
Contributor I

The addres which I give the write function is UWORD and its given as it shows (0x4000 or 0xC000), should there be a some kind of conversion? I used some kind of converter, which is used at Paged addres flash, but it screwed the writing addres big time, so after conversion it pointed at 0x0000.

I dont't know what you mean with post compilable routines, but compiler command line arguments are:

-CPUHCS12X -D_FAR_DATA_NO_FLOAT__ -Lasm=%n.lst -Mb

defines:

#define     UBYTE       unsigned char
#define     SBYTE                char
#define     UWORD       unsigned  int
#define     SWORD                 int
#define     UDWORD      unsigned  long int
#define     SDWORD                long int

wait 4 flash:

static UBYTE WaitForFlash[]=
{
 0x1E, 0x01, 0x05, 0x20, 0x05,                    // BRSET _FSTAT,#32,*+10
 0x1F, 0x01, 0x05, 0x10, 0x03,                    // BRCLR _FSTAT,#16,*+8
 0xC6, 0x09,                                      // LDAB  #9
 0x3D,                                            // RTS
 0x1F, 0x01, 0x05, 0x40, 0xFB,                    // BRCLR _FSTAT,#64,*+0
 0x3D                                             // RTS
};


0 Kudos

1,227 Views
K_p
Contributor I
Some progress is made, I took away *far , from typecasting. And after that seems the FLAS-writing works fine. It seems that when you hit your head into wall long enough, after a while you finaly get through :smileyhappy:. I hope this will solve my problems.

Thanks for tips, I hope those will give some hints in future.
0 Kudos

1,227 Views
kef
Specialist I
I see "//Jump to Wait in RAM code" comment in your code. That's good, flash is not readable while it's being programmed. But flashing procedure starts a little sooner than you jump to RAM, when you clear CBEIF flag:
 
   FSTAT = 0x80;
 
You should move this ^^ "clear CBEIF" code to your wait in RAM routine and not return from there while CCIF is cleared.
 
It could work in banked mode because S12X has several banks. You can run and read one bank while programming another bank.
0 Kudos

1,227 Views
K_p
Contributor I
Thanks for fast reply

But I think that's not the problem. I moved clear CBEIF into RAM toutine, but didn't do the trick.

And I forgot to tell that i'm not copying memory to memory, i'm copying CAN-messages Datafield to FLASH. by byte by byte. In these testing I only use DLC 1 to make sure theres no change to make extra errors.

Juha-Matti
0 Kudos

1,227 Views
kef
Specialist I

Flash programming routine must execute from RAM ( or EEPROM or another FLASH bank).  CPU can't read or execute from flash bank being programmed. As soon as you write a one to CBEIF flag, flash programming starts, and CPU stops being able  to read data and also execute code from bank you pointed your programming routine to. CPU will be able to read flash and execute from it after flash module sets CCIF flag, So you must run somewhere else (for example in RAM) from FSTAT=0x80 to CCIF==1.

It doesn't matter what is your data source. CPU hangs when you try to execute code being in the same bank, you are trying to program a part of.

0 Kudos