Comments (8)
I failed to find the root of the problem by the moment but I've found out the following information. I hope it is useful.
I checked the code of "st-flash" utility and found out the following. It loops forever in
stlink_erase_flash_page() -> stlink_wait_flash_busy(). when it is called here
/* start erase operation, reset by hw with bsy bit */
set_flash_cr_strt(sl);
/* wait for completion */
wait_flash_busy(sl); <- this line is 1070
/* relock the flash */
lock_flash(sl);
I tried adding some delay in the following way:
static void wait_flash_busy(stlink_t sl) {
/ todo: add some delays here */
while (is_flash_busy(sl))
usleep( 100000 ); <- this line.
}
but it doesn't help. read_flash_sr(sl) result is always 3 and "read_flash_sr(sl) & (1 << FLASH_SR_BSY)" is 1 respectively.
It seems previous operations in stlink_erase_flash_page() are wrong a bit:
/* unlock if locked */
unlock_flash_if(sl);
/* set the page erase bit */
set_flash_cr_per(sl);
/* select the page to erase */
write_flash_ar(sl, flashaddr);
/* start erase operation, reset by hw with bsy bit */
set_flash_cr_strt(sl);
from stlink.
Can you run in the debugger and make sure that in is_flash_busy() the F2/F4 code path is not taken. Perhaps we somehow decipher the chip_id wrong.
gdb st-flash
b is_flash_busy
r write 0x80000000
and when is_flash_busy is hit check the chip_id
Hope this helps.
from stlink.
Thank you very much for reply!
It seems to me F2/F4 path is not taken. I followed "st-flash" line by line with GDB and the path taken in function stlink_erase_flash_page(...) is the following:
else if (sl->core_id == STM32VL_CORE_ID)
{
/* wait for ongoing op to finish */
wait_flash_busy(sl);
/* unlock if locked */
unlock_flash_if(sl);
/* set the page erase bit */
set_flash_cr_per(sl);
/* select the page to erase */
write_flash_ar(sl, flashaddr);
/* start erase operation, reset by hw with bsy bit */
set_flash_cr_strt(sl);
/* wait for completion */
wait_flash_busy(sl);
/* relock the flash */
lock_flash(sl);
}
The routine loops infinitely in second from the bottom function wait_flash_busy(sl). In this function (wait_flash_busy(...)) result coming from ST-LINK is 3 and 0 bit is checked. So result is always 3 & (1 << 0) = 1. In is_flash_busy(...) second path takes place, e.i.
else
return read_flash_sr(sl) & (1 << FLASH_SR_BSY);
I try checking if sector erase procedure corresponds documentation. I've found something related to FLASH in PM0075 "STM32F10xxx Flash memory microcontrollers". Is it a correct place to compare? I've compared FLASH erase procedure with one from PDF. It looks like they match. FLASH_KEYR, FLASH_CR, FLASH_SR, FLASH_AR and all appropriate bits also match.
from stlink.
Here I tested the stlink-v1 with the stm32-discovery. The STM32F100 RBT6 on that board is also a medium density device, but flash programming is covered by pm0063 versus pm0075 for 101/102/103/105/107. Reference manual is rm0041 versus rm0008. I also programmed STM32F105RC with a standalone STLINK. But this is a connectivity line part. So check for subtile difference in medium size F100 and medium size F102 programming.
B.t.w: Perhaps cabling has some influence. Is it short and sensible? Do you have access to a standalone STLINK to compare?
from stlink.
I've compared pm0063 with pm0075. It looks like procedures are the same. Registers and bits involved are the same as well.
As for cable, at the moment it is about 9 cm long. I may play with it and I think I may make it as short as about 2 cm. The strange issue is that is is flashed very well with Atollic GDB server from one hand. And from the other hand FLASH content remains completely unchanged after erase attempt either with "st-flash" or "st-util"-"arm-none-eabi-gdb" couple.
Unfortunately, I don't have ST-LINK with stm32Fxxx, only with stm32Lxxx. With it I experience no problems. But flashing procedures are different in this case.
Anyway, I'll try very short cable and report about results.
from stlink.
9 cm is really short ;-)
I don't think making the cableeven shorter will help. And I compared pm0063 with pm0075 too and found no difference too. Do you have access to a scope or logic analyser?
Other idea: Does Atollic perhaps set some option bit? Erase the device with Attollic and try to program, erase and program with st-flash. If that works, try to find the offending option bit and make st-flash emit some warning.
from stlink.
Hello!
I'm very surprised but today board's managed to be flashed by st-flash. What's changed? I've soldered nokia 3310 screen to it :)
The situation is the following. With Atollic GDB server it still flashes with 100% probability. With st-flash from here https://github.com/texane/stlink sometimes it doesn't. Success probability is about 60-70%.
I've added a few improvements (at least I think these are improvements) to flashing routines such as maximum wait time, return in the case of failures at a step with a result where it concerns flash erase and fixed function name in log message. I've no idea why, but flashing probability with it is also 100%. It might be because of optimization off and additional usleep()s between USB queries related to flash busy checks.
Anyway, if my modifications look usefull it might be it would nice to merge them. The branch I've created is the following: [email protected]:z80/stlink.git.
from stlink.
Problem has been solved.
No patch necessary as modification is user-specific and has therefore not been submitted.
from stlink.
Related Issues (20)
- Cmake minimal version mismatch HOT 1
- Debian 11 x64 doesn't work with v1.8.0 because of incompatible glibc HOT 3
- When I build stlink on windows, it says libusb not found HOT 1
- [feature] Just a question .. about next release and ... clones ... HOT 2
- CH32F103C8T6: Flashing fails because of timeout HOT 1
- [feature] Nucleo-H563ZI Board not recognized HOT 6
- [STM32L4R5ZI]: gdb-multiarch uses wrong osabi
- [STM32L471RG]: STLINKV3 : can't flash the device. Programmer not supported ? HOT 2
- st-util is very slow when stepping through code HOT 2
- [feature] Workflow w/ RAM uploads and SWO
- v1.8.0 is very slow stepping through code HOT 1
- [feature] Adding a graceful way for st-util to exit
- [STM32H573]: Reports chipid 0x000 HOT 1
- [STLINK-V3-SET]: If the device fails to enter SWD mode, the usb device is not released HOT 4
- [st-trace] Bug in function static bool read_trace( ) HOT 1
- [STM32H753ZIT6]: ERROR common_flash.c: Failed to unlock flash option! HOT 1
- [STM32 F407VET6]: WARN usb.c: skipping ST device: 0x483:0x5720 HOT 1
- STM32G491: programming flash error, non-erased value. (was #1310) HOT 3
- [installation]: Unable to install stlink in ubuntu based devcontainer HOT 1
- [STM32L41x_L42x]: Read option bytes is getting into error unexpectedly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stlink.