Skip to content
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

Timing issue when reading the STM32L431 flash size gets result 0 #801

Closed
6 tasks done
bmarvo opened this issue May 8, 2019 · 10 comments · Fixed by #1071
Closed
6 tasks done

Timing issue when reading the STM32L431 flash size gets result 0 #801

bmarvo opened this issue May 8, 2019 · 10 comments · Fixed by #1071

Comments

@bmarvo
Copy link

bmarvo commented May 8, 2019

  • Programmer/board type: Stlink/v2
  • Programmer firmware version: V2J29S7 (what st-link utility says)
  • Operating system: Windows 10 Pro
  • Stlink tools version and/or git commit hash: git-cf67780
  • Stlink commandline tool name: st-info
  • Target chip (and optional board): STM32L431CC (custom board)

Flash size for STM32L431 reads 0.

Output:

C:\Development\stlink\scripts>st-info.exe --flash
0x0

I did some digging and found that I was able to get the flash size to read correctly every time by adding a delay before the read in common.c :

// These are fixed...
sl->flash_base = STM32_FLASH_BASE;
sl->sram_base = STM32_SRAM_BASE;
delay(10);
stlink_read_debug32(sl,(params->flash_size_reg) & ~3, &flash_size);
if (params->flash_size_reg & 2)
    flash_size = flash_size >>16;
flash_size = flash_size & 0xffff;

With the delay:

C:\Development\stlink\scripts>st-info.exe --flash
0x40000

The delay is 10 milliseconds, but I just arbitrarily chose it.

I should also note that all other parameters (sram size, chip id, etc.) seem to read just fine as is.

@xor-gate
Copy link
Member

This is really weird, by changing timing it works.

@xor-gate
Copy link
Member

What is your libusb version, and which platform are you using e.g mingw, cygwin, visual studio?

@bmarvo
Copy link
Author

bmarvo commented May 13, 2019

libusb version 1.0.22

I have tested with MinGW-w64 and Visual Studio 2017. Same issue with both. Same fix works with both as well.

I will try building with GCC on Linux to see if I have the same issue there.

@bmarvo
Copy link
Author

bmarvo commented May 13, 2019

I can confirm that the same issue exists when building with GCC 8.3.0 on Arch Linux. The same fix also works.

I made my own program using libstlink and it exhibits the same behavior when reading flash size for the STM32L431.

@xor-gate
Copy link
Member

Thanks @bmarvo for investigating this more, good it has the same behaviour on two independent systems and configurations. Have you tried updating the firmware of the programmer to the latest? It is also common programmers itself can have bugs programmed too :=D

@xor-gate xor-gate changed the title STM32L431 flash size reads 0 Timing issue when reading the STM32L431 flash size gets result 0 May 13, 2019
@bmarvo
Copy link
Author

bmarvo commented May 17, 2019

@xor-gate I updated my programmers to the latest firmware (which stsw-link007 says is V2.J34.S7) and I'm still getting 0 for flash size without the delay.

@YcSmile
Copy link

YcSmile commented May 26, 2019

@xor-gate
chip : stm32f103ret6
version: v1.5.1-28-gd040db5
info : gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10)

i had the same question.And i build the st-flash with a version of v1.5.1-28-gd040db5 in ubuntu 16.04 and gcc 5.4.0 20160609.
when read the stm32f103 chip flash size reg , delay >5 ms or do a stlink_reset solved my problem.

further information:

 % dpkg -l | grep libusb        
ii  libgusb2:amd64                                              0.2.9-0ubuntu1                                              amd64        GLib wrapper around libusb1
ii  libhidapi-libusb0:amd64                                     0.8.0~rc1+git20140818.d17db57+dfsg-1                        amd64        Multi-Platform library for communication with HID devices (libusb backend)
ii  libusb-0.1-4:amd64                                          2:0.1.12-28                                                 amd64        userspace USB programming library
ii  libusb-1.0-0:amd64                                          2:1.0.20-1                                                  amd64        userspace USB programming library
ii  libusb-1.0-0-dev:amd64                                      2:1.0.20-1                                                  amd64        userspace USB programming library development files
ii  libusb-1.0-doc                                              2:1.0.20-1                                                  all          documentation for userspace USB programming
ii  libusb-dev                                                  2:0.1.12-28                                                 amd64        userspace USB programming library development files
ii  libusbmuxd4:amd64                                           1.0.10-2ubuntu0.1                                           amd64        USB multiplexor daemon for iPhone and iPod Touch devices - library

@Nightwalker-87 Nightwalker-87 added this to the General milestone Feb 19, 2020
@Nightwalker-87 Nightwalker-87 modified the milestones: General, Feedback required Feb 21, 2020
@bmarvo bmarvo self-assigned this Feb 21, 2020
@Nightwalker-87 Nightwalker-87 modified the milestones: Feedback required, v1.6.1 Mar 20, 2020
@Nightwalker-87 Nightwalker-87 modified the milestones: v1.6.1, v1.6.2 May 6, 2020
@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Apr 3, 2021

The proposed fix has not made it into the code yet.

Two questions from my side:

  • Can this behaviour be reproduced with other chips or boards?
  • Is it really related to libusb?

@Nightwalker-87 Nightwalker-87 added the programmer/STLINK/V2 V2 / V2-A / V2-B label Apr 3, 2021
@Ant-ON
Copy link
Collaborator

Ant-ON commented Apr 5, 2021

@Nightwalker-87 There is some strange behavior. Most likely it is related with a reset and may be fixed by #1071

@Nightwalker-87
Copy link
Member

Assumed to be closed by #1071.

@stlink-org stlink-org locked as resolved and limited conversation to collaborators Apr 11, 2021
@Nightwalker-87 Nightwalker-87 moved this to Done in Release v1.7.0 Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants