grigorig / stcgal

Open Source STC MCU ISP flash tool
642 stars 135 forks source link

Does not work with STC15L104W 7.2.5Q #68

Open kasbert opened 3 years ago

kasbert commented 3 years ago

I got read timeout in 'Trimming frequency ' with device STC15L104W

Without options. Shouldn't it detect this device ?

$ stcgal -D main.ihx 
Waiting for MCU, please cycle power: <- Packet data: 46 B9 68 00 34 50 99 8A E2 4A BC BF 57 0A A0 AB 8B C0 F5 27 05 02 08 20 4E D4 03 C9 D4 15 64 10 6E E1 02 1D 8D 46 51 65 CA 80 14 41 46 98 BD 09 BF FF FD 65 56 D0
<- Packet data: A1
<- Packet data: C0
<- Packet data: 13
<- Packet data: 2E
<- Packet data: 59
<- Packet data: FE
^Cinterrupted

As stc15

$ stcgal -D -P stc15 main.ihx  
Waiting for MCU, please cycle power: <- Packet data: 46 B9 68 00 34 50 66 71 9C C2 F7 BB 9F 00 B7 2D C0 FD 27 41 00 00 72 51 03 F2 D4 05 06 70 C2 02 1D 23 24 29 29 80 14 10 04 D6 FF C2 BF FF FF 19 05 17 01 13 2E 16
done
Target model:
  Name: STC15L104W
  Magic: F2D4
  Code flash: 4.0 KB
  EEPROM flash: 1.0 KB
Target frequency: 12.005 MHz
Target BSL version: 7.2.5Q
Target wakeup frequency: 26.225 KHz
Target options:
  reset_pin_enabled=False
  clock_source=internal
  clock_gain=high
  watchdog_por_enabled=False
  watchdog_stop_idle=True
  watchdog_prescale=256
  low_voltage_reset=True
  low_voltage_threshold=3
  eeprom_lvd_inhibit=True
  eeprom_erase_enabled=False
  bsl_pindetect_enabled=False
  por_reset_delay=long
  rstout_por_state=high
  uart2_passthrough=False
  uart2_pin_mode=normal
  cpu_core_voltage=unknown
Loading flash: 906 bytes (Intel HEX)
Trimming frequency: -> Packet data: 46 B9 6A 00 20 00 0C 00 C0 80 C0 FF C0 00 80 80 80 FF 80 00 40 80 40 FF 40 00 00 80 00 C0 00 0A D3 16
<- Packet data: 46 B9 68 00 20 00 0C 0C 07 11 11 16 39 17 F1 21 F1 2C 00 30 97 44 56 58 29 4D 8E 6C 06 7A A2 07 A9 16
-> Packet data: 46 B9 6A 00 20 00 0C BE 80 BF 80 C0 80 C1 80 C2 80 C3 80 94 40 95 40 96 40 97 40 98 40 99 40 0D 20 16
<- Packet data: 46 B9 68 00 20 00 0C 27 0A 27 19 26 D8 26 F1 27 14 27 19 47 7B 47 A3 47 E4 48 07 48 20 48 43 07 AE 16
12.005 MHz
Switching to 19200 baud: -> Packet data: 46 B9 6A 00 0E 01 97 40 FB 7F C2 80 81 04 8D 16
<- Packet data: 46 B9 68 00 07 01 00 70 16
-> Packet data: 46 B9 6A 00 0B 05 00 00 5A A5 01 79 16
Serial port error: read timeout

As stc15a. Target frequency is quite wild.

$ stcgal -D -P stc15a main.ihx 
Waiting for MCU, please cycle power: <- Packet data: 46 B9 68 00 34 50 66 71 9C C2 F7 BB 9F 00 B7 2D C0 FD 27 46 00 00 72 51 03 F2 D4 05 06 70 C2 02 1D 23 24 29 29 80 14 10 04 D6 FF C2 BF FF FF 19 05 17 01 13 33 16
done
Target model:
  Name: STC15L104W
  Magic: F2D4
  Code flash: 4.0 KB
  EEPROM flash: 1.0 KB
Target frequency: 175.349 MHz
Target BSL version: 7.2Q
Target options:
  reset_pin_enabled=False
  watchdog_por_enabled=True
  watchdog_stop_idle=True
  watchdog_prescale=8
  low_voltage_reset=True
  low_voltage_threshold=0
  eeprom_lvd_inhibit=False
  eeprom_erase_enabled=True
  bsl_pindetect_enabled=True
Loading flash: 906 bytes (Intel HEX)
Trimming frequency: -> Packet data: 46 B9 6A 00 0D 50 00 00 36 01 F2 D4 02 C4 16
Serial port error: read timeout

With STC-ISP the progamming seem to work and it uses baudrate 38400 . Device does not work, though. Probably a problem with my program.

Checking target MCU ... 
  MCU type: STC15L104W
  F/W version: 7.2.5Q

Current H/W Option:
  . Current system clock source is internal IRC oscillator
  . Current frequency: 12.023MHz
  . Wakeup Timer frequency: 26.225KHz
  . Do not detect the level of P3.2 and P3.3 next download
  . Power-on reset, use the extra power-on delay
  . RESET pin behaves as IO pin
  . Reset while detect a Low-Voltage
  . Thresh voltage level of the built-in LVD : 2.42 V
  . Inhibit EEPROM operation under Low-Voltage  . Hardware do not enable Watch-Dog-Timer
  . Watch-Dog-Timer pre-scalar : 256
  . Watch-Dog-Timer stop count in idle mode
  . Program can modify the Watch-Dog-Timer scalar
  . Erase user EEPROM area at next download
  . Do not control 485 at next download
  . Do not check user password next download
  . TXD is independent IO
  . TXD pin as quasi-bidirectional mode after reset
  . P3.3 output HIGH level after reset
  . Reference voltage: 1238 mV (Range: 1150~1320mV)
  . Testing time: 2019-5-17

  MCU type: STC15L104W
  F/W version: 7.2.5Q
...
Adjusting frequency ...         [0.755"]
Adjusted frequency: 11.075MHz (0.141)

Re-handshaking ... Successful           [0.126"]
Current Baudrate: 38400
Erasing MCU flash ...  OK !     [0.393"]
MCU ID : F2D4C3F301B4FB
Programming user code ... OK !%     [0.589"]
Programming OPTIONS ... OK !        [0.057"]

H/W Option upgrade to:
  . Current system clock source is internal IRC oscillator
  . Current frequency: 11.075MHz
  . Do not detect the level of P3.2 and P3.3 next download
  . Power-on reset, use the extra power-on delay
  . RESET pin behaves as IO pin
  . Reset while detect a Low-Voltage
  . Thresh voltage level of the built-in LVD : 2.42 V
  . Inhibit EEPROM operation under Low-Voltage  . Hardware do not enable Watch-Dog-Timer
  . Watch-Dog-Timer pre-scalar : 256
  . Watch-Dog-Timer stop count in idle mode
  . Program can modify the Watch-Dog-Timer scalar
  . Do not erase user EEPROM area at next download
  . Do not control 485 at next download
  . Do not check user password next download
  . TXD is independent IO
  . TXD pin as quasi-bidirectional mode after reset
  . P3.3 output HIGH level after reset
  . Reference voltage: 1238 mV (Range: 1150~1320mV)
  . Testing time: 2019-5-17
MCU ID : F2D4C3F301B4FB

  MCU type: STC15L104W
  F/W version: 7.2.5Q

Here is a usb data capture of a STC-ISP programming event. I changed frequency to 12.000Mhz at some moment.

   33.311  3470 W: <Buffer 7f>
   33.321  3472 W: <Buffer 7f>
   33.331  3474 W: <Buffer 7f>
   33.342  3476 W: <Buffer 7f>
   33.352  3480 W: <Buffer 7f>
   33.363  3482 W: <Buffer 7f>
   33.373  3484 W: <Buffer 7f>
   33.384  3486 W: <Buffer 7f>
   33.850  3622 W: <Buffer 46 b9 6a 00 20 00 0b 00 c0 80 c0 ff c0 00 80 80 80 ff 80 00 40 80 40 ff 40 00 00 80 00 00 00 0a 12 16>
   33.850  3623 W: <Buffer fe>
   33.861  3626 W: <Buffer fe>
   33.871  3627 W: <Buffer fe>
   33.997  3631 W: <Buffer fe fe fe fe fe fe fe fe fe fe fe fe>
   34.005  3633 W: <Buffer fe>
   34.015  3636 W: <Buffer fe>
   34.026  3637 W: <Buffer fe>
   34.066  3639 W: <Buffer fe fe fe>
   34.070  3643 W: <Buffer fe>
   34.221  3714 W: <Buffer 46 b9 6a 00 20 00 0c bd 80 be 80 bf 80 c0 80 c1 80 c2 80 94 40 95 40 96 40 97 40 98 40 99 40 0d 1a 16>
   34.222  3716 W: <Buffer fe>
   34.232  3718 W: <Buffer fe>
   34.242  3719 W: <Buffer fe>
   34.368  3721 W: <Buffer fe fe fe fe fe fe fe fe fe fe fe fe>
   34.376  3723 W: <Buffer fe>
   34.387  3726 W: <Buffer fe>
   34.397  3729 W: <Buffer fe>
   34.437  3731 W: <Buffer fe fe fe>
   34.442  3733 W: <Buffer fe>
   34.635  3806 W: <Buffer 46 b9 6a 00 0e 01 97 40 fd c0 fc 9f 81 05 29 16>
   34.793  3844 W: <Buffer 46 b9 6a 00 0b 05 00 00 5a a5 01 79 16>
   34.809  3866 W: <Buffer 46 b9 6a 00 0b 03 00 00 5a a5 01 77 16>
   35.154  3902 W: <Buffer 46 b9 6a 00 4b 32 00 00 5a a5 02 00 69 32 ff ff ff ff ff ff ff 02 00 d2 ff ff ff ff ff 32 ff ff ff ff ff ff ff 32 ff ff ff ff ff ff ff 32 ff ff ff ff ... >
   35.154  3903 W: <Buffer ff ff ff ff ff 32 ff ff ff ff 37 50 16>
   35.186  3926 W: <Buffer 46 b9 6a 00 4b 12 00 40 5a a5 ff ff ff 32 ff ff ff ff ff ff ff 32 ff ff ff ff ff ff ff 02 00 d1 ff ff ff ff ff 32 ff ff ff ff ff ff ff 02 00 f0 02 02 ... >
   35.186  3927 W: <Buffer 79 00 e9 44 00 60 1b 7a 00 90 29 47 16>
   35.220  3950 W: <Buffer 46 b9 6a 00 4b 12 00 80 5a a5 03 8a 78 01 75 a0 00 e4 93 f2 a3 08 b8 00 02 05 a0 d9 f4 da f2 75 a0 ff e4 78 ff f6 d8 fd 78 00 e8 44 00 60 0a 79 01 75 ... >
   35.220  3951 W: <Buffer 79 00 90 00 01 e4 f0 a3 d8 fc 22 5d 16>
   35.256  3976 W: <Buffer 46 b9 6a 00 4b 12 00 c0 5a a5 d9 fa 75 31 64 75 32 00 75 33 64 75 34 00 02 00 66 32 c0 e0 c0 d0 74 01 25 27 f5 27 e4 35 28 f5 28 e4 35 29 f5 29 e4 35 ... >
   35.256  3977 W: <Buffer c0 82 c0 83 c0 07 c0 06 c0 05 21 0f 16>
   35.291  4000 W: <Buffer 46 b9 6a 00 4b 12 01 00 5a a5 c0 04 c0 03 c0 02 c0 01 c0 00 c0 d0 75 d0 08 85 31 10 85 32 11 90 00 09 75 d0 00 12 03 69 75 d0 08 ae 82 af 83 a2 34 e4 ... >
   35.291  4001 W: <Buffer d0 00 12 03 69 75 d0 08 ac 82 1a 4e 16>
   35.327  4024 W: <Buffer 46 b9 6a 00 4b 12 01 40 5a a5 ad 83 d0 0e d0 0f ec 2e f5 31 ed 3f f5 32 85 33 10 85 34 11 90 00 09 75 d0 00 12 03 69 75 d0 08 ae 82 af 83 a2 33 e4 33 ... >
   35.327  4025 W: <Buffer 00 12 03 69 75 d0 08 ac 82 ad 1c 17 16>
   35.365  4048 W: <Buffer 46 b9 6a 00 4b 12 01 80 5a a5 83 d0 0e d0 0f ec 2e f5 33 ed 3f f5 34 c3 74 32 95 31 74 80 85 32 f0 63 f0 80 95 f0 50 06 7e 01 7f 00 80 04 7e 00 7f 00 ... >
   35.365  4049 W: <Buffer f0 50 06 7c 01 7d 00 80 04 7c 1e 8b 16>
   35.401  4072 W: <Buffer 46 b9 6a 00 4b 12 01 c0 5a a5 00 7d 00 ee b5 2d 06 ef b5 2e 02 80 0c 8e 2d 8f 2e 75 2b 01 75 2c 00 80 05 e4 f5 2b f5 2c ec b5 2f 06 ed b5 30 02 80 04 ... >
   35.401  4073 W: <Buffer d0 04 d0 05 d0 06 d0 07 d0 83 1c d3 16>
   35.437  4098 W: <Buffer 46 b9 6a 00 4b 12 02 00 5a a5 d0 82 d0 f0 d0 e0 d0 20 32 43 b2 20 53 b1 df 43 b2 04 53 b1 fb e4 f5 27 f5 28 f5 29 f5 2a f5 21 f5 22 85 27 23 85 28 24 ... >
   35.437  4099 W: <Buffer 2e f5 2f f5 30 c2 32 c2 35 d2 21 78 16>
   35.474  4122 W: <Buffer 46 b9 6a 00 4b 12 02 40 5a a5 34 d2 33 43 8f 10 53 89 f0 53 8e 7f 75 8c fc 75 8a 18 ae 8e 43 06 04 8e 8e 75 d7 a0 75 d6 15 d2 a9 43 af 04 d2 8c ae 8e ... >
   35.474  4123 W: <Buffer 27 10 85 28 11 85 29 12 85 2a 1e da 16>
   35.509  4146 W: <Buffer 46 b9 6a 00 4b 12 02 80 5a a5 13 c3 e5 10 9c e5 11 9d e5 12 9e e5 13 9f 40 17 e5 10 c3 9c f8 e5 11 9d f9 e5 12 9e fa e5 13 9f 88 82 89 83 8a f0 22 c3 ... >
   35.509  4147 W: <Buffer 10 fc ed 35 11 fd ee 35 12 fe 28 b4 16>
   35.545  4180 W: <Buffer 46 b9 6a 00 4b 12 02 c0 5a a5 ef 35 13 8c 82 8d 83 8e f0 22 85 82 21 85 83 22 85 27 23 85 28 24 85 29 25 85 2a 26 22 12 02 09 d2 af e4 b5 21 05 b5 22 ... >
   35.545  4181 W: <Buffer 74 02 b5 21 06 e4 b5 22 02 80 18 87 16>
   35.581  4204 W: <Buffer 46 b9 6a 00 4b 12 03 00 5a a5 33 74 03 b5 21 06 e4 b5 22 02 80 3a 80 52 c2 35 c2 32 75 87 02 00 90 00 01 12 02 ca 80 c4 e5 2d 45 2e 24 ff 92 32 e5 2d ... >
   35.581  4205 W: <Buffer e5 2d 45 2e 24 ff 92 32 90 00 19 ec 16>
   35.616  4228 W: <Buffer 46 b9 6a 00 4b 12 03 40 5a a5 03 12 02 ca 80 9c e5 2d 45 2e 24 ff 92 32 e5 2d 45 2e 60 03 02 02 e2 90 00 00 12 02 ca 02 02 e2 90 00 00 12 02 ca 02 02 ... >
   35.616  4229 W: <Buffer a4 d0 f0 25 f0 c5 83 85 10 f0 1d 3b 16>
   35.653  4254 W: <Buffer 46 b9 6a 00 4b 12 03 80 5a a5 a4 25 83 f5 83 22 75 82 00 22 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ... >
   35.653  4255 W: <Buffer ff ff ff ff ff ff ff ff ff ff 3c 12 16>
   35.708  4278 W: <Buffer 46 b9 6a 00 4b 04 00 00 5a a5 ff ff ff 00 ff ff 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 00 ff b7 ff 2d ff c0 ff fd 03 ff ff ff ff ff ff ff ... >
   35.708  4279 W: <Buffer ff ff ff ff ff c2 bf f7 bb 9f 39 fc 16>
   35.932  4318 W: <Buffer 46 b9 6a 00 07 ff 01 70 16>

The code looks like this (does not work)

:04000000020069325F
:03000B000200D21E
:0100130032BA
:01001B0032B2
:0100230032AA
:01002B0032A2
:01003300329A
:01003B003292
:01004300328A
:01004B003282
:030053000200D1D7
:01005B003272
:030063000200F0A8
:0F00C20075316475320075336475340002006661
:030066000202DDB6
:2000D10032C0E0C0D074012527F527E43528F528E43529F529E4352AF52AD0D0D0E032C06E
:2000F10020C0E0C0F0C082C083C007C006C005C004C003C002C001C000C0D075D00885314B
:200111001085321190000975D00012036975D008AE82AF83A234E433F5107511009000647F
:20013100C00FC00E75D00012036975D008AC82AD83D00ED00FEC2EF531ED3FF5328533108B
...
:2002F100B5220280287402B52106E4B5220280337403B52106E4B52202803A8052C235C255
:2003110032758702009000011202CA80C4E52D452E24FF9232E52D452E70B690000212022C
:20033100CA80AED235E52D452E24FF92329000031202CA809CE52D452E24FF9232E52D45F1
:180351002E60030202E29000001202CA0202E29000001202CA0202E275
:06009800E478FFF6D8FD3C
:200076007900E94400601B7A0090038A780175A000E493F2A308B8000205A0D9F4DAF275A3
:02009600A0FFC9
:1D036900E5828510F0A4C582C0F08511F0A4D0F025F0C5838510F0A42583F583223E
:20009E007800E84400600A790175A000E4F309D8FC7800E84400600C7900900001E4F0A360
:0400BE00D8FCD9FA97
:0D006900758134120386E582600302006693
:04038600758200225A
:00000001FF

I was using "pip3 install stcgal" version, but I got the same results with git master-branch version

mosagepa commented 2 years ago

Make sure you're flashing the STC15Ls with 3V3 and not 5V. If they're on a module designed for any particular purpose, check carefully if there's any regulator or what level the VCC to the chip is really being fed.

See e.g.:** Trivial solution to "bricked" STC15s

Kind regards and good luck!

kasbert commented 2 years ago

Well, the programming worked with STC-ISP, so I expect there is a problem with stcgal.

mosagepa commented 2 years ago

Oh I see. Anyway maybe the info I posted is of some relevance with people having issues. Good luck, if you find any solution of course let us know

In my case even after noticing the problem was VCC level, I've found that a lot you can learn about STC protocol just by reading and messing a bit with the Python code. Don't be afraid of doing just that (if you have the time, obviously.)

In any case, the chip initially reporting > 100MHz is quite strange. Revise the code in STGAL that deals with this initial frequency determination. Find thru the Python in 'protocol.py' with the string "stc15apro" and below the first line that matches.

A good trick also when strange freqs. are reported is to try and relaunch the STCGAL command with -l 2400 -b 2400, or just -l 2400. Don't include any -t option initially.

Regards from Spain