cancel
Showing results for 
Search instead for 
Did you mean: 

block write simulation problem of eeprom in stm8s105c6 using cosmic

cgha21
Associate II
Posted on October 29, 2009 at 05:56

block write simulation problem of eeprom in stm8s105c6 using cosmic

9 REPLIES 9
cgha21
Associate II
Posted on May 17, 2011 at 15:05

hello,all

I am using stlink3 and stvd with cosmic.Here is my code and setting.

//以�写的方�写入ID

#pragma section (EE_CODE)

void SetRfID(void)

{

U8 i;

FLASH_DUKR = 0xAE;

FLASH_DUKR = 0x56; //while((FLASH_IAPSR & 0x08) == 0 );

FLASH_CR2 |= 0x01;

FLASH_NCR2 &= (u8)(~0x01);

for(i=0;i

{

E2_RfID[i] = DevIDCode[i];

}

while((FLASH_IAPSR &0x04) ==0);

//FLASH_IAPSR &= ~0x08;

}

#pragma section()

in project setting->linker->input->ram segment,i add a section called EE_CODE,and the option is -ic. then i add the _fctcpy('E') in main,but when i try to execute the setrfid,it throws a swim prog error [42004],what should i do?

brazov2
Associate II
Posted on May 17, 2011 at 15:05

before unlocking memory, put devidcodes in ram locations and then in your loop assign to E2_RfID[i] the ram locations.

hope it works.

coluber

mozra27
Associate II
Posted on May 17, 2011 at 15:05

Hi,

What is this!!!! What you need to do exactly?

In your case you use a byte programming mode so, you don't need to copy your code in the RAM

void SetRfID(void)

{

U8 i;

FLASH_PUKR = 0x56;

FLASH_PUKR = 0xAE;

while((FLASH_IAPSR & 0x02) == 0 ); /*Unlock the program memory */

for(i=0;i

{

E2_RfID[i] = DevIDCode[i];

}

}

When linking the code in RAM and power down your board the section code placed in the RAM will be erased, If you want to do this you don't need to call the _fctcpy() function your code is linked directly to RAM by the linker

If you want to execute your code in standalone mode from RAM you need to declare two sections one in the Flash memory and the other in the RAM, the section declared in the RAM is to store a copy from the section linked to the flash memory. This copy is performed when executing the _fctcpy() function.

In this case you can update your linker file as following:

# Segment Code,Constants:

+seg .const -b 0x8080 -m 0x7f80 -n .const -it

+seg .text -a .const -n .text

+seg .EE_CODE -a .const -n .EE_CODE

# Segment Eeprom:

+seg .eeprom -b 0x1000 -m 0x400 -n .eeprom

# Segment Zero Page:

+seg .bsct -b 0x0 -m 0x100 -n .bsct

+seg .ubsct -a .bsct -n .ubsct

+seg .bit -a .ubsct -n .bit -id

+seg .share -a .bit -n .share -is

# Segment Ram:

+seg .data -b 0x100 -m 0x500 -n .data

+seg .bss -a .data -n .bss

+seg .EE_CODE -a .bss -n boot_Ram -ic

#

The _fctcpy('b') takes the first letter as parameter for the section name when you want to copy your movable code

Regards

mozra

cgha21
Associate II
Posted on May 17, 2011 at 15:05

Thanks!

I declared E2_RfID as @eeprom U8 E2_RfID[5];

Where can mozra find out i'm using the byte programming?Sorry,i'm just confused.

Yeath,i've copy the programming code in ram using _fctcpy('E') in main initilize,and i just want to use my stlink3 to debug the eeprom write in bulk mode,but it always give me the error.

Does mozra means I should add one more section in flash segment using the same EE_CODE name? Thanks!

[ This message was edited by: cgha21 on 29-10-2009 08:45 ]

cgha21
Associate II
Posted on May 17, 2011 at 15:05

I've tested mozra method,and now it do not give me error,but it can not step though the while((FLASH_IAPSR &0x04) ==0);//check write finish

cgha21
Associate II
Posted on May 17, 2011 at 15:05

Oh,sorry, it still gives me the error after i revised the _fctcpy('E') to _fctcpy('b');

[ This message was edited by: cgha21 on 29-10-2009 09:34 ]

mozra27
Associate II
Posted on May 17, 2011 at 15:05

Yes, the section EE_CODE should be @eeprom and use other section in the RAM(copy for the previously section placed @eeprom)

In this case you need to edit manually your linker file by adding the following lines

@RAM after bss section :

+seg .EE_CODE -a .bss -n boot_Ram -ic

@eeprom after const section :

+seg .EE_CODE -a .const -n .EE_CODE

Use the letter 'b' as parameter for the _fctcpy() function: _fctcpy('b')

Regards

mozra

mozra27
Associate II
Posted on May 17, 2011 at 15:05

Can you please check your variable address (E2_RfID)

To declare the variable E2_RfID @eeprom you can specify his address as follows:

U8 E2_RfID[5] @0x9000;

The end of programming flag (EOP) should be set after each byte access to the flash.

A+

cgha21
Associate II
Posted on May 17, 2011 at 15:05

Gived up,use byte write.