cancel
Showing results for 
Search instead for 
Did you mean: 

IAP & SWIM Debug

fggnrc
Associate II
Posted on December 02, 2009 at 04:08

IAP & SWIM Debug

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

Hi!

I'm developing a custom bootloader for a STM8207C8 which I debug with STVD and RLink.

After my code unlocks flash programming, i.e. it executes:

MOV FLASH_PUKR,#$56

MOV FLASH_PUKR,#$AE

STVD starts sending the following messages:

Error: swim prog error [42008]: attempt to write to protected area

What does this message mean?

Have I to execute IAP code from RAM, i.e. unlock flash, program it, then lock it again from RAM?

Thanks

EtaPhi

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

Hi,

as I know, you have no need to program FLASH from RAM in case you use WORD or BYTE programming. Please check the following points on your code:

1. memory is not readout protected (ROP)

2. you're writing into an unprotected memory area (UBC)

3. after unloking, poll PUL bit, before to proceed writing program flash

have a look on Programming Manual for further details:

http://www.st.com/stonline/products/literature/pm/14614.pdf

coluber

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

Hi,

If you use an external oscillator HSE >16MHz you should set the wait state option byte

Regards

mozra

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

I thank you, brazov2 for your reply.

My bootloader uses block programming to update flash from an image stored in a microSD.

My code is written in assembler and it does all that chapter 4. of STM8 Microcontroller Family (RM0016) says.

It successfully programmed the microcontroller flash, but I can't debug it because of this annoying message.

I can ''live'' without debugging it, because my programming routine is 48 bytes long, but I'm a bit curious of that message...

BTW, who is in charge of those error messages?

The STVD team or Raisonance?

Regards

EtaPhi

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

Hello mozra27!

I use an external 16 MHz resonator, so no wait state should be added.

Do you have any other piece of advise?

Thank you for your reply

EtaPhi

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

In your mapping I don't see any confusion, are you sure that the bloc programming function is placed in the RAM before running your application? Also your data should be in the RAM.

Just one remark: in debug mode you don't need to unlock the Flash program memory it is unlocked by the SWIM.

Thanks to check these points

Regards

Mozra

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

Hi,

Can you please share with us the segments configuration defined in your linker file...;)

Regards

mozra

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

mozra27,

here is the mapping.asm file that STVD 4.1.3 generates with my segments definition:

Code:

stm8/

;------------------------------------------------------

; SEGMENT MAPPING FILE AUTOMATICALLY GENERATED BY STVD

; SHOULD NOT BE MANUALLY MODIFIED.

; CHANGES WILL BE LOST WHEN FILE IS REGENERATED.

;------------------------------------------------------

include ''mapping.inc''

BYTES ; The following addresses are 8 bits long

segment byte at ram0_segment_start-ram0_segment_end 'ram0'

WORDS ; The following addresses are 16 bits long

segment byte at ram1_segment_start-ram1_segment_end 'ram1'

WORDS ; The following addresses are 16 bits long

segment byte at stack_segment_start-stack_segment_end 'stack'

WORDS ; The following addresses are 16 bits long

segment byte at 4000-45FF 'eeprom'

WORDS ; The following addresses are 16 bits long

segment byte at 8000-807F 'vectit'

WORDS ; The following addresses are 16 bits long

segment byte at 8080-99FF 'boot'

WORDS ; The following addresses are 16 bits long

segment byte at 9A00-FFBF 'code'

WORDS ; The following addresses are 16 bits long

segment byte at FFC0-FFFF 'interface'

WORDS ; The following addresses are 16 bits long

segment byte at 10000-17FFF 'rom'

END

Regards

EtaPhi

PS: My application is developed with the STM8 Assembler toolchain.

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

Mozra,

here is my WORKING code which writes a microSD sector (i.e. 512 bytes) to flash.

These 512 bytes are stored from $100 to $2FF and they are written to my code and

interface segment ($9A00-$FFFF) or to my rom segment ($10000-$17FFF). In the

former case, X initial value is $1A00, while in the latter case X=$8000.

As a safety measure, FLASH is unlocked in Flasher code only.

My code is simple.

It copies Flasher code to RAM with the following instructions:

Code:

<BR> ; Copy Flasher code to RAM <BR> LDW X,&sharp;FlasherEnd <BR> LDW Y,&sharp;$stack_segment_start <BR>CopyFlasherLoop <BR> DECW X <BR> LD A,(X) <BR> DECW Y <BR> LD (Y),A <BR> CPW X,&sharp;Flasher <BR> JRNE CopyFlasherLoop <BR>

Then it sets up and executes the programming loop:

Code:

<BR> ; Load 1st sector in $ 100 - $ 2FF <BR> CALL LoadFirstFirmwareSector <BR> LDW X,&sharp;$ 1A00 <BR>FirmwareSectorLoop <BR> LDW Y,&sharp;$ 100 <BR>FirmwareFlashLoop <BR> CALL {$stack_segment_start+Flasher-FlasherEnd} <BR> JRNC FirmwareUpdateError <BR> ; Stop conditions: <BR> ; X = $ 0000 (destination: $ 10000 - $ 17FFF) <BR> ; X = $ 8000 (destination: $ 09A00 - $ 0FFFF) <BR> TNZW X <BR> JREQ FirmwareUpdated <BR> CPW X,&sharp;$ 8000 <BR> JREQ FirmwareUpdated <BR> CPW Y,&sharp;$ 300 <BR> JRMI FirmwareFlashLoop <BR> ; Load the following sector <BR> PUSHW X <BR> CALL LoadNextFirmwareSector <BR> POPW X <BR> JRC FirmwareSectorLoop <BR>FirmwareUpdateError <BR> ; Some error handling code... <BR>FirmwareUpdated <BR> ; Some post-installation code... <BR> <BR>;------- <BR>; Flasher <BR>;------- <BR>; This code writes 128 bytes to flash. X register holds the <BR>; starting address of the block to write. Y register holds <BR>; the address of the RAM buffer where data is stored. <BR>; NOTICE: <BR>; this code WORKS only if it's copied to RAM <BR>;------- <BR> <BR>Flasher <BR> ; unlock FLASH <BR> MOV FLASH_PUKR,&sharp;$ 56 <BR> MOV FLASH_PUKR,&sharp;$ AE <BR> BTJF FLASH_IAPSR,&sharp;1,FlasherExit <BR> PUSH &sharp;128 <BR> ; Enable block programming <BR> PUSHW X <BR> LDW X,&sharp;$ 01FE <BR> ; NOTICE: this instruction changes FLASH_NCR2 after FLASH_CR2 <BR> LDW FLASH_CR2,X <BR> POPW X <BR>FlasherLoop <BR> LD A,(Y) <BR> LD ($ 8000,X),A <BR> INCW Y <BR> INCW X <BR> DEC (1,SP) <BR> JRNE FlasherLoop <BR> POP A <BR>FlasherWait <BR> BTJF FLASH_IAPSR,&sharp;2,FlasherWait <BR> ; lock FLASH <BR> BRES FLASH_IAPSR,&sharp;1 <BR>FlasherExit <BR> RET <BR>FlasherEnd <BR> <BR>

As you can see, it's a very simple code which works.

Since I can't even watch STM8 core registers value after Flasher unlocks flash,

I think that the SWIM error is due to the following condition: block programming

is taking place, so flash can't be read. When I step through Flasher code, SWIM

tries to read $7F00 - $7F0A to update STM8 core register values. These addresses

may be unaccessible as flash is and this gives birth to my error.

Regards

EtaPhi

PS: this formum post editor doesn't allow me to enter '#' and it does strange things with '$' inside a CODE block. Is there a workaround for this?

[ This message was edited by: EtaPhi on 03-12-2009 06:52 ]