-
Notifications
You must be signed in to change notification settings - Fork 141
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
Unable to upload to STC15L2K32S2 #8
Comments
I haven't really tested stcgal on OS X, so...
Maybe you could also verify that this isn't an OS specific issue by using another PC with Linux or Windows. |
For me at least, on Mac with cp2102 uart and stc15f204ea, I have to set both handshake and transfer speeds to 9600. Nothing else will work. I don't have the problem with same chip and uart on Linux. For whatever reason |
These problems can be caused by bad drivers and certain buggy versions of pyserial. The latest version 3.01 of pyserial should be fine. |
Just an update... Tried pyserial 3.01, and no change for my case - still have to use 9600/9600. |
Thank you for your prompt response and trying to help! I did try using ISP.exe on a windows vm using the same usb serial adapter with the same binary and that was successful. I'm also using python under OSX to flash ESP8266 using the same usb adapter, so I know the hardware can work (most of the time ;-) ). Tried with stcgal with 9600/9600:
and made sure I'm using pyserial 3.0.1 but get the same message as in the original post. It looks like it fails in the |
another stab in the dark: |
Other protocols definitely won't work, not much use trying. The BSL/bootloader on your device requires stc15. If flashing works with the VM, maybe you can get a dump of the serial traffic? Maybe there's something special about your device. |
Hey all, I'm having similar issues with my setup. Linux, CH340 UART, pySerial 3.0.1. I don't have any alternative UARTs at the moment unless I can figure out how to make this work with a bus pirate. I've tried different baud rates from 9600 to 57600, matching handshake and protocol baud, and the alternative stc12a protocol. Haven't found any combination that works so far. Is it possible to write protect STC MCUs?
|
@rfb This problem does not seem to be related, please open a separate issue. The stc12 protocol is quite a bit different. That said, the current Linux driver for ch340 is very buggy. I have several improvements lined up that I'm going to submit for inclusion in the Linux kernel as I have a number of these UARTs. If you are willing to try compiling a Linux kernel with these improvements, I can forward a patch set or publish a branch. |
Thanks @girgoirg, I'll open another ticket. Yes, I'm happy to try one of the kernel patches. |
@Mrnt any changes with the current version of stcgal? Perhaps try with another UART, updated drivers or Linux. |
@grigorig sorry for the delay in responding. I pulled the latest stcgal and then also set it up on my Windows VM and tried using it to flash from the Windows VM. The good news is that using the same version of pyserial with the same USB/serial adapter, stc gal worked under Windows VM. However it still does not work under OSX for some reason, I even tried updated Prolific drivers for OSX. I noticed that the info packet when using stcgal under the Windows VM is slightly different than under OSX which seems odd to me. I'm including the debug output here to see if this makes any sense to you: ***** WINDOWS start ***** ***** OSX start ***** |
Thanks, that is valuable feedback. The slight differences in the info packet are fine. The info packet includes some timing measurements based on the serial baudrate. These are used to determine the clock frequency of the MCU. Clocks of both serial adapter and MCU jitter and depend on operating conditions, so these differences are expected. Of course it is rather unfortunate that there is an incompatibility with OS X. Maybe I can ask some of my colleagues with Mac computers to get this fixed. If I have anything specific for you to test, I'll post it here. |
I am also having this issue on OSX using a Prolific adapter. No joy at all with an FTDI adapter. Johns-MacBook-Pro:stc_diyclock john$ stcgal -p /dev/cu.usbserial -b 115200 -b 9600 -l 9600 main.hex |
Can you please try again with the dump option (-D)? I have a hunch it's related to baud rate changes, but I'd like to verify. |
Thanks for the swift response: Johns-MacBook-Pro:stc_diyclock john$ stcgal -p /dev/cu.usbserial -D -b 9600 -l 9600 main.hex |
Scratch that, baud rate changes only happen later. I suspect it's some buffering issue with OSX drivers or pyserial. Can you try these workarounds:
|
Something else to try:
|
I am not sure I have made the correct change. I have changed line 163 in protocols.py to:
` def pulse(self, character=b"\0xfe", timeout=0):`
AFter doing this i get streams of characters:
<- Packet data: FC
<- Packet data: FC
This continues and the request to power cycle the processor doesn't wait. The particular character output varies depending on the baud rate selected by -b. The above at 9600 and below at 19200 default.
Johns-MacBook-Pro:stc_diyclock john$ stcgal -p /dev/cu.usbserial -D main.hex
Waiting for MCU, please cycle power: <- Packet data: C0
<- Packet data: FE
<- Packet data: 80
<- Packet data: FE
<- Packet data: 80
<- Packet data: FE
<- Packet data: 80
<- Packet data: FE
<- Packet data: 80
<- Packet data: FE
<- Packet data: 80
<- Packet data: FE
<- Packet data: 80
<- Packet data: FE
<- Packet data: 80
<- Packet data: FE
<- Packet data: 80
<- Packet data: FE
<- Packet data: 80
<- Packet data: FE
|
the above using your osx-fix branch. |
I have loaded up stcgal on a Win7 machine to prove the stc15w408as hardware. The hardware is good and I can program the chip under Win7. Still unable to program using OSX. |
if using pl2303 on mac, are you sure it's geniune pl2303? I have seen some problems with clone chipsets while working on chirp project... (I guess the deciding factor is if you had to rollback the prolific driver on win7 to a previous version to get it to work) Unsure if this is valid for later versions of macos... |
Oh, interesting @zerog2k. I hope it's a driver issue because the dumps don't make much sense. |
I have tried the the open driver and still have an issue. I have also tried with two FTDI serial adapters and can't get past "Waiting for MCU, please cycle power: " with those two. I have finally located an English version of STC-ISP, again only Windows but it does allow setting the clock speed to 22.1184 Mhz which doesn't appear possible with the -t command. Johns-MacBook-Pro:stc-led-clock john$ stcgal -D -p /dev/cu.usbserial main.hex |
curious, can you run wine on your mac? Their latest stc-isp software in english is here: |
I have just installed VirtualBox on my Mac and loaded a copy of Win7. STC-ISP works OK. |
That should work fine. Note that you need to specify the clock in KHz, not MHz. Anyway, I'm not sure this is just one issue. There appears to be driver trouble, or something along these lines, with various serial adapters on OSX. On the other hand, it's possible that the new firmware/BSL (7.2.5) has some incompatibilities as well, so stcgal needs to be updated. I'll order some new chips. If I get chips with the new BSL, it should be possible to update stcgal. It might also help if you can provide dumps of the serial port traffic when running with STC-ISP (where everything seems to work for you). |
If I remember correctly, there are some problems with some usb-serial drivers, when switching baudrate. It brought me a LOT of pain when i was hacking my own stc programming solution. The problem behind it is that the kernel driver switches the baudrate BEFORE all bytes are out of the hardware fifo. This can be easily picked by a logic analyzer. The workarounds are:
@grigorig - FYI this is my implementation of the hack: https://github.com/nekromant/stcdude/blob/7af99a6dcea2e5b721398cf36ed6e955f455e06a/src/stcdude.c#L85 this may need to be adjusted a bit to be ported to stcgal. i'll see if i find one of those 'broken' serial dongles to give it a spin. |
I don't like such hacks, but with all these various issues, it seems like a good idea to implement such a delay. Thanks for the pointer. |
@grigorig The worst part of this hack is, that it has to be applied either manually (thus spoiling user experience), or to certain combinations of usb2uart dongles/OS (even OS versions), and that's another list to maintain. ;( The delay calculated in stcdude's code should be okay for CP2103 and linux (If I'm not mistaken, it's been some 4 years already). |
Well, or maybe just use a safe default delay that is so high that it'll always work? Well, that would suck. But we don't actually need to wait after sending every packet, like stcdude does it. It's good enough to wait before a baud rate switch or after every byte sent when "pulsing". Note that the USB protocol support extensively uses the "safe delay" approach: the bootloader won't react to anything over USB while it is flashing, so you have to wait for a "safe" time when flashing a block or you'll just get USB errors. |
Actually there's already a delay in place of 0.2 seconds before every baud rate change after a write. That should be good enough for badly behaved serial drivers even at low baud rates with the typical packet sizes used when switching the baud rate. |
I don't really remember why I've put the delay there, so that it would delay after every packet, most likely it was just a "temporary" hack. I can recommend allowing user to tune the delay via commandline and see if it affects behavior. If I remember correctly, if the delay is too long, things break as well, and that is all baudrate-dependant, hence I've come up with that mostly 'trial-and-error' formula. 0.2 seconds seems like a lot to me. |
Yeah, it might be too long - I'm going to replace it with a calculated delay. That'll also speed up stcgal and that is of course always a plus. |
LwwdeMacBook-Air:桌面lww $ stcgal -a -P stc89 -p /dev/tty.wchusbserial1410 main.ihx -D |
1 similar comment
LwwdeMacBook-Air:桌面lww $ stcgal -a -P stc89 -p /dev/tty.wchusbserial1410 main.ihx -D |
It just can't stop.What's wrong...555 |
I think I have pinpointed a possible reason acounting for this issue. I tried STCGAL on an ARM board running linux, and it failed with "Trimming frequency: Serial port error: pulse timeout". I noticed that the speed of "print" is quite different between ARM board and Desktop Linux, so I added some debug codes as:
Then, I used the same command to run STCGAL on both ARM board and Desktop Linux platforms: On ARM board: On Desktop Linux: By adding a delay to STCGAL on Desktop Linux like this:
then the STCGAL cannot work on Desktop Linux either! I guess, the "print" function takes too much time on some platforms that the STC chip detects a timeout. I also notice that this timeout tolerance varies with different handshake baudrate. Specifically, the tolerance is about 0.1 second under -l 115200 and about 0.6 second under -l 2400. Hope my rely can help a bit! @grigorig |
Thank you so much for developing this tool!
I am having a little trouble getting it to work with a STC15L2K32S2 with a PL2303 on OSX. It appears to detect the chip correctly:
However, when I attempt to flash it using the blinky sample I am seeing this:
and stcgal bails.
I'm a newbie to programming the STC chips so I apologize if this is user error.
The text was updated successfully, but these errors were encountered: