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

STM32L011D4 flash/erase error #565

Closed
6 tasks done
duro80 opened this issue Mar 10, 2017 · 11 comments · Fixed by #572
Closed
6 tasks done

STM32L011D4 flash/erase error #565

duro80 opened this issue Mar 10, 2017 · 11 comments · Fixed by #572

Comments

@duro80
Copy link

duro80 commented Mar 10, 2017

  • Programmer/board type: Stlink/v2,
  • Programmer firmware version: V2J28S7
  • Operating system: Linux Mint 17.1, 64b
  • Stlink tools version and/or git commit hash: v1.3.1-4-g9d08810
  • Stlink commandline tool name: st-flash
  • Target chip (and optional board): STM32L011D4 (in TSSOP14 package)

Program st-info detect connected MCU, only RAM size is wrong. After try erase/flashing binary file (with st-flash), there is an error:

st-flash erase

st-flash 1.3.1-4-g9d08810
2017-03-10T10:43:40 INFO src/common.c: Loading device parameters....
2017-03-10T10:43:40 INFO src/common.c: Device connected is: L011 device, id 0x10086457
2017-03-10T10:43:40 INFO src/common.c: SRAM size: 0x4000 bytes (16 KiB), Flash: 0x4000 bytes (16 KiB) in pages of 128 bytes
-> Flash page at     0/  128 erased
2017-03-10T10:43:40 WARN src/common.c: pecr.pelock not clear (0x2030405)
2017-03-10T10:43:40 WARN src/common.c: Failed to erase_flash_page(0x8000080) == -1
stlink_erase_flash_mass() == -1

st-flash write program.bin 0x8000000

st-flash 1.3.1-4-g9d08810
2017-03-10T10:43:25 INFO src/common.c: Loading device parameters....
2017-03-10T10:43:25 INFO src/common.c: Device connected is: L011 device, id 0x10086457
2017-03-10T10:43:25 INFO src/common.c: SRAM size: 0x4000 bytes (16 KiB), Flash: 0x4000 bytes (16 KiB) in pages of 128 bytes
2017-03-10T10:43:25 INFO src/common.c: Attempting to write 7148 (0x1bec) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08000000 erased2017-03-10T10:43:25 WARN src/common.c: pecr.pelock not clear (0x2030405)
2017-03-10T10:43:25 ERROR src/common.c: Failed to erase_flash_page(0x8000080) == -1
stlink_fwrite_flash() == -1

I also try MCU STM32L031K6 (nucleo32 board) and works fine. Is there problem in flashloader or somewhere else?
Please add support for STM32L011xx.

@xor-gate
Copy link
Member

Probably duplicate of #564. I only added preliminary support for STM32L011xx so it would show up in the probe. It indeed seems te flashloader for this version is currently broken.

@xor-gate
Copy link
Member

Could you test against PR #572 (latest git master)?

@duro80
Copy link
Author

duro80 commented Mar 16, 2017

Hello!
I tested flashing against #572. Chip erase is OK, with flashnig are some problems:
When flashing, in terminal counts of flashed pages. From 1/66 to 65/65. In penultimate page occurs error:

/usr/local/bin/st-flash --reset write build/EMS_tx_C.bin 0x8000000
st-flash 1.3.1-4-g9d08810
2017-03-16T08:23:21 INFO src/common.c: Loading device parameters....
2017-03-16T08:23:21 INFO src/common.c: Device connected is: L011 device, id 0x10086457
2017-03-16T08:23:21 INFO src/common.c: SRAM size: 0x2000 bytes (8 KiB), Flash: 0x4000 bytes (16 KiB) in pages of 128 bytes
2017-03-16T08:23:21 INFO src/common.c: Ignoring 60 bytes of 0x00 at end of file
2017-03-16T08:23:21 INFO src/common.c: Attempting to write 8504 (0x2138) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08002100 erased
2017-03-16T08:23:22 INFO src/common.c: Finished erasing 67 pages of 128 (0x80) bytes
2017-03-16T08:23:22 INFO src/common.c: Starting Half page flash write for STM32L core id
2017-03-16T08:23:22 ERROR src/flash_loader.c: unknown coreid, not sure what flash loader to use, aborting! coreid: bc11477, chipid: 457
2017-03-16T08:23:22 WARN src/flash_loader.c: Failed to write flash loader to sram!
2017-03-16T08:23:22 WARN src/common.c: stlink_flash_loader_init() == -1
2017-03-16T08:23:22 WARN src/common.c: 
write_half_pages failed == -1
 65/ 66 pages written
2017-03-16T08:23:30 INFO src/common.c: Starting verification of write complete
2017-03-16T08:23:30 ERROR src/common.c: Verification of flash failed at offset: 0
stlink_fwrite_flash() == -1
make: *** [flash] Chyba 255

Size of flashed program was 8.5k and interesting thing is, that program start after reset.

In #572, is wrong parameter .sram_size, I thing. The amount of sram is only 2kB, so .sram_size=0x800

Next, if the MCU is in boot state (BOOT0 pin in hi state after HW reset), stlink cant connect: unknown chip id! 0

@zakqwy
Copy link
Contributor

zakqwy commented Mar 16, 2017

I tried flashing another board and got the same error (3/4 pages written as it was a small test program), so #572 might have some issues. The .sram_size parameter is a bit confusing; the chip only has 2kB of sram but table 3 of RM0377 (pg 52) seems to suggest that the total reserved memory address space is 8k. I'll try changing back to .sram_size=0x800 and see if that fixes the error.

@zakqwy
Copy link
Contributor

zakqwy commented Mar 16, 2017

@duro80 I missed adding sl->chip_id == STLINK_CHIPID_STM32_L011 to flash_loader.c. I just made that change and tested flashing an STM32L011G4 and didn't get any errors. See this commit -- can you test to verify that it works on your end before I submit a fresh PR?

Note that I tried changing .sram_size from 0x2000 to 0x800 and I didn't get errors either way, so I left it as-is. I defer to the experts on that one.

@duro80
Copy link
Author

duro80 commented Mar 17, 2017

Hi @zakqwy .
There is still some error:

st-flash 1.3.1-4-g9d08810
2017-03-17T08:17:48 INFO src/common.c: Loading device parameters....
2017-03-17T08:17:48 INFO src/common.c: Device connected is: L011 device, id 0x10086457
2017-03-17T08:17:48 INFO src/common.c: SRAM size: 0x2000 bytes (8 KiB), Flash: 0x4000 bytes (16 KiB) in pages of 128 bytes
2017-03-17T08:17:48 INFO src/common.c: Ignoring 60 bytes of 0x00 at end of file
2017-03-17T08:17:48 INFO src/common.c: Attempting to write 10228 (0x27f4) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08002780 erased
2017-03-17T08:17:48 INFO src/common.c: Finished erasing 80 pages of 128 (0x80) bytes
2017-03-17T08:17:48 INFO src/common.c: Starting Half page flash write for STM32L core id
2017-03-17T08:17:48 INFO src/flash_loader.c: Successfully loaded flash loader in sram
2017-03-17T08:17:51 ERROR src/flash_loader.c: flash loader run error
2017-03-17T08:17:51 WARN src/common.c: l1_stlink_flash_loader_run(0x8000000) failed! == -1
2017-03-17T08:17:51 WARN src/common.c: 
write_half_pages failed == -1
 78/ 79 pages written
2017-03-17T08:18:00 INFO src/common.c: Starting verification of write complete
2017-03-17T08:18:00 ERROR src/common.c: Verification of flash failed at offset: 0
stlink_fwrite_flash() == -1

The change is in line: src/flash_loader.c: Successfully loaded flash loader in sram
but next line is another error.
And still write only (n-1) pages from.

@zakqwy
Copy link
Contributor

zakqwy commented Mar 17, 2017

@duro80 does running with --debug give you any more detail on the error? I can't recreate on my end, at least with my STM32L011G4 boards.

@duro80
Copy link
Author

duro80 commented Mar 17, 2017

I try on another computer, and result is here:

st-flash 1.3.1-9-gc04df7f
2017-03-17T17:33:12 INFO src/common.c: Loading device parameters....
2017-03-17T17:33:12 INFO src/common.c: Device connected is: L011 device, id 0x10086457
2017-03-17T17:33:12 INFO src/common.c: SRAM size: 0x2000 bytes (8 KiB), Flash: 0x4000 bytes (16 KiB) in pages of 128 bytes
2017-03-17T17:33:13 INFO src/common.c: Attempting to write 7124 (0x1bd4) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08001b80 erased
2017-03-17T17:33:13 INFO src/common.c: Finished erasing 56 pages of 128 (0x80) bytes
2017-03-17T17:33:13 INFO src/common.c: Starting Half page flash write for STM32L core id
2017-03-17T17:33:13 INFO src/flash_loader.c: Successfully loaded flash loader in sram
2017-03-17T17:33:16 ERROR src/flash_loader.c: flash loader run error
2017-03-17T17:33:16 WARN src/common.c: l1_stlink_flash_loader_run(0x8000000) failed! == -1
2017-03-17T17:33:16 WARN src/common.c: 
write_half_pages failed == -1
 54/ 55 pages written
2017-03-17T17:33:22 INFO src/common.c: Starting verification of write complete
2017-03-17T17:33:22 INFO src/common.c: Flash written and verified! jolly good!

With parameter --debug: http://pastebin.com/6VV3VnZV

@duro80
Copy link
Author

duro80 commented Mar 17, 2017

Problem seems to be in function stlink_flash_loader_run(...), sile flash_loader.c. At the end of function (line 363) is wait cycle:

    for (i = 0; i < WAIT_ROUNDS; i++) {
        usleep(10);
        if (stlink_is_core_halted(sl))
            break;
    }
    if (i >= WAIT_ROUNDS) {
        ELOG("flash loader run error\n");
        return -1;
    }

I think, that core is still RUNNING, because function stlink_flash_loader_run return -1. In my previous comment, I attached listing of st-flash with --debud parameter. The file has 3.5MB and most of the content of log output was:

2017-03-17T17:35:46 DEBUG src/common.c: *** stlink_status ***
2017-03-17T17:35:46 DEBUG src/common.c:   core status: running

But I don't now how to enter in HALT state to correctly exit stlink_flash_loader_run function. May be flashloader is no correct for L0, I don't now.

@zakqwy
Copy link
Contributor

zakqwy commented Mar 17, 2017

Hmm. Again, unfortunately I have to defer to the experts on this one. I was able to get the micro flashed tying the BOOT0 pin to ground and disconnecting the nRST line from my Stlink/v2. Maybe give that a shot?

@duro80
Copy link
Author

duro80 commented Mar 17, 2017

Hi. I use ST-link like http://www.ebay.com/itm/Mini-ST-Link-V2-Stlink-Emulator-Downloader-Programming-STM8-STM32-w-Metal-Shell-/282122691251
When I flashing the code the MCU have to be in normal/run mode. When MCU is in boot mode (running the bootloader) by connect log.0 to NRST while BOOT0 pin is in log.1, the st-flash/st-info cant connect to MCU.

But: interesting is, that st-flash write "Flash written and verified! jolly good!" and the end.

@Nightwalker-87 Nightwalker-87 modified the milestones: Unplanned (Contributions Welcome), Next, General, Feedback required Feb 19, 2020
@Nightwalker-87 Nightwalker-87 self-assigned this Feb 21, 2020
@Nightwalker-87 Nightwalker-87 modified the milestones: Feedback required, v1.4.0 Mar 18, 2020
@Nightwalker-87 Nightwalker-87 linked a pull request Mar 18, 2020 that will close this issue
@Nightwalker-87 Nightwalker-87 removed their assignment Mar 18, 2020
@stlink-org stlink-org locked as resolved and limited conversation to collaborators Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants