vdudouyt / stm8flash

program your stm8 devices with SWIM/stlinkv(1,2)
GNU General Public License v2.0
403 stars 183 forks source link

Stlinkv2 stm8l unlock #98

Closed sjborley closed 8 months ago

sjborley commented 6 years ago

This aims to fix unlocking the STM8L. I've tested it on STM8L052R8 but it ought for other STM8L devices. Only fixed this for the stlinkv2. I've trying to fix for stlink too but without success, so have omitted those changes.

Also noted, that the EEPROM read and write appears to be working for this device, although I'm not aware I did anything that would have affected this. I just tested it.

DKrepsky commented 6 years ago

Tested this PR with STM8L151K4 and worked as expected.

Thanks

lkord commented 6 years ago

Tested with STM8L151G6 and unlock is working. Thank You. I was trying earlier and did not accomplish this. Why do You put 0x01 into buf[10]? This seems to be BROWNOUT Reset ON. With Off (0x00) it is also working.

B4Me commented 6 years ago

I have made a pull of the changes by @sjborley , but cant get my STM8L052C6, unlocked Does anyone else have a hint of what I can do to get the unlocking to work ?

lkord commented 6 years ago

@B4Me show the command You use and error You get

B4Me commented 6 years ago

@lkord Here are my commands: sudo ./stm8flash -c stlinkv2 -p stm8l052c6 -u

Determine OPT area Due to its file extension (or lack thereof), "Workaround" is considered as RAW BINARY format! Unlocked device. Option bytes reset to default state. Bytes written: 13

sudo ./stm8flash -c stlinkv2 -p stm8l052c6 -s flash -w calib.ihx

Determine FLASH area Due to its file extension (or lack thereof), "calib.ihx" is considered as INTEL HEX format! 20628 bytes at 0x8000... Tries exceeded

lkord commented 6 years ago

@B4Me after first operation. Can You read OPT Bytes?: sudo ./stm8flash -c stlinkv2 -p stm8l052c6 -s opt -r OB.hex -b 13 See in datasheet what should appear on first byte? 0xAA or 0x00? Workaround for unlock can be (but not tested on this part):

  1. Unlock with STVP
  2. Download OPTION BYTES sectors to *.hex file
  3. Write (change -r to -w from command above) that file to opt area to unlock. Can do same things to lock.

I have never seen .ihx files before. Did You mean .hex?

B4Me commented 6 years ago

Hi @lkord Sorry for the delay, had an accident, so first had time now. After running unlock, and reading out opt bytes I get: AA 00 00 00 00 00 00

But I still cant write to the device after a reset of the power. The issue as I see it, are in the syntax, flash AA, read EOP, flash AA, read EOP I dont think the code is correct yet But I dont know what to change yet.

I have to be able to do it through linux, sadly, so using STVP, isnt an option, as its for a production rig, where everything needs to run from a single box, running on raspberry pi

lkord commented 6 years ago

@B4Me

  1. According to datasheet the uC is unlocked 0xAA in 0x4800 address,
  2. Unlock code You can find in stlinkv2.c but in sborley branch for STM8L,
  3. The STVP solution is to read bytes to a .hex file just once and then use it as an input file, no need for Windows and STVP,
  4. Last question: I have never seen .ihx files before. Did You mean .hex?
spth commented 4 years ago
4. Last question: I have never seen *.ihx files before. Did You mean *.hex?

These are just alternative file endings for the same Intel Hex type of file, like .jpg and .jpeg for JPEG.

spth commented 3 years ago

I think we now have working STM8L unlock support in master? If yes, can this pull request be closed or is there still something left here that we want in master?

spth commented 8 months ago

Closing, out of date.