IOsetting / stc8prog

Open Source STC8G/STC8H ISP flash tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

STC8G1K08A-8PIN 7.3.12U on MacOS: doesn't flash

Darwinnn opened this issue · comments

Even though macOS isn't supported, I was able to compile the binary using Linux termios.c dep.

Testing on STC8G1K08A-8PIN was initially promising:

./stc8prog -p /dev/cu.usbserial-1440                                         
Opening port /dev/cu.usbserial-1440: done
Waiting for MCU, please cycle power: detected
MCU type: STC8G1K08A-8PIN
Protocol: STC8G/8H
F/W version: 7.3.12U
IRC frequency(Hz): 11061600
Switching to 115200 baud, chip: set, host: set, ping: succ

However, upon trying to flash an actual firmware, I stumbled upon this issue where the MCU just won't reply back:

./stc8prog -p /dev/cu.usbserial-1440 -d -f ../projects/blink/test.hex 
Loading hex file:    Loaded 134 bytes between: 0000 to 0085
02 00 06 02 00 6F 75 81 07 12 00 82 E5 82 60 03 02 00 03 79 00 E9 44 00 60 1B 7A 00 90 00 86 78 00 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 00 75 A0 00 E4 F3 09 D8 FC 78 00 E8 44 00 60 0C 79 00 90 00 00 E4 F0 A3 D8 FC D9 FA 02 00 03 7F 36 7E 0E 7D 1D DF FE DE FC DD FA 22 53 B1 F7 43 B2 08 B2 B3 12 00 62 12 00 62 12 00 62 80 F3 75 82 00 22 
Opening port /dev/cu.usbserial-1440: done
Waiting for MCU, please cycle power: .............................................................................................................................................................read 3 bytes:
0x46 | flag:1
0xb9 | flag:2
0x68 | flag:3
read 3 bytes:
0x00 | flag:4
0x38 | sum:00A0, count:50, index:0 flag:5
0x50 | sum:00F0, index:1, count:50 flag:5
read 3 bytes:
0x00 | sum:00F0, index:2, count:50 flag:5
0xa8 | sum:0198, index:3, count:50 flag:5
0xc9 | sum:0261, index:4, count:50 flag:5
read 3 bytes:
0x60 | sum:02C1, index:5, count:50 flag:5
0x99 | sum:035A, index:6, count:50 flag:5
0x00 | sum:035A, index:7, count:50 flag:5
read 2 bytes:
0x02 | sum:035C, index:8, count:50 flag:5
0xff | sum:045B, index:9, count:50 flag:5
read 3 bytes:
0xff | sum:055A, index:10, count:50 flag:5
0xff | sum:0659, index:11, count:50 flag:5
0xbf | sum:0718, index:12, count:50 flag:5
read 2 bytes:
0xff | sum:0817, index:13, count:50 flag:5
0x26 | sum:083D, index:14, count:50 flag:5
read 3 bytes:
0xea | sum:0927, index:15, count:50 flag:5
0xf7 | sum:0A1E, index:16, count:50 flag:5
0x20 | sum:0A3E, index:17, count:50 flag:5
read 2 bytes:
0x73 | sum:0AB1, index:18, count:50 flag:5
0x55 | sum:0B06, index:19, count:50 flag:5
read 3 bytes:
0x00 | sum:0B06, index:20, count:50 flag:5
0xf7 | sum:0BFD, index:21, count:50 flag:5
0x94 | sum:0C91, index:22, count:50 flag:5
read 3 bytes:
0x0c | sum:0C9D, index:23, count:50 flag:5
0x8a | sum:0D27, index:24, count:50 flag:5
0x16 | sum:0D3D, index:25, count:50 flag:5
read 2 bytes:
0x97 | sum:0DD4, index:26, count:50 flag:5
0xbf | sum:0E93, index:27, count:50 flag:5
read 3 bytes:
0x10 | sum:0EA3, index:28, count:50 flag:5
0x20 | sum:0EC3, index:29, count:50 flag:5
0x20 | sum:0EE3, index:30, count:50 flag:5
read 2 bytes:
0xff | sum:0FE2, index:31, count:50 flag:5
0x00 | sum:0FE2, index:32, count:50 flag:5
read 2 bytes:
0x30 | sum:1012, index:33, count:50 flag:5
0x00 | sum:1012, index:34, count:50 flag:5
read 3 bytes:
0x20 | sum:1032, index:35, count:50 flag:5
0x04 | sum:1036, index:36, count:50 flag:5
0xa5 | sum:10DB, index:37, count:50 flag:5
read 2 bytes:
0x21 | sum:10FC, index:38, count:50 flag:5
0x07 | sum:1103, index:39, count:50 flag:5
read 3 bytes:
0x02 | sum:1105, index:40, count:50 flag:5
0x01 | sum:1106, index:41, count:50 flag:5
0xff | sum:1205, index:42, count:50 flag:5
read 2 bytes:
0x65 | sum:126A, index:43, count:50 flag:5
0x1c | sum:1286, index:44, count:50 flag:5
read 3 bytes:
0x43 | sum:12C9, index:45, count:50 flag:5
0x6d | sum:1336, index:46, count:50 flag:5
0x89 | sum:13BF, index:47, count:50 flag:5
read 2 bytes:
0xa2 | sum:1461, index:48, count:50 flag:5
0xd0 | sum:1531, index:49, count:50 flag:5
read 3 bytes:
0xd0 | sum:1601, index:50, count:50 flag:6
0x16 | sum: 0x16 flag:7
0x01 | sum check: 0x01 flag:8
read 1 bytes:
0x16 | end byte reached flag:9
50 00 A8 C9 60 99 00 02 FF FF FF BF FF 26 EA F7 20 73 55 00 F7 94 0C 8A 16 97 BF 10 20 20 FF 00 30 00 20 04 A5 21 07 02 01 FF 65 1C 43 6D 89 A2 D0 D0 
detected
MCU type: STC8G1K08A-8PIN
Protocol: STC8G/8H
F/W version: 7.3.12U
IRC frequency(Hz): 11061600
Switching to 115200 baud, chip: TX: 46 B9 6A 00 0E 01 60 40 FF CC 00 00 97 03 7B 16 
........read 1 bytes:
0x46 | flag:1
read 3 bytes:
0xb9 | flag:2
0x68 | flag:3
0x00 | flag:4
read 2 bytes:
0x07 | sum:006F, count:1, index:0 flag:5
0x01 | sum:0070, index:1, count:1 flag:6
read 2 bytes:
0x00 | sum: 0x00 flag:7
0x70 | sum check: 0x70 flag:8
read 1 bytes:
0x16 | end byte reached flag:9
01 
set, host: set, ping: TX: 46 B9 6A 00 0B 05 00 00 5A A5 01 79 16 
.read 9 bytes:
0x46 | flag:1
0xb9 | flag:2
0x68 | flag:3
0x00 | flag:4
0x07 | sum:006F, count:1, index:0 flag:5
0x05 | sum:0074, index:1, count:1 flag:6
0x00 | sum: 0x00 flag:7
0x74 | sum check: 0x74 flag:8
0x16 | end byte reached flag:9
05 
succ
Writing flash, size 134:   0.00%TX: 46 B9 6A 00 8B 22 00 00 5A A5 02 00 06 02 00 6F 75 81 07 12 00 82 E5 82 60 03 02 00 03 79 00 E9 44 00 60 1B 7A 00 90 00 86 78 00 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 00 75 A0 00 E4 F3 09 D8 FC 78 00 E8 44 00 60 0C 79 00 90 00 00 E4 F0 A3 D8 FC D9 FA 02 00 03 7F 36 7E 0E 7D 1D DF FE DE FC DD FA 22 53 B1 F7 43 B2 08 B2 B3 12 00 62 12 00 62 12 00 62 38 43 16 
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
TX: 46 B9 6A 00 11 22 00 80 5A A5 80 F3 75 82 00 22 04 A8 16 
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
.read nothing
 done

Additionally I tested the erase feature, which actually worked.
I flashed a simple blinky via STC-ISP and after erasing it stopped executing, so I assume it actually erased the flash contents:

./stc8prog -p /dev/cu.usbserial-1440 -e -d 
Opening port /dev/cu.usbserial-1440: done
Waiting for MCU, please cycle power: ..........................................................................................read 1 bytes:
0xff | flag:0
......................................................read 3 bytes:
0x46 | flag:1
0xb9 | flag:2
0x68 | flag:3
read 2 bytes:
0x00 | flag:4
0x38 | sum:00A0, count:50, index:0 flag:5
read 3 bytes:
0x50 | sum:00F0, index:1, count:50 flag:5
0x00 | sum:00F0, index:2, count:50 flag:5
0xa8 | sum:0198, index:3, count:50 flag:5
read 2 bytes:
0xc9 | sum:0261, index:4, count:50 flag:5
0x60 | sum:02C1, index:5, count:50 flag:5
read 2 bytes:
0x99 | sum:035A, index:6, count:50 flag:5
0x00 | sum:035A, index:7, count:50 flag:5
read 3 bytes:
0x02 | sum:035C, index:8, count:50 flag:5
0xff | sum:045B, index:9, count:50 flag:5
0xff | sum:055A, index:10, count:50 flag:5
read 2 bytes:
0xff | sum:0659, index:11, count:50 flag:5
0xbf | sum:0718, index:12, count:50 flag:5
read 3 bytes:
0xff | sum:0817, index:13, count:50 flag:5
0x26 | sum:083D, index:14, count:50 flag:5
0xea | sum:0927, index:15, count:50 flag:5
read 2 bytes:
0xf7 | sum:0A1E, index:16, count:50 flag:5
0x20 | sum:0A3E, index:17, count:50 flag:5
read 2 bytes:
0x73 | sum:0AB1, index:18, count:50 flag:5
0x55 | sum:0B06, index:19, count:50 flag:5
read 3 bytes:
0x00 | sum:0B06, index:20, count:50 flag:5
0xf7 | sum:0BFD, index:21, count:50 flag:5
0x94 | sum:0C91, index:22, count:50 flag:5
read 2 bytes:
0x0c | sum:0C9D, index:23, count:50 flag:5
0x8a | sum:0D27, index:24, count:50 flag:5
read 3 bytes:
0x16 | sum:0D3D, index:25, count:50 flag:5
0x97 | sum:0DD4, index:26, count:50 flag:5
0xbf | sum:0E93, index:27, count:50 flag:5
read 3 bytes:
0x10 | sum:0EA3, index:28, count:50 flag:5
0x20 | sum:0EC3, index:29, count:50 flag:5
0x20 | sum:0EE3, index:30, count:50 flag:5
read 3 bytes:
0xff | sum:0FE2, index:31, count:50 flag:5
0x00 | sum:0FE2, index:32, count:50 flag:5
0x30 | sum:1012, index:33, count:50 flag:5
read 2 bytes:
0x00 | sum:1012, index:34, count:50 flag:5
0x20 | sum:1032, index:35, count:50 flag:5
read 3 bytes:
0x04 | sum:1036, index:36, count:50 flag:5
0xa5 | sum:10DB, index:37, count:50 flag:5
0x21 | sum:10FC, index:38, count:50 flag:5
read 2 bytes:
0x07 | sum:1103, index:39, count:50 flag:5
0x02 | sum:1105, index:40, count:50 flag:5
read 3 bytes:
0x01 | sum:1106, index:41, count:50 flag:5
0xff | sum:1205, index:42, count:50 flag:5
0x65 | sum:126A, index:43, count:50 flag:5
read 2 bytes:
0x1c | sum:1286, index:44, count:50 flag:5
0x43 | sum:12C9, index:45, count:50 flag:5
read 2 bytes:
0x6d | sum:1336, index:46, count:50 flag:5
0x89 | sum:13BF, index:47, count:50 flag:5
read 3 bytes:
0xa2 | sum:1461, index:48, count:50 flag:5
0xd0 | sum:1531, index:49, count:50 flag:5
0xd0 | sum:1601, index:50, count:50 flag:6
read 2 bytes:
0x16 | sum: 0x16 flag:7
0x01 | sum check: 0x01 flag:8
read 1 bytes:
0x16 | end byte reached flag:9
50 00 A8 C9 60 99 00 02 FF FF FF BF FF 26 EA F7 20 73 55 00 F7 94 0C 8A 16 97 BF 10 20 20 FF 00 30 00 20 04 A5 21 07 02 01 FF 65 1C 43 6D 89 A2 D0 D0 
detected
MCU type: STC8G1K08A-8PIN
Protocol: STC8G/8H
F/W version: 7.3.12U
IRC frequency(Hz): 11061600
Switching to 115200 baud, chip: TX: 46 B9 6A 00 0E 01 60 40 FF CC 00 00 97 03 7B 16 
........read 2 bytes:
0x46 | flag:1
0xb9 | flag:2
read 2 bytes:
0x68 | flag:3
0x00 | flag:4
read 3 bytes:
0x07 | sum:006F, count:1, index:0 flag:5
0x01 | sum:0070, index:1, count:1 flag:6
0x00 | sum: 0x00 flag:7
read 2 bytes:
0x70 | sum check: 0x70 flag:8
0x16 | end byte reached flag:9
01 
set, host: set, ping: TX: 46 B9 6A 00 0B 05 00 00 5A A5 01 79 16 
.read 9 bytes:
0x46 | flag:1
0xb9 | flag:2
0x68 | flag:3
0x00 | flag:4
0x07 | sum:006F, count:1, index:0 flag:5
0x05 | sum:0074, index:1, count:1 flag:6
0x00 | sum: 0x00 flag:7
0x74 | sum check: 0x74 flag:8
0x16 | end byte reached flag:9
05 
succ
Erasing chip: TX: 46 B9 6A 00 0B 03 00 00 5A A5 01 77 16 
...............read 16 bytes:
0x46 | flag:1
0xb9 | flag:2
0x68 | flag:3
0x00 | flag:4
0x0e | sum:0076, count:8, index:0 flag:5
0x03 | sum:0079, index:1, count:8 flag:5
0xf7 | sum:0170, index:2, count:8 flag:5
0x94 | sum:0204, index:3, count:8 flag:5
0xc3 | sum:02C7, index:4, count:8 flag:5
0xa9 | sum:0370, index:5, count:8 flag:5
0x08 | sum:0378, index:6, count:8 flag:5
0x27 | sum:039F, index:7, count:8 flag:5
0xde | sum:047D, index:8, count:8 flag:6
0x04 | sum: 0x04 flag:7
0x7d | sum check: 0x7D flag:8
0x16 | end byte reached flag:9
03 F7 94 C3 A9 08 27 DE 
succ

I know it was never stated that this was supposed to work on macOS, but maybe it's not something macOS related or the problem is something really simple that we can easily fix. I can assist from my side in case you need any further details or help.
Thanks!

EDIT: I've also tried using different baudrates from 300 up to 115200, didn't help.

It is possibly a known issue, please try flashing with -e argument, something like

./stc8prog -p /dev/ttyUSB0 -e -f foo.hex

I don't have a macbook at hand so if the above change doesn't work, I may need other people's help.

That actually worked!

./stc8prog -p /dev/cu.usbserial-1440 -e -f ../projects/blink/test.hex 
Loading hex file:    Loaded 134 bytes between: 0000 to 0085
Opening port /dev/cu.usbserial-1440: done
Waiting for MCU, please cycle power: detected
MCU type: STC8G1K08A-8PIN
Protocol: STC8G/8H
F/W version: 7.3.12U
IRC frequency(Hz): 11061600
Switching to 115200 baud, chip: set, host: set, ping: succ
Erasing chip: succ
Writing flash, size 134: 100.00% done

Thank you very much for helping out! Since this now works on macOS I'll be pushing a PR containing little fixes I made for this to compile properly (on macOS).

You are welcome~