New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stm8s103f3 flashing - Tries exceed - Protected chip #38

Open
EvgenyAgafonchikov opened this Issue Jan 27, 2016 · 17 comments

Comments

Projects
None yet
10 participants
@EvgenyAgafonchikov

EvgenyAgafonchikov commented Jan 27, 2016

./stm8flash -c stlinkv2 -p stm8s103?3 -w ../sdcc-examples-stm8/blinky.ihx

results into

Determine FLASH area
Writing Intel hex file 194 bytes at 0x8000... Tries exceeded

There is stm8s103f3 controller on the "minimal system board". Can I help (e.g. providing of additional logs, testing) to make this toolset work with the controller mentioned?

Also, is there any native Linux way to flash stm8 as a temporary solution?

Hardware is similar to the listed in this article

@EvgenyAgafonchikov

This comment has been minimized.

Show comment
Hide comment
@EvgenyAgafonchikov

EvgenyAgafonchikov Jan 28, 2016

I tried to flash the same chip from Windows ST Visual Programmer and got "Device is protected" message. Removing of protection resolved the issue. Flashing is OK now from Windows and Linux both. Is it possible to add chip protection removal to stm8flash?

EvgenyAgafonchikov commented Jan 28, 2016

I tried to flash the same chip from Windows ST Visual Programmer and got "Device is protected" message. Removing of protection resolved the issue. Flashing is OK now from Windows and Linux both. Is it possible to add chip protection removal to stm8flash?

@EvgenyAgafonchikov EvgenyAgafonchikov changed the title from stm8s103f3 flashing - Tries exceed to stm8s103f3 flashing - Tries exceed - Protected chip Jan 28, 2016

@arselzer

This comment has been minimized.

Show comment
Hide comment
@arselzer

arselzer Mar 10, 2016

Having the same problem with the stm8s103f3. Is there any way to "unprotect" the thing on Linux? Sadly I don't have any experience with STM8 microcontrollers, and would just like to experiment with them, so all I can do is +1 the issue.

arselzer commented Mar 10, 2016

Having the same problem with the stm8s103f3. Is there any way to "unprotect" the thing on Linux? Sadly I don't have any experience with STM8 microcontrollers, and would just like to experiment with them, so all I can do is +1 the issue.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Mar 11, 2016

read the manual and datasheet before ask, pls.

$ echo "00" | xxd -r -p >ROP_CLEAR.bin
$ stm8flash -c stlinkv2 -p stm8s103f3 -s opt -w ROP_CLEAR.bin 

ghost commented Mar 11, 2016

read the manual and datasheet before ask, pls.

$ echo "00" | xxd -r -p >ROP_CLEAR.bin
$ stm8flash -c stlinkv2 -p stm8s103f3 -s opt -w ROP_CLEAR.bin 
@arselzer

This comment has been minimized.

Show comment
Hide comment
@arselzer

arselzer Mar 11, 2016

@kensenjiha thanks. I've tried your solution on two boards, but it does not appear to solve the issue.

I still get the same error. Also, if that is relevant, the red LED (might be specific to the model I bought) stopped blinking when it is powered on:

stm8flash -c stlinkv2 -p stm8s103f3 -w blinky.ihx

Determine FLASH area
Writing Intel hex file 178 bytes at 0x8000... Tries exceeded

read the manual and datasheet before ask

No idea where to start, the 100 page PDF is for sure intimidating to me, and I would just like to get the 10 1$ microcontrollers from China working without having to use a crappy OS called Windows and a proprietary program :)

arselzer commented Mar 11, 2016

@kensenjiha thanks. I've tried your solution on two boards, but it does not appear to solve the issue.

I still get the same error. Also, if that is relevant, the red LED (might be specific to the model I bought) stopped blinking when it is powered on:

stm8flash -c stlinkv2 -p stm8s103f3 -w blinky.ihx

Determine FLASH area
Writing Intel hex file 178 bytes at 0x8000... Tries exceeded

read the manual and datasheet before ask

No idea where to start, the 100 page PDF is for sure intimidating to me, and I would just like to get the 10 1$ microcontrollers from China working without having to use a crappy OS called Windows and a proprietary program :)

@merbanan

This comment has been minimized.

Show comment
Hide comment
@merbanan

merbanan Apr 16, 2016

I tried tinkering with a HC-11 board with a stm8s003f3 mcu. The ROP_CLEAR.bin file completed once but not again.

Determine OPT area
Writing binary file 1 bytes at 0x4800... OK
Bytes written: 1

And all other commands end up in the following:

Determine OPT area
Writing binary file 1 bytes at 0x4800... Tries exceeded

merbanan commented Apr 16, 2016

I tried tinkering with a HC-11 board with a stm8s003f3 mcu. The ROP_CLEAR.bin file completed once but not again.

Determine OPT area
Writing binary file 1 bytes at 0x4800... OK
Bytes written: 1

And all other commands end up in the following:

Determine OPT area
Writing binary file 1 bytes at 0x4800... Tries exceeded

@merbanan

This comment has been minimized.

Show comment
Hide comment
@merbanan

merbanan Apr 16, 2016

I tried ST Visual programmer and that worked fine. So I tried with increasing the duration of the TRY macro. This helps somewhat, I can read/write 50% of the times. With the windows software I get 100%, so something is wrong with the commands or timing.

diff --git a/try.h b/try.h
index f584cf1..a077f6a 100644
--- a/try.h
+++ b/try.h
@@ -1,7 +1,7 @@
#define TRY(times, statement) do { \

  •   int c = (times);                        \
    
  •   int c = (times*10);                     \
    while(c > 0) {                          \
    
  •           usleep(3000);                   \
    
  •           usleep(10000);                  \
            if((statement)) break;          \
            c--;                            \
    }                                       \
    

merbanan commented Apr 16, 2016

I tried ST Visual programmer and that worked fine. So I tried with increasing the duration of the TRY macro. This helps somewhat, I can read/write 50% of the times. With the windows software I get 100%, so something is wrong with the commands or timing.

diff --git a/try.h b/try.h
index f584cf1..a077f6a 100644
--- a/try.h
+++ b/try.h
@@ -1,7 +1,7 @@
#define TRY(times, statement) do { \

  •   int c = (times);                        \
    
  •   int c = (times*10);                     \
    while(c > 0) {                          \
    
  •           usleep(3000);                   \
    
  •           usleep(10000);                  \
            if((statement)) break;          \
            c--;                            \
    }                                       \
    
@minobull

This comment has been minimized.

Show comment
Hide comment
@minobull

minobull Apr 23, 2016

@AlexanderSelzer , try reset to factory defaults:

echo "00 00 ff 00 ff 00 ff 00 ff 00 ff" | xxd -r -p > factory_defaults.bin
stm8flash -c stlinkv2 -p stm8s103f3 -s opt -w factory_defaults.bin

minobull commented Apr 23, 2016

@AlexanderSelzer , try reset to factory defaults:

echo "00 00 ff 00 ff 00 ff 00 ff 00 ff" | xxd -r -p > factory_defaults.bin
stm8flash -c stlinkv2 -p stm8s103f3 -s opt -w factory_defaults.bin

@arselzer

This comment has been minimized.

Show comment
Hide comment
@arselzer

arselzer Apr 23, 2016

@minobull Now it works, I was able to write to flash now. Thank you.

Also, if anyone has the same issue, the sdcc-examples-stm8 blinky.c example does not work on the stm8s103f3 boards. Use one from there instead: http://www.cnx-software.com/2015/04/13/how-to-program-stm8s-1-board-in-linux/

arselzer commented Apr 23, 2016

@minobull Now it works, I was able to write to flash now. Thank you.

Also, if anyone has the same issue, the sdcc-examples-stm8 blinky.c example does not work on the stm8s103f3 boards. Use one from there instead: http://www.cnx-software.com/2015/04/13/how-to-program-stm8s-1-board-in-linux/

@hraftery

This comment has been minimized.

Show comment
Hide comment
@hraftery

hraftery Jun 26, 2016

@minobull that is sensational. After 5 hours working on this, your two-liner has turned a dead end into a success.

I guess the opt2 box in README.md can be changed to OK for stm8s103f3.

Very pleased to report success with OS X (El Capitan) + ST-Link V2 (Mini emulator on eBay) + sdcc + stm8flash + STM8S103F3P6 (minimum system development board on eBay).

Have attached a minimum blinky.c and a minimum Makefile to any others working along the same path. Just cut out the .txt extensions.

blinky.c.txt
Makefile.txt

hraftery commented Jun 26, 2016

@minobull that is sensational. After 5 hours working on this, your two-liner has turned a dead end into a success.

I guess the opt2 box in README.md can be changed to OK for stm8s103f3.

Very pleased to report success with OS X (El Capitan) + ST-Link V2 (Mini emulator on eBay) + sdcc + stm8flash + STM8S103F3P6 (minimum system development board on eBay).

Have attached a minimum blinky.c and a minimum Makefile to any others working along the same path. Just cut out the .txt extensions.

blinky.c.txt
Makefile.txt

@blahlt

This comment has been minimized.

Show comment
Hide comment
@blahlt

blahlt Jul 19, 2016

It works also on Win7 x64+ ST-Link V2 + SDCC + STM8S103F3P6
I'd problem with error "Writing Intel hex file xxx bytes at 0x8000... Tries exceeded" and solution with factory_defaults.bin and ROP_CLEAR.bin didn't help to me. So, I installed "ST Visual Develop", have rewritten data in OPTION BYTE tab and my STM8S103F3P6 alive now.

I create options backup without ROP and now you can unlock your STM8S103F3P6 with command:
stm8flash -c stlinkv2 -p stm8s103f3 -s opt -w optdefault.bin

optdefault.bin.txt

blahlt commented Jul 19, 2016

It works also on Win7 x64+ ST-Link V2 + SDCC + STM8S103F3P6
I'd problem with error "Writing Intel hex file xxx bytes at 0x8000... Tries exceeded" and solution with factory_defaults.bin and ROP_CLEAR.bin didn't help to me. So, I installed "ST Visual Develop", have rewritten data in OPTION BYTE tab and my STM8S103F3P6 alive now.

I create options backup without ROP and now you can unlock your STM8S103F3P6 with command:
stm8flash -c stlinkv2 -p stm8s103f3 -s opt -w optdefault.bin

optdefault.bin.txt

@wonbinbk

This comment has been minimized.

Show comment
Hide comment
@wonbinbk

wonbinbk Feb 16, 2017

@minobull Thank god I found you!

Crazy...
Yeah I didn't read manual or datasheet. I just wanted to confirm that my toolchain was working.
That's why I follow tutorial online.
How would I know that the chip has been altered from factory defaults. Never happen before.
You sir, have saved my day.
Below is my blinky version with sine wave emulating breathing on the LED (don't know what to call it but I think it's cool to look at).
blinky.c.txt

wonbinbk commented Feb 16, 2017

@minobull Thank god I found you!

Crazy...
Yeah I didn't read manual or datasheet. I just wanted to confirm that my toolchain was working.
That's why I follow tutorial online.
How would I know that the chip has been altered from factory defaults. Never happen before.
You sir, have saved my day.
Below is my blinky version with sine wave emulating breathing on the LED (don't know what to call it but I think it's cool to look at).
blinky.c.txt

@bWildered1

This comment has been minimized.

Show comment
Hide comment
@bWildered1

bWildered1 Jul 7, 2017

Hi.
I have encountered a similar, but not identical, problem with an STM8 L 151K4 device.

stm8flash 20170616-1.1
Ubuntu 16.04.1 64-bit

Initial attempt to flash this device reported
'Determine FLASH area
Writing Intel hex file 217 bytes at 0x8000... Tries exceeded'

Testing with STVP on Windows indicated that the device was read out protected. Cleared read out protection, using STVP.
Note: On this device, read out protection seems to be disabled when first option byte is set to a value of AA. This seems to be the opposite of some other devices in the STM8 series.

Could now flash device on Windows using STVP.
But still cannot flash device on Ubuntu using stm8flash, getting same report (Tries exceeded) as earlier.

However, can read both flash and option bytes using stm8flash on Ubuntu machine.

stm8l151k4_opt.txt

Am probably doing something silly.

Should I have posted this a a separate (new) issue?

I have attached the result of the stm8flash option byte read, although this file had to be renamed with a .txt extension to be uploaded.

Take care.

M

bWildered1 commented Jul 7, 2017

Hi.
I have encountered a similar, but not identical, problem with an STM8 L 151K4 device.

stm8flash 20170616-1.1
Ubuntu 16.04.1 64-bit

Initial attempt to flash this device reported
'Determine FLASH area
Writing Intel hex file 217 bytes at 0x8000... Tries exceeded'

Testing with STVP on Windows indicated that the device was read out protected. Cleared read out protection, using STVP.
Note: On this device, read out protection seems to be disabled when first option byte is set to a value of AA. This seems to be the opposite of some other devices in the STM8 series.

Could now flash device on Windows using STVP.
But still cannot flash device on Ubuntu using stm8flash, getting same report (Tries exceeded) as earlier.

However, can read both flash and option bytes using stm8flash on Ubuntu machine.

stm8l151k4_opt.txt

Am probably doing something silly.

Should I have posted this a a separate (new) issue?

I have attached the result of the stm8flash option byte read, although this file had to be renamed with a .txt extension to be uploaded.

Take care.

M

@dj0abr

This comment has been minimized.

Show comment
Hide comment
@dj0abr

dj0abr Aug 30, 2017

the issue with "tries...exceeded" has nothing to do with a protected chip or similar.
It is a timing issue of stm8flash. If i run stm8flash in a loop, then sometimes it works, and most of the time does not work. Maybe depends on the speed of the PC ?

dj0abr commented Aug 30, 2017

the issue with "tries...exceeded" has nothing to do with a protected chip or similar.
It is a timing issue of stm8flash. If i run stm8flash in a loop, then sometimes it works, and most of the time does not work. Maybe depends on the speed of the PC ?

@alekratz

This comment has been minimized.

Show comment
Hide comment
@alekratz

alekratz Mar 29, 2018

I am having "tries exceeded" happen on my STM8s103f3 chip when trying to reset to factory defaults. I have not run it in a loop to see if I can get one try to work, but I will overnight and see if it works.

alekratz commented Mar 29, 2018

I am having "tries exceeded" happen on my STM8s103f3 chip when trying to reset to factory defaults. I have not run it in a loop to see if I can get one try to work, but I will overnight and see if it works.

@alekratz

This comment has been minimized.

Show comment
Hide comment
@alekratz

alekratz Mar 29, 2018

Did not work. Anyone who finds a solution, please ping me - I would like to get my boards working :)

alekratz commented Mar 29, 2018

Did not work. Anyone who finds a solution, please ping me - I would like to get my boards working :)

@alekratz

This comment has been minimized.

Show comment
Hide comment
@alekratz

alekratz Mar 31, 2018

Update: I got a new ST-Linkv2 in the mail and I tried that with my STM8 boards - two out of three worked on the first try with the new link. The third one is being a problem child, and I get this feeling I may have messed something up with it in the process of trying to get it to flash. I used the -d slow option, I'm not sure if that helped. If you want some sort of diagnostics about where tries exceeded, change line 6 in error.h to read like this:

#define ERROR(s) do { fprintf(stderr, "%s in %s:%d\n", (s), __FILE__, __LINE__); exit(-1); } while(0)

This will tell you the source file and line that actually ended up failing.

Honestly, I think these are the results of cheap hardware and good/bad luck. Keep trying, and if you have the money to buy another STM8 or ST-linkv2, it might fix any problems you have with the flash. It's disappointing, I understand, but that's the price you pay for cheap hardware. Good luck and godspeed the rest of you reading this.

alekratz commented Mar 31, 2018

Update: I got a new ST-Linkv2 in the mail and I tried that with my STM8 boards - two out of three worked on the first try with the new link. The third one is being a problem child, and I get this feeling I may have messed something up with it in the process of trying to get it to flash. I used the -d slow option, I'm not sure if that helped. If you want some sort of diagnostics about where tries exceeded, change line 6 in error.h to read like this:

#define ERROR(s) do { fprintf(stderr, "%s in %s:%d\n", (s), __FILE__, __LINE__); exit(-1); } while(0)

This will tell you the source file and line that actually ended up failing.

Honestly, I think these are the results of cheap hardware and good/bad luck. Keep trying, and if you have the money to buy another STM8 or ST-linkv2, it might fix any problems you have with the flash. It's disappointing, I understand, but that's the price you pay for cheap hardware. Good luck and godspeed the rest of you reading this.

@bWildered1

This comment has been minimized.

Show comment
Hide comment
@bWildered1

bWildered1 Mar 31, 2018

bWildered1 commented Mar 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment