-
Notifications
You must be signed in to change notification settings - Fork 1
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
Can't read flash twice or more consecutively #2
Comments
BTW, I have tried with a real stlinkv2 which works well. Logs are attached for your reference:
|
Hi @llinjupt, thanks for using my project! Cheers,
|
THX for your rapid response. I have just cloned stm8flash form https://github.com/vdudouyt/stm8flash and enabled the DEBUG option, and logs attached:
After simply analysing, I realized It seems related to swim_update(), so I just updated swim_init(true) to swim_init(false) to disable async mode and It worked. Of course the details need more effort to dig out if I have time I will try. BTW, It seems that you did that in a linux-like system. Would you like to try it on Window10? |
Hi @stefaandesmet2003 stefaandesmet2003. I have just verified on Ubuntu and it's ok under async mode. So things become a bit clear that it should be related to the Win10 OS (maybe usb transfer related, just guess). Logs:
|
In your case the swim entry sequence seems to go wrong. The return code of swim_doEntrySequence() is not checked at the moment, so the error is not reported on the 'read status' immediately after. But any subsequent WOTF/ROTF will fail because the stm8 target isn't ready to accept swim commands (in your log the write to SWIM_CSR fails) I remember having had problems initially with generating the swim entry sequence, but after rewriting the delayMicroseconds() code, it worked reliably for me. This is of course linked to the stm32 only, and doesn't explain why it works on linux for you, and not on windows. but you might want to check the swim signal with a logic analyzer, or test with different stm8 targets. I tried on windows10 just now, rebuilt stm8flash under cygwin, but so far I don't manage to reproduce your error. sorry!
|
@stefaandesmet2003 Sound strange. How to explain swim_init(false) worked in the same environment? In this case writing SWIM_CSR didn't fail. I tried on another PC instead of my notebook just now and the same case happened as well. And the precompiled stm8flash and firmwares are attached below to see if it's convinent for you to reproduce your side. If I have spare time, I will check the code carefully and do more anyalysis with a scope to see what's going on there. Thanks anyway. |
I can't explain the difference in behaviour for you between sync and async. The purpose of async mode is to enable the PC (stm8flash) to keep inquiring READ_STATUS over usb, while the stm32 is reading/writing data over swim. In sync mode the ROTF/WOTF are blocking, and the host USB is waiting (NACK on the usb pipe) until the transfer is completed. the stm8flash.exe won't run on my win10 machine (the application was unable to start correctly...) |
Yes, in both async/no async modes, the first time to read always dump out this info:
For aysnc mode firmware, the second time to read quit after dumpping out "SWIM error 0x04". |
Hi @llinjupt, the logic analyzer shows that the first WOTF command is aborted, although the target acks correctly I added a bugfix branch. Would you be so kind to test it? It works for me, although I don't fully understand yet why. It may be linked to a small bug in swim_doEntrySequence() that is still there : when the target stm8 is already in swim mode (on your second run), it acks every pulse of the entry sequence (interprets it as swim resets), so you see about 20 pulses, but only 10 DMA's requested. Maybe this situation ripples through to the next use of DMA (where the error occurs), although the DMA channel has been disabled/enabled in between. |
Sorry for my mistake that I shoule have mentioned that I compiled with Msys2 directly rather than platformIO which is not avaliable here for some reasons I don't know. Refering to https://github.com/libopencm3/libopencm3-template and put your code into my-project, following the instructions in README.md, I got the bin file at last. So I checked rules.mk deployed in libopencm3-template and found below lines just as you guessed:
And the size of the bin file grew bigger to be about 18KB instead of the original 15KB.
Yeah, as long as I removed -Os, it worked without touching any code.
Actually I noticed this queer waveform at the very beginning, but I didn't know why it happend for no such info mentioned in UM0470.pdf. Now it made sense to me as you said the entry sequence interpreted as resets when in swim mode already. And I confirmed that even with the real stlinkv2, the waveform is still the same. But stlinkv2 is able to get over it. If there is a way to know whether it is in swim mode, there is no need to call swim_doEntrySequence() again. IMHO, volatile has noting to do with DMA. After finishing the work on my hand, I'd like to do further analysis and give some useful feedback I hope. |
Hi @stefaandesmet2003, A normal request and ack include 10 pulses, but an abnormal one includes 18 pulses (it acks every pulse). But swim_doEntrySequence() always try to sample in10 pulses. So if it's in SWIM mode the left 8 pulses are still on going when the next wtof cmd comes (cause it's in aysnc mode) and the left pulses are captured wrongly (actually only the last pulse is captured at my side looking at the waveform. And it's releated to the period of code excuting. So that's why the memset you added would solve this problem cause it introduced a tiny delay that just luckly got rid of the last pulse. And the same idea is why -Os brought this issue as well.). The simple solution is just to add below lines at the end of swim_doEntrySequence(void):
|
Thanks for your work @llinjupt ! |
Yes, here it worked well.
There's no busy-waiting and only 10 pulses are handled before extra pulses consumption. And actully it doesn't try to really catch all left 8 pulses completely but just gets rid of these pulses.
Looking forward to your solution. |
Hi stefaandesmet, first thanks for your work and it's interesting and helpful. I am not sure if it's a bug that
I can't read the taget MCU (STM8S105KCT6) twice like below:
But in the same environment writing twice is OK. Once the error occurs tring to write will fail as well. The only way to solve it is to repower the target MCU. THX again.
The text was updated successfully, but these errors were encountered: