cancel
Showing results for 
Search instead for 
Did you mean: 

Copy code to SRAM

skubit
Associate II
Posted on October 18, 2004 at 11:24

Copy code to SRAM

5 REPLIES 5
skubit
Associate II
Posted on May 17, 2011 at 12:03

Hi,All!

I want to write a boot loader that can read and write into to two flash.

So I want to copy my boot loader from secondary flash (where I start execution) to SRAM.

I don’t want to jump execution to main flash because I don’t want to copy flash access code into to main program.

But when I set the VM register to 0xA (access secondary flash with RD,WR and PSEN), my my program execution stop!! So I can’t read my flash.

And if I configure, in PSD soft, the seconday flash to ‘Both Program and data space’, the code don’t start.

How can I copy my code from seconday flash to SRAM.

Do you have exemple to copy code from flash to SRAM.

Configuration : UPSD 3333D

Mapping :

Rs0 : 0 – 1FFF

Csiop : 2000 – 20FF

Fs0 : 0 - 3fff and bk0, 8000 – bfff

FS1 – fs8 : bk1-8 and 8000 – bfff

Csboot0 : 0 – 1fff and 8000 – 9fff

Csboot1 : a000 – bfff

Csboot2 : c000 – dfff

Csboot3 : e000 – ffff

Thanks!

lwang
Associate II
Posted on May 17, 2011 at 12:03

You said:

''...

Fs0 : 0 - 3fff and bk0, 8000 – bfff

FS1 – fs8 : bk1-8 and 8000 – bfff

Csboot0 : 0 – 1fff and 8000 – 9fff

...''

I think you actually mean:

''...

Fs0 : 0 - 3fff OR bk0, 8000 – bfff

FS1 – fs8 : bk1-8 OR 8000 – bfff

Csboot0 : 0 – 1fff OR 8000 – 9fff

...''

Am I correct?

Before you change VM to 0xA, what was its value? (Set up by PSDsoft Express.)

What is the address of the code that changes VM to 0xA? Is this code in Primary or Secondary Flash?
skubit
Associate II
Posted on May 17, 2011 at 12:03

Yes, it's right

Configuration : UPSD 3333D

Mapping :

Rs0 : 0 – 1FFF

Csiop : 2000 – 20FF

Fs0 : 0 - 3fff or bk0, 8000 – bfff

FS1 – fs8 : bk1-8 or 8000 – bfff

Csboot0 : 0 – 1fff or 8000 – 9fff

Csboot1 : a000 – bfff

Csboot2 : c000 – dfff

Csboot3 : e000 – ffff

Before you change VM to 0xA, VM = 0x12

My code is on secondary Flash

lwang
Associate II
Posted on May 17, 2011 at 12:03

You can copy SBoot to SRAM without changing VM.

a) Set up A and DPTR to point to the SBoot in Code Space.

b) Use MOVC A,@A+DPTR to read SBoot into Acc.

c) Set up DPTR to point to the SRAM in XData Space.

d) Use MOVX @DPTR,A to write SRAM from Acc.

If you change VM to 0xA, you should be able to copy SBoot to SRAM too.

a) Set up DPTR to point to the SBoot in XData Space.

b) Use MOVX A,@DPTR to read SBoot into Acc.

c) Set up DPTR to point to the SRAM in XData Space.

d) Use MOVX @DPTR,A to write SRAM from Acc.

I do not know why it did not work for you. One possible scenario is that you unintentionally generated a *WR cycle to the SBoot. This could happen if Ri or DPTR is pointing to SBoot in XData Space and a MOVX @Ri,A or a MOVX @DPTR,A is executed. Doing so may take the SBoot out of “Read Array Mode� and your program will crash.

When you mapped SBoot to both Code and XData Space, you have to avoid generating *WR cycle targeted at SBoot. (The same precaution applies to Primary Flash too. When you mapped Primary Flash to both Code and XData Space, you have to avoid generating *WR cycle targeted at Primary Flash.)

skubit
Associate II
Posted on May 17, 2011 at 12:03

thanks, it's working